clear;

NUM_MAPS = 4;

fid = fopen('image.h', 'W');

for num = 1:NUM_MAPS
    
    img_name = ['image' num2str(num) '.bmp'];
    img = imread(img_name, 'bmp');
    img = img(:,:,1);
    img = double(img);
    [height width] = size(img);
    img = ~round(img/255);

    fprintf(fid, 'flash unsigned char image%d[%d] = {%d,%d,%d,%d,\n',num, width/8*height+4, 0, width, 0, height);

	for j = 1:height    
        for i = 1:width
            if (mod((i-1),8) == 0) %beginning of new byte
                fprintf(fid, '0b%d', img(j,i));
            elseif(i==width & j==height) %very last character
                fprintf(fid, '%d};', img(j,i));
            elseif (mod((i-1),8 )==7) %end of byte
               fprintf(fid, '%d, ', img(j,i));
           else
               fprintf(fid, '%d', img(j,i));  
           end 
        end
        fprintf(fid, '\n');
	end
        fprintf(fid, '\n\n\n');

        

figure(num)
imagesc(img);
pbaspect([width,height,1]);
axis off;

end
fclose(fid);


colormap(gray);