2013-12-29 04:53:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Glyptodon LLC
|
2012-01-03 01:59:52 +00:00
|
|
|
*
|
2013-12-29 04:53:12 +00:00
|
|
|
* 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:
|
2012-01-03 01:59:52 +00:00
|
|
|
*
|
2013-12-29 04:53:12 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2012-01-03 01:59:52 +00:00
|
|
|
*
|
2013-12-29 04:53:12 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-01-01 22:44:28 +00:00
|
|
|
#include "config.h"
|
2012-01-03 01:59:52 +00:00
|
|
|
|
2014-01-01 22:44:28 +00:00
|
|
|
#include "client.h"
|
2014-04-30 18:44:06 +00:00
|
|
|
#include "guac_surface.h"
|
2014-01-01 22:44:28 +00:00
|
|
|
#include "rdp_bitmap.h"
|
2014-06-11 01:45:14 +00:00
|
|
|
#include "rdp_settings.h"
|
2012-01-03 01:59:52 +00:00
|
|
|
|
|
|
|
#include <cairo/cairo.h>
|
2014-01-01 22:44:28 +00:00
|
|
|
#include <freerdp/codec/bitmap.h>
|
|
|
|
#include <freerdp/codec/color.h>
|
|
|
|
#include <freerdp/freerdp.h>
|
2012-01-03 01:59:52 +00:00
|
|
|
#include <guacamole/client.h>
|
2014-01-01 22:44:28 +00:00
|
|
|
#include <guacamole/socket.h>
|
2012-01-03 01:59:52 +00:00
|
|
|
|
2013-07-17 18:54:24 +00:00
|
|
|
#ifdef ENABLE_WINPR
|
|
|
|
#include <winpr/wtypes.h>
|
|
|
|
#else
|
|
|
|
#include "compat/winpr-wtypes.h"
|
|
|
|
#endif
|
|
|
|
|
2014-06-11 01:45:14 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-04-10 21:23:37 +00:00
|
|
|
void guac_rdp_cache_bitmap(rdpContext* context, rdpBitmap* bitmap) {
|
2012-01-03 01:59:52 +00:00
|
|
|
|
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
|
|
|
guac_socket* socket = client->socket;
|
|
|
|
|
2014-04-30 18:44:06 +00:00
|
|
|
/* Allocate surface */
|
2012-04-10 18:51:46 +00:00
|
|
|
guac_layer* buffer = guac_client_alloc_buffer(client);
|
2015-08-11 22:18:12 +00:00
|
|
|
guac_common_surface* surface = guac_common_surface_alloc(client, socket,
|
|
|
|
buffer, bitmap->width, bitmap->height);
|
2012-04-10 18:51:46 +00:00
|
|
|
|
2012-04-10 18:04:38 +00:00
|
|
|
/* Cache image data if present */
|
|
|
|
if (bitmap->data != NULL) {
|
|
|
|
|
|
|
|
/* Create surface from image data */
|
2014-04-30 18:44:06 +00:00
|
|
|
cairo_surface_t* image = cairo_image_surface_create_for_data(
|
2012-04-10 18:04:38 +00:00
|
|
|
bitmap->data, CAIRO_FORMAT_RGB24,
|
|
|
|
bitmap->width, bitmap->height, 4*bitmap->width);
|
|
|
|
|
|
|
|
/* Send surface to buffer */
|
2014-04-30 18:44:06 +00:00
|
|
|
guac_common_surface_draw(surface, 0, 0, image);
|
2012-04-10 18:04:38 +00:00
|
|
|
|
|
|
|
/* Free surface */
|
2014-04-30 18:44:06 +00:00
|
|
|
cairo_surface_destroy(image);
|
2012-04-10 18:04:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-10 18:51:46 +00:00
|
|
|
/* Store buffer reference in bitmap */
|
2014-04-30 18:44:06 +00:00
|
|
|
((guac_rdp_bitmap*) bitmap)->buffer = buffer;
|
|
|
|
((guac_rdp_bitmap*) bitmap)->surface = surface;
|
2012-04-10 18:51:46 +00:00
|
|
|
|
2012-04-10 18:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void guac_rdp_bitmap_new(rdpContext* context, rdpBitmap* bitmap) {
|
2012-02-08 23:09:12 +00:00
|
|
|
|
2012-01-03 01:59:52 +00:00
|
|
|
/* Convert image data if present */
|
2014-11-20 22:58:14 +00:00
|
|
|
if (bitmap->data != NULL && bitmap->bpp != 32) {
|
2012-01-03 01:59:52 +00:00
|
|
|
|
|
|
|
/* Convert image data to 32-bit RGB */
|
|
|
|
unsigned char* image_buffer = freerdp_image_convert(bitmap->data, NULL,
|
|
|
|
bitmap->width, bitmap->height,
|
2014-07-21 16:12:17 +00:00
|
|
|
guac_rdp_get_depth(context->instance),
|
2012-02-08 20:32:27 +00:00
|
|
|
32, ((rdp_freerdp_context*) context)->clrconv);
|
2012-01-03 01:59:52 +00:00
|
|
|
|
2012-04-10 18:04:38 +00:00
|
|
|
/* Free existing image, if any */
|
2014-11-21 05:41:38 +00:00
|
|
|
if (image_buffer != bitmap->data) {
|
|
|
|
#ifdef FREERDP_BITMAP_REQUIRES_ALIGNED_MALLOC
|
2014-11-21 03:21:11 +00:00
|
|
|
_aligned_free(bitmap->data);
|
2014-11-21 05:41:38 +00:00
|
|
|
#else
|
|
|
|
free(bitmap->data);
|
|
|
|
#endif
|
|
|
|
}
|
2012-02-08 20:11:32 +00:00
|
|
|
|
2012-04-10 18:04:38 +00:00
|
|
|
/* Store converted image in bitmap */
|
|
|
|
bitmap->data = image_buffer;
|
2012-02-08 20:11:32 +00:00
|
|
|
|
2012-01-03 01:59:52 +00:00
|
|
|
}
|
|
|
|
|
2014-04-30 18:44:06 +00:00
|
|
|
/* No corresponding surface yet - caching is deferred. */
|
|
|
|
((guac_rdp_bitmap*) bitmap)->buffer = NULL;
|
|
|
|
((guac_rdp_bitmap*) bitmap)->surface = NULL;
|
2012-04-10 20:21:13 +00:00
|
|
|
|
|
|
|
/* Start at zero usage */
|
|
|
|
((guac_rdp_bitmap*) bitmap)->used = 0;
|
2012-04-10 18:04:38 +00:00
|
|
|
|
2012-01-03 01:59:52 +00:00
|
|
|
}
|
|
|
|
|
2012-01-03 21:04:50 +00:00
|
|
|
void guac_rdp_bitmap_paint(rdpContext* context, rdpBitmap* bitmap) {
|
2012-01-03 21:20:24 +00:00
|
|
|
|
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
2014-04-30 18:44:06 +00:00
|
|
|
rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;
|
|
|
|
|
|
|
|
guac_common_surface* surface = ((guac_rdp_bitmap*) bitmap)->surface;
|
2012-01-03 21:20:24 +00:00
|
|
|
|
2012-03-05 20:10:03 +00:00
|
|
|
int width = bitmap->right - bitmap->left + 1;
|
|
|
|
int height = bitmap->bottom - bitmap->top + 1;
|
2012-03-01 20:27:25 +00:00
|
|
|
|
2012-04-10 20:21:13 +00:00
|
|
|
/* If not cached, cache if necessary */
|
2014-04-30 18:44:06 +00:00
|
|
|
if (surface == NULL && ((guac_rdp_bitmap*) bitmap)->used >= 1)
|
2012-04-10 21:23:37 +00:00
|
|
|
guac_rdp_cache_bitmap(context, bitmap);
|
2012-04-10 20:21:13 +00:00
|
|
|
|
2012-04-10 18:04:38 +00:00
|
|
|
/* If cached, retrieve from cache */
|
2014-04-30 18:44:06 +00:00
|
|
|
if (surface != NULL)
|
|
|
|
guac_common_surface_copy(surface, 0, 0, width, height,
|
|
|
|
client_data->default_surface, bitmap->left, bitmap->top);
|
2012-04-03 21:03:52 +00:00
|
|
|
|
|
|
|
/* Otherwise, draw with stored image data */
|
|
|
|
else if (bitmap->data != NULL) {
|
|
|
|
|
|
|
|
/* Create surface from image data */
|
2014-04-30 18:44:06 +00:00
|
|
|
cairo_surface_t* image = cairo_image_surface_create_for_data(
|
2012-04-03 21:03:52 +00:00
|
|
|
bitmap->data, CAIRO_FORMAT_RGB24,
|
|
|
|
width, height, 4*bitmap->width);
|
|
|
|
|
2014-04-30 18:44:06 +00:00
|
|
|
/* Draw image on default surface */
|
|
|
|
guac_common_surface_draw(client_data->default_surface, bitmap->left, bitmap->top, image);
|
2012-04-03 21:03:52 +00:00
|
|
|
|
|
|
|
/* Free surface */
|
2014-04-30 18:44:06 +00:00
|
|
|
cairo_surface_destroy(image);
|
2012-04-03 21:03:52 +00:00
|
|
|
|
|
|
|
}
|
2012-02-08 20:11:32 +00:00
|
|
|
|
2012-04-10 20:21:13 +00:00
|
|
|
/* Increment usage counter */
|
|
|
|
((guac_rdp_bitmap*) bitmap)->used++;
|
|
|
|
|
2012-01-03 21:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void guac_rdp_bitmap_free(rdpContext* context, rdpBitmap* bitmap) {
|
2014-04-30 18:44:06 +00:00
|
|
|
|
2012-01-03 21:04:50 +00:00
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
2014-04-30 18:44:06 +00:00
|
|
|
guac_layer* buffer = ((guac_rdp_bitmap*) bitmap)->buffer;
|
|
|
|
guac_common_surface* surface = ((guac_rdp_bitmap*) bitmap)->surface;
|
2012-02-08 20:32:27 +00:00
|
|
|
|
2014-04-30 18:44:06 +00:00
|
|
|
/* If cached, free surface */
|
|
|
|
if (surface != NULL)
|
|
|
|
guac_common_surface_free(surface);
|
2012-04-10 20:21:13 +00:00
|
|
|
|
2014-04-30 19:32:19 +00:00
|
|
|
/* If cached, free buffer */
|
|
|
|
if (buffer != NULL)
|
|
|
|
guac_client_free_buffer(client, buffer);
|
|
|
|
|
2012-01-03 21:04:50 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 18:54:24 +00:00
|
|
|
void guac_rdp_bitmap_setsurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary) {
|
2014-04-30 18:44:06 +00:00
|
|
|
|
2012-01-03 21:39:59 +00:00
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
2014-04-30 18:44:06 +00:00
|
|
|
rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;
|
2012-01-11 07:31:24 +00:00
|
|
|
|
2012-02-08 20:11:32 +00:00
|
|
|
if (primary)
|
2014-04-30 18:44:06 +00:00
|
|
|
client_data->current_surface = client_data->default_surface;
|
2012-04-10 18:04:38 +00:00
|
|
|
|
|
|
|
else {
|
|
|
|
|
2013-06-14 06:38:20 +00:00
|
|
|
/* Make sure that the recieved bitmap is not NULL before processing */
|
|
|
|
if (bitmap == NULL) {
|
2014-11-08 00:32:19 +00:00
|
|
|
guac_client_log(client, GUAC_LOG_INFO, "NULL bitmap found in bitmap_setsurface instruction.");
|
2013-06-14 06:38:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-10 18:51:46 +00:00
|
|
|
/* If not available as a surface, make available. */
|
2014-04-30 18:44:06 +00:00
|
|
|
if (((guac_rdp_bitmap*) bitmap)->surface == NULL)
|
2012-04-10 21:23:37 +00:00
|
|
|
guac_rdp_cache_bitmap(context, bitmap);
|
2012-04-10 18:51:46 +00:00
|
|
|
|
2014-04-30 18:44:06 +00:00
|
|
|
client_data->current_surface = ((guac_rdp_bitmap*) bitmap)->surface;
|
2012-04-10 18:04:38 +00:00
|
|
|
|
|
|
|
}
|
2012-02-08 23:09:12 +00:00
|
|
|
|
2012-01-03 21:39:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 18:35:40 +00:00
|
|
|
#ifdef LEGACY_RDPBITMAP
|
|
|
|
void guac_rdp_bitmap_decompress(rdpContext* context, rdpBitmap* bitmap, UINT8* data,
|
|
|
|
int width, int height, int bpp, int length, BOOL compressed) {
|
|
|
|
#else
|
|
|
|
void guac_rdp_bitmap_decompress(rdpContext* context, rdpBitmap* bitmap, UINT8* data,
|
|
|
|
int width, int height, int bpp, int length, BOOL compressed, int codec_id) {
|
|
|
|
#endif
|
2012-01-11 07:31:24 +00:00
|
|
|
|
2014-11-20 22:58:14 +00:00
|
|
|
int size = width * height * 4;
|
2012-01-11 07:31:24 +00:00
|
|
|
|
2014-11-21 05:41:38 +00:00
|
|
|
#ifdef FREERDP_BITMAP_REQUIRES_ALIGNED_MALLOC
|
2015-02-24 04:24:28 +00:00
|
|
|
/* Free pre-existing data, if any (might be reused) */
|
|
|
|
if (bitmap->data != NULL)
|
|
|
|
_aligned_free(bitmap->data);
|
|
|
|
|
|
|
|
/* Allocate new data */
|
2014-11-20 22:58:14 +00:00
|
|
|
bitmap->data = (UINT8*) _aligned_malloc(size, 16);
|
2014-11-21 05:41:38 +00:00
|
|
|
#else
|
2015-02-24 04:24:28 +00:00
|
|
|
/* Free pre-existing data, if any (might be reused) */
|
|
|
|
free(bitmap->data);
|
|
|
|
|
|
|
|
/* Allocate new data */
|
2014-11-21 05:41:38 +00:00
|
|
|
bitmap->data = (UINT8*) malloc(size);
|
|
|
|
#endif
|
2012-01-11 07:31:24 +00:00
|
|
|
|
2014-11-21 02:39:05 +00:00
|
|
|
if (compressed) {
|
|
|
|
|
2014-11-21 03:21:11 +00:00
|
|
|
#ifdef HAVE_RDPCONTEXT_CODECS
|
2014-11-21 02:39:05 +00:00
|
|
|
rdpCodecs* codecs = context->codecs;
|
|
|
|
|
|
|
|
/* Decode as interleaved if less than 32 bits per pixel */
|
|
|
|
if (bpp < 32) {
|
|
|
|
freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_INTERLEAVED);
|
2015-01-23 23:08:00 +00:00
|
|
|
#ifdef INTERLEAVED_DECOMPRESS_TAKES_PALETTE
|
2014-11-21 02:39:05 +00:00
|
|
|
interleaved_decompress(codecs->interleaved, data, length, bpp,
|
|
|
|
&(bitmap->data), PIXEL_FORMAT_XRGB32, -1, 0, 0, width, height,
|
2015-01-23 23:08:00 +00:00
|
|
|
(BYTE*) ((rdp_freerdp_context*) context)->palette);
|
|
|
|
bitmap->bpp = 32;
|
|
|
|
#else
|
|
|
|
interleaved_decompress(codecs->interleaved, data, length, bpp,
|
|
|
|
&(bitmap->data), PIXEL_FORMAT_XRGB32, -1, 0, 0, width, height);
|
|
|
|
bitmap->bpp = bpp;
|
|
|
|
#endif
|
2014-11-21 02:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, decode as planar */
|
|
|
|
else {
|
|
|
|
freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_PLANAR);
|
2015-01-23 23:08:00 +00:00
|
|
|
#ifdef PLANAR_DECOMPRESS_CAN_FLIP
|
|
|
|
planar_decompress(codecs->planar, data, length,
|
|
|
|
&(bitmap->data), PIXEL_FORMAT_XRGB32, -1, 0, 0, width, height,
|
|
|
|
TRUE);
|
|
|
|
bitmap->bpp = 32;
|
|
|
|
#else
|
2014-11-21 02:39:05 +00:00
|
|
|
planar_decompress(codecs->planar, data, length,
|
2015-01-23 23:08:00 +00:00
|
|
|
&(bitmap->data), PIXEL_FORMAT_XRGB32, -1, 0, 0, width, height);
|
|
|
|
bitmap->bpp = bpp;
|
|
|
|
#endif
|
2014-11-21 02:39:05 +00:00
|
|
|
}
|
2014-11-21 03:21:11 +00:00
|
|
|
#else
|
|
|
|
bitmap_decompress(data, bitmap->data, width, height, length, bpp, bpp);
|
|
|
|
bitmap->bpp = bpp;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
freerdp_image_flip(data, bitmap->data, width, height, bpp);
|
|
|
|
bitmap->bpp = bpp;
|
2014-11-21 02:39:05 +00:00
|
|
|
}
|
2012-01-11 07:31:24 +00:00
|
|
|
|
2013-07-17 18:54:24 +00:00
|
|
|
bitmap->compressed = FALSE;
|
2012-01-11 07:31:24 +00:00
|
|
|
bitmap->length = size;
|
|
|
|
|
2012-01-08 23:18:31 +00:00
|
|
|
}
|
|
|
|
|