function qr = encode_qr(message, s)
% ENCODE_QR create a 2D QR code containing a message
%  
% This function creates a QR code containing a string message. The QR code
% can be of varying sizes.
%
% Note that this function requires zxing (http://code.google.com/p/zxing/)
% installed, and core/core.jar, javase/javase.jar on the classpath
%
%   Parameters:
%
%       message - string containing message
%       s       - width and height of the QR code
%
%   Returns:
%
%       qr - logical matrix of size s containing the QR code

%% AUTHOR    : Lior Shapira 
%% $DATE     : 02-Nov-2010 11:20:45 $ 
%% $Revision : 1.00 $ 
%% DEVELOPED : 7.11.0.584 (R2010b) 
%% FILENAME  : encode_qr.m 

% dynamically add library to java path
wdir = fileparts(mfilename('fullpath'));
javaaddpath(sprintf('%s/3rd_party/zxing-1.7/core/core.jar', wdir));
javaaddpath(sprintf('%s/3rd_party/zxing-1.7/javase/javase.jar', wdir));

%import com.google.zxing.qrcode.QRCodeWriter;
%import com.google.zxing.BarcodeFormat;
import com.google.zxing.qrcode.*;
import com.google.zxing.*;


% encoding qr
qr_writer = QRCodeWriter;
M_java = qr_writer.encode(message, BarcodeFormat.QR_CODE, s(2), s(1));
qr = zeros(M_java.height, M_java.width);
for i=1:M_java.height
    for j=1:M_java.width
        qr(i,j) = M_java.get(j-1,i-1);
    end
end

clear qr_writer;
clear M_java;

qr = logical(qr);

% Created with NEWFCN.m by Frank González-Morphy  
% Contact...: frank.gonzalez-morphy@mathworks.de  
% ===== EOF ====== [encode_qr.m] ======  
