From 052736a82507f849b874df402eeab2a53002790e Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 25 Jan 2017 08:33:36 +0100 Subject: [PATCH] Fixed conversion to XColor. --- client/X11/xf_gdi.c | 77 ++++++++++++++++++++++++------------------------ client/X11/xf_graphics.c | 53 ++++++++++++++++++++------------- client/X11/xf_graphics.h | 3 +- 3 files changed, 72 insertions(+), 61 deletions(-) diff --git a/client/X11/xf_gdi.c b/client/X11/xf_gdi.c index d7e972a..5bd0b07 100644 --- a/client/X11/xf_gdi.c +++ b/client/X11/xf_gdi.c @@ -321,15 +321,14 @@ fail: static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) { const rdpBrush* brush; - UINT32 foreColor; - UINT32 backColor; xfContext* xfc = (xfContext*) context; BOOL ret = FALSE; + XColor xfg, xbg; - if (!xf_decode_color(context->gdi, patblt->foreColor, &foreColor, NULL)) + if (!xf_decode_color(xfc, patblt->foreColor, &xfg)) return FALSE; - if (!xf_decode_color(context->gdi, patblt->backColor, &backColor, NULL)) + if (!xf_decode_color(xfc, patblt->backColor, &xbg)) return FALSE; xf_lock_x11(xfc, FALSE); @@ -342,8 +341,8 @@ static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) { case GDI_BS_SOLID: XSetFillStyle(xfc->display, xfc->gc, FillSolid); - XSetBackground(xfc->display, xfc->gc, backColor); - XSetForeground(xfc->display, xfc->gc, foreColor); + XSetBackground(xfc->display, xfc->gc, xbg.pixel); + XSetForeground(xfc->display, xfc->gc, xfg.pixel); XFillRectangle(xfc->display, xfc->drawing, xfc->gc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); break; @@ -352,8 +351,8 @@ static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) { Pixmap pattern = xf_mono_bitmap_new(xfc, 8, 8, &GDI_BS_HATCHED_PATTERNS[8 * brush->hatch]); - XSetBackground(xfc->display, xfc->gc, backColor); - XSetForeground(xfc->display, xfc->gc, foreColor); + XSetBackground(xfc->display, xfc->gc, xbg.pixel); + XSetForeground(xfc->display, xfc->gc, xfg.pixel); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetStipple(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); @@ -378,8 +377,8 @@ static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) else { Pixmap pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data); - XSetBackground(xfc->display, xfc->gc, foreColor); - XSetForeground(xfc->display, xfc->gc, backColor); + XSetBackground(xfc->display, xfc->gc, xfg.pixel); + XSetForeground(xfc->display, xfc->gc, xbg.pixel); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetStipple(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); @@ -437,18 +436,18 @@ fail: static BOOL xf_gdi_opaque_rect(rdpContext* context, const OPAQUE_RECT_ORDER* opaque_rect) { - UINT32 color; + XColor color; rdpGdi* gdi = context->gdi; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - if (!xf_decode_color(gdi, opaque_rect->color, &color, NULL)) + if (!xf_decode_color(xfc, opaque_rect->color, &color)) return FALSE; xf_lock_x11(xfc, FALSE); XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); - XSetForeground(xfc->display, xfc->gc, color); + XSetForeground(xfc->display, xfc->gc, color.pixel); XFillRectangle(xfc->display, xfc->drawing, xfc->gc, opaque_rect->nLeftRect, opaque_rect->nTopRect, opaque_rect->nWidth, opaque_rect->nHeight); @@ -469,15 +468,15 @@ static BOOL xf_gdi_multi_opaque_rect(rdpContext* context, xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; rdpGdi* gdi = context->gdi; - UINT32 color; + XColor color; - if (!xf_decode_color(gdi, multi_opaque_rect->color, &color, NULL)) + if (!xf_decode_color(xfc, multi_opaque_rect->color, &color)) return FALSE; xf_lock_x11(xfc, FALSE); XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); - XSetForeground(xfc->display, xfc->gc, color); + XSetForeground(xfc->display, xfc->gc, color.pixel); for (i = 0; i < multi_opaque_rect->numRectangles; i++) { @@ -500,17 +499,17 @@ static BOOL xf_gdi_multi_opaque_rect(rdpContext* context, static BOOL xf_gdi_line_to(rdpContext* context, const LINE_TO_ORDER* line_to) { - UINT32 color; + XColor color; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - if (!xf_decode_color(context->gdi, line_to->penColor, &color, NULL)) + if (!xf_decode_color(xfc, line_to->penColor, &color)) return FALSE; xf_lock_x11(xfc, FALSE); xf_set_rop2(xfc, line_to->bRop2); XSetFillStyle(xfc->display, xfc->gc, FillSolid); - XSetForeground(xfc->display, xfc->gc, color); + XSetForeground(xfc->display, xfc->gc, color.pixel); XDrawLine(xfc->display, xfc->drawing, xfc->gc, line_to->nXStart, line_to->nYStart, line_to->nXEnd, line_to->nYEnd); @@ -569,18 +568,18 @@ static BOOL xf_gdi_polyline(rdpContext* context, { int i; int npoints; - UINT32 color; + XColor color; XPoint* points; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - if (!xf_decode_color(context->gdi, polyline->penColor, &color, NULL)) + if (!xf_decode_color(xfc, polyline->penColor, &color)) return FALSE; xf_lock_x11(xfc, FALSE); xf_set_rop2(xfc, polyline->bRop2); XSetFillStyle(xfc->display, xfc->gc, FillSolid); - XSetForeground(xfc->display, xfc->gc, color); + XSetForeground(xfc->display, xfc->gc, color.pixel); npoints = polyline->numDeltaEntries + 1; points = malloc(sizeof(XPoint) * npoints); @@ -652,8 +651,8 @@ static BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) { const rdpBrush* brush; xfBitmap* bitmap; - UINT32 foreColor; - UINT32 backColor; + XColor foreColor; + XColor backColor; Pixmap pattern = 0; xfContext* xfc = (xfContext*) context; BOOL ret = FALSE; @@ -661,10 +660,10 @@ static BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) if (!xfc->display || !xfc->drawing) return FALSE; - if (!xf_decode_color(context->gdi, mem3blt->foreColor, &foreColor, NULL)) + if (!xf_decode_color(xfc, mem3blt->foreColor, &foreColor)) return FALSE; - if (!xf_decode_color(context->gdi, mem3blt->backColor, &backColor, NULL)) + if (!xf_decode_color(xfc, mem3blt->backColor, &backColor)) return FALSE; xf_lock_x11(xfc, FALSE); @@ -687,8 +686,8 @@ static BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) else { pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data); - XSetBackground(xfc->display, xfc->gc, backColor); - XSetForeground(xfc->display, xfc->gc, foreColor); + XSetBackground(xfc->display, xfc->gc, backColor.pixel); + XSetForeground(xfc->display, xfc->gc, foreColor.pixel); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetStipple(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); @@ -698,8 +697,8 @@ static BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) case GDI_BS_SOLID: XSetFillStyle(xfc->display, xfc->gc, FillSolid); - XSetBackground(xfc->display, xfc->gc, backColor); - XSetForeground(xfc->display, xfc->gc, foreColor); + XSetBackground(xfc->display, xfc->gc, backColor.pixel); + XSetForeground(xfc->display, xfc->gc, foreColor.pixel); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); break; @@ -735,11 +734,11 @@ static BOOL xf_gdi_polygon_sc(rdpContext* context, { int i, npoints; XPoint* points; - UINT32 brush_color; + XColor brush_color; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - if (!xf_decode_color(context->gdi, polygon_sc->brushColor, &brush_color, NULL)) + if (!xf_decode_color(xfc, polygon_sc->brushColor, &brush_color)) return FALSE; xf_lock_x11(xfc, FALSE); @@ -778,7 +777,7 @@ static BOOL xf_gdi_polygon_sc(rdpContext* context, } XSetFillStyle(xfc->display, xfc->gc, FillSolid); - XSetForeground(xfc->display, xfc->gc, brush_color); + XSetForeground(xfc->display, xfc->gc, brush_color.pixel); XFillPolygon(xfc->display, xfc->drawing, xfc->gc, points, npoints, Complex, CoordModePrevious); @@ -801,15 +800,15 @@ static BOOL xf_gdi_polygon_cb(rdpContext* context, XPoint* points; Pixmap pattern; const rdpBrush* brush; - UINT32 foreColor; - UINT32 backColor; + XColor foreColor; + XColor backColor; xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; - if (!xf_decode_color(context->gdi, polygon_cb->foreColor, &foreColor, NULL)) + if (!xf_decode_color(xfc, polygon_cb->foreColor, &foreColor)) return FALSE; - if (!xf_decode_color(context->gdi, polygon_cb->backColor, &backColor, NULL)) + if (!xf_decode_color(xfc, polygon_cb->backColor, &backColor)) return FALSE; xf_lock_x11(xfc, FALSE); @@ -859,8 +858,8 @@ static BOOL xf_gdi_polygon_cb(rdpContext* context, else { pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data); - XSetForeground(xfc->display, xfc->gc, backColor); - XSetBackground(xfc->display, xfc->gc, foreColor); + XSetForeground(xfc->display, xfc->gc, backColor.pixel); + XSetBackground(xfc->display, xfc->gc, foreColor.pixel); if (polygon_cb->backMode == BACKMODE_TRANSPARENT) XSetFillStyle(xfc->display, xfc->gc, FillStippled); diff --git a/client/X11/xf_graphics.c b/client/X11/xf_graphics.c index fa6b402..a7a6ee0 100644 --- a/client/X11/xf_graphics.c +++ b/client/X11/xf_graphics.c @@ -42,25 +42,36 @@ #include #define TAG CLIENT_TAG("x11") -BOOL xf_decode_color(rdpGdi* gdi, const UINT32 srcColor, - UINT32* color, UINT32* format) +BOOL xf_decode_color(xfContext* xfc, const UINT32 srcColor, XColor* color) { - xfContext* xfc; - UINT32 DstFormat; + rdpGdi* gdi; + rdpSettings* settings; UINT32 SrcFormat; + BYTE r, g, b, a; + + if (!xfc || !color) + return FALSE; + + gdi = xfc->context.gdi; - if (!gdi || !gdi->context || !gdi->context->settings) + if (!gdi) return FALSE; - xfc = (xfContext*)gdi->context; - SrcFormat = gdi_get_pixel_format(gdi->context->settings->ColorDepth); + settings = xfc->context.settings; - if (format) - *format = SrcFormat; + if (!settings) + return FALSE; + + SrcFormat = gdi_get_pixel_format(settings->ColorDepth); + SplitColor(srcColor, SrcFormat, &r, &g, &b, &a, &gdi->palette); + color->blue = (unsigned short)(b << 8); + color->green = (unsigned short)(g << 8); + color->red = (unsigned short)(r << 8); + color->flags = DoRed | DoGreen | DoBlue; + + if (XAllocColor(xfc->display, xfc->colormap, color) == 0) + return FALSE; - DstFormat = xf_get_local_color_format(xfc, FALSE); - *color = ConvertColor(srcColor, SrcFormat, - DstFormat, &gdi->palette); return TRUE; } @@ -393,11 +404,12 @@ static BOOL xf_Glyph_BeginDraw(rdpContext* context, UINT32 x, UINT32 y, { xfContext* xfc = (xfContext*) context; XRectangle rect; + XColor xbgcolor, xfgcolor; - if (!xf_decode_color(context->gdi, bgcolor, &bgcolor, NULL)) + if (!xf_decode_color(xfc, bgcolor, &xbgcolor)) return FALSE; - if (!xf_decode_color(context->gdi, fgcolor, &fgcolor, NULL)) + if (!xf_decode_color(xfc, fgcolor, &xfgcolor)) return FALSE; rect.x = x; @@ -408,14 +420,14 @@ static BOOL xf_Glyph_BeginDraw(rdpContext* context, UINT32 x, UINT32 y, if (!fOpRedundant) { - XSetForeground(xfc->display, xfc->gc, fgcolor); - XSetBackground(xfc->display, xfc->gc, fgcolor); + XSetForeground(xfc->display, xfc->gc, xfgcolor.pixel); + XSetBackground(xfc->display, xfc->gc, xfgcolor.pixel); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XFillRectangle(xfc->display, xfc->drawable, xfc->gc, x, y, width, height); } - XSetForeground(xfc->display, xfc->gc, bgcolor); - XSetBackground(xfc->display, xfc->gc, fgcolor); + XSetForeground(xfc->display, xfc->gc, xbgcolor.pixel); + XSetBackground(xfc->display, xfc->gc, xfgcolor.pixel); xf_unlock_x11(xfc, FALSE); return TRUE; } @@ -426,11 +438,12 @@ static BOOL xf_Glyph_EndDraw(rdpContext* context, UINT32 x, UINT32 y, { xfContext* xfc = (xfContext*) context; BOOL ret = TRUE; + XColor xfgcolor, xbgcolor; - if (!xf_decode_color(context->gdi, bgcolor, &bgcolor, NULL)) + if (!xf_decode_color(xfc, bgcolor, &xbgcolor)) return FALSE; - if (!xf_decode_color(context->gdi, fgcolor, &fgcolor, NULL)) + if (!xf_decode_color(xfc, fgcolor, &xfgcolor)) return FALSE; if (xfc->drawing == xfc->primary) diff --git a/client/X11/xf_graphics.h b/client/X11/xf_graphics.h index dde4928..d185baa 100644 --- a/client/X11/xf_graphics.h +++ b/client/X11/xf_graphics.h @@ -26,8 +26,7 @@ BOOL xf_register_pointer(rdpGraphics* graphics); BOOL xf_register_graphics(rdpGraphics* graphics); -BOOL xf_decode_color(rdpGdi* gdi, const UINT32 srcColor, - UINT32* color, UINT32* format); +BOOL xf_decode_color(xfContext* xfc, const UINT32 srcColor, XColor* color); UINT32 xf_get_local_color_format(xfContext* xfc, BOOL aligned); #endif /* __XF_GRAPHICS_H */ -- 2.7.4