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
12 #include "Orientation.h"
13 #include "mozilla/Maybe.h"
14 #include "mozilla/image/Resolution.h"
15 #include "mozilla/gfx/Point.h"
17 namespace mozilla::image
{
19 enum class ByteOrder
: uint8_t { Unknown
, LittleEndian
, BigEndian
};
22 const Orientation orientation
= Orientation();
23 const Resolution resolution
= Resolution();
26 struct ParsedEXIFData
;
28 enum class ResolutionUnit
: uint8_t {
35 static EXIFData
Parse(const uint8_t* aData
, const uint32_t aLength
,
36 const gfx::IntSize
& aRealImageSize
) {
38 return parser
.ParseEXIF(aData
, aLength
, aRealImageSize
);
47 mByteOrder(ByteOrder::Unknown
) {}
49 EXIFData
ParseEXIF(const uint8_t* aData
, const uint32_t aLength
,
50 const gfx::IntSize
& aRealImageSize
);
51 bool ParseEXIFHeader();
52 bool ParseTIFFHeader(uint32_t& aIFD0OffsetOut
);
54 void ParseIFD(ParsedEXIFData
&, uint32_t aDepth
= 0);
55 bool ParseOrientation(uint16_t aType
, uint32_t aCount
, Orientation
&);
56 bool ParseResolution(uint16_t aType
, uint32_t aCount
, Maybe
<float>&);
57 bool ParseResolutionUnit(uint16_t aType
, uint32_t aCount
,
58 Maybe
<ResolutionUnit
>&);
59 bool ParseDimension(uint16_t aType
, uint32_t aCount
, Maybe
<uint32_t>&);
61 bool Initialize(const uint8_t* aData
, const uint32_t aLength
);
62 void Advance(const uint32_t aDistance
);
63 void JumpTo(const uint32_t aOffset
);
65 uint32_t CurrentOffset() const { return mCurrent
- mStart
; }
72 ScopedJump(EXIFParser
& aParser
, uint32_t aOffset
)
73 : mParser(aParser
), mOldOffset(aParser
.CurrentOffset()) {
74 mParser
.JumpTo(aOffset
);
77 ~ScopedJump() { mParser
.JumpTo(mOldOffset
); }
80 bool MatchString(const char* aString
, const uint32_t aLength
);
81 bool MatchUInt16(const uint16_t aValue
);
82 bool ReadUInt16(uint16_t& aOut
);
83 bool ReadUInt32(uint32_t& aOut
);
84 bool ReadRational(float& aOut
);
86 const uint8_t* mStart
;
87 const uint8_t* mCurrent
;
89 uint32_t mRemainingLength
;
93 } // namespace mozilla::image
95 #endif // mozilla_image_decoders_EXIF_h