mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Ensure conversion to sRGB occurs before background #99
This commit is contained in:
parent
c2fcf7fc4a
commit
6190ca4307
29
src/sharp.cc
29
src/sharp.cc
@ -511,8 +511,9 @@ class ResizeWorker : public NanAsyncWorker {
|
|||||||
image = shrunk_on_load;
|
image = shrunk_on_load;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import embedded colour profile, if present
|
// Handle colour profile, if any, for non sRGB images
|
||||||
if (vips_image_get_typeof(image, VIPS_META_ICC_NAME)) {
|
if (image->Type != VIPS_INTERPRETATION_sRGB && vips_image_get_typeof(image, VIPS_META_ICC_NAME)) {
|
||||||
|
// Import embedded profile
|
||||||
VipsImage *profile = vips_image_new();
|
VipsImage *profile = vips_image_new();
|
||||||
vips_object_local(hook, profile);
|
vips_object_local(hook, profile);
|
||||||
if (vips_icc_import(image, &profile, NULL, "embedded", TRUE, "pcs", VIPS_PCS_XYZ, NULL)) {
|
if (vips_icc_import(image, &profile, NULL, "embedded", TRUE, "pcs", VIPS_PCS_XYZ, NULL)) {
|
||||||
@ -520,6 +521,14 @@ class ResizeWorker : public NanAsyncWorker {
|
|||||||
}
|
}
|
||||||
g_object_unref(image);
|
g_object_unref(image);
|
||||||
image = profile;
|
image = profile;
|
||||||
|
// Convert to sRGB colour space
|
||||||
|
VipsImage *colourspaced = vips_image_new();
|
||||||
|
vips_object_local(hook, colourspaced);
|
||||||
|
if (vips_colourspace(profile, &colourspaced, VIPS_INTERPRETATION_sRGB, NULL)) {
|
||||||
|
return resize_error(baton, hook);
|
||||||
|
}
|
||||||
|
g_object_unref(image);
|
||||||
|
image = colourspaced;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flatten image to remove alpha channel
|
// Flatten image to remove alpha channel
|
||||||
@ -710,14 +719,16 @@ class ResizeWorker : public NanAsyncWorker {
|
|||||||
image = gamma_decoded;
|
image = gamma_decoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always convert to sRGB colour space
|
// Convert to sRGB colour space, if not already
|
||||||
VipsImage *colourspaced = vips_image_new();
|
if (image->Type != VIPS_INTERPRETATION_sRGB) {
|
||||||
vips_object_local(hook, colourspaced);
|
VipsImage *colourspaced = vips_image_new();
|
||||||
if (vips_colourspace(image, &colourspaced, VIPS_INTERPRETATION_sRGB, NULL)) {
|
vips_object_local(hook, colourspaced);
|
||||||
return resize_error(baton, hook);
|
if (vips_colourspace(image, &colourspaced, VIPS_INTERPRETATION_sRGB, NULL)) {
|
||||||
|
return resize_error(baton, hook);
|
||||||
|
}
|
||||||
|
g_object_unref(image);
|
||||||
|
image = colourspaced;
|
||||||
}
|
}
|
||||||
g_object_unref(image);
|
|
||||||
image = colourspaced;
|
|
||||||
|
|
||||||
// Generate image tile cache when interlace output is required
|
// Generate image tile cache when interlace output is required
|
||||||
if (baton->progressive) {
|
if (baton->progressive) {
|
||||||
|
@ -327,6 +327,16 @@ async.series([
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
// Check colour space conversion from CMYK to sRGB works with background colour (yellow=fail)
|
||||||
|
function(done) {
|
||||||
|
sharp(inputJpgWithCmykProfile).resize(320, 240).background('white').embed().toFile(path.join(fixturesPath, 'output.cmyk2srgb.jpg'), function(err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(320, info.width);
|
||||||
|
assert.strictEqual(240, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
},
|
||||||
// Interpolation: nearest neighbour
|
// Interpolation: nearest neighbour
|
||||||
function(done) {
|
function(done) {
|
||||||
sharp(inputJpg).resize(320, 240).interpolateWith(sharp.interpolator.nearest).toBuffer(function(err, data, info) {
|
sharp(inputJpg).resize(320, 240).interpolateWith(sharp.interpolator.nearest).toBuffer(function(err, data, info) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user