GUAC-236: Implement WebP decoding.
This commit is contained in:
parent
960ee263e8
commit
21c568c0b4
@ -21,14 +21,57 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "log.h"
|
||||||
#include "webp.h"
|
#include "webp.h"
|
||||||
|
|
||||||
#include <cairo/cairo.h>
|
#include <cairo/cairo.h>
|
||||||
|
#include <guacamole/client.h>
|
||||||
|
#include <webp/decode.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
cairo_surface_t* guacenc_webp_decoder(unsigned char* data, int length) {
|
cairo_surface_t* guacenc_webp_decoder(unsigned char* data, int length) {
|
||||||
/* STUB */
|
|
||||||
|
int width, height;
|
||||||
|
|
||||||
|
/* Validate WebP and pull dimensions */
|
||||||
|
if (!WebPGetInfo((uint8_t*) data, length, &width, &height)) {
|
||||||
|
guacenc_log(GUAC_LOG_WARNING, "Invalid WebP data");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create blank Cairo surface */
|
||||||
|
cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
|
||||||
|
width, height);
|
||||||
|
|
||||||
|
/* Fill surface with opaque black */
|
||||||
|
cairo_t* cairo = cairo_create(surface);
|
||||||
|
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
||||||
|
cairo_set_source_rgba(cairo, 0.0, 0.0, 0.0, 1.0);
|
||||||
|
cairo_paint(cairo);
|
||||||
|
cairo_destroy(cairo);
|
||||||
|
|
||||||
|
/* Finish any pending draws */
|
||||||
|
cairo_surface_flush(surface);
|
||||||
|
|
||||||
|
/* Pull underlying buffer and its stride */
|
||||||
|
int stride = cairo_image_surface_get_stride(surface);
|
||||||
|
unsigned char* image = cairo_image_surface_get_data(surface);
|
||||||
|
|
||||||
|
/* Read WebP into surface */
|
||||||
|
uint8_t* result = WebPDecodeBGRAInto((uint8_t*) data, length,
|
||||||
|
(uint8_t*) image, stride * height, stride);
|
||||||
|
|
||||||
|
/* Verify WebP was successfully decoded */
|
||||||
|
if (result == NULL) {
|
||||||
|
guacenc_log(GUAC_LOG_WARNING, "Invalid WebP data");
|
||||||
|
cairo_surface_destroy(surface);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* WebP was read successfully */
|
||||||
|
return surface;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user