Microsoft.Protocols.TestTools.StackSdk.RemoteDesktop.Rdpbcgr.RdpbcgrDecoder.ParseTsBitmapData C# (CSharp) Method

ParseTsBitmapData() private method

Parse TS_BITMAP_DATA (parser index is updated according to parsed length)
private ParseTsBitmapData ( byte data, int &currentIndex ) : TS_BITMAP_DATA
data byte data to be parsed
currentIndex int current parser index
return TS_BITMAP_DATA
        private TS_BITMAP_DATA ParseTsBitmapData(byte[] data, ref int currentIndex)
        {
            TS_BITMAP_DATA bitmapData = new TS_BITMAP_DATA();

            // TS_BITMAP_DATA: destLeft
            bitmapData.destLeft = ParseUInt16(data, ref currentIndex, false);

            // TS_BITMAP_DATA: destTop
            bitmapData.destTop = ParseUInt16(data, ref currentIndex, false);

            // TS_BITMAP_DATA: destRight
            bitmapData.destRight = ParseUInt16(data, ref currentIndex, false);

            // TS_BITMAP_DATA: destBottom
            bitmapData.destBottom = ParseUInt16(data, ref currentIndex, false);

            // TS_BITMAP_DATA: width
            bitmapData.width = ParseUInt16(data, ref currentIndex, false);

            // TS_BITMAP_DATA: height
            bitmapData.height = ParseUInt16(data, ref currentIndex, false);

            // TS_BITMAP_DATA: bitsPerPixel
            bitmapData.bitsPerPixel = ParseUInt16(data, ref currentIndex, false);

            // TS_BITMAP_DATA: Flags
            bitmapData.Flags = (TS_BITMAP_DATA_Flags_Values)ParseUInt16(data, ref currentIndex, false);

            // TS_BITMAP_DATA: bitmapLength
            bitmapData.bitmapLength = ParseUInt16(data, ref currentIndex, false);

            // 32bpp is not supported
            if (bitmapData.bitsPerPixel == ConstValue.BITS_PER_PIXEL_32)
            {
                throw new NotSupportedException("32bpp compressed bitmaps are not supported!");
            }

            // If header is absent
            if (IsFlagExist((UInt16)bitmapData.Flags, (UInt16)TS_BITMAP_DATA_Flags_Values.NO_BITMAP_COMPRESSION_HDR))
            {
                // TS_BITMAP_DATA: bitmapDataStream
                bitmapData.bitmapDataStream = GetBytes(data, ref currentIndex, bitmapData.bitmapLength);
            }
            else
            {
                // reserve current parser index
                int reservedIndex = currentIndex;

                // TS_BITMAP_DATA: bitmapComprHdr
                bitmapData.bitmapComprHdr = ParseTsCdHeader(data, ref currentIndex);

                // TS_BITMAP_DATA: bitmapDataStream
                int remainLength = bitmapData.bitmapLength - (currentIndex - reservedIndex);
                bitmapData.bitmapDataStream = GetBytes(data, ref currentIndex, remainLength);
            }

            // Decompress if bitmapData were compressed
            if (IsFlagExist((UInt16)bitmapData.Flags, (UInt16)TS_BITMAP_DATA_Flags_Values.BITMAP_COMPRESSION))
            {
                RleDecompressor.Decompress(
                    bitmapData.bitmapDataStream,
                    (ColorDepth)bitmapData.bitsPerPixel,
                    bitmapData.width,
                    bitmapData.height);
            }
            return bitmapData;
        }
RdpbcgrDecoder