diff --git a/docs/changelog.md b/docs/changelog.md index 6f7f4af5..2d75a0c1 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -10,6 +10,10 @@ Requires libvips v8.6.1. [#1241](https://github.com/lovell/sharp/issues/1241) [@anahit42](https://github.com/anahit42) +* Ensure extractChannel sets correct single-channel colour space interpretation. + [#1257](https://github.com/lovell/sharp/issues/1257) + [@jeremychone](https://github.com/jeremychone) + #### v0.20.3 - 29th May 2018 * Fix tint operation by ensuring LAB interpretation and allowing negative values. diff --git a/src/pipeline.cc b/src/pipeline.cc index 0516557a..13b4501c 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -694,7 +694,9 @@ class PipelineWorker : public Nan::AsyncWorker { (baton->err).append("Cannot extract channel from image. Too few channels in image."); return Error(); } - image = image.extract_band(baton->extractChannel); + image = image + .extract_band(baton->extractChannel) + .copy(VImage::option()->set("interpretation", VIPS_INTERPRETATION_B_W)); } // Convert image to sRGB, if not already if (sharp::Is16Bit(image.interpretation())) { diff --git a/test/fixtures/expected/extract-lch.jpg b/test/fixtures/expected/extract-lch.jpg new file mode 100644 index 00000000..6840777a Binary files /dev/null and b/test/fixtures/expected/extract-lch.jpg differ diff --git a/test/unit/extractChannel.js b/test/unit/extractChannel.js index a12fa708..2b599b7e 100644 --- a/test/unit/extractChannel.js +++ b/test/unit/extractChannel.js @@ -54,6 +54,21 @@ describe('Image channel extraction', function () { }); }); + it('With colorspace conversion', function (done) { + const output = fixtures.path('output.extract-lch.jpg'); + sharp(fixtures.inputJpg) + .toColourspace('lch') + .extractChannel(1) + .resize(320, 240) + .toFile(output, function (err, info) { + if (err) throw err; + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + fixtures.assertMaxColourDistance(output, fixtures.expected('extract-lch.jpg')); + done(); + }); + }); + it('Invalid channel number', function () { assert.throws(function () { sharp(fixtures.inputJpg)