Java error reading non-sRGB JPG files ?

Kenneth Morris Lee

Well-known member
Messages
172
Reaction score
74
Location
MA, US
In Photoshop, I saved a JPG image with 3 different embedded ICC profiles: sRGB, P3 and Adobe RGB. I also saved a copy with no ICC profile.

I then sampled the color values of the same pixel in the 4 images, using the Photoshop Eyedropper tool, the PHP function imagecolorat(), and the Java method getRGB().

JPG with embedded sRGB profile
Photoshop RGB: 84,44,18
PHP RGB: 84,44,18
Java RGB: 84,44,18

JPG with No Profile
Photoshop RGB: 84,44,18
PHP RGB: 84,44,18
Java RGB: 83,44,19

JPG with embedded P3 profile
Photoshop RGB: 78,46,23
PHP RGB: 78,46,23
Java RGB: 83,44,17 (same as sRGB/no profile ?)

JPG with embedded Adobe RGB profile
Photoshop RGB: 76,48,27
PHP RGB: 76,48,27
Java RGB: 83,44,19 (same as sRGB/no profile ?)

Changing the embedded profiles adjusts the colors a bit, which is to be expected I presume.

1) The JPG with no profile, has the same values as the JPG with an sRGB profile. What does that tell us ?

2) While Photoshop and PHP seem to take the ICC profile into consideration (and show adjusted colors), the Java sampling method keeps giving us the values which match the images with no profile/sRGB profile.

According to the Java documentation the getRGB() method "Returns an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space, from a portion of the image data. Color conversion takes place if the default model does not match the image ColorModel."

Does that mean that Java is ignoring the embedded profile, or converting the data to sRGB ?

Thanks for your help :-)
 
Last edited:
It could be useful if you uploaded all three jpegs, and maybe the codes used to sample them.
 
From what I can tell, Photoshop and PHP logic show you pixels after being transformed by the embedded ICC profile - which is what I would want to see if I embedded a profile. I would expect a web browser to do the same thing: apply the profile transformations and show me the resulting values.

Unlike Photoshop and PHP, Java appears to ignore the influence of an embedded ICC profile when reporting a pixel value. Java seems to be simply reporting the non-profiled pixel values - or converting them back to sRGB values - which amounts to the same thing.

The Java code looks like ths:

// Make an image from a file path
BufferedImage image = ImageIO.read(new File(filePath));
// Get the pixel at the specified x,y coordinates
int rgb = image.getRGB(x, y);
// extract r, g, b values
int r = (rgb >> 16) & 0xFF;
int g = (rgb >> 8) & 0xFF;
int b = rgb & 0xFF;

The PHP code looks like this:

// Make an image from a file path
$image = ImageCreateFromJpeg($filePath);
// Get the pixel at the specified x,y coordinates
$rgb = imagecolorat($im, $x, $y);
// extract r, g, b values
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;

Here is a copy of the JPG file which has no ICC profile. In Photoshop you can assign any other profile you like and examine the results with the Eyedropper Tool. I looked repeatedly at pixel (500,500)

76eaf8b31f7348d2b71a771cca5acb4b.jpg

Here's what Photoshop shows when you sample the above image at pixel (500,500)

RGB value = 84,44,14

22f41157e72147a096fc54ee5a2ee0a7.jpg
 
Last edited:
In Photoshop, I saved a JPG image with 3 different embedded ICC profiles: sRGB, P3 and Adobe RGB. I also saved a copy with no ICC profile.

I then sampled the color values of the same pixel in the 4 images, using the Photoshop Eyedropper tool, the PHP function imagecolorat(), and the Java method getRGB().

JPG with embedded sRGB profile
Photoshop RGB: 84,44,18
PHP RGB: 84,44,18
Java RGB: 84,44,18

JPG with No Profile
Photoshop RGB: 84,44,18
PHP RGB: 84,44,18
Java RGB: 83,44,19

JPG with embedded P3 profile
Photoshop RGB: 78,46,23
PHP RGB: 78,46,23
Java RGB: 83,44,17 (same as sRGB/no profile ?)

JPG with embedded Adobe RGB profile
Photoshop RGB: 76,48,27
PHP RGB: 76,48,27
Java RGB: 83,44,19 (same as sRGB/no profile ?)

Changing the embedded profiles adjusts the colors a bit, which is to be expected I presume.
I assume you used Convert to Profile in Photoshop. In this case the RGB values change but the colors stay the same ie convert to the same XYZ values.
1) The JPG with no profile, has the same values as the JPG with an sRGB profile. What does that tell us ?
That the original jpeg was sRGB.
2) While Photoshop and PHP seem to take the ICC profile into consideration (and show adjusted colors), the Java sampling method keeps giving us the values which match the images with no profile/sRGB profile.

According to the Java documentation the getRGB() method "Returns an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space, from a portion of the image data. Color conversion takes place if the default model does not match the image ColorModel."

Does that mean that Java is ignoring the embedded profile, or converting the data to sRGB ?
I'm not familiar with that java script but going on your quote it appears to convert the data to sRGB values.

Dave
Thanks for your help :-)
 

Keyboard shortcuts

Back
Top