2013-12-29 04:53:12 +00:00
|
|
|
/*
|
2016-03-25 19:59:40 +00:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
2012-01-03 21:48:20 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-01-03 21:48:20 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2013-12-29 04:53:12 +00:00
|
|
|
*/
|
|
|
|
|
2019-12-23 20:48:22 +00:00
|
|
|
#include "color.h"
|
2019-12-23 21:29:13 +00:00
|
|
|
#include "common/surface.h"
|
2020-01-04 21:07:28 +00:00
|
|
|
#include "config.h"
|
2019-12-23 20:48:22 +00:00
|
|
|
#include "glyph.h"
|
2019-12-23 21:29:13 +00:00
|
|
|
#include "rdp.h"
|
2014-01-01 22:44:28 +00:00
|
|
|
|
2012-01-03 21:48:20 +00:00
|
|
|
#include <freerdp/freerdp.h>
|
2014-01-01 22:44:28 +00:00
|
|
|
#include <guacamole/client.h>
|
2013-07-17 18:54:24 +00:00
|
|
|
#include <winpr/wtypes.h>
|
|
|
|
|
2014-06-11 01:45:14 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-07-08 20:03:04 +00:00
|
|
|
/* Define cairo_format_stride_for_width() if missing */
|
|
|
|
#ifndef HAVE_CAIRO_FORMAT_STRIDE_FOR_WIDTH
|
|
|
|
#define cairo_format_stride_for_width(format, width) (width*4)
|
|
|
|
#endif
|
|
|
|
|
2017-03-26 02:59:04 +00:00
|
|
|
BOOL guac_rdp_glyph_new(rdpContext* context, const rdpGlyph* glyph) {
|
2012-02-09 18:09:14 +00:00
|
|
|
|
|
|
|
int x, y, i;
|
|
|
|
int stride;
|
|
|
|
unsigned char* image_buffer;
|
|
|
|
unsigned char* image_buffer_row;
|
|
|
|
|
|
|
|
unsigned char* data = glyph->aj;
|
|
|
|
int width = glyph->cx;
|
|
|
|
int height = glyph->cy;
|
|
|
|
|
|
|
|
/* Init Cairo buffer */
|
|
|
|
stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
|
|
|
|
image_buffer = malloc(height*stride);
|
|
|
|
image_buffer_row = image_buffer;
|
|
|
|
|
|
|
|
/* Copy image data from image data to buffer */
|
|
|
|
for (y = 0; y<height; y++) {
|
|
|
|
|
|
|
|
unsigned int* image_buffer_current;
|
|
|
|
|
|
|
|
/* Get current buffer row, advance to next */
|
|
|
|
image_buffer_current = (unsigned int*) image_buffer_row;
|
|
|
|
image_buffer_row += stride;
|
|
|
|
|
|
|
|
for (x = 0; x<width;) {
|
|
|
|
|
|
|
|
/* Get byte from image data */
|
|
|
|
unsigned int v = *(data++);
|
|
|
|
|
|
|
|
/* Read bits, write pixels */
|
|
|
|
for (i = 0; i<8 && x<width; i++, x++) {
|
|
|
|
|
|
|
|
/* Output RGB */
|
|
|
|
if (v & 0x80)
|
|
|
|
*(image_buffer_current++) = 0xFF000000;
|
|
|
|
else
|
|
|
|
*(image_buffer_current++) = 0x00000000;
|
|
|
|
|
|
|
|
/* Next bit */
|
|
|
|
v <<= 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-05 23:45:04 +00:00
|
|
|
/* Store glyph surface */
|
|
|
|
((guac_rdp_glyph*) glyph)->surface = cairo_image_surface_create_for_data(
|
|
|
|
image_buffer, CAIRO_FORMAT_ARGB32, width, height, stride);
|
2012-02-09 18:09:14 +00:00
|
|
|
|
2017-03-26 02:59:04 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2012-01-03 21:48:20 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 02:59:04 +00:00
|
|
|
BOOL guac_rdp_glyph_draw(rdpContext* context, const rdpGlyph* glyph,
|
2019-09-22 18:09:44 +00:00
|
|
|
INT32 x, INT32 y, INT32 w, INT32 h, INT32 sx, INT32 sy,
|
2019-09-29 22:03:40 +00:00
|
|
|
BOOL redundant) {
|
2012-02-09 18:09:14 +00:00
|
|
|
|
2012-01-03 21:48:20 +00:00
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
|
|
|
guac_common_surface* current_surface = rdp_client->current_surface;
|
|
|
|
uint32_t fgcolor = rdp_client->glyph_color;
|
2012-04-06 05:38:10 +00:00
|
|
|
|
2014-05-05 07:28:07 +00:00
|
|
|
/* Paint with glyph as mask */
|
|
|
|
guac_common_surface_paint(current_surface, x, y, ((guac_rdp_glyph*) glyph)->surface,
|
|
|
|
(fgcolor & 0xFF0000) >> 16,
|
|
|
|
(fgcolor & 0x00FF00) >> 8,
|
|
|
|
fgcolor & 0x0000FF);
|
2012-04-05 23:45:04 +00:00
|
|
|
|
2017-03-26 02:59:04 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2012-01-03 21:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void guac_rdp_glyph_free(rdpContext* context, rdpGlyph* glyph) {
|
2012-04-05 23:45:04 +00:00
|
|
|
|
|
|
|
unsigned char* image_buffer = cairo_image_surface_get_data(
|
|
|
|
((guac_rdp_glyph*) glyph)->surface);
|
|
|
|
|
|
|
|
/* Free surface */
|
|
|
|
cairo_surface_destroy(((guac_rdp_glyph*) glyph)->surface);
|
|
|
|
free(image_buffer);
|
|
|
|
|
2019-12-31 00:11:13 +00:00
|
|
|
/* NOTE: FreeRDP-allocated memory for the rdpGlyph will NOT be
|
|
|
|
* automatically released after this free handler is invoked, thus we must
|
|
|
|
* do so manually here */
|
|
|
|
|
|
|
|
free(glyph->aj);
|
|
|
|
free(glyph);
|
|
|
|
|
2012-01-03 21:48:20 +00:00
|
|
|
}
|
|
|
|
|
2019-09-22 18:09:44 +00:00
|
|
|
BOOL guac_rdp_glyph_begindraw(rdpContext* context, INT32 x, INT32 y,
|
|
|
|
INT32 width, INT32 height, UINT32 fgcolor, UINT32 bgcolor,
|
|
|
|
BOOL redundant) {
|
2012-02-09 18:25:06 +00:00
|
|
|
|
2012-01-09 03:23:37 +00:00
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_rdp_client* rdp_client =
|
|
|
|
(guac_rdp_client*) client->data;
|
2012-02-09 18:25:06 +00:00
|
|
|
|
2012-04-06 05:38:10 +00:00
|
|
|
/* Fill background with color if specified */
|
2020-01-02 04:33:46 +00:00
|
|
|
if (width != 0 && height != 0 && !redundant) {
|
2012-02-09 18:25:06 +00:00
|
|
|
|
2012-04-06 05:38:10 +00:00
|
|
|
/* Convert background color */
|
2014-11-21 05:06:39 +00:00
|
|
|
bgcolor = guac_rdp_convert_color(context, bgcolor);
|
2012-03-01 20:37:00 +00:00
|
|
|
|
2016-12-20 05:13:20 +00:00
|
|
|
guac_common_surface_set(rdp_client->current_surface,
|
|
|
|
x, y, width, height,
|
|
|
|
(bgcolor & 0xFF0000) >> 16,
|
|
|
|
(bgcolor & 0x00FF00) >> 8,
|
|
|
|
(bgcolor & 0x0000FF),
|
|
|
|
0xFF);
|
2012-04-06 05:55:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-05 07:28:07 +00:00
|
|
|
/* Convert foreground color */
|
2016-03-01 05:50:00 +00:00
|
|
|
rdp_client->glyph_color = guac_rdp_convert_color(context, fgcolor);
|
2012-03-07 21:57:49 +00:00
|
|
|
|
2017-03-26 02:59:04 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2012-01-09 03:23:37 +00:00
|
|
|
}
|
|
|
|
|
2019-09-22 18:09:44 +00:00
|
|
|
BOOL guac_rdp_glyph_enddraw(rdpContext* context, INT32 x, INT32 y,
|
|
|
|
INT32 width, INT32 height, UINT32 fgcolor, UINT32 bgcolor) {
|
2014-05-05 07:28:07 +00:00
|
|
|
/* IGNORE */
|
2017-03-26 02:59:04 +00:00
|
|
|
return TRUE;
|
2012-01-09 03:23:37 +00:00
|
|
|
}
|
|
|
|
|