/src/mozilla-central/image/decoders/EXIF.h
Line | Count | Source (jump to first uncovered line) |
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_image_decoders_EXIF_h |
7 | | #define mozilla_image_decoders_EXIF_h |
8 | | |
9 | | #include <stdint.h> |
10 | | #include "nsDebug.h" |
11 | | |
12 | | #include "Orientation.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace image { |
16 | | |
17 | | enum class ByteOrder : uint8_t { |
18 | | Unknown, |
19 | | LittleEndian, |
20 | | BigEndian |
21 | | }; |
22 | | |
23 | | struct EXIFData |
24 | | { |
25 | 0 | EXIFData() { } |
26 | 0 | explicit EXIFData(Orientation aOrientation) : orientation(aOrientation) { } |
27 | | |
28 | | const Orientation orientation; |
29 | | }; |
30 | | |
31 | | class EXIFParser |
32 | | { |
33 | | public: |
34 | | static EXIFData |
35 | | Parse(const uint8_t* aData, const uint32_t aLength) |
36 | 0 | { |
37 | 0 | EXIFParser parser; |
38 | 0 | return parser.ParseEXIF(aData, aLength); |
39 | 0 | } |
40 | | |
41 | | private: |
42 | | EXIFParser() |
43 | | : mStart(nullptr) |
44 | | , mCurrent(nullptr) |
45 | | , mLength(0) |
46 | | , mRemainingLength(0) |
47 | | , mByteOrder(ByteOrder::Unknown) |
48 | 0 | { } |
49 | | |
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); |
55 | | |
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); |
59 | | |
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); |
64 | | |
65 | | const uint8_t* mStart; |
66 | | const uint8_t* mCurrent; |
67 | | uint32_t mLength; |
68 | | uint32_t mRemainingLength; |
69 | | ByteOrder mByteOrder; |
70 | | }; |
71 | | |
72 | | } // namespace image |
73 | | } // namespace mozilla |
74 | | |
75 | | #endif // mozilla_image_decoders_EXIF_h |