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

Subversion Repositories video_dithering

[/] [video_dithering/] [trunk/] [tb.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Peip_Rober
library IEEE;
2
use IEEE.std_logic_1164.all;
3
use IEEE.numeric_std.all;
4
use IEEE.std_logic_textio.all;
5
use STD.textio.all;
6
 
7
 
8
entity tb is
9
end entity;
10
 
11
architecture arch of tb is
12
 
13
   constant img_width      : integer := 256;
14
   constant img_height     : integer := 512;
15
   constant reduced_width  : integer := 4;
16
 
17
   type   bit_vector_file is file of bit_vector;
18
   file   read_file       : bit_vector_file open read_mode is "input.bmp";
19
 
20
   type   std_file is file of character;
21
   file   write_file      : std_file open write_mode is "output.bmp";
22
 
23
   signal clk        : std_logic := '1';
24
 
25
   type t_color is array(1 to 3) of std_logic_vector(7 downto 0);
26
   type t_bmp is array(0 to img_width, 0 to img_height) of t_color;
27
   signal bmp_read   : t_bmp;
28
   signal bmp_out    : t_bmp := (others => (others => (others => (others => '0'))));
29
 
30
   signal enable     : std_logic := '0';
31
 
32
   signal din_r      : std_logic_vector(7 downto 0) := (others => '0');
33
   signal din_g      : std_logic_vector(7 downto 0) := (others => '0');
34
   signal din_b      : std_logic_vector(7 downto 0) := (others => '0');
35
   signal dout_r     : std_logic_vector(7 downto 0);
36
   signal dout_g     : std_logic_vector(7 downto 0);
37
   signal dout_b     : std_logic_vector(7 downto 0);
38
 
39
   signal x_count    : integer := 0;
40
   signal y_count    : integer := 0;
41
   signal x_in       : integer := 0;
42
   signal y_in       : integer := 1;
43
   signal x_out      : integer := 0;
44
   signal y_out      : integer := 1;
45
 
46
   signal running    : std_logic := '0';
47
   signal done       : std_logic := '0';
48
 
49
begin
50
 
51
 
52
   clk <= not clk after 5 ns;
53
 
54
 
55
   pcreate_pixelpositions : process (clk)
56
   begin
57
      if rising_edge(clk) then
58
 
59
         if (running = '1' and done = '0') then
60
 
61
            if (x_count < img_width-1) then
62
               x_count <= x_count + 1;
63
            else
64
               x_count <= 0;
65
               if (y_count< img_height-1) then
66
                  y_count <= y_count + 1;
67
               else
68
                  done <= '1';
69
               end if;
70
            end if;
71
 
72
            -- for test only one half of image is dithered
73
            if (y_count < img_height / 2) then
74
               enable <= '1';
75
            else
76
               enable <= '0';
77
            end if;
78
 
79
            x_in <= x_count;
80
            y_in <= y_count;
81
 
82
            x_out <= x_in;
83
            y_out <= y_in;
84
 
85
            din_r <= bmp_read(x_count,y_count)(1);
86
            din_g <= bmp_read(x_count,y_count)(2);
87
            din_b <= bmp_read(x_count,y_count)(3);
88
 
89
            bmp_out(x_out,y_out)(1) <= dout_r(7 downto 7 - reduced_width + 1) & (7 - reduced_width downto 0 => '0');
90
            bmp_out(x_out,y_out)(2) <= dout_g(7 downto 7 - reduced_width + 1) & (7 - reduced_width downto 0 => '0');
91
            bmp_out(x_out,y_out)(3) <= dout_b(7 downto 7 - reduced_width + 1) & (7 - reduced_width downto 0 => '0');
92
 
93
         end if;
94
 
95
      end if;
96
   end process;
97
 
98
 
99
 
100
   idither : entity work.eDither
101
   generic map
102
   (
103
      img_width      => img_width,
104
      img_height     => img_height,
105
      color_width    => 8,
106
      reduced_width  => reduced_width
107
   )
108
   port map
109
   (
110
      clk       => clk,
111
      enable    => enable,
112
      x         => x_in,
113
      din_r     => din_r,
114
      din_g     => din_g,
115
      din_b     => din_b,
116
      dout_r    => dout_r,
117
      dout_g    => dout_g,
118
      dout_b    => dout_b
119
   );
120
 
121
 
122
 
123
   pfile_actions : process
124
 
125
      variable next_vector : bit_vector (0 downto 0);
126
      variable actual_len  : natural;
127
      variable addr        : unsigned(17 downto 0) := (others => '0');
128
      variable to_write    : signed(15 downto 0);
129
      variable read_byte   : std_logic_vector(7 downto 0);
130
 
131
      -- copy from std_logic_arith, not used here because numeric std is also included
132
      function CONV_STD_LOGIC_VECTOR(ARG: INTEGER; SIZE: INTEGER) return STD_LOGIC_VECTOR is
133
        variable result: STD_LOGIC_VECTOR (SIZE-1 downto 0);
134
        variable temp: integer;
135
      begin
136
 
137
         temp := ARG;
138
         for i in 0 to SIZE-1 loop
139
 
140
         if (temp mod 2) = 1 then
141
            result(i) := '1';
142
         else
143
            result(i) := '0';
144
         end if;
145
 
146
         if temp > 0 then
147
            temp := temp / 2;
148
         elsif (temp > integer'low) then
149
            temp := (temp - 1) / 2; -- simulate ASR
150
         else
151
            temp := temp / 2; -- simulate ASR
152
         end if;
153
        end loop;
154
 
155
        return result;
156
      end;
157
 
158
      variable std_buffer : character;
159
 
160
   begin
161
 
162
      -- copy bmp header
163
      for i in 1 to 51 loop
164
         read(read_file, next_vector, actual_len);
165
         std_buffer := character'val(to_integer(unsigned(CONV_STD_LOGIC_VECTOR(bit'pos(next_vector(0)), 8))));
166
         write(write_file, std_buffer);
167
      end loop;
168
 
169
      -- read in bmp color data
170
      for y in 0 to img_height-1 loop
171
         for x in 0 to img_width-1 loop
172
            for c in 1 to 3 loop
173
 
174
               read(read_file, next_vector, actual_len);
175
               read_byte := CONV_STD_LOGIC_VECTOR(bit'pos(next_vector(0)), 8);
176
               bmp_read(x,y)(c) <= read_byte;
177
               wait for 5 ns;
178
 
179
            end loop;
180
         end loop;
181
      end loop;
182
 
183
      running <= '1';
184
 
185
      wait until done = '1';
186
 
187
      -- write result to bmp
188
      for y in 0 to img_height-1 loop
189
         for x in 0 to img_width-1 loop
190
            for c in 1 to 3 loop
191
 
192
               std_buffer := character'val(to_integer(unsigned(bmp_out(x,y)(c))));
193
               write(write_file, std_buffer);
194
 
195
            end loop;
196
         end loop;
197
      end loop;
198
 
199
      running <= '0';
200
 
201
      ASSERT false REPORT "End of Test" SEVERITY FAILURE;
202
 
203
      wait;
204
 
205
   end process;
206
 
207
 
208
 
209
end architecture;
210
 
211
 
212
 
213
 
214
 

powered by: WebSVN 2.1.0

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