From 5149d6d5c4b76a9258327a32e33e844c12a2a3bd Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 27 Feb 2016 17:58:07 -0800 Subject: [PATCH] GUAC-236: Add decoder search function. --- src/guacenc/image-stream.c | 23 +++++++++++++++++++++++ src/guacenc/image-stream.h | 13 +++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/guacenc/image-stream.c b/src/guacenc/image-stream.c index 261232b6..5830722f 100644 --- a/src/guacenc/image-stream.c +++ b/src/guacenc/image-stream.c @@ -23,6 +23,7 @@ #include "config.h" #include "image-stream.h" #include "jpeg.h" +#include "log.h" #include "png.h" #ifdef ENABLE_WEBP @@ -30,6 +31,7 @@ #endif #include +#include guacenc_decoder_mapping guacenc_decoder_map[] = { {"image/png", &guacenc_png_decoder}, @@ -40,3 +42,24 @@ guacenc_decoder_mapping guacenc_decoder_map[] = { {NULL, NULL} }; +guacenc_decoder* guacenc_get_decoder(const char* mimetype) { + + /* Search through mapping for the decoder having given mimetype */ + guacenc_decoder_mapping* current = guacenc_decoder_map; + while (current->mimetype != NULL) { + + /* Return decoder if mimetype matches */ + if (strcmp(current->mimetype, mimetype) == 0) + return current->decoder; + + /* Next candidate decoder */ + current++; + + } + + /* No such decoder */ + guacenc_log(GUAC_LOG_WARNING, "Support for \"%s\" not present", mimetype); + return NULL; + +} + diff --git a/src/guacenc/image-stream.h b/src/guacenc/image-stream.h index 1f03dc19..5cd8f4cd 100644 --- a/src/guacenc/image-stream.h +++ b/src/guacenc/image-stream.h @@ -193,5 +193,18 @@ typedef struct guacenc_decoder_mapping { */ extern guacenc_decoder_mapping guacenc_decoder_map[]; +/** + * Returns the decoder associated with the given mimetype. If no such decoder + * exists, NULL is returned. + * + * @param mimetype + * The image mimetype to return the associated decoder of. + * + * @return + * The decoder associated with the given mimetype, or NULL if no such + * decoder exists. + */ +guacenc_decoder* guacenc_get_decoder(const char* mimetype); + #endif