| Exiv2

Loading...
Searching...
No Matches
tiffimage_int.hpp
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3#ifndef TIFFIMAGE_INT_HPP_
4#define TIFFIMAGE_INT_HPP_
5
6// *****************************************************************************
7// included header files
8#include <unordered_map>
9#include "image.hpp"
10#include "tiffcomposite_int.hpp"
11#include "tifffwd_int.hpp"
12
13// *****************************************************************************
14// namespace extensions
15 namespace Exiv2::Internal {
20
21// *****************************************************************************
22// class definitions
23
29 class TiffHeaderBase {
30 public:
32
33
34 TiffHeaderBase(uint16_t tag, uint32_t size, ByteOrder byteOrder, uint32_t offset);
36 virtual ~TiffHeaderBase() = default;
38
40
41
51 virtual bool read(const byte* pData, size_t size);
53 virtual void setByteOrder(ByteOrder byteOrder);
55 virtual void setOffset(uint32_t offset);
57
59
60
66 [[nodiscard]] virtual DataBuf write() const;
73 virtual void print(std::ostream& os, const std::string& prefix = "") const;
75 [[nodiscard]] virtual ByteOrder byteOrder() const;
77 [[nodiscard]] virtual uint32_t offset() const;
79 [[nodiscard]] virtual uint32_t size() const;
81 [[nodiscard]] virtual uint16_t tag() const;
96 virtual bool isImageTag(uint16_t tag, IfdId group, const PrimaryGroups* pPrimaryGroups) const;
98
99 private:
100 // DATA
101 uint16_t tag_;
102 uint32_t size_;
103 ByteOrder byteOrder_;
104 uint32_t offset_;
105};
106
108 bool isTiffImageTag(uint16_t tag, IfdId group);
109
113 class TiffHeader : public TiffHeaderBase {
114 public:
116
117
118 explicit TiffHeader(ByteOrder byteOrder = littleEndian, uint32_t offset = 0x00000008, bool hasImageTags = true);
120
121
122 bool isImageTag(uint16_t tag, IfdId group, const PrimaryGroups* pPrimaryGroups) const override;
124
125 private:
126 // DATA
127 bool hasImageTags_;
128};
129
133 using TiffGroupKey = std::pair<uint32_t, IfdId>;
134
135 struct TiffGroupKey_hash {
136 std::size_t operator()(const TiffGroupKey& pair) const noexcept {
137 return std::hash<uint64_t>{}(static_cast<uint64_t>(pair.first) << 32 | static_cast<uint64_t>(pair.second));
138 }
139};
140
145 using TiffGroupTable = std::unordered_map<TiffGroupKey, NewTiffCompFct, TiffGroupKey_hash>;
146
152 using TiffTreeParent = std::pair<IfdId, uint32_t>; // Parent group, parent tag
153 using TiffTreeTable = std::unordered_map<TiffGroupKey, TiffTreeParent, TiffGroupKey_hash>;
154
158 class TiffCreator {
159 public:
166 static std::unique_ptr<TiffComponent> create(uint32_t extendedTag, IfdId group);
172 static TiffPath getPath(uint32_t extendedTag, IfdId group, uint32_t root);
173
174 private:
175 static const TiffTreeTable tiffTreeTable_;
176 static const TiffGroupTable tiffGroupTable_;
177};
178
183 class TiffParserWorker {
184 public:
207 static ByteOrder decode(ExifData& exifData, IptcData& iptcData, XmpData& xmpData, const byte* pData, size_t size,
208 uint32_t root, FindDecoderFct findDecoderFct, TiffHeaderBase* pHeader = nullptr);
219 static WriteMethod encode(BasicIo& io, const byte* pData, size_t size, ExifData& exifData, IptcData& iptcData,
220 XmpData& xmpData, uint32_t root, FindEncoderFct findEncoderFct, TiffHeaderBase* pHeader,
221 OffsetWriter* pOffsetWriter);
222
223 private:
237 static std::unique_ptr<TiffComponent> parse(const byte* pData, size_t size, uint32_t root, TiffHeaderBase* pHeader);
245 static PrimaryGroups findPrimaryGroups(TiffComponent* pSourceDir);
246};
247
255 class TiffMapping {
256 public:
269 static DecoderFct findDecoder(const std::string& make, uint32_t extendedTag, IfdId group);
283 static EncoderFct findEncoder(const std::string& make, uint32_t extendedTag, IfdId group);
284
285 private:
286 static const TiffMappingInfo tiffMappingInfo_[];
287};
288
295 class OffsetWriter {
296 public:
298 enum OffsetId {
299 cr2RawIfdOffset
300 };
301
302
303
309 void setOrigin(OffsetId id, uint32_t origin, ByteOrder byteOrder);
315 void setTarget(OffsetId id, uint32_t target);
317
319
320
321 void writeOffsets(BasicIo& io) const;
323 private:
325 struct OffsetData {
326 uint32_t origin_{};
327 uint32_t target_{};
328 ByteOrder byteOrder_{littleEndian};
329 };
331 using OffsetList = std::map<OffsetId, OffsetData>;
332
333 // DATA
334 OffsetList offsetList_;
335
336}; // class OffsetWriter
337
338// Todo: Move this class to metadatum_int.hpp or tags_int.hpp
340 class FindExifdatum {
341 public:
343 explicit FindExifdatum(Exiv2::IfdId ifdId) : ifdId_(ifdId) {
344 }
345
346 bool operator()(const Exiv2::Exifdatum& md) const {
347 return ifdId_ == md.ifdId();
348 }
349
350 private:
351 Exiv2::IfdId ifdId_;
352
353}; // class FindExifdatum
354
355} // namespace Exiv2::Internal
356
357#endif // #ifndef TIFFIMAGE_INT_HPP_
Exiv2::BasicIo
An interface for simple binary IO.
Definition basicio.hpp:35
Exiv2::ExifData
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition exif.hpp:379
Exiv2::Exifdatum
An Exif metadatum, consisting of an ExifKey and a Value and methods to manipulate these.
Definition exif.hpp:41
Exiv2::Exifdatum::ifdId
IfdId ifdId() const
Return the IFD id as an integer. (Do not use, this is meant for library internal use....
Definition exif.cpp:300
Exiv2::Internal::FindExifdatum::FindExifdatum
FindExifdatum(Exiv2::IfdId ifdId)
Constructor, initializes the object with the IfdId to look for.
Definition tiffimage_int.hpp:343
Exiv2::Internal::FindExifdatum::operator()
bool operator()(const Exiv2::Exifdatum &md) const
Returns true if IFD id matches.
Definition tiffimage_int.hpp:346
Exiv2::Internal::OffsetWriter
Class to insert pointers or offsets to computed addresses at specific locations in an image....
Definition tiffimage_int.hpp:295
Exiv2::Internal::OffsetWriter::setTarget
void setTarget(OffsetId id, uint32_t target)
Set the target for offset id, i.e., the address to which the offset points.
Definition tiffimage_int.cpp:2358
Exiv2::Internal::OffsetWriter::OffsetId
OffsetId
Identifiers for supported offsets.
Definition tiffimage_int.hpp:298
Exiv2::Internal::OffsetWriter::cr2RawIfdOffset
@ cr2RawIfdOffset
CR2 RAW IFD offset, a pointer in the CR2 header to the 4th IFD in a CR2 image.
Definition tiffimage_int.hpp:299
Exiv2::Internal::OffsetWriter::writeOffsets
void writeOffsets(BasicIo &io) const
Write the offsets to the IO instance io.
Definition tiffimage_int.cpp:2364
Exiv2::Internal::OffsetWriter::setOrigin
void setOrigin(OffsetId id, uint32_t origin, ByteOrder byteOrder)
Set the origin of the offset for id, i.e., the location in the image where the offset is,...
Definition tiffimage_int.cpp:2354
Exiv2::Internal::TiffComponent
Interface class for components of a TIFF directory hierarchy (Composite pattern). Both TIFF directori...
Definition tiffcomposite_int.hpp:152
Exiv2::Internal::TiffCreator
TIFF component factory.
Definition tiffimage_int.hpp:158
Exiv2::Internal::TiffCreator::getPath
static TiffPath getPath(uint32_t extendedTag, IfdId group, uint32_t root)
Get the path, i.e., a list of extended tag and group pairs, from the root TIFF element to the TIFF en...
Definition tiffimage_int.cpp:2013
Exiv2::Internal::TiffCreator::create
static std::unique_ptr< TiffComponent > create(uint32_t extendedTag, IfdId group)
Create the TiffComponent for TIFF entry extendedTag and group. The embedded lookup table is used to f...
Definition tiffimage_int.cpp:1992
Exiv2::Internal::TiffHeaderBase
Contains internal objects which are not published and are not part of the libexiv2 API.
Definition tiffimage_int.hpp:29
Exiv2::Internal::TiffHeaderBase::isImageTag
virtual bool isImageTag(uint16_t tag, IfdId group, const PrimaryGroups *pPrimaryGroups) const
Return true if the Exif tag from group is an image tag.
Definition tiffimage_int.cpp:2224
Exiv2::Internal::TiffHeaderBase::tag
virtual uint16_t tag() const
Return the tag value (magic number) which identifies the buffer as TIFF data.
Definition tiffimage_int.cpp:2220
Exiv2::Internal::TiffHeaderBase::~TiffHeaderBase
virtual ~TiffHeaderBase()=default
Virtual destructor.
Exiv2::Internal::TiffHeaderBase::size
virtual uint32_t size() const
Return the size (in bytes) of the image header.
Definition tiffimage_int.cpp:2216
Exiv2::Internal::TiffHeaderBase::read
virtual bool read(const byte *pData, size_t size)
Read the image header from a data buffer. Return false if the data buffer does not contain an image h...
Definition tiffimage_int.cpp:2143
Exiv2::Internal::TiffHeaderBase::setByteOrder
virtual void setByteOrder(ByteOrder byteOrder)
Set the byte order.
Definition tiffimage_int.cpp:2204
Exiv2::Internal::TiffHeaderBase::write
virtual DataBuf write() const
Return the image header in binary format. The caller owns this data and DataBuf ensures that it will ...
Definition tiffimage_int.cpp:2163
Exiv2::Internal::TiffHeaderBase::TiffHeaderBase
TiffHeaderBase(uint16_t tag, uint32_t size, ByteOrder byteOrder, uint32_t offset)
Constructor taking tag, size and default byteOrder and offset.
Definition tiffimage_int.cpp:2139
Exiv2::Internal::TiffHeaderBase::print
virtual void print(std::ostream &os, const std::string &prefix="") const
Print debug info for the image header to os.
Definition tiffimage_int.cpp:2181
Exiv2::Internal::TiffHeaderBase::byteOrder
virtual ByteOrder byteOrder() const
Return the byte order (little or big endian).
Definition tiffimage_int.cpp:2200
Exiv2::Internal::TiffHeaderBase::setOffset
virtual void setOffset(uint32_t offset)
Set the offset to the start of the root directory.
Definition tiffimage_int.cpp:2212
Exiv2::Internal::TiffHeaderBase::offset
virtual uint32_t offset() const
Return the offset to the start of the root directory.
Definition tiffimage_int.cpp:2208
Exiv2::Internal::TiffHeader::TiffHeader
TiffHeader(ByteOrder byteOrder=littleEndian, uint32_t offset=0x00000008, bool hasImageTags=true)
Default constructor.
Definition tiffimage_int.cpp:2319
Exiv2::Internal::TiffHeader::isImageTag
bool isImageTag(uint16_t tag, IfdId group, const PrimaryGroups *pPrimaryGroups) const override
Return true if the Exif tag from group is an image tag.
Definition tiffimage_int.cpp:2323
Exiv2::Internal::TiffMapping
Table of TIFF decoding and encoding functions and find functions. This class is separated from the me...
Definition tiffimage_int.hpp:255
Exiv2::Internal::TiffMapping::findDecoder
static DecoderFct findDecoder(const std::string &make, uint32_t extendedTag, IfdId group)
Find the decoder function for a key.
Definition tiffimage_int.cpp:1974
Exiv2::Internal::TiffMapping::findEncoder
static EncoderFct findEncoder(const std::string &make, uint32_t extendedTag, IfdId group)
Find special encoder function for a key.
Definition tiffimage_int.cpp:1983
Exiv2::Internal::TiffParserWorker
Stateless parser class for data in TIFF format. Images use this class to decode and encode TIFF-based...
Definition tiffimage_int.hpp:183
Exiv2::Internal::TiffParserWorker::encode
static WriteMethod encode(BasicIo &io, const byte *pData, size_t size, ExifData &exifData, IptcData &iptcData, XmpData &xmpData, uint32_t root, FindEncoderFct findEncoderFct, TiffHeaderBase *pHeader, OffsetWriter *pOffsetWriter)
Encode TIFF metadata from the metadata containers into a memory block blob.
Definition tiffimage_int.cpp:2045
Exiv2::Internal::TiffParserWorker::decode
static ByteOrder decode(ExifData &exifData, IptcData &iptcData, XmpData &xmpData, const byte *pData, size_t size, uint32_t root, FindDecoderFct findDecoderFct, TiffHeaderBase *pHeader=nullptr)
Decode TIFF metadata from a data buffer pData of length size into the provided metadata containers.
Definition tiffimage_int.cpp:2028
Exiv2::IptcData
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition iptc.hpp:153
Exiv2::XmpData
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition xmp_exiv2.hpp:138
Exiv2::Internal
Helper structure for the Matroska tags lookup table.
Definition matroskavideo.hpp:39
Exiv2::Internal::TiffPath
std::stack< TiffPathItem > TiffPath
Stack to hold a path from the TIFF root element to a TIFF entry.
Definition tifffwd_int.hpp:77
Exiv2::Internal::FindDecoderFct
DecoderFct(*)(const std::string &make, uint32_t extendedTag, IfdId group) FindDecoderFct
Type for a function pointer for a function to decode a TIFF component.
Definition tifffwd_int.hpp:64
Exiv2::Internal::TiffGroupTable
std::unordered_map< TiffGroupKey, NewTiffCompFct, TiffGroupKey_hash > TiffGroupTable
Data structure used as a row (element) of a table (array) defining the TIFF component used for each t...
Definition tiffimage_int.hpp:145
Exiv2::Internal::EncoderFct
void(TiffEncoder::*)(TiffEntryBase *, const Exifdatum *) EncoderFct
Function pointer type for a TiffDecoder member function to decode a TIFF component.
Definition tifffwd_int.hpp:60
Exiv2::Internal::TiffTreeParent
std::pair< IfdId, uint32_t > TiffTreeParent
Data structure used as a row of the table which describes TIFF trees. Multiple trees are needed as TI...
Definition tiffimage_int.hpp:152
Exiv2::Internal::FindEncoderFct
EncoderFct(*)(const std::string &make, uint32_t extendedTag, IfdId group) FindEncoderFct
Type for a function pointer for a function to encode a TIFF component.
Definition tifffwd_int.hpp:68
Exiv2::Internal::PrimaryGroups
std::vector< IfdId > PrimaryGroups
Type for a list of primary image groups.
Definition tifffwd_int.hpp:80
Exiv2::Internal::DecoderFct
void(TiffDecoder::*)(const TiffEntryBase *) DecoderFct
Function pointer type for a TiffDecoder member function to decode a TIFF component.
Definition tifffwd_int.hpp:55
Exiv2::Internal::TiffGroupKey
std::pair< uint32_t, IfdId > TiffGroupKey
Data structure used to list image tags for TIFF and TIFF-like images.
Definition tiffimage_int.hpp:133
Exiv2::Internal::isTiffImageTag
bool isTiffImageTag(uint16_t tag, IfdId group)
Convenience function to check if tag, group is in the list of TIFF image tags.
Definition tiffimage_int.cpp:2306
Exiv2::IfdId
IfdId
Type to specify the IFD to which a metadata belongs.
Definition tags.hpp:34
Exiv2::make
EXIV2API ExifData::const_iterator make(const ExifData &ed)
Return the camera make. Please keep in mind that this accessor is provided for convenience only and w...
Definition easyaccess.cpp:333
Exiv2::ByteOrder
ByteOrder
Type to express the byte order (little or big endian).
Definition types.hpp:34
Exiv2::WriteMethod
WriteMethod
Type to indicate write method used by TIFF parsers.
Definition types.hpp:41
Exiv2::DataBuf
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition types.hpp:124
Exiv2::Internal::TiffGroupKey_hash
Definition tiffimage_int.hpp:135
Exiv2::Internal::TiffMappingInfo
TIFF mapping table for functions to decode special cases.
Definition tiffcomposite_int.hpp:342