question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with loading CMYK jpeg as BufferedImage with CMYK color model

See original GitHub issue

Hi!

First off, thanks so much for your work on this library and for your immense help on StackOverflow. It made my life a lot easier!

I am using your JPEGImageReader to load a CMYK JPEG image with an ICC profile. When I read it with the default setup, I get a BufferedImage with an sRGB color model, and its RGB values correspond to what I get in Photoshop. But my CMYK gamut is not a strict subset of sRGB, so I thought I wanted to keep the image in CMYK color space, so that no clipping to sRGB would occur.

In the tests, I found a method that does this: JPEGImageReaderTest.testReadCMYKAsCMYK. But the problem I encountered was that the CMYK BufferedImage generated this way returns different RGB values than the RGB image (using getRGB). If I’m understanding this correctly, it should return the same values – the only difference being whether the conversion ICC CMYK -> sRGB is done during loading or when calling getRGB.

I debugged the code to see what might be the issue, and it seems the problem is this line in JPEGImageReader:

convert = new ColorConvertOp(intendedCS, image.getColorModel().getColorSpace(), null);

the intended CS is the ICC CMYK that’s loaded from the image, but the image’s color space is different from that and as a result, the image is converted from one CMYK to another, but this conversion is redundant (and incorrect, in the end) if I understand it correctly.

Here’s my Scala code that fails with the image I linked above, I can convert it to Java if that’s an issue https://gist.github.com/the21st/7db788d0417dbff63d6c4ba6a80b5dc8

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
haraldkcommented, Nov 3, 2016

@the21st This bugfix is now included in the official 3.3 release.

0reactions
the21stcommented, Jun 29, 2016

Awesome, thank you for such a quick response! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - ImageIO : cannot read image with CMYK color space
Since I have found my image has a CMYK color space, I have found a solution on stackoverflow : Problem reading jpeg image...
Read more >
Reading CMYK JPEG images with Java ImageIO - Randelshofer
The image that you linked is loaded fine by the code that I wrote. The color profile is not interpreted properly, but this...
Read more >
TIFF Metadata Format Specification and Usage Notes
A default CMYK color space if the image has photometric type CMYK and four samples per pixel. Grayscale if the image has one...
Read more >
Scaling and then saving as JPEG: wrong colors | Java
I've googled around and found some references to CMYK color space, but nothing which would indicate a solution to my problem: I'm reading...
Read more >
How does Java handle different Images and ColorSpaces
If you wanted to view a CMYK image as a BufferedImage in Java directly, you would need to convert the Image data into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found