Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color profile detection in JPEG

Tags:

I would like to be able to detect the presence of a color profile in JPEG. To be clear: I'm not interested in actually carrying out the color corrections or doing anything else with them.

I did some investigation, but I could not find any definite source of information. Here is what I know so far:

  • There is a color profile information in the XMP block. The XMP block is in a 0xFFE1 JPEG section (the same as EXIF). The marked of this section is followed by the http://ns.adobe.com/xap/1.0/ string. However, when I stripped this section, Photoshop was still able to detect the color profile.

  • There is a color space tag in EXIF itself as well (tag = 0xA001). It has only one value defined in the EXIF specification: 1 = sRGB. I noticed that in my image it takes the value 0xFFFF which means uncalibrated. So it’s not this tag.

  • I did an experiment with one image saving it in two different color profiles, and besides the changes in XMP and EXIF, I noticed that there is probably a whole new JPEG section. It starts by 0xFFE2 and its marker is followed by the string ICC_PROFILE. This seems to be the most likely case.

Does anybody have experience with managing color profiles in JPEG? I would say that the information in EXIF and XMP are just metadata, and that the important thing is the presence of the ICC_PROFILE section.

like image 458
Jan Zich Avatar asked Sep 22 '09 10:09

Jan Zich


2 Answers

ICC profiles are stored in a JPEG file's Application Segments. These blocks are for letting applications store whatever data they need, so they are not mandated by the JPEG spec. In other words, the JPEG file format does not define a way to embed color profiles, you are just seeing the de facto ways of doing it.

Since the application segments can be used by anyone for anything, you need to identify and validate the contents, before you can say for certain that it contains an ICC profile.

So there are three ways common ways ICC profiles could be supplied:

  • By embedding an ICC profile in Application Segment 02, prepended with ICC_PROFILE\0x00\0x01\0x01 for identifying it. I'm currently unsure if the two \0x01 mean anything, or if they are always that. After those 14 characters, the actual ICC profile is stored.
  • By embedding an ICC profile in an embedded EXIF metadata file in Application Segment 01.
  • By embedding an ICC profile in an embedded XAM metadata file in Application Segment 01. This is prepended with http://ns.adobe.com/xap/1.0/\0x00.

I have not been able to find any concrete information either. It would be nice if ICC said, "this is how to do it", but I have not yet been able to find any of the sort. Thus as far as I know, any of these could potentially be used as an ICC profile and it would depend on the application on whether it would load the profile or not. Application Segment 02 seems to be the common way of doing it, though what you want to check might depend on your use case. As the other comment showed, some HELIOS EtherShare software has/had its own way of doing it. (I have not yet confirmed the presence of an ICC profile in the metadata, however I haven't really looked that hard and it wouldn't surprise me if you could find files with multiple conflicting ICC profiles in the wild.)

like image 107
Sebastian Wahl Avatar answered Sep 30 '22 08:09

Sebastian Wahl


Here is an information about ICC profiles in JPEG: http://209.85.129.132/search?q=cache%3ANx_M6GRbZzYJ%3Awww.helios.de%2FPDFs%2FICC-tag.pdf+JPEG+format+ICC+offset&hl=ru&gl=ru

That's from Google cache.

like image 26
Vladislav Rastrusny Avatar answered Sep 30 '22 07:09

Vladislav Rastrusny