Improve extractChannel support for 16-bit output #3453

This commit is contained in:
Lovell Fuller
2022-11-15 15:00:32 +00:00
parent 789d4851ea
commit 01ffa80338
5 changed files with 38 additions and 39 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -54,19 +54,13 @@ describe('Image channel extraction', function () {
});
});
it('With colorspace conversion', function (done) {
const output = fixtures.path('output.extract-lch.jpg');
sharp(fixtures.inputJpg)
.extractChannel(1)
it('With colorspace conversion', async () => {
const [chroma] = await sharp({ create: { width: 1, height: 1, channels: 3, background: 'red' } })
.toColourspace('lch')
.resize(320, 240, { fastShrinkOnLoad: false })
.toFile(output, function (err, info) {
if (err) throw err;
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
fixtures.assertMaxColourDistance(output, fixtures.expected('extract-lch.jpg'), 9);
done();
});
.extractChannel(1)
.toBuffer();
assert.strictEqual(chroma, 104);
});
it('Alpha from 16-bit PNG', function (done) {
@@ -108,12 +102,12 @@ describe('Image channel extraction', function () {
});
});
it('Non-existent channel', function (done) {
sharp(fixtures.inputPng)
.extractChannel(1)
.toBuffer(function (err) {
assert(err instanceof Error);
done();
});
});
it('Non-existent channel', async () =>
await assert.rejects(
() => sharp({ create: { width: 1, height: 1, channels: 3, background: 'red' } })
.extractChannel(3)
.toBuffer(),
/Cannot extract channel 3 from image with channels 0-2/
)
);
});