protected int DecodeERISACodeIndex (ErisaProbModel pModel) { uint dwAcc = m_dwCodeRegister * pModel.TotalCount / m_dwAugendRegister; if (dwAcc >= ErisaProbModel.TotalLimit) { return -1; } int iSym = 0; ushort wAcc = (ushort)dwAcc; ushort wFs = 0; ushort wOccured; for (;;) { wOccured = pModel.SymTable[iSym].Occured; if (wAcc < wOccured) break; wAcc -= wOccured; wFs += wOccured; if (++iSym >= pModel.SymbolSorts) return -1; } m_dwCodeRegister -= (m_dwAugendRegister * wFs + pModel.TotalCount - 1) / pModel.TotalCount; m_dwAugendRegister = m_dwAugendRegister * wOccured / pModel.TotalCount; Debug.Assert (m_dwAugendRegister != 0); while (0 == (m_dwAugendRegister & 0x8000)) { int nNextBit = GetABit(); if (1 == nNextBit) { if ((++m_nPostBitCount) >= 256) return -1; nNextBit = 0; } m_dwCodeRegister = (m_dwCodeRegister << 1) | ((uint)nNextBit & 1); m_dwAugendRegister <<= 1; } m_dwCodeRegister &= 0xFFFF; return iSym; }
public int DecodeERISACode (ErisaProbModel pModel) { int iSym = DecodeERISACodeIndex (pModel); int nSymbol = ErisaProbModel.EscCode; if (iSym >= 0) { nSymbol = pModel.SymTable[iSym].Symbol; pModel.IncreaseSymbol (iSym); } return nSymbol; }
uint DecodeERISACodeBytes (sbyte[] ptrDst, uint nCount) { var pProb = m_pLastERISAProb; int nSymbol, iSym; uint i = 0; while (i < nCount) { if (m_nLength > 0) { uint nCurrent = nCount - i; if (nCurrent > m_nLength) nCurrent = m_nLength; m_nLength -= nCurrent; for (uint j = 0; j < nCurrent; j++) { ptrDst[i++] = 0; } continue; } iSym = DecodeERISACodeIndex (pProb); if (iSym < 0) break; nSymbol = pProb.SymTable[iSym].Symbol; pProb.IncreaseSymbol (iSym); ptrDst[i++] = (sbyte)nSymbol; if (0 == nSymbol) { iSym = DecodeERISACodeIndex (m_pRunLenProb); if (iSym < 0) break; m_nLength = (uint)m_pRunLenProb.SymTable[iSym].Symbol; m_pRunLenProb.IncreaseSymbol (iSym); } pProb = m_ppTableERISA[nSymbol & 0xFF]; } m_pLastERISAProb = pProb; return i; }
public void PrepareToDecodeERISACode () { if (null == m_ppTableERISA) { m_ppTableERISA = new ErisaProbModel[0x101]; for (int i = 0; i < 0x101; ++i) { m_ppTableERISA[i] = new ErisaProbModel(); m_ppTableERISA[i].Initialize(); } } m_pLastERISAProb = m_ppTableERISA[0]; m_pPhraseLenProb.Initialize(); m_pPhraseIndexProb.Initialize(); m_pRunLenProb.Initialize(); InitializeERISACode(); }
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); }
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); }