% load image
A = open('');
if std(single(alpha(:))) > std(single(cdata(:)))
    A = alpha;
    A(A<130) = 0;A(A>129) = 1;
    A = ~A; A = 255*A;
else
    A = cdata;
end
% scale and pad image
L = floor(size(A,1)/29);
B = 255*ones(48*L,64*L);
P = floor((size(B,1)-size(A,1))/2);
PP= floor((38*L-size(A,1))/2);
B(P+1:P+size(A,1),PP+1:PP+size(A,2)) = mean(A,3);
% resize image
C = imresize(B, [48,64]);
C(C<130) = 1;C(C>129) = 0;D = [];
% flatten to numbers
for ii=1:6
    P = 8*(ii-1);
    D = [D C(P+1:P+8,:)]; 
end
% flip image
E = D'; F = []; FF = 2.^[0:7];
% generate hexadecimal
for ii=1:size(E,1)
   F(ii) =  E(ii,:)*FF';
end
figure(1); imagesc(C);
fprintf('\nuint8_t icon[] = {\n');
for ii=1:16:384
    fprintf(sprintf('0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s,0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s,\n',...
        dec2hex(F(ii),2), dec2hex(F(ii+1),2), dec2hex(F(ii+2),2), ...
        dec2hex(F(ii+3),2), dec2hex(F(ii+4),2), dec2hex(F(ii+5),2),...
        dec2hex(F(ii+6),2), dec2hex(F(ii+7)), dec2hex(F(ii+8),2), ...
        dec2hex(F(ii+9),2), dec2hex(F(ii+10),2), ...
        dec2hex(F(ii+11),2), dec2hex(F(ii+12),2), dec2hex(F(ii+13),2),...
        dec2hex(F(ii+14),2), dec2hex(F(ii+15))));
end
fprintf('};\n');
imagesc(C);