Skip to content

Commit

Permalink
Ensure boolean, bandbool, extractChannel ops occur before sRGB conver…
Browse files Browse the repository at this point in the history
…sion (#504)
  • Loading branch information
mhirsch authored and lovell committed Jul 13, 2016
1 parent 2d50055 commit 15a5778
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>(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())) {
Expand Down Expand Up @@ -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<char*>(srgbProfile.data()), VImage::option()
->set("embedded", TRUE)
);
}
}

// Override EXIF Orientation tag
if (baton->withMetadata && baton->withMetadataOrientation != -1) {
SetExifOrientation(image, baton->withMetadataOrientation);
Expand Down
9 changes: 9 additions & 0 deletions test/unit/extractChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

});

0 comments on commit 15a5778

Please sign in to comment.