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
This commit is contained in:
James Zern 2015-08-13 20:51:52 -07:00
parent b918724280
commit 24a9693223
2 changed files with 11 additions and 6 deletions

View File

@ -181,11 +181,14 @@ VP8StatusCode WebPAllocateDecBuffer(int w, int h,
h = ch; h = ch;
} }
if (options->use_scaling) { 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; return VP8_STATUS_INVALID_PARAM;
} }
w = options->scaled_width; w = scaled_width;
h = options->scaled_height; h = scaled_height;
} }
} }
out->width = w; out->width = w;

View File

@ -806,11 +806,13 @@ int WebPIoInitFromOptions(const WebPDecoderOptions* const options,
// Scaling // Scaling
io->use_scaling = (options != NULL) && (options->use_scaling > 0); io->use_scaling = (options != NULL) && (options->use_scaling > 0);
if (io->use_scaling) { 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; return 0;
} }
io->scaled_width = options->scaled_width; io->scaled_width = scaled_width;
io->scaled_height = options->scaled_height; io->scaled_height = scaled_height;
} }
// Filter // Filter