diff --git a/docs/changelog.md b/docs/changelog.md index 920eb31a..99347473 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,11 @@ Requires libvips v8.8.1. +#### v0.23.5 - TBD + +* Ensure correct colour output for 16-bit, 2-channel PNG input with ICC profile. + [#2013](https://github.com/lovell/sharp/issues/2013) + #### v0.23.4 - 5th December 2019 * Handle zero-length Buffer objects when using Node.js v13.2.0+. diff --git a/src/pipeline.cc b/src/pipeline.cc index 83ba354d..d542688e 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -311,7 +311,11 @@ class PipelineWorker : public Nan::AsyncWorker { } // Ensure we're using a device-independent colour space - if (sharp::HasProfile(image) && image.interpretation() != VIPS_INTERPRETATION_LABS) { + if ( + sharp::HasProfile(image) && + image.interpretation() != VIPS_INTERPRETATION_LABS && + image.interpretation() != VIPS_INTERPRETATION_GREY16 + ) { // Convert to sRGB using embedded profile try { image = image.icc_transform("srgb", VImage::option() diff --git a/test/fixtures/16-bit-grey-alpha.png b/test/fixtures/16-bit-grey-alpha.png new file mode 100644 index 00000000..fab9f503 Binary files /dev/null and b/test/fixtures/16-bit-grey-alpha.png differ diff --git a/test/fixtures/expected/16-bit-grey-alpha-identity.png b/test/fixtures/expected/16-bit-grey-alpha-identity.png new file mode 100644 index 00000000..766074b3 Binary files /dev/null and b/test/fixtures/expected/16-bit-grey-alpha-identity.png differ diff --git a/test/fixtures/index.js b/test/fixtures/index.js index 85c6f0a8..affe8c3f 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -79,6 +79,7 @@ module.exports = { inputPngWithGreyAlpha: getPath('grey-8bit-alpha.png'), inputPngWithOneColor: getPath('2x2_fdcce6.png'), inputPngWithTransparency16bit: getPath('tbgn2c16.png'), // http://www.schaik.com/pngsuite/tbgn2c16.png + inputPng16BitGreyAlpha: getPath('16-bit-grey-alpha.png'), // CC-BY-NC-SA florc http://www.colourlovers.com/pattern/50713/pat inputPngOverlayLayer0: getPath('alpha-layer-0-background.png'), inputPngOverlayLayer1: getPath('alpha-layer-1-fill.png'), inputPngAlphaPremultiplicationSmall: getPath('alpha-premultiply-1024x768-paper.png'), diff --git a/test/unit/png.js b/test/unit/png.js index d3c642b6..4661d414 100644 --- a/test/unit/png.js +++ b/test/unit/png.js @@ -103,6 +103,15 @@ describe('PNG', function () { }); }); + it('16-bit grey+alpha PNG identity transform', function () { + const actual = fixtures.path('output.16-bit-grey-alpha-identity.png'); + return sharp(fixtures.inputPng16BitGreyAlpha) + .toFile(actual) + .then(function () { + fixtures.assertMaxColourDistance(actual, fixtures.expected('16-bit-grey-alpha-identity.png')); + }); + }); + it('Valid PNG libimagequant palette value does not throw error', function () { assert.doesNotThrow(function () { sharp().png({ palette: false });