From a56102a2090bb6dbcc5d9912601bcccc31b02e07 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Thu, 4 Dec 2014 11:28:09 +0000 Subject: [PATCH] Ensure ICC transform of withMetadata output #133 --- README.md | 2 +- src/resize.cc | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1d7a56da..05b1543f 100755 --- a/README.md +++ b/README.md @@ -403,7 +403,7 @@ Use progressive (interlace) scan for JPEG and PNG output. This typically reduces #### withMetadata() -Include all metadata (ICC, EXIF, XMP) from the input image in the output image. +Include all metadata (EXIF, XMP, IPTC) from the input image in the output image. This will also convert to and add the latest web-friendly v2 sRGB ICC profile. The default behaviour is to strip all metadata and convert to the device-independent sRGB colour space. diff --git a/src/resize.cc b/src/resize.cc index 1596fe17..58d0a995 100755 --- a/src/resize.cc +++ b/src/resize.cc @@ -115,6 +115,9 @@ class ResizeWorker : public NanAsyncWorker { // Increment processing task counter g_atomic_int_inc(&counterProcess); + // Latest v2 sRGB ICC profile + std::string srgbProfile = baton->iccProfilePath + "sRGB_IEC61966-2-1_black_scaled.icc"; + // Hang image references from this hook object VipsObject *hook = reinterpret_cast(vips_image_new()); @@ -272,7 +275,6 @@ class ResizeWorker : public NanAsyncWorker { // Ensure we're using a device-independent colour space if (HasProfile(image)) { // Convert to sRGB using embedded profile - std::string srgbProfile = baton->iccProfilePath + "sRGB_IEC61966-2-1_black_scaled.icc"; VipsImage *transformed; if (!vips_icc_transform(image, &transformed, srgbProfile.c_str(), "embedded", TRUE, NULL)) { // Embedded profile can fail, so only update references on success @@ -281,7 +283,6 @@ class ResizeWorker : public NanAsyncWorker { } } else if (image->Type == VIPS_INTERPRETATION_CMYK) { // Convert to sRGB using default "USWebCoatedSWOP" CMYK profile - std::string srgbProfile = baton->iccProfilePath + "sRGB_IEC61966-2-1_black_scaled.icc"; std::string cmykProfile = baton->iccProfilePath + "USWebCoatedSWOP.icc"; VipsImage *transformed; if (vips_icc_transform(image, &transformed, srgbProfile.c_str(), "input_profile", cmykProfile.c_str(), NULL)) { @@ -576,7 +577,7 @@ class ResizeWorker : public NanAsyncWorker { VipsImage *rgb; if (baton->withMetadata && HasProfile(image)) { // Convert to device-dependent RGB using embedded profile of input - if (vips_icc_export(image, &rgb, NULL)) { + if (vips_icc_transform(image, &rgb, srgbProfile.c_str(), "embedded", TRUE, NULL)) { return Error(baton, hook); } } else {