diff --git a/docs/changelog.md b/docs/changelog.md index 412a2b20..7eb4b3d3 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -16,6 +16,9 @@ Requires libvips v8.14.2 [#3674](https://github.com/lovell/sharp/pull/3674) [@bianjunjie1981](https://github.com/bianjunjie1981) +* Prevent over-compute in affine-based rotate before resize. + [#3722](https://github.com/lovell/sharp/issues/3722) + ### v0.32.1 - 27th April 2023 * Add experimental `unflatten` operation. diff --git a/src/pipeline.cc b/src/pipeline.cc index c4e52b3a..6fb9e674 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -116,7 +116,7 @@ class PipelineWorker : public Napi::AsyncWorker { MultiPageUnsupported(nPages, "Rotate"); std::vector background; std::tie(image, background) = sharp::ApplyAlpha(image, baton->rotationBackground, FALSE); - image = image.rotate(baton->rotationAngle, VImage::option()->set("background", background)); + image = image.rotate(baton->rotationAngle, VImage::option()->set("background", background)).cache(); } } diff --git a/test/unit/rotate.js b/test/unit/rotate.js index ded228b1..86e9a8a6 100644 --- a/test/unit/rotate.js +++ b/test/unit/rotate.js @@ -473,4 +473,20 @@ describe('Rotation', function () { assert.strictEqual(g, 64); assert.strictEqual(b, 30); }); + + it('Resize after affine-based rotation does not overcompute', async () => + sharp({ + create: { + width: 4640, + height: 2610, + channels: 3, + background: 'black' + } + }) + .rotate(28) + .resize({ width: 640, height: 360 }) + .raw() + .timeout({ seconds: 5 }) + .toBuffer() + ); });