I have multiple images with a custom profile embedded in them and want to convert the image to sRGB in order to serve it up to a browser. I have seen code like the following:
BufferedImage image = ImageIO.read(fileIn);
ColorSpace ics = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorConvertOp cco = new ColorConvertOp(ics, null);
BufferedImage result = cco.filter(image, null);
ImageIO.write(result, "PNG", fileOut);
where fileIn and fileOut are File objects representing the input file and output file respectively. This works to an extent. The problem is that the resulting image is lighter than the original. If I was to convert the color space in photoshop the colors would appear the same. In fact if I pull up both images with photoshop and take a screen shot and sample the colors, they are the same. What is photoshop doing that the code above isn't and what can I do to correct the problem?
There are various types of images being converted, including JPEG, PNG, and TIFF. I have tried using TwelveMonkeys to read in JPEG and TIFF images and I still get the same effect, where the image is too light. The conversion process seems worst when applied to an image that didn't have an embedded profile in the first place.
Edit:
I've added some sample images, the first of which has the color profile embedded in it and the second was converted using the code I showed above. Note that the second looks much lighter than the original. There are two things going on.
- The image on the left is actually lighter than it shows up in Chrome but Chrome ignores the color profile so it looks darker than it should, which is my original problem. If it's viewed in Safari the difference between images isn't as great because Safari loads the profile correctly.
- The conversion makes the image look lighter.
Again, I want to iterate that when Photoshop converts the color space it looks the same after the conversion. (Note: to get a larger image, remove the 't' from the end of the image link.)
As others have suggested I tried using image magick and I get two error messages when attempting to convert the image,
convert: iCCP: profile 'Photoshop ICC profile': 0h: PCS illuminant is not D50 'tiger.png' @ warning/png.c/MagickPNGWarningHandler/1656.
convert: delegate library support not built-in 'tiger.png' (LCMS) @ warning/profile.c/ProfileImage/853.`
I used convert tiger.png -profile "~/Desktop/sRGB_IEC61966-2-1_black_scaled.icc" tiger2.jpg.
Aucun commentaire:
Enregistrer un commentaire