diff --git a/examples/dwebp.c b/examples/dwebp.c index 2876828a..e5f3964f 100644 --- a/examples/dwebp.c +++ b/examples/dwebp.c @@ -706,7 +706,11 @@ int main(int argc, const char *argv[]) { return -1; } - status = ExUtilDecodeWebP(data, data_size, incremental, verbose, &config); + if (incremental) { + status = ExUtilDecodeWebPIncremental(data, data_size, verbose, &config); + } else { + status = ExUtilDecodeWebP(data, data_size, verbose, &config); + } End: free((void*)data); ok = (status == VP8_STATUS_OK); diff --git a/examples/example_util.c b/examples/example_util.c index d3dbc618..ecede97e 100644 --- a/examples/example_util.c +++ b/examples/example_util.c @@ -118,6 +118,15 @@ static const char* const kStatusMessages[] = { "UNSUPPORTED_FEATURE", "SUSPENDED", "USER_ABORT", "NOT_ENOUGH_DATA" }; +static void PrintAnimationWarning(const WebPDecoderConfig* const config) { + if (config->input.has_animation) { + fprintf(stderr, + "Error! Decoding of an animated WebP file is not supported.\n" + " Use webpmux to extract the individual frames or\n" + " vwebp to view this image.\n"); + } +} + void ExUtilPrintWebPError(const char* const in_file, int status) { fprintf(stderr, "Decoding of %s failed.\n", in_file); fprintf(stderr, "Status: %d", status); @@ -149,28 +158,41 @@ int ExUtilLoadWebP(const char* const in_file, return 1; } +//------------------------------------------------------------------------------ + VP8StatusCode ExUtilDecodeWebP(const uint8_t* const data, size_t data_size, - int incremental, int verbose, - WebPDecoderConfig* const config) { + int verbose, WebPDecoderConfig* const config) { Stopwatch stop_watch; VP8StatusCode status = VP8_STATUS_OK; - if (config == NULL) return 0; + if (config == NULL) return VP8_STATUS_INVALID_PARAM; - if (verbose) { - StopwatchReset(&stop_watch); - } + PrintAnimationWarning(config); - if (config->input.has_animation) { - fprintf(stderr, - "Error! Decoding of an animated WebP file is not supported.\n" - " Use webpmux to extract the individual frames or\n" - " vwebp to view this image.\n"); - } + StopwatchReset(&stop_watch); // Decoding call. - if (!incremental) { - status = WebPDecode(data, data_size, config); - } else { + status = WebPDecode(data, data_size, config); + + if (verbose) { + const double decode_time = StopwatchReadAndReset(&stop_watch); + fprintf(stderr, "Time to decode picture: %.3fs\n", decode_time); + } + return status; +} + +VP8StatusCode ExUtilDecodeWebPIncremental( + const uint8_t* const data, size_t data_size, + int verbose, WebPDecoderConfig* const config) { + Stopwatch stop_watch; + VP8StatusCode status = VP8_STATUS_OK; + if (config == NULL) return VP8_STATUS_INVALID_PARAM; + + PrintAnimationWarning(config); + + StopwatchReset(&stop_watch); + + // Decoding call. + { WebPIDecoder* const idec = WebPIDecode(data, data_size, config); if (idec == NULL) { fprintf(stderr, "Failed during WebPINewDecoder().\n"); diff --git a/examples/example_util.h b/examples/example_util.h index 9b396350..8a9f68be 100644 --- a/examples/example_util.h +++ b/examples/example_util.h @@ -53,17 +53,21 @@ int ExUtilLoadWebP(const char* const in_file, const uint8_t** data, size_t* data_size, struct WebPBitstreamFeatures* bitstream); -// Decodes the WebP contained in 'data'. 'config' is a structure previously -// initialized by WebPInitDecoderConfig(). 'config->output' should have the -// desired colorspace selected. If 'incremental' is set to true the WebP -// incremental decoder will be used. 'verbose' will cause decode timing to be -// reported. +// Decodes the WebP contained in 'data'. +// 'config' is a structure previously initialized by WebPInitDecoderConfig(). +// 'config->output' should have the desired colorspace selected. 'verbose' will +// cause decode timing to be reported. // Returns the decoder status. On success 'config->output' will contain the // decoded picture. enum VP8StatusCode ExUtilDecodeWebP(const uint8_t* const data, size_t data_size, - int incremental, int verbose, + int verbose, struct WebPDecoderConfig* const config); +// Same as ExUtilDecodeWebP(), but using the incremental decoder. +enum VP8StatusCode ExUtilDecodeWebPIncremental( + const uint8_t* const data, size_t data_size, + int verbose, struct WebPDecoderConfig* const config); + #ifdef __cplusplus } // extern "C" #endif diff --git a/examples/webpdec.c b/examples/webpdec.c index 126b4523..b527a167 100644 --- a/examples/webpdec.c +++ b/examples/webpdec.c @@ -43,7 +43,7 @@ int ReadWebP(const char* const in_file, WebPPicture* const pic, const int has_alpha = keep_alpha && bitstream->has_alpha; output_buffer->colorspace = has_alpha ? MODE_RGBA : MODE_RGB; - status = ExUtilDecodeWebP(data, data_size, 0, 0, &config); + status = ExUtilDecodeWebP(data, data_size, 0, &config); if (status == VP8_STATUS_OK) { const uint8_t* const rgba = output_buffer->u.RGBA.rgba; const int stride = output_buffer->u.RGBA.stride;