From 696c3c3184d3970f1b11533e999d973896fc8462 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 27 Feb 2016 00:29:22 -0800 Subject: [PATCH] GUAC-236: Stub resize of buffers. Implement size. --- src/guacenc/Makefile.am | 1 + src/guacenc/buffer.c | 46 ++++++++++++++++++++++++++++++++++ src/guacenc/buffer.h | 44 ++++++++++++++++++++++++++++++++ src/guacenc/instruction-size.c | 10 +++++--- src/guacenc/layer.c | 17 +++++++++++++ 5 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 src/guacenc/buffer.c diff --git a/src/guacenc/Makefile.am b/src/guacenc/Makefile.am index 7a6ec48f..35a149e4 100644 --- a/src/guacenc/Makefile.am +++ b/src/guacenc/Makefile.am @@ -34,6 +34,7 @@ noinst_HEADERS = \ log.h guacenc_SOURCES = \ + buffer.c \ display.c \ encode.c \ guacenc.c \ diff --git a/src/guacenc/buffer.c b/src/guacenc/buffer.c new file mode 100644 index 00000000..56cc409b --- /dev/null +++ b/src/guacenc/buffer.c @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2016 Glyptodon, Inc. + * + * 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: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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. + */ + +#include "config.h" +#include "buffer.h" + +#include + +guacenc_buffer* guacenc_buffer_alloc() { + return calloc(1, sizeof(guacenc_buffer)); +} + +void guacenc_buffer_free(guacenc_buffer* buffer) { + free(buffer); +} + +int guacenc_buffer_resize(guacenc_buffer* buffer, int width, int height) { + + /* STUB */ + + buffer->width = width; + buffer->height = height; + + return 0; + +} + diff --git a/src/guacenc/buffer.h b/src/guacenc/buffer.h index 6bd3ce3c..ed6f6ac2 100644 --- a/src/guacenc/buffer.h +++ b/src/guacenc/buffer.h @@ -41,7 +41,51 @@ typedef struct guacenc_buffer { */ int height; + /** + * The number of bytes in each row of image data. + */ + int stride; + } guacenc_buffer; +/** + * Allocates and initializes a new buffer object. This allocation is + * independent of the Guacamole video encoder display; the allocated + * guacenc_buffer will not automatically be associated with the active display. + * + * @return + * A newly-allocated and initialized guacenc_buffer, or NULL if allocation + * fails. + */ +guacenc_buffer* guacenc_buffer_alloc(); + +/** + * Frees all memory associated with the given buffer object. If the buffer + * provided is NULL, this function has no effect. + * + * @param buffer + * The buffer to free, which may be NULL. + */ +void guacenc_buffer_free(guacenc_buffer* buffer); + +/** + * Resizes the given buffer to the given dimensions, allocating or freeing + * memory as necessary, and updating the buffer's width, height, and stride + * properties. + * + * @param buffer + * The buffer to resize. + * + * @param width + * The new width of the buffer, in pixels. + * + * @param height + * The new height of the buffer, in pixels. + * + * @return + * Zero if the resize operation is successful, non-zero on error. + */ +int guacenc_buffer_resize(guacenc_buffer* buffer, int width, int height); + #endif diff --git a/src/guacenc/instruction-size.c b/src/guacenc/instruction-size.c index 24375bc7..c650c218 100644 --- a/src/guacenc/instruction-size.c +++ b/src/guacenc/instruction-size.c @@ -41,9 +41,13 @@ int guacenc_handle_size(guacenc_display* display, int argc, char** argv) { int width = atoi(argv[1]); int height = atoi(argv[2]); - /* STUB */ - guacenc_log(GUAC_LOG_DEBUG, "size: layer=%i %ix%i", index, width, height); - return 0; + /* Retrieve requested layer */ + guacenc_layer* layer = guacenc_display_get_layer(display, index); + if (layer == NULL) + return 1; + + /* Resize layer */ + return guacenc_buffer_resize(layer->buffer, width, height); } diff --git a/src/guacenc/layer.c b/src/guacenc/layer.c index 1265622b..b0ec9696 100644 --- a/src/guacenc/layer.c +++ b/src/guacenc/layer.c @@ -21,6 +21,7 @@ */ #include "config.h" +#include "buffer.h" #include "layer.h" #include @@ -32,6 +33,13 @@ guacenc_layer* guacenc_layer_alloc() { if (layer == NULL) return NULL; + /* Allocate associated buffer (width, height, and image storage) */ + layer->buffer = guacenc_buffer_alloc(); + if (layer->buffer == NULL) { + free(layer); + return NULL; + } + /* Layers default to fully opaque */ layer->opacity = 0xFF; @@ -40,6 +48,15 @@ guacenc_layer* guacenc_layer_alloc() { } void guacenc_layer_free(guacenc_layer* layer) { + + /* Ignore NULL layers */ + if (layer == NULL) + return; + + /* Free underlying buffer */ + guacenc_buffer_free(layer->buffer); + free(layer); + }