Skip to content

Commit

Permalink
Ensure linear op works with 16-bit input #3605
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Apr 1, 2023
1 parent 97cf69c commit b9c3851
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions src/operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
Binary file added test/fixtures/expected/linear-16bit.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions test/unit/linear.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ describe('Linear adjustment', function () {
});
});

it('applies linear levels adjustment to 16-bit w alpha ch', function (done) {
sharp(fixtures.inputPngWithTransparency16bit)
.linear(a, b)
.png({ compressionLevel: 0 })
.toBuffer(function (err, data) {
if (err) throw err;
fixtures.assertSimilar(fixtures.expected('linear-16bit.png'), data, done);
});
});

it('applies slope level adjustment w alpha ch', function (done) {
sharp(fixtures.inputPngOverlayLayer1)
.resize(240)
Expand Down

0 comments on commit b9c3851

Please sign in to comment.