JPEG Files – Extracting Color Profile Information

binaryimage manipulationparsing

I'm trying to look up info about reading JPEG's color profile info and to my surprise there's very little open specific how-to information on that regard, but rather lots of general explanation on what it is.

Does anyone know how to find and read the color profile information from JPEG?

Best Answer

Independent JPEG ground - http://www.ijg.org/ is the authority (reference) code for JPEG decoding and JPEG encoding encapsuled as libjpeg; which is also the most portable and default library for JPEG in most platforms.

You should try to dig into libjpeg for this.

Specifically, there is an ambiguity in the native representation of JPEG's color space. As IJG's documentation describes:

The JPEG standard itself is "color blind" and doesn't specify any particular color space. It is customary to convert color data to a luminance/chrominance color space before compressing, since this permits greater compression. The existing de-facto JPEG file format standards specify YCbCr or grayscale data (JFIF), or grayscale, RGB, YCbCr, CMYK, or YCCK (Adobe). For special applications such as multispectral images, other color spaces can be used, but it must be understood that such files will be unportable.

Different applications actually have a different ways to represent this which is actually a problem. See this: http://photo.net/digital-darkroom-forum/00TVcQ

However, it doesn't mean that things are absolutely broken. The information related to color space is usually in the file format, namely JFIF or EXIF.

JFIF

For JFIF (Reference 1: OR Reference 2) - there is a notion of default color space.
From the spec:

Standard color space The color space to be used is YCbCr as defined by CCIR 601 (256 levels). The RGB components calculated by linear conversion from YCbCr shall not be gamma corrected (gamma = 1.0). If only one component is used, that component shall be Y.

The conversion of YCbCr to RGB and vice-versa is also given in the same document. You can also checkout the libjpeg library (IJG) for actual code on this.

EXIF:

In EXIF,

The color space information tag (ColorSpace) is always recorded as the color space specifier. Normally sRGB (=1) is used to define the color space based on the PC monitor conditions and environment. If a color space other than sRGB is used, Uncalibrated (=FFFF.H) is set.

EXIF, allows to specify your custom color table and gamma levels through alternative set of tags including: TransferFunction, white point, PrimaryChromaticities, ReferenceBlackWhite and YCbCrCoefficients.

See. Appendix E, "Color Space Guidelines," Reference: http://www.exif.org/Exif2-1.PDF


See also,

  1. JPEG Files -wikipedia
  2. JFIF, JPEG File Interchange Format, Version 1.02
  3. Embedding ICC profiles in image file formats
Related Topic