Skip to content

Commit

Permalink
Ensure extractChannel sets bw colourspace interp #1257
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Jun 19, 2018
1 parent da0b034 commit 94607b5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 - 29<sup>th</sup> May 2018

* Fix tint operation by ensuring LAB interpretation and allowing negative values.
Expand Down
4 changes: 3 additions & 1 deletion src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down
Binary file added test/fixtures/expected/extract-lch.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions test/unit/extractChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 94607b5

Please sign in to comment.