diff --git a/src/pipeline.cc b/src/pipeline.cc index 91c09de49..b21625c5e 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -357,11 +357,6 @@ class PipelineWorker : public Napi::AsyncWorker { image = sharp::Flatten(image, baton->flattenBackground); } - // Negate the colours in the image - if (baton->negate) { - image = sharp::Negate(image, baton->negateAlpha); - } - // Gamma encoding (darken) if (baton->gamma >= 1 && baton->gamma <= 3) { image = sharp::Gamma(image, 1.0 / baton->gamma); @@ -821,6 +816,12 @@ class PipelineWorker : public Napi::AsyncWorker { } else if (baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) { image = sharp::SetProfile(image, inputProfile); } + + // Negate the colours in the image + if (baton->negate) { + image = sharp::Negate(image, baton->negateAlpha); + } + // Override EXIF Orientation tag if (baton->withMetadataOrientation != -1) { image = sharp::SetExifOrientation(image, baton->withMetadataOrientation); diff --git a/test/fixtures/XCMYK 2017.icc b/test/fixtures/XCMYK 2017.icc new file mode 100644 index 000000000..ec9aae7d4 Binary files /dev/null and b/test/fixtures/XCMYK 2017.icc differ diff --git a/test/fixtures/expected/colourspace.cmyk-to-cmyk-negated.tif b/test/fixtures/expected/colourspace.cmyk-to-cmyk-negated.tif new file mode 100644 index 000000000..e1f1b60e9 Binary files /dev/null and b/test/fixtures/expected/colourspace.cmyk-to-cmyk-negated.tif differ diff --git a/test/fixtures/expected/negate-trans.png b/test/fixtures/expected/negate-trans.png index 52e79e5f6..d590068cc 100644 Binary files a/test/fixtures/expected/negate-trans.png and b/test/fixtures/expected/negate-trans.png differ diff --git a/test/fixtures/fogra-0-100-100-0.tif b/test/fixtures/fogra-0-100-100-0.tif new file mode 100644 index 000000000..d6c3a598a Binary files /dev/null and b/test/fixtures/fogra-0-100-100-0.tif differ diff --git a/test/fixtures/index.js b/test/fixtures/index.js index a436e8ead..40f05dbc9 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -114,6 +114,7 @@ module.exports = { inputTiffUncompressed: getPath('uncompressed_tiff.tiff'), // https://code.google.com/archive/p/imagetestsuite/wikis/TIFFTestSuite.wiki file: 0c84d07e1b22b76f24cccc70d8788e4a.tif inputTiff8BitDepth: getPath('8bit_depth.tiff'), inputTifftagPhotoshop: getPath('tifftag-photoshop.tiff'), // https://github.com/lovell/sharp/issues/1600 + inputTiffFogra: getPath('fogra-0-100-100-0.tif'), // https://github.com/lovell/sharp/issues/4045 inputJp2: getPath('relax.jp2'), // https://www.fnordware.com/j2k/relax.jp2 inputGif: getPath('Crash_test.gif'), // http://upload.wikimedia.org/wikipedia/commons/e/e3/Crash_test.gif diff --git a/test/unit/colourspace.js b/test/unit/colourspace.js index 71ce402d6..33e4e329b 100644 --- a/test/unit/colourspace.js +++ b/test/unit/colourspace.js @@ -106,6 +106,43 @@ describe('Colour space conversion', function () { ); }); + it('CMYK profile to CMYK profile conversion using perceptual intent', async () => { + const data = await sharp(fixtures.inputTiffFogra) + .resize(320, 240) + .toColourspace('cmyk') + .pipelineColourspace('cmyk') + .withIccProfile(fixtures.path('XCMYK 2017.icc')) + .raw() + .toBuffer(); + + const [c, m, y, k] = data; + assert.deepStrictEqual( + { c, m, y, k }, + { c: 1, m: 239, y: 227, k: 5 } + ); + }); + + it('CMYK profile to CMYK profile with negate', (done) => { + sharp(fixtures.inputTiffFogra) + .resize(320, 240) + .toColourspace('cmyk') + .pipelineColourspace('cmyk') + .withIccProfile(fixtures.path('XCMYK 2017.icc')) + .negate() + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual('tiff', info.format); + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + fixtures.assertSimilar( + fixtures.expected('colourspace.cmyk-to-cmyk-negated.tif'), + data, + { threshold: 0 }, + done + ); + }); + }); + it('From sRGB with RGB16 pipeline, resize with gamma, to sRGB', function (done) { sharp(fixtures.inputPngGradients) .pipelineColourspace('rgb16')