internal PKPixelInfo(Guid pGUIDPixFmt, uint cChannel, COLORFORMAT cfColorFormat, BITDEPTH_BITS bdBitDepth, uint cbitUnit, ulong grBit, uint uInterpretation, uint uSamplePerPixel, uint uBitsPerSample, uint uSampleFormat) { this.pGUIDPixFmt = pGUIDPixFmt; this.cChannel = cChannel; this.cfColorFormat = cfColorFormat; this.bdBitDepth = bdBitDepth; this.cbitUnit = cbitUnit; this.grBit = grBit; this.uInterpretation = uInterpretation; this.uSamplePerPixel = uSamplePerPixel; this.uBitsPerSample = uBitsPerSample; this.uSampleFormat = uSampleFormat; }
private void ReadImagePlaneHeader(SimpleBitIO bitIO) { // internal color format cfColorFormat = (COLORFORMAT)bitIO.GetBit32_SB(Constant.ColorFormatNumBits); if (cfColorFormat != COLORFORMAT.Y_ONLY /* accept DEM only! */) { throw new ArgumentOutOfRangeException("bitIO", "cfColorFormat = " + cfColorFormat); } // lossless mode bScaledArith = bitIO.GetBit32_SB(Constant.NoScaledFlagNumBits) == 1; // subbands sbSubband = (SUBBAND)bitIO.GetBit32_SB(Constant.BandsPresentNumBits); if (sbSubband != SUBBAND.SB_ALL) { throw new ArgumentOutOfRangeException("bitIO", "sbSubband = " + sbSubband); } cNumChannels = 1; bitIO.GetBit32_SB(8); // pSCP->nLenMantissaOrShift = (U8)GetBit32_SB(pSB, 8); // quantization uQPMode = 0; // DC uniform if (bitIO.GetBit32_SB(Constant.DCFrameUniformNumBits) == 1) { uQPMode += (uint)BitstreamDecoder.ReadQuantizerSB(out uiQPIndexDC, bitIO) << 3; } else { uQPMode++; } if (sbSubband != SUBBAND.SB_DC_ONLY) { if (bitIO.GetBit32_SB(Constant.UseDCQuantizerNumBits) == 0) { // don't use DC QP uQPMode += 0x200; if (bitIO.GetBit32_SB(Constant.LPFrameUniformNumBits) == 1) // LP uniform { uQPMode += (uint)BitstreamDecoder.ReadQuantizerSB(out uiQPIndexLP, bitIO) << 5; } else { uQPMode += 2; } } else { uQPMode += ((uQPMode & 1) << 1) + ((uQPMode & 0x18) << 2); } if (sbSubband != SUBBAND.SB_NO_HIGHPASS) { if (bitIO.GetBit32_SB(Constant.UseLPQuantizerNumBits) == 0) { // don't use LP QP uQPMode += 0x400; if (bitIO.GetBit32_SB(Constant.HPFrameUniformNumBits) == 1) // HP uniform { uQPMode += (uint)BitstreamDecoder.ReadQuantizerSB(out uiQPIndexHP, bitIO) << 7; } else { uQPMode += 4; } } else { uQPMode += ((uQPMode & 2) << 1) + ((uQPMode & 0x60) << 2); } } } if (sbSubband == SUBBAND.SB_DC_ONLY) { uQPMode |= 0x200; } else if (sbSubband == SUBBAND.SB_NO_HIGHPASS) { uQPMode |= 0x400; } if ((uQPMode & 0x600) == 0) { throw new ArgumentOutOfRangeException("bitIO", "Frame level QPs must be specified independently!"); } bitIO.Flush(); }
/************************************************************************* UpdateModelMB : update adaptive model at end of macroblock (for lowest resolution only) *************************************************************************/ private static void UpdateModelMB(COLORFORMAT cf, int iChannels, int[] iLaplacianMean, CAdaptiveModel pModel) { iLaplacianMean[0] *= Constant.aWeight0[pModel.m_band - CAdaptiveModel.BAND.BAND_DC]; if (cf == COLORFORMAT.YUV_420) { iLaplacianMean[1] *= Constant.aWeight2[pModel.m_band - CAdaptiveModel.BAND.BAND_DC]; } else if (cf == COLORFORMAT.YUV_422) { iLaplacianMean[1] *= Constant.aWeight2[3 + (pModel.m_band) - CAdaptiveModel.BAND.BAND_DC]; } else { iLaplacianMean[1] *= Constant.aWeight1[pModel.m_band - CAdaptiveModel.BAND.BAND_DC][iChannels - 1]; if (pModel.m_band == CAdaptiveModel.BAND.BAND_AC) iLaplacianMean[1] >>= 4; } for (int j = 0; j < 2; j++) { int iLM = iLaplacianMean[j]; int iMS = pModel.m_iFlcState[j]; int iDelta = (iLM - Constant.MODELWEIGHT) >> 2; if (iDelta <= -8) { iDelta += 4; if (iDelta < -16) iDelta = -16; iMS += iDelta; if (iMS < -8) { if (pModel.m_iFlcBits[j] == 0) iMS = -8; else { iMS = 0; pModel.m_iFlcBits[j]--; } } } else if (iDelta >= 8) { iDelta -= 4; if (iDelta > 15) iDelta = 15; iMS += iDelta; if (iMS > 8) { if (pModel.m_iFlcBits[j] >= 15) { pModel.m_iFlcBits[j] = 15; iMS = 8; } else { iMS = 0; pModel.m_iFlcBits[j]++; } } } pModel.m_iFlcState[j] = iMS; if (cf == COLORFORMAT.Y_ONLY) break; } }
/// <summary> /// Reads header of FIRST PLANE only (p.39, HD Photo Bitstream Specification) /// </summary> /// <param name="bitIO">Stream to read the image plane header from</param> private void ReadImagePlaneHeader(SimpleBitIO bitIO) { // internal color format cfColorFormat = (COLORFORMAT)bitIO.GetBit32_SB(Constant.ColorFormatNumBits); if (cfColorFormat != COLORFORMAT.Y_ONLY /* accept DEM only! */) { throw new ArgumentOutOfRangeException("bitIO", "cfColorFormat = " + cfColorFormat); } // lossless mode bScaledArith = bitIO.GetBit32_SB(Constant.NoScaledFlagNumBits) == 1; // subbands sbSubband = (SUBBAND)bitIO.GetBit32_SB(Constant.BandsPresentNumBits); if (sbSubband != SUBBAND.SB_ALL) { throw new ArgumentOutOfRangeException("bitIO", "sbSubband = " + sbSubband); } cNumChannels = 1; bitIO.GetBit32_SB(8);// pSCP->nLenMantissaOrShift = (U8)GetBit32_SB(pSB, 8); // quantization uQPMode = 0; // DC uniform if (bitIO.GetBit32_SB(Constant.DCFrameUniformNumBits) == 1) { uQPMode += (uint)BitstreamDecoder.ReadQuantizerSB(out uiQPIndexDC, bitIO) << 3; } else { uQPMode++; } if (sbSubband != SUBBAND.SB_DC_ONLY) { if (bitIO.GetBit32_SB(Constant.UseDCQuantizerNumBits) == 0) { // don't use DC QP uQPMode += 0x200; if (bitIO.GetBit32_SB(Constant.LPFrameUniformNumBits) == 1) // LP uniform { uQPMode += (uint)BitstreamDecoder.ReadQuantizerSB(out uiQPIndexLP, bitIO) << 5; } else { uQPMode += 2; } } else { uQPMode += ((uQPMode & 1) << 1) + ((uQPMode & 0x18) << 2); } if (sbSubband != SUBBAND.SB_NO_HIGHPASS) { if (bitIO.GetBit32_SB(Constant.UseLPQuantizerNumBits) == 0) { // don't use LP QP uQPMode += 0x400; if (bitIO.GetBit32_SB(Constant.HPFrameUniformNumBits) == 1) // HP uniform { uQPMode += (uint)BitstreamDecoder.ReadQuantizerSB(out uiQPIndexHP, bitIO) << 7; } else { uQPMode += 4; } } else { uQPMode += ((uQPMode & 2) << 1) + ((uQPMode & 0x60) << 2); } } } if (sbSubband == SUBBAND.SB_DC_ONLY) { uQPMode |= 0x200; } else if (sbSubband == SUBBAND.SB_NO_HIGHPASS) { uQPMode |= 0x400; } if ((uQPMode & 0x600) == 0) { throw new ArgumentOutOfRangeException("bitIO", "Frame level QPs must be specified independently!"); } bitIO.Flush(); }
internal PKPixelInfo(Guid pGUIDPixFmt, uint cChannel, COLORFORMAT cfColorFormat, BITDEPTH_BITS bdBitDepth, uint cbitUnit, ulong grBit, uint uInterpretation, uint uSamplePerPixel, uint uBitsPerSample, uint uSampleFormat) { this.pGUIDPixFmt = pGUIDPixFmt; this.cChannel = cChannel; this.cfColorFormat = cfColorFormat; this.bdBitDepth = bdBitDepth; this.cbitUnit = cbitUnit; this.grBit = grBit; this.uInterpretation = uInterpretation; this.uSamplePerPixel = uSamplePerPixel; this.uBitsPerSample = uBitsPerSample; this.uSampleFormat = uSampleFormat; }