-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageLoader.vhd
80 lines (67 loc) · 1.93 KB
/
ImageLoader.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.all;
use ieee.std_logic_arith.all;
library std;
use work.Pixel.all;
entity ImageLoader is
generic (
init_file : STRING;
image_width : INTEGER;
image_height : INTEGER;
memory_size : INTEGER;
address_width : INTEGER
);
port (
clk : in STD_LOGIC;
column : in INTEGER;
row : in INTEGER;
pixel : out pixel_type
);
end entity ImageLoader;
architecture rtl of ImageLoader is
component ROM
generic (
init_file : STRING;
data_width : INTEGER;
address_width : INTEGER;
memory_size : INTEGER
);
port (
address : in STD_LOGIC_VECTOR (address_width - 1 downto 0);
clock : in STD_LOGIC := '1';
q : out STD_LOGIC_VECTOR (data_width - 1 downto 0)
);
end component;
signal pixel_index : INTEGER;
signal pixel_address : STD_LOGIC_VECTOR(address_width - 1 downto 0);
signal pixel_data : STD_LOGIC_VECTOR(7 downto 0);
signal should_draw : BOOLEAN;
begin
image : ROM
generic map(
init_file => init_file,
data_width => 8,
address_width => address_width,
memory_size => memory_size
)
port map(
clock => clk,
address => pixel_address,
q => pixel_data
);
-- Image is serialized column-major
pixel_index <= row + (column * image_height);
pixel_address <= conv_std_logic_vector(pixel_index, pixel_address'length);
should_draw <= (column <= image_width and row <= image_height and pixel_index <= memory_size);
pixel.red <=
pixel_data(7 downto 0) when (should_draw) else
"00000000";
pixel.green <=
pixel_data(7 downto 0) when (should_draw) else
"00000000";
pixel.blue <=
pixel_data(7 downto 0) when (should_draw) else
"00000000";
end architecture;