OpenCores
URL https://opencores.org/ocsvn/2d_game_console/2d_game_console/trunk

Subversion Repositories 2d_game_console

[/] [2d_game_console/] [trunk/] [bmp2hex_16bits/] [bmp2hex_16bits.m] - Rev 2

Compare with Previous | Blame | View Log

img=imread('image_test.bmp'); % 24-bit BMP image RGB888
 
col = 640;
lin = 480;
mem_depth = 1048576;        %The size of memory in words
mem_width = 16;             %The size of data in bits
a = zeros(1, (col*lin));    %Preallocation of pixels vector
 
address = (lin*col*16)/mem_width;
 
if (address > mem_depth)
    disp('Error: Not enough memory!');
    disp(' ');
 
else
 
    %Teste das funcoes
    test1 = dec2bin(204,8);
    test2 = dec2bin(153,8);
    test3 = test1(1:5);
    test4 = test2(1:5);
    test5 = [test3 , test4];
    test6 = bin2dec(test5);
 
    k=1;
    for i=1:lin
        disp(i);
        for j=1:col
            r = dec2bin( img(i,j,1), 8 );
            g = dec2bin( img(i,j,2), 8 );
            b = dec2bin( img(i,j,3), 8 );
 
            r = r(1:5);
            g = g(1:6);
            b = b(1:5);
 
            pixel = [b, g, r];
            pixel_2 = [pixel(9:16), pixel(1:8)];
            a(k) = bin2dec(pixel_2);
            k = k+1;
        end
    end
 
    fid = fopen('image_test.hex', 'wt');
    fprintf(fid, '%04X', a);
    disp('Text file write done');disp(' ');
    fclose(fid);
end
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.