OpenCores
URL https://opencores.org/ocsvn/image_component_labeling_and_feature_extraction/image_component_labeling_and_feature_extraction/trunk

Subversion Repositories image_component_labeling_and_feature_extraction

[/] [image_component_labeling_and_feature_extraction/] [trunk/] [img_testbench2_08bits.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 malikpearl
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_arith.all;
4
use ieee.std_logic_unsigned.all;
5
use std.textio.all;
6
 
7
entity img_testbench is
8
  port (
9
    pclk_i              : in  std_logic;
10
         reset_i                : in  std_logic;
11
         fsync_i                : in  std_logic;
12
         rsync_i                : in  std_logic;
13
    pdata_i             : in std_logic_vector(7 downto 0);
14
    cols_o              : out std_logic_vector(15 downto 0);
15
         rows_o         : out std_logic_vector(15 downto 0);
16
         col_o          : out std_logic_vector(15 downto 0);
17
         row_o          : out std_logic_vector(15 downto 0);
18
         rsync_o                : out std_logic;
19
         fsync_o                : out std_logic;
20
    pdata_o             : out std_logic_vector(7 downto 0) );
21
end img_testbench;
22
 
23
architecture main of img_testbench is
24
 
25
  type ByteT is (c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,
26
                                                c19,c20,c21,c22,c23,c24,c25,c26,c27,c28,c29,c30,c31,c32,c33,c34,
27
                                                c35,c36,c37,c38,c39,c40,c41,c42,c43,c44,c45,c46,c47,c48,c49,c50,
28
                                                c51,c52,c53,c54,c55,c56,c57,c58,c59,c60,c61,c62,c63,c64,c65,c66,
29
                                                c67,c68,c69,c70,c71,c72,c73,c74,c75,c76,c77,c78,c79,c80,c81,c82,
30
                                                c83,c84,c85,c86,c87,c88,c89,c90,c91,c92,c93,c94,c95,c96,c97,c98,
31
                                                c99,c100,c101,c102,c103,c104,c105,c106,c107,c108,c109,c110,c111,
32
                                                c112,c113,c114,c115,c116,c117,c118,c119,c120,c121,c122,c123,c124,
33
                                                c125,c126,c127,c128,c129,c130,c131,c132,c133,c134,c135,c136,c137,
34
                                                c138,c139,c140,c141,c142,c143,c144,c145,c146,c147,c148,c149,c150,
35
                                                c151,c152,c153,c154,c155,c156,c157,c158,c159,c160,c161,c162,c163,
36
                                                c164,c165,c166,c167,c168,c169,c170,c171,c172,c173,c174,c175,c176,
37
                                                c177,c178,c179,c180,c181,c182,c183,c184,c185,c186,c187,c188,c189,
38
                                                c190,c191,c192,c193,c194,c195,c196,c197,c198,c199,c200,c201,c202,
39
                                                c203,c204,c205,c206,c207,c208,c209,c210,c211,c212,c213,c214,c215,
40
                                                c216,c217,c218,c219,c220,c221,c222,c223,c224,c225,c226,c227,c228,
41
                                                c229,c230,c231,c232,c233,c234,c235,c236,c237,c238,c239,c240,c241,
42
                                c242,c243,c244,c245,c246,c247,c248,c249,c250,c251,c252,c253,c254,c255);
43
  subtype Byte is ByteT;
44
  type ByteFileType is file of Byte;
45
  file infile   : ByteFileType open read_mode is "test1.bmp";
46
  file outfile  : ByteFileType open write_mode is "result_08bits.bmp";
47
 
48
  -- integer to bit_vector conversion
49
  function int2bit_vec(A: integer; SIZE: integer) return BIT_VECTOR is
50
                variable RESULT : BIT_VECTOR(SIZE-1 DOWNTO 0);
51
                variable TMP            : integer;
52
        begin
53
                TMP := A;
54
                for i in 0 to SIZE - 1 loop
55
                        if TMP mod 2 = 1 then RESULT(i) := '1';
56
                        else RESULT(i) := '0';
57
                        end if;
58
                        TMP := TMP / 2;
59
                end loop;
60
                return RESULT;
61
        end;
62
 
63
begin  -- main
64
 
65
        img_read : process (pclk_i)
66
                variable pixelB : Byte;
67
                variable pixelG : Byte;
68
                variable pixelR : Byte;
69
                variable pixel : Byte;
70
                variable pixel1 : REAL;
71
                variable cols   : std_logic_vector(15 downto 0);
72
                variable rows   : std_logic_vector(15 downto 0);
73
                variable col    : std_logic_vector(15 downto 0);
74
                variable row    : std_logic_vector(15 downto 0);
75
                variable cnt    : integer;
76
                variable rsync  : std_logic := '0';
77
                variable stop   : std_logic;
78
                variable pixptr : std_logic_vector(19 downto 0) := (others => '0');
79
                type videomemtype is array (1048575 downto 0) of std_logic_vector(7 downto 0);
80
                variable videomem : videomemtype := (others=> (others=>'0'));
81
 
82
        begin  -- process img_read
83
                if (reset_i = '1') then
84
                        pdata_o <= (others => '0');
85
                        col             := (others => '0');
86
                        row             :=      (others => '0');
87
                for i in 0 to 53 loop -- read header infos
88
                        read(infile, pixel);
89
                        write(outfile, pixel);
90
                        case i is
91
                                when 18 =>              -- 1st byte of cols
92
                                        cols(7 downto 0 ) := To_Stdlogicvector(int2bit_vec(ByteT'pos(pixel), 8));
93
                                when 19 =>              -- 2nd byte of cols
94
                                        cols(15 downto 8) := To_Stdlogicvector(int2bit_vec(ByteT'pos(pixel), 8));
95
                                when 22 =>              -- 1st byte of rows
96
                                        rows(7 downto 0 ) := To_Stdlogicvector(int2bit_vec(ByteT'pos(pixel), 8));
97
                                when 23 =>              -- 2nd byte of  rows
98
                                        rows(15 downto 8) := to_Stdlogicvector(int2bit_vec(ByteT'pos(pixel), 8));
99
                                when 24 =>              -- do important things
100
                                        cols_o  <= cols;
101
                                        rows_o  <= rows;
102
                                        cols            := cols - 1;
103
                                        rows            := rows - 1;
104
                                when others =>
105
                                        null;
106
                        end case;
107
                end loop; -- i
108
                rsync := '1';
109
                cnt     := 10;
110
                stop    := '0';
111
 
112
                elsif (pclk_i'event and pclk_i = '1') then
113
                        rsync_o <= rsync;
114
                        if rsync = '1' then
115
 
116
                                if row = "0000000000000000" and col = "0000000000000000" then
117
                                        fsync_o <= '1';
118
                                        pixptr := (others => '0');
119
                                else
120
                                        fsync_o <= '0';
121
                                end if;
122
 
123
                                if stop = '0' then
124
                                        read(infile, pixelB); -- B
125
                                        read(infile, pixelG); -- G
126
                                        read(infile, pixelR); -- R
127
                                        pixel1  := (ByteT'pos(pixelB)*0.11) + (ByteT'pos(pixelR)*0.3) + (ByteT'pos(pixelG)*0.59);
128
                                        pdata_o <= CONV_STD_LOGIC_VECTOR(INTEGER(pixel1), 8);
129
                                        videomem(conv_integer(pixptr)) := CONV_STD_LOGIC_VECTOR(INTEGER(pixel1), 8);
130
                                        pixptr := pixptr + 1;
131
                                        col_o           <= col;
132
                                        row_o           <= row;
133
                                else
134
                                        pdata_o <= videomem(conv_integer(pixptr));
135
                                        pixptr := pixptr + 1;
136
                                end if;
137
 
138
                                if col = cols then
139
                                        col     := (others => '0');
140
                                        rsync   := '0';
141
                                        if row = rows then
142
                                                File_Close(infile);
143
                                                stop := '1';
144
                                                row := (others=>'0'); -- This line was added by Benny
145
                                        else
146
                                                row := row + 1;
147
                                        end if;         -- row
148
                                else
149
                                        col := col + 1;
150
                                end if;                 -- col
151
 
152
                        else                                    -- rsync
153
                                if cnt > 0 then
154
                                        cnt     := cnt -1;
155
                                else
156
                                        cnt     := 10;  -- Can be changed from 10 to 300 to get correct frame speed timing
157
                                        rsync := '1';
158
                                end if;
159
                                pdata_o <= (others => 'X');
160
                        end if; -- rsync
161
 
162
                        if rsync_i = '1' then
163
                                write(outfile, ByteT'val(ieee.numeric_std.To_Integer(ieee.numeric_std.unsigned(pdata_i)))); --, pixel);
164
                                write(outfile, ByteT'val(ieee.numeric_std.To_Integer(ieee.numeric_std.unsigned(pdata_i)))); --, pixel);
165
                                write(outfile, ByteT'val(ieee.numeric_std.To_Integer(ieee.numeric_std.unsigned(pdata_i)))); --, pixel);
166
                        end if; -- rsync_i
167
 
168
                end if;   -- clk
169
        end process img_read;
170
end main;

powered by: WebSVN 2.1.0

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