Bug 50847 - EXIF orientation in JPEG
Summary: EXIF orientation in JPEG
Status: RESOLVED DUPLICATE of bug 19688
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
Depends on:
Reported: 2010-12-10 14:55 PST by Cosmin Truta
Modified: 2010-12-10 21:45 PST (History)
3 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Cosmin Truta 2010-12-10 14:55:55 PST
This is a request from a Chromium user. Most digital cameras and even camera phones store JPEG images in a predefined format (typically landscape) and then set the EXIF orientation flag. That flag should not be ignored; otherwise, the image may be displayed sideways or upside-down.

The orientation flag is found at offset 0x112 within the EXIF marker, and occupies 2 bytes, according to exiftool's documentation:

A more detailed explanation, showing all the 8 possible orientations, and accompanied by sample code, is available here:

This can be implemented in WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp as follows:
Read the EXIF marker, extract the two bytes of interest, then populate the pixel data according to the orientation flag. There are 8 possible orientations. Care must be taken when calling setSize: the width and the height stay the same for the orientation values 1,2,3,4, and they are swapped for the values 5,6,7,8.

More EXIF flags can be interpreted later, if the need arises, but for the time being, a check for the EXIF marker, followed by the extraction of endianness and orientation field from the EXIF segment (and perhaps some elementary checks to ensure that it looks like a legitimate EXIF segment) should be sufficient. I see no need for a full-blown parsing of the EXIF stream.
Comment 1 Alexey Proskuryakov 2010-12-10 21:44:00 PST

*** This bug has been marked as a duplicate of bug 19688 ***
Comment 2 Alexey Proskuryakov 2010-12-10 21:45:44 PST
This differs from bug 19688 slightly in that in addition to cross-platform changes, it discusses changes to image-decoders. But there doesn't seem to be a practical reason to track this separately at this point.