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.
*** This bug has been marked as a duplicate of bug 19688 ***
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.