mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Ensure withoutReduction does not interfere with contain/crop/embed (#3081)
This commit is contained in:
committed by
GitHub
parent
7eb5efa3a3
commit
83db5f8a2a
@@ -885,7 +885,7 @@ namespace sharp {
|
||||
}
|
||||
|
||||
std::pair<double, double> ResolveShrink(int width, int height, int targetWidth, int targetHeight,
|
||||
Canvas canvas, bool swap, bool withoutEnlargement) {
|
||||
Canvas canvas, bool swap, bool withoutEnlargement, bool withoutReduction) {
|
||||
if (swap) {
|
||||
// Swap input width and height when requested.
|
||||
std::swap(width, height);
|
||||
@@ -940,9 +940,14 @@ namespace sharp {
|
||||
}
|
||||
}
|
||||
|
||||
// We should not enlarge (oversample) the output image,
|
||||
// if withoutEnlargement is specified.
|
||||
if (withoutEnlargement) {
|
||||
// We should not reduce or enlarge the output image, if
|
||||
// withoutReduction or withoutEnlargement is specified.
|
||||
if (withoutReduction) {
|
||||
// Equivalent of VIPS_SIZE_UP
|
||||
hshrink = std::min(1.0, hshrink);
|
||||
vshrink = std::min(1.0, vshrink);
|
||||
} else if (withoutEnlargement) {
|
||||
// Equivalent of VIPS_SIZE_DOWN
|
||||
hshrink = std::max(1.0, hshrink);
|
||||
vshrink = std::max(1.0, vshrink);
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ namespace sharp {
|
||||
the required thumbnail width/height and canvas mode.
|
||||
*/
|
||||
std::pair<double, double> ResolveShrink(int width, int height, int targetWidth, int targetHeight,
|
||||
Canvas canvas, bool swap, bool withoutEnlargement);
|
||||
Canvas canvas, bool swap, bool withoutEnlargement, bool withoutReduction);
|
||||
|
||||
} // namespace sharp
|
||||
|
||||
|
||||
@@ -138,17 +138,6 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
pageHeight = inputHeight;
|
||||
}
|
||||
|
||||
// If withoutReduction is specified,
|
||||
// Override target width and height if less than respective value from input file
|
||||
if (baton->withoutReduction) {
|
||||
if (baton->width < inputWidth) {
|
||||
baton->width = inputWidth;
|
||||
}
|
||||
if (baton->height < inputHeight) {
|
||||
baton->height = inputHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// Scaling calculations
|
||||
double hshrink;
|
||||
double vshrink;
|
||||
@@ -161,7 +150,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
// Shrink to pageHeight, so we work for multi-page images
|
||||
std::tie(hshrink, vshrink) = sharp::ResolveShrink(
|
||||
inputWidth, pageHeight, targetResizeWidth, targetResizeHeight,
|
||||
baton->canvas, swap, baton->withoutEnlargement);
|
||||
baton->canvas, swap, baton->withoutEnlargement, baton->withoutReduction);
|
||||
|
||||
// The jpeg preload shrink.
|
||||
int jpegShrinkOnLoad = 1;
|
||||
@@ -286,7 +275,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
// Shrink to pageHeight, so we work for multi-page images
|
||||
std::tie(hshrink, vshrink) = sharp::ResolveShrink(
|
||||
inputWidth, pageHeight, targetResizeWidth, targetResizeHeight,
|
||||
baton->canvas, swap, baton->withoutEnlargement);
|
||||
baton->canvas, swap, baton->withoutEnlargement, baton->withoutReduction);
|
||||
|
||||
int targetHeight = static_cast<int>(std::rint(static_cast<double>(pageHeight) / vshrink));
|
||||
int targetPageHeight = targetHeight;
|
||||
|
||||
Reference in New Issue
Block a user