Fixed rectangle clipping and warnings.
authorArmin Novak <armin.novak@thincast.com>
Mon, 18 Jul 2016 10:36:22 +0000 (12:36 +0200)
committerArmin Novak <armin.novak@thincast.com>
Thu, 6 Oct 2016 11:43:02 +0000 (13:43 +0200)
12 files changed:
client/X11/xf_gdi.c
client/X11/xf_gdi.h
client/X11/xf_graphics.c
include/freerdp/gdi/gdi.h
libfreerdp/codec/test/TestFreeRDPCodecClear.c
libfreerdp/gdi/gdi.c
libfreerdp/gdi/graphics.c
libfreerdp/gdi/region.c
libfreerdp/gdi/test/TestGdiBitBlt.c
libfreerdp/gdi/test/TestGdiCreate.c
libfreerdp/gdi/test/TestGdiEllipse.c
libfreerdp/gdi/test/TestGdiLine.c

index fdca10d..70cf4d5 100644 (file)
@@ -218,58 +218,6 @@ BOOL xf_set_rop3(xfContext* xfc, int rop3)
        return TRUE;
 }
 
-UINT32 xf_convert_rdp_order_color(xfContext* xfc, UINT32 color)
-{
-       BYTE r = 0, g = 0, b = 0;
-
-       switch (xfc->srcBpp)
-       {
-               case 32:
-               case 24:
-                       if (xfc->visual->red_mask == 0xFF0000 &&
-                           xfc->visual->green_mask == 0xFF00 &&
-                           xfc->visual->blue_mask == 0xFF)
-                       {
-                               return color;
-                       }
-
-                       color = GetColor(xfc->format, r, g, b, 0xFF);
-                       break;
-
-               case 16:
-                       color = (color & 0xFF00) | ((color >> 16) & 0xFF);
-
-                       if (xfc->visual->red_mask == 0xF800 &&
-                           xfc->visual->green_mask == 0x07E0 &&
-                           xfc->visual->blue_mask == 0x001F)
-                       {
-                               return color;
-                       }
-
-                       color = GetColor(xfc->format, r, g, b, 0xFF);
-                       break;
-
-               case 15:
-                       color = (color & 0xFF00) | ((color >> 16) & 0xFF);
-                       color = GetColor(xfc->format, r, g, b, 0xFF);
-                       break;
-
-               case 8:
-                       color = (color >> 16) & (UINT32) 0xFF;
-                       UINT32 dstColor = xfc->context.gdi->palette.palette[color];
-                       SplitColor(dstColor, xfc->format, &r, &g, &b,
-                                  NULL, NULL);
-                       break;
-
-               default:
-                       return color;
-       }
-
-       return (((r >> xfc->red_shift_r) << xfc->red_shift_l) |
-               ((g >> xfc->green_shift_r) << xfc->green_shift_l) |
-               ((b >> xfc->blue_shift_r) << xfc->blue_shift_l));
-}
-
 Pixmap xf_brush_new(xfContext* xfc, int width, int height, int bpp, BYTE* data)
 {
        GC gc;
@@ -487,11 +435,16 @@ static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
        UINT32 backColor;
        xfContext* xfc = (xfContext*) context;
        BOOL ret = TRUE;
+
+       if (!gdi_decode_color(context->gdi, patblt->foreColor, &foreColor, NULL))
+               return FALSE;
+
+       if (!gdi_decode_color(context->gdi, patblt->backColor, &backColor, NULL))
+               return FALSE;
+
        xf_lock_x11(xfc, FALSE);
        brush = &patblt->brush;
        xf_set_rop3(xfc, gdi_rop3_code(patblt->bRop));
-       foreColor = xf_convert_rdp_order_color(xfc, patblt->foreColor);
-       backColor = xf_convert_rdp_order_color(xfc, patblt->backColor);
 
        if (brush->style == GDI_BS_SOLID)
        {
@@ -671,9 +624,12 @@ static BOOL xf_gdi_line_to(rdpContext* context, const LINE_TO_ORDER* line_to)
        UINT32 color;
        xfContext* xfc = (xfContext*) context;
        BOOL ret = TRUE;
+
+       if (!gdi_decode_color(context->gdi, line_to->penColor, &color, NULL))
+               return FALSE;
+
        xf_lock_x11(xfc, FALSE);
        xf_set_rop2(xfc, line_to->bRop2);
-       color = xf_convert_rdp_order_color(xfc, line_to->penColor);
        XSetFillStyle(xfc->display, xfc->gc, FillSolid);
        XSetForeground(xfc->display, xfc->gc, color);
        XDrawLine(xfc->display, xfc->drawing, xfc->gc,
@@ -738,9 +694,12 @@ static BOOL xf_gdi_polyline(rdpContext* context,
        XPoint* points;
        xfContext* xfc = (xfContext*) context;
        BOOL ret = TRUE;
+
+       if (!gdi_decode_color(context->gdi, polyline->penColor, &color, NULL))
+               return FALSE;
+
        xf_lock_x11(xfc, FALSE);
        xf_set_rop2(xfc, polyline->bRop2);
-       color = xf_convert_rdp_order_color(xfc, polyline->penColor);
        XSetFillStyle(xfc->display, xfc->gc, FillSolid);
        XSetForeground(xfc->display, xfc->gc, color);
        npoints = polyline->numDeltaEntries + 1;
@@ -818,12 +777,16 @@ static BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
        if (!xfc->display || !xfc->drawing)
                return FALSE;
 
+       if (!gdi_decode_color(context->gdi, mem3blt->foreColor, &foreColor, NULL))
+               return FALSE;
+
+       if (!gdi_decode_color(context->gdi, mem3blt->backColor, &backColor, NULL))
+               return FALSE;
+
        xf_lock_x11(xfc, FALSE);
        brush = &mem3blt->brush;
        bitmap = (xfBitmap*) mem3blt->bitmap;
        xf_set_rop3(xfc, gdi_rop3_code(mem3blt->bRop));
-       foreColor = xf_convert_rdp_order_color(xfc, mem3blt->foreColor);
-       backColor = xf_convert_rdp_order_color(xfc, mem3blt->backColor);
 
        if (brush->style == GDI_BS_PATTERN)
        {
@@ -884,9 +847,12 @@ static BOOL xf_gdi_polygon_sc(rdpContext* context,
        UINT32 brush_color;
        xfContext* xfc = (xfContext*) context;
        BOOL ret = TRUE;
+
+       if (!gdi_decode_color(context->gdi, polygon_sc->brushColor, &brush_color, NULL))
+               return FALSE;
+
        xf_lock_x11(xfc, FALSE);
        xf_set_rop2(xfc, polygon_sc->bRop2);
-       brush_color = xf_convert_rdp_order_color(xfc, polygon_sc->brushColor);
        npoints = polygon_sc->numPoints + 1;
        points = malloc(sizeof(XPoint) * npoints);
 
@@ -948,11 +914,16 @@ static BOOL xf_gdi_polygon_cb(rdpContext* context,
        UINT32 backColor;
        xfContext* xfc = (xfContext*) context;
        BOOL ret = TRUE;
+
+       if (!gdi_decode_color(context->gdi, polygon_cb->foreColor, &foreColor, NULL))
+               return FALSE;
+
+       if (!gdi_decode_color(context->gdi, polygon_cb->backColor, &backColor, NULL))
+               return FALSE;
+
        xf_lock_x11(xfc, FALSE);
        brush = &(polygon_cb->brush);
        xf_set_rop2(xfc, polygon_cb->bRop2);
-       foreColor = xf_convert_rdp_order_color(xfc, polygon_cb->foreColor);
-       backColor = xf_convert_rdp_order_color(xfc, polygon_cb->backColor);
        npoints = polygon_cb->numPoints + 1;
        points = malloc(sizeof(XPoint) * npoints);
 
index f2d7794..f300d7b 100644 (file)
@@ -28,7 +28,7 @@
 #include "xfreerdp.h"
 
 void xf_gdi_register_update_callbacks(rdpUpdate* update);
-BOOL xf_gdi_bitmap_update(rdpContext* context, const BITMAP_UPDATE* bitmapUpdate);
-UINT32 xf_convert_rdp_order_color(xfContext* xfc, UINT32 color);
+BOOL xf_gdi_bitmap_update(rdpContext* context,
+                          const BITMAP_UPDATE* bitmapUpdate);
 
 #endif /* __XF_GDI_H */
index f6f2192..db8ae2d 100644 (file)
@@ -396,8 +396,13 @@ static BOOL xf_Glyph_BeginDraw(rdpContext* context, UINT32 x, UINT32 y,
                                UINT32 fgcolor, BOOL fOpRedundant)
 {
        xfContext* xfc = (xfContext*) context;
-       bgcolor = xf_convert_rdp_order_color(xfc, bgcolor);
-       fgcolor = xf_convert_rdp_order_color(xfc, fgcolor);
+
+       if (!gdi_decode_color(context->gdi, bgcolor, &bgcolor, NULL))
+               return FALSE;
+
+       if (!gdi_decode_color(context->gdi, fgcolor, &fgcolor, NULL))
+               return FALSE;
+
        xf_lock_x11(xfc, FALSE);
        XSetFunction(xfc->display, xfc->gc, GXcopy);
 
index 2ec7357..cf3ffcb 100644 (file)
@@ -312,11 +312,13 @@ extern "C" {
 
 FREERDP_API DWORD gdi_rop3_code(BYTE code);
 FREERDP_API UINT32 gdi_get_pixel_format(UINT32 bitsPerPixel, BOOL vFlip);
+FREERDP_API BOOL gdi_decode_color(rdpGdi* gdi, const UINT32 srcColor,
+                                  UINT32* color, UINT32* format);
 FREERDP_API BYTE* gdi_get_bitmap_pointer(HGDI_DC hdcBmp, UINT32 x, UINT32 y);
 FREERDP_API BYTE* gdi_get_brush_pointer(HGDI_DC hdcBrush, UINT32 x, UINT32 y);
 FREERDP_API BOOL gdi_resize(rdpGdi* gdi, UINT32 width, UINT32 height);
 FREERDP_API BOOL gdi_resize_ex(rdpGdi* gdi, UINT32 width, UINT32 height,
-                               INT32 stride, INT32 format, BYTE* buffer,
+                               UINT32 stride, UINT32 format, BYTE* buffer,
                                void (*pfree)(void*));
 FREERDP_API BOOL gdi_init(freerdp* instance, UINT32 format);
 FREERDP_API BOOL gdi_init_ex(freerdp* instance, UINT32 format,
index b726d64..75b24df 100644 (file)
@@ -6,36 +6,36 @@
 static BYTE TEST_CLEAR_EXAMPLE_1[] = "\x03\xc3\x11\x00";
 
 static BYTE TEST_CLEAR_EXAMPLE_2[] =
-       "\x00\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x82\x00\x00\x00\x00\x00"
-       "\x00\x00\x4e\x00\x11\x00\x75\x00\x00\x00\x02\x0e\xff\xff\xff\x00"
-       "\x00\x00\xdb\xff\xff\x00\x3a\x90\xff\xb6\x66\x66\xb6\xff\xb6\x66"
-       "\x00\x90\xdb\xff\x00\x00\x3a\xdb\x90\x3a\x3a\x90\xdb\x66\x00\x00"
-       "\xff\xff\xb6\x64\x64\x64\x11\x04\x11\x4c\x11\x4c\x11\x4c\x11\x4c"
-       "\x11\x4c\x00\x47\x13\x00\x01\x01\x04\x00\x01\x00\x00\x47\x16\x00"
-       "\x11\x02\x00\x47\x29\x00\x11\x01\x00\x49\x0a\x00\x01\x00\x04\x00"
-       "\x01\x00\x00\x4a\x0a\x00\x09\x00\x01\x00\x00\x47\x05\x00\x01\x01"
-       "\x1c\x00\x01\x00\x11\x4c\x11\x4c\x11\x4c\x00\x47\x0d\x4d\x00\x4d";
+    "\x00\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x82\x00\x00\x00\x00\x00"
+    "\x00\x00\x4e\x00\x11\x00\x75\x00\x00\x00\x02\x0e\xff\xff\xff\x00"
+    "\x00\x00\xdb\xff\xff\x00\x3a\x90\xff\xb6\x66\x66\xb6\xff\xb6\x66"
+    "\x00\x90\xdb\xff\x00\x00\x3a\xdb\x90\x3a\x3a\x90\xdb\x66\x00\x00"
+    "\xff\xff\xb6\x64\x64\x64\x11\x04\x11\x4c\x11\x4c\x11\x4c\x11\x4c"
+    "\x11\x4c\x00\x47\x13\x00\x01\x01\x04\x00\x01\x00\x00\x47\x16\x00"
+    "\x11\x02\x00\x47\x29\x00\x11\x01\x00\x49\x0a\x00\x01\x00\x04\x00"
+    "\x01\x00\x00\x4a\x0a\x00\x09\x00\x01\x00\x00\x47\x05\x00\x01\x01"
+    "\x1c\x00\x01\x00\x11\x4c\x11\x4c\x11\x4c\x00\x47\x0d\x4d\x00\x4d";
 
 static BYTE TEST_CLEAR_EXAMPLE_3[] =
-       "\x00\xdf\x0e\x00\x00\x00\x8b\x00\x00\x00\x00\x00\x00\x00\xfe\xfe"
-       "\xfe\xff\x80\x05\xff\xff\xff\x40\xfe\xfe\xfe\x40\x00\x00\x3f\x00"
-       "\x03\x00\x0b\x00\xfe\xfe\xfe\xc5\xd0\xc6\xd0\xc7\xd0\x68\xd4\x69"
-       "\xd4\x6a\xd4\x6b\xd4\x6c\xd4\x6d\xd4\x1a\xd4\x1a\xd4\xa6\xd0\x6e"
-       "\xd4\x6f\xd4\x70\xd4\x71\xd4\x72\xd4\x73\xd4\x74\xd4\x21\xd4\x22"
-       "\xd4\x23\xd4\x24\xd4\x25\xd4\xd9\xd0\xda\xd0\xdb\xd0\xc5\xd0\xc5"
-       "\xd0\xdc\xd0\xc2\xd0\x21\xd4\x22\xd4\x23\xd4\x24\xd4\x25\xd4\xc9"
-       "\xd0\xca\xd0\x5a\xd4\x2b\xd1\x28\xd1\x2c\xd1\x75\xd4\x27\xd4\x28"
-       "\xd4\x29\xd4\x2a\xd4\x1a\xd4\x1a\xd4\x1a\xd4\xb7\xd0\xb8\xd0\xb9"
-       "\xd0\xba\xd0\xbb\xd0\xbc\xd0\xbd\xd0\xbe\xd0\xbf\xd0\xc0\xd0\xc1"
-       "\xd0\xc2\xd0\xc3\xd0\xc4\xd0";
+    "\x00\xdf\x0e\x00\x00\x00\x8b\x00\x00\x00\x00\x00\x00\x00\xfe\xfe"
+    "\xfe\xff\x80\x05\xff\xff\xff\x40\xfe\xfe\xfe\x40\x00\x00\x3f\x00"
+    "\x03\x00\x0b\x00\xfe\xfe\xfe\xc5\xd0\xc6\xd0\xc7\xd0\x68\xd4\x69"
+    "\xd4\x6a\xd4\x6b\xd4\x6c\xd4\x6d\xd4\x1a\xd4\x1a\xd4\xa6\xd0\x6e"
+    "\xd4\x6f\xd4\x70\xd4\x71\xd4\x72\xd4\x73\xd4\x74\xd4\x21\xd4\x22"
+    "\xd4\x23\xd4\x24\xd4\x25\xd4\xd9\xd0\xda\xd0\xdb\xd0\xc5\xd0\xc5"
+    "\xd0\xdc\xd0\xc2\xd0\x21\xd4\x22\xd4\x23\xd4\x24\xd4\x25\xd4\xc9"
+    "\xd0\xca\xd0\x5a\xd4\x2b\xd1\x28\xd1\x2c\xd1\x75\xd4\x27\xd4\x28"
+    "\xd4\x29\xd4\x2a\xd4\x1a\xd4\x1a\xd4\x1a\xd4\xb7\xd0\xb8\xd0\xb9"
+    "\xd0\xba\xd0\xbb\xd0\xbc\xd0\xbd\xd0\xbe\xd0\xbf\xd0\xc0\xd0\xc1"
+    "\xd0\xc2\xd0\xc3\xd0\xc4\xd0";
 
 static BYTE TEST_CLEAR_EXAMPLE_4[] =
-       "\x01\x0b\x78\x00\x00\x00\x00\x00\x46\x00\x00\x00\x00\x00\x00\x00"
-       "\x00\x00\x06\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x0f\xff\xff\xff"
-       "\xff\xff\xff\xff\xff\xff\xb6\xff\xff\xff\xff\xff\xff\xff\xff\xff"
-       "\xb6\x66\xff\xff\xff\xff\xff\xff\xff\xb6\x66\xdb\x90\x3a\xff\xff"
-       "\xb6\xff\xff\xff\xff\xff\xff\xff\xff\xff\x46\x91\x47\x91\x48\x91"
-       "\x49\x91\x4a\x91\x1b\x91";
+    "\x01\x0b\x78\x00\x00\x00\x00\x00\x46\x00\x00\x00\x00\x00\x00\x00"
+    "\x00\x00\x06\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x0f\xff\xff\xff"
+    "\xff\xff\xff\xff\xff\xff\xb6\xff\xff\xff\xff\xff\xff\xff\xff\xff"
+    "\xb6\x66\xff\xff\xff\xff\xff\xff\xff\xb6\x66\xdb\x90\x3a\xff\xff"
+    "\xb6\xff\xff\xff\xff\xff\xff\xff\xff\xff\x46\x91\x47\x91\x48\x91"
+    "\x49\x91\x4a\x91\x1b\x91";
 
 static int test_ClearDecompressExample1(void)
 {
@@ -44,20 +44,14 @@ static int test_ClearDecompressExample1(void)
        UINT32 SrcSize;
        BYTE pDstData[16384];
        CLEAR_CONTEXT* clear;
-
        clear = clear_context_new(FALSE);
-
        SrcSize = sizeof(TEST_CLEAR_EXAMPLE_1) - 1;
        pSrcData = (BYTE*) TEST_CLEAR_EXAMPLE_1;
-
        status = clear_decompress(clear, pSrcData, SrcSize, 0, 0,
-                                 pDstData, PIXEL_FORMAT_XRGB32, 64 * 4, 1, 1, 64, 64,
-                                 NULL);
-
+                                 pDstData, PIXEL_FORMAT_XRGB32, 64 * 4, 1, 1, 64, 64,
+                                 NULL);
        printf("clear_decompress example 1 status: %d\n", status);
-
        clear_context_free(clear);
-
        return status;
 }
 
@@ -68,20 +62,14 @@ static int test_ClearDecompressExample2(void)
        UINT32 SrcSize;
        BYTE* pDstData = NULL;
        CLEAR_CONTEXT* clear;
-
        clear = clear_context_new(FALSE);
-
        SrcSize = sizeof(TEST_CLEAR_EXAMPLE_2) - 1;
        pSrcData = (BYTE*) TEST_CLEAR_EXAMPLE_2;
-
        status = clear_decompress(clear, pSrcData, SrcSize, 0, 0,
-                                 pDstData, PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0,
-                                 NULL);
-
+                                 pDstData, PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0,
+                                 NULL);
        printf("clear_decompress example 2 status: %d\n", status);
-
        clear_context_free(clear);
-
        return status;
 }
 
@@ -92,20 +80,14 @@ static int test_ClearDecompressExample3(void)
        UINT32 SrcSize;
        BYTE* pDstData = NULL;
        CLEAR_CONTEXT* clear;
-
        clear = clear_context_new(FALSE);
-
        SrcSize = sizeof(TEST_CLEAR_EXAMPLE_3) - 1;
        pSrcData = (BYTE*) TEST_CLEAR_EXAMPLE_3;
-
        status = clear_decompress(clear, pSrcData, SrcSize, 0, 0,
-                                         pDstData, PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0,
-                                         NULL);
-
+                                 pDstData, PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0,
+                                 NULL);
        printf("clear_decompress example 3 status: %d\n", status);
-
        clear_context_free(clear);
-
        return status;
 }
 
@@ -116,37 +98,32 @@ static int test_ClearDecompressExample4(void)
        UINT32 SrcSize;
        BYTE* pDstData = NULL;
        CLEAR_CONTEXT* clear;
-
        clear = clear_context_new(FALSE);
-
        SrcSize = sizeof(TEST_CLEAR_EXAMPLE_4) - 1;
        pSrcData = (BYTE*) TEST_CLEAR_EXAMPLE_4;
-
        status = clear_decompress(clear, pSrcData, SrcSize, 0, 0,
-                                         pDstData, PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0,
-                                         NULL);
-
+                                 pDstData, PIXEL_FORMAT_XRGB32, 0, 0, 0, 0, 0,
+                                 NULL);
        printf("clear_decompress example 4 status: %d\n", status);
-
        clear_context_free(clear);
-
        return status;
 }
 
 int TestFreeRDPCodecClear(int argc, char* argv[])
 {
-       /* TODO: These samples are not working at all...
        if (test_ClearDecompressExample1())
                return -1;
+
        if (test_ClearDecompressExample2())
                return -1;
+
        if (test_ClearDecompressExample3())
                return -1;
+
        if (test_ClearDecompressExample4())
                return -1;
-       */
-       fprintf(stderr, "TODO: %s not implemented!!!\n", __FUNCTION__);
 
+       fprintf(stderr, "TODO: %s not implemented!!!\n", __FUNCTION__);
        return 0;
 }
 
index 80d2db2..e4ef48c 100644 (file)
@@ -318,8 +318,8 @@ static const BYTE GDI_BS_HATCHED_PATTERNS[] =
        0x7E, 0xBD, 0xDB, 0xE7, 0xE7, 0xDB, 0xBD, 0x7E /* HS_DIACROSS */
 };
 
-static INLINE BOOL decode_color(rdpGdi* gdi, const UINT32 srcColor,
-                                UINT32* color, UINT32* format)
+INLINE BOOL gdi_decode_color(rdpGdi* gdi, const UINT32 srcColor,
+                             UINT32* color, UINT32* format)
 {
        UINT32 SrcFormat = gdi_get_pixel_format(gdi->context->settings->ColorDepth,
                                                FALSE);
@@ -574,7 +574,12 @@ static BOOL gdi_set_bounds(rdpContext* context, const rdpBounds* bounds)
 
 static BOOL gdi_dstblt(rdpContext* context, const DSTBLT_ORDER* dstblt)
 {
-       rdpGdi* gdi = context->gdi;
+       rdpGdi* gdi;
+
+       if (!context || !dstblt)
+               return FALSE;
+
+       gdi = context->gdi;
        return gdi_BitBlt(gdi->drawing->hdc, dstblt->nLeftRect, dstblt->nTopRect,
                          dstblt->nWidth, dstblt->nHeight, NULL, 0, 0,
                          gdi_rop3_code(dstblt->bRop), &gdi->palette);
@@ -593,10 +598,10 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
        UINT32 nXSrc = 0;
        UINT32 nYSrc = 0;
 
-       if (!decode_color(gdi, patblt->foreColor, &foreColor, NULL))
+       if (!gdi_decode_color(gdi, patblt->foreColor, &foreColor, NULL))
                return FALSE;
 
-       if (!decode_color(gdi, patblt->backColor, &backColor, NULL))
+       if (!gdi_decode_color(gdi, patblt->backColor, &backColor, NULL))
                return FALSE;
 
        originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);
@@ -778,7 +783,7 @@ static BOOL gdi_opaque_rect(rdpContext* context,
        gdi_CRgnToRect(opaque_rect->nLeftRect, opaque_rect->nTopRect,
                       opaque_rect->nWidth, opaque_rect->nHeight, &rect);
 
-       if (!decode_color(gdi, opaque_rect->color, &brush_color, NULL))
+       if (!gdi_decode_color(gdi, opaque_rect->color, &brush_color, NULL))
                return FALSE;
 
        if (!(hBrush = gdi_CreateSolidBrush(brush_color)))
@@ -799,7 +804,7 @@ static BOOL gdi_multi_opaque_rect(rdpContext* context,
        rdpGdi* gdi = context->gdi;
        BOOL ret = TRUE;
 
-       if (!decode_color(gdi, multi_opaque_rect->color, &brush_color, NULL))
+       if (!gdi_decode_color(gdi, multi_opaque_rect->color, &brush_color, NULL))
                return FALSE;
 
        hBrush = gdi_CreateSolidBrush(brush_color);
@@ -826,7 +831,7 @@ static BOOL gdi_line_to(rdpContext* context, const LINE_TO_ORDER* lineTo)
        UINT32 SrcFormat;
        rdpGdi* gdi = context->gdi;
 
-       if (!decode_color(gdi, lineTo->backColor, &color, &SrcFormat))
+       if (!gdi_decode_color(gdi, lineTo->backColor, &color, &SrcFormat))
                return FALSE;
 
        if (!(hPen = gdi_CreatePen(lineTo->penStyle, lineTo->penWidth, color,
@@ -852,7 +857,7 @@ static BOOL gdi_polyline(rdpContext* context, const POLYLINE_ORDER* polyline)
        UINT32 SrcFormat;
        rdpGdi* gdi = context->gdi;
 
-       if (!decode_color(gdi, polyline->penColor, &color, &SrcFormat))
+       if (!gdi_decode_color(gdi, polyline->penColor, &color, &SrcFormat))
                return FALSE;
 
        if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 1, color, SrcFormat, &gdi->palette)))
@@ -898,10 +903,10 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
        UINT32 backColor;
        UINT32 originalColor;
 
-       if (!decode_color(gdi, mem3blt->foreColor, &foreColor, NULL))
+       if (!gdi_decode_color(gdi, mem3blt->foreColor, &foreColor, NULL))
                return FALSE;
 
-       if (!decode_color(gdi, mem3blt->backColor, &backColor, NULL))
+       if (!gdi_decode_color(gdi, mem3blt->backColor, &backColor, NULL))
                return FALSE;
 
        originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);
@@ -1157,11 +1162,17 @@ void gdi_register_update_callbacks(rdpUpdate* update)
        update->altsec->FrameMarker = gdi_frame_marker;
 }
 
-static BOOL gdi_init_primary(rdpGdi* gdi, UINT32 stride, BYTE* buffer,
-                             void (*pfree)(void*))
+static BOOL gdi_init_primary(rdpGdi* gdi, UINT32 stride, UINT32 format,
+                             BYTE* buffer, void (*pfree)(void*))
 {
        gdi->primary = (gdiBitmap*) calloc(1, sizeof(gdiBitmap));
 
+       if (format > 0)
+               gdi->dstFormat = format;
+
+       if (stride > 0)
+               gdi->stride = stride;
+
        if (!gdi->primary)
                goto fail_primary;
 
@@ -1226,7 +1237,7 @@ BOOL gdi_resize(rdpGdi* gdi, UINT32 width, UINT32 height)
 }
 
 BOOL gdi_resize_ex(rdpGdi* gdi, UINT32 width, UINT32 height,
-                   INT32 stride, INT32 format, BYTE* buffer,
+                   UINT32 stride, UINT32 format, BYTE* buffer,
                    void (*pfree)(void*))
 {
        if (!gdi || !gdi->primary)
@@ -1243,7 +1254,7 @@ BOOL gdi_resize_ex(rdpGdi* gdi, UINT32 width, UINT32 height,
        gdi_bitmap_free_ex(gdi->primary);
        gdi->primary = NULL;
        gdi->primary_buffer = NULL;
-       return gdi_init_primary(gdi, stride, buffer, pfree);
+       return gdi_init_primary(gdi, stride, format, buffer, pfree);
 }
 
 /**
@@ -1282,7 +1293,7 @@ BOOL gdi_init_ex(freerdp* instance, UINT32 format, UINT32 stride, BYTE* buffer,
 
        gdi->hdc->format = gdi->dstFormat;
 
-       if (!gdi_init_primary(gdi, stride, buffer, pfree))
+       if (!gdi_init_primary(gdi, stride, gdi->dstFormat, buffer, pfree))
                goto fail;
 
        if (!(context->cache = cache_new(instance->settings)))
index e19273d..c897dc0 100644 (file)
@@ -258,18 +258,29 @@ static BOOL gdi_Glyph_BeginDraw(rdpContext* context, UINT32 x, UINT32 y,
        HGDI_BRUSH brush;
        rdpGdi* gdi = context->gdi;
        BOOL ret = FALSE;
-       UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE);
-       /* TODO: handle fOpRedundant! See xf_Glyph_BeginDraw() */
-       bgcolor = ConvertColor(bgcolor, SrcFormat, gdi->drawing->hdc->format,
-                              &gdi->palette);
-       fgcolor = ConvertColor(fgcolor, SrcFormat, gdi->drawing->hdc->format,
-                              &gdi->palette);
+
+       if (!gdi_decode_color(gdi, bgcolor, &bgcolor, NULL))
+               return FALSE;
+
+       if (!gdi_decode_color(gdi, fgcolor, &fgcolor, NULL))
+               return FALSE;
 
        if (!(brush = gdi_CreateSolidBrush(fgcolor)))
                goto out;
 
        gdi_CRgnToRect(x, y, width, height, &rect);
-       ret = gdi_FillRect(gdi->drawing->hdc, &rect, brush);
+
+       switch (fOpRedundant)
+       {
+               case 0:
+                       ret = gdi_FillRect(gdi->drawing->hdc, &rect, brush);
+                       break;
+
+               default:
+                       ret = TRUE;
+                       break;
+       }
+
        gdi_DeleteObject((HGDIOBJECT) brush);
 out:
        gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor);
index 6f8bed3..ac1565b 100644 (file)
  */
 
 HGDI_RGN gdi_CreateRectRgn(UINT32 nLeftRect, UINT32 nTopRect,
-                          UINT32 nRightRect, UINT32 nBottomRect)
+                           UINT32 nRightRect, UINT32 nBottomRect)
 {
        HGDI_RGN hRgn = (HGDI_RGN) calloc(1, sizeof(GDI_RGN));
+
        if (!hRgn)
                return NULL;
 
@@ -69,9 +70,10 @@ HGDI_RGN gdi_CreateRectRgn(UINT32 nLeftRect, UINT32 nTopRect,
  */
 
 HGDI_RECT gdi_CreateRect(UINT32 xLeft, UINT32 yTop,
-                        UINT32 xRight, UINT32 yBottom)
+                         UINT32 xRight, UINT32 yBottom)
 {
        HGDI_RECT hRect = (HGDI_RECT) calloc(1, sizeof(GDI_RECT));
+
        if (!hRect)
                return NULL;
 
@@ -107,7 +109,7 @@ INLINE void gdi_RectToRgn(HGDI_RECT rect, HGDI_RGN rgn)
  */
 
 INLINE void gdi_CRectToRgn(UINT32 left, UINT32 top,
-                          UINT32 right, UINT32 bottom, HGDI_RGN rgn)
+                           UINT32 right, UINT32 bottom, HGDI_RGN rgn)
 {
        rgn->x = left;
        rgn->y = top;
@@ -124,8 +126,8 @@ INLINE void gdi_CRectToRgn(UINT32 left, UINT32 top,
  * @param h height
  */
 
-INLINE void gdi_RectToCRgn(const HGDI_RECT rect, UINT32 *x, UINT32 *y,
-                          UINT32 *w, UINT32 *h)
+INLINE void gdi_RectToCRgn(const HGDI_RECT rect, UINT32* x, UINT32* y,
+                           UINT32* w, UINT32* h)
 {
        *x = rect->left;
        *y = rect->top;
@@ -145,8 +147,9 @@ INLINE void gdi_RectToCRgn(const HGDI_RECT rect, UINT32 *x, UINT32 *y,
  * @param h height
  */
 
-INLINE void gdi_CRectToCRgn(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom,
-                           UINT32 *x, UINT32 *y, UINT32 *w, UINT32 *h)
+INLINE void gdi_CRectToCRgn(UINT32 left, UINT32 top, UINT32 right,
+                            UINT32 bottom,
+                            UINT32* x, UINT32* y, UINT32* w, UINT32* h)
 {
        *x = left;
        *y = top;
@@ -177,12 +180,18 @@ INLINE void gdi_RgnToRect(HGDI_RGN rgn, HGDI_RECT rect)
  * @param rect destination rectangle
  */
 
-INLINE void gdi_CRgnToRect(UINT32 x, UINT32 y, UINT32 w, UINT32 h, HGDI_RECT rect)
+INLINE void gdi_CRgnToRect(UINT32 x, UINT32 y, UINT32 w, UINT32 h,
+                           HGDI_RECT rect)
 {
+       memset(rect, 0, sizeof(GDI_RECT));
        rect->left = x;
        rect->top = y;
-       rect->right = x + w - 1;
-       rect->bottom = y + h - 1;
+
+       if (w > 0)
+               rect->right = x + w - 1;
+
+       if (h > 0)
+               rect->bottom = y + h - 1;
 }
 
 /**
@@ -194,8 +203,8 @@ INLINE void gdi_CRgnToRect(UINT32 x, UINT32 y, UINT32 w, UINT32 h, HGDI_RECT rec
  * @param bottom y2
  */
 
-INLINE void gdi_RgnToCRect(HGDI_RGN rgn, UINT32 *left, UINT32 *top,
-                          UINT32 *right, UINT32 *bottom)
+INLINE void gdi_RgnToCRect(HGDI_RGN rgn, UINT32* left, UINT32* top,
+                           UINT32* right, UINT32* bottom)
 {
        *left = rgn->x;
        *top = rgn->y;
@@ -216,7 +225,7 @@ INLINE void gdi_RgnToCRect(HGDI_RGN rgn, UINT32 *left, UINT32 *top,
  */
 
 INLINE void gdi_CRgnToCRect(UINT32 x, UINT32 y, UINT32 w, UINT32 h,
-                           UINT32 *left, UINT32 *top, UINT32 *right, UINT32 *bottom)
+                            UINT32* left, UINT32* top, UINT32* right, UINT32* bottom)
 {
        *left = x;
        *top = y;
@@ -236,16 +245,14 @@ INLINE void gdi_CRgnToCRect(UINT32 x, UINT32 y, UINT32 w, UINT32 h,
  */
 
 INLINE BOOL gdi_CopyOverlap(UINT32 x, UINT32 y, UINT32 width, UINT32 height,
-                           UINT32 srcx, UINT32 srcy)
+                            UINT32 srcx, UINT32 srcy)
 {
        GDI_RECT dst;
        GDI_RECT src;
-
        gdi_CRgnToRect(x, y, width, height, &dst);
        gdi_CRgnToRect(srcx, srcy, width, height, &src);
-
        return (dst.right >= src.left && dst.left <= src.right &&
-               dst.bottom >= src.top && dst.top <= src.bottom) ? TRUE : FALSE;
+               dst.bottom >= src.top && dst.top <= src.bottom) ? TRUE : FALSE;
 }
 
 /**
@@ -260,7 +267,7 @@ INLINE BOOL gdi_CopyOverlap(UINT32 x, UINT32 y, UINT32 width, UINT32 height,
  */
 
 INLINE BOOL gdi_SetRect(HGDI_RECT rc, UINT32 xLeft, UINT32 yTop,
-                       UINT32 xRight, UINT32 yBottom)
+                        UINT32 xRight, UINT32 yBottom)
 {
        rc->left = xLeft;
        rc->top = yTop;
@@ -280,7 +287,7 @@ INLINE BOOL gdi_SetRect(HGDI_RECT rc, UINT32 xLeft, UINT32 yTop,
  */
 
 INLINE BOOL gdi_SetRgn(HGDI_RGN hRgn, UINT32 nXLeft, UINT32 nYLeft,
-                      UINT32 nWidth, UINT32 nHeight)
+                       UINT32 nWidth, UINT32 nHeight)
 {
        hRgn->x = nXLeft;
        hRgn->y = nYLeft;
@@ -301,7 +308,7 @@ INLINE BOOL gdi_SetRgn(HGDI_RGN hRgn, UINT32 nXLeft, UINT32 nYLeft,
  */
 
 INLINE BOOL gdi_SetRectRgn(HGDI_RGN hRgn, UINT32 nLeftRect, UINT32 nTopRect,
-                          UINT32 nRightRect, UINT32 nBottomRect)
+                           UINT32 nRightRect, UINT32 nBottomRect)
 {
        gdi_CRectToRgn(nLeftRect, nTopRect, nRightRect, nBottomRect, hRgn);
        hRgn->null = 0;
@@ -361,7 +368,6 @@ INLINE BOOL gdi_PtInRect(HGDI_RECT rc, UINT32 x, UINT32 y)
         * points on the left and top sides are considered in,
         * while points on the right and bottom sides are considered out
         */
-
        if (x >= rc->left && x <= rc->right)
        {
                if (y >= rc->top && y <= rc->bottom)
@@ -384,7 +390,8 @@ INLINE BOOL gdi_PtInRect(HGDI_RECT rc, UINT32 x, UINT32 y)
  * @return nonzero on success, 0 otherwise
  */
 
-INLINE BOOL gdi_InvalidateRegion(HGDI_DC hdc, UINT32 x, UINT32 y, UINT32 w, UINT32 h)
+INLINE BOOL gdi_InvalidateRegion(HGDI_DC hdc, UINT32 x, UINT32 y, UINT32 w,
+                                 UINT32 h)
 {
        GDI_RECT inv;
        GDI_RECT rgn;
@@ -406,18 +413,18 @@ INLINE BOOL gdi_InvalidateRegion(HGDI_DC hdc, UINT32 x, UINT32 y, UINT32 w, UINT
        {
                int new_cnt;
                HGDI_RGN new_rgn;
-
                new_cnt = hdc->hwnd->count * 2;
                new_rgn = (HGDI_RGN) realloc(cinvalid, sizeof(GDI_RGN) * new_cnt);
+
                if (!new_rgn)
                        return FALSE;
+
                hdc->hwnd->count = new_cnt;
                cinvalid = new_rgn;
        }
 
        gdi_SetRgn(&cinvalid[hdc->hwnd->ninvalid++], x, y, w, h);
        hdc->hwnd->cinvalid = cinvalid;
-
        invalid = hdc->hwnd->invalid;
 
        if (invalid->null)
@@ -452,6 +459,5 @@ INLINE BOOL gdi_InvalidateRegion(HGDI_DC hdc, UINT32 x, UINT32 y, UINT32 w, UINT
                inv.bottom = rgn.bottom;
 
        gdi_RectToRgn(&inv, invalid);
-
        return TRUE;
 }
index f016273..41a3343 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "line.h"
 #include "brush.h"
+#include "helpers.h"
 
 /* BitBlt() Test Data */
 
@@ -408,17 +409,17 @@ struct test_bitblt
 {
        UINT32 rop;
        const BYTE* src;
-       HGDI_BITMAP* bmp;
+       HGDI_BITMAP bmp;
 };
 
 static BOOL test_rop(HGDI_DC hdcDst, HGDI_DC hdcSrc, HGDI_BITMAP hBmpSrc,
                      HGDI_BITMAP hBmpDst,
-                     HGDI_BITMAP hBmpDstOriginal, UINT32 rop, HGDI_BITMAP* expected,
+                     HGDI_BITMAP hBmpDstOriginal, UINT32 rop, HGDI_BITMAP expected,
                      const gdiPalette* hPalette)
 {
        /* restore original destination bitmap */
-       gdi_SelectObject(hdcSrc, hBmpDstOriginal);
-       gdi_SelectObject(hdcDst, hBmpDst);
+       gdi_SelectObject(hdcSrc, (HGDIOBJECT)hBmpDstOriginal);
+       gdi_SelectObject(hdcDst, (HGDIOBJECT)hBmpDst);
 
        if (!gdi_BitBlt(hdcDst, 0, 0, 16, 16, hdcSrc, 0, 0, GDI_SRCCOPY, hPalette))
                return FALSE;
index 9a0e29a..d99d2cc 100644 (file)
@@ -5,11 +5,13 @@
 #include <freerdp/gdi/pen.h>
 #include <freerdp/gdi/region.h>
 #include <freerdp/gdi/bitmap.h>
+#include <freerdp/gdi/gdi.h>
 
 #include <winpr/crt.h>
 
 #include "line.h"
 #include "brush.h"
+#include "drawing.h"
 
 static int test_gdi_GetDC(void)
 {
@@ -344,7 +346,7 @@ static int test_gdi_MoveToEx(void)
        HGDI_PEN hPen;
        HGDI_POINT prevPoint;
        const UINT32 format = PIXEL_FORMAT_RGBA32;
-       rdpPalette* palette = NULL;
+       gdiPalette* palette = NULL;
 
        if (!(hdc = gdi_GetDC()))
        {
index fdc544b..eaad347 100644 (file)
@@ -80,7 +80,7 @@ static const BYTE ellipse_case_3[256] =
 int TestGdiEllipse(int argc, char* argv[])
 {
        int rc = -1;
-       UINT32 i, j;
+       UINT32 i;
        HGDI_DC hdc;
        HGDI_PEN pen;
        HGDI_BITMAP hBmp;
@@ -113,7 +113,7 @@ int TestGdiEllipse(int argc, char* argv[])
        for (i = 0; i < number_formats; i++)
        {
                const UINT32 format = colorFormats[i];
-               rdpPalette* hPalette = &g;
+               gdiPalette* hPalette = &g;
                g.format = format;
 
                for (i = 0; i < 256; i++)
index eaaca39..a7182f0 100644 (file)
@@ -12,6 +12,7 @@
 #include "line.h"
 #include "brush.h"
 #include "clipping.h"
+#include "drawing.h"
 
 #include "helpers.h"
 
@@ -618,7 +619,7 @@ struct ropMap
 {
        UINT32 rop;
        HGDI_BITMAP bmp;
-       BYTE* src;
+       const BYTE* src;
 };
 
 static BOOL test_line(HGDI_DC hdc, const gdiPalette* hPalette, UINT32 mX,
@@ -643,7 +644,7 @@ static BOOL test_line(HGDI_DC hdc, const gdiPalette* hPalette, UINT32 mX,
 int TestGdiLine(int argc, char* argv[])
 {
        int rc = -1;
-       UINT32 x, i, j;
+       UINT32 x, i;
        gdiPalette g;
        const UINT32 RawFormat = PIXEL_FORMAT_RGB8;
        const UINT32 colorFormats[] =