Skip to content

Commit

Permalink
Ensure withMetadata skips default profile for RGB16 #3773
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Aug 24, 2023
1 parent 44a0ee3 commit 9563568
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/api-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ await sharp(pixelArray, { raw: { width, height, channels } })

## withMetadata
Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
This will also convert to and add a web-friendly sRGB ICC profile unless a custom
output profile is provided.
This will also convert to and add a web-friendly sRGB ICC profile if appropriate,
unless a custom output profile is provided.

The default behaviour, when `withMetadata` is not used, is to convert to the device-independent
sRGB colour space and strip all metadata, including the removal of any ICC profile.
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

Requires libvips v8.14.4

### v0.32.6 - TBD

* Ensure `withMetadata` does not add default sRGB profile to RGB16 (regression in 0.32.5).
[#3773](https://github.com/lovell/sharp/issues/3773)

### v0.32.5 - 15th August 2023

* Upgrade to libvips v8.14.4 for upstream bug fixes.
Expand Down
2 changes: 1 addition & 1 deletion docs/search-index.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ function toBuffer (options, callback) {

/**
* Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
* This will also convert to and add a web-friendly sRGB ICC profile unless a custom
* output profile is provided.
* This will also convert to and add a web-friendly sRGB ICC profile if appropriate,
* unless a custom output profile is provided.
*
* The default behaviour, when `withMetadata` is not used, is to convert to the device-independent
* sRGB colour space and strip all metadata, including the removal of any ICC profile.
Expand Down
14 changes: 8 additions & 6 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,14 @@ class PipelineWorker : public Napi::AsyncWorker {

// Apply output ICC profile
if (baton->withMetadata) {
image = image.icc_transform(
baton->withMetadataIcc.empty() ? "srgb" : const_cast<char*>(baton->withMetadataIcc.data()),
VImage::option()
->set("input_profile", processingProfile)
->set("embedded", TRUE)
->set("intent", VIPS_INTENT_PERCEPTUAL));
if (image.interpretation() == VIPS_INTERPRETATION_sRGB || !baton->withMetadataIcc.empty()) {
image = image.icc_transform(
baton->withMetadataIcc.empty() ? "srgb" : const_cast<char*>(baton->withMetadataIcc.data()),
VImage::option()
->set("input_profile", processingProfile)
->set("embedded", TRUE)
->set("intent", VIPS_INTENT_PERCEPTUAL));
}
}
// Override EXIF Orientation tag
if (baton->withMetadata && baton->withMetadataOrientation != -1) {
Expand Down
11 changes: 11 additions & 0 deletions test/unit/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,17 @@ describe('Image metadata', function () {
assert.strictEqual(intent, 'Perceptual');
});

it('withMetadata does not add default sRGB profile to RGB16', async () => {
const data = await sharp(fixtures.inputJpg)
.resize(32, 24)
.toColorspace('rgb16')
.withMetadata()
.toBuffer();

const metadata = await sharp(data).metadata();
assert.strictEqual(undefined, metadata.icc);
});

it('File input with corrupt header fails gracefully', function (done) {
sharp(fixtures.inputJpgWithCorruptHeader)
.metadata(function (err) {
Expand Down

0 comments on commit 9563568

Please sign in to comment.