diff --git a/src/pipeline.cc b/src/pipeline.cc index 45b8550d..20f2a645 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -774,20 +774,6 @@ class PipelineWorker : public AsyncWorker { image = Normalize(image); } - // Convert image to sRGB, if not already - if (Is16Bit(image.interpretation())) { - image = image.cast(VIPS_FORMAT_USHORT); - } - if (image.interpretation() != VIPS_INTERPRETATION_sRGB) { - image = image.colourspace(VIPS_INTERPRETATION_sRGB); - // Transform colours from embedded profile to sRGB profile - if (baton->withMetadata && HasProfile(image)) { - image = image.icc_transform(const_cast(srgbProfile.data()), VImage::option() - ->set("embedded", TRUE) - ); - } - } - // Apply bitwise boolean operation between images if (baton->booleanOp != VIPS_OPERATION_BOOLEAN_LAST && (baton->booleanBufferInLength > 0 || !baton->booleanFileIn.empty())) { @@ -840,6 +826,20 @@ class PipelineWorker : public AsyncWorker { image = image.extract_band(baton->extractChannel); } + // Convert image to sRGB, if not already + if (Is16Bit(image.interpretation())) { + image = image.cast(VIPS_FORMAT_USHORT); + } + if (image.interpretation() != VIPS_INTERPRETATION_sRGB) { + image = image.colourspace(VIPS_INTERPRETATION_sRGB); + // Transform colours from embedded profile to sRGB profile + if (baton->withMetadata && HasProfile(image)) { + image = image.icc_transform(const_cast(srgbProfile.data()), VImage::option() + ->set("embedded", TRUE) + ); + } + } + // Override EXIF Orientation tag if (baton->withMetadata && baton->withMetadataOrientation != -1) { SetExifOrientation(image, baton->withMetadataOrientation); diff --git a/test/unit/extractChannel.js b/test/unit/extractChannel.js index 843b8567..60f69b5f 100644 --- a/test/unit/extractChannel.js +++ b/test/unit/extractChannel.js @@ -69,4 +69,13 @@ describe('Image channel extraction', function() { }); }); + it('Non-existant channel', function(done) { + sharp(fixtures.inputPng) + .extractChannel(1) + .toBuffer(function(err) { + assert(err instanceof Error); + done(); + }); + }); + });