mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-28 06:38:20 +01:00
utils/rescaler: add WebPRescalerGetScaledDimensions
+ use it in WebPPictureRescale() Change-Id: I491bea8cd56f0eb1ac8bf0829b9f36c77804219a
This commit is contained in:
parent
923e8edafb
commit
b918724280
@ -211,16 +211,10 @@ int WebPPictureRescale(WebPPicture* pic, int width, int height) {
|
|||||||
if (pic == NULL) return 0;
|
if (pic == NULL) return 0;
|
||||||
prev_width = pic->width;
|
prev_width = pic->width;
|
||||||
prev_height = pic->height;
|
prev_height = pic->height;
|
||||||
// if width is unspecified, scale original proportionally to height ratio.
|
if (!WebPRescalerGetScaledDimensions(
|
||||||
if (width == 0) {
|
prev_width, prev_height, &width, &height)) {
|
||||||
width = (prev_width * height + prev_height / 2) / prev_height;
|
return 0;
|
||||||
}
|
}
|
||||||
// if height is unspecified, scale original proportionally to width ratio.
|
|
||||||
if (height == 0) {
|
|
||||||
height = (prev_height * width + prev_width / 2) / prev_width;
|
|
||||||
}
|
|
||||||
// Check if the overall dimensions still make sense.
|
|
||||||
if (width <= 0 || height <= 0) return 0;
|
|
||||||
|
|
||||||
PictureGrabSpecs(pic, &tmp);
|
PictureGrabSpecs(pic, &tmp);
|
||||||
tmp.width = width;
|
tmp.width = width;
|
||||||
|
@ -50,6 +50,34 @@ void WebPRescalerInit(WebPRescaler* const wrk, int src_width, int src_height,
|
|||||||
WebPRescalerDspInit();
|
WebPRescalerDspInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WebPRescalerGetScaledDimensions(int src_width, int src_height,
|
||||||
|
int* const scaled_width,
|
||||||
|
int* const scaled_height) {
|
||||||
|
assert(scaled_width != NULL);
|
||||||
|
assert(scaled_height != NULL);
|
||||||
|
{
|
||||||
|
int width = *scaled_width;
|
||||||
|
int height = *scaled_height;
|
||||||
|
|
||||||
|
// if width is unspecified, scale original proportionally to height ratio.
|
||||||
|
if (width == 0) {
|
||||||
|
width = (src_width * height + src_height / 2) / src_height;
|
||||||
|
}
|
||||||
|
// if height is unspecified, scale original proportionally to width ratio.
|
||||||
|
if (height == 0) {
|
||||||
|
height = (src_height * width + src_width / 2) / src_width;
|
||||||
|
}
|
||||||
|
// Check if the overall dimensions still make sense.
|
||||||
|
if (width <= 0 || height <= 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*scaled_width = width;
|
||||||
|
*scaled_height = height;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// all-in-one calls
|
// all-in-one calls
|
||||||
|
|
||||||
|
@ -48,6 +48,14 @@ void WebPRescalerInit(WebPRescaler* const rescaler,
|
|||||||
int num_channels,
|
int num_channels,
|
||||||
int32_t* const work);
|
int32_t* const work);
|
||||||
|
|
||||||
|
// If either 'scaled_width' or 'scaled_height' (but not both) is 0 the value
|
||||||
|
// will be calculated preserving the aspect ratio, otherwise the values are
|
||||||
|
// left unmodified. Returns true on success, false if either value is 0 after
|
||||||
|
// performing the scaling calculation.
|
||||||
|
int WebPRescalerGetScaledDimensions(int src_width, int src_height,
|
||||||
|
int* const scaled_width,
|
||||||
|
int* const scaled_height);
|
||||||
|
|
||||||
// Returns the number of input lines needed next to produce one output line,
|
// Returns the number of input lines needed next to produce one output line,
|
||||||
// considering that the maximum available input lines are 'max_num_lines'.
|
// considering that the maximum available input lines are 'max_num_lines'.
|
||||||
int WebPRescaleNeededLines(const WebPRescaler* const rescaler,
|
int WebPRescaleNeededLines(const WebPRescaler* const rescaler,
|
||||||
|
Loading…
Reference in New Issue
Block a user