mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Improve extractChannel support for 16-bit output #3453
This commit is contained in:
@@ -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/
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user