|
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/. */ |
|
5 |
|
6 #ifndef MOZILLA_IMAGELIB_EXIF_H_ |
|
7 #define MOZILLA_IMAGELIB_EXIF_H_ |
|
8 |
|
9 #include <stdint.h> |
|
10 #include "mozilla/TypedEnum.h" |
|
11 #include "nsDebug.h" |
|
12 |
|
13 #include "Orientation.h" |
|
14 |
|
15 namespace mozilla { |
|
16 namespace image { |
|
17 |
|
18 MOZ_BEGIN_ENUM_CLASS(ByteOrder, uint8_t) |
|
19 Unknown, |
|
20 LittleEndian, |
|
21 BigEndian |
|
22 MOZ_END_ENUM_CLASS(ByteOrder) |
|
23 |
|
24 struct EXIFData |
|
25 { |
|
26 EXIFData() { } |
|
27 explicit EXIFData(Orientation aOrientation) : orientation(aOrientation) { } |
|
28 |
|
29 const Orientation orientation; |
|
30 }; |
|
31 |
|
32 class EXIFParser |
|
33 { |
|
34 public: |
|
35 static EXIFData |
|
36 Parse(const uint8_t* aData, const uint32_t aLength) |
|
37 { |
|
38 EXIFParser parser; |
|
39 return parser.ParseEXIF(aData, aLength); |
|
40 } |
|
41 |
|
42 private: |
|
43 EXIFParser() |
|
44 : mStart(nullptr) |
|
45 , mCurrent(nullptr) |
|
46 , mLength(0) |
|
47 , mRemainingLength(0) |
|
48 , mByteOrder(ByteOrder::Unknown) |
|
49 { } |
|
50 |
|
51 EXIFData ParseEXIF(const uint8_t* aData, const uint32_t aLength); |
|
52 bool ParseEXIFHeader(); |
|
53 bool ParseTIFFHeader(uint32_t& aIFD0OffsetOut); |
|
54 bool ParseIFD0(Orientation& aOrientationOut); |
|
55 bool ParseOrientation(uint16_t aType, uint32_t aCount, Orientation& aOut); |
|
56 |
|
57 bool Initialize(const uint8_t* aData, const uint32_t aLength); |
|
58 void Advance(const uint32_t aDistance); |
|
59 void JumpTo(const uint32_t aOffset); |
|
60 |
|
61 bool MatchString(const char* aString, const uint32_t aLength); |
|
62 bool MatchUInt16(const uint16_t aValue); |
|
63 bool ReadUInt16(uint16_t& aOut); |
|
64 bool ReadUInt32(uint32_t& aOut); |
|
65 |
|
66 const uint8_t* mStart; |
|
67 const uint8_t* mCurrent; |
|
68 uint32_t mLength; |
|
69 uint32_t mRemainingLength; |
|
70 ByteOrder mByteOrder; |
|
71 }; |
|
72 |
|
73 } |
|
74 } |
|
75 |
|
76 #endif |