From 9d760f39587aa986fcd9f8c854c045de44618f3f Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Mon, 5 Dec 2022 20:40:41 +0000 Subject: [PATCH] Improve perf of ops that introduce non-opaque background #3465 --- docs/changelog.md | 3 +++ src/common.cc | 2 +- test/unit/rotate.js | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index c6374becf..f04b7aaba 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -18,6 +18,9 @@ Requires libvips v8.13.3 * Ignore `sequentialRead` option when calculating image statistics. [#3462](https://github.com/lovell/sharp/issues/3462) +* Small performance improvement for operations that introduce a non-opaque background. + [#3465](https://github.com/lovell/sharp/issues/3465) + * Ensure integral output of `linear` operation. [#3468](https://github.com/lovell/sharp/issues/3468) diff --git a/src/common.cc b/src/common.cc index 0c6302a35..3a208951f 100644 --- a/src/common.cc +++ b/src/common.cc @@ -913,7 +913,7 @@ namespace sharp { // Add non-transparent alpha channel, if required if (colour[3] < 255.0 && !HasAlpha(image)) { image = image.bandjoin( - VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier)); + VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier).cast(image.format())); } return std::make_tuple(image, alphaColour); } diff --git a/test/unit/rotate.js b/test/unit/rotate.js index a08bc51a6..33dfb18fa 100644 --- a/test/unit/rotate.js +++ b/test/unit/rotate.js @@ -67,7 +67,7 @@ describe('Rotation', function () { it('Rotate by 30 degrees with solid background', function (done) { sharp(fixtures.inputJpg) .resize(320) - .rotate(30, { background: { r: 255, g: 0, b: 0, alpha: 0.5 } }) + .rotate(30, { background: { r: 255, g: 0, b: 0 } }) .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format);