⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quantize.vhd

📁 protel电路设计教程
💻 VHD
字号:
package Quantize is
  function DeQuantize9 (value : std_logic_vector(7 downto 0);
                        hpixel: std_logic_vector(1 downto 0); 
                        vpixel: std_logic_vector(7 downto 0)) return std_logic_vector(3 downto 0);
  function DeQuantize6 (value : std_logic_vector(7 downto 0);
                        hpixel: std_logic_vector(1 downto 0); 
                        vpixel: std_logic_vector(7 downto 0)) return std_logic_vector(3 downto 0);
end Quantize; 
                      
package body Quantize is

------------------------------------------------------------
    -- DeQuantize9 
    -- Hard coded lossy 9-1 compression one layer (no color information included) 
    --
    -- a 720 x 240 12 bit color image takes 19.2k bytes to store 
    --   
    -- Function takes an 8-bit value, extracts the color information and modifies 
    -- to reflect the block desriptor 
    --  
    -- Bit pattern     7   6   5   4   3   2   1  0         --- --- ---
    --                ___ ___ ___ ___ ___ ___ ___ ___      |   |   |   |  X = Center Color Value 
    --               |   |   |   |   |   |   |   |   |      --- --- ---       obtained from the  
    --                --- --- --- --- --- --- --- ---      |   | X |   |      High Order nibble 
    --               \ 4 bit lum    /\ block descipt/       --- --- ---       of the bit pattern 
    --                                                     |   |   |   | 
    --                                                      --- --- --- 
    --   Block Descriptor Traits 
    --   0 : No Change      4 : LS Down        8 : LS UL to LR   C : HS Down
    --   1 : LS  Right      5 : LS LL to UR    9 : HS Right      D : CC LL AND UR 
    --   2 : LS  Left       6 : LS UR to LL    A : HS Left       E : CC LR AND UL 
    --   3 : LS  UP         7 : LS LR to UL    B : HS UP         F : CC ALL 
    --
    --   LS = Light Sweep   = 1/2  1   2
    --   HS = Heavy Sweep   = 1    1   4
    --   CR = Corner Darker = 4X on Specifid Corners, 2X on Adjacent 
    --   UR = Upper Right     UL = Upper Left  LR = Lower Right   LL = Lower Left
    --
------------------------------------------------------------


function DeQuantize9 (value : std_logic_vector(7 downto 0);
                      hpixel: std_logic_vector(1 downto 0);
                      vpixel: std_logic_vector(1 downto 0)) return std_logic_vector(3 downto 0) is
         variable s      : std_logic_vector(3 downto 0);
         variable lum    : std_logic_vector(3 downto 0);
         variable descrpt: std_logic_vector(3 downto 0); 
begin
  lum(0) <= value(4); 
  lum(1) <= value(5);
  lum(2) <= value(6);
  lum(3) <= value(7);
  descrpt(0) <= value(0);
  descrpt(1) <= value(1);
  descrpt(2) <= value(2);
  descrpt(3) <= value(3);
  
  if descrpt = 0 then            --   0 : No Change       
    s <= lum; 
  elsif descrpt = 1 then         --   1 : LS  Right   
    if hpixel = 1 then
      s <= lum sll 1; 
    elsif hpixel = 3 then
      s <= lum slr 1;
    else
      s <= lum;
    end if; 
  elsif descrpt = 2 then         --   2 : LS  Left       
    if hpixel = 3 then
      s <= lum sll 1; 
    elsif hpixel = 1 then
      s <= lum slr 1;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 3 then         --   3 : LS  UP           
    if vpixel = 1 then
      s <= lum sll 1; 
    elsif vpixel = 3 then
      s <= lum slr 1;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 4 then         --   4 : LS Down                 
    if vpixel = 3 then
      s <= lum sll 1; 
    elsif vpixel = 1 then
      s <= lum slr 1;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 5 then         --   5 : LS LL to UR     
    if vpixel = 1 and hpixel = 3 then
      s <= lum sll 1;
    elsif vpixel = 3 and hpixel = 1 then
      s <= lum slr 1;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 6 then         --   6 : LS UR to LL     
    if vpixel = 1 and hpixel = 3 then
      s <= lum slr 1;
    elsif vpixel = 3 and hpixel = 1 then
      s <= lum sll 1;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 7 then         --   7 : LS LR to UL     
    if vpixel = 1 and hpixel = 1 then
      s <= lum sll 1;
    elsif vpixel = 3 and hpixel = 3 then
      s <= lum slr 1;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 8 then         --   8 : LS UL to LR    
    if vpixel = 1 and hpixel = 1 then
      s <= lum slr 1;
    elsif vpixel = 3 and hpixel = 3 then
      s <= lum sll 1;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 9 then         --   9 : HS Right       
    if hpixel = 1 then
      s <= lum sll 2;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 10 then        --   A : HS Left        
    if hpixel = 3 then
      s <= lum sll 2;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 11 then        --   B : HS UP          
    if vpixel = 1 then
      s <= lum sll 2;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 12 then        --   C : HS Down 
    if vpixel = 3 then
      s <= lum sll 2;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 13 then        --   D : CC LL AND UR 
    if (hpixel = 1 and vpixel = 3) or 
       (hpixel = 3 and vpixel = 1) then
      s <= lum sll 2;
    elsif (hpixel and 2) Xor (vpixel and 2)
      s < lum sll 1; 
    else
      s <= lum; 
    end if; 
  elsif descrpt = 14 then        --   E : CC LR AND UL 
    if (hpixel = 3 and vpixel = 3) or 
       (hpixel = 1 and vpixel = 1) then
      s <= lum sll 2;
    elsif (hpixel and 2) Xor (vpixel and 2)
      s < lum sll 1; 
    else
      s <= lum; 
    end if; 
  elsif descrpt = 15 then        --   F : CC ALL 
    if (hpixel = 3 or hpixel = 1) and
        hpixel != 2 then
      s <= lum sll 2;
    elsif (hpixel and 2) Xor (vpixel and 2)
      s < lum sll 1; 
    else
      s <= lum; 
    end if; 
  end if; 
  return (s); 
end DeQuantize9;

------------------------------------------------------------
    -- DeQuantize6 
    -- Hard coded lossy 6-1 compression one layer (no color information included) 
    --
    -- a 720 x 240 12 bit color image takes 28.8k bytes to store 
    -- 
    -- Function takes an 8-bit value, extracts the color information and modifies 
    -- to reflect the block desriptor 
    --  
    -- Bit pattern     7   6   5   4   3   2   1  0         --- --- ---
    --                ___ ___ ___ ___ ___ ___ ___ ___      | X |   |   |  X = Base Color Value 
    --               |   |   |   |   |   |   |   |   |      --- --- ---       obtained from the  
    --                --- --- --- --- --- --- --- ---      |   |   |   |      High Order nibble 
    --               \ 4 bit lum    /\ block descipt/       --- --- ---       of the bit pattern 
    --                                                                   
    --                                                                  
    --   Block Descriptor Traits 
    --   0 : No Change      4 : LSL Down        8 : HSL Right      C : HSL LC
    --   1 : LSD Right      5 : LSD to LR       9 : HSD Down       D : 2-1 and 1-3 darker       
    --   2 : LSL Right      6 : LSL to LR       A : HSL Down       E : middle darker       
    --   3 : LSD Down       7 : HSD Right       B : HSD LC         F : Far Corner Inversed
    --
    --   LSD = Light Sweep   = 1    2   4
    --   LSL = Light Sweep   = 1   1/2 1/4
    --   HSD = Heavy Sweep   = 1    4   8
    --   HSL = Heavy Sweep   = 1   1/4 1/8
    --  
------------------------------------------------------------

function DeQuantize6 (value : std_logic_vector(7 downto 0);
                      hpixel: std_logic_vector(1 downto 0);
                      vpixel: std_logic_vector(1 downto 0)) return std_logic_vector(3 downto 0) is
         variable s      : std_logic_vector(3 downto 0);
         variable lum    : std_logic_vector(3 downto 0);
         variable descrpt: std_logic_vector(3 downto 0); 
begin
  lum(0) <= value(4); 
  lum(1) <= value(5);
  lum(2) <= value(6);
  lum(3) <= value(7);
  descrpt(0) <= value(0);
  descrpt(1) <= value(1);
  descrpt(2) <= value(2);
  descrpt(3) <= value(3);
  
--  4 : LSL Down        8 : HSL Right      C : HSL LC
--  5 : LSD to LR       9 : HSD Down       D : 2-1 and 1-3 darker       
--  6 : LSL to LR       A : HSL Down       E : middle darker       
--  7 : HSD Right       B : HSD LC         F : Far Corner Inversed
  if descrpt = 0 then                 --   0 : No Change       
    s <= lum; 
  elsif descrpt = 1 then              --   1 : LSD Right       
    if hpixel = 2 then
      s <= lum sll 1; 
    elsif hpixel = 3 then
      s <= lum sll 2;
    else
      s <= lum;
    end if; 
  elsif descrpt = 2 then              --   2 : LSL Right       
    if hpixel = 2 then
      s <= lum slr 1; 
    elsif hpixel = 3 then
      s <= lum slr 2;
    else
      s <= lum;
    end if; 
  elsif descrpt = 3 then              --   3 : LSD Down        
    if vpixel = 2 then
      s <= lum sll 1; 
    elsif vpixel = 3 then
      s <= lum sll 2;
    else
      s <= lum; 
    end if;                           --   4 : LSL Down         
  elsif descrpt = 4 then 
    if vpixel = 2 then  
      s <= lum slr 1; 
    elsif vpixel = 3 then
      s <= lum slr 2;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 5 then              --   5 : LSD to LR        
    if (vpixel = 1 and hpixel = 3) or 
       (vpixel = 2 and hpixel = 2) then
      s <= lum sll 1;
    if (vpixel = 2 and hpixel = 3) then
      s <= lum sll 2;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 6 then              --   6 : LSL to LR        
    if (vpixel = 1 and hpixel = 3) or 
       (vpixel = 2 and hpixel = 2) then
      s <= lum slr 1;
    if (vpixel = 2 and hpixel = 3) then
      s <= lum slr 2;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 7 then              --   7 : HSD Right        
    if hpixel = 2 then
      s <= lum sll 2; 
    elsif hpixel = 3 then
      s <= lum sll 3;  
    else
      s <= lum;
    end if; 
  elsif descrpt = 8 then               --   8 : HSL Right       
    if hpixel = 2 then               
      s <= lum slr 2;
    elsif hpixel = 3 then
      s <= lum slr 3;
    else
      s <= lum;
    end if; 
  elsif descrpt = 9 then               --   9 : HSD Down        
    if hpixel = 2 then
      s <= lum sll 2;       
    else
      s <= lum; 
    end if;         
  elsif descrpt = 10 then              --   A : HSL Down        
    if hpixel = 2 then
      s <= lum slr 2;
    else
      s <= lum; 
    end if;         
  elsif descrpt = 11 then              --   B : HSD LC          
    if (vpixel = 1 and hpixel = 3) or
       (vpixel = 2 and hpixel = 2) then
      s <= lum sll 2;
    elsif hpixel = 3 then
      s <= lum sll 3; 
    else
      s <= lum; 
    end if; 
  elsif descrpt = 12 then              --   C : HSL LC 
    if (vpixel = 1 and hpixel = 3) or
       (vpixel = 2 and hpixel = 2) then
      s <= lum slr 2;
    elsif hpixel = 3 then
      s <= lum slr 3; 
    else
      s <= lum; 
    end if; 
  elsif descrpt = 13 then              --   D : 2-1 and 1-3 darker 
    if (hpixel = 1 and vpixel = 2) or 
       (hpixel = 3 and vpixel = 1) then
      s <= lum sll 1;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 14 then              --   E : middle darker 
    if hpixel = 2 then
      s <= lum sll 1;
    else
      s <= lum; 
    end if; 
  elsif descrpt = 15 then              --   F : Far Corner Inversed 
    if hpixel = 3 and vpixel = 2 then 
      s <= lum ror 2;
    else
      s <= lum; 
    end if; 
  end if; 
  return (s); 
end DeQuantize6;


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -