From 337d1b4d5f6c0758cc20450f9e8e53236fc034c5 Mon Sep 17 00:00:00 2001 From: Seth Fowler Date: Sun, 25 Aug 2013 00:19:43 -0700 Subject: [PATCH] Bug 869723 (Part 3) - Parse EXIF orientation in nsJPEGDecoder. r=joe --- image/decoders/nsJPEGDecoder.cpp | 25 ++++++++++++++++++++++++- image/decoders/nsJPEGDecoder.h | 2 ++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/image/decoders/nsJPEGDecoder.cpp b/image/decoders/nsJPEGDecoder.cpp index fa580d57f74d..58c653fe3ca7 100644 --- a/image/decoders/nsJPEGDecoder.cpp +++ b/image/decoders/nsJPEGDecoder.cpp @@ -6,6 +6,8 @@ #include "ImageLogging.h" #include "nsJPEGDecoder.h" +#include "Orientation.h" +#include "EXIF.h" #include "nsIInputStream.h" @@ -235,7 +237,7 @@ nsJPEGDecoder::WriteInternal(const char *aBuffer, uint32_t aCount) } // Post our size to the superclass - PostSize(mInfo.image_width, mInfo.image_height); + PostSize(mInfo.image_width, mInfo.image_height, ReadOrientationFromEXIF()); if (HasError()) { // Setting the size led to an error. mState = JPEG_ERROR; @@ -533,6 +535,27 @@ nsJPEGDecoder::WriteInternal(const char *aBuffer, uint32_t aCount) return; } +Orientation +nsJPEGDecoder::ReadOrientationFromEXIF() +{ + jpeg_saved_marker_ptr marker; + + // Locate the APP1 marker, where EXIF data is stored, in the marker list. + for (marker = mInfo.marker_list ; marker != nullptr ; marker = marker->next) { + if (marker->marker == JPEG_APP0 + 1) + break; + } + + // If we're at the end of the list, there's no EXIF data. + if (!marker) + return Orientation(); + + // Extract the orientation information. + EXIFData exif = EXIFParser::Parse(marker->data, + static_cast(marker->data_length)); + return exif.orientation; +} + void nsJPEGDecoder::NotifyDone() { diff --git a/image/decoders/nsJPEGDecoder.h b/image/decoders/nsJPEGDecoder.h index 00409f3e7697..3b25363495c9 100644 --- a/image/decoders/nsJPEGDecoder.h +++ b/image/decoders/nsJPEGDecoder.h @@ -47,6 +47,7 @@ typedef enum { } jstate; class RasterImage; +class Orientation; class nsJPEGDecoder : public Decoder { @@ -62,6 +63,7 @@ public: void NotifyDone(); protected: + Orientation ReadOrientationFromEXIF(); void OutputScanlines(bool* suspend); public: