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] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 lucas.vbal
img=imread('image_test.bmp'); % 24-bit BMP image RGB888
2
 
3
col = 640;
4
lin = 480;
5
mem_depth = 1048576;        %The size of memory in words
6
mem_width = 16;             %The size of data in bits
7
a = zeros(1, (col*lin));    %Preallocation of pixels vector
8
 
9
address = (lin*col*16)/mem_width;
10
 
11
if (address > mem_depth)
12
    disp('Error: Not enough memory!');
13
    disp(' ');
14
 
15
else
16
 
17
    %Teste das funcoes
18
    test1 = dec2bin(204,8);
19
    test2 = dec2bin(153,8);
20
    test3 = test1(1:5);
21
    test4 = test2(1:5);
22
    test5 = [test3 , test4];
23
    test6 = bin2dec(test5);
24
 
25
    k=1;
26
    for i=1:lin
27
        disp(i);
28
        for j=1:col
29
            r = dec2bin( img(i,j,1), 8 );
30
            g = dec2bin( img(i,j,2), 8 );
31
            b = dec2bin( img(i,j,3), 8 );
32
 
33
            r = r(1:5);
34
            g = g(1:6);
35
            b = b(1:5);
36
 
37
            pixel = [b, g, r];
38
            pixel_2 = [pixel(9:16), pixel(1:8)];
39
            a(k) = bin2dec(pixel_2);
40
            k = k+1;
41
        end
42
    end
43
 
44
    fid = fopen('image_test.hex', 'wt');
45
    fprintf(fid, '%04X', a);
46
    disp('Text file write done');disp(' ');
47
    fclose(fid);
48
end

powered by: WebSVN 2.1.0

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