From b9c38515157d0830fd2656fe29eae858dd4916be Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sat, 1 Apr 2023 12:08:14 +0100 Subject: [PATCH] Ensure linear op works with 16-bit input #3605 --- docs/changelog.md | 3 +++ src/operations.cc | 5 +++-- test/fixtures/expected/linear-16bit.png | Bin 0 -> 1168 bytes test/unit/linear.js | 10 ++++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/expected/linear-16bit.png diff --git a/docs/changelog.md b/docs/changelog.md index ec4ac5a7..59d52d6d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -9,6 +9,9 @@ Requires libvips v8.14.2 * Ensure use of `flip` operation forces random access read (regression in 0.32.0). [#3600](https://github.com/lovell/sharp/issues/3600) +* Ensure `linear` operation works with 16-bit input (regression in 0.31.3). + [#3605](https://github.com/lovell/sharp/issues/3605) + ### v0.32.0 - 24th March 2023 * Default to using sequential rather than random access read where possible. diff --git a/src/operations.cc b/src/operations.cc index ea8652ec..026a0ffd 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -332,12 +332,13 @@ namespace sharp { if (a.size() > bands) { throw VError("Band expansion using linear is unsupported"); } + bool const uchar = !Is16Bit(image.interpretation()); if (HasAlpha(image) && a.size() != bands && (a.size() == 1 || a.size() == bands - 1 || bands - 1 == 1)) { // Separate alpha channel VImage alpha = image[bands - 1]; - return RemoveAlpha(image).linear(a, b, VImage::option()->set("uchar", TRUE)).bandjoin(alpha); + return RemoveAlpha(image).linear(a, b, VImage::option()->set("uchar", uchar)).bandjoin(alpha); } else { - return image.linear(a, b, VImage::option()->set("uchar", TRUE)); + return image.linear(a, b, VImage::option()->set("uchar", uchar)); } } diff --git a/test/fixtures/expected/linear-16bit.png b/test/fixtures/expected/linear-16bit.png new file mode 100644 index 0000000000000000000000000000000000000000..3e7bfc5256249cd12c209d4a1f5bbbf4e37cfe14 GIT binary patch literal 1168 zcmV;B1aJF^P)9~Z7VDkv382~j{yu+Zv*f>hgV(RCB3HtH z3BkV2M%wKr^5h9&AxK>PM`tIe8yj4+rU059A0KmYaKKqA1v11Iiza%*C6L1b!^4!i zyD97b%SIyX?(V8%$uY0lO@LCVq&7S{I#L~v$0%mA!KY6U4#U6zm`n}9ii)B}t~OT9 zx3{+&1JtZisZb~sU}*`uyP>ZSLLq(}9g)xHH7{qg@Z}5i_rtSiRY18nhK4A_Ca(^J)@xD0nJ7Sn`-!61o5f@Y@x1qE?c5~z)D*xA`xQ{UU$Bbi*4D}mW8 zSLO#pLvg02X1KVxXbxb*rUCTRe=C4~d1O+OUMv>XwO(6WBNAEFrwN4k9U(Ru9*!Eq ze=C3;y9OZ3G4WsNnX9Gi7G-=q(i*^p%K%`(qW19P*S?K1Y5+Jq zJXFQQ;Y~U^YT`LYN2i#cp2lt;!{v&qS+!Lv#*5bgAj=$cY9wmEefSIjGTTW2m#aSe z!NCN6e+aw%TuYeOXMZceL~)`jQ>X*HONhS>d>2#W}UrXBToz4_?dk`TC2$5C2w|BWcfbbt-O~{>hYju5o zm}S-gAUB{s{2osPhvQdFrVK(HsNd%2bF_6GZyjuDLKEu~yx_%+Jt0qo-ek6OI%@!1 zOis??a=EbCcCNlK~5WwU4u0_OZ zjo%HRb{f*((`2?Ybkb=6h@hQk)uPcTj~`b@vsf~Cy(?-8uI`8VTC+R7h=lC1v$LbV z{oK^|f-F(Al&apI5}>C?9=8gLvW}uu)RB98cbkg00??un&&3-?KxRRC)xLWd#AK2? zUWPuy+qZ`;#oGbUAoM9ZM$C`}BasL`pAV;VfUYh-fxv!S;_U)xATkBZqggE1U%hgf z3NbP=qTYz@ir*DL=pQHgEV!_+pguZuCVm!xFl_&;EO`B$_pp!`-(pl iKp%~JkMU4|2m9Y-@#nc$3izo20000