예제 #1
0
 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;
 }
예제 #2
0
        private void ReadWMIHeader(SimpleBitIO bitIO)
        {
            // check signature
            for (int i = 0; i < Constant.GDISignature.Length; i++)
            {
                if ((byte)bitIO.GetBit32_SB(8) != Constant.GDISignature[i])
                {
                    throw new ArgumentOutOfRangeException("bitIO", "GDISignature[" + i + "]");
                }
            }

            // check codec version and ignore subversion
            if (bitIO.GetBit32_SB(Constant.CodecVersionNumBits) != Constant.CodecVersion)
            {
                throw new ArgumentOutOfRangeException("bitIO", "CodecVersion");
            }

            // ignore subversion
            bitIO.GetBit32_SB(Constant.CodecVersionNumBits);

            // 9 primary parameters
            // tiling present
            bTilingPresent = bitIO.GetBit32_SB(Constant.TilingFlagNumBits) == 1;
            if (bTilingPresent)
            {
                throw new ArgumentOutOfRangeException("bitIO", "bTilingPresent = " + bTilingPresent);
            }

            // bitstream layout
            bfBitstreamFormat = (BITSTREAMFORMAT)bitIO.GetBit32_SB(Constant.BitStreamFormatNumBits);
            if (bfBitstreamFormat != BITSTREAMFORMAT.SPATIAL)
            {
                throw new ArgumentOutOfRangeException("bitIO", "bfBitstreamFormat = " + bfBitstreamFormat);
            }
            // presentation orientation
            // ORIENTATION oOrientation = bitIO.GetBit32_SB(Constant.OriantationNumBits);
            bitIO.GetBit32_SB(Constant.OriantationNumBits);

            // bool bIndexTable = bitIO.GetBit32_SB(Constant.IndexTablePresentFlagNumBits) == 1;
            bitIO.GetBit32_SB(Constant.IndexTablePresentFlagNumBits);

            // overlap
            olOverlap = (OVERLAP)bitIO.GetBit32_SB(Constant.OverlapNumBits);
            if (olOverlap == OVERLAP.OL_MAX)
            {
                throw new ArgumentOutOfRangeException("bitIO", "olOverlap = " + olOverlap);
            }

            // 11 some other parameters
            // short words for size and tiles
            bAbbreviatedHeader = bitIO.GetBit32_SB(Constant.ShortHeaderFlagNumBits) == 1;
            bitIO.GetBit32_SB(1);            //pSCP->bdBitDepth = (BITDEPTH)GetBit32_SB(1); // long word
            bitIO.GetBit32_SB(1);            //pSCP->bdBitDepth = BD_LONG; // remove when optimization is done
            // windowing
            bInscribed = bitIO.GetBit32_SB(Constant.WindowingFlagNumBits) == 1;
            if (bInscribed)
            {
                throw new ArgumentOutOfRangeException("bitIO", "bInscribed = " + bInscribed);
            }

            // trim flexbits flag
            bTrimFlexbitsFlag = bitIO.GetBit32_SB(Constant.TrimFlexbitsFlagNumBits) == 1;
            // tile stretching flag
            bTileStretch = bitIO.GetBit32_SB(Constant.TileStretchFlagNumBits) == 1;
            if (bTileStretch)
            {
                throw new ArgumentOutOfRangeException("bitIO", "bTileStretch = " + bTileStretch);
            }

            bitIO.GetBit32_SB(2);            //GetBit32_SB(2);  // padding / reserved bits

            // 10 - informational
            bitIO.GetBit32_SB(4);            //pII->cfColorFormat = GetBit32_SB(pSB, 4); // source color format
            // source bit depth
            bdBitDepth = (BITDEPTH_BITS)bitIO.GetBit32_SB(Constant.SourceBitDepthNumBits);
            // DEM Only
            if (bdBitDepth != BITDEPTH_BITS.BD_16S)
            {
                throw new ArgumentOutOfRangeException("bitIO", "bdBitDepth = " + bdBitDepth);
            }

            if (BITDEPTH_BITS.BD_1alt == bdBitDepth)
            {
                bdBitDepth = BITDEPTH_BITS.BD_1;
            }

            //// 12 - Variable length fields
            //// size
            cWidth          = bitIO.GetBit32_SB((uint)(bAbbreviatedHeader ? Constant.ShortHeaderNumBits : Constant.LongHeaderNumBits)) + 1;
            cHeight         = bitIO.GetBit32_SB((uint)(bAbbreviatedHeader ? Constant.ShortHeaderNumBits : Constant.LongHeaderNumBits)) + 1;
            cExtraPixelsTop = cExtraPixelsLeft = cExtraPixelsBottom = cExtraPixelsRight = 0;
            if (bInscribed == false && ((cWidth & 0xf) != 0))
            {
                cExtraPixelsRight = 0x10 - (cWidth & 0xF);
            }
            if (bInscribed == false && ((cHeight & 0xf) != 0))
            {
                cExtraPixelsBottom = 0x10 - (cHeight & 0xF);
            }

            //// tiling (note: if tiling is added check code in HDPhotoDecoder.CheckTilePos
            cNumOfSliceMinus1V = cNumOfSliceMinus1H = 0;

            if (((cWidth + cExtraPixelsLeft + cExtraPixelsRight) & 0xf) + ((cHeight + cExtraPixelsTop + cExtraPixelsBottom) & 0xf) != 0)
            {
                if (((cWidth & 0xf) + (cHeight & 0xf) + cExtraPixelsLeft + cExtraPixelsTop != 0) ||
                    (cWidth <= cExtraPixelsRight || cHeight <= cExtraPixelsBottom))
                {
                    throw new ArgumentOutOfRangeException("bitIO", "WMP_errInvalidParameter 07");
                }

                cWidth  -= cExtraPixelsRight;
                cHeight -= cExtraPixelsBottom;
            }
        }
        /// <summary>
        /// Reads header of image (p.33)
        /// </summary>
        /// <param name="bitIO">Stream to read the header from</param>
        private void ReadWMIHeader(SimpleBitIO bitIO)
        {
            // check signature
            for (int i=0; i<Constant.GDISignature.Length; i++)
            {
                if ((byte)bitIO.GetBit32_SB(8) != Constant.GDISignature[i])
                {
                    throw new ArgumentOutOfRangeException("bitIO", "GDISignature[" + i + "]");
                }
            }

            // check codec version and ignore subversion
            if (bitIO.GetBit32_SB(Constant.CodecVersionNumBits) != Constant.CodecVersion)
            {
                throw new ArgumentOutOfRangeException("bitIO", "CodecVersion");
            }

            // ignore subversion
            bitIO.GetBit32_SB(Constant.CodecVersionNumBits);

            // 9 primary parameters
            // tiling present
            bTilingPresent = bitIO.GetBit32_SB(Constant.TilingFlagNumBits) == 1;
            if (bTilingPresent)
            {
                throw new ArgumentOutOfRangeException("bitIO", "bTilingPresent = " + bTilingPresent);
            }

            // bitstream layout
            bfBitstreamFormat = (BITSTREAMFORMAT)bitIO.GetBit32_SB(Constant.BitStreamFormatNumBits);
            if (bfBitstreamFormat != BITSTREAMFORMAT.SPATIAL)
            {
                throw new ArgumentOutOfRangeException("bitIO", "bfBitstreamFormat = " + bfBitstreamFormat);
            }
            // presentation orientation
            // ORIENTATION oOrientation = bitIO.GetBit32_SB(Constant.OriantationNumBits);
            bitIO.GetBit32_SB(Constant.OriantationNumBits);

            // bool bIndexTable = bitIO.GetBit32_SB(Constant.IndexTablePresentFlagNumBits) == 1;
            bitIO.GetBit32_SB(Constant.IndexTablePresentFlagNumBits);

            // overlap
            olOverlap = (OVERLAP)bitIO.GetBit32_SB(Constant.OverlapNumBits);
            if (olOverlap == OVERLAP.OL_MAX)
            {
                throw new ArgumentOutOfRangeException("bitIO", "olOverlap = " + olOverlap);
            }

            // 11 some other parameters
            // short words for size and tiles
            bAbbreviatedHeader = bitIO.GetBit32_SB(Constant.ShortHeaderFlagNumBits) == 1;
            bitIO.GetBit32_SB(1);//pSCP->bdBitDepth = (BITDEPTH)GetBit32_SB(1); // long word
            bitIO.GetBit32_SB(1);//pSCP->bdBitDepth = BD_LONG; // remove when optimization is done
            // windowing
            bInscribed = bitIO.GetBit32_SB(Constant.WindowingFlagNumBits) == 1;
            if (bInscribed)
            {
                throw new ArgumentOutOfRangeException("bitIO", "bInscribed = " + bInscribed);
            }

            // trim flexbits flag
            bTrimFlexbitsFlag = bitIO.GetBit32_SB(Constant.TrimFlexbitsFlagNumBits) == 1;
            // tile stretching flag
            bTileStretch = bitIO.GetBit32_SB(Constant.TileStretchFlagNumBits) == 1;
            if (bTileStretch)
            {
                throw new ArgumentOutOfRangeException("bitIO", "bTileStretch = " + bTileStretch);
            }

            bitIO.GetBit32_SB(2);//GetBit32_SB(2);  // padding / reserved bits

            // 10 - informational
            bitIO.GetBit32_SB(4);//pII->cfColorFormat = GetBit32_SB(pSB, 4); // source color format
            // source bit depth
            bdBitDepth = (BITDEPTH_BITS)bitIO.GetBit32_SB(Constant.SourceBitDepthNumBits);
            // DEM Only
            if (bdBitDepth != BITDEPTH_BITS.BD_16S)
            {
                throw new ArgumentOutOfRangeException("bitIO", "bdBitDepth = " + bdBitDepth);
            }

            if (BITDEPTH_BITS.BD_1alt == bdBitDepth)
            {
                bdBitDepth = BITDEPTH_BITS.BD_1;
            }

            //// 12 - Variable length fields
            //// size
            cWidth  = bitIO.GetBit32_SB((uint)(bAbbreviatedHeader ? Constant.ShortHeaderNumBits : Constant.LongHeaderNumBits)) + 1;
            cHeight = bitIO.GetBit32_SB((uint)(bAbbreviatedHeader ? Constant.ShortHeaderNumBits : Constant.LongHeaderNumBits)) + 1;
            cExtraPixelsTop = cExtraPixelsLeft = cExtraPixelsBottom = cExtraPixelsRight = 0;
            if (bInscribed == false && ((cWidth & 0xf) != 0))
                cExtraPixelsRight = 0x10 - (cWidth & 0xF);
            if (bInscribed == false && ((cHeight & 0xf) != 0))
                cExtraPixelsBottom = 0x10 - (cHeight & 0xF);

            //// tiling (note: if tiling is added check code in HDPhotoDecoder.CheckTilePos
            cNumOfSliceMinus1V = cNumOfSliceMinus1H = 0;

            if(((cWidth + cExtraPixelsLeft + cExtraPixelsRight) & 0xf) + ((cHeight + cExtraPixelsTop + cExtraPixelsBottom) & 0xf) != 0)
            {
                if (((cWidth & 0xf) + (cHeight & 0xf) + cExtraPixelsLeft + cExtraPixelsTop != 0) ||
                    (cWidth <= cExtraPixelsRight || cHeight <= cExtraPixelsBottom))
                {
                    throw new ArgumentOutOfRangeException("bitIO", "WMP_errInvalidParameter 07");
                }

                cWidth -= cExtraPixelsRight;
                cHeight -= cExtraPixelsBottom;
            }
        }
            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;
            }