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() =0;
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();
153
154
155 bool isImageTag( uint16_t tag,
156 IfdId group,
157 const PrimaryGroups* pPrimaryGroups) const;
159
160 private:
161 // DATA
162 bool hasImageTags_;
163 }; // class TiffHeader
164
170 struct Key {
172 Key(uint16_t t, IfdId g) : t_(t), g_(g) {}
173 uint16_t t_;
175 };
176
178 bool operator==(const Key& key) const
179 {
180 return key.g_ == group_ && key.t_ == tag_;
181 }
182
183 // DATA
184 uint16_t tag_;
186 }; // struct TiffImgTagStruct
187
194 struct Key {
196 Key(uint32_t e, IfdId g) : e_(e), g_(g) {}
197 uint32_t e_;
199 };
200
202 bool operator==(const Key& key) const
203 {
204 return key.g_ == group_
205 && (Tag::all == extendedTag_ || key.e_ == extendedTag_);
206 }
208 uint16_t tag() const { return static_cast<uint16_t>(extendedTag_ & 0xffff); }
209
210 // DATA
211 uint32_t extendedTag_;
214 };
215
222 struct Key;
224 bool operator==(const Key& key) const;
225
226 // DATA
227 uint32_t root_;
230 uint32_t parentExtTag_;
231 };
232
236 Key(uint32_t r, IfdId g) : r_(r), g_(g) {}
237 uint32_t r_;
239 };
240
245 public:
252 static std::auto_ptr<TiffComponent> create(uint32_t extendedTag,
253 IfdId group);
259 static void getPath(TiffPath& tiffPath,
260 uint32_t extendedTag,
261 IfdId group,
262 uint32_t root);
263
264 private:
265 static const TiffTreeStruct tiffTreeStruct_[]; //<! TIFF tree structure
266 static const TiffGroupStruct tiffGroupStruct_[]; //<! TIFF group structure
267
268 }; // class TiffCreator
269
275 public:
298 static ByteOrder decode(
299 ExifData& exifData,
300 IptcData& iptcData,
301 XmpData& xmpData,
302 const byte* pData,
303 uint32_t size,
304 uint32_t root,
305 FindDecoderFct findDecoderFct,
306 TiffHeaderBase* pHeader =0
307 );
318 static WriteMethod encode(
319 BasicIo& io,
320 const byte* pData,
321 uint32_t size,
322 const ExifData& exifData,
323 const IptcData& iptcData,
324 const XmpData& xmpData,
325 uint32_t root,
326 FindEncoderFct findEncoderFct,
327 TiffHeaderBase* pHeader,
328 OffsetWriter* pOffsetWriter
329 );
330
331 private:
345 static std::auto_ptr<TiffComponent> parse(
346 const byte* pData,
347 uint32_t size,
348 uint32_t root,
349 TiffHeaderBase* pHeader
350 );
358 static void findPrimaryGroups(
359 PrimaryGroups& primaryGroups,
360 TiffComponent* pSourceDir
361 );
362
363 }; // class TiffParserWorker
364
373 public:
386 static DecoderFct findDecoder(const std::string& make,
387 uint32_t extendedTag,
388 IfdId group);
402 static EncoderFct findEncoder(
403 const std::string& make,
404 uint32_t extendedTag,
405 IfdId group
406 );
407
408 private:
409 static const TiffMappingInfo tiffMappingInfo_[]; //<! TIFF mapping table
410
411 }; // class TiffMapping
412
420 public:
422 enum OffsetId {
424 };
426
427
433 void setOrigin(OffsetId id, uint32_t origin, ByteOrder byteOrder);
439 void setTarget(OffsetId id, uint32_t target);
441
443
444
445 void writeOffsets(BasicIo& io) const;
447 private:
449 struct OffsetData {
451 OffsetData() : origin_(0), target_(0), byteOrder_(littleEndian) {}
453 OffsetData(uint32_t origin, ByteOrder byteOrder) : origin_(origin), target_(0), byteOrder_(byteOrder) {}
454 // DATA
455 uint32_t origin_;
456 uint32_t target_;
457 ByteOrder byteOrder_;
458 };
460 typedef std::map<OffsetId, OffsetData> OffsetList;
461
462 // DATA
463 OffsetList offsetList_;
464
465 }; // class OffsetWriter
466
467 // Todo: Move this class to metadatum_int.hpp or tags_int.hpp
470 public:
472 explicit FindExifdatum(Exiv2::Internal::IfdId ifdId) : ifdId_(ifdId) {}
474 bool operator()(const Exiv2::Exifdatum& md) const { return ifdId_ == md.ifdId(); }
475
476 private:
478
479 }; // class FindExifdatum
480
481}} // namespace Internal, Exiv2
482
483#endif // #ifndef TIFFIMAGE_INT_HPP_
An interface for simple binary IO.
Definition: basicio.hpp:55
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition: types.hpp:193
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:365
Unary predicate that matches an Exifdatum with a given IfdId.
Definition: tiffimage_int.hpp:469
FindExifdatum(Exiv2::Internal::IfdId ifdId)
Constructor, initializes the object with the IfdId to look for.
Definition: tiffimage_int.hpp:472
bool operator()(const Exiv2::Exifdatum &md) const
Returns true if IFD id matches.
Definition: tiffimage_int.hpp:474
Class to insert pointers or offsets to computed addresses at specific locations in an image....
Definition: tiffimage_int.hpp:419
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:2132
OffsetId
Identifiers for supported offsets.
Definition: tiffimage_int.hpp:422
@ cr2RawIfdOffset
CR2 RAW IFD offset, a pointer in the CR2 header to the 4th IFD in a CR2 image.
Definition: tiffimage_int.hpp:423
void writeOffsets(BasicIo &io) const
Write the offsets to the IO instance io.
Definition: tiffimage_int.cpp:2138
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:2127
Interface class for components of a TIFF directory hierarchy (Composite pattern). Both TIFF directori...
Definition: tiffcomposite_int.hpp:171
TIFF component factory.
Definition: tiffimage_int.hpp:244
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:1701
static std::auto_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:1675
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:1986
virtual uint16_t tag() const
Return the tag value (magic number) which identifies the buffer as TIFF data.
Definition: tiffimage_int.cpp:1981
virtual uint32_t size() const
Return the size (in bytes) of the image header.
Definition: tiffimage_int.cpp:1976
virtual void setByteOrder(ByteOrder byteOrder)
Set the byte order.
Definition: tiffimage_int.cpp:1961
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:1919
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:1885
virtual ~TiffHeaderBase()=0
Virtual destructor.
Definition: tiffimage_int.cpp:1896
virtual void print(std::ostream &os, const std::string &prefix="") const
Print debug info for the image header to os.
Definition: tiffimage_int.cpp:1939
virtual ByteOrder byteOrder() const
Return the byte order (little or big endian).
Definition: tiffimage_int.cpp:1956
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:1900
virtual void setOffset(uint32_t offset)
Set the offset to the start of the root directory.
Definition: tiffimage_int.cpp:1971
virtual uint32_t offset() const
Return the offset to the start of the root directory.
Definition: tiffimage_int.cpp:1966
Standard TIFF header structure.
Definition: tiffimage_int.hpp:142
~TiffHeader()
Destructor.
Definition: tiffimage_int.cpp:2085
TiffHeader(ByteOrder byteOrder=littleEndian, uint32_t offset=0x00000008, bool hasImageTags=true)
Default constructor.
Definition: tiffimage_int.cpp:2079
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:2089
Table of TIFF decoding and encoding functions and find functions. This class is separated from the me...
Definition: tiffimage_int.hpp:372
static DecoderFct findDecoder(const std::string &make, uint32_t extendedTag, IfdId group)
Find the decoder function for a key.
Definition: tiffimage_int.cpp:1640
static EncoderFct findEncoder(const std::string &make, uint32_t extendedTag, IfdId group)
Find special encoder function for a key.
Definition: tiffimage_int.cpp:1654
Stateless parser class for data in TIFF format. Images use this class to decode and encode TIFF-based...
Definition: tiffimage_int.hpp:274
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:1717
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:1747
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition: iptc.hpp:170
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition: xmp_exiv2.hpp:166
const uint32_t all
Special tag: all tags in a group.
Definition: tiffcomposite_int.hpp:75
DecoderFct(* FindDecoderFct)(const std::string &make, uint32_t extendedTag, IfdId group)
Type for a function pointer for a function to decode a TIFF component.
Definition: tifffwd_int.hpp:85
std::auto_ptr< TiffComponent >(* NewTiffCompFct)(uint16_t tag, IfdId group)
Type for a function pointer for a function to create a TIFF component. Use TiffComponent::AutoPtr,...
Definition: tifffwd_int.hpp:101
void(TiffEncoder::* EncoderFct)(TiffEntryBase *, const Exifdatum *)
Function pointer type for a TiffDecoder member function to decode a TIFF component.
Definition: tifffwd_int.hpp:81
void(TiffDecoder::* DecoderFct)(const TiffEntryBase *)
Function pointer type for a TiffDecoder member function to decode a TIFF component.
Definition: tifffwd_int.hpp:76
std::vector< IfdId > PrimaryGroups
Type for a list of primary image groups.
Definition: tifffwd_int.hpp:107
std::stack< TiffPathItem > TiffPath
Stack to hold a path from the TIFF root element to a TIFF entry.
Definition: tifffwd_int.hpp:104
IfdId
Type to specify the IFD to which a metadata belongs.
Definition: tags_int.hpp:46
EncoderFct(* FindEncoderFct)(const std::string &make, uint32_t extendedTag, IfdId group)
Type for a function pointer for a function to encode a TIFF component.
Definition: tifffwd_int.hpp:91
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:1993
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
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:102
WriteMethod
Type to indicate write method used by TIFF parsers.
Definition: types.hpp:105
Search key for TIFF group structure.
Definition: tiffimage_int.hpp:194
uint32_t e_
Extended tag.
Definition: tiffimage_int.hpp:197
Key(uint32_t e, IfdId g)
Constructor.
Definition: tiffimage_int.hpp:196
IfdId g_
Group
Definition: tiffimage_int.hpp:198
Data structure used as a row (element) of a table (array) defining the TIFF component used for each t...
Definition: tiffimage_int.hpp:192
IfdId group_
Group that contains the tag.
Definition: tiffimage_int.hpp:212
uint32_t extendedTag_
Tag (32 bit so that it can contain special tags)
Definition: tiffimage_int.hpp:211
bool operator==(const Key &key) const
Comparison operator to compare a TiffGroupStruct with a TiffGroupStruct::Key.
Definition: tiffimage_int.hpp:202
uint16_t tag() const
Return the tag corresponding to the extended tag.
Definition: tiffimage_int.hpp:208
NewTiffCompFct newTiffCompFct_
Function to create the correct TIFF component.
Definition: tiffimage_int.hpp:213
Search key for TIFF image tag structure.
Definition: tiffimage_int.hpp:170
Key(uint16_t t, IfdId g)
Constructor.
Definition: tiffimage_int.hpp:172
uint16_t t_
Tag
Definition: tiffimage_int.hpp:173
IfdId g_
Group
Definition: tiffimage_int.hpp:174
Data structure used to list image tags for TIFF and TIFF-like images.
Definition: tiffimage_int.hpp:168
bool operator==(const Key &key) const
Comparison operator to compare a TiffImgTagStruct with a TiffImgTagStruct::Key.
Definition: tiffimage_int.hpp:178
IfdId group_
Group that contains the image tag.
Definition: tiffimage_int.hpp:185
uint16_t tag_
Image tag.
Definition: tiffimage_int.hpp:184
TIFF mapping table for functions to decode special cases.
Definition: tiffcomposite_int.hpp:373
Search key for TIFF tree structure.
Definition: tiffimage_int.hpp:234
IfdId g_
Group
Definition: tiffimage_int.hpp:238
uint32_t r_
Root.
Definition: tiffimage_int.hpp:237
Key(uint32_t r, IfdId g)
Constructor.
Definition: tiffimage_int.hpp:236
Data structure used as a row of the table which describes TIFF trees. Multiple trees are needed as TI...
Definition: tiffimage_int.hpp:221
IfdId group_
Each group is a node in the tree.
Definition: tiffimage_int.hpp:228
bool operator==(const Key &key) const
Comparison operator to compare a TiffTreeStruct with a TiffTreeStruct::Key.
Definition: tiffimage_int.cpp:1670
uint32_t parentExtTag_
Parent tag (32 bit so that it can contain special tags)
Definition: tiffimage_int.hpp:230
uint32_t root_
Tree root element, identifies a tree.
Definition: tiffimage_int.hpp:227
IfdId parentGroup_
Parent group.
Definition: tiffimage_int.hpp:229