Example #1
0
        public int GetHuffmanCode (HuffmanTree tree)
        {
            int nCode;
            if (tree.m_iEscape != Erina.HuffmanNull)
            {
                int iEntry = Erina.HuffmanRoot;
                int iChild = tree.m_hnTree[Erina.HuffmanRoot].ChildCode;
                do
                {
                    if (!PrefetchBuffer())
                    {
                        return Erina.HuffmanEscape;
                    }
                    iEntry = iChild + (int)(m_dwIntBuffer >> 31);
                    iChild = tree.m_hnTree[iEntry].ChildCode;
                    m_dwIntBuffer <<= 1;
                    --m_nIntBufCount;
                }
                while (0 == (iChild & Erina.CodeFlag));

                if ((m_dwERINAFlags != efERINAOrder0) ||
                    (tree.m_hnTree[Erina.HuffmanRoot].Weight < Erina.HuffmanMax-1))
                {
                    tree.IncreaseOccuredCount (iEntry);
                }
                nCode = iChild & ~Erina.CodeFlag;
                if (nCode != Erina.HuffmanEscape)
                {
                    return  nCode;
                }
            }
            nCode = (int)GetNBits (8);
            tree.AddNewEntry (nCode);

            return nCode;
        }
Example #2
0
        public uint DecodeErinaCodeBytes (sbyte[] ptrDst, uint nCount)
        {
            var tree = m_pLastHuffmanTree;
            int symbol, length;
            uint i = 0;
            if (m_nLength > 0)
            {
                length = (int)Math.Min (m_nLength, nCount);
                m_nLength -= (uint)length;
                do
                {
                    ptrDst[i++] = 0;
                }
                while (0 != --length);
            }
            while (i < nCount)
            {
                symbol = GetHuffmanCode (tree);
                if (Erina.HuffmanEscape == symbol)
                {
                    break;
                }
                ptrDst[i++] = (sbyte)symbol;

                if (0 == symbol)
                {
                    length = GetLengthHuffman (m_ppHuffmanTree[0x100]);
                    if (Erina.HuffmanEscape == length)
                    {
                        break;
                    }
                    if (0 != --length)
                    {
                        m_nLength = (uint)length;
                        if (i + length > nCount)
                        {
                            length = (int)(nCount - i);
                        }
                        m_nLength -= (uint)length;
                        while (length > 0)
                        {
                            ptrDst[i++] = 0;
                            --length;
                        }
                    }
                }
                tree = m_ppHuffmanTree[symbol & 0xFF];
            }
            m_pLastHuffmanTree = tree;
            return i;
        }
Example #3
0
        private void InitializeLossy ()
        {
            if (3 != m_info.BlockingDegree)
                throw new InvalidFormatException();

            m_nBlockSize = 1 << m_info.BlockingDegree;
            m_nBlockArea = 1 << (m_info.BlockingDegree * 2);
            m_nBlockSamples = m_nBlockArea * m_nChannelCount;
            m_nWidthBlocks  = ((int)m_info.Width + m_nBlockSize * 2 - 1) >> (m_info.BlockingDegree + 1);
            m_nHeightBlocks = ((int)m_info.Height + m_nBlockSize * 2 - 1) >> (m_info.BlockingDegree + 1);

            if (CvType.LOT_ERI == m_info.Transformation)
            {
                ++m_nWidthBlocks;
                ++m_nHeightBlocks;
            }

            if (EriSampling.YUV_4_4_4  == m_info.SamplingFlags)
            {
                m_nBlocksetCount = m_nChannelCount * 4;
            }
            else if (EriSampling.YUV_4_1_1 == m_info.SamplingFlags)
            {
                switch (m_nChannelCount)
                {
                case 1:
                    m_nBlocksetCount = 4;
                    break;
                case 3:
                    m_nBlocksetCount = 6;
                    break;
                case 4:
                    m_nBlocksetCount = 10;
                    break;
                default:
                    throw new InvalidFormatException();
                }
            }
            else
                throw new InvalidFormatException();

            m_ptrDecodeBuf  = new sbyte[m_nBlockArea * 16];
            m_ptrVertBufLOT = new float[m_nBlockSamples * 2 * m_nWidthBlocks];
            m_ptrHorzBufLOT = new float[m_nBlockSamples * 2];
            m_ptrBlocksetBuf = new float[16][];
            m_ptrMatrixBuf = new float[m_nBlockArea * 16];
            m_ptrIQParamBuf = new float[m_nBlockArea * 2];
            m_ptrIQParamTable = new byte[m_nBlockArea * 2];

            int dwTotalBlocks = m_nWidthBlocks * m_nHeightBlocks;
            m_ptrLossyOps = new sbyte[dwTotalBlocks * 2];
            m_ptrImageBuf = new sbyte[dwTotalBlocks * m_nBlockArea * m_nBlocksetCount];
            m_ptrMovingVector = new sbyte[dwTotalBlocks * 4];
            m_ptrMoveVecFlags = new sbyte[dwTotalBlocks];
            m_ptrMovePrevBlocks = new int[dwTotalBlocks * 4];

            for (int i = 0; i < 16; i ++)
            {
                m_ptrBlocksetBuf[i] = new float[m_nBlockArea];
            }

            m_nYUVPixelBytes = m_nChannelCount;
            if (3 == m_nYUVPixelBytes)
            {
                m_nYUVPixelBytes = 4;
            }
            m_nYUVLineBytes = ((m_nYUVPixelBytes * m_nWidthBlocks * m_nBlockSize * 2) + 0xF) & (~0xF);
            int nYUVImageSize = m_nYUVLineBytes * m_nHeightBlocks * m_nBlockSize * 2;
            m_ptrBlockLineBuf = new sbyte[m_nYUVLineBytes * 16];
            m_ptrYUVImage = new sbyte[nYUVImageSize];

            InitializeZigZagTable();

            m_pHuffmanTree = new HuffmanTree();
            m_pProbERISA = new ErisaProbModel();

            m_context = new HuffmanDecodeContext (0x10000);
        }
Example #4
0
 public void PrepareToDecodeERINACode (int flags = efERINAOrder1)
 {
     int i;
     if (null == m_ppHuffmanTree)
     {
         m_ppHuffmanTree = new HuffmanTree[0x101];
     }
     m_dwERINAFlags = flags;
     m_nLength = 0;
     if (efERINAOrder0 == flags)
     {
         m_ppHuffmanTree[0] = new HuffmanTree();
         m_ppHuffmanTree[0x100] = new HuffmanTree();
         for (i = 1; i < 0x100; i++)
         {
             m_ppHuffmanTree[i] = m_ppHuffmanTree[0];
         }
     }
     else
     {
         for (i = 0; i < 0x101; i++)
         {
             m_ppHuffmanTree[i] = new HuffmanTree();
         }
     }
     m_pLastHuffmanTree = m_ppHuffmanTree[0];
 }
Example #5
0
        private void InitializeLossless ()
        {
            if (0 != m_info.BlockingDegree)
            {
                m_nBlockSize = 1 << m_info.BlockingDegree;
                m_nBlockArea = 1 << (m_info.BlockingDegree * 2);
                m_nBlockSamples = m_nBlockArea * m_nChannelCount;
                m_nWidthBlocks  = ((int)m_info.Width  + m_nBlockSize - 1) >> m_info.BlockingDegree;
                m_nHeightBlocks = ((int)m_info.Height + m_nBlockSize - 1) >> m_info.BlockingDegree;

                m_ptrOperations = new byte[m_nWidthBlocks * m_nHeightBlocks];
                m_ptrColumnBuf  = new sbyte[m_nBlockSize * m_nChannelCount];
                m_ptrLineBuf    = new sbyte[m_nChannelCount * (m_nWidthBlocks << m_info.BlockingDegree)];
                m_ptrDecodeBuf  = new sbyte[m_nBlockSamples];
                m_ptrArrangeBuf = new sbyte[m_nBlockSamples];

                InitializeArrangeTable();
            }
            if (0x00020200 == m_info.Version)
            {
                if (EriCode.RunlengthHuffman == m_info.Architecture)
                {
                    m_pHuffmanTree = new HuffmanTree();
                }
                else if (EriCode.Nemesis == m_info.Architecture)
                {
                    m_pProbERISA = new ErisaProbModel();
                }
            }
            if (EriCode.RunlengthHuffman == m_info.Architecture)
                m_context = new HuffmanDecodeContext (0x10000);
            else if (EriCode.Nemesis == m_info.Architecture)
                m_context = new ProbDecodeContext (0x10000);
            else
                m_context = new RLEDecodeContext (0x10000);
        }