GUAC-236: Stub resize of buffers. Implement size.

This commit is contained in:
Michael Jumper 2016-02-27 00:29:22 -08:00
parent 314d66727a
commit 696c3c3184
5 changed files with 115 additions and 3 deletions

View File

@ -34,6 +34,7 @@ noinst_HEADERS = \
log.h log.h
guacenc_SOURCES = \ guacenc_SOURCES = \
buffer.c \
display.c \ display.c \
encode.c \ encode.c \
guacenc.c \ guacenc.c \

46
src/guacenc/buffer.c Normal file
View File

@ -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 <stdlib.h>
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;
}

View File

@ -41,7 +41,51 @@ typedef struct guacenc_buffer {
*/ */
int height; int height;
/**
* The number of bytes in each row of image data.
*/
int stride;
} guacenc_buffer; } 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 #endif

View File

@ -41,9 +41,13 @@ int guacenc_handle_size(guacenc_display* display, int argc, char** argv) {
int width = atoi(argv[1]); int width = atoi(argv[1]);
int height = atoi(argv[2]); int height = atoi(argv[2]);
/* STUB */ /* Retrieve requested layer */
guacenc_log(GUAC_LOG_DEBUG, "size: layer=%i %ix%i", index, width, height); guacenc_layer* layer = guacenc_display_get_layer(display, index);
return 0; if (layer == NULL)
return 1;
/* Resize layer */
return guacenc_buffer_resize(layer->buffer, width, height);
} }

View File

@ -21,6 +21,7 @@
*/ */
#include "config.h" #include "config.h"
#include "buffer.h"
#include "layer.h" #include "layer.h"
#include <stdlib.h> #include <stdlib.h>
@ -32,6 +33,13 @@ guacenc_layer* guacenc_layer_alloc() {
if (layer == NULL) if (layer == NULL)
return 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 */ /* Layers default to fully opaque */
layer->opacity = 0xFF; layer->opacity = 0xFF;
@ -40,6 +48,15 @@ guacenc_layer* guacenc_layer_alloc() {
} }
void guacenc_layer_free(guacenc_layer* layer) { void guacenc_layer_free(guacenc_layer* layer) {
/* Ignore NULL layers */
if (layer == NULL)
return;
/* Free underlying buffer */
guacenc_buffer_free(layer->buffer);
free(layer); free(layer);
} }