Skip to content

Commit

Permalink
Tests: add tests for decoding RGB/RGBA palette PNGs
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Nov 23, 2021
1 parent 549219f commit 1d4bed2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/unit/png.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 1d4bed2

Please sign in to comment.