JFIF colorspace - working practice

Discussion in 'Digital Photography' started by Thomas Richter, Jul 16, 2009.

  1. Hi folks,

    what is the working practice how to interpret the colorspaces in JFIF
    (aka "JPEG") files? I'm specifically interested in the case where no
    other colorspace information is available in the file.

    Details:

    JFIF specifies to use the CCITT (now ITU) 601 transformation, you find
    the formulas in the JFIF document. However, this is not the complete
    story, unlike what most people might think. Rec. 601 *also* defines
    primaries for red, green and blue, and gamma values (note that wikipedia
    is incorrect here, 601 *is* an absolute color space defining such data).
    These values are *different* from the ones specified by sRGB,
    unfortunately, which is a colorspace typical for computer monitors; Rec.
    601 is typical for TVs.

    My question is now, what do existing applications do if they want to
    render a JFIF file on a computer screen in the absence of any other
    color information in the file. Do they perform (in addition to the YCbCr
    to RGB decorrelation) a conversion from 601 to sRGB? Or do they just
    render the data "as if" it would be sRGB already, hoping to get away
    with that?

    Specifically, if you do have a monitor profile and render JFIF to such
    monitor, it would be required to first run the YCbCr->RGB transformation
    (done in all implementations), then convert Rec.601 RGB to the monitor RGB.

    Alternatively, applications might assume that the color space JFIF
    renders to is sRGB directly, then doing a sRGB->monitor RGB conversion
    (a different one).

    For example, the IJG command line tool "djpeg" creates PPM files from
    ..jpg (JFIF) files by doing the YCbCr -> RGB transformation, nothing
    else. As PPM files are in sRGB, the output is "incorrectly" in sRGB, and
    not in Rec. 601 RGB. Is that common practice, or is IJG simply ignorant
    of color spaces and more professional applications rather assume
    Rec.601 RGB instead.

    (601 RGB = an RGB color space using the primaries as defined in the
    recommendation, with gamma values as defined there. The YCbCr
    transformation is irrelevant for this.)

    Thanks for opinions,

    Thomas
     
    Thomas Richter, Jul 16, 2009
    #1
    1. Advertisements

  2. Photoshop handles JPEG compression for RGB images as follows:

    1. The image compression is executed merely based on RGB numbers.
    2. An ICC profile can be embedded.
    3. Opening a JPEG with missing profile, or with a profile different to
    the
    actual working space, the operator can assign a profile.
    4. The image is shown via the actual monitor profile (if the color
    settings
    are correct).

    JPEG compression for the Web follows these rules:
    1. Convert to sRGB.
    2. Apply JPEG compression without embedding a profile.
    Here it is assumed that the receiver views through a browser
    and the monitor is either calibrated (near to sRGB) or uncalibrated
    (bad luck).

    JPEG compression for prepress:
    The highest quality delivers typically a compression ratio of only 3
    and the image appearance is almost identical with the original.
    The color space is typically AdobeRGB (aRGB) and the profile is
    embedded.
    JPEG for prepress is normally not recommended, because not
    everybody is aware of the damage for lower quality settings.

    A critical test:
    1. Convert an aRGB or sRGB image to ProPhotoRGB (pRGB).
    2. Save as JPEG without profile (or with profile).
    3. Open the JPEG and assign pRGB (or let Photoshop 'honour'
    the embedded profile).
    4. The color appearance is that of the original image.

    IMO a browser without color management sends the RGB numbers
    directly to the graphics card. If the monitor is calibrated near to
    sRGB,
    then an sRGB JPEG would deliver reasonable results (but that's not
    accurate, because the monitor profile, which can be (slightly)
    different
    to sRGB, is not used).

    During my own JPEG programming and that of a student, we didn't
    encounter anywhere a compulsory color space definition. But that's
    long ago:
    http://www.fho-emden.de/~hoffmann/jpeg131200.pdf

    Best regards --Gernot Hoffmann
     
    Gernot Hoffmann, Jul 16, 2009
    #2
    1. Advertisements

  3. I would be really surprised if there was a "typical" for TV sets
    that was significantly different from that for computer monitors.

    Given that Plasma, LED, LCD, and CRT are likely significantly
    different due to differences in phosphors, filters, and the
    appropriate semiconductor materials, and that it isn't likely
    that the factories keep each of those completely separate for
    the two product lines.

    -- glen
     
    glen herrmannsfeldt, Jul 16, 2009
    #3
  4. Thomas Richter

    Bob Larter Guest

    Either "as is", or it's assumed to be sRGB, depending on the viewing
    program.
     
    Bob Larter, Jul 17, 2009
    #4
  5. It is different (Rec. 601 vs. RGB) in both the primaries and the gamma
    (2.2 vs. 2.4). Depending on your purposes, this might be significant or not.
    No, not the plasma and the phosphors, but the electronics is probably
    calibrated in a different way, or runs the color transformation
    differently depending on the input. Who knows - I don't. All I'm telling
    is that the two are, indeed, surprisingly, not the same.

    So long,
    Thomas
     
    Thomas Richter, Jul 17, 2009
    #5
  6. ---> It doesn't spam Usenet.

    jue
     
    Jürgen Exner, Jul 17, 2009
    #6
  7. Thomas Richter

    Ray Fischer Guest

    Top 10 reasons why Beer is better than Religion...

    10. No one will kill you for not drinking Beer.

    9. Beer doesn't tell you how to have sex.

    8. Beer has never caused a major war.

    7. They don't force Beer on minors who can't think for themselves.

    6. When you have a Beer, you don't knock on people's doors trying to
    give it away.

    5. Nobody's ever been burned at the stake, hanged, or tortured over
    his brand of Beer.

    4. You don't have to wait 2000+ years for a second Beer.

    3. There are laws saying Beer labels can't lie to you.

    2. You can prove you have a Beer.

    1. If you've devoted your life to Beer, there are groups to help you
    stop.
     
    Ray Fischer, Jul 18, 2009
    #7
  8. Thomas Richter

    Ross Ridge Guest

    JFIF 1.02 says:

    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).

    So raw decoded JFIF RGB output values aren't supposed to be in either
    sRGB or Rec. 601 RGB.
    I believe djpeg predates PPM files being defined as using the CIE Rec. 709
    colour space and just outputs files in the linear PPM variant.

    In practice I expect most applications don't do any colour space
    conversions before displaying JFIF images.

    Ross Ridge
     
    Ross Ridge, Jul 25, 2009
    #8
  9. How do you read this into the above statement? The first sentence
    explicitly states that the color space *is* CCIR (now ITU) 601.

    Unfortunately - or fortunately - this is not how JFIF is used. The
    confusion created by JFIF is that they use YCbCr as *decorrelation*
    transformation to minimize the energy in chroma, but not Rec. 601 as a
    color space, which is what is stated.

    I'm now even more confused, please explain.
    It uses a linear transformation, but the output color space doesn't have
    a linear gamma, i.e. gamma correction is done by the monitor as usual.
    That's what I would believe as well, but then JFIF should probably
    specify that

    a) the YCbCr to RGB transformation applies to the raw sample values as
    "decorrelation transformation",
    b) the output color space of this transformation is sRGB.

    This is not what it says, unfortunately.

    Greetings,
    Thomas
     
    Thomas Richter, Jul 25, 2009
    #9
  10. what is the working practice how to interpret the colorspaces in JFIF
    They are sent unchanged to the video card. ATI cards have linear gamma
    as the default setting.
     
    Mihai Cartoaje, Jul 25, 2009
    #10
  11. Thomas Richter

    Ross Ridge Guest

    Remember that the JFIF document was written before sRGB existed, so that's
    not a reasonable expectation. I beleive the intent of the document was
    to specify that a) the YCbCr to RGB transform is done using the equations
    given, b) the resulting output color space is linear RGB (gamma = 1.0).
    That seems to be the common interpretation, and I think specifying any
    other RGB color space would've been fairly radical at the time.

    Applications should've done gamma correction (from whatever output
    colour space JFIF actually specified) before displaying JFIF images,
    but apparently many didn't think it was worth the trouble. Back when
    the World Wide Web was young and 256 colour graphics looked impressive,
    maybe it wasn't. In any case the trick now is to encode JPEG images as if
    sRGB was specified, knowing that outside of a professional setting that's
    most likely way to get the image to display as intended. Accordingly
    applications that display JPEG images that don't have some other extension
    specifying the colour space should follow existing practices and display
    the RGB values as is. In this respect JFIF is a broken standard, so it
    really doesn't matter it actually says or was intended to say.

    Ross Ridge
     
    Ross Ridge, Jul 27, 2009
    #11
  12. I wrote a program to measure the gamma for the computer I bought in 1996,
    and it was linear to within experimental error.

    There's this from Pennebaker & Mitchell 1993 p.26:

    "The capture device is typically the most linear part of the system, in
    that the quantum efficiency (the number of electrons emitted for each
    photon arriving from the image) is quite constant in a well-designed and
    well-calbrated imaging device. (Quantum efficiency is usually dependent
    on the color of the light.)

    The output device, especially if it is a CRT display, is often quite
    nonlinear. A gamma correction is often applied to displays to correct for
    the nonlinear characteristics of the electron gun and to make the
    visually perceived output fairly linear. In critical applications the
    device characteristics should be measured and the input corrected to
    achieve a linear response."

    Intel graphics chips also have linear gamma as the default setting:
    http://www.intel.com/support/graphics/sb/cs-013542.htm
     
    Mihai Cartoaje, May 22, 2010
    #12
  13. How do you measure gamma without a colorimeter? Or rather, the gamma of
    what? Of the overall graphics card-monitor-eye system? That is *not*
    quite the gamma of the monitor. The monitor has a gamma of around 2.2
    for CRTs, and LCDs do use a lookup table to match that gamma, even
    though the display technology by itself is close to linear.

    However, your eye has a logarithmic sensitivity curve which is close,
    but not identical to the inverse of the monitor gamma - thus the overall
    monitor-eye system is not too far from linear.
    That's so far correct to my knowledge.
    The gamma correction is not really applied to the display to my
    knowledge. Instead, the signal is coded and transmitted gamma corrected.
    For a regular TV transmission, this correction is applied at the sender
    (the TV studio) to my very knowledge. This makes the
    camera-gamma-correction-transmission-monitor system linear.
    No doubt about it.

    Question is (or was): Which primary colors are used for JFIF? Does a
    display application (such as photoshop) really implement a REC-601 (JFIF
    primaries "as standardized") into sRGB (Rec 709) transformation? I
    actually don't know, but I suspect that most if not all programs use the
    sRGB primaries and gamma for interpreting JFIF, *not* Rec-601 colors and
    gamma as they should.

    Greetings,
    Thomas
     
    Thomas Richter, May 22, 2010
    #13
  14. The gamma of the visual output compared to the numerical values. I
    wrote a svgalib program that displayed two rectangles on the screen,
    one on the left and one on the right. One rectangle was an uniform
    gray color, which I denote A. The other rectangle had alternating
    lines of another gray color, which I denote B, and black. By pressing
    the arrow keys, I could change the value of A until both rectangles
    looked the same color from far. When the program quit, it displayed my
    choice for the value A. I did this test for multiple values of B and
    found A to be approximately B/2.

    My understanding is that video cards apply a gamma correction that
    makes the visual output linear.

    If your copy of X.Org is like mine, it changes the video card's gamma
    from 1.0 to 2.2, unless there is a Gamma line in the "Monitors"
    section.
    This might depend on the opening of the iris. Video compression folks
    (mplayer man page) write that the contrast sensitivity is lower for
    dim or bright regions.
     
    Mihai Cartoaje, May 22, 2010
    #14
  15. (snip)
    I am not so sure what video cards do. Back to the early days of
    television, gamma correction was applied to the video signal.
    It is easier to do once at the transmitter than in every TV set.

    One incompatibility of the NTSC color signal with B&W TVs is
    in the gamma correction. It is applied separately to each of
    the R, G, and B signals before the matrix to convert to the
    signals for the subcarrier. The luminance signal (as seen by
    B&W receivers) is right for a white or gray signal, but not quite
    right for a brightly colored signal. It was considered close
    enough though, but the difference was documented.
    It might also depend on how much of the visual field is involved.
    Normally your eye can correct for the average color for light
    sources that aren't exactly white, but not for only part of
    the visual field. The correction doesn't work for slide
    projectors or TV pictures.

    -- glen
     
    glen herrmannsfeldt, May 23, 2010
    #15
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.