From 23033e2050d9ef099ecb02dde0f56f9f23e8d30d Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Fri, 4 Mar 2022 23:17:07 +0000 Subject: [PATCH] Prevent double unpremultiply with some composite blends --- docs/changelog.md | 5 +++++ src/pipeline.cc | 2 +- test/fixtures/expected/composite-multiple.png | Bin 320 -> 320 bytes .../expected/composite.blend.dest-over.png | Bin 291 -> 292 bytes test/fixtures/expected/composite.blend.over.png | Bin 292 -> 292 bytes .../expected/composite.blend.saturate.png | Bin 288 -> 286 bytes test/fixtures/expected/composite.blend.xor.png | Bin 286 -> 285 bytes test/unit/extend.js | 2 +- 8 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 58e80884..25dbe2cd 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,11 @@ Requires libvips v8.12.2 +### v0.30.3 - TBD + +* Prevent double unpremultiply with some composite blend modes (regression in 0.30.2). + [#3118](https://github.com/lovell/sharp/issues/3118) + ### v0.30.2 - 2nd March 2022 * Improve performance and accuracy when compositing multiple images. diff --git a/src/pipeline.cc b/src/pipeline.cc index 2289dd21..a0858605 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -354,7 +354,7 @@ class PipelineWorker : public Napi::AsyncWorker { } bool const shouldPremultiplyAlpha = sharp::HasAlpha(image) && - (shouldResize || shouldBlur || shouldConv || shouldSharpen || shouldComposite); + (shouldResize || shouldBlur || shouldConv || shouldSharpen); // Premultiply image alpha channel before all transformations to avoid // dark fringing around bright pixels diff --git a/test/fixtures/expected/composite-multiple.png b/test/fixtures/expected/composite-multiple.png index 2aef0fbdee9faa6bb1fd6002bb265361800e4461..18671a39b6ce4491c6ec64bd0c852074559e5f21 100644 GIT binary patch delta 255 zcmVA>0Nq@}13_t)CLt&JJp*$#WAXY7X+I^V7$!Q!*<%Y3S#mYYk0WJZS z4qWY{=m;agbi2tVf&kO)C}Ru)%#&o0Mu5?Q^pBz=i~!T^CYJ~TOt+(qF$geEl0lj; z0oEcr^_uT%r@9>`Km?d>mpQ@+Fx^gbi6Fq7C}Ru)j1HUz>3DdFc*?~kf?N2qOqjMY z)>#;&<0UdJR4*H8EB*YuOsLJ;{S9Nc1c(5K4qT3Kd;;F6A>0Nq@w^1ji5+O=%d)lS2{Pc1_9SZHsrJtXd3AI_fzhUf_01@EOfy)t&Z{Pt7qg)~gu-kEEj6s0it}BBy z0z5_c0q2^h90DBOPP0rvfTP=O)>#N}oF)rZ1UNb!_yJla9Ple{DG~qx002ovPDHLk FV1iKQYTf_< diff --git a/test/fixtures/expected/composite.blend.dest-over.png b/test/fixtures/expected/composite.blend.dest-over.png index a230c331a763b265a97d97b243ad8aadded7a8ce..f7f7b1eb92d5a9b910e864e6104e642e80264fa9 100644 GIT binary patch delta 170 zcmV;b09F5^0;B?vIZxI}L_t(|ob8)25yUVM#01iS4o^rdGzY_fij5~Kj(|oQZ(}x$ z$KMPP9*+bPAOf6bMH+|zM*}%`379Yf91Y|H316&y>9zou051((^^u@VP-wykFm0QB zL=a%wMmb{;U`{%RGy;qU(ogX<33~`|``M7!m0-dMa5Rv9iYANzr)`su2m+k8QNPZZ Y8`#oRLlzl`^#A|>07*qoM6N<$g0{&&X8-^I delta 193 zcmZ3&w3umvW&Kr87srr_Id5lgrY+p%qgLlJpwsloqYCQ~>x1DrnVO*9w z#h8up*^*)pSn{(o| smq8+ng_MWAtFT)G#2CNZE8^47@NUp{3F*1Wmd5}Dp00i_>zopr0G#gTe~ HDWM4f7$9S= literal 288 zcmeAS@N?(olHy`uVBq!ia0vp^0YGfS!3HEhs@wJeDb50q$YKTt<`*E$xV1Vc8z^|m z)5S5QV$R#y8wHOT@EqPS(|DFydfJKlgD;w#xF0kaOAAZ%&zDrN`6uMjz)>(uG*f{| zhBxKCkU=7gh13alp?wxVFS$0jH%w=nSJkD~!*F@qNp}{;Ww}#~*%;F>3w=gj;Tw$pQ&xbDgCa-I!leQ{u!{3F(L>2Wa7YYd*QelF{r G5}E)3zG7kk literal 286 zcmeAS@N?(olHy`uVBq!ia0vp^0YGfS!3HEhs@wJeDb50q$YKTt<`*E$xV1Vc8z^|e z)5S5QV$R#y8+n->c@FQ`xo4-b^CYKy8*Y7v2^OZu4^{j*!|?FqbO$DvhRbU_m<1nX zD3nic;8Z?v(IIZahYgjN*D{1REN+bUzt|#}aLepxhr)p^y+y|q4#Zfsn=tjTU81JM zM?=nPj)K2ACmwqlB(hjYdDy!OyERFVdQ I&MBb@0IctB$N&HU diff --git a/test/unit/extend.js b/test/unit/extend.js index 3d81e312..1e22df77 100644 --- a/test/unit/extend.js +++ b/test/unit/extend.js @@ -158,6 +158,6 @@ describe('Extend', function () { }) .raw() .toBuffer(); - assert.deepStrictEqual(Array.from(data), [191, 25, 65, 204, 238, 31, 82, 204]); + assert.deepStrictEqual(Array.from(data), [191, 25, 66, 204, 191, 25, 66, 204]); }); });