1 -------------------------------------------------------------------------------
2 -- Description: This file implements the loopfilter. A filter that do
3 -- a deblocking on the fragments.
4 -------------------------------------------------------------------------------
9 use ieee.std_logic_1164.
all;
10 use ieee.numeric_std.
all;
17 Reset_n
: in std_logic;
18 Enable
: in std_logic;
20 in_request
: out std_logic;
21 in_valid
: in std_logic;
22 in_data
: in signed
(31 downto 0);
24 in_sem_request
: out std_logic;
25 in_sem_valid
: in std_logic;
26 in_sem_addr
: out unsigned
(19 downto 0);
27 in_sem_data
: in signed
(31 downto 0);
29 out_sem_requested
: in std_logic;
30 out_sem_valid
: out std_logic;
31 out_sem_addr
: out unsigned
(19 downto 0);
32 out_sem_data
: out signed
(31 downto 0);
34 out_done
: out std_logic
38 architecture a_LoopFilter
of LoopFilter
is
41 DEPTH
: positive
:= 64; -- How many slots
42 DATA_WIDTH
: positive
:= 16; -- How many bits per slot
43 ADDR_WIDTH
: positive
:= 6 -- = ceil(log2(DEPTH))
48 wr_addr
: in unsigned
(ADDR_WIDTH
-1 downto 0);
49 wr_data
: in signed
(DATA_WIDTH
-1 downto 0);
50 rd_addr
: in unsigned
(ADDR_WIDTH
-1 downto 0);
51 rd_data
: out signed
(DATA_WIDTH
-1 downto 0)
55 component ReconPixelIndex
57 Reset_n
: in std_logic;
59 in_request
: out std_logic;
60 in_valid
: in std_logic;
61 in_data
: in signed
(31 downto 0);
63 out_requested
: in std_logic;
64 out_valid
: out std_logic;
65 out_data
: out signed
(31 downto 0)
71 parameter
: in unsigned
(8 downto 0);
72 FLimit
: in signed
(8 downto 0);
73 fbv_value
: out signed
(9 downto 0));
77 -- We are using 1024 as the maximum width and height size
78 -- = ceil(log2(Maximum Size))
79 constant LG_MAX_SIZE
: natural
:= 10;
80 constant MEM_ADDR_WIDTH
: natural
:= 20;
81 constant ZERO_ADDR_MEM
: unsigned
(LG_MAX_SIZE
*2 downto 0) := "
000000000000000000000"
;
83 -- This values must not be changed.
84 constant MEM_DATA_WIDTH
: natural
:= 32;
86 subtype ogg_int32_t
is signed
(31 downto 0);
87 subtype uchar_t
is unsigned
(7 downto 0);
89 type mem_64_8bits_t
is array (0 to 63) of uchar_t
;
91 -- Fragment Parameters
92 signal HFragments
: unsigned
(LG_MAX_SIZE
-3 downto 0);
93 signal VFragments
: unsigned
(LG_MAX_SIZE
-3 downto 0);
94 signal YStride
: unsigned
(LG_MAX_SIZE
+1 downto 0);
95 signal UVStride
: unsigned
(LG_MAX_SIZE
downto 0);
96 signal YPlaneFragments
: unsigned
(LG_MAX_SIZE
*2 downto 0);
97 signal UVPlaneFragments
: unsigned
(LG_MAX_SIZE
*2-2 downto 0);
98 signal ReconYDataOffset
: unsigned
(MEM_ADDR_WIDTH
-1 downto 0);
99 signal ReconUDataOffset
: unsigned
(MEM_ADDR_WIDTH
-1 downto 0);
100 signal ReconVDataOffset
: unsigned
(MEM_ADDR_WIDTH
-1 downto 0);
101 signal UnitFragmets
: unsigned
(LG_MAX_SIZE
*2 downto 0);
104 signal FLimit
: signed
(8 downto 0);
105 signal fbv_position
: unsigned
(8 downto 0);
106 signal fbv_value
: signed
(9 downto 0);
108 -- ReconPixelIndex signals and constants
109 constant RPI_DATA_WIDTH
: positive
:= 32;
110 constant RPI_POS_WIDTH
: positive
:= 17;
111 signal rpi_position
: unsigned
(RPI_POS_WIDTH
-1 downto 0);
112 signal rpi_value
: signed
(RPI_DATA_WIDTH
-1 downto 0);
114 signal s_rpi_in_request
: std_logic;
115 signal s_rpi_in_valid
: std_logic;
116 signal s_rpi_in_data
: signed
(31 downto 0);
118 signal s_rpi_out_requested
: std_logic;
119 signal s_rpi_out_valid
: std_logic;
120 signal s_rpi_out_data
: signed
(31 downto 0);
124 signal LoopFilterLimits
: mem_64_8bits_t
;
127 signal ThisFrameQualityValue
: signed
(31 downto 0);
129 signal QIndex
: unsigned
(5 downto 0);
130 signal pli
: unsigned
(1 downto 0);
132 signal FragsAcross
: unsigned
(LG_MAX_SIZE
-3 downto 0);
133 signal FragsDown
: unsigned
(LG_MAX_SIZE
-3 downto 0);
134 signal LineLength
: unsigned
(LG_MAX_SIZE
+1 downto 0);
135 signal LineFragments
: unsigned
(LG_MAX_SIZE
-3 downto 0);
136 signal Fragment
: unsigned
(LG_MAX_SIZE
*2 downto 0);
137 signal dpf_position
: unsigned
(LG_MAX_SIZE
*2 downto 0);
139 signal MaxDPFCount
: unsigned
(LG_MAX_SIZE
*2 downto 0);
141 signal pixelPtr
: unsigned
(MEM_ADDR_WIDTH
-1 downto 0);
142 signal DeltaHorizFilter
: signed
(3 downto 0);
144 signal CountFilter
: unsigned
(2 downto 0);
145 signal CountColumns
: unsigned
(2 downto 0);
147 signal disp_frag_value
: std_logic;
149 signal CountMiddles
: unsigned
(LG_MAX_SIZE
*2 downto 0);
150 signal CountMidCols
: unsigned
(LG_MAX_SIZE
*2 downto 0);
153 signal mem_rd_data
: signed
(31 downto 0);
154 signal mem_rd_valid
: std_logic;
155 signal mem_wr_ready
: std_logic;
158 type state_t
is (readIn
, proc
);
159 signal state
: state_t
;
161 type read_state_t
is (stt_qTT
, stt_lfLim
,
162 stt_dispFrag
, stt_Others
,
164 signal read_state
: read_state_t
;
167 type proc_state_t
is (stt_ReadMemory
, stt_WriteMemory
,
168 stt_FindQIndex
, stt_CalcFLimit
,
169 stt_SelectColor
, stt_ApplyFilter
,
171 stt_CallFilterHoriz
, stt_CalcFilterHoriz
,
172 stt_CallFilterVert
, stt_CalcFilterVert
,
174 signal proc_state
: proc_state_t
;
175 signal back_proc_state
: proc_state_t
;
176 signal next_proc_state
: proc_state_t
;
178 type calc_rpi_state_t
is (stt_calc_rpi1
, stt_calc_rpi2
);
179 signal calc_rpi_state
: calc_rpi_state_t
;
181 type set_bound_val_state_t
is (stt_SetBVal1
, stt_SetBVal2
, stt_SetBVal3
, stt_SetBVal4
);
182 signal set_bound_val_state
: set_bound_val_state_t
;
184 type calc_filter_state_t
is (stt_CalcFilter1
, stt_CalcFilter2
,
186 signal calc_filter_state
: calc_filter_state_t
;
189 type apply_filter_state_t
is (stt_ApplyFilter_1
, stt_ApplyFilter_2
,
190 stt_ApplyFilter_3
, stt_ApplyFilter_4
,
191 stt_ApplyFilter_5
, stt_ApplyFilter_6
,
192 stt_ApplyFilter_7
, stt_ApplyFilter_8
,
193 stt_ApplyFilter_9
, stt_ApplyFilter_10
,
194 stt_ApplyFilter_11
, stt_ApplyFilter_12
,
195 stt_ApplyFilter_13
, stt_ApplyFilter_14
,
196 stt_ApplyFilter_15
, stt_ApplyFilter_16
,
197 stt_ApplyFilter_17
, stt_ApplyFilter_18
,
198 stt_ApplyFilter_19
, stt_ApplyFilter_20
,
199 stt_ApplyFilter_21
, stt_ApplyFilter_22
,
200 stt_ApplyFilter_23
, stt_ApplyFilter_24
,
201 stt_ApplyFilter_25
, stt_ApplyFilter_26
,
202 stt_ApplyFilter_27
, stt_ApplyFilter_28
,
203 stt_ApplyFilter_29
, stt_ApplyFilter_30
,
204 stt_ApplyFilter_31
, stt_ApplyFilter_32
,
205 stt_ApplyFilter_33
, stt_ApplyFilter_34
);
206 signal apply_filter_state
: apply_filter_state_t
;
207 signal next_apply_filter_state
: apply_filter_state_t
;
210 type disp_frag_state_t
is (stt_DispFrag1
, stt_DispFrag2
,
211 stt_DispFrag3
, stt_DispFrag4
,
212 stt_DispFrag5
, stt_DispFrag6
,
213 stt_DispFrag7
, stt_DispFrag8
,
214 stt_DispFrag9
, stt_DispFrag10
,
215 stt_DispFrag11
, stt_DispFrag12
,
216 stt_DispFrag13
, stt_DispFrag14
,
217 stt_DispFrag15
, stt_DispFrag16
,
218 stt_DispFrag17
, stt_DispFrag18
,
219 stt_DispFrag19
, stt_DispFrag20
,
220 stt_DispFrag21
, stt_DispFrag22
);
222 signal disp_frag_state
: disp_frag_state_t
;
223 signal next_disp_frag_state
: disp_frag_state_t
;
225 type calc_disp_frag_state_t
is (stt_CalcDispFrag1
,
228 signal calc_disp_frag_state
: calc_disp_frag_state_t
;
231 signal count
: integer range 0 to 2097151;
233 signal s_in_request
: std_logic;
235 signal s_in_sem_request
: std_logic;
236 signal s_out_sem_valid
: std_logic;
237 signal s_out_done
: std_logic;
239 signal lfr_OffSet
: unsigned
(MEM_ADDR_WIDTH
-1 downto 0);
241 constant NULL_24bits
: signed
(23 downto 0) := "
000000000000000000000000"
;
242 constant NULL_32bits
: signed
(31 downto 0) := x"
00000000"
;
243 constant MAX_32bits
: signed
(31 downto 0) := x"
11111111"
;
245 constant QTT_DEPTH
: positive
:= 64;
246 constant QTT_DATA_WIDTH
: positive
:= 32;
247 constant QTT_ADDR_WIDTH
: positive
:= 6;
249 constant DPF_DEPTH
: positive
:= 57;
250 constant DPF_DATA_WIDTH
: positive
:= 32;
251 constant DPF_ADDR_WIDTH
: positive
:= 6;
254 signal qtt_wr_e
: std_logic;
255 signal qtt_wr_addr
: unsigned
(QTT_ADDR_WIDTH
-1 downto 0);
256 signal qtt_wr_data
: signed
(QTT_DATA_WIDTH
-1 downto 0);
257 signal qtt_rd_addr
: unsigned
(QTT_ADDR_WIDTH
-1 downto 0);
258 signal qtt_rd_data
: signed
(QTT_DATA_WIDTH
-1 downto 0);
260 type mem4bytes_t
is array (0 to 3) of uchar_t
;
261 signal Pixel
: mem4bytes_t
;
262 type lfr_array_2_t
is array (0 to 1) of ogg_int32_t
;
263 signal lfr_datas
: lfr_array_2_t
;
264 type lfr_pos_pixels_t
is array (0 to 1) of unsigned
(1 downto 0);
265 signal lfr_pos_pixels
: lfr_pos_pixels_t
;
267 signal dpf_wr_e
: std_logic;
268 signal dpf_wr_addr
: unsigned
(DPF_ADDR_WIDTH
-1 downto 0);
269 signal dpf_wr_data
: signed
(DPF_DATA_WIDTH
-1 downto 0);
270 signal dpf_rd_addr
: unsigned
(DPF_ADDR_WIDTH
-1 downto 0);
271 signal dpf_rd_data
: signed
(DPF_DATA_WIDTH
-1 downto 0);
274 -- signal T_Pixel1 : ogg_int32_t;
275 -- signal T_Pixel2 : ogg_int32_t;
277 -- signal applyfilter_states : integer;
278 -- signal dispfragstates_states : integer;
281 begin -- a_LoopFilter
283 in_request
<= s_in_request
;
284 in_sem_request
<= s_in_sem_request
;
285 out_sem_valid
<= s_out_sem_valid
;
286 out_done
<= s_out_done
;
288 mem_64_int32
: syncram
289 generic map (QTT_DEPTH
, QTT_DATA_WIDTH
, QTT_ADDR_WIDTH
)
290 port map (clk
, qtt_wr_e
, qtt_wr_addr
, qtt_wr_data
, qtt_rd_addr
, qtt_rd_data
);
292 mem_512_int32_1
: syncram
293 generic map (DPF_DEPTH
, DPF_DATA_WIDTH
, DPF_ADDR_WIDTH
)
294 port map (clk
, dpf_wr_e
, dpf_wr_addr
, dpf_wr_data
, dpf_rd_addr
, dpf_rd_data
);
297 port map (fbv_position
, FLimit
, fbv_value
);
299 rpi0
: reconpixelindex
300 port map (Clk
=> Clk
,
302 in_request
=> s_rpi_out_requested
,
303 in_valid
=> s_rpi_out_valid
,
304 in_data
=> s_rpi_out_data
,
306 out_requested
=> s_rpi_in_request
,
307 out_valid
=> s_rpi_in_valid
,
308 out_data
=> s_rpi_in_data
);
311 RPI_HandShake
: process (count
, in_data
, in_valid
,
312 state
, read_state
, proc_state
,
313 calc_rpi_state
, rpi_position
,
315 begin -- process RPI_HandShake
316 s_rpi_out_data
<= x"
00000000"
;
317 s_rpi_out_valid
<= '0';
318 if (s_in_request
= '1') then
319 if (state
= readIn
and read_state
= stt_32bitsData
) then
320 if (count
>=0 and count
<=8) then
321 s_rpi_out_data
<= in_data
;
322 s_rpi_out_valid
<= in_valid
;
327 proc_state
= stt_Calc_RPI_Value
and
328 calc_rpi_state
= stt_calc_rpi1
) then
329 s_rpi_out_data
<= resize
(signed
('0'&rpi_position), 32);
330 s_rpi_out_valid <= '1';
333 end process RPI_HandShake;
337 -------------------------------------------------------------------------------
338 -- Procedures called when state is readIn
339 -------------------------------------------------------------------------------
340 procedure Read32bitsData is
342 -- assert false report "in_data = "&integer'image(to_integer(in_data)) severity note;
344 HFragments <= unsigned(in_data(LG_MAX_SIZE-3 downto 0));
346 elsif (count = 1) then
347 YPlaneFragments <= unsigned(in_data(LG_MAX_SIZE*2 downto 0));
349 elsif (count = 2) then
350 YStride <= unsigned(in_data(LG_MAX_SIZE+1 downto 0));
352 elsif (count = 3) then
353 UVPlaneFragments <= unsigned(in_data(LG_MAX_SIZE*2-2 downto 0));
355 elsif (count = 4) then
356 UVStride <= unsigned(in_data(LG_MAX_SIZE downto 0));
358 elsif (count = 5) then
359 VFragments <= unsigned(in_data(LG_MAX_SIZE-3 downto 0));
361 elsif (count = 6) then
362 ReconYDataOffset <= unsigned(in_data(MEM_ADDR_WIDTH-1 downto 0));
364 elsif (count = 7) then
365 ReconUDataOffset <= unsigned(in_data(MEM_ADDR_WIDTH-1 downto 0));
367 elsif (count = 8) then
368 ReconVDataOffset <= unsigned(in_data(MEM_ADDR_WIDTH-1 downto 0));
371 assert false report "UnitFragments = "&integer'image(to_integer(in_data)) severity note;
372 UnitFragmets <= unsigned(in_data(LG_MAX_SIZE*2 downto 0));
374 MaxDPFCount <= SHIFT_RIGHT(
375 unsigned(in_data(LG_MAX_SIZE*2 downto 0)), 5) + 1;
376 if (in_data(4 downto 0) = "00000") then
377 MaxDPFCount <= SHIFT_RIGHT(
378 unsigned(in_data(LG_MAX_SIZE*2 downto 0)), 5);
380 read_state <= stt_qTT;
383 end procedure Read32bitsData;
385 -------------------------------------------------------------------------------
386 -- Procedure that receives the QThreashTable matrice and keep the data
388 -------------------------------------------------------------------------------
389 procedure QThreTab is
392 qtt_wr_data <= in_data;
393 qtt_wr_addr <= qtt_wr_addr + 1;
396 qtt_wr_addr <= "000000";
398 elsif (count = 63) then
399 read_state <= stt_lfLim;
401 -- on next state must set qtt_wr_e to 0
405 end procedure QThreTab;
407 -------------------------------------------------------------------------------
408 -- Procedure that receives the loop filter limits values and keep the data
409 -- in an internal memory
410 -------------------------------------------------------------------------------
415 LoopFilterLimits(count + 3) <= unsigned(in_data(7 downto 0));
416 LoopFilterLimits(count + 2) <= unsigned(in_data(15 downto 8));
417 LoopFilterLimits(count + 1) <= unsigned(in_data(23 downto 16));
418 LoopFilterLimits(count) <= unsigned(in_data(31 downto 24));
420 read_state <= stt_dispFrag;
427 -------------------------------------------------------------------------------
428 -- Procedure that receives the display fragments matrice and keep the data
430 -------------------------------------------------------------------------------
431 procedure DispFrag is
434 dpf_wr_data <= in_data;
435 dpf_wr_addr <= dpf_wr_addr + 1;
437 dpf_wr_addr <= "000000";
439 elsif (count = MaxDPFCount - 1) then
440 read_state <= stt_Others;
445 end procedure DispFrag;
447 -------------------------------------------------------------------------------
448 -- Procedure that receives the ThisFrameQualityValue and the Last Reconstructed
450 -------------------------------------------------------------------------------
451 procedure ReadOthers is
454 ThisFrameQualityValue <= in_data;
457 lfr_OffSet <= SHIFT_RIGHT(unsigned(in_data(MEM_ADDR_WIDTH-1 downto 0)), 2);
460 read_state <= stt_dispFrag;
461 proc_state <= stt_FindQIndex;
465 end procedure ReadOthers;
467 -------------------------------------------------------------------------------
468 -- Procedure that controls the read state machine
469 -------------------------------------------------------------------------------
475 s_out_sem_valid <= '0';
476 s_in_sem_request <= '0';
477 if (s_in_request = '1' and in_valid = '1') then
480 when stt_qTT => QThreTab;
481 when stt_lfLim => LfLim;
482 when stt_dispFrag => DispFrag;
483 when stt_Others => ReadOthers;
484 when others => Read32bitsData;
487 end procedure ReadIn;
489 -- *****************************************************
490 -- Procedures called when state is proc
491 -- *****************************************************
493 procedure ReadMemory is
495 -- After use the data mem_rd_valid must
497 mem_rd_valid <= in_sem_valid;
498 s_in_sem_request <= '1';
499 if (s_in_sem_request = '1' and in_sem_valid = '1') then
500 mem_rd_data <= in_sem_data;
501 s_in_sem_request <= '0';
502 proc_state <= back_proc_state;
504 end procedure ReadMemory;
506 procedure WriteMemory is
508 if (out_sem_requested = '1') then
509 proc_state <= back_proc_state;
511 s_out_sem_valid <= '0';
513 end procedure WriteMemory;
515 procedure CalcRPIValue is
517 case calc_rpi_state is
518 when stt_calc_rpi1 =>
519 -- Wait until ReconPixelIndex can receive the data
520 if (s_rpi_out_requested = '1') then
521 calc_rpi_state <= stt_calc_rpi2;
526 -- Wait until ReconPixelIndex returns the value
527 s_rpi_in_request <= '1';
528 if (s_rpi_in_request = '1' and s_rpi_in_valid = '1') then
529 rpi_value <= s_rpi_in_data;
530 s_rpi_in_request <= '0';
531 proc_state <= next_proc_state;
534 end procedure CalcRPIValue;
536 -------------------------------------------------------------------------------
537 -- Initialize QIndex with 63.
538 -- For each element i of qtt in decreasing order, if i >= ThisFrameQualityValue
539 -- then stop, else subtract one of the QIndex and read the i-1 element of qtt,
541 -------------------------------------------------------------------------------
542 procedure FindQIndex is
545 qtt_rd_addr <= QIndex;
547 elsif (count = 1) then
548 qtt_rd_addr <= QIndex - 1;
551 if ((QIndex = "000000") or
552 (qtt_rd_data >= ThisFrameQualityValue)) then
553 proc_state <= stt_CalcFLimit;
556 qtt_rd_addr <= QIndex - 2;
557 QIndex <= QIndex - 1;
561 end procedure FindQIndex;
563 -------------------------------------------------------------------------------
564 -- If LoopFilterLimits[QIndex] is not zero do the loopfiltering in the frame.
565 -- The next procedure is SelectColor
566 -------------------------------------------------------------------------------
567 procedure CalcFLimit is
569 if (LoopFilterLimits(to_integer(QIndex)) /= "00000000000000000000000000000000") then
570 proc_state <= stt_SelectColor;
571 FLimit <= '0' & signed(LoopFilterLimits(to_integer(QIndex)));
578 read_state <= stt_dispFrag;
579 proc_state <= stt_FindQIndex;
580 apply_filter_state <= stt_ApplyFilter_1;
581 calc_filter_state <= stt_CalcFilter1;
583 end procedure CalcFLimit;
585 -------------------------------------------------------------------------------
586 -- Adjust some parameters according the plane of color
587 -------------------------------------------------------------------------------
588 procedure SelectColor is
591 FragsAcross <= HFragments;
592 LineLength <= YStride;
593 LineFragments <= HFragments;
594 FragsDown <= VFragments;
595 Fragment <= "000000000000000000000";
596 proc_state <= stt_ApplyFilter;
597 disp_frag_state <= stt_DispFrag1;
600 elsif (pli = "01") then
602 FragsAcross <= SHIFT_RIGHT(HFragments, 1);
603 LineLength <= '0' & UVStride;
604 LineFragments <= SHIFT_RIGHT(HFragments, 1);
605 FragsDown <= SHIFT_RIGHT(VFragments, 1);
606 Fragment <= YPlaneFragments;
607 proc_state <= stt_ApplyFilter;
608 disp_frag_state <= stt_DispFrag1;
611 elsif (pli = "10") then
613 FragsAcross <= SHIFT_RIGHT(HFragments, 1);
614 LineLength <= '0' & UVStride;
615 LineFragments <= SHIFT_RIGHT(HFragments, 1);
616 FragsDown <= SHIFT_RIGHT(VFragments, 1);
617 Fragment <= YPlaneFragments + UVPlaneFragments;
618 proc_state <= stt_ApplyFilter;
619 disp_frag_state <= stt_DispFrag1;
622 assert false report "SelectColor 4" severity note;
628 read_state <= stt_dispFrag;
629 proc_state <= stt_FindQIndex;
630 apply_filter_state <= stt_ApplyFilter_1;
631 calc_filter_state <= stt_CalcFilter1;
633 end procedure SelectColor;
636 procedure CallFilterHoriz is
637 variable fourPixels : signed(MEM_DATA_WIDTH-1 downto 0);
638 variable memPosPixel : unsigned(1 downto 0);
639 variable numPixel : signed(RPI_DATA_WIDTH-1 downto 0);
642 numPixel := rpi_value +
644 ('0' & signed
(pixelPtr
) + count
);
645 memPosPixel
:= unsigned
(numPixel
(1 downto 0));
647 -- When use the data mem_rd_valid must
649 if (mem_rd_valid
= '0') then
650 s_in_sem_request
<= '1';
651 in_sem_addr
<= lfr_OffSet
+
653 SHIFT_RIGHT
('0' & unsigned(numPixel), 2)
656 back_proc_state <= stt_CallFilterHoriz;
657 proc_state <= stt_ReadMemory;
660 fourPixels := (SHIFT_RIGHT(
663 to_integer(memPosPixel) * 8));
664 Pixel(count) <= unsigned(fourPixels(7 downto 0));
666 if (count = 1 or count = 2) then
667 -- Saves the second or third pixel data slot and
668 -- their positions in the slot
669 lfr_datas(count - 1) <= mem_rd_data;
670 lfr_pos_pixels(count - 1) <= memPosPixel;
673 fbv_position <= resize(unsigned(
679 signed(Pixel(1))) * 3) +
681 signed(Pixel(2))) * 3) -
683 signed(fourPixels(7 downto 0))) + 4
687 proc_state <= stt_CalcFilterHoriz;
692 end procedure CallFilterHoriz;
694 procedure CalcFilterHoriz is
695 variable Pixel1 : ogg_int32_t;
696 variable Pixel2 : ogg_int32_t;
697 variable newPixel : uchar_t;
700 if (calc_filter_state = stt_CalcFilter1) then
702 Pixel1 := NULL_24bits &
703 signed(Pixel(1)) + fbv_value;
704 -- T_Pixel1 <= Pixel1;
706 out_sem_addr <= lfr_OffSet +
713 ('0' & signed
(pixelPtr
)) + 1)
718 if (Pixel1
< "
00000000000000000000000000000000"
) then
719 newPixel
:= "
00000000"
;
720 elsif (Pixel1
> "
00000000000000000000000011111111"
) then
721 newPixel
:= "
11111111"
;
723 newPixel
:= unsigned
(Pixel1
(7 downto 0));
726 case lfr_pos_pixels
(0) is
728 out_sem_data
<= signed
(newPixel
) &
729 lfr_datas
(0)(23 downto 0);
731 out_sem_data
<= lfr_datas
(0)(31 downto 24) &
733 lfr_datas
(0)(15 downto 0);
735 out_sem_data
<= lfr_datas
(0)(31 downto 16) &
737 lfr_datas
(0)(7 downto 0);
739 out_sem_data
<= lfr_datas
(0)(31 downto 8) &
743 s_out_sem_valid
<= '1';
744 calc_filter_state
<= stt_CalcFilter2
;
745 back_proc_state
<= stt_CalcFilterHoriz
;
746 proc_state
<= stt_WriteMemory
;
748 elsif (calc_filter_state
= stt_CalcFilter2
) then
749 Pixel2
:= NULL_24bits
&
750 signed
(Pixel
(2)) - fbv_value
;
752 -- T_Pixel2 <= Pixel2;
754 out_sem_addr
<= lfr_OffSet
+
761 ('0' & signed(pixelPtr)) + 2)
767 if (Pixel2 < "00000000000000000000000000000000") then
768 newPixel := "00000000";
769 elsif (Pixel2 > "00000000000000000000000011111111") then
770 newPixel := "11111111";
772 newPixel := unsigned(Pixel2(7 downto 0));
775 case lfr_pos_pixels(1) is
777 out_sem_data <= signed(newPixel) &
778 lfr_datas(1)(23 downto 0);
780 out_sem_data <= lfr_datas(1)(31 downto 24) &
782 lfr_datas(1)(15 downto 0);
784 out_sem_data <= lfr_datas(1)(31 downto 16) &
786 lfr_datas(1)(7 downto 0);
788 out_sem_data <= lfr_datas(1)(31 downto 8) &
792 s_out_sem_valid <= '1';
793 calc_filter_state <= stt_CalcFilter3;
794 back_proc_state <= stt_CalcFilterHoriz;
795 proc_state <= stt_WriteMemory;
799 if (CountFilter = "111") then
800 proc_state <= stt_ApplyFilter;
801 apply_filter_state <= next_apply_filter_state; -- Next state
802 pixelPtr <= "00000000000000000000";
803 CountFilter <= "000";
805 pixelPtr <= pixelPtr + LineLength; -- Next Row
806 proc_state <= stt_CallFilterHoriz;
807 CountFilter <= CountFilter + 1;
809 calc_filter_state <= stt_CalcFilter1;
811 end procedure CalcFilterHoriz;
814 procedure CallFilterVert is
815 variable fourPixels : signed(MEM_DATA_WIDTH-1 downto 0);
816 variable memPosPixel : unsigned(1 downto 0);
817 variable numPixel : signed(RPI_DATA_WIDTH-1 downto 0);
818 variable posLine : signed(2 downto 0);
822 elsif (count = 1) then
824 elsif (count = 2) then
830 numPixel := rpi_value +
831 (signed('0' & LineLength
)*posLine
) +
832 ('0' & signed(CountColumns));
833 memPosPixel := unsigned(numPixel(1 downto 0));
835 -- When use the data mem_rd_valid must
838 if (mem_rd_valid = '0') then
839 s_in_sem_request <= '1';
840 in_sem_addr <= lfr_OffSet +
842 SHIFT_RIGHT('0' & unsigned
(numPixel
), 2)
846 if (to_integer
(lfr_OffSet
+
848 SHIFT_RIGHT
('0' & unsigned(numPixel), 2)
854 back_proc_state <= stt_CallFilterVert;
855 proc_state <= stt_ReadMemory;
860 fourPixels := (SHIFT_RIGHT(
863 to_integer(memPosPixel) * 8));
865 Pixel(count) <= unsigned(fourPixels(7 downto 0));
867 if (count = 1 or count = 2) then
868 -- Saves the second or third pixel data slot and
869 -- their positions in the slot
870 lfr_datas(count - 1) <= mem_rd_data;
871 lfr_pos_pixels(count - 1) <= memPosPixel;
874 fbv_position <= resize(unsigned(
880 signed(Pixel(1))) * 3) +
882 signed(Pixel(2))) * 3) -
884 signed(fourPixels(7 downto 0))) + 4
887 proc_state <= stt_CalcFilterVert;
892 end procedure CallFilterVert;
894 procedure CalcFilterVert is
895 variable Pixel1 : ogg_int32_t;
896 variable Pixel2 : ogg_int32_t;
897 variable newPixel : uchar_t;
901 if (calc_filter_state = stt_CalcFilter1) then
903 Pixel1 := (NULL_24bits &
904 signed(Pixel(1))) + fbv_value;
905 -- T_Pixel1 <= Pixel1;
906 out_sem_addr <= lfr_OffSet +
912 ('0' & signed
(LineLength
)) +
913 ('0' & signed(CountColumns)))
918 if (Pixel1 < "00000000000000000000000000000000") then
919 newPixel := "00000000";
920 elsif (Pixel1 > "00000000000000000000000011111111") then
921 newPixel := "11111111";
923 newPixel := unsigned(Pixel1(7 downto 0));
926 case lfr_pos_pixels(0) is
928 out_sem_data <= signed(newPixel) &
929 lfr_datas(0)(23 downto 0);
931 out_sem_data <= lfr_datas(0)(31 downto 24) &
933 lfr_datas(0)(15 downto 0);
935 out_sem_data <= lfr_datas(0)(31 downto 16) &
937 lfr_datas(0)(7 downto 0);
939 out_sem_data <= lfr_datas(0)(31 downto 8) &
943 s_out_sem_valid <= '1';
944 calc_filter_state <= stt_CalcFilter2;
945 back_proc_state <= stt_CalcFilterVert;
946 proc_state <= stt_WriteMemory;
948 elsif (calc_filter_state = stt_CalcFilter2) then
950 Pixel2 := (NULL_24bits &
951 signed(Pixel(2))) - fbv_value;
952 -- T_Pixel2 <= Pixel2;
954 out_sem_addr <= lfr_OffSet +
960 ('0' & signed
(CountColumns
)))
965 if (Pixel2
< "
00000000000000000000000000000000"
) then
966 newPixel
:= "
00000000"
;
967 elsif (Pixel2
> "
00000000000000000000000011111111"
) then
968 newPixel
:= "
11111111"
;
970 newPixel
:= unsigned
(Pixel2
(7 downto 0));
973 case lfr_pos_pixels
(1) is
975 out_sem_data
<= signed
(newPixel
) &
976 lfr_datas
(1)(23 downto 0);
978 out_sem_data
<= lfr_datas
(1)(31 downto 24) &
980 lfr_datas
(1)(15 downto 0);
982 out_sem_data
<= lfr_datas
(1)(31 downto 16) &
984 lfr_datas
(1)(7 downto 0);
986 out_sem_data
<= lfr_datas
(1)(31 downto 8) &
990 s_out_sem_valid
<= '1';
991 calc_filter_state
<= stt_CalcFilter3
;
992 back_proc_state
<= stt_CalcFilterVert
;
993 proc_state
<= stt_WriteMemory
;
997 if (CountFilter
= "
111"
) then
998 proc_state
<= stt_ApplyFilter
;
999 apply_filter_state
<= next_apply_filter_state
; -- Next state
1000 CountFilter
<= "
000"
;
1001 CountColumns
<= "
000"
;
1003 CountColumns
<= CountColumns
+ 1;
1004 proc_state
<= stt_CallFilterVert
;
1005 CountFilter
<= CountFilter
+ 1;
1007 calc_filter_state
<= stt_CalcFilter1
;
1009 end procedure CalcFilterVert
;
1012 procedure CalcDispFragPos
is
1014 if (calc_disp_frag_state
= stt_CalcDispFrag1
) then
1015 -- Wait display_fragments memory
1016 calc_disp_frag_state
<= stt_CalcDispFrag2
;
1019 disp_frag_value
<= dpf_rd_data
(31 - to_integer
(dpf_position
(4 downto 0)));
1020 calc_disp_frag_state
<= stt_CalcDispFrag1
;
1021 proc_state
<= stt_ApplyFilter
;
1022 apply_filter_state
<= next_apply_filter_state
; -- Next state
1023 disp_frag_state
<= next_disp_frag_state
;
1025 end procedure CalcDispFragPos
;
1028 procedure ApplyFilter
is
1029 variable NextFragment
: unsigned
(LG_MAX_SIZE
*2 downto 0);
1032 if (apply_filter_state
= stt_ApplyFilter_1
) then
1033 -- applyfilter_states <= 1;
1034 -- ******************************************************
1036 -- ******************************************************
1037 -- First column coditions
1038 -- only do 2 prediction if fragment coded and on non intra
1039 -- or if all fragments are intra
1040 if (disp_frag_state
= stt_DispFrag1
) then
1041 -- dispfragstates_states <= 1;
1042 -- dpf_rd_addr <= resize(SHIFT_RIGHT(Fragment,5), DPF_ADDR_WIDTH);
1043 dpf_rd_addr
<= Fragment
((4+DPF_ADDR_WIDTH
) downto 5);
1044 dpf_position
<= Fragment
;
1045 proc_state
<= stt_CalcDispFragPos
;
1046 next_apply_filter_state
<= stt_ApplyFilter_1
;
1047 next_disp_frag_state
<= stt_DispFrag2
;
1049 if (disp_frag_value
= '1') then
1050 apply_filter_state
<= stt_ApplyFilter_34
;
1052 apply_filter_state
<= stt_ApplyFilter_3
;
1056 elsif (apply_filter_state
= stt_ApplyFilter_34
) then
1057 -- applyfilter_states <= 34;
1058 -- Filter right hand border only if the block to the right
1060 if (disp_frag_state
= stt_DispFrag2
) then
1061 -- dispfragstates_states <= 2;
1062 NextFragment
:= Fragment
+ 1;
1063 dpf_rd_addr
<= NextFragment
((4+DPF_ADDR_WIDTH
) downto 5);
1064 dpf_position
<= Fragment
+ 1;
1065 proc_state
<= stt_CalcDispFragPos
;
1066 next_apply_filter_state
<= stt_ApplyFilter_34
;
1067 next_disp_frag_state
<= stt_DispFrag3
;
1069 if (disp_frag_value
= '0') then
1070 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1071 -- Horizontal Filter Parameter
1072 DeltaHorizFilter
<= x"
6"
;
1074 -- Calculate RPI_Value before continue
1075 proc_state
<= stt_Calc_RPI_Value
;
1076 calc_rpi_state
<= stt_calc_rpi1
;
1077 -- Next state after RPI_Value calculation
1078 next_proc_state
<= stt_CallFilterHoriz
;
1079 next_apply_filter_state
<= stt_ApplyFilter_2
;
1081 apply_filter_state
<= stt_ApplyFilter_2
;
1085 elsif (apply_filter_state
= stt_ApplyFilter_2
) then
1086 -- applyfilter_states <= 2;
1087 -- Bottom done if next row set
1088 if (disp_frag_state
= stt_DispFrag3
) then
1089 NextFragment
:= Fragment
+ LineFragments
;
1090 dpf_rd_addr
<= NextFragment
((4+DPF_ADDR_WIDTH
) downto 5);
1091 dpf_position
<= Fragment
+ LineFragments
;
1092 proc_state
<= stt_CalcDispFragPos
;
1093 next_apply_filter_state
<= stt_ApplyFilter_2
;
1094 next_disp_frag_state
<= stt_DispFrag4
;
1096 if (disp_frag_value
= '0') then
1097 rpi_position
<= resize
(Fragment
+ LineFragments
, RPI_POS_WIDTH
);
1099 -- Calculate RPI_Value before continue
1100 proc_state
<= stt_Calc_RPI_Value
;
1101 calc_rpi_state
<= stt_calc_rpi1
;
1102 -- Next state after RPI_Value calculation
1103 next_proc_state
<= stt_CallFilterVert
;
1104 next_apply_filter_state
<= stt_ApplyFilter_3
;
1106 apply_filter_state
<= stt_ApplyFilter_3
;
1110 elsif (apply_filter_state
= stt_ApplyFilter_3
) then
1111 -- applyfilter_states <= 3;
1112 Fragment
<= Fragment
+ 1;
1113 CountMiddles
<= '0' & x"
00001"
;
1114 apply_filter_state
<= stt_ApplyFilter_4
;
1115 disp_frag_state
<= stt_DispFrag4
;
1117 elsif (apply_filter_state
= stt_ApplyFilter_4
) then
1119 if (CountMiddles
< FragsAcross
- 1) then
1123 if (disp_frag_state
= stt_DispFrag4
) then
1124 dpf_rd_addr
<= Fragment
((4+DPF_ADDR_WIDTH
) downto 5);
1125 dpf_position
<= Fragment
;
1126 proc_state
<= stt_CalcDispFragPos
;
1127 next_apply_filter_state
<= stt_ApplyFilter_4
;
1128 next_disp_frag_state
<= stt_DispFrag5
;
1132 if (disp_frag_value
= '1') then
1133 -- Filter Left edge always
1134 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1135 -- Horizontal Filter Parameter
1136 DeltaHorizFilter
<= x"E"
;
1138 -- Calculate RPI_Value before continue
1139 proc_state
<= stt_Calc_RPI_Value
;
1140 calc_rpi_state
<= stt_calc_rpi1
;
1141 -- Next state after RPI_Value calculation
1142 next_proc_state
<= stt_CallFilterHoriz
;
1144 next_apply_filter_state
<= stt_ApplyFilter_5
;
1146 apply_filter_state
<= stt_ApplyFilter_7
; -- Increment CountMiddles
1150 apply_filter_state
<= stt_ApplyFilter_8
;
1151 disp_frag_state
<= stt_DispFrag7
;
1156 elsif (apply_filter_state
= stt_ApplyFilter_5
) then
1158 -- Enter here only if (CountMiddles < FragsAcross - 1) is true
1159 -- and display_fragments(Fragment) is not zero
1160 if (disp_frag_state
= stt_DispFrag5
) then
1161 NextFragment
:= Fragment
+ 1;
1162 dpf_rd_addr
<= NextFragment
((4+DPF_ADDR_WIDTH
) downto 5);
1164 dpf_position
<= Fragment
+ 1;
1165 proc_state
<= stt_CalcDispFragPos
;
1166 next_apply_filter_state
<= stt_ApplyFilter_5
;
1167 next_disp_frag_state
<= stt_DispFrag6
;
1171 if (disp_frag_value
= '0') then
1173 -- Filter right hand border only if the block to the right is
1175 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1176 -- Horizontal Filter Parameter
1177 DeltaHorizFilter
<= x"
6"
;
1179 -- Calculate RPI_Value before continue
1180 proc_state
<= stt_Calc_RPI_Value
;
1181 calc_rpi_state
<= stt_calc_rpi1
;
1182 -- Next state after RPI_Value calculation
1183 next_proc_state
<= stt_CallFilterHoriz
;
1184 next_apply_filter_state
<= stt_ApplyFilter_6
;
1187 apply_filter_state
<= stt_ApplyFilter_6
;
1191 elsif (apply_filter_state
= stt_ApplyFilter_6
) then
1193 -- Enter here only if (CountMiddles < FragsAcross - 1) is true
1194 -- and display_fragments(Fragment) is not zero
1195 if (disp_frag_state
= stt_DispFrag6
) then
1196 NextFragment
:= Fragment
+ LineFragments
;
1197 dpf_rd_addr
<= NextFragment
((4+DPF_ADDR_WIDTH
) downto 5);
1199 dpf_position
<= Fragment
+ LineFragments
;
1200 proc_state
<= stt_CalcDispFragPos
;
1201 next_apply_filter_state
<= stt_ApplyFilter_6
;
1202 next_disp_frag_state
<= stt_DispFrag7
;
1206 if (disp_frag_value
= '0') then
1208 -- Bottom done if next row set
1209 rpi_position
<= resize
(Fragment
+ LineFragments
, RPI_POS_WIDTH
);
1211 -- Calculate RPI_Value before continue
1212 proc_state
<= stt_Calc_RPI_Value
;
1213 calc_rpi_state
<= stt_calc_rpi1
;
1214 -- Next state after RPI_Value calculation
1215 next_proc_state
<= stt_CallFilterVert
;
1216 next_apply_filter_state
<= stt_ApplyFilter_7
;
1218 apply_filter_state
<= stt_ApplyFilter_7
;
1222 elsif (apply_filter_state
= stt_ApplyFilter_7
) then
1224 CountMiddles
<= CountMiddles
+ 1;
1225 Fragment
<= Fragment
+ 1;
1226 apply_filter_state
<= stt_ApplyFilter_4
;
1227 disp_frag_state
<= stt_DispFrag4
;
1230 elsif (apply_filter_state
= stt_ApplyFilter_8
) then
1232 -- ******************************************************
1234 -- ******************************************************
1235 if (disp_frag_state
= stt_DispFrag7
) then
1236 dpf_rd_addr
<= Fragment
((4+DPF_ADDR_WIDTH
) downto 5);
1238 dpf_position
<= Fragment
;
1239 proc_state
<= stt_CalcDispFragPos
;
1240 next_apply_filter_state
<= stt_ApplyFilter_8
;
1241 next_disp_frag_state
<= stt_DispFrag8
;
1245 if (disp_frag_value
= '1') then
1246 -- Filter Left edge always
1247 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1248 -- Horizontal Filter Parameter
1249 DeltaHorizFilter
<= x"E"
;
1251 -- Calculate RPI_Value before continue
1252 proc_state
<= stt_Calc_RPI_Value
;
1253 calc_rpi_state
<= stt_calc_rpi1
;
1254 -- Next state after RPI_Value calculation
1255 next_proc_state
<= stt_CallFilterHoriz
;
1256 next_apply_filter_state
<= stt_ApplyFilter_9
;
1258 apply_filter_state
<= stt_ApplyFilter_10
;
1262 elsif (apply_filter_state
= stt_ApplyFilter_9
) then
1264 if (disp_frag_state
= stt_DispFrag8
) then
1265 NextFragment
:= Fragment
+ LineFragments
;
1266 dpf_rd_addr
<= NextFragment
((4+DPF_ADDR_WIDTH
) downto 5);
1268 dpf_position
<= Fragment
+ LineFragments
;
1269 proc_state
<= stt_CalcDispFragPos
;
1270 next_apply_filter_state
<= stt_ApplyFilter_9
;
1271 next_disp_frag_state
<= stt_DispFrag9
;
1274 if (disp_frag_value
= '0') then
1275 -- Bottom done if next row set
1276 rpi_position
<= resize
(Fragment
+ LineFragments
, RPI_POS_WIDTH
);
1278 -- Calculate RPI_Value before continue
1279 proc_state
<= stt_Calc_RPI_Value
;
1280 calc_rpi_state
<= stt_calc_rpi1
;
1281 -- Next state after RPI_Value calculation
1282 next_proc_state
<= stt_CallFilterVert
;
1283 next_apply_filter_state
<= stt_ApplyFilter_10
;
1285 apply_filter_state
<= stt_ApplyFilter_10
;
1289 elsif (apply_filter_state
= stt_ApplyFilter_10
) then
1291 Fragment
<= Fragment
+ 1;
1292 CountMiddles
<= '0' & x"
00001"
;
1293 apply_filter_state
<= stt_ApplyFilter_11
;
1294 disp_frag_state
<= stt_DispFrag9
;
1296 elsif (apply_filter_state
= stt_ApplyFilter_11
) then
1299 -- ******************************************************
1301 -- ******************************************************
1302 if (CountMiddles
< FragsDown
- 1) then
1303 -- first column conditions
1304 -- only do 2 prediction if fragment coded and on non intra or if
1305 -- all fragments are intra */
1306 if (disp_frag_state
= stt_DispFrag9
) then
1307 dpf_rd_addr
<= Fragment
((4+DPF_ADDR_WIDTH
) downto 5);
1309 dpf_position
<= Fragment
;
1310 proc_state
<= stt_CalcDispFragPos
;
1311 next_apply_filter_state
<= stt_ApplyFilter_11
;
1312 next_disp_frag_state
<= stt_DispFrag10
;
1314 if (disp_frag_value
= '1') then
1315 -- TopRow is always done
1316 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1318 -- Calculate RPI_Value before continue
1319 proc_state
<= stt_Calc_RPI_Value
;
1320 calc_rpi_state
<= stt_calc_rpi1
;
1321 -- Next state after RPI_Value calculation
1322 next_proc_state
<= stt_CallFilterVert
;
1323 next_apply_filter_state
<= stt_ApplyFilter_12
;
1325 apply_filter_state
<= stt_ApplyFilter_14
; -- Do middle columns
1329 apply_filter_state
<= stt_ApplyFilter_24
; -- End "Loop"
1330 disp_frag_state
<= stt_DispFrag17
;
1334 elsif (apply_filter_state
= stt_ApplyFilter_12
) then
1336 -- Enter here only if (CountMiddles < FragsDown - 1) is true
1337 -- and display_fragments(Fragment) is not zero
1338 if (disp_frag_state
= stt_DispFrag10
) then
1339 NextFragment
:= Fragment
+ 1;
1340 dpf_rd_addr
<= NextFragment
((4+DPF_ADDR_WIDTH
) downto 5);
1342 dpf_position
<= Fragment
+ 1;
1343 proc_state
<= stt_CalcDispFragPos
;
1344 next_apply_filter_state
<= stt_ApplyFilter_12
;
1345 next_disp_frag_state
<= stt_DispFrag11
;
1348 if (disp_frag_value
= '0') then
1349 -- Filter right hand border only if the block to the right is
1351 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1352 -- Horizontal Filter Parameter
1353 DeltaHorizFilter
<= x"
6"
;
1355 -- Calculate RPI_Value before continue
1356 proc_state
<= stt_Calc_RPI_Value
;
1357 calc_rpi_state
<= stt_calc_rpi1
;
1358 -- Next state after RPI_Value calculation
1359 next_proc_state
<= stt_CallFilterHoriz
;
1360 next_apply_filter_state
<= stt_ApplyFilter_13
;
1362 apply_filter_state
<= stt_ApplyFilter_13
;
1366 elsif (apply_filter_state
= stt_ApplyFilter_13
) then
1368 -- Enter here only if (CountMiddles < FragsDown - 1) is true
1369 -- and display_fragments(Fragment) is not zero
1370 if (disp_frag_state
= stt_DispFrag11
) then
1371 NextFragment
:= Fragment
+ LineFragments
;
1372 dpf_rd_addr
<= NextFragment
((4+DPF_ADDR_WIDTH
) downto 5);
1374 dpf_position
<= Fragment
+ LineFragments
;
1375 proc_state
<= stt_CalcDispFragPos
;
1376 next_apply_filter_state
<= stt_ApplyFilter_13
;
1377 next_disp_frag_state
<= stt_DispFrag12
;
1380 if (disp_frag_value
= '0') then
1381 -- Bottom done if next row set
1382 rpi_position
<= resize
(Fragment
+ LineFragments
, RPI_POS_WIDTH
);
1384 -- Calculate RPI_Value before continue
1385 proc_state
<= stt_Calc_RPI_Value
;
1386 calc_rpi_state
<= stt_calc_rpi1
;
1387 -- Next state after RPI_Value calculation
1388 next_proc_state
<= stt_CallFilterVert
;
1389 next_apply_filter_state
<= stt_ApplyFilter_14
;
1391 apply_filter_state
<= stt_ApplyFilter_14
;
1396 elsif (apply_filter_state
= stt_ApplyFilter_14
) then
1398 Fragment
<= Fragment
+ 1; -- Increment position
1399 CountMidCols
<= '0' & x"
00001"
; -- Initialize Counter
1400 apply_filter_state
<= stt_ApplyFilter_15
;
1401 disp_frag_state
<= stt_DispFrag12
;
1403 elsif (apply_filter_state
= stt_ApplyFilter_15
) then
1405 -- ******************************************************
1406 -- Middle Columns inside Middle Rows
1407 -- ******************************************************
1408 if (CountMidCols
< FragsAcross
- 1) then
1410 if (disp_frag_state
= stt_DispFrag12
) then
1411 dpf_rd_addr
<= Fragment
((4+DPF_ADDR_WIDTH
) downto 5);
1413 dpf_position
<= Fragment
;
1414 proc_state
<= stt_CalcDispFragPos
;
1415 next_apply_filter_state
<= stt_ApplyFilter_15
;
1416 next_disp_frag_state
<= stt_DispFrag13
;
1418 if (disp_frag_value
= '1') then
1419 -- Filter Left edge always
1420 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1421 -- Horizontal Filter Parameter
1422 DeltaHorizFilter
<= x"E"
;
1424 -- Calculate RPI_Value before continue
1425 proc_state
<= stt_Calc_RPI_Value
;
1426 calc_rpi_state
<= stt_calc_rpi1
;
1427 -- Next state after RPI_Value calculation
1428 next_proc_state
<= stt_CallFilterHoriz
;
1429 next_apply_filter_state
<= stt_ApplyFilter_16
;
1431 apply_filter_state
<= stt_ApplyFilter_19
; -- Increment CountMidCols
1436 apply_filter_state
<= stt_ApplyFilter_20
; -- End "Loop" and
1438 disp_frag_state
<= stt_DispFrag15
;
1442 elsif (apply_filter_state
= stt_ApplyFilter_16
) then
1444 -- Enter here only if (CountMidCols < FragsAcross - 1) is true
1445 -- and display_fragments(Fragment) is not zero
1447 -- TopRow is always done
1448 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1450 -- Calculate RPI_Value before continue
1451 proc_state
<= stt_Calc_RPI_Value
;
1452 calc_rpi_state
<= stt_calc_rpi1
;
1453 -- Next state after RPI_Value calculation
1454 next_proc_state
<= stt_CallFilterVert
;
1455 next_apply_filter_state
<= stt_ApplyFilter_17
;
1458 elsif (apply_filter_state
= stt_ApplyFilter_17
) then
1460 -- Enter here only if (CountMidCols < FragsAcross - 1) is true
1461 -- and display_fragments(Fragment) is not zero
1463 -- Filter right hand border only if the block to the right
1465 if (disp_frag_state
= stt_DispFrag13
) then
1466 NextFragment
:= Fragment
+ 1;
1467 dpf_rd_addr
<= NextFragment
((4+DPF_ADDR_WIDTH
) downto 5);
1469 dpf_position
<= Fragment
+ 1;
1470 proc_state
<= stt_CalcDispFragPos
;
1471 next_apply_filter_state
<= stt_ApplyFilter_17
;
1472 next_disp_frag_state
<= stt_DispFrag14
;
1474 if (disp_frag_value
= '0') then
1475 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1476 -- Horizontal Filter Parameter
1477 DeltaHorizFilter
<= x"
6"
;
1479 -- Calculate RPI_Value before continue
1480 proc_state
<= stt_Calc_RPI_Value
;
1481 calc_rpi_state
<= stt_calc_rpi1
;
1482 -- Next state after RPI_Value calculation
1483 next_proc_state
<= stt_CallFilterHoriz
;
1484 next_apply_filter_state
<= stt_ApplyFilter_18
;
1486 apply_filter_state
<= stt_ApplyFilter_18
;
1490 elsif (apply_filter_state
= stt_ApplyFilter_18
) then
1492 -- Enter here only if (CountMidCols < FragsAcross - 1) is true
1493 -- and display_fragments(Fragment) is not zero
1495 -- Bottom done if next row set
1496 if (disp_frag_state
= stt_DispFrag14
) then
1497 NextFragment
:= Fragment
+ LineFragments
;
1498 dpf_rd_addr
<= NextFragment
((4+DPF_ADDR_WIDTH
) downto 5);
1500 dpf_position
<= Fragment
+ LineFragments
;
1501 proc_state
<= stt_CalcDispFragPos
;
1502 next_apply_filter_state
<= stt_ApplyFilter_18
;
1503 next_disp_frag_state
<= stt_DispFrag15
;
1505 if (disp_frag_value
= '0') then
1506 rpi_position
<= resize
(Fragment
+ LineFragments
, RPI_POS_WIDTH
);
1508 -- Calculate RPI_Value before continue
1509 proc_state
<= stt_Calc_RPI_Value
;
1510 calc_rpi_state
<= stt_calc_rpi1
;
1511 -- Next state after RPI_Value calculation
1512 next_proc_state
<= stt_CallFilterVert
;
1513 next_apply_filter_state
<= stt_ApplyFilter_19
;
1515 apply_filter_state
<= stt_ApplyFilter_19
;
1519 elsif (apply_filter_state
= stt_ApplyFilter_19
) then
1521 CountMidCols
<= CountMidCols
+ 1;
1522 Fragment
<= Fragment
+ 1;
1523 apply_filter_state
<= stt_ApplyFilter_15
;
1524 disp_frag_state
<= stt_DispFrag12
;
1526 elsif (apply_filter_state
= stt_ApplyFilter_20
) then
1530 if (disp_frag_state
= stt_DispFrag15
) then
1531 dpf_rd_addr
<= Fragment
((4+DPF_ADDR_WIDTH
) downto 5);
1533 dpf_position
<= Fragment
;
1534 proc_state
<= stt_CalcDispFragPos
;
1535 next_apply_filter_state
<= stt_ApplyFilter_20
;
1536 next_disp_frag_state
<= stt_DispFrag16
;
1538 if (disp_frag_value
= '1') then
1539 -- Filter Left edge always
1540 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1541 -- Horizontal Filter Parameter
1542 DeltaHorizFilter
<= x"E"
;
1544 -- Calculate RPI_Value before continue
1545 proc_state
<= stt_Calc_RPI_Value
;
1546 calc_rpi_state
<= stt_calc_rpi1
;
1547 -- Next state after RPI_Value calculation
1548 next_proc_state
<= stt_CallFilterHoriz
;
1549 next_apply_filter_state
<= stt_ApplyFilter_21
;
1551 apply_filter_state
<= stt_ApplyFilter_23
;
1555 elsif (apply_filter_state
= stt_ApplyFilter_21
) then
1557 -- Enter here only if display_fragments(Fragment) not zero
1559 -- TopRow is always done
1560 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1562 -- Calculate RPI_Value before continue
1563 proc_state
<= stt_Calc_RPI_Value
;
1564 calc_rpi_state
<= stt_calc_rpi1
;
1565 -- Next state after RPI_Value calculation
1566 next_proc_state
<= stt_CallFilterVert
;
1567 next_apply_filter_state
<= stt_ApplyFilter_22
;
1570 elsif (apply_filter_state
= stt_ApplyFilter_22
) then
1571 -- Enter here only if display_fragments(Fragment) not zero
1574 -- Bottom done if next row set
1575 if (disp_frag_state
= stt_DispFrag16
) then
1576 NextFragment
:= Fragment
+ LineFragments
;
1577 dpf_rd_addr
<= NextFragment
((4+DPF_ADDR_WIDTH
) downto 5);
1579 dpf_position
<= Fragment
+ LineFragments
;
1580 proc_state
<= stt_CalcDispFragPos
;
1581 next_apply_filter_state
<= stt_ApplyFilter_22
;
1582 next_disp_frag_state
<= stt_DispFrag17
;
1585 if (disp_frag_value
= '0') then
1586 rpi_position
<= resize
(Fragment
+ LineFragments
, RPI_POS_WIDTH
);
1588 -- Calculate RPI_Value before continue
1589 proc_state
<= stt_Calc_RPI_Value
;
1590 calc_rpi_state
<= stt_calc_rpi1
;
1591 -- Next state after RPI_Value calculation
1592 next_proc_state
<= stt_CallFilterVert
;
1593 next_apply_filter_state
<= stt_ApplyFilter_23
;
1595 apply_filter_state
<= stt_ApplyFilter_23
;
1599 elsif (apply_filter_state
= stt_ApplyFilter_23
) then
1601 Fragment
<= Fragment
+ 1;
1602 CountMiddles
<= CountMiddles
+ 1;
1603 apply_filter_state
<= stt_ApplyFilter_11
;
1604 disp_frag_state
<= stt_DispFrag9
;
1606 elsif (apply_filter_state
= stt_ApplyFilter_24
) then
1608 -- ******************************************************
1610 -- ******************************************************
1612 -- First column conditions
1613 -- Only do 2 prediction if fragment coded and on non intra or if
1614 -- all fragments are intra */
1615 if (disp_frag_state
= stt_DispFrag17
) then
1616 dpf_rd_addr
<= Fragment
((4+DPF_ADDR_WIDTH
) downto 5);
1617 dpf_position
<= Fragment
;
1618 proc_state
<= stt_CalcDispFragPos
;
1619 next_apply_filter_state
<= stt_ApplyFilter_24
;
1620 next_disp_frag_state
<= stt_DispFrag18
;
1623 if (disp_frag_value
= '1') then
1624 -- TopRow is always done
1625 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1627 -- Calculate RPI_Value before continue
1628 proc_state
<= stt_Calc_RPI_Value
;
1629 calc_rpi_state
<= stt_calc_rpi1
;
1630 -- Next state after RPI_Value calculation
1631 next_proc_state
<= stt_CallFilterVert
;
1632 next_apply_filter_state
<= stt_ApplyFilter_25
;
1634 apply_filter_state
<= stt_ApplyFilter_26
;
1637 elsif (apply_filter_state
= stt_ApplyFilter_25
) then
1639 -- Enter here only if display_fragments(Fragment) is not zero
1641 -- Filter right hand border only if the block to the right
1643 if (disp_frag_state
= stt_DispFrag18
) then
1644 NextFragment
:= Fragment
+ 1;
1645 dpf_rd_addr
<= NextFragment
((4+DPF_ADDR_WIDTH
) downto 5);
1647 dpf_position
<= Fragment
+ 1;
1648 proc_state
<= stt_CalcDispFragPos
;
1649 next_apply_filter_state
<= stt_ApplyFilter_25
;
1650 next_disp_frag_state
<= stt_DispFrag19
;
1653 if (disp_frag_value
= '0') then
1654 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1655 -- Horizontal Filter Parameter
1656 DeltaHorizFilter
<= x"
6"
;
1658 -- Calculate RPI_Value before continue
1659 proc_state
<= stt_Calc_RPI_Value
;
1660 calc_rpi_state
<= stt_calc_rpi1
;
1661 -- Next state after RPI_Value calculation
1662 next_proc_state
<= stt_CallFilterHoriz
;
1663 next_apply_filter_state
<= stt_ApplyFilter_26
;
1665 apply_filter_state
<= stt_ApplyFilter_26
;
1669 elsif (apply_filter_state
= stt_ApplyFilter_26
) then
1671 Fragment
<= Fragment
+ 1;
1672 CountMiddles
<= '0' & x"
00001"
;
1673 apply_filter_state
<= stt_ApplyFilter_27
;
1674 disp_frag_state
<= stt_DispFrag19
;
1676 elsif (apply_filter_state
= stt_ApplyFilter_27
) then
1678 if (CountMiddles
< FragsAcross
- 1) then
1680 if (disp_frag_state
= stt_DispFrag19
) then
1681 dpf_rd_addr
<= Fragment
((4+DPF_ADDR_WIDTH
) downto 5);
1683 dpf_position
<= Fragment
;
1684 proc_state
<= stt_CalcDispFragPos
;
1685 next_apply_filter_state
<= stt_ApplyFilter_27
;
1686 next_disp_frag_state
<= stt_DispFrag20
;
1688 if (disp_frag_value
= '1') then
1689 -- Filter Left edge always
1690 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1691 -- Horizontal Filter Parameter
1692 DeltaHorizFilter
<= x"E"
;
1694 -- Calculate RPI_Value before continue
1695 proc_state
<= stt_Calc_RPI_Value
;
1696 calc_rpi_state
<= stt_calc_rpi1
;
1697 -- Next state after RPI_Value calculation
1698 next_proc_state
<= stt_CallFilterHoriz
;
1699 next_apply_filter_state
<= stt_ApplyFilter_28
;
1701 apply_filter_state
<= stt_ApplyFilter_30
; -- Increment CountMiddles
1705 apply_filter_state
<= stt_ApplyFilter_31
; -- End "Loop"
1706 disp_frag_state
<= stt_DispFrag21
;
1709 elsif (apply_filter_state
= stt_ApplyFilter_28
) then
1711 -- Enter here only if display_fragments(Fragment) is not zero
1713 -- TopRow is always done
1714 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1716 -- Calculate RPI_Value before continue
1717 proc_state
<= stt_Calc_RPI_Value
;
1718 calc_rpi_state
<= stt_calc_rpi1
;
1719 -- Next state after RPI_Value calculation
1720 next_proc_state
<= stt_CallFilterVert
;
1721 next_apply_filter_state
<= stt_ApplyFilter_29
;
1723 elsif (apply_filter_state
= stt_ApplyFilter_29
) then
1725 -- Enter here only if (CountMidCols < FragsAcross - 1) is true
1726 -- and display_fragments(Fragment) is not zero
1728 -- Filter right hand border only if the block to the right
1730 if (disp_frag_state
= stt_DispFrag20
) then
1731 NextFragment
:= Fragment
+ 1;
1732 dpf_rd_addr
<= NextFragment
((4+DPF_ADDR_WIDTH
) downto 5);
1734 dpf_position
<= Fragment
+ 1;
1735 proc_state
<= stt_CalcDispFragPos
;
1736 next_apply_filter_state
<= stt_ApplyFilter_29
;
1737 next_disp_frag_state
<= stt_DispFrag21
;
1739 if (disp_frag_value
= '0') then
1740 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1741 --Horizontal Filter Parameter
1742 DeltaHorizFilter
<= x"
6"
;
1744 -- Calculate RPI_Value before continue
1745 proc_state
<= stt_Calc_RPI_Value
;
1746 calc_rpi_state
<= stt_calc_rpi1
;
1747 -- Next state after RPI_Value calculation
1748 next_proc_state
<= stt_CallFilterHoriz
;
1749 next_apply_filter_state
<= stt_ApplyFilter_30
;
1751 apply_filter_state
<= stt_ApplyFilter_30
;
1756 elsif (apply_filter_state
= stt_ApplyFilter_30
) then
1758 CountMiddles
<= CountMiddles
+1;
1759 Fragment
<= Fragment
+ 1;
1760 apply_filter_state
<= stt_ApplyFilter_27
;
1761 disp_frag_state
<= stt_DispFrag19
;
1763 elsif (apply_filter_state
= stt_ApplyFilter_31
) then
1765 -- ******************************************************
1767 -- ******************************************************
1768 if (disp_frag_state
= stt_DispFrag21
) then
1769 dpf_rd_addr
<= Fragment
((4+DPF_ADDR_WIDTH
) downto 5);
1771 dpf_position
<= Fragment
;
1772 proc_state
<= stt_CalcDispFragPos
;
1773 next_apply_filter_state
<= stt_ApplyFilter_31
;
1774 next_disp_frag_state
<= stt_DispFrag22
;
1777 if (disp_frag_value
= '1') then
1778 -- Filter Left edge always
1779 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1780 -- Horizontal Filter Parameter
1781 DeltaHorizFilter
<= x"E"
;
1783 -- Calculate RPI_Value before continue
1784 proc_state
<= stt_Calc_RPI_Value
;
1785 calc_rpi_state
<= stt_calc_rpi1
;
1786 -- Next state after RPI_Value calculation
1787 next_proc_state
<= stt_CallFilterHoriz
;
1788 next_apply_filter_state
<= stt_ApplyFilter_32
;
1790 apply_filter_state
<= stt_ApplyFilter_33
;
1794 elsif (apply_filter_state
= stt_ApplyFilter_32
) then
1796 -- Enter here only if display_fragments(Fragment) is not zero
1798 -- TopRow is always done
1799 rpi_position
<= resize
(Fragment
, RPI_POS_WIDTH
);
1801 -- Calculate RPI_Value before continue
1802 proc_state
<= stt_Calc_RPI_Value
;
1803 calc_rpi_state
<= stt_calc_rpi1
;
1804 -- Next state after RPI_Value calculation
1805 next_proc_state
<= stt_CallFilterVert
;
1806 next_apply_filter_state
<= stt_ApplyFilter_33
;
1809 --elsif (apply_filter_state = stt_ApplyFilter_33) then
1812 proc_state
<= stt_SelectColor
;
1813 apply_filter_state
<= stt_ApplyFilter_1
;
1814 next_disp_frag_state
<= stt_DispFrag1
;
1816 end procedure ApplyFilter
;
1822 when stt_ReadMemory
=> ReadMemory
;
1823 when stt_WriteMemory
=> WriteMemory
;
1824 when stt_Calc_RPI_Value
=> CalcRPIValue
;
1825 when stt_FindQIndex
=> FindQIndex
;
1826 when stt_CalcFLimit
=> CalcFLimit
;
1827 when stt_SelectColor
=> SelectColor
;
1828 when stt_ApplyFilter
=> ApplyFilter
;
1829 when stt_CalcDispFragPos
=> CalcDispFragPos
;
1830 when stt_CallFilterHoriz
=> CallFilterHoriz
;
1831 when stt_CalcFilterHoriz
=> CalcFilterHoriz
;
1832 when stt_CallFilterVert
=> CallFilterVert
;
1833 -- when stt_CalcFilterVert = other
1834 when others => CalcFilterVert
;
1841 if (clk
'event and clk
= '1') then
1842 if (Reset_n
= '0') then
1844 read_state
<= stt_32bitsData
;
1845 proc_state
<= stt_FindQIndex
;
1846 apply_filter_state
<= stt_ApplyFilter_1
;
1847 calc_filter_state
<= stt_CalcFilter1
;
1848 calc_rpi_state
<= stt_calc_rpi1
;
1850 s_in_request
<= '0';
1851 s_in_sem_request
<= '0';
1854 s_out_sem_valid
<= '0';
1857 mem_rd_valid
<= '0';
1859 CountFilter
<= "
000"
;
1860 CountColumns
<= "
000"
;
1861 pixelPtr
<= "
00000000000000000000"
;
1863 rpi_position
<= '0' & x"
0000"
;
1864 HFragments
<= x"
11"
;
1865 VFragments
<= x"
00"
;
1867 UVStride
<= "
000"
& x"
00"
;
1868 YPlaneFragments
<= '0' & x"
00000"
;
1869 UVPlaneFragments
<= "
000"
& x"
0000"
;
1870 ReconYDataOffset
<= x"
00000"
;
1871 ReconUDataOffset
<= x"
00000"
;
1872 ReconVDataOffset
<= x"
00000"
;
1874 -- FLimits signals initialiation
1875 fbv_position
<= "
000000000"
;
1876 FLimit
<= "
000000000"
;
1879 -- QThreshTable signal memories
1881 qtt_wr_addr
<= "
000000"
;
1882 qtt_wr_data
<= "
00000000000000000000000000000000"
;
1883 qtt_rd_addr
<= "
000000"
;
1886 --display_fragments signal memories
1888 dpf_wr_addr
<= to_unsigned
(0, DPF_ADDR_WIDTH
);
1889 dpf_wr_data
<= "
00000000000000000000000000000000"
;
1890 dpf_rd_addr
<= to_unsigned
(0, DPF_ADDR_WIDTH
);
1892 if (Enable
= '1') then
1894 when readIn
=> ReadIn
;
1896 when others => ReadIn
; state
<= readIn
;