Emit warning for invalid ICC profile #3895

This commit is contained in:
Lovell Fuller 2023-12-15 12:13:57 +00:00
parent c9e3996007
commit fe2b298a2f
4 changed files with 30 additions and 5 deletions

View File

@ -9,6 +9,9 @@ Requires libvips v8.15.0
* Add support for Yarn Plug'n'Play filesystem layout.
[#3888](https://github.com/lovell/sharp/issues/3888)
* Emit warning when attempting to use invalid ICC profiles.
[#3895](https://github.com/lovell/sharp/issues/3895)
### v0.33.0 - 29th November 2023
* Drop support for Node.js 14 and 16, now requires Node.js >= 18.17.0

View File

@ -794,11 +794,15 @@ class PipelineWorker : public Napi::AsyncWorker {
// Apply output ICC profile
if (!baton->withIccProfile.empty()) {
image = image.icc_transform(const_cast<char*>(baton->withIccProfile.data()), VImage::option()
->set("input_profile", processingProfile)
->set("embedded", TRUE)
->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
->set("intent", VIPS_INTENT_PERCEPTUAL));
try {
image = image.icc_transform(const_cast<char*>(baton->withIccProfile.data()), VImage::option()
->set("input_profile", processingProfile)
->set("embedded", TRUE)
->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
->set("intent", VIPS_INTENT_PERCEPTUAL));
} catch(...) {
sharp::VipsWarningCallback(nullptr, G_LOG_LEVEL_WARNING, "Invalid profile", nullptr);
}
} else if (baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) {
image = sharp::SetProfile(image, inputProfile);
}

BIN
test/fixtures/invalid-illuminant.icc vendored Normal file

Binary file not shown.

View File

@ -598,6 +598,24 @@ describe('Image metadata', function () {
assert.strictEqual(undefined, metadata.icc);
});
it('transform to invalid ICC profile emits warning', async () => {
const img = sharp({ create })
.png()
.withIccProfile(fixtures.path('invalid-illuminant.icc'));
let warningEmitted = '';
img.on('warning', (warning) => {
warningEmitted = warning;
});
const data = await img.toBuffer();
assert.strictEqual('Invalid profile', warningEmitted);
const metadata = await sharp(data).metadata();
assert.strictEqual(3, metadata.channels);
assert.strictEqual(undefined, metadata.icc);
});
it('Apply CMYK output ICC profile', function (done) {
const output = fixtures.path('output.icc-cmyk.jpg');
sharp(fixtures.inputJpg)