/// <summary>
 /// Load a residual layer bitmap into clearcode encoder.
 /// </summary>
 /// <param name = "subcodecBitmap"> specifies a subcodec layer image </param>
 /// <param name = "pos"> specifies position of subcodec layer image, relative to residual layer image </param>
 /// <param name = "sbcID"> specifies subcodec ID to encoding subcodec layer image </param>
 public void LoadSubcodecBitmap(Bitmap subcodecBitmap, RDPGFX_POINT16 pos, CLEARCODEC_SUBCODEC_ID sbcID)
 {
     if (subcodecBitmap != null)
     {
         ClearCodec_RECT16 scRect = new ClearCodec_RECT16();
         scRect.left   = pos.x;
         scRect.top    = pos.y;
         scRect.right  = (ushort)(pos.x + subcodecBitmap.Width);
         scRect.bottom = (ushort)(pos.x + subcodecBitmap.Height);
         BMP_INFO bmp_info = new BMP_INFO();
         bmp_info.bmp  = subcodecBitmap;
         bmp_info.scID = sbcID;
         this.subcodecDict.Add(scRect, bmp_info);
     }
 }
 /// <summary>
 /// Load a residual layer bitmap into clearcode encoder.   
 /// </summary>
 /// <param name = "subcodecBitmap"> specifies a subcodec layer image </param>
 /// <param name = "pos"> specifies position of subcodec layer image, relative to residual layer image </param>
 /// <param name = "sbcID"> specifies subcodec ID to encoding subcodec layer image </param>
 public void LoadSubcodecBitmap(Bitmap subcodecBitmap, RDPGFX_POINT16 pos, CLEARCODEC_SUBCODEC_ID sbcID)
 {
     if (subcodecBitmap != null)
     {
         ClearCodec_RECT16 scRect = new ClearCodec_RECT16();
         scRect.left = pos.x;
         scRect.top = pos.y;
         scRect.right = (ushort)(pos.x + subcodecBitmap.Width);
         scRect.bottom = (ushort)(pos.x + subcodecBitmap.Height);
         BMP_INFO bmp_info = new BMP_INFO();
         bmp_info.bmp = subcodecBitmap;
         bmp_info.scID = sbcID;
         this.subcodecDict.Add(scRect, bmp_info);
     }
 }
        public void RDPEGFX_ClearCodec_NegativeTest_SubCodecRLEX_IncorrectPlatteCount()
        {
            this.TestSite.Log.Add(LogEntryKind.Comment, "Do capability exchange.");
            // Init for capability exchange
            RDPEGFX_CapabilityExchange();

            this.TestSite.Log.Add(LogEntryKind.Comment, "Create a surface and fill it with green color.");
            // Create & output a surface
            RDPGFX_RECT16 surfRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.surfPos, RdpegfxTestUtility.surfWidth, RdpegfxTestUtility.surfHeight);
            Surface surf = this.rdpegfxAdapter.CreateAndOutputSurface(surfRect, PixelFormat.PIXEL_FORMAT_XRGB_8888);
            this.TestSite.Assert.IsNotNull(surf, "Surface {0} is created", surf.Id);

            // Send solid fill request to client to fill surface with green color
            RDPGFX_RECT16 fillSurfRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.imgPos, RdpegfxTestUtility.surfWidth, RdpegfxTestUtility.surfHeight);
            RDPGFX_RECT16[] fillRects = { fillSurfRect };  // Relative to surface
            uint fid = this.rdpegfxAdapter.SolidFillSurface(surf, RdpegfxTestUtility.fillColorGreen, fillRects);
            this.TestSite.Log.Add(LogEntryKind.Debug, "Surface is filled with solid color in frame: {0}", fid);
            this.rdpegfxAdapter.ExpectFrameAck(fid);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Encode Header/Data Messages to client.");
            // Init a subcodec bitmap for clearcodec RLEX encoding
            Image bgImage;
            BMP_INFO bmp_info = new BMP_INFO();
            bmp_info.scID = CLEARCODEC_SUBCODEC_ID.SUBCODEC_RLEX;
            bmp_info.bmp = (Bitmap)RdpegfxTestUtility.captureFromImage(testData.ClearCodecImage, RdpegfxTestUtility.imgPos,
                                                RdpegfxTestUtility.ccSubcodecWidth, RdpegfxTestUtility.ccSubcodecHeight, out bgImage);
            Dictionary<RDPGFX_POINT16, BMP_INFO> subcodecBmpDict = new Dictionary<RDPGFX_POINT16, BMP_INFO>();
            subcodecBmpDict.Add(RdpegfxTestUtility.imgPos, bmp_info);
            // Set clearcodec bitmap rectangle, relative to surface
            RDPGFX_RECT16 scRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.imgPos, RdpegfxTestUtility.surfWidth, RdpegfxTestUtility.surfHeight);
            // test type to instruct clearcodec encoder to add correct Palette Count with 1 in RLEX encoding
            this.rdpegfxAdapter.SetTestType(RdpegfxNegativeTypes.ClearCodec_Band_Subcodec_IncorrectPaletteCount);
            // Send encoded clearcodec bitmap data in w2s_1 PDU
            fid = this.rdpegfxAdapter.SendImageWithClearCodec(surf.Id, PixelFormat.PIXEL_FORMAT_XRGB_8888, ClearCodec_BitmapStream.CLEARCODEC_FLAG_NONE, 0,
                                                        fillSurfRect, null, null, subcodecBmpDict);
            // Test case pass if RDP connection is stopped due to incorrect Palette Count in RLEX encoding
            bool bDisconnected = this.rdpbcgrAdapter.WaitForDisconnection(waitTime);
            this.TestSite.Assert.IsTrue(bDisconnected, "Client is expected to drop the connection when sending a ClearCodec stream with incorrect palette count in subcodec layer.");
        }
        public void RDPEGFX_ClearCodec_NegativeTest_SubCodecRLEX_EncodedBytesTooMuch()
        {
            this.TestSite.Log.Add(LogEntryKind.Comment, "Do capability exchange.");
            // Init for capability exchange
            RDPEGFX_CapabilityExchange();

            this.TestSite.Log.Add(LogEntryKind.Comment, "Create a surface and fill it with green color.");
            // Create & output a surface
            RDPGFX_RECT16 surfRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.surfPos, RdpegfxTestUtility.surfWidth, RdpegfxTestUtility.surfHeight);
            Surface surf = this.rdpegfxAdapter.CreateAndOutputSurface(surfRect, PixelFormat.PIXEL_FORMAT_XRGB_8888);
            this.TestSite.Assert.IsNotNull(surf, "Surface {0} is created", surf.Id);

            // Send solid fill request to client to fill surface with green color
            RDPGFX_RECT16 fillSurfRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.imgPos, RdpegfxTestUtility.surfWidth, RdpegfxTestUtility.surfHeight);
            RDPGFX_RECT16[] fillRects = { fillSurfRect };  // Relative to surface
            uint fid = this.rdpegfxAdapter.SolidFillSurface(surf, RdpegfxTestUtility.fillColorGreen, fillRects);
            this.TestSite.Log.Add(LogEntryKind.Debug, "Surface is filled with solid color in frame: {0}", fid);
            this.rdpegfxAdapter.ExpectFrameAck(fid);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending ClearCodec Encoded Bitmap Messages with RLEX encoded bytes number larger than 3 * width * height to client.");
            // Set a subcodec bitmap with each pixel color is unique for clearcodec RLEX encoding
            BMP_INFO bmp_info = new BMP_INFO();
            bmp_info.scID = CLEARCODEC_SUBCODEC_ID.SUBCODEC_RLEX;
            bmp_info.bmp = (Bitmap)RdpegfxTestUtility.DrawImageWithUniqueColor(RdpegfxTestUtility.ccSubcodecWidth, RdpegfxTestUtility.ccSubcodecHeight, Color.Red);
            Dictionary<RDPGFX_POINT16, BMP_INFO> subcodecBmpDict = new Dictionary<RDPGFX_POINT16, BMP_INFO>();
            subcodecBmpDict.Add(RdpegfxTestUtility.imgPos, bmp_info);
            // Set clearcodec bitmap rectangle, relative to surface
            RDPGFX_RECT16 scRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.imgPos, RdpegfxTestUtility.ccSubcodecWidth, RdpegfxTestUtility.ccSubcodecHeight);
            // Send encoded clearcodec bitmap data in w2s_1 PDU
            fid = this.rdpegfxAdapter.SendImageWithClearCodec(surf.Id, PixelFormat.PIXEL_FORMAT_XRGB_8888, ClearCodec_BitmapStream.CLEARCODEC_FLAG_NONE, 0,
                                                        scRect, null, null, subcodecBmpDict);
            // Test case pass if RDP connection is stopped due to RLEX encoded bytes is larger than 3 * width * height in subcodec layer.
            bool bDisconnected = this.rdpbcgrAdapter.WaitForDisconnection(waitTime);
            this.TestSite.Assert.IsTrue(bDisconnected, "Client is expected to drop the connection when sending a ClearCodec stream with RLEX encoded bytes larger than 3 * width * height in subcodec layer.");
        }
        public void RDPEGFX_ClearCodec_PositiveTest_Subcodec_MaxPlatteColor()
        {
            this.TestSite.Log.Add(LogEntryKind.Comment, "Do capability exchange.");
            // Init for capability exchange
            RDPEGFX_CapabilityExchange();

            this.TestSite.Log.Add(LogEntryKind.Comment, "Create a surface and fill it with green color.");
            // Create & output a surface
            RDPGFX_RECT16 surfRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.surfPos, RdpegfxTestUtility.surfWidth3, RdpegfxTestUtility.surfHeight3);
            Surface surf = this.rdpegfxAdapter.CreateAndOutputSurface(surfRect, PixelFormat.PIXEL_FORMAT_XRGB_8888);
            this.TestSite.Assert.IsNotNull(surf, "Surface {0} is created", surf.Id);

            // Send solid fill request to client to fill surface with green color
            RDPGFX_RECT16 fillSurfRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.imgPos, RdpegfxTestUtility.surfWidth3, RdpegfxTestUtility.surfHeight3);
            RDPGFX_RECT16[] fillRects = { fillSurfRect };  // Relative to surface
            uint fid = this.rdpegfxAdapter.SolidFillSurface(surf, RdpegfxTestUtility.fillColorGreen, fillRects);
            this.TestSite.Log.Add(LogEntryKind.Debug, "Surface is filled with solid color in frame: {0}", fid);
            this.rdpegfxAdapter.ExpectFrameAck(fid);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending ClearCodec Encoded Subcodec layer Bitmap(max colors in palette) Messages to client.");
            // Init a subcodec bitmap with max(127) type of color
            BMP_INFO bmp_info = new BMP_INFO();
            bmp_info.scID = CLEARCODEC_SUBCODEC_ID.SUBCODEC_RLEX;
            bmp_info.bmp = RdpegfxTestUtility.DrawGradientImage(RdpegfxTestUtility.ccSubcodecMaxWidth, RdpegfxTestUtility.ccSubcodecHeight, Color.Red);
            Dictionary<RDPGFX_POINT16, BMP_INFO> subcodecBmpDict = new Dictionary<RDPGFX_POINT16, BMP_INFO>();
            subcodecBmpDict.Add(RdpegfxTestUtility.imgPos, bmp_info);
            // Set clearcodec subcodec layer bitmap rectangle, relative to surface
            RDPGFX_RECT16 scRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.imgPos, RdpegfxTestUtility.ccSubcodecMaxWidth, RdpegfxTestUtility.ccSubcodecHeight);
            // Send encoded clearcodec bitmap data in w2s_1 PDU
            fid = this.rdpegfxAdapter.SendImageWithClearCodec(surf.Id, PixelFormat.PIXEL_FORMAT_XRGB_8888, ClearCodec_BitmapStream.CLEARCODEC_FLAG_NONE, 0,
                                                        scRect, null, null, subcodecBmpDict);
            // Test case pass if frame acknowledge is received.
            this.rdpegfxAdapter.ExpectFrameAck(fid);

            // Delete the surface
            this.rdpegfxAdapter.DeleteSurface(surf.Id);
            this.TestSite.Log.Add(LogEntryKind.Debug, "Surface {0} is deleted", surf.Id);
        }
        public void RDPEGFX_ClearCodec_PositiveTest_SubCodecUncompressed()
        {
            this.TestSite.Log.Add(LogEntryKind.Comment, "Do capability exchange.");
            // Init for capability exchange
            RDPEGFX_CapabilityExchange();

            this.TestSite.Log.Add(LogEntryKind.Comment, "Create a surface and fill it with green color.");
            // Create & output a surface
            RDPGFX_RECT16 surfRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.surfPos, RdpegfxTestUtility.surfWidth, RdpegfxTestUtility.surfHeight);
            Surface surf = this.rdpegfxAdapter.CreateAndOutputSurface(surfRect, PixelFormat.PIXEL_FORMAT_XRGB_8888);
            this.TestSite.Assert.IsNotNull(surf, "Surface {0} is created", surf.Id);

            // Send solid fill request to client to fill surface with green color
            RDPGFX_RECT16 fillSurfRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.imgPos, RdpegfxTestUtility.surfWidth, RdpegfxTestUtility.surfHeight);
            RDPGFX_RECT16[] fillRects = { fillSurfRect };  // Relative to surface
            uint fid = this.rdpegfxAdapter.SolidFillSurface(surf, RdpegfxTestUtility.fillColorGreen, fillRects);
            this.TestSite.Log.Add(LogEntryKind.Debug, "Surface is filled with solid color in frame: {0}", fid);
            this.rdpegfxAdapter.ExpectFrameAck(fid);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending ClearCodec Encoded Bitmap Data Messages(with raw format in subcodec layer) to client.");
            // Set clearcodec residual layer and subcodec layer bitmap
            Image bgImage;
            BMP_INFO bmp_info = new BMP_INFO();
            bmp_info.scID = CLEARCODEC_SUBCODEC_ID.SUBCODEC_RAW;  // Set subcodec layer bitmap to be encoded in raw format
            bmp_info.bmp = (Bitmap)RdpegfxTestUtility.captureFromImage(testData.ClearCodecImage, RdpegfxTestUtility.imgPos,
                                                RdpegfxTestUtility.ccSubcodecWidth, RdpegfxTestUtility.ccSubcodecHeight, out bgImage);

            Dictionary<RDPGFX_POINT16, BMP_INFO> subcodecBmpDict = new Dictionary<RDPGFX_POINT16, BMP_INFO>();
            subcodecBmpDict.Add(RdpegfxTestUtility.imgPos, bmp_info);
            // Set clearcodec bitmap rectangle, relative to surface
            RDPGFX_RECT16 ccRect = RdpegfxTestUtility.ConvertToRect(RdpegfxTestUtility.imgPos, (ushort)bgImage.Width, (ushort)bgImage.Height);
            // Send encoded clearcodec bitmap data in w2s_1 PDU
            fid = this.rdpegfxAdapter.SendImageWithClearCodec(surf.Id, PixelFormat.PIXEL_FORMAT_XRGB_8888, ClearCodec_BitmapStream.CLEARCODEC_FLAG_NONE, 0,
                                                        ccRect, (Bitmap)bgImage, null, subcodecBmpDict);
            // Test case pass if frame acknowledge is received.
            this.rdpegfxAdapter.ExpectFrameAck(fid);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Verify output on SUT Display if the verifySUTDisplay entry in PTF config is true.");
            this.VerifySUTDisplay(false, surfRect);

            // Delete the surface
            this.rdpegfxAdapter.DeleteSurface(surf.Id);
            this.TestSite.Log.Add(LogEntryKind.Debug, "Surface {0} is deleted", surf.Id);
        }