📄 h264intra4x4.vhd
字号:
lvalid <= '0';
state <= IDLE;
STROBEO <= '0';
fbpending <= '0';
end if;
if NEWSLICE='1' then
tvalid <= '0';
elsif NEWLINE='1' then
tvalid <= '1';
end if;
--
if state=15 then
submb <= submb+1;
end if;
if state=1 or state=15 then
oldxx <= xx;
end if;
if state=IDLE and statei=0 then
null; --wait for some data
elsif state=3 and statei(5 downto 4)=yy then
null; --wait for enough data
elsif state=11 and (READYO='0' or FBSTROBE='1' or fbpending='1') then
null; --wait before output
elsif state=15 and xx(0)='1' and submb/=15 then
state <= IDLE+2; --quickly onto next (no need to await strobe)
elsif state=19 and (FBSTROBE='1' or fbpending='1' or chreadyi='1' or chreadyii='1') then
null; --wait for fb / chready complete
elsif state=19 and submb/=0 then
state <= IDLE+3; --onto next
elsif state=20 then
--new macroblock, XXINC is set this state
state <= IDLE; --reload new TOP stuff
else
state <= state+1;
end if;
if state=15 and xx(0)='0' then
chreadyi <= '1';
end if;
if outf='0' and chreadyi='1' and READYO='0' then
chreadyii <= '1';
chreadyi <= '0';
elsif READYO='0' and readyod='1' and chreadyii='1' then
chreadyii <= '0';
end if;
readyod <= READYO;
--
if state=2 or state=16 then
--read TOPMI for this submb (only if tvalid&lvalid)
if TOPMI < lmode(conv_integer(yy)) then
prevmode <= TOPMI;
else
prevmode <= lmode(conv_integer(yy));
end if;
--
sumt <= (b"00"&topi0) + (b"00"&topi1) + (b"00"&topi2) + (b"00"&topi3);
topih <= TOPI;
end if;
suml <= (b"00"&left0) + (b"00"&left1) + (b"00"&left2) + (b"00"&left3);
if state=3 then
-- set avg by setting sumtl
if lvalid='1' or xx/=0 then --left valid
if tvalid='1' or yy/=0 then --top valid
sumtl <= ('0'&sumt) + ('0'&suml) + 4;
else
sumtl <= (suml&'0') + 4;
end if;
else
if tvalid='1' or yy/=0 then --top valid
sumtl <= (sumt&'0') + 4;
else
sumtl <= x"80"&b"000";
end if;
end if;
topii <= topih;
end if;
--
-- states 4..7(pass1) 12..15(pass2)
dat0 <= pix(conv_integer(yy & state(1 downto 0) & xx));
leftp <= pixleft(conv_integer(yyfull));
--
-- states 5..8 (pass1) 13..16 (pass2)
vdif0 <= ('0'&datai0) - ('0'&topii0);
vdif1 <= ('0'&datai1) - ('0'&topii1);
vdif2 <= ('0'&datai2) - ('0'&topii2);
vdif3 <= ('0'&datai3) - ('0'&topii3);
--
hdif0 <= ('0'&datai0) - ('0'&leftp);
hdif1 <= ('0'&datai1) - ('0'&leftp);
hdif2 <= ('0'&datai2) - ('0'&leftp);
hdif3 <= ('0'&datai3) - ('0'&leftp);
leftpd <= leftp;
--
ddif0 <= ('0'&datai0) - ('0'&avg);
ddif1 <= ('0'&datai1) - ('0'&avg);
ddif2 <= ('0'&datai2) - ('0'&avg);
ddif3 <= ('0'&datai3) - ('0'&avg);
--
-- states 6..9
if vdif0(8)='0' then
vabsdif0 <= vdif0(7 downto 0);
else
vabsdif0 <= x"00"-vdif0(7 downto 0);
end if;
if vdif1(8)='0' then
vabsdif1 <= vdif1(7 downto 0);
else
vabsdif1 <= x"00"-vdif1(7 downto 0);
end if;
if vdif2(8)='0' then
vabsdif2 <= vdif2(7 downto 0);
else
vabsdif2 <= x"00"-vdif2(7 downto 0);
end if;
if vdif3(8)='0' then
vabsdif3 <= vdif3(7 downto 0);
else
vabsdif3 <= x"00"-vdif3(7 downto 0);
end if;
--
if hdif0(8)='0' then
habsdif0 <= hdif0(7 downto 0);
else
habsdif0 <= x"00"-hdif0(7 downto 0);
end if;
if hdif1(8)='0' then
habsdif1 <= hdif1(7 downto 0);
else
habsdif1 <= x"00"-hdif1(7 downto 0);
end if;
if hdif2(8)='0' then
habsdif2 <= hdif2(7 downto 0);
else
habsdif2 <= x"00"-hdif2(7 downto 0);
end if;
if hdif3(8)='0' then
habsdif3 <= hdif3(7 downto 0);
else
habsdif3 <= x"00"-hdif3(7 downto 0);
end if;
--
if ddif0(8)='0' then
dabsdif0 <= ddif0(7 downto 0);
else
dabsdif0 <= x"00"-ddif0(7 downto 0);
end if;
if ddif1(8)='0' then
dabsdif1 <= ddif1(7 downto 0);
else
dabsdif1 <= x"00"-ddif1(7 downto 0);
end if;
if ddif2(8)='0' then
dabsdif2 <= ddif2(7 downto 0);
else
dabsdif2 <= x"00"-ddif2(7 downto 0);
end if;
if ddif3(8)='0' then
dabsdif3 <= ddif3(7 downto 0);
else
dabsdif3 <= x"00"-ddif3(7 downto 0);
end if;
--
if state=6 then
vtotdif <= (others => '0');
htotdif <= (others => '0');
dtotdif <= (others => '0');
if (tvalid='1' or yy/=0) and (lvalid='1' or xx/=0) then
dconly <= '0';
else
dconly <= '1';
end if;
end if;
-- states 7..10
if state>=7 and state<=10 then
vtotdif <= (x"0"&vabsdif0) + (x"0"&vabsdif1) + (x"0"&vabsdif2) + (x"0"&vabsdif3) + vtotdif;
htotdif <= (x"0"&habsdif0) + (x"0"&habsdif1) + (x"0"&habsdif2) + (x"0"&habsdif3) + htotdif;
dtotdif <= (x"0"&dabsdif0) + (x"0"&dabsdif1) + (x"0"&dabsdif2) + (x"0"&dabsdif3) + dtotdif;
end if;
--
if state=11 then
if vtotdif <= htotdif and vtotdif <= dtotdif and dconly='0' then
modeoi <= x"0"; --vertical prefer
elsif htotdif <= dtotdif and dconly='0' then
modeoi <= x"1"; --horizontal prefer
else
modeoi <= x"2"; --DC
end if;
end if;
if state=12 then
lmode(conv_integer(yy)) <= modeoi;
assert modeoi=2 or dconly='0' report "modeoi wrong for dconly";
if dconly='1' or prevmode = modeoi then
PMODEO <= '1';
elsif modeoi < prevmode then
PMODEO <= '0';
RMODEO <= modeoi(2 downto 0);
else
PMODEO <= '0';
RMODEO <= modeoi(2 downto 0) - 1;
end if;
end if;
if state>=12 and state<=15 then
outf1 <= '1';
else
outf1 <= '0';
end if;
outf <= outf1;
-- states 14..17
if outf='1' then
STROBEO <= '1';
MSTROBEO <= not outf1;
if modeoi=0 then
DATAO <= vdif3&vdif2&vdif1&vdif0;
BASEO <= topii;
elsif modeoi=1 then
DATAO <= hdif3&hdif2&hdif1&hdif0;
BASEO <= leftpd&leftpd&leftpd&leftpd;
elsif modeoi=2 then
DATAO <= ddif3&ddif2&ddif1&ddif0;
BASEO <= avg&avg&avg&avg;
end if;
else
STROBEO <= '0';
MSTROBEO <= '0';
end if;
if state=15 and FBSTROBE='0' then --set feedback ptr to get later feedback
fbptr <= yy & b"00";
fbpending <= '1';
end if;
--
-- this comes back from transform/quantise/dequant/detransform loop
-- some time later...
--
if FBSTROBE='1' then
pixleft(conv_integer(fbptr)) <= FEEDBI;
fbptr <= fbptr + 1;
fbpending <= '0';
if (submb=14 or submb=15) and NEWLINE='0' then
lvalid <= '1';
end if;
end if;
--
end if;
end process;
--
end hw; --h264intra4x4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -