Fixed conversion to XColor.

This commit is contained in:
Armin Novak 2017-01-25 08:33:36 +01:00
parent 042594bf82
commit 052736a825
3 changed files with 72 additions and 61 deletions

View File

@ -321,15 +321,14 @@ fail:
static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
{ {
const rdpBrush* brush; const rdpBrush* brush;
UINT32 foreColor;
UINT32 backColor;
xfContext* xfc = (xfContext*) context; xfContext* xfc = (xfContext*) context;
BOOL ret = FALSE; 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; return FALSE;
if (!xf_decode_color(context->gdi, patblt->backColor, &backColor, NULL)) if (!xf_decode_color(xfc, patblt->backColor, &xbg))
return FALSE; return FALSE;
xf_lock_x11(xfc, FALSE); xf_lock_x11(xfc, FALSE);
@ -342,8 +341,8 @@ static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
{ {
case GDI_BS_SOLID: case GDI_BS_SOLID:
XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetFillStyle(xfc->display, xfc->gc, FillSolid);
XSetBackground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, xbg.pixel);
XSetForeground(xfc->display, xfc->gc, foreColor); XSetForeground(xfc->display, xfc->gc, xfg.pixel);
XFillRectangle(xfc->display, xfc->drawing, xfc->gc, XFillRectangle(xfc->display, xfc->drawing, xfc->gc,
patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight);
break; break;
@ -352,8 +351,8 @@ static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
{ {
Pixmap pattern = xf_mono_bitmap_new(xfc, 8, 8, Pixmap pattern = xf_mono_bitmap_new(xfc, 8, 8,
&GDI_BS_HATCHED_PATTERNS[8 * brush->hatch]); &GDI_BS_HATCHED_PATTERNS[8 * brush->hatch]);
XSetBackground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, xbg.pixel);
XSetForeground(xfc->display, xfc->gc, foreColor); XSetForeground(xfc->display, xfc->gc, xfg.pixel);
XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled);
XSetStipple(xfc->display, xfc->gc, pattern); XSetStipple(xfc->display, xfc->gc, pattern);
XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y);
@ -378,8 +377,8 @@ static BOOL xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
else else
{ {
Pixmap pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data); Pixmap pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data);
XSetBackground(xfc->display, xfc->gc, foreColor); XSetBackground(xfc->display, xfc->gc, xfg.pixel);
XSetForeground(xfc->display, xfc->gc, backColor); XSetForeground(xfc->display, xfc->gc, xbg.pixel);
XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled);
XSetStipple(xfc->display, xfc->gc, pattern); XSetStipple(xfc->display, xfc->gc, pattern);
XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y);
@ -437,18 +436,18 @@ fail:
static BOOL xf_gdi_opaque_rect(rdpContext* context, static BOOL xf_gdi_opaque_rect(rdpContext* context,
const OPAQUE_RECT_ORDER* opaque_rect) const OPAQUE_RECT_ORDER* opaque_rect)
{ {
UINT32 color; XColor color;
rdpGdi* gdi = context->gdi; rdpGdi* gdi = context->gdi;
xfContext* xfc = (xfContext*) context; xfContext* xfc = (xfContext*) context;
BOOL ret = TRUE; BOOL ret = TRUE;
if (!xf_decode_color(gdi, opaque_rect->color, &color, NULL)) if (!xf_decode_color(xfc, opaque_rect->color, &color))
return FALSE; return FALSE;
xf_lock_x11(xfc, FALSE); xf_lock_x11(xfc, FALSE);
XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFunction(xfc->display, xfc->gc, GXcopy);
XSetFillStyle(xfc->display, xfc->gc, FillSolid); 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, XFillRectangle(xfc->display, xfc->drawing, xfc->gc,
opaque_rect->nLeftRect, opaque_rect->nTopRect, opaque_rect->nLeftRect, opaque_rect->nTopRect,
opaque_rect->nWidth, opaque_rect->nHeight); opaque_rect->nWidth, opaque_rect->nHeight);
@ -469,15 +468,15 @@ static BOOL xf_gdi_multi_opaque_rect(rdpContext* context,
xfContext* xfc = (xfContext*) context; xfContext* xfc = (xfContext*) context;
BOOL ret = TRUE; BOOL ret = TRUE;
rdpGdi* gdi = context->gdi; 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; return FALSE;
xf_lock_x11(xfc, FALSE); xf_lock_x11(xfc, FALSE);
XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFunction(xfc->display, xfc->gc, GXcopy);
XSetFillStyle(xfc->display, xfc->gc, FillSolid); 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++) 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) static BOOL xf_gdi_line_to(rdpContext* context, const LINE_TO_ORDER* line_to)
{ {
UINT32 color; XColor color;
xfContext* xfc = (xfContext*) context; xfContext* xfc = (xfContext*) context;
BOOL ret = TRUE; 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; return FALSE;
xf_lock_x11(xfc, FALSE); xf_lock_x11(xfc, FALSE);
xf_set_rop2(xfc, line_to->bRop2); xf_set_rop2(xfc, line_to->bRop2);
XSetFillStyle(xfc->display, xfc->gc, FillSolid); 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, XDrawLine(xfc->display, xfc->drawing, xfc->gc,
line_to->nXStart, line_to->nYStart, line_to->nXEnd, line_to->nYEnd); 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 i;
int npoints; int npoints;
UINT32 color; XColor color;
XPoint* points; XPoint* points;
xfContext* xfc = (xfContext*) context; xfContext* xfc = (xfContext*) context;
BOOL ret = TRUE; BOOL ret = TRUE;
if (!xf_decode_color(context->gdi, polyline->penColor, &color, NULL)) if (!xf_decode_color(xfc, polyline->penColor, &color))
return FALSE; return FALSE;
xf_lock_x11(xfc, FALSE); xf_lock_x11(xfc, FALSE);
xf_set_rop2(xfc, polyline->bRop2); xf_set_rop2(xfc, polyline->bRop2);
XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetFillStyle(xfc->display, xfc->gc, FillSolid);
XSetForeground(xfc->display, xfc->gc, color); XSetForeground(xfc->display, xfc->gc, color.pixel);
npoints = polyline->numDeltaEntries + 1; npoints = polyline->numDeltaEntries + 1;
points = malloc(sizeof(XPoint) * npoints); points = malloc(sizeof(XPoint) * npoints);
@ -652,8 +651,8 @@ static BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
{ {
const rdpBrush* brush; const rdpBrush* brush;
xfBitmap* bitmap; xfBitmap* bitmap;
UINT32 foreColor; XColor foreColor;
UINT32 backColor; XColor backColor;
Pixmap pattern = 0; Pixmap pattern = 0;
xfContext* xfc = (xfContext*) context; xfContext* xfc = (xfContext*) context;
BOOL ret = FALSE; BOOL ret = FALSE;
@ -661,10 +660,10 @@ static BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
if (!xfc->display || !xfc->drawing) if (!xfc->display || !xfc->drawing)
return FALSE; return FALSE;
if (!xf_decode_color(context->gdi, mem3blt->foreColor, &foreColor, NULL)) if (!xf_decode_color(xfc, mem3blt->foreColor, &foreColor))
return FALSE; return FALSE;
if (!xf_decode_color(context->gdi, mem3blt->backColor, &backColor, NULL)) if (!xf_decode_color(xfc, mem3blt->backColor, &backColor))
return FALSE; return FALSE;
xf_lock_x11(xfc, FALSE); xf_lock_x11(xfc, FALSE);
@ -687,8 +686,8 @@ static BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
else else
{ {
pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data); pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data);
XSetBackground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, backColor.pixel);
XSetForeground(xfc->display, xfc->gc, foreColor); XSetForeground(xfc->display, xfc->gc, foreColor.pixel);
XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled);
XSetStipple(xfc->display, xfc->gc, pattern); XSetStipple(xfc->display, xfc->gc, pattern);
XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); 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: case GDI_BS_SOLID:
XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetFillStyle(xfc->display, xfc->gc, FillSolid);
XSetBackground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, backColor.pixel);
XSetForeground(xfc->display, xfc->gc, foreColor); XSetForeground(xfc->display, xfc->gc, foreColor.pixel);
XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y);
break; break;
@ -735,11 +734,11 @@ static BOOL xf_gdi_polygon_sc(rdpContext* context,
{ {
int i, npoints; int i, npoints;
XPoint* points; XPoint* points;
UINT32 brush_color; XColor brush_color;
xfContext* xfc = (xfContext*) context; xfContext* xfc = (xfContext*) context;
BOOL ret = TRUE; 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; return FALSE;
xf_lock_x11(xfc, FALSE); xf_lock_x11(xfc, FALSE);
@ -778,7 +777,7 @@ static BOOL xf_gdi_polygon_sc(rdpContext* context,
} }
XSetFillStyle(xfc->display, xfc->gc, FillSolid); 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, XFillPolygon(xfc->display, xfc->drawing, xfc->gc,
points, npoints, Complex, CoordModePrevious); points, npoints, Complex, CoordModePrevious);
@ -801,15 +800,15 @@ static BOOL xf_gdi_polygon_cb(rdpContext* context,
XPoint* points; XPoint* points;
Pixmap pattern; Pixmap pattern;
const rdpBrush* brush; const rdpBrush* brush;
UINT32 foreColor; XColor foreColor;
UINT32 backColor; XColor backColor;
xfContext* xfc = (xfContext*) context; xfContext* xfc = (xfContext*) context;
BOOL ret = TRUE; 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; return FALSE;
if (!xf_decode_color(context->gdi, polygon_cb->backColor, &backColor, NULL)) if (!xf_decode_color(xfc, polygon_cb->backColor, &backColor))
return FALSE; return FALSE;
xf_lock_x11(xfc, FALSE); xf_lock_x11(xfc, FALSE);
@ -859,8 +858,8 @@ static BOOL xf_gdi_polygon_cb(rdpContext* context,
else else
{ {
pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data); pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data);
XSetForeground(xfc->display, xfc->gc, backColor); XSetForeground(xfc->display, xfc->gc, backColor.pixel);
XSetBackground(xfc->display, xfc->gc, foreColor); XSetBackground(xfc->display, xfc->gc, foreColor.pixel);
if (polygon_cb->backMode == BACKMODE_TRANSPARENT) if (polygon_cb->backMode == BACKMODE_TRANSPARENT)
XSetFillStyle(xfc->display, xfc->gc, FillStippled); XSetFillStyle(xfc->display, xfc->gc, FillStippled);

View File

@ -42,25 +42,36 @@
#include <freerdp/log.h> #include <freerdp/log.h>
#define TAG CLIENT_TAG("x11") #define TAG CLIENT_TAG("x11")
BOOL xf_decode_color(rdpGdi* gdi, const UINT32 srcColor, BOOL xf_decode_color(xfContext* xfc, const UINT32 srcColor, XColor* color)
UINT32* color, UINT32* format)
{ {
xfContext* xfc; rdpGdi* gdi;
UINT32 DstFormat; rdpSettings* settings;
UINT32 SrcFormat; UINT32 SrcFormat;
BYTE r, g, b, a;
if (!gdi || !gdi->context || !gdi->context->settings) if (!xfc || !color)
return FALSE; return FALSE;
xfc = (xfContext*)gdi->context; gdi = xfc->context.gdi;
SrcFormat = gdi_get_pixel_format(gdi->context->settings->ColorDepth);
if (format) if (!gdi)
*format = SrcFormat; return FALSE;
settings = xfc->context.settings;
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; return TRUE;
} }
@ -393,11 +404,12 @@ static BOOL xf_Glyph_BeginDraw(rdpContext* context, UINT32 x, UINT32 y,
{ {
xfContext* xfc = (xfContext*) context; xfContext* xfc = (xfContext*) context;
XRectangle rect; XRectangle rect;
XColor xbgcolor, xfgcolor;
if (!xf_decode_color(context->gdi, bgcolor, &bgcolor, NULL)) if (!xf_decode_color(xfc, bgcolor, &xbgcolor))
return FALSE; return FALSE;
if (!xf_decode_color(context->gdi, fgcolor, &fgcolor, NULL)) if (!xf_decode_color(xfc, fgcolor, &xfgcolor))
return FALSE; return FALSE;
rect.x = x; rect.x = x;
@ -408,14 +420,14 @@ static BOOL xf_Glyph_BeginDraw(rdpContext* context, UINT32 x, UINT32 y,
if (!fOpRedundant) if (!fOpRedundant)
{ {
XSetForeground(xfc->display, xfc->gc, fgcolor); XSetForeground(xfc->display, xfc->gc, xfgcolor.pixel);
XSetBackground(xfc->display, xfc->gc, fgcolor); XSetBackground(xfc->display, xfc->gc, xfgcolor.pixel);
XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled);
XFillRectangle(xfc->display, xfc->drawable, xfc->gc, x, y, width, height); XFillRectangle(xfc->display, xfc->drawable, xfc->gc, x, y, width, height);
} }
XSetForeground(xfc->display, xfc->gc, bgcolor); XSetForeground(xfc->display, xfc->gc, xbgcolor.pixel);
XSetBackground(xfc->display, xfc->gc, fgcolor); XSetBackground(xfc->display, xfc->gc, xfgcolor.pixel);
xf_unlock_x11(xfc, FALSE); xf_unlock_x11(xfc, FALSE);
return TRUE; return TRUE;
} }
@ -426,11 +438,12 @@ static BOOL xf_Glyph_EndDraw(rdpContext* context, UINT32 x, UINT32 y,
{ {
xfContext* xfc = (xfContext*) context; xfContext* xfc = (xfContext*) context;
BOOL ret = TRUE; BOOL ret = TRUE;
XColor xfgcolor, xbgcolor;
if (!xf_decode_color(context->gdi, bgcolor, &bgcolor, NULL)) if (!xf_decode_color(xfc, bgcolor, &xbgcolor))
return FALSE; return FALSE;
if (!xf_decode_color(context->gdi, fgcolor, &fgcolor, NULL)) if (!xf_decode_color(xfc, fgcolor, &xfgcolor))
return FALSE; return FALSE;
if (xfc->drawing == xfc->primary) if (xfc->drawing == xfc->primary)

View File

@ -26,8 +26,7 @@
BOOL xf_register_pointer(rdpGraphics* graphics); BOOL xf_register_pointer(rdpGraphics* graphics);
BOOL xf_register_graphics(rdpGraphics* graphics); BOOL xf_register_graphics(rdpGraphics* graphics);
BOOL xf_decode_color(rdpGdi* gdi, const UINT32 srcColor, BOOL xf_decode_color(xfContext* xfc, const UINT32 srcColor, XColor* color);
UINT32* color, UINT32* format);
UINT32 xf_get_local_color_format(xfContext* xfc, BOOL aligned); UINT32 xf_get_local_color_format(xfContext* xfc, BOOL aligned);
#endif /* __XF_GRAPHICS_H */ #endif /* __XF_GRAPHICS_H */