From 1d4bed28b3da2fb8a8acf42f6c8a629adb90760b Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 23 Nov 2021 14:19:47 +0000 Subject: [PATCH] Tests: add tests for decoding RGB/RGBA palette PNGs --- test/unit/png.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/unit/png.js b/test/unit/png.js index 92feb25e0..9db15854e 100644 --- a/test/unit/png.js +++ b/test/unit/png.js @@ -128,6 +128,45 @@ describe('PNG', function () { assert.strictEqual(alphaMeanAfter, alphaMeanBefore); }); + it('RGB palette PNG decode', async () => { + const rgb = await sharp(fixtures.inputJpg) + .resize(8, 8) + .png({ palette: true }) + .toBuffer(); + + const { info } = await sharp(rgb) + .toBuffer({ resolveWithObject: true }); + const { size, ...infoWithoutSize } = info; + + assert.deepStrictEqual(infoWithoutSize, { + format: 'png', + width: 8, + height: 8, + channels: 3, + premultiplied: false + }); + }); + + it('RGBA palette PNG decode', async () => { + const rgba = await sharp(fixtures.inputJpg) + .resize(8, 8) + .ensureAlpha(0.5) + .png({ palette: true }) + .toBuffer(); + + const { info } = await sharp(rgba) + .toBuffer({ resolveWithObject: true }); + const { size, ...infoWithoutSize } = info; + + assert.deepStrictEqual(infoWithoutSize, { + format: 'png', + width: 8, + height: 8, + channels: 4, + premultiplied: false + }); + }); + it('Valid PNG libimagequant palette value does not throw error', function () { assert.doesNotThrow(function () { sharp().png({ palette: false });