c++cjpegcolor-profile

JPG - how to read / extract data from ICC profile section APP2


I have a JPG file from which I have extracted ICC color profile section (APP2). However, I dont know, how to extract relevant data from it, like white point, black point, RGB settings etc. I wasnt even able to find section description.

I have found this: https://exiftool.org/ which provides API, but I cannot use this, because it is a wrapper around running background process.


Solution

  • The overall format of an APP2 segment containing an ICC profile is described in Appendix B.4 of the ICC spec:

    The JPEG standard (ISO/IEC 10918-1[2]) supports application specific data segments. These segments may be used for tagging images with ICC profiles. The APP2 marker is used to introduce the ICC profile tag. Given that there are only 15 supported APP markers, there is a chance of many applications using the same marker. ICC tags are thus identified by beginning the data with a special null terminated byte sequence, “ICC_PROFILE”. The length field of a JPEG marker is only two bytes long; the length of the length field is included in the total. Hence, the values 0 and 1 are not legal lengths. This would limit the maximum data length to 65 533. The identification sequence would lower this even further. As it is quite possible for an ICC profile to be longer than this, a mechanism is required to break the profile into chunks and place each chunk in a separate marker. A mechanism to identify each chunk in sequence order is therefore necessary. The identifier sequence is followed by one byte indicating the sequence number of the chunk (counting starts at 1) and one byte indicating the total number of chunks. All chunks in the sequence should indicate the same total number of chunks. The 1-byte chunk count limits the size of embeddable profiles to 16 707 345 bytes.

    So, to get a usable profile, you need to strip off the leading "ICC_PROFILE", the length field, and the sequence number from each chunk, then put all the chunks together in sequence.

    From there, you'll want to look through section 7 of the ICC for details. Some of the data (e.g., the XYZ of the illuminant) are easy to find in the profile header. Others will need to be computed from the data in the profile (which can be quite non-trivial in some cases).

    Reference

    ICC Spec