Bug 869723 (Part 3) - Parse EXIF orientation in nsJPEGDecoder. r=joe

This commit is contained in:
Seth Fowler 2013-08-25 00:19:43 -07:00
parent fc9c9c54a7
commit 337d1b4d5f
2 changed files with 26 additions and 1 deletions

View File

@ -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<uint32_t>(marker->data_length));
return exif.orientation;
}
void
nsJPEGDecoder::NotifyDone()
{

View File

@ -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: