Exiv2
tiffimage_int.hpp
1// ***************************************************************** -*- C++ -*-
2/*
3 * Copyright (C) 2004-2021 Exiv2 authors
4 * This program is part of the Exiv2 distribution.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
19 */
20#ifndef TIFFIMAGE_INT_HPP_
21#define TIFFIMAGE_INT_HPP_
22
23// *****************************************************************************
24// included header files
25#include "tifffwd_int.hpp"
26#include "tiffcomposite_int.hpp"
27#include "image.hpp"
28#include "tags_int.hpp"
29#include "types.hpp"
30
31// + standard includes
32#include <map>
33#include <utility>
34
35// *****************************************************************************
36// namespace extensions
37namespace Exiv2 {
42 namespace Internal {
43
44// *****************************************************************************
45// class definitions
46
53 public:
55
56
57 TiffHeaderBase(uint16_t tag,
58 uint32_t size,
60 uint32_t offset);
62 virtual ~TiffHeaderBase() = default;
64
66
67
77 virtual bool read(const byte* pData, uint32_t size);
79 virtual void setByteOrder(ByteOrder byteOrder);
81 virtual void setOffset(uint32_t offset);
83
85
86
92 virtual DataBuf write() const;
99 virtual void print(std::ostream& os, const std::string& prefix ="") const;
101 virtual ByteOrder byteOrder() const;
103 virtual uint32_t offset() const;
105 virtual uint32_t size() const;
107 virtual uint16_t tag() const;
122 virtual bool isImageTag( uint16_t tag,
123 IfdId group,
124 const PrimaryGroups* pPrimaryGroups) const;
126
127 private:
128 // DATA
129 const uint16_t tag_;
130 const uint32_t size_;
131 ByteOrder byteOrder_;
132 uint32_t offset_;
133
134 }; // class TiffHeaderBase
135
137 bool isTiffImageTag(uint16_t tag, IfdId group);
138
142 class TiffHeader : public TiffHeaderBase {
143 public:
145
146
147 TiffHeader(ByteOrder byteOrder =littleEndian,
148 uint32_t offset =0x00000008,
149 bool hasImageTags =true);
151 ~TiffHeader() override = default;
153
154
155 bool isImageTag(uint16_t tag, IfdId group, const PrimaryGroups* pPrimaryGroups) const override;
157
158 private:
159 // DATA
160 bool hasImageTags_;
161 }; // class TiffHeader
162
168 struct Key {
170 Key(uint16_t t, IfdId g) : t_(t), g_(g) {}
171 uint16_t t_;
173 };
174
176 bool operator==(const Key& key) const
177 {
178 return key.g_ == group_ && key.t_ == tag_;
179 }
180
181 // DATA
182 uint16_t tag_;
184 }; // struct TiffImgTagStruct
185
192 struct Key {
194 Key(uint32_t e, IfdId g) : e_(e), g_(g) {}
195 uint32_t e_;
197 };
198
200 bool operator==(const Key& key) const
201 {
202 return key.g_ == group_
203 && (Tag::all == extendedTag_ || key.e_ == extendedTag_);
204 }
206 uint16_t tag() const { return static_cast<uint16_t>(extendedTag_ & 0xffff); }
207
208 // DATA
209 uint32_t extendedTag_;
212 };
213
220 struct Key;
222 bool operator==(const Key& key) const;
223
224 // DATA
225 uint32_t root_;
228 uint32_t parentExtTag_;
229 };
230
234 Key(uint32_t r, IfdId g) : r_(r), g_(g) {}
235 uint32_t r_;
237 };
238
243 public:
250 static std::unique_ptr<TiffComponent> create(uint32_t extendedTag,
251 IfdId group);
257 static void getPath(TiffPath& tiffPath,
258 uint32_t extendedTag,
259 IfdId group,
260 uint32_t root);
261
262 private:
263 static const TiffTreeStruct tiffTreeStruct_[]; //<! TIFF tree structure
264 static const TiffGroupStruct tiffGroupStruct_[]; //<! TIFF group structure
265
266 }; // class TiffCreator
267
273 public:
296 static ByteOrder decode(
297 ExifData& exifData,
298 IptcData& iptcData,
299 XmpData& xmpData,
300 const byte* pData,
301 uint32_t size,
302 uint32_t root,
303 FindDecoderFct findDecoderFct,
304 TiffHeaderBase* pHeader =0
305 );
316 static WriteMethod encode(
317 BasicIo& io,
318 const byte* pData,
319 uint32_t size,
320 const ExifData& exifData,
321 const IptcData& iptcData,
322 const XmpData& xmpData,
323 uint32_t root,
324 FindEncoderFct findEncoderFct,
325 TiffHeaderBase* pHeader,
326 OffsetWriter* pOffsetWriter
327 );
328
329 private:
343 static std::unique_ptr<TiffComponent> parse(
344 const byte* pData,
345 uint32_t size,
346 uint32_t root,
347 TiffHeaderBase* pHeader
348 );
356 static void findPrimaryGroups(
357 PrimaryGroups& primaryGroups,
358 TiffComponent* pSourceDir
359 );
360
361 }; // class TiffParserWorker
362
371 public:
384 static DecoderFct findDecoder(const std::string& make,
385 uint32_t extendedTag,
386 IfdId group);
400 static EncoderFct findEncoder(
401 const std::string& make,
402 uint32_t extendedTag,
403 IfdId group
404 );
405
406 private:
407 static const TiffMappingInfo tiffMappingInfo_[]; //<! TIFF mapping table
408
409 }; // class TiffMapping
410
418 public:
420 enum OffsetId {
422 };
424
425
431 void setOrigin(OffsetId id, uint32_t origin, ByteOrder byteOrder);
437 void setTarget(OffsetId id, uint32_t target);
439
441
442
443 void writeOffsets(BasicIo& io) const;
445 private:
447 struct OffsetData {
449 OffsetData() : origin_(0), target_(0), byteOrder_(littleEndian) {}
451 OffsetData(uint32_t origin, ByteOrder byteOrder) : origin_(origin), target_(0), byteOrder_(byteOrder) {}
452 // DATA
453 uint32_t origin_;
454 uint32_t target_;
455 ByteOrder byteOrder_;
456 };
458 using OffsetList = std::map<OffsetId, OffsetData>;
459
460 // DATA
461 OffsetList offsetList_;
462
463 }; // class OffsetWriter
464
465 // Todo: Move this class to metadatum_int.hpp or tags_int.hpp
468 public:
470 explicit FindExifdatum(Exiv2::Internal::IfdId ifdId) : ifdId_(ifdId) {}
472 bool operator()(const Exiv2::Exifdatum& md) const { return ifdId_ == md.ifdId(); }
473
474 private:
476
477 }; // class FindExifdatum
478
479}} // namespace Internal, Exiv2
480
481#endif // #ifndef TIFFIMAGE_INT_HPP_
An interface for simple binary IO.
Definition: basicio.hpp:55
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition: exif.hpp:434
An Exif metadatum, consisting of an ExifKey and a Value and methods to manipulate these.
Definition: exif.hpp:59
int ifdId() const
Return the IFD id as an integer. (Do not use, this is meant for library internal use....
Definition: exif.cpp:366
Unary predicate that matches an Exifdatum with a given IfdId.
Definition: tiffimage_int.hpp:467
FindExifdatum(Exiv2::Internal::IfdId ifdId)
Constructor, initializes the object with the IfdId to look for.
Definition: tiffimage_int.hpp:470
bool operator()(const Exiv2::Exifdatum &md) const
Returns true if IFD id matches.
Definition: tiffimage_int.hpp:472
Class to insert pointers or offsets to computed addresses at specific locations in an image....
Definition: tiffimage_int.hpp:417
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:2245
OffsetId
Identifiers for supported offsets.
Definition: tiffimage_int.hpp:420
@ cr2RawIfdOffset
CR2 RAW IFD offset, a pointer in the CR2 header to the 4th IFD in a CR2 image.
Definition: tiffimage_int.hpp:421
void writeOffsets(BasicIo &io) const
Write the offsets to the IO instance io.
Definition: tiffimage_int.cpp:2251
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:2240
Interface class for components of a TIFF directory hierarchy (Composite pattern). Both TIFF directori...
Definition: tiffcomposite_int.hpp:172
TIFF component factory.
Definition: tiffimage_int.hpp:242
static void getPath(TiffPath &tiffPath, 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:1832
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:1806
Abstract base class defining the interface of an image header. Used internally by classes for TIFF-ba...
Definition: tiffimage_int.hpp:52
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:2108
virtual uint16_t tag() const
Return the tag value (magic number) which identifies the buffer as TIFF data.
Definition: tiffimage_int.cpp:2103
virtual ~TiffHeaderBase()=default
Virtual destructor.
virtual uint32_t size() const
Return the size (in bytes) of the image header.
Definition: tiffimage_int.cpp:2098
virtual void setByteOrder(ByteOrder byteOrder)
Set the byte order.
Definition: tiffimage_int.cpp:2083
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:2041
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:2011
virtual void print(std::ostream &os, const std::string &prefix="") const
Print debug info for the image header to os.
Definition: tiffimage_int.cpp:2061
virtual ByteOrder byteOrder() const
Return the byte order (little or big endian).
Definition: tiffimage_int.cpp:2078
virtual bool read(const byte *pData, uint32_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:2022
virtual void setOffset(uint32_t offset)
Set the offset to the start of the root directory.
Definition: tiffimage_int.cpp:2093
virtual uint32_t offset() const
Return the offset to the start of the root directory.
Definition: tiffimage_int.cpp:2088
Standard TIFF header structure.
Definition: tiffimage_int.hpp:142
TiffHeader(ByteOrder byteOrder=littleEndian, uint32_t offset=0x00000008, bool hasImageTags=true)
Default constructor.
Definition: tiffimage_int.cpp:2200
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:2206
~TiffHeader() override=default
Destructor.
Table of TIFF decoding and encoding functions and find functions. This class is separated from the me...
Definition: tiffimage_int.hpp:370
static DecoderFct findDecoder(const std::string &make, uint32_t extendedTag, IfdId group)
Find the decoder function for a key.
Definition: tiffimage_int.cpp:1771
static EncoderFct findEncoder(const std::string &make, uint32_t extendedTag, IfdId group)
Find special encoder function for a key.
Definition: tiffimage_int.cpp:1785
Stateless parser class for data in TIFF format. Images use this class to decode and encode TIFF-based...
Definition: tiffimage_int.hpp:272
static ByteOrder decode(ExifData &exifData, IptcData &iptcData, XmpData &xmpData, const byte *pData, uint32_t size, uint32_t root, FindDecoderFct findDecoderFct, TiffHeaderBase *pHeader=0)
Decode TIFF metadata from a data buffer pData of length size into the provided metadata containers.
Definition: tiffimage_int.cpp:1848
static WriteMethod encode(BasicIo &io, const byte *pData, uint32_t size, const ExifData &exifData, const IptcData &iptcData, const 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:1878
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition: iptc.hpp:169
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition: xmp_exiv2.hpp:165
const uint32_t all
Special tag: all tags in a group.
Definition: tiffcomposite_int.hpp:76
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:89
void(TiffEncoder::*)(TiffEntryBase *, const Exifdatum *) EncoderFct
Function pointer type for a TiffDecoder member function to decode a TIFF component.
Definition: tifffwd_int.hpp:81
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:85
std::stack< TiffPathItem > TiffPath
Stack to hold a path from the TIFF root element to a TIFF entry.
Definition: tifffwd_int.hpp:98
std::vector< IfdId > PrimaryGroups
Type for a list of primary image groups.
Definition: tifffwd_int.hpp:101
void(TiffDecoder::*)(const TiffEntryBase *) DecoderFct
Function pointer type for a TiffDecoder member function to decode a TIFF component.
Definition: tifffwd_int.hpp:76
IfdId
Type to specify the IFD to which a metadata belongs.
Definition: tags_int.hpp:46
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:2115
std::unique_ptr< TiffComponent >(*)(uint16_t tag, IfdId group) NewTiffCompFct
Type for a function pointer for a function to create a TIFF component. Use TiffComponent::UniquePtr,...
Definition: tifffwd_int.hpp:95
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: basicio.hpp:43
EXIV2API ExifData::const_iterator make(const ExifData &ed)
Return the camera make.
Definition: easyaccess.cpp:437
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:83
WriteMethod
Type to indicate write method used by TIFF parsers.
Definition: types.hpp:86
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition: types.hpp:162
Search key for TIFF group structure.
Definition: tiffimage_int.hpp:192
uint32_t e_
Extended tag.
Definition: tiffimage_int.hpp:195
Key(uint32_t e, IfdId g)
Constructor.
Definition: tiffimage_int.hpp:194
IfdId g_
Group
Definition: tiffimage_int.hpp:196
Data structure used as a row (element) of a table (array) defining the TIFF component used for each t...
Definition: tiffimage_int.hpp:190
IfdId group_
Group that contains the tag.
Definition: tiffimage_int.hpp:210
uint32_t extendedTag_
Tag (32 bit so that it can contain special tags)
Definition: tiffimage_int.hpp:209
bool operator==(const Key &key) const
Comparison operator to compare a TiffGroupStruct with a TiffGroupStruct::Key.
Definition: tiffimage_int.hpp:200
uint16_t tag() const
Return the tag corresponding to the extended tag.
Definition: tiffimage_int.hpp:206
NewTiffCompFct newTiffCompFct_
Function to create the correct TIFF component.
Definition: tiffimage_int.hpp:211
Search key for TIFF image tag structure.
Definition: tiffimage_int.hpp:168
Key(uint16_t t, IfdId g)
Constructor.
Definition: tiffimage_int.hpp:170
uint16_t t_
Tag
Definition: tiffimage_int.hpp:171
IfdId g_
Group
Definition: tiffimage_int.hpp:172
Data structure used to list image tags for TIFF and TIFF-like images.
Definition: tiffimage_int.hpp:166
bool operator==(const Key &key) const
Comparison operator to compare a TiffImgTagStruct with a TiffImgTagStruct::Key.
Definition: tiffimage_int.hpp:176
IfdId group_
Group that contains the image tag.
Definition: tiffimage_int.hpp:183
uint16_t tag_
Image tag.
Definition: tiffimage_int.hpp:182
TIFF mapping table for functions to decode special cases.
Definition: tiffcomposite_int.hpp:374
Search key for TIFF tree structure.
Definition: tiffimage_int.hpp:232
IfdId g_
Group
Definition: tiffimage_int.hpp:236
uint32_t r_
Root.
Definition: tiffimage_int.hpp:235
Key(uint32_t r, IfdId g)
Constructor.
Definition: tiffimage_int.hpp:234
Data structure used as a row of the table which describes TIFF trees. Multiple trees are needed as TI...
Definition: tiffimage_int.hpp:219
IfdId group_
Each group is a node in the tree.
Definition: tiffimage_int.hpp:226
bool operator==(const Key &key) const
Comparison operator to compare a TiffTreeStruct with a TiffTreeStruct::Key.
Definition: tiffimage_int.cpp:1801
uint32_t parentExtTag_
Parent tag (32 bit so that it can contain special tags)
Definition: tiffimage_int.hpp:228
uint32_t root_
Tree root element, identifies a tree.
Definition: tiffimage_int.hpp:225
IfdId parentGroup_
Parent group.
Definition: tiffimage_int.hpp:227