From 98195e606a1c47c9a9b125c9468d121de9b06f04 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 20 Nov 2014 21:06:39 -0800 Subject: [PATCH] GUAC-852: Abstract away color conversion. --- configure.ac | 9 ++++++ src/protocols/rdp/Makefile.am | 2 ++ src/protocols/rdp/rdp_color.c | 56 +++++++++++++++++++++++++++++++++++ src/protocols/rdp/rdp_color.h | 42 ++++++++++++++++++++++++++ src/protocols/rdp/rdp_gdi.c | 6 ++-- src/protocols/rdp/rdp_glyph.c | 11 ++----- 6 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 src/protocols/rdp/rdp_color.c create mode 100644 src/protocols/rdp/rdp_color.h diff --git a/configure.ac b/configure.ac index bb43e559..d619ccd7 100644 --- a/configure.ac +++ b/configure.ac @@ -423,6 +423,15 @@ then [RDP_LIBS="$RDP_LIBS -lfreerdp-codec"]) fi +# Available color conversion functions +if test "x${have_freerdp}" = "xyes" +then + AC_CHECK_DECL([freerdp_convert_gdi_order_color], + [AC_DEFINE([HAVE_FREERDP_CONVERT_GDI_ORDER_COLOR],, + [Whether freerdp_convert_gdi_order_color() id defined])],, + [#include ]) +fi + # Check for interval polling in plugins if test "x${have_freerdp}" = "xyes" then diff --git a/src/protocols/rdp/Makefile.am b/src/protocols/rdp/Makefile.am index 2550dc46..73328675 100644 --- a/src/protocols/rdp/Makefile.am +++ b/src/protocols/rdp/Makefile.am @@ -33,6 +33,7 @@ libguac_client_rdp_la_SOURCES = \ guac_handlers.c \ rdp_bitmap.c \ rdp_cliprdr.c \ + rdp_color.c \ rdp_fs.c \ rdp_gdi.c \ rdp_glyph.c \ @@ -83,6 +84,7 @@ noinst_HEADERS = \ guac_handlers.h \ rdp_bitmap.h \ rdp_cliprdr.h \ + rdp_color.h \ rdp_fs.h \ rdp_gdi.h \ rdp_glyph.h \ diff --git a/src/protocols/rdp/rdp_color.c b/src/protocols/rdp/rdp_color.c new file mode 100644 index 00000000..5344a4a9 --- /dev/null +++ b/src/protocols/rdp/rdp_color.c @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2013 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "config.h" + +#include "client.h" +#include "rdp_settings.h" + +#include +#include + +#ifdef ENABLE_WINPR +#include +#else +#include "compat/winpr-wtypes.h" +#endif + +UINT32 guac_rdp_convert_color(rdpContext* context, UINT32 color) { + +#ifdef HAVE_FREERDP_CONVERT_GDI_ORDER_COLOR + UINT32* palette = ((rdp_freerdp_context*) context)->palette; + + /* Convert given color to ARGB32 */ + return freerdp_convert_gdi_order_color(color, + guac_rdp_get_depth(context->instance), PIXEL_FORMAT_ARGB32, + (BYTE*) palette); +#else + CLRCONV* clrconv = ((rdp_freerdp_context*) context)->clrconv; + + /* Convert given color to ARGB32 */ + return freerdp_color_convert_var(color, + guac_rdp_get_depth(context->instance), 32, + clrconv); +#endif + +} + diff --git a/src/protocols/rdp/rdp_color.h b/src/protocols/rdp/rdp_color.h new file mode 100644 index 00000000..6c47450b --- /dev/null +++ b/src/protocols/rdp/rdp_color.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2013 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef GUAC_RDP_COLOR_H +#define GUAC_RDP_COLOR_H + +#include + +#ifdef ENABLE_WINPR +#include +#else +#include "compat/winpr-wtypes.h" +#endif + +/** + * Converts the given color to ARGB32. The color given may be an index + * referring to the palette, a 16-bit or 32-bit color, etc. all depending on + * the current color depth of the RDP session. + */ +UINT32 guac_rdp_convert_color(rdpContext* context, UINT32 color); + +#endif + diff --git a/src/protocols/rdp/rdp_gdi.c b/src/protocols/rdp/rdp_gdi.c index e21db36a..f30b3d10 100644 --- a/src/protocols/rdp/rdp_gdi.c +++ b/src/protocols/rdp/rdp_gdi.c @@ -25,6 +25,7 @@ #include "client.h" #include "guac_surface.h" #include "rdp_bitmap.h" +#include "rdp_color.h" #include "rdp_settings.h" #include @@ -320,11 +321,8 @@ void guac_rdp_gdi_opaquerect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect /* Get client data */ guac_client* client = ((rdp_freerdp_context*) context)->client; - UINT32* palette = ((rdp_freerdp_context*) context)->palette; - UINT32 color = freerdp_convert_gdi_order_color(opaque_rect->color, - guac_rdp_get_depth(context->instance), - PIXEL_FORMAT_ARGB32, (BYTE*) palette); + UINT32 color = guac_rdp_convert_color(context, opaque_rect->color); guac_common_surface* current_surface = ((rdp_guac_client_data*) client->data)->current_surface; diff --git a/src/protocols/rdp/rdp_glyph.c b/src/protocols/rdp/rdp_glyph.c index 8053c5ba..735d2ed0 100644 --- a/src/protocols/rdp/rdp_glyph.c +++ b/src/protocols/rdp/rdp_glyph.c @@ -24,6 +24,7 @@ #include "client.h" #include "guac_surface.h" +#include "rdp_color.h" #include "rdp_glyph.h" #include "rdp_settings.h" @@ -128,7 +129,6 @@ void guac_rdp_glyph_begindraw(rdpContext* context, int x, int y, int width, int height, UINT32 fgcolor, UINT32 bgcolor) { guac_client* client = ((rdp_freerdp_context*) context)->client; - UINT32* palette = ((rdp_freerdp_context*) context)->palette; rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data; @@ -136,9 +136,7 @@ void guac_rdp_glyph_begindraw(rdpContext* context, if (width != 0 && height != 0) { /* Convert background color */ - bgcolor = freerdp_convert_gdi_order_color(bgcolor, - guac_rdp_get_depth(context->instance), - PIXEL_FORMAT_ARGB32, (BYTE*) palette); + bgcolor = guac_rdp_convert_color(context, bgcolor); guac_common_surface_rect(guac_client_data->current_surface, x, y, width, height, (bgcolor & 0xFF0000) >> 16, @@ -148,10 +146,7 @@ void guac_rdp_glyph_begindraw(rdpContext* context, } /* Convert foreground color */ - guac_client_data->glyph_color = - freerdp_convert_gdi_order_color(fgcolor, - guac_rdp_get_depth(context->instance), - PIXEL_FORMAT_ARGB32, (BYTE*) palette); + guac_client_data->glyph_color = guac_rdp_convert_color(context, fgcolor); }