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

Subversion Repositories mkjpeg

[/] [mkjpeg/] [trunk/] [design/] [JFIFGen/] [JFIFGen.vhd] - Blame information for rev 36

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 mikel262
-------------------------------------------------------------------------------
2
-- File Name :  JFIFGen.vhd
3
--
4
-- Project   : JPEG_ENC
5
--
6
-- Module    : JFIFGen
7
--
8
-- Content   : JFIF Header Generator
9
--
10
-- Description :
11
--
12
-- Spec.     : 
13
--
14
-- Author    : Michal Krepa
15
--
16
-------------------------------------------------------------------------------
17
-- History :
18
-- 20090309: (MK): Initial Creation.
19
-------------------------------------------------------------------------------
20
 
21
-------------------------------------------------------------------------------
22
-------------------------------------------------------------------------------
23
----------------------------------- LIBRARY/PACKAGE ---------------------------
24
-------------------------------------------------------------------------------
25
-------------------------------------------------------------------------------
26
 
27
-------------------------------------------------------------------------------
28
-- generic packages/libraries:
29
-------------------------------------------------------------------------------
30
library ieee;
31
  use ieee.std_logic_1164.all;
32
  use ieee.numeric_std.all;
33
 
34
library work;
35
  use work.JPEG_PKG.all;
36
 
37
-------------------------------------------------------------------------------
38
-- user packages/libraries:
39
-------------------------------------------------------------------------------
40
 
41
-------------------------------------------------------------------------------
42
-------------------------------------------------------------------------------
43
----------------------------------- ENTITY ------------------------------------
44
-------------------------------------------------------------------------------
45
-------------------------------------------------------------------------------
46
entity JFIFGen is
47
  port
48
  (
49
        CLK                : in  std_logic;
50
        RST                : in  std_logic;
51
        -- CTRL
52
        start              : in  std_logic;
53
        ready              : out std_logic;
54
        eoi                : in  std_logic;
55
 
56
        -- ByteStuffer
57
        num_enc_bytes      : in  std_logic_vector(23 downto 0);
58
 
59
        -- HOST IF
60
        qwren              : in  std_logic;
61 32 mikel262
        qwaddr             : in  std_logic_vector(6 downto 0);
62 25 mikel262
        qwdata             : in  std_logic_vector(7 downto 0);
63
        image_size_reg     : in  std_logic_vector(31 downto 0);
64
        image_size_reg_wr  : in  std_logic;
65
 
66
        -- OUT RAM
67
        ram_byte           : out std_logic_vector(7 downto 0);
68
        ram_wren           : out std_logic;
69
        ram_wraddr         : out std_logic_vector(23 downto 0)
70
    );
71
end entity JFIFGen;
72
 
73
-------------------------------------------------------------------------------
74
-------------------------------------------------------------------------------
75
----------------------------------- ARCHITECTURE ------------------------------
76
-------------------------------------------------------------------------------
77
-------------------------------------------------------------------------------
78
architecture RTL of JFIFGen is
79
 
80
  constant C_SIZE_Y_H  : integer := 25;
81
  constant C_SIZE_Y_L  : integer := 26;
82
  constant C_SIZE_X_H  : integer := 27;
83
  constant C_SIZE_X_L  : integer := 28;
84
 
85
  constant C_EOI       : std_logic_vector(15 downto 0) := X"FFD9";
86 32 mikel262
  constant C_QLUM_BASE : integer := 44;
87
  constant C_QCHR_BASE : integer := 44+69;
88 25 mikel262
 
89
 
90
  signal hr_data      : std_logic_vector(7 downto 0);
91 36 mikel262
  signal hr_waddr     : std_logic_vector(9 downto 0);
92
  signal hr_raddr     : std_logic_vector(9 downto 0);
93 25 mikel262
  signal hr_we        : std_logic;
94
  signal hr_q         : std_logic_vector(7 downto 0);
95
  signal size_wr_cnt  : unsigned(2 downto 0);
96
  signal size_wr      : std_logic;
97 36 mikel262
  signal rd_cnt       : unsigned(9 downto 0);
98 25 mikel262
  signal rd_en        : std_logic;
99
  signal rd_en_d1     : std_logic;
100 36 mikel262
  signal rd_cnt_d1    : unsigned(rd_cnt'range);
101
  signal rd_cnt_d2    : unsigned(rd_cnt'range);
102 25 mikel262
  signal eoi_cnt      : unsigned(1 downto 0);
103
  signal eoi_wr       : std_logic;
104
  signal eoi_wr_d1    : std_logic;
105
 
106
-------------------------------------------------------------------------------
107
-- Architecture: begin
108
-------------------------------------------------------------------------------
109
begin
110
 
111
  -------------------------------------------------------------------
112
  -- Header RAM
113
  -------------------------------------------------------------------
114
  U_Header_RAM : entity work.RAMZ
115
  generic map
116
  (
117 36 mikel262
      RAMADDR_W     => 10,
118 25 mikel262
      RAMDATA_W     => 8
119
  )
120
  port map
121
  (
122
        d           => hr_data,
123
        waddr       => hr_waddr,
124
        raddr       => hr_raddr,
125
        we          => hr_we,
126
        clk         => CLK,
127
 
128
        q           => hr_q
129
  );
130
 
131
  hr_raddr <= std_logic_vector(rd_cnt);
132
 
133
  -------------------------------------------------------------------
134
  -- Host programming
135
  -------------------------------------------------------------------
136
  p_host_wr : process(CLK, RST)
137
  begin
138
    if RST = '1' then
139
      size_wr_cnt <= (others => '0');
140
      size_wr     <= '0';
141
      hr_we       <= '0';
142
      hr_data     <= (others => '0');
143
      hr_waddr    <= (others => '0');
144
    elsif CLK'event and CLK = '1' then
145
      hr_we <= '0';
146
 
147
      if image_size_reg_wr = '1' then
148
        size_wr_cnt <= (others => '0');
149
        size_wr     <= '1';
150
      end if;
151
 
152
      -- write image size
153
      if size_wr = '1' then
154
        if size_wr_cnt = 4 then
155
          size_wr_cnt <= (others => '0');
156
          size_wr     <= '0';
157
        else
158
          size_wr_cnt <= size_wr_cnt + 1;
159
          hr_we <= '1';
160
          case size_wr_cnt is
161
            -- height H byte
162
            when "000" =>
163
              hr_data  <= image_size_reg(15 downto 8);
164
              hr_waddr <= std_logic_vector(to_unsigned(C_SIZE_Y_H,hr_waddr'length));
165
            -- height L byte
166
            when "001" =>
167
              hr_data <= image_size_reg(7 downto 0);
168
              hr_waddr <= std_logic_vector(to_unsigned(C_SIZE_Y_L,hr_waddr'length));
169
            -- width H byte
170
            when "010" =>
171
              hr_data <= image_size_reg(31 downto 24);
172
              hr_waddr <= std_logic_vector(to_unsigned(C_SIZE_X_H,hr_waddr'length));
173
            -- width L byte
174
            when "011" =>
175
              hr_data <= image_size_reg(23 downto 16);
176
              hr_waddr <= std_logic_vector(to_unsigned(C_SIZE_X_L,hr_waddr'length));
177
            when others =>
178
              null;
179
          end case;
180
        end if;
181
      -- write Quantization table
182
      elsif qwren = '1' then
183 32 mikel262
        -- luminance table select
184
        if qwaddr(6) = '0' then
185
          hr_waddr <= std_logic_vector
186
                        ( resize(unsigned(qwaddr(5 downto 0)),hr_waddr'length) +
187
                          to_unsigned(C_QLUM_BASE,hr_waddr'length));
188
        else
189
          -- chrominance table select
190
          hr_waddr <= std_logic_vector
191
                        ( resize(unsigned(qwaddr(5 downto 0)),hr_waddr'length) +
192
                          to_unsigned(C_QCHR_BASE,hr_waddr'length));
193
        end if;
194 25 mikel262
        hr_we   <= '1';
195
        hr_data <= qwdata;
196
      end if;
197
 
198
    end if;
199
  end process;
200
 
201
  -------------------------------------------------------------------
202
  -- CTRL
203
  -------------------------------------------------------------------
204
  p_ctrl : process(CLK, RST)
205
  begin
206
    if RST = '1' then
207
      ready      <= '0';
208
      rd_en      <= '0';
209
      rd_cnt     <= (others => '0');
210
      rd_cnt_d1  <= (others => '0');
211
      rd_cnt_d2  <= (others => '0');
212
      rd_cnt_d1  <= (others => '0');
213
      rd_en_d1   <= '0';
214
      eoi_wr_d1  <= '0';
215
      eoi_wr     <= '0';
216
      eoi_cnt    <= (others => '0');
217
      ram_wren   <= '0';
218
      ram_byte   <= (others => '0');
219
      ram_wraddr <= (others => '0');
220
    elsif CLK'event and CLK = '1' then
221
      ready     <= '0';
222
      rd_cnt_d1 <= rd_cnt;
223
      rd_cnt_d2 <= rd_cnt_d1;
224
      rd_en_d1  <= rd_en;
225
      eoi_wr_d1 <= eoi_wr;
226
 
227
      -- defaults: encoded data write
228
      ram_wren   <= rd_en_d1;
229
      ram_wraddr <= std_logic_vector(resize(rd_cnt_d1,ram_wraddr'length));
230
      ram_byte   <= hr_q;
231
 
232
      -- start JFIF
233
      if start = '1' and eoi = '0' then
234
        rd_cnt <= (others => '0');
235
        rd_en  <= '1';
236
      elsif start = '1' and eoi = '1' then
237
        eoi_wr  <= '1';
238
        eoi_cnt <= (others => '0');
239
      end if;
240
 
241
      -- read JFIF Header
242
      if rd_en = '1' then
243
        if rd_cnt = C_HDR_SIZE-1 then
244
          rd_en  <= '0';
245
          ready  <= '1';
246
        else
247
          rd_cnt <= rd_cnt + 1;
248
        end if;
249
      end if;
250
 
251
      -- EOI MARKER write
252
      if eoi_wr = '1' then
253
        if eoi_cnt = 2 then
254
          eoi_cnt  <= (others => '0');
255
          eoi_wr   <= '0';
256
          ready    <= '1';
257
        else
258
          eoi_cnt  <= eoi_cnt + 1;
259
          ram_wren <= '1';
260
          if eoi_cnt = 0 then
261
            ram_byte   <= C_EOI(15 downto 8);
262
            ram_wraddr <= num_enc_bytes;
263
          elsif eoi_cnt = 1 then
264
            ram_byte   <= C_EOI(7 downto 0);
265
            ram_wraddr <= std_logic_vector(unsigned(num_enc_bytes) +
266
                                           to_unsigned(1,ram_wraddr'length));
267
          end if;
268
        end if;
269
      end if;
270
    end if;
271
  end process;
272
 
273
end architecture RTL;
274
-------------------------------------------------------------------------------
275
-- Architecture: end
276
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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