mirror of
https://github.com/lovell/sharp.git
synced 2025-07-13 04:20:12 +02:00
Ensure integral output of linear op #3468
This commit is contained in:
parent
a472aea025
commit
0265d305fe
@ -18,6 +18,9 @@ Requires libvips v8.13.3
|
||||
* Ignore `sequentialRead` option when calculating image statistics.
|
||||
[#3462](https://github.com/lovell/sharp/issues/3462)
|
||||
|
||||
* Ensure integral output of `linear` operation.
|
||||
[#3468](https://github.com/lovell/sharp/issues/3468)
|
||||
|
||||
### v0.31.2 - 4th November 2022
|
||||
|
||||
* Upgrade to libvips v8.13.3 for upstream bug fixes.
|
||||
|
@ -345,9 +345,9 @@ namespace sharp {
|
||||
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).bandjoin(alpha);
|
||||
return RemoveAlpha(image).linear(a, b, VImage::option()->set("uchar", TRUE)).bandjoin(alpha);
|
||||
} else {
|
||||
return image.linear(a, b);
|
||||
return image.linear(a, b, VImage::option()->set("uchar", TRUE));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,28 @@ describe('Linear adjustment', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('output is integer, not float, RGB', async () => {
|
||||
const data = await sharp({ create: { width: 1, height: 1, channels: 3, background: 'red' } })
|
||||
.linear(1, 0)
|
||||
.tiff({ compression: 'none' })
|
||||
.toBuffer();
|
||||
|
||||
const { channels, depth } = await sharp(data).metadata();
|
||||
assert.strictEqual(channels, 3);
|
||||
assert.strictEqual(depth, 'uchar');
|
||||
});
|
||||
|
||||
it('output is integer, not float, RGBA', async () => {
|
||||
const data = await sharp({ create: { width: 1, height: 1, channels: 4, background: '#ff000077' } })
|
||||
.linear(1, 0)
|
||||
.tiff({ compression: 'none' })
|
||||
.toBuffer();
|
||||
|
||||
const { channels, depth } = await sharp(data).metadata();
|
||||
assert.strictEqual(channels, 4);
|
||||
assert.strictEqual(depth, 'uchar');
|
||||
});
|
||||
|
||||
it('Invalid linear arguments', function () {
|
||||
assert.throws(
|
||||
() => sharp().linear('foo'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user