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

📄 compressor.vhd

📁 enkoder jpeg - very good
💻 VHD
📖 第 1 页 / 共 5 页
字号:
      end if;         result := ('0' & UNum) * ('0' & Prod);      if Num(Num'High) = '1' then --negative result         result := (not result) + 1; --2's Complement      end if;      return result(24 downto 0);	end MultiplierQ;      function Mult_Columns (Line : in std_logic_vector) return std_logic_vector;   	function Mult_Columns (Line : in std_logic_vector) return std_logic_vector is		variable result : std_logic_vector(12 downto 0);	begin      result := "0000000000000" + (Line & "00000000") + (Line & "000000") + (Line & "00000");		return result; --with Line max=1111, the max. result will be=1010010100000 (12..0)	end Mult_Columns;   function Mult_Half_Columns (Line : in std_logic_vector) return std_logic_vector;   	function Mult_Half_Columns (Line : in std_logic_vector) return std_logic_vector is		variable result : std_logic_vector(10 downto 0);	begin      result := "00000000000" + (Line & "0000000") + (Line & "00000") + (Line & "0000");		return result; --with Line max=111, the max. result will be=10011010000 (10..0)	end Mult_Half_Columns;        function GetCategory (Coef : in std_logic_vector) return integer;      --function fixed to work under ModelSim by Peter Eisemann      function GetCategory (Coef : in std_logic_vector) return integer is         --tells us the category of the coefficient (AC and DC) based on a "sign-less" version of itself!         variable Coeff : std_logic_vector(Coef'High downto 0);         variable result: integer := 0;      begin         if Coef(Coef'High) = '1' then            Coeff := (not Coef) + 1;         else            Coeff := Coef;         end if;            categoryloop:for index in Coeff'range loop            if Coeff(index) = '1' then               -- return (index + 1);  Eim               result := (index +1);               exit categoryloop when Coeff(index) = '1';            end if;            end loop categoryloop;                        return result;   end GetCategory;      --   function GetCategory (Coef : in std_logic_vector) return integer;--   --   function GetCategory (Coef : in std_logic_vector) return integer is--      --tells us the category of the coefficient (AC and DC) based on a "sign-less" version of itself!--      variable Coeff : std_logic_vector(Coef'High downto 0);--   begin--      if Coef(Coef'High) = '1' then--         Coeff := (not Coef) + 1;--      else--        Coeff := Coef;--      end if;   --      for index in Coeff'range loop--         if Coeff(index) = '1' then--            return (index + 1);--        end if;   --      end loop;               --      return 0;--   end GetCategory;         function AppendHuffmanWord (HuffmanWord, Code : in std_logic_vector; Pos : in integer) return std_logic_vector;      function AppendHuffmanWord (HuffmanWord, Code : in std_logic_vector; Pos : in integer) return std_logic_vector is      variable result : std_logic_vector(22 downto 0);      begin      result := HuffmanWord;      for i in (Code'length-1) downto 0 loop        result(Pos-i) := Code(i); --Code(Code'length-1-i); --MSB first!!        --IMPORTANT: the std_logic_vector is "to", not "downto", that's why the MSB is opposite as usual      end loop;         return result;   end AppendHuffmanWord;   --this function is an overload with Code as std_logic (used when it must only append the sign)   function AppendHuffmanWord (HuffmanWord : in std_logic_vector; Code : in std_logic; Pos : in integer) return std_logic_vector;      function AppendHuffmanWord (HuffmanWord : in std_logic_vector; Code : in std_logic; Pos : in integer) return std_logic_vector is      variable result : std_logic_vector(22 downto 0);   begin      result := HuffmanWord;      result(Pos) := Code;            return result;   end AppendHuffmanWord;      --this one is to define the MSB of Code in case it is not length-1, so that CodeLength is the new length-1   function AppendHuffmanWordL (HuffmanWord, Code : in std_logic_vector; CodeLength : in integer; Pos : in integer) return std_logic_vector;      function AppendHuffmanWordL (HuffmanWord, Code : in std_logic_vector; CodeLength : in integer; Pos : in integer) return std_logic_vector is      variable result : std_logic_vector(22 downto 0);   begin      result := HuffmanWord;      for i in Code'length downto 0 loop         if i < CodeLength then --this may look redundant but it avoids an "unbound loop" error            result(Pos-i) := Code(CodeLength-1-i); --careful! here bit 0 is the LSB, X-File         end if;         end loop;         return result;   end AppendHuffmanWordL;         function To_std_logicvpor11(ZeroRun : in integer) return std_logic_vector;      function To_std_logicvpor11(ZeroRun : in integer) return std_logic_vector is      --returns the integer times 11 in a std_logic_vector(8 downto 0)   begin      case ZeroRun is         when 0 =>            return "000000000";         when 1 =>            return "000001011";         when 2 =>            return "000010110";         when 3 =>            return "000100001";         when 4 =>            return "000101100";         when 5 =>            return "000110111";         when 6 =>            return "001000010";         when 7 =>            return "001001101";         when 8 =>            return "001011000";         when 9 =>            return "001100011";         when 10 =>            return "001101110";         when 11 =>            return "001111001";         when 12 =>            return "010000100";         when 13 =>            return "010001111";         when 14 =>            return "010011010";         when others => --15 =>            return "010100101"; --165      end case;   end To_std_logicvpor11;         function To_std_logicv(Cat : in integer) return std_logic_vector;      function To_std_logicv(Cat : in integer) return std_logic_vector is   begin      case Cat is         when 0 =>            return "0000";         when 1 =>            return "0001";         when 2 =>            return "0010";         when 3 =>            return "0011";         when 4 =>            return "0100";         when 5 =>            return "0101";         when 6 =>            return "0110";         when 7 =>            return "0111";         when 8 =>            return "1000";         when 9 =>            return "1001";         when others => -- 10 => there won't be 11 because we only use it for AC            return "1010";      end case;            end To_std_logicv;      function GetMagnitude (Coef : in std_logic_vector; Cat : in integer) return std_logic_vector;      function GetMagnitude (Coef : in std_logic_vector; Cat : in integer) return std_logic_vector is   begin      case Cat is         when 0 =>            return "000000000000"; --we avoid this case with an if because it wouldn't be correct         when 1 =>            return "000000000000"; --we avoid this case with an if because it wouldn't be correct         when 2 =>            return (Coef - "10");         when 3 =>            return (Coef - "100");         when 4 =>            return (Coef - "1000");         when 5 =>            return (Coef - "10000");         when 6 =>            return (Coef - "100000");         when 7 =>            return (Coef - "1000000");         when 8 =>            return (Coef - "10000000");         when 9 =>            return (Coef - "100000000");         when 10 =>            return (Coef - "1000000000");         when others => --11 =>            return (Coef - "10000000000");      end case;   end GetMagnitude;         function CompressDC(Cat : in integer; LumaBlock : in std_logic) return std_logic_vector;      function CompressDC(Cat : in integer; LumaBlock : in std_logic) return std_logic_vector is      variable result : std_logic_vector(14 downto 0) := (others => '0');   begin --the four MSBs of result keep the number of the MSB bit of the data in the LSBs      if LumaBlock = '1' then --compress with DC Luminance Table         case Cat is            when 0 =>               result := "000100000000000";            when 1 =>               result := "001000000000010";            when 2 =>               result := "001000000000011";            when 3 =>               result := "001000000000100";            when 4 =>               result := "001000000000101";            when 5 =>               result := "001000000000110";            when 6 =>               result := "001100000001110";            when 7 =>               result := "010000000011110";            when 8 =>               result := "010100000111110";            when 9 =>               result := "011000001111110";            when 10 =>               result := "011100011111110";            when others => --11               result := "100000111111110";         end case;      else --DC chrominance table         case Cat is            when 0 =>               result := "000100000000000";            when 1 =>               result := "000100000000001";            when 2 =>               result := "000100000000010";            when 3 =>               result := "001000000000110";            when 4 =>               result := "001100000001110";            when 5 =>               result := "010000000011110";            when 6 =>               result := "010100000111110";            when 7 =>               result := "011000001111110";            when 8 =>               result := "011100011111110";            when 9 =>               result := "100000111111110";            when 10 =>               result := "100101111111110";            when others => --11               result := "101011111111110";         end case;      end if;   

⌨️ 快捷键说明

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