From 1263965511a3ba55dd5ad1f3e3c35240c562eca9 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 11 Aug 2015 20:43:46 -0700 Subject: [PATCH] GUAC-240: Add function for streaming JPEG images via img instruction. --- src/libguac/client.c | 22 ++++++++++++++++++++++ src/libguac/guacamole/client.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/libguac/client.c b/src/libguac/client.c index ca1c30fe..f7747ea3 100644 --- a/src/libguac/client.c +++ b/src/libguac/client.c @@ -24,6 +24,7 @@ #include "client.h" #include "client-handlers.h" +#include "encode-jpeg.h" #include "encode-png.h" #include "error.h" #include "instruction.h" @@ -397,3 +398,24 @@ void guac_client_stream_png(guac_client* client, guac_socket* socket, } +void guac_client_stream_jpeg(guac_client* client, guac_socket* socket, + guac_composite_mode mode, const guac_layer* layer, int x, int y, + cairo_surface_t* surface, int quality) { + + /* Allocate new stream for image */ + guac_stream* stream = guac_client_alloc_stream(client); + + /* Declare stream as containing image data */ + guac_protocol_send_img(socket, stream, mode, layer, "image/jpeg", x, y); + + /* Write JPEG data */ + guac_jpeg_write(socket, stream, surface, quality); + + /* Terminate stream */ + guac_protocol_send_end(socket, stream); + + /* Free allocated stream */ + guac_client_free_stream(client, stream); + +} + diff --git a/src/libguac/guacamole/client.h b/src/libguac/guacamole/client.h index b8773c10..3aabf2af 100644 --- a/src/libguac/guacamole/client.h +++ b/src/libguac/guacamole/client.h @@ -661,6 +661,39 @@ void guac_client_stream_png(guac_client* client, guac_socket* socket, guac_composite_mode mode, const guac_layer* layer, int x, int y, cairo_surface_t* surface); +/** + * Streams the image data of the given surface over an image stream ("img" + * instruction) as JPEG-encoded data at the given quality. The image stream + * will be automatically allocated and freed. + * + * @param client + * The Guacamole client from which the image stream should be allocated. + * + * @param socket + * The socket over which instructions associated with the image stream + * should be sent. + * + * @param mode + * The composite mode to use when rendering the image over the given layer. + * + * @param layer + * The destination layer. + * + * @param x + * The X coordinate of the upper-left corner of the destination rectangle + * within the given layer. + * + * @param y + * The Y coordinate of the upper-left corner of the destination rectangle + * within the given layer. + * + * @param surface + * A Cairo surface containing the image data to be streamed. + */ +void guac_client_stream_jpeg(guac_client* client, guac_socket* socket, + guac_composite_mode mode, const guac_layer* layer, int x, int y, + cairo_surface_t* surface, int quality); + /** * The default Guacamole client layer, layer 0. */