Backed out changeset 177eae915693 (bug 1206581) for bustage
[gecko.git] / image / decoders / EXIF.h
blob9028f2cf83283909386bcc508413e4a97f0c2d64
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_image_decoders_EXIF_h
7 #define mozilla_image_decoders_EXIF_h
9 #include <stdint.h>
10 #include "nsDebug.h"
12 #include "Orientation.h"
14 namespace mozilla {
15 namespace image {
17 enum class ByteOrder : uint8_t {
18 Unknown,
19 LittleEndian,
20 BigEndian
23 struct EXIFData
25 EXIFData() { }
26 explicit EXIFData(Orientation aOrientation) : orientation(aOrientation) { }
28 const Orientation orientation;
31 class EXIFParser
33 public:
34 static EXIFData
35 Parse(const uint8_t* aData, const uint32_t aLength)
37 EXIFParser parser;
38 return parser.ParseEXIF(aData, aLength);
41 private:
42 EXIFParser()
43 : mStart(nullptr)
44 , mCurrent(nullptr)
45 , mLength(0)
46 , mRemainingLength(0)
47 , mByteOrder(ByteOrder::Unknown)
48 { }
50 EXIFData ParseEXIF(const uint8_t* aData, const uint32_t aLength);
51 bool ParseEXIFHeader();
52 bool ParseTIFFHeader(uint32_t& aIFD0OffsetOut);
53 bool ParseIFD0(Orientation& aOrientationOut);
54 bool ParseOrientation(uint16_t aType, uint32_t aCount, Orientation& aOut);
56 bool Initialize(const uint8_t* aData, const uint32_t aLength);
57 void Advance(const uint32_t aDistance);
58 void JumpTo(const uint32_t aOffset);
60 bool MatchString(const char* aString, const uint32_t aLength);
61 bool MatchUInt16(const uint16_t aValue);
62 bool ReadUInt16(uint16_t& aOut);
63 bool ReadUInt32(uint32_t& aOut);
65 const uint8_t* mStart;
66 const uint8_t* mCurrent;
67 uint32_t mLength;
68 uint32_t mRemainingLength;
69 ByteOrder mByteOrder;
72 } // namespace image
73 } // namespace mozilla
75 #endif // mozilla_image_decoders_EXIF_h