From 24a96932230f0740b2eb50c4c3b32cd5dba268fb Mon Sep 17 00:00:00 2001 From: James Zern Date: Thu, 13 Aug 2015 20:51:52 -0700 Subject: [PATCH] dec: allow 0 as a scaling dimension this allows scaling to a particular width/height while preserving the source aspect ratio using WebPRescalerGetScaledDimensions(). Change-Id: I77b11528753290c1e9bb942ac761c215ccfb8701 --- src/dec/buffer.c | 9 ++++++--- src/dec/webp.c | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/dec/buffer.c b/src/dec/buffer.c index c6e4eb84..63f9d74b 100644 --- a/src/dec/buffer.c +++ b/src/dec/buffer.c @@ -181,11 +181,14 @@ VP8StatusCode WebPAllocateDecBuffer(int w, int h, h = ch; } if (options->use_scaling) { - if (options->scaled_width <= 0 || options->scaled_height <= 0) { + int scaled_width = options->scaled_width; + int scaled_height = options->scaled_height; + if (!WebPRescalerGetScaledDimensions( + w, h, &scaled_width, &scaled_height)) { return VP8_STATUS_INVALID_PARAM; } - w = options->scaled_width; - h = options->scaled_height; + w = scaled_width; + h = scaled_height; } } out->width = w; diff --git a/src/dec/webp.c b/src/dec/webp.c index c76a704b..649c73e5 100644 --- a/src/dec/webp.c +++ b/src/dec/webp.c @@ -806,11 +806,13 @@ int WebPIoInitFromOptions(const WebPDecoderOptions* const options, // Scaling io->use_scaling = (options != NULL) && (options->use_scaling > 0); if (io->use_scaling) { - if (options->scaled_width <= 0 || options->scaled_height <= 0) { + int scaled_width = options->scaled_width; + int scaled_height = options->scaled_height; + if (!WebPRescalerGetScaledDimensions(w, h, &scaled_width, &scaled_height)) { return 0; } - io->scaled_width = options->scaled_width; - io->scaled_height = options->scaled_height; + io->scaled_width = scaled_width; + io->scaled_height = scaled_height; } // Filter