GUACAMOLE-249: Remove usage of CLRCONV.

This commit is contained in:
Michael Jumper 2019-09-21 16:09:50 -07:00
parent 17d31d94b7
commit 554251cc72
6 changed files with 66 additions and 105 deletions

View File

@ -130,7 +130,6 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) {
rdpGlyph* glyph; rdpGlyph* glyph;
rdpPointer* pointer; rdpPointer* pointer;
rdpPrimaryUpdate* primary; rdpPrimaryUpdate* primary;
CLRCONV* clrconv;
guac_rdp_dvc_list* dvc_list = guac_rdp_dvc_list_alloc(); 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 */ /* Dynamic virtual channel list is no longer needed */
guac_rdp_dvc_list_free(dvc_list); 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 */ /* Init FreeRDP cache */
instance->context->cache = cache_new(instance->settings); instance->context->cache = cache_new(instance->settings);
@ -274,7 +265,6 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) {
/* Set up GDI */ /* Set up GDI */
instance->update->DesktopResize = guac_rdp_gdi_desktop_resize; instance->update->DesktopResize = guac_rdp_gdi_desktop_resize;
instance->update->EndPaint = guac_rdp_gdi_end_paint; instance->update->EndPaint = guac_rdp_gdi_end_paint;
instance->update->Palette = guac_rdp_gdi_palette_update;
instance->update->SetBounds = guac_rdp_gdi_set_bounds; instance->update->SetBounds = guac_rdp_gdi_set_bounds;
primary = instance->update->primary; primary = instance->update->primary;
@ -740,7 +730,6 @@ static int guac_rdp_handle_connection(guac_client* client) {
freerdp_disconnect(rdp_inst); freerdp_disconnect(rdp_inst);
/* Clean up RDP client context */ /* Clean up RDP client context */
freerdp_clrconv_free(((rdp_freerdp_context*) rdp_inst->context)->clrconv);
cache_free(rdp_inst->context->cache); cache_free(rdp_inst->context->cache);
freerdp_context_free(rdp_inst); freerdp_context_free(rdp_inst);

View File

@ -191,13 +191,6 @@ typedef struct rdp_freerdp_context {
*/ */
guac_client* client; 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. * The current color palette, as received from the RDP server.
*/ */

View File

@ -74,19 +74,21 @@ BOOL guac_rdp_bitmap_new(rdpContext* context, rdpBitmap* bitmap) {
/* Convert image data if present */ /* Convert image data if present */
if (bitmap->data != NULL && bitmap->bpp != 32) { if (bitmap->data != NULL && bitmap->bpp != 32) {
/* Convert image data to 32-bit RGB */ /* Allocate sufficient space for converted image */
unsigned char* image_buffer = freerdp_image_convert(bitmap->data, NULL, unsigned char* image_buffer = _aligned_malloc(bitmap->width * bitmap->height * 4, 16);
bitmap->width, bitmap->height,
guac_rdp_get_depth(context->instance),
32, ((rdp_freerdp_context*) context)->clrconv);
/* Free existing image, if any */ /* Attempt image conversion */
if (image_buffer != bitmap->data) { if (!freerdp_image_copy(image_buffer, PIXEL_FORMAT_ARGB32, 0, 0, 0,
_aligned_free(bitmap->data); 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 */ /* If successful, replace original image with converted image */
else {
_aligned_free(bitmap->data);
bitmap->data = image_buffer; bitmap->data = image_buffer;
}
} }

View File

@ -27,13 +27,55 @@
#include <freerdp/freerdp.h> #include <freerdp/freerdp.h>
#include <winpr/wtypes.h> #include <winpr/wtypes.h>
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 */ /* 32- and 24-bit RGB (8 bits per color component) */
return freerdp_color_convert_drawing_order_color_to_gdi_color(color, case 32:
guac_rdp_get_depth(context->instance), clrconv); 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);
} }

View File

@ -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) { void guac_rdp_gdi_set_bounds(rdpContext* context, rdpBounds* bounds) {
guac_client* client = ((rdp_freerdp_context*) context)->client; guac_client* client = ((rdp_freerdp_context*) context)->client;

View File

@ -41,17 +41,17 @@ void guac_rdp_pointer_new(rdpContext* context, rdpPointer* pointer) {
rdp_client->display, pointer->width, pointer->height); rdp_client->display, pointer->width, pointer->height);
/* Allocate data for image */ /* Allocate data for image */
unsigned char* data = unsigned char* data = _aligned_malloc(pointer->width * pointer->height * 4, 16);
(unsigned char*) malloc(pointer->width * pointer->height * 4);
cairo_surface_t* surface; cairo_surface_t* surface;
/* Convert to alpha cursor if mask data present */ /* Convert to alpha cursor if mask data present */
if (pointer->andMaskData && pointer->xorMaskData) if (pointer->andMaskData && pointer->xorMaskData)
freerdp_alpha_cursor_convert(data, freerdp_image_copy_from_pointer_data(data, 0, 0, 0,
pointer->xorMaskData, pointer->andMaskData, pointer->width, pointer->height,
pointer->width, pointer->height, pointer->xorBpp, pointer->xorMaskData, pointer->lengthXorMask,
((rdp_freerdp_context*) context)->clrconv); pointer->andMaskData, pointer->lengthAndMask,
pointer->xorBpp, &context->gdi->palette);
/* Create surface from image data */ /* Create surface from image data */
surface = cairo_image_surface_create_for_data( surface = cairo_image_surface_create_for_data(
@ -63,7 +63,7 @@ void guac_rdp_pointer_new(rdpContext* context, rdpPointer* pointer) {
/* Free surface */ /* Free surface */
cairo_surface_destroy(surface); cairo_surface_destroy(surface);
free(data); _aligned_free(data);
/* Remember buffer */ /* Remember buffer */
((guac_rdp_pointer*) pointer)->layer = buffer; ((guac_rdp_pointer*) pointer)->layer = buffer;