Bug 1689243 [wpt PR 27362] - Reland "Element reflection implementation updates."...
[gecko.git] / image / decoders / EXIF.h
blob7b696de5773e530180b9c50a07f71a871f0660f4
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 { Unknown, LittleEndian, BigEndian };
19 struct EXIFData {
20 EXIFData() {}
21 explicit EXIFData(Orientation aOrientation) : orientation(aOrientation) {}
23 const Orientation orientation;
26 class EXIFParser {
27 public:
28 static EXIFData Parse(const uint8_t* aData, const uint32_t aLength) {
29 EXIFParser parser;
30 return parser.ParseEXIF(aData, aLength);
33 private:
34 EXIFParser()
35 : mStart(nullptr),
36 mCurrent(nullptr),
37 mLength(0),
38 mRemainingLength(0),
39 mByteOrder(ByteOrder::Unknown) {}
41 EXIFData ParseEXIF(const uint8_t* aData, const uint32_t aLength);
42 bool ParseEXIFHeader();
43 bool ParseTIFFHeader(uint32_t& aIFD0OffsetOut);
44 bool ParseIFD0(Orientation& aOrientationOut);
45 bool ParseOrientation(uint16_t aType, uint32_t aCount, Orientation& aOut);
47 bool Initialize(const uint8_t* aData, const uint32_t aLength);
48 void Advance(const uint32_t aDistance);
49 void JumpTo(const uint32_t aOffset);
51 bool MatchString(const char* aString, const uint32_t aLength);
52 bool MatchUInt16(const uint16_t aValue);
53 bool ReadUInt16(uint16_t& aOut);
54 bool ReadUInt32(uint32_t& aOut);
56 const uint8_t* mStart;
57 const uint8_t* mCurrent;
58 uint32_t mLength;
59 uint32_t mRemainingLength;
60 ByteOrder mByteOrder;
63 } // namespace image
64 } // namespace mozilla
66 #endif // mozilla_image_decoders_EXIF_h