Beruflich Dokumente
Kultur Dokumente
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
----------------------------------------------------------------------------------
-- Connectivity.
----------------------------------------------------------------------------------
entity ETC1Decompressor is
Port ( textureLine : in STD_LOGIC_VECTOR(63 downto 0);
PIX : in STD_LOGIC_VECTOR(3 downto 0);
-- ETC2
OverflowR : out STD_LOGIC;
OverflowG : out STD_LOGIC;
OverflowB : out STD_LOGIC
);
end ETC1Decompressor;
----------------------------------------------------------------------------------
-- Synthetizable logic.
----------------------------------------------------------------------------------
-- Used in Clipper.
signal Rs : std_logic;
signal Ro : std_logic;
signal Gs : std_logic;
signal Go : std_logic;
signal Bs : std_logic;
signal Bo : std_logic;
begin
--
-- Stage 0 :
-- Init, cut the 64 bit chunk and assign to temp signals.
-- Perform u,v,w working bit calculation.
process (textureLine, PIX)
begin
-- Chunk cutting.
----------------------------------------------------
diffbit <= textureLine(33);
flipbit <= textureLine(32);
pixels <= textureLine(31 downto 0);
--
-- Stage 1A :
-- Select Base Color A, B or A+Delta for each component.
-- Perform at the same time a conversion from 555/444/
process (u,v,diffbit,component1, component2, component3)
begin
-- Stage U : Select Color
if (u = '0') then
add_compR <= "000";
add_compG <= "000";
add_compB <= "000";
else
add_compR <= component1(2 downto 0); -- 3 Bit delta extended to 5
bit.
add_compG <= component2(2 downto 0); -- 3 Bit delta extended to 5
bit.
add_compB <= component3(2 downto 0); -- 3 Bit delta extended to 5
bit.
end if;
--
-- State 1B : Optionnal overflow detector for ETC2 extension.
--
-- ETC2 : Delete this block if pure ETC1 decoder.
process (v, outcolR, outcolG, outcolB)
begin
if (v='0') then
OverflowR <= '0';
OverflowG <= '0';
OverflowB <= '0';
else
OverflowR <= outcolR(5);
OverflowG <= outcolG(5);
OverflowB <= outcolB(5);
end if;
end process;
--
-- Stage 1C : Code book setup.
--
process (w,PIX, pixels, textureLine)
begin
if (w = '0') then
-- Sub block 1
tableCode <= textureLine(39 downto 37);
else
-- Sub block 2
tableCode <= textureLine(36 downto 34);
end if;
-- Pixel Layout.
-- --> U / Width
-- 0---- ---- ---- ----
-- |a |e |i |m |
-- | | | | |
-- ---- ---- ---- ----
-- |b |f |j |n |
-- | | | | |
-- ---- ---- ---- ----
-- |c |g |k |o |
-- | | | | |
-- ---- ---- ---- ----
-- |d |h |l |p |
-- | | | | |
-- ---- ---- ---- ----
case PIX is
-- As specified in Khronos Group documentation.
when "0000" => pixIdx <= pixels(16) & pixels(0); -- a
when "0001" => pixIdx <= pixels(17) & pixels(1); -- b
when "0010" => pixIdx <= pixels(18) & pixels(2); -- c
when "0011" => pixIdx <= pixels(19) & pixels(3); -- d
when "0100" => pixIdx <= pixels(20) & pixels(4); -- e
when "0101" => pixIdx <= pixels(21) & pixels(5);
when "0110" => pixIdx <= pixels(22) & pixels(6);
when "0111" => pixIdx <= pixels(23) & pixels(7);
when "1000" => pixIdx <= pixels(24) & pixels(8);
when "1001" => pixIdx <= pixels(25) & pixels(9);
when "1010" => pixIdx <= pixels(26) & pixels(10);
when "1011" => pixIdx <= pixels(27) & pixels(11);
when "1100" => pixIdx <= pixels(28) & pixels(12);
when "1101" => pixIdx <= pixels(29) & pixels(13);
when "1110" => pixIdx <= pixels(30) & pixels(14);
when others => pixIdx <= pixels(31) & pixels(15);
end case;
--
-- logic.
--
process (outcolR, outcolG, outcolB, diffbit, addCode)
begin
tempCompR <= outcolR(4 downto 0) & outcolR(4 downto 2); -- 5 -> 8
tempCompG <= outcolG(4 downto 0) & outcolG(4 downto 2); -- 5 -> 8
tempCompB <= outcolB(4 downto 0) & outcolB(4 downto 2); -- 5 -> 8
--
-- Clamp Code.
--
process (tempCompR2, tempCompG2, tempCompB2, addCode)
begin
-- Clamp Code.
-- 255 if too positive, 0 if too negative.
-- * tempComp garanteed by encoder.
-- * sign of addCode then valid overflow/underflow.
-- Behaviour
-- Overflow / addcode Sign -> Operation.
-- 0 x -> Value
-- 1 / 0 -> 255
-- 1 / 1 -> 0
--
-- Logic : (val & not(Overflow)) | (Overflow & not(sign))
-- (Value if no overflow) | 0 if no overflow, 1 if
overflow and + value.
-- else 0
--
-- Demonstration.
-- O S V&(~O) (O&(~S)) Complete Formula
-- 0 0 V | 0 --> V
-- 0 1 V | 0 --> V
-- 1 0 0 | 1 --> 1
-- 1 1 0 | 0 --> 0
--
Ro <= not(tempCompR2(8));
Rs <= tempCompR2(8) and (not(addCode(8)));
Go <= not(tempCompG2(8));
Gs <= tempCompG2(8) and (not(addCode(8)));
Bo <= not(tempCompB2(8));
Bs <= tempCompB2(8) and (not(addCode(8)));