diff --git a/src/protocols/rdp/rdp.c b/src/protocols/rdp/rdp.c index 97807934..01ceabac 100644 --- a/src/protocols/rdp/rdp.c +++ b/src/protocols/rdp/rdp.c @@ -130,7 +130,6 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) { rdpGlyph* glyph; rdpPointer* pointer; rdpPrimaryUpdate* primary; - CLRCONV* clrconv; guac_rdp_dvc_list* dvc_list = guac_rdp_dvc_list_alloc(); @@ -227,14 +226,6 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) { /* Dynamic virtual channel list is no longer needed */ guac_rdp_dvc_list_free(dvc_list); - /* Init color conversion structure */ - clrconv = calloc(1, sizeof(CLRCONV)); - clrconv->alpha = 1; - clrconv->invert = 0; - clrconv->rgb555 = 0; - clrconv->palette = calloc(1, sizeof(rdpPalette)); - ((rdp_freerdp_context*) context)->clrconv = clrconv; - /* Init FreeRDP cache */ instance->context->cache = cache_new(instance->settings); @@ -274,7 +265,6 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) { /* Set up GDI */ instance->update->DesktopResize = guac_rdp_gdi_desktop_resize; instance->update->EndPaint = guac_rdp_gdi_end_paint; - instance->update->Palette = guac_rdp_gdi_palette_update; instance->update->SetBounds = guac_rdp_gdi_set_bounds; primary = instance->update->primary; @@ -740,7 +730,6 @@ static int guac_rdp_handle_connection(guac_client* client) { freerdp_disconnect(rdp_inst); /* Clean up RDP client context */ - freerdp_clrconv_free(((rdp_freerdp_context*) rdp_inst->context)->clrconv); cache_free(rdp_inst->context->cache); freerdp_context_free(rdp_inst); diff --git a/src/protocols/rdp/rdp.h b/src/protocols/rdp/rdp.h index ec0f939d..5d181a18 100644 --- a/src/protocols/rdp/rdp.h +++ b/src/protocols/rdp/rdp.h @@ -191,13 +191,6 @@ typedef struct rdp_freerdp_context { */ guac_client* client; -#if 0 - /** - * Color conversion structure to be used to convert RDP images to PNGs. - */ - CLRCONV* clrconv; -#endif - /** * The current color palette, as received from the RDP server. */ diff --git a/src/protocols/rdp/rdp_bitmap.c b/src/protocols/rdp/rdp_bitmap.c index e6343d49..b6c126c7 100644 --- a/src/protocols/rdp/rdp_bitmap.c +++ b/src/protocols/rdp/rdp_bitmap.c @@ -74,19 +74,21 @@ BOOL guac_rdp_bitmap_new(rdpContext* context, rdpBitmap* bitmap) { /* Convert image data if present */ if (bitmap->data != NULL && bitmap->bpp != 32) { - /* Convert image data to 32-bit RGB */ - unsigned char* image_buffer = freerdp_image_convert(bitmap->data, NULL, - bitmap->width, bitmap->height, - guac_rdp_get_depth(context->instance), - 32, ((rdp_freerdp_context*) context)->clrconv); + /* Allocate sufficient space for converted image */ + unsigned char* image_buffer = _aligned_malloc(bitmap->width * bitmap->height * 4, 16); - /* Free existing image, if any */ - if (image_buffer != bitmap->data) { - _aligned_free(bitmap->data); + /* Attempt image conversion */ + if (!freerdp_image_copy(image_buffer, PIXEL_FORMAT_ARGB32, 0, 0, 0, + bitmap->width, bitmap->height, bitmap->data, bitmap->format, + 0, 0, 0, &context->gdi->palette, FREERDP_FLIP_NONE)) { + _aligned_free(image_buffer); } - /* Store converted image in bitmap */ - bitmap->data = image_buffer; + /* If successful, replace original image with converted image */ + else { + _aligned_free(bitmap->data); + bitmap->data = image_buffer; + } } diff --git a/src/protocols/rdp/rdp_color.c b/src/protocols/rdp/rdp_color.c index 98345a12..b2d0d0bc 100644 --- a/src/protocols/rdp/rdp_color.c +++ b/src/protocols/rdp/rdp_color.c @@ -27,13 +27,55 @@ #include #include -UINT32 guac_rdp_convert_color(rdpContext* context, UINT32 color) { +/** + * Returns the integer constant used by the FreeRDP API to represent the colors + * used by a connection having the given bit depth. These constants each have + * corresponding PIXEL_FORMAT_* macros defined within freerdp/codec/color.h. + * + * @param depth + * The color depth which should be translated into the integer constant + * defined by FreeRDP's corresponding PIXEL_FORMAT_* macro. + * + * @return + * The integer value of the PIXEL_FORMAT_* macro corresponding to the + * given color depth. + */ +static UINT32 guac_rdp_get_pixel_format(int depth) { - CLRCONV* clrconv = ((rdp_freerdp_context*) context)->clrconv; + switch (depth) { - /* Convert given color to ARGB32 */ - return freerdp_color_convert_drawing_order_color_to_gdi_color(color, - guac_rdp_get_depth(context->instance), clrconv); + /* 32- and 24-bit RGB (8 bits per color component) */ + case 32: + case 24: + return PIXEL_FORMAT_BGR24; + + /* 16-bit palette (6-bit green, 5-bit red and blue) */ + case 16: + return PIXEL_FORMAT_RGB16; + + /* 15-bit RGB (5 bits per color component) */ + case 15: + return PIXEL_FORMAT_RGB15; + + /* 8-bit palette */ + case 8: + return PIXEL_FORMAT_RGB8; + + } + + /* Unknown format */ + return PIXEL_FORMAT_BGR24; + +} + +UINT32 guac_rdp_convert_color(rdpContext* context, UINT32 color) { + + int depth = guac_rdp_get_depth(context->instance); + rdpGdi* gdi = context->gdi; + + /* Convert given color to ARGB32 */ + return FreeRDPConvertColor(color, guac_rdp_get_pixel_format(depth), + PIXEL_FORMAT_ARGB32, &gdi->palette); } diff --git a/src/protocols/rdp/rdp_gdi.c b/src/protocols/rdp/rdp_gdi.c index 7ea64cae..fef672c1 100644 --- a/src/protocols/rdp/rdp_gdi.c +++ b/src/protocols/rdp/rdp_gdi.c @@ -340,71 +340,6 @@ void guac_rdp_gdi_opaquerect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect } -#if 0 -/** - * Updates the palette within a FreeRDP CLRCONV object using the new palette - * entries provided by an RDP palette update. - * - * @param clrconv - * The FreeRDP CLRCONV object to update. - * - * @param palette - * An RDP palette update message containing the palette to store within the - * given CLRCONV object. - */ -static void guac_rdp_update_clrconv(CLRCONV* clrconv, - PALETTE_UPDATE* palette) { - - clrconv->palette->count = palette->number; - memcpy(clrconv->palette->entries, palette->entries, - sizeof(palette->entries)); - -} -#endif - -/** - * Updates a raw ARGB32 palette using the new palette entries provided by an - * RDP palette update. - * - * @param guac_palette - * An array of 256 ARGB32 colors, with each entry corresponding to an - * entry in the color palette. - * - * @param palette - * An RDP palette update message containing the palette to store within the - * given array of ARGB32 colors. - */ -static void guac_rdp_update_palette(UINT32* guac_palette, - PALETTE_UPDATE* palette) { - - PALETTE_ENTRY* entry = palette->entries; - int i; - - /* Copy each palette entry as ARGB32 */ - for (i=0; i < palette->number; i++) { - - *guac_palette = 0xFF000000 - | (entry->red << 16) - | (entry->green << 8) - | entry->blue; - - guac_palette++; - entry++; - } - -} - -void guac_rdp_gdi_palette_update(rdpContext* context, PALETTE_UPDATE* palette) { -#if 0 - CLRCONV* clrconv = ((rdp_freerdp_context*) context)->clrconv; - UINT32* guac_palette = ((rdp_freerdp_context*) context)->palette; - - /* Update internal palette representations */ - guac_rdp_update_clrconv(clrconv, palette); - guac_rdp_update_palette(guac_palette, palette); -#endif -} - void guac_rdp_gdi_set_bounds(rdpContext* context, rdpBounds* bounds) { guac_client* client = ((rdp_freerdp_context*) context)->client; diff --git a/src/protocols/rdp/rdp_pointer.c b/src/protocols/rdp/rdp_pointer.c index fae8ed01..303b6ef0 100644 --- a/src/protocols/rdp/rdp_pointer.c +++ b/src/protocols/rdp/rdp_pointer.c @@ -41,17 +41,17 @@ void guac_rdp_pointer_new(rdpContext* context, rdpPointer* pointer) { rdp_client->display, pointer->width, pointer->height); /* Allocate data for image */ - unsigned char* data = - (unsigned char*) malloc(pointer->width * pointer->height * 4); + unsigned char* data = _aligned_malloc(pointer->width * pointer->height * 4, 16); cairo_surface_t* surface; /* Convert to alpha cursor if mask data present */ if (pointer->andMaskData && pointer->xorMaskData) - freerdp_alpha_cursor_convert(data, - pointer->xorMaskData, pointer->andMaskData, - pointer->width, pointer->height, pointer->xorBpp, - ((rdp_freerdp_context*) context)->clrconv); + freerdp_image_copy_from_pointer_data(data, 0, 0, 0, + pointer->width, pointer->height, + pointer->xorMaskData, pointer->lengthXorMask, + pointer->andMaskData, pointer->lengthAndMask, + pointer->xorBpp, &context->gdi->palette); /* Create surface from image data */ surface = cairo_image_surface_create_for_data( @@ -63,7 +63,7 @@ void guac_rdp_pointer_new(rdpContext* context, rdpPointer* pointer) { /* Free surface */ cairo_surface_destroy(surface); - free(data); + _aligned_free(data); /* Remember buffer */ ((guac_rdp_pointer*) pointer)->layer = buffer;