-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
keepIccProfile doesn't retain profile on cmyk image #3906
Comments
Have you tried setting the pipeline colourspace to ensure the image remains in CMYK throughout? .pipelineColourspace('cmyk') https://sharp.pixelplumbing.com/api-colour#pipelinecolourspace |
Yes, tried several combinations both with |
When using the // test code
const sharp = require("sharp");
(async () => {
console.log('origin metadata', await sharp("./cmyk.jpg").metadata());
console.log('new metadata use toColorspace', await sharp(await sharp("./cmyk.jpg").toColorspace("cmyk").keepMetadata().toBuffer()).metadata());
console.log('new metadata use pipelineColorspace', await sharp(await sharp("./cmyk.jpg").pipelineColorspace("cmyk").keepMetadata().toBuffer()).metadata());
})();
``
```js
origin metadata {
format: 'jpeg',
width: 500,
height: 333,
space: 'cmyk',
channels: 4,
depth: 'uchar',
density: 180,
chromaSubsampling: '4:4:4:4',
isProgressive: false,
resolutionUnit: 'inch',
hasProfile: true,
hasAlpha: false,
orientation: 1,
exif: <Buffer 45 78 69 66 00 00 49 49 2a 00 08 00 00 00 0a 00 0f 01 02 00 06 00 00 00 86 00 00 00 10 01 02 00 17 00 00 00 8c 00 00 00 12 01 03 00 01 00 00 00 01 00 ... 9492 more bytes>,
icc: <Buffer 00 08 80 70 41 44 42 45 02 10 00 00 70 72 74 72 43 4d 59 4b 4c 61 62 20 07 d0 00 07 00 1a 00 05 00 29 00 35 61 63 73 70 41 50 50 4c 00 00 00 00 41 44 ... 557118 more bytes>,
iptc: <Buffer 50 68 6f 74 6f 73 68 6f 70 20 33 2e 30 00 38 42 49 4d 04 25 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 42 49 4d 03 ed 00 00 ... 9948 more bytes>,
xmp: <Buffer 3c 3f 78 70 61 63 6b 65 74 20 62 65 67 69 6e 3d 22 ef bb bf 22 20 69 64 3d 22 57 35 4d 30 4d 70 43 65 68 69 48 7a 72 65 53 7a 4e 54 63 7a 6b 63 39 64 ... 16899 more bytes>
}
new metadata use toColorspace {
format: 'jpeg',
size: 93328,
width: 500,
height: 333,
space: 'srgb',
channels: 3,
depth: 'uchar',
density: 180,
chromaSubsampling: '4:2:0',
isProgressive: false,
resolutionUnit: 'inch',
hasProfile: false,
hasAlpha: false,
orientation: 1,
exif: <Buffer 45 78 69 66 00 00 49 49 2a 00 08 00 00 00 0a 00 0f 01 02 00 06 00 00 00 86 00 00 00 10 01 02 00 17 00 00 00 8c 00 00 00 12 01 03 00 01 00 00 00 01 00 ... 9490 more bytes>,
iptc: <Buffer 50 68 6f 74 6f 73 68 6f 70 20 33 2e 30 00 38 42 49 4d 04 25 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 42 49 4d 03 ed 00 00 ... 9948 more bytes>,
xmp: <Buffer 3c 3f 78 70 61 63 6b 65 74 20 62 65 67 69 6e 3d 22 ef bb bf 22 20 69 64 3d 22 57 35 4d 30 4d 70 43 65 68 69 48 7a 72 65 53 7a 4e 54 63 7a 6b 63 39 64 ... 16899 more bytes>
}
new metadata use pipelineColorspace {
format: 'jpeg',
size: 92010,
width: 500,
height: 333,
space: 'srgb',
channels: 3,
depth: 'uchar',
density: 180,
chromaSubsampling: '4:2:0',
isProgressive: false,
resolutionUnit: 'inch',
hasProfile: false,
hasAlpha: false,
orientation: 1,
exif: <Buffer 45 78 69 66 00 00 49 49 2a 00 08 00 00 00 0a 00 0f 01 02 00 06 00 00 00 86 00 00 00 10 01 02 00 17 00 00 00 8c 00 00 00 12 01 03 00 01 00 00 00 01 00 ... 9490 more bytes>,
iptc: <Buffer 50 68 6f 74 6f 73 68 6f 70 20 33 2e 30 00 38 42 49 4d 04 25 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 42 49 4d 03 ed 00 00 ... 9948 more bytes>,
xmp: <Buffer 3c 3f 78 70 61 63 6b 65 74 20 62 65 67 69 6e 3d 22 ef bb bf 22 20 69 64 3d 22 57 35 4d 30 4d 70 43 65 68 69 48 7a 72 65 53 7a 4e 54 63 7a 6b 63 39 64 ... 16899 more bytes>
} the |
Do we have any update on this. I am also facing kind of similiar issue. Where we have an image which is cmyk and when I am trying to process it using sharp it is changing the color space. And my image is not having the icc profile in it. |
The test keep existing ICC profile seems to test for a Confirmed that the current implementation of it('keep existing CMYK ICC profile', async () => {
const data = await sharp(fixtures.inputJpgWithCmykProfile)
.keepIccProfile()
.toBuffer();
const metadata = await sharp(data).metadata();
const { description } = icc.parse(metadata.icc);
assert.strictEqual(description, 'U.S. Web Coated (SWOP) v2');
}); Taking a look at the pipeline, it seems this fails because it converts to Lines 330 to 352 in 26d0b71
Updating that code to the following fixes the issue: // Convert to sRGB/P3 using embedded profile
try {
if ((baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) && baton->withIccProfile.empty()) {
// New implementation
if (image.interpretation() == VIPS_INTERPRETATION_CMYK) {
baton->colourspace = VIPS_INTERPRETATION_CMYK;
}
image = image.icc_transform(inputProfile.first, VImage::option()
->set("input_profile", inputProfile.first)
->set("embedded", TRUE)
->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
->set("intent", VIPS_INTENT_PERCEPTUAL));
} else {
// Current implementation
image = image.icc_transform(processingProfile, VImage::option()
->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 embedded profile", nullptr);
} @lovell All tests, including the new one for preserving a CMYK profile, pass successfully. I am uncertain if this adjustment is located in the most suitable part of the codebase though, as I have a limited understanding of C and the specific workings of ICC tranformations in the pipeline. I'm willing to work on a preliminary PR if that helps facilitate a more detailed review and discussion on how best to integrate these changes. |
The change in commit fb70fbb prevents the erroneous sRGB transformation when using CMYK everywhere, plus adds a slightly-modified version of @adriaanmeuris' example test case to help prevent regression. Thanks all for reporting and helping analyse this issue. |
@lovell thank you so much for the recent update; I noticed that the profile is correcly attached now. However, it seems this icc transform to Lines 330 to 344 in 60f4048
Which results in a color shift. Commenting out the Adding this condition to the image.interpretation() != VIPS_INTERPRETATION_CMYK && Additionally, I found that to maintain the color profile, it's essential to use I'm happy to help out or provide additional information if needed. |
@adriaanmeuris Are you able to test to see if the following patch fixes the problem you're seeing? --- a/src/pipeline.cc
+++ b/src/pipeline.cc
@@ -331,6 +331,7 @@ class PipelineWorker : public Napi::AsyncWorker {
sharp::HasProfile(image) &&
image.interpretation() != VIPS_INTERPRETATION_LABS &&
image.interpretation() != VIPS_INTERPRETATION_GREY16 &&
+ baton->colourspaceInput != VIPS_INTERPRETATION_CMYK &&
!baton->input->ignoreIcc
) {
// Convert to sRGB/P3 using embedded profile (I need to refactor some of the variable naming in here as |
@lovell Yes, the patch works as expected. The profile is attached, and the output colors now align with the input colors. Looks great! |
@adriaanmeuris Great, thanks for confirming, added via commit 3eeaee7 |
v0.33.3 now available, thanks everyone for your help fixing/testing this. |
Possible bug
Is this a possible bug in a feature of sharp, unrelated to installation?
npm install sharp
completes without error.node -e "require('sharp')"
completes without error.If you cannot confirm both of these, please open an installation issue instead.
Are you using the latest version of sharp?
sharp
as reported bynpm view sharp dist-tags.latest
.If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.
If you are using another package which depends on a version of
sharp
that is not the latest, please open an issue against that package instead.What is the output of running
npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp
?What are the steps to reproduce?
Load an cmyk image with embedded icc profile. Try to do anything with it using
keepIccProfile
and no profile is in the output.What I'm actually want to achieve is to resize an image with cmyk where output is cmyk and icc profile is retained.
What is the expected behaviour?
That it retains the icc profile and output color space is cmyk.
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
Please provide sample image(s) that help explain this problem
https://upload.wikimedia.org/wikipedia/en/2/25/Channel_digital_image_CMYK_color.jpg
The text was updated successfully, but these errors were encountered: