Skip to content

Commit

Permalink
WebPRescalerGetScaledDimensions: round scaled dimension up
Browse files Browse the repository at this point in the history
This is to prevent resizing to dimension 0

+ added some safety checks about src_width > 0 and src_height > 0

BUG=webp:418

Change-Id: Ic04a53ad26455d80538bc8681882a554fca2a340
  • Loading branch information
Skal committed Feb 18, 2019
1 parent 62eb3f0 commit d9a662e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/utils/rescaler_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ int WebPRescalerGetScaledDimensions(int src_width, int src_height,
int height = *scaled_height;

// if width is unspecified, scale original proportionally to height ratio.
if (width == 0) {
if (width == 0 && src_height > 0) {
width =
(int)(((uint64_t)src_width * height + src_height / 2) / src_height);
(int)(((uint64_t)src_width * height + src_height - 1) / src_height);
}
// if height is unspecified, scale original proportionally to width ratio.
if (height == 0) {
if (height == 0 && src_width > 0) {
height =
(int)(((uint64_t)src_height * width + src_width / 2) / src_width);
(int)(((uint64_t)src_height * width + src_width - 1) / src_width);
}
// Check if the overall dimensions still make sense.
if (width <= 0 || height <= 0) {
Expand Down

0 comments on commit d9a662e

Please sign in to comment.