Add ignoreIcc input option to ignore embedded ICC profile

This commit is contained in:
Lovell Fuller
2023-02-12 17:51:24 +00:00
parent a2988c9edc
commit 42d2f07e44
8 changed files with 54 additions and 5 deletions

View File

@@ -103,6 +103,10 @@ namespace sharp {
if (HasAttr(input, "density")) {
descriptor->density = AttrAsDouble(input, "density");
}
// Should we ignore any embedded ICC profile
if (HasAttr(input, "ignoreIcc")) {
descriptor->ignoreIcc = AttrAsBool(input, "ignoreIcc");
}
// Raw pixel input
if (HasAttr(input, "rawChannels")) {
descriptor->rawDepth = AttrAsEnum<VipsBandFormat>(input, "rawDepth", VIPS_TYPE_BAND_FORMAT);

View File

@@ -55,6 +55,7 @@ namespace sharp {
size_t bufferLength;
bool isBuffer;
double density;
bool ignoreIcc;
VipsBandFormat rawDepth;
int rawChannels;
int rawWidth;
@@ -93,6 +94,7 @@ namespace sharp {
bufferLength(0),
isBuffer(FALSE),
density(72.0),
ignoreIcc(FALSE),
rawDepth(VIPS_FORMAT_UCHAR),
rawChannels(0),
rawWidth(0),

View File

@@ -320,7 +320,8 @@ class PipelineWorker : public Napi::AsyncWorker {
if (
sharp::HasProfile(image) &&
image.interpretation() != VIPS_INTERPRETATION_LABS &&
image.interpretation() != VIPS_INTERPRETATION_GREY16
image.interpretation() != VIPS_INTERPRETATION_GREY16 &&
!baton->input->ignoreIcc
) {
// Convert to sRGB/P3 using embedded profile
try {
@@ -329,7 +330,7 @@ class PipelineWorker : public Napi::AsyncWorker {
->set("depth", image.interpretation() == VIPS_INTERPRETATION_RGB16 ? 16 : 8)
->set("intent", VIPS_INTENT_PERCEPTUAL));
} catch(...) {
// Ignore failure of embedded profile
sharp::VipsWarningCallback(nullptr, G_LOG_LEVEL_WARNING, "Invalid embedded profile", nullptr);
}
} else if (image.interpretation() == VIPS_INTERPRETATION_CMYK) {
image = image.icc_transform(processingProfile, VImage::option()