diff --git a/docs/changelog.md b/docs/changelog.md index aa78725ab..b198fab7c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -29,6 +29,9 @@ Requires libvips v8.15.2 [#4172](https://github.com/lovell/sharp/pull/4172) [@marcosc90](https://github.com/marcosc90) +* Ensure `keepIccProfile` avoids colour transformation where possible. + [#4186](https://github.com/lovell/sharp/issues/4186) + ### v0.33.4 - 16th May 2024 * Remove experimental status from `pipelineColourspace`. diff --git a/src/pipeline.cc b/src/pipeline.cc index fafd695ca..ac5ead01e 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -325,6 +325,7 @@ class PipelineWorker : public Napi::AsyncWorker { if ((baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) && baton->withIccProfile.empty()) { // Cache input profile for use with output inputProfile = sharp::GetProfile(image); + baton->input->ignoreIcc = true; } char const *processingProfile = image.interpretation() == VIPS_INTERPRETATION_RGB16 ? "p3" : "srgb"; if ( diff --git a/test/fixtures/index.js b/test/fixtures/index.js index a791ac7e8..e4b8e266e 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -99,6 +99,7 @@ module.exports = { inputPngTrimSpecificColour16bit: getPath('Flag_of_the_Netherlands-16bit.png'), // convert Flag_of_the_Netherlands.png -depth 16 Flag_of_the_Netherlands-16bit.png inputPngTrimSpecificColourIncludeAlpha: getPath('Flag_of_the_Netherlands-alpha.png'), // convert Flag_of_the_Netherlands.png -alpha set -background none -channel A -evaluate multiply 0.5 +channel Flag_of_the_Netherlands-alpha.png inputPngUint32Limit: getPath('65536-uint32-limit.png'), // https://alexandre.alapetite.fr/doc-alex/large-image/ + inputPngWithProPhotoProfile: getPath('prophoto.png'), inputWebP: getPath('4.webp'), // http://www.gstatic.com/webp/gallery/4.webp inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp diff --git a/test/fixtures/prophoto.png b/test/fixtures/prophoto.png new file mode 100644 index 000000000..e01fcb02a Binary files /dev/null and b/test/fixtures/prophoto.png differ diff --git a/test/unit/metadata.js b/test/unit/metadata.js index 417871299..83fddf30f 100644 --- a/test/unit/metadata.js +++ b/test/unit/metadata.js @@ -601,6 +601,17 @@ describe('Image metadata', function () { assert.strictEqual(description, 'Generic RGB Profile'); }); + it('keep existing ICC profile, avoid colour transform', async () => { + const [r, g, b] = await sharp(fixtures.inputPngWithProPhotoProfile) + .keepIccProfile() + .raw() + .toBuffer(); + + assert.strictEqual(r, 131); + assert.strictEqual(g, 141); + assert.strictEqual(b, 192); + }); + it('keep existing CMYK ICC profile', async () => { const data = await sharp(fixtures.inputJpgWithCmykProfile) .pipelineColourspace('cmyk')