Switching to cairo, partial translation.
This commit is contained in:
parent
56c3b04e9e
commit
e49798364b
@ -44,7 +44,7 @@ AC_PROG_LIBTOOL
|
||||
|
||||
# Checks for libraries.
|
||||
AC_CHECK_LIB([guac], [guac_get_client],, AC_MSG_ERROR("libguac is required for communication via the guacamole protocol"))
|
||||
AC_CHECK_LIB([png], [png_write_png],, AC_MSG_ERROR("libpng is required for writing png messages"))
|
||||
AC_CHECK_LIB([cairo], [cairo_create],, AC_MSG_ERROR("cairo is required for drawing instructions"))
|
||||
AC_CHECK_LIB([vncclient], [rfbInitClient],, AC_MSG_ERROR("libvncclient is required"))
|
||||
|
||||
# Checks for header files.
|
||||
|
@ -38,13 +38,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <png.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <guacamole/log.h>
|
||||
#include <cairo/cairo.h>
|
||||
|
||||
#include <rfb/rfbclient.h>
|
||||
|
||||
#include <guacamole/log.h>
|
||||
#include <guacamole/guacio.h>
|
||||
#include <guacamole/protocol.h>
|
||||
#include <guacamole/client.h>
|
||||
@ -66,10 +66,6 @@ typedef struct vnc_guac_client_data {
|
||||
rfbClient* rfb_client;
|
||||
MallocFrameBufferProc rfb_MallocFrameBuffer;
|
||||
|
||||
png_byte** png_buffer;
|
||||
png_byte** png_buffer_alpha;
|
||||
int buffer_height;
|
||||
|
||||
int copy_rect_used;
|
||||
char* password;
|
||||
char* encodings;
|
||||
@ -78,61 +74,69 @@ typedef struct vnc_guac_client_data {
|
||||
|
||||
void guac_vnc_cursor(rfbClient* client, int x, int y, int w, int h, int bpp) {
|
||||
|
||||
int dx, dy;
|
||||
|
||||
guac_client* gc = rfbClientGetClientData(client, __GUAC_CLIENT);
|
||||
GUACIO* io = gc->io;
|
||||
png_byte** png_buffer = ((vnc_guac_client_data*) gc->data)->png_buffer_alpha;
|
||||
png_byte* row;
|
||||
|
||||
png_byte** png_row_current = png_buffer;
|
||||
/* Cairo image buffer */
|
||||
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, w);
|
||||
unsigned char* buffer = malloc(h*stride);
|
||||
unsigned char* buffer_row_current = buffer;
|
||||
cairo_surface_t* surface;
|
||||
|
||||
unsigned int bytesPerRow = bpp * w;
|
||||
/* VNC image buffer */
|
||||
unsigned int fb_stride = bpp * w;
|
||||
unsigned char* fb_row_current = client->rcSource;
|
||||
unsigned char* fb_mask = client->rcMask;
|
||||
unsigned char* fb_row;
|
||||
unsigned int v;
|
||||
|
||||
/* Copy image data from VNC client to PNG */
|
||||
int dx, dy;
|
||||
|
||||
/* Copy image data from VNC client to RGBA buffer */
|
||||
for (dy = 0; dy<h; dy++) {
|
||||
|
||||
row = *(png_row_current++);
|
||||
unsigned char* buffer_current = buffer_row_current;
|
||||
buffer_row_current += stride;
|
||||
|
||||
fb_row = fb_row_current;
|
||||
fb_row_current += bytesPerRow;
|
||||
unsigned char* fb_current = fb_row_current;
|
||||
fb_row_current += fb_stride;
|
||||
|
||||
for (dx = 0; dx<w; dx++) {
|
||||
|
||||
unsigned char alpha;
|
||||
unsigned int v;
|
||||
|
||||
/* Read current pixel value */
|
||||
switch (bpp) {
|
||||
case 4:
|
||||
v = *((unsigned int*) fb_row);
|
||||
v = *((unsigned int*) fb_current);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
v = *((unsigned short*) fb_row);
|
||||
v = *((unsigned short*) fb_current);
|
||||
break;
|
||||
|
||||
default:
|
||||
v = *((unsigned char*) fb_row);
|
||||
v = *((unsigned char*) fb_current);
|
||||
}
|
||||
|
||||
*(row++) = (v >> client->format.redShift) * 256 / (client->format.redMax+1);
|
||||
*(row++) = (v >> client->format.greenShift) * 256 / (client->format.greenMax+1);
|
||||
*(row++) = (v >> client->format.blueShift) * 256 / (client->format.blueMax+1);
|
||||
/* Translate mask to alpha */
|
||||
if (*(fb_mask++)) alpha = 0xFF;
|
||||
else alpha = 0x00;
|
||||
|
||||
/* Handle mask */
|
||||
if (*(fb_mask++))
|
||||
*(row++) = 255;
|
||||
else
|
||||
*(row++) = 0;
|
||||
/* Output ARGB */
|
||||
*(buffer_current++) = alpha;
|
||||
*(buffer_current++) = (v >> client->format.redShift) * 0x100 / (client->format.redMax + 1);
|
||||
*(buffer_current++) = (v >> client->format.greenShift) * 0x100 / (client->format.greenMax+ 1);
|
||||
*(buffer_current++) = (v >> client->format.blueShift) * 0x100 / (client->format.blueMax + 1);
|
||||
|
||||
fb_row += bpp;
|
||||
/* Next VNC pixel */
|
||||
fb_current += bpp;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* SEND CURSOR */
|
||||
guac_send_cursor(io, x, y, png_buffer, w, h);
|
||||
surface = cairo_image_surface_create_for_data(buffer, CAIRO_FORMAT_ARGB32, w, h, stride);
|
||||
guac_send_cursor(io, x, y, surface);
|
||||
|
||||
/* libvncclient does not free rcMask as it does rcSource */
|
||||
free(client->rcMask);
|
||||
@ -220,17 +224,6 @@ rfbBool guac_vnc_malloc_framebuffer(rfbClient* rfb_client) {
|
||||
guac_client* gc = rfbClientGetClientData(rfb_client, __GUAC_CLIENT);
|
||||
vnc_guac_client_data* guac_client_data = (vnc_guac_client_data*) gc->data;
|
||||
|
||||
/* Free old buffers */
|
||||
if (guac_client_data->png_buffer != NULL)
|
||||
guac_free_png_buffer(guac_client_data->png_buffer, guac_client_data->buffer_height);
|
||||
if (guac_client_data->png_buffer_alpha != NULL)
|
||||
guac_free_png_buffer(guac_client_data->png_buffer_alpha, guac_client_data->buffer_height);
|
||||
|
||||
/* Allocate new buffers */
|
||||
guac_client_data->png_buffer = guac_alloc_png_buffer(rfb_client->width, rfb_client->height, 3); /* No-alpha */
|
||||
guac_client_data->png_buffer_alpha = guac_alloc_png_buffer(rfb_client->width, rfb_client->height, 4); /* With alpha */
|
||||
guac_client_data->buffer_height = rfb_client->height;
|
||||
|
||||
/* Send new size */
|
||||
guac_send_size(gc->io, rfb_client->width, rfb_client->height);
|
||||
|
||||
@ -303,14 +296,7 @@ int vnc_guac_client_clipboard_handler(guac_client* client, char* data) {
|
||||
int vnc_guac_client_free_handler(guac_client* client) {
|
||||
|
||||
vnc_guac_client_data* guac_client_data = (vnc_guac_client_data*) client->data;
|
||||
|
||||
rfbClient* rfb_client = guac_client_data->rfb_client;
|
||||
png_byte** png_buffer = guac_client_data->png_buffer;
|
||||
png_byte** png_buffer_alpha = guac_client_data->png_buffer_alpha;
|
||||
|
||||
/* Free PNG data */
|
||||
guac_free_png_buffer(png_buffer, guac_client_data->buffer_height);
|
||||
guac_free_png_buffer(png_buffer_alpha, guac_client_data->buffer_height);
|
||||
|
||||
/* Free encodings string, if used */
|
||||
if (guac_client_data->encodings != NULL)
|
||||
@ -394,8 +380,6 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
|
||||
rfb_client->GetPassword = guac_vnc_get_password;
|
||||
|
||||
/* Hook into allocation so we can handle resize. */
|
||||
guac_client_data->png_buffer = NULL;
|
||||
guac_client_data->png_buffer_alpha = NULL;
|
||||
guac_client_data->rfb_MallocFrameBuffer = rfb_client->MallocFrameBuffer;
|
||||
rfb_client->MallocFrameBuffer = guac_vnc_malloc_framebuffer;
|
||||
rfb_client->canHandleNewFBSize = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user