diff --git a/src/sharp.cc b/src/sharp.cc index e88b15d3..60a98719 100755 --- a/src/sharp.cc +++ b/src/sharp.cc @@ -511,6 +511,17 @@ class ResizeWorker : public NanAsyncWorker { image = shrunk_on_load; } + // Import embedded colour profile, if present + if (vips_image_get_typeof(image, VIPS_META_ICC_NAME)) { + VipsImage *profile = vips_image_new(); + vips_object_local(hook, profile); + if (vips_icc_import(image, &profile, NULL, "embedded", TRUE, "pcs", VIPS_PCS_XYZ, NULL)) { + return resize_error(baton, hook); + } + g_object_unref(image); + image = profile; + } + // Flatten image to remove alpha channel if (baton->flatten && sharp_image_has_alpha(image)) { // Background colour diff --git a/tests/fixtures/Channel_digital_image_CMYK_color.jpg b/tests/fixtures/Channel_digital_image_CMYK_color.jpg new file mode 100644 index 00000000..a489c0df Binary files /dev/null and b/tests/fixtures/Channel_digital_image_CMYK_color.jpg differ diff --git a/tests/unit.js b/tests/unit.js index caabe4de..ba1a988c 100755 --- a/tests/unit.js +++ b/tests/unit.js @@ -13,6 +13,7 @@ var fixturesPath = path.join(__dirname, 'fixtures'); var inputJpg = path.join(fixturesPath, '2569067123_aca715a2ee_o.jpg'); // http://www.flickr.com/photos/grizdave/2569067123/ var inputJpgWithExif = path.join(fixturesPath, 'Landscape_8.jpg'); // https://github.com/recurser/exif-orientation-examples/blob/master/Landscape_8.jpg var inputJpgWithGammaHoliness = path.join(fixturesPath, 'gamma_dalai_lama_gray.jpg'); // http://www.4p8.com/eric.brasseur/gamma.html +var inputJpgWithCmykProfile = path.join(fixturesPath, 'Channel_digital_image_CMYK_color.jpg'); // http://en.wikipedia.org/wiki/File:Channel_digital_image_CMYK_color.jpg var inputPng = path.join(fixturesPath, '50020484-00001.png'); // http://c.searspartsdirect.com/lis_png/PLDM/50020484-00001.png var inputPngWithTransparency = path.join(fixturesPath, 'blackbug.png'); // public domain @@ -316,6 +317,16 @@ async.series([ done(); }); }, + // Check colour space conversion from CMYK to sRGB + function(done) { + sharp(inputJpgWithCmykProfile).resize(320).toBuffer(function(err, data, info) { + if (err) throw err; + assert.strictEqual(true, data.length > 0); + assert.strictEqual('jpeg', info.format); + assert.strictEqual(320, info.width); + done(); + }); + }, // Interpolation: nearest neighbour function(done) { sharp(inputJpg).resize(320, 240).interpolateWith(sharp.interpolator.nearest).toBuffer(function(err, data, info) {