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)
{
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);

View File

@ -42,25 +42,36 @@
#include <freerdp/log.h>
#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 (!gdi || !gdi->context || !gdi->context->settings)
if (!xfc || !color)
return FALSE;
xfc = (xfContext*)gdi->context;
SrcFormat = gdi_get_pixel_format(gdi->context->settings->ColorDepth);
gdi = xfc->context.gdi;
if (format)
*format = SrcFormat;
if (!gdi)
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;
}
@ -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)

View File

@ -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 */