Unable to embed ICC profile in JPEG
See original GitHub issueThe context is the following: I’m trying to achieve the following:
- read an image and its icc profile (not converting the image to the icc profile, just reading the two)
- write the image and its original icc profile (again, no conversion)
I first thought this would be a triviality but I’ve had no success so far. My current code is in this file, using this image which has an Adobe RGB (1998)
color profile. The code can be summarized as follows:
public static void readAndWriteTwelveMonkeys(ImageInputStream iis) {
ImageReader r = ...; // the twelvemonkeys one
r.setInput(iis);
IIOMetadata meta = r.getImageMetadata(0);
// if I print the image metadata, I see that the color profile is correct (AdobeRGB)
ImageTypeSpecifier its = r.getRawImageType(0);
ImageReadParam p = r.getDefaultReadParam();
p.setDestinationType(its);
// color space is RGB (not sRGB), not sure if it's relevant
System.out.println("is ColorSpace RGB? "+(its.getColorModel().getColorSpace().getType() == ColorSpace.TYPE_RGB));
BufferedImage bi = r.read(0, p);
Iterator<ImageWriter> itw2 = ImageIO.getImageWriters(new ImageTypeSpecifier(bi), "jpeg");
ImageWriter iw2 = itw2.next();
if (iw2 == null) {
System.out.println("no writer for the image type of the buffered image");
} else {
ImageWriteParam wp = iw2.getDefaultWriteParam();
wp.setDestinationType(its);
ImageOutputStream out = ImageIO.createImageOutputStream(new File("test-regularjpg.jpg"));
iw2.setOutput(out);
iw2.write(null, new IIOImage(bi, null, meta), wp);
}
is.close();
iis.close();
}
which works but the output doesn’t have the original icc profile embedded; even more strange it embeds an sRGB profile.
Is it generally possible to achieve what I want: with ImageIO
in general (I’m starting to doubt it)? with TwelveMonkeys?
java -version
says
openjdk version "11.0.5" 2019-10-15
Edit: I initially reported a silly configuration error, sorry
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Solved: The embedded ICC profile cannot be used because th...
A fix that worked for me on a PC was just go into the Color Management System using the search bar. Make sure...
Read more >How can I embed an ICC color profile in a JPEG file?
Step 3. Locate the ICC color profiles on your hard disk. The file names of some of the most common profiles are sRGB...
Read more >JPG embedded ICC profile causing problems #521 - GitHub
It appears to be trying to use the embedded CMYK ICC profile but failing, the image itself is marked as sRGB. I did...
Read more >Embedded ICC profile is invalid in converted JPEG
I open converted.jpg in Photoshop, and as it comes up, I get a message box stating "The embedded ICC profile cannot be used...
Read more >Please provide ability to embed color profiles when exporting ...
A possible solution consists in embedding a color profile in the Illustrator-generated PNG using software that has that capability.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
it looks fixed indeed, thanks a lot!
Hi,
I think I might have “accidentally” fixed this is #573 (TwelveMonkeys 3.7.0), as we now always return non-null from
getRawImageType
. The raw type will use the color space created from the ICC profile (given that it is compatible with the image data), and the same type is available ingetImageTypes
as well.If you find the time, please test the new functionality, and see if that works for you. If not, you may re-open the issue with your new findings. 😀
Closing for now.
Best regards,
– Harald K