GUAC-236: Add stub structure for image decoding.

This commit is contained in:
Michael Jumper 2016-02-27 17:52:07 -08:00
parent 8c0a9b8bc5
commit 083e48d089
9 changed files with 481 additions and 2 deletions

View File

@ -30,14 +30,17 @@ noinst_HEADERS = \
encode.h \
image-stream.h \
instructions.h \
jpeg.h \
layer.h \
log.h
log.h \
png.h
guacenc_SOURCES = \
buffer.c \
display.c \
encode.c \
guacenc.c \
image-stream.c \
instructions.c \
instruction-blob.c \
instruction-cfill.c \
@ -52,8 +55,16 @@ guacenc_SOURCES = \
instruction-size.c \
instruction-sync.c \
instruction-transfer.c \
jpeg.c \
layer.c \
log.c
log.c \
png.c
# Compile WebP support if available
if ENABLE_WEBP
guacenc_SOURCES += webp.c
noinst_HEADERS += webp.h
endif
guacenc_CFLAGS = \
-Werror -Wall -pedantic \

View File

@ -0,0 +1,42 @@
/*
* 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 "image-stream.h"
#include "jpeg.h"
#include "png.h"
#ifdef ENABLE_WEBP
#include "webp.h"
#endif
#include <stdlib.h>
guacenc_decoder_mapping guacenc_decoder_map[] = {
{"image/png", &guacenc_png_decoder},
{"image/jpeg", &guacenc_jpeg_decoder},
#ifdef ENABLE_WEBP
{"image/webp", &guacenc_webp_decoder},
#endif
{NULL, NULL}
};

View File

@ -24,6 +24,13 @@
#define GUACENC_IMAGE_STREAM_H
#include "config.h"
#include "buffer.h"
/**
* A decoder implementation which processes arbitrary image data of a
* particular type. Image data is fed explicitly into the decoder as chunks.
*/
typedef struct guacenc_decoder guacenc_decoder;
/**
* The current state of an allocated Guacamole image stream.
@ -41,7 +48,150 @@ typedef struct guacenc_image_stream {
*/
int mask;
/**
* The X coordinate of the upper-left corner of the rectangle within the
* destination layer or buffer that the decoded image should be drawn to.
*/
int x;
/**
* The Y coordinate of the upper-left corner of the rectangle within the
* destination layer or buffer that the decoded image should be drawn to.
*/
int y;
/**
* The decoder to use when decoding the raw data received along this
* stream, or NULL if no such decoder exists.
*/
guacenc_decoder* decoder;
/**
* Arbitrary implementation-specific data associated with the stream.
*/
void* data;
} guacenc_image_stream;
/**
* Callback function which is invoked when a decoder has been assigned to an
* image stream.
*
* @param stream
* The image stream that the decoder has been assigned to.
*
* @return
* Zero if initialization was successful, non-zero otherwise.
*/
typedef int guacenc_decoder_init_handler(guacenc_image_stream* stream);
/**
* Callback function which is invoked when data has been received along an
* image stream with an associated decoder.
*
* @param stream
* The image stream that the decoder was assigned to.
*
* @param data
* The chunk of data received along the image stream.
*
* @param length
* The length of the chunk of data received, in bytes.
*
* @return
* Zero if the provided data was processed successfully, non-zero
* otherwise.
*/
typedef int guacenc_decoder_data_handler(guacenc_image_stream* stream,
unsigned char* data, int length);
/**
* Callback function which is invoked when an image stream with an associated
* decoder has ended (reached end-of-stream). The image stream will contain
* the required meta-information describing the drawing operation, including
* the destination X/Y coordinates.
*
* @param stream
* The image stream that has ended.
*
* @param buffer
* The buffer to which the decoded image should be drawn.
*
* @return
* Zero if the end of the stream has been processed successfully and the
* resulting image has been rendered to the given buffer, non-zero
* otherwise.
*/
typedef int guacenc_decoder_end_handler(guacenc_image_stream* stream,
guacenc_buffer* buffer);
/**
* Callback function which will be invoked when the data associated with an
* image stream must be freed. This may happen at any time, and will not
* necessarily occur only after the image stream has ended. It is possible
* that an image stream will be in-progress at the end of a protocol dump, thus
* the memory associated with the stream will need to be freed without ever
* ending.
*
* @param stream
* The stream whose associated data must be freed.
*
* @return
* Zero if the data was successfully freed, non-zero otherwise.
*/
typedef int guacenc_decoder_free_handler(guacenc_image_stream* stream);
struct guacenc_decoder {
/**
* Callback invoked when this decoder has just been assigned to an image
* stream.
*/
guacenc_decoder_init_handler* init_handler;
/**
* Callback invoked when data has been received along an image stream to
* which this decoder has been assigned.
*/
guacenc_decoder_data_handler* data_handler;
/**
* Callback invoked when an image stream to which this decoder has been
* assigned has ended (reached end-of-stream).
*/
guacenc_decoder_end_handler* end_handler;
/**
* Callback invoked when data associated with an image stream by this
* decoder must be freed.
*/
guacenc_decoder_free_handler* free_handler;
};
/**
* Mapping of image mimetype to corresponding decoder.
*/
typedef struct guacenc_decoder_mapping {
/**
* The mimetype of the image that the associated decoder can read.
*/
const char* mimetype;
/**
* The decoder to use when an image stream of the associated mimetype is
* received.
*/
guacenc_decoder* decoder;
} guacenc_decoder_mapping;
/**
* Array of all mimetype/decoder mappings for all supported image types,
* terminated by an entry with a NULL mimetype.
*/
extern guacenc_decoder_mapping guacenc_decoder_map[];
#endif

57
src/guacenc/jpeg.c Normal file
View File

@ -0,0 +1,57 @@
/*
* 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 "image-stream.h"
#include "jpeg.h"
#include <stdlib.h>
int guacenc_jpeg_init(guacenc_image_stream* stream) {
/* STUB */
return 0;
}
int guacenc_jpeg_data(guacenc_image_stream* stream, unsigned char* data,
int length) {
/* STUB */
return 0;
}
int guacenc_jpeg_end(guacenc_image_stream* stream, guacenc_buffer* buffer) {
/* STUB */
return 0;
}
int guacenc_jpeg_free(guacenc_image_stream* stream) {
/* STUB */
return 0;
}
guacenc_decoder guacenc_jpeg_decoder = {
.init_handler = guacenc_jpeg_init,
.data_handler = guacenc_jpeg_data,
.end_handler = guacenc_jpeg_end,
.free_handler = guacenc_jpeg_free
};

35
src/guacenc/jpeg.h Normal file
View File

@ -0,0 +1,35 @@
/*
* 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.
*/
#ifndef GUACENC_JPEG_H
#define GUACENC_JPEG_H
#include "config.h"
#include "image-stream.h"
/**
* Decoder implementation which handles "image/jpeg" images.
*/
extern guacenc_decoder guacenc_jpeg_decoder;
#endif

57
src/guacenc/png.c Normal file
View File

@ -0,0 +1,57 @@
/*
* 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 "image-stream.h"
#include "png.h"
#include <stdlib.h>
int guacenc_png_init(guacenc_image_stream* stream) {
/* STUB */
return 0;
}
int guacenc_png_data(guacenc_image_stream* stream, unsigned char* data,
int length) {
/* STUB */
return 0;
}
int guacenc_png_end(guacenc_image_stream* stream, guacenc_buffer* buffer) {
/* STUB */
return 0;
}
int guacenc_png_free(guacenc_image_stream* stream) {
/* STUB */
return 0;
}
guacenc_decoder guacenc_png_decoder = {
.init_handler = guacenc_png_init,
.data_handler = guacenc_png_data,
.end_handler = guacenc_png_end,
.free_handler = guacenc_png_free
};

35
src/guacenc/png.h Normal file
View File

@ -0,0 +1,35 @@
/*
* 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.
*/
#ifndef GUACENC_PNG_H
#define GUACENC_PNG_H
#include "config.h"
#include "image-stream.h"
/**
* Decoder implementation which handles "image/png" images.
*/
extern guacenc_decoder guacenc_png_decoder;
#endif

57
src/guacenc/webp.c Normal file
View File

@ -0,0 +1,57 @@
/*
* 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 "image-stream.h"
#include "webp.h"
#include <stdlib.h>
int guacenc_webp_init(guacenc_image_stream* stream) {
/* STUB */
return 0;
}
int guacenc_webp_data(guacenc_image_stream* stream, unsigned char* data,
int length) {
/* STUB */
return 0;
}
int guacenc_webp_end(guacenc_image_stream* stream, guacenc_buffer* buffer) {
/* STUB */
return 0;
}
int guacenc_webp_free(guacenc_image_stream* stream) {
/* STUB */
return 0;
}
guacenc_decoder guacenc_webp_decoder = {
.init_handler = guacenc_webp_init,
.data_handler = guacenc_webp_data,
.end_handler = guacenc_webp_end,
.free_handler = guacenc_webp_free
};

35
src/guacenc/webp.h Normal file
View File

@ -0,0 +1,35 @@
/*
* 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.
*/
#ifndef GUACENC_WEBP_H
#define GUACENC_WEBP_H
#include "config.h"
#include "image-stream.h"
/**
* Decoder implementation which handles "image/webp" images.
*/
extern guacenc_decoder guacenc_webp_decoder;
#endif