Exiv2
tiffimage_int.hpp
Go to the documentation of this file.
1// ***************************************************************** -*- C++ -*-
2/*
3 * Copyright (C) 2004-2018 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 */
27#ifndef TIFFIMAGE_INT_HPP_
28#define TIFFIMAGE_INT_HPP_
29
30// *****************************************************************************
31// included header files
32#include "tifffwd_int.hpp"
33#include "tiffcomposite_int.hpp"
34#include "image.hpp"
35#include "tags_int.hpp"
36#include "types.hpp"
37
38// + standard includes
39#include <map>
40#include <utility>
41
42// *****************************************************************************
43// namespace extensions
44namespace Exiv2 {
49 namespace Internal {
50
51// *****************************************************************************
52// class definitions
53
60 public:
62
63
64 TiffHeaderBase(uint16_t tag,
65 uint32_t size,
67 uint32_t offset);
69 virtual ~TiffHeaderBase() =0;
71
73
74
84 virtual bool read(const byte* pData, uint32_t size);
86 virtual void setByteOrder(ByteOrder byteOrder);
88 virtual void setOffset(uint32_t offset);
90
92
93
99 virtual DataBuf write() const;
106 virtual void print(std::ostream& os, const std::string& prefix ="") const;
108 virtual ByteOrder byteOrder() const;
110 virtual uint32_t offset() const;
112 virtual uint32_t size() const;
114 virtual uint16_t tag() const;
129 virtual bool isImageTag( uint16_t tag,
130 IfdId group,
131 const PrimaryGroups* pPrimaryGroups) const;
133
134 private:
135 // DATA
136 const uint16_t tag_;
137 const uint32_t size_;
138 ByteOrder byteOrder_;
139 uint32_t offset_;
140
141 }; // class TiffHeaderBase
142
144 bool isTiffImageTag(uint16_t tag, IfdId group);
145
149 class TiffHeader : public TiffHeaderBase {
150 public:
152
153
154 TiffHeader(ByteOrder byteOrder =littleEndian,
155 uint32_t offset =0x00000008,
156 bool hasImageTags =true);
158 ~TiffHeader();
160
161
162 bool isImageTag( uint16_t tag,
163 IfdId group,
164 const PrimaryGroups* pPrimaryGroups) const;
166
167 private:
168 // DATA
169 bool hasImageTags_;
170 }; // class TiffHeader
171
177 struct Key {
179 Key(uint16_t t, IfdId g) : t_(t), g_(g) {}
180 uint16_t t_;
182 };
183
185 bool operator==(const Key& key) const
186 {
187 return key.g_ == group_ && key.t_ == tag_;
188 }
189
190 // DATA
191 uint16_t tag_;
193 }; // struct TiffImgTagStruct
194
201 struct Key {
203 Key(uint32_t e, IfdId g) : e_(e), g_(g) {}
204 uint32_t e_;
206 };
207
209 bool operator==(const Key& key) const
210 {
211 return key.g_ == group_
212 && (Tag::all == extendedTag_ || key.e_ == extendedTag_);
213 }
215 uint16_t tag() const { return static_cast<uint16_t>(extendedTag_ & 0xffff); }
216
217 // DATA
218 uint32_t extendedTag_;
221 };
222
229 struct Key;
231 bool operator==(const Key& key) const;
232
233 // DATA
234 uint32_t root_;
237 uint32_t parentExtTag_;
238 };
239
243 Key(uint32_t r, IfdId g) : r_(r), g_(g) {}
244 uint32_t r_;
246 };
247
252 public:
259 static std::auto_ptr<TiffComponent> create(uint32_t extendedTag,
260 IfdId group);
266 static void getPath(TiffPath& tiffPath,
267 uint32_t extendedTag,
268 IfdId group,
269 uint32_t root);
270
271 private:
272 static const TiffTreeStruct tiffTreeStruct_[]; //<! TIFF tree structure
273 static const TiffGroupStruct tiffGroupStruct_[]; //<! TIFF group structure
274
275 }; // class TiffCreator
276
282 public:
305 static ByteOrder decode(
306 ExifData& exifData,
307 IptcData& iptcData,
308 XmpData& xmpData,
309 const byte* pData,
310 uint32_t size,
311 uint32_t root,
312 FindDecoderFct findDecoderFct,
313 TiffHeaderBase* pHeader =0
314 );
325 static WriteMethod encode(
326 BasicIo& io,
327 const byte* pData,
328 uint32_t size,
329 const ExifData& exifData,
330 const IptcData& iptcData,
331 const XmpData& xmpData,
332 uint32_t root,
333 FindEncoderFct findEncoderFct,
334 TiffHeaderBase* pHeader,
335 OffsetWriter* pOffsetWriter
336 );
337
338 private:
352 static std::auto_ptr<TiffComponent> parse(
353 const byte* pData,
354 uint32_t size,
355 uint32_t root,
356 TiffHeaderBase* pHeader
357 );
365 static void findPrimaryGroups(
366 PrimaryGroups& primaryGroups,
367 TiffComponent* pSourceDir
368 );
369
370 }; // class TiffParserWorker
371
380 public:
394 uint32_t extendedTag,
395 IfdId group);
409 static EncoderFct findEncoder(
410 const std::string& make,
411 uint32_t extendedTag,
412 IfdId group
413 );
414
415 private:
416 static const TiffMappingInfo tiffMappingInfo_[]; //<! TIFF mapping table
417
418 }; // class TiffMapping
419
427 public:
429 enum OffsetId {
431 };
433
434
440 void setOrigin(OffsetId id, uint32_t origin, ByteOrder byteOrder);
446 void setTarget(OffsetId id, uint32_t target);
448
450
451
452 void writeOffsets(BasicIo& io) const;
454 private:
456 struct OffsetData {
458 OffsetData() : origin_(0), target_(0), byteOrder_(littleEndian) {}
460 OffsetData(uint32_t origin, ByteOrder byteOrder) : origin_(origin), target_(0), byteOrder_(byteOrder) {}
461 // DATA
462 uint32_t origin_;
463 uint32_t target_;
464 ByteOrder byteOrder_;
465 };
467 typedef std::map<OffsetId, OffsetData> OffsetList;
468
469 // DATA
470 OffsetList offsetList_;
471
472 }; // class OffsetWriter
473
474 // Todo: Move this class to metadatum_int.hpp or tags_int.hpp
477 public:
479 explicit FindExifdatum(Exiv2::Internal::IfdId ifdId) : ifdId_(ifdId) {}
481 bool operator()(const Exiv2::Exifdatum& md) const { return ifdId_ == md.ifdId(); }
482
483 private:
485
486 }; // class FindExifdatum
487
488}} // namespace Internal, Exiv2
489
490#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:204
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:340
Unary predicate that matches an Exifdatum with a given IfdId.
Definition: tiffimage_int.hpp:476
FindExifdatum(Exiv2::Internal::IfdId ifdId)
Constructor, initializes the object with the IfdId to look for.
Definition: tiffimage_int.hpp:479
bool operator()(const Exiv2::Exifdatum &md) const
Returns true if IFD id matches.
Definition: tiffimage_int.hpp:481
Class to insert pointers or offsets to computed addresses at specific locations in an image....
Definition: tiffimage_int.hpp:426
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:2012
OffsetId
Identifiers for supported offsets.
Definition: tiffimage_int.hpp:429
@ cr2RawIfdOffset
CR2 RAW IFD offset, a pointer in the CR2 header to the 4th IFD in a CR2 image.
Definition: tiffimage_int.hpp:430
void writeOffsets(BasicIo &io) const
Write the offsets to the IO instance io.
Definition: tiffimage_int.cpp:2018
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:2007
Interface class for components of a TIFF directory hierarchy (Composite pattern). Both TIFF directori...
Definition: tiffcomposite_int.hpp:174
TIFF component factory.
Definition: tiffimage_int.hpp:251
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:1581
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:1555
Abstract base class defining the interface of an image header. Used internally by classes for TIFF-ba...
Definition: tiffimage_int.hpp:59
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:1866
virtual uint16_t tag() const
Return the tag value (magic number) which identifies the buffer as TIFF data.
Definition: tiffimage_int.cpp:1861
virtual uint32_t size() const
Return the size (in bytes) of the image header.
Definition: tiffimage_int.cpp:1856
virtual void setByteOrder(ByteOrder byteOrder)
Set the byte order.
Definition: tiffimage_int.cpp:1841
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:1799
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:1765
virtual ~TiffHeaderBase()=0
Virtual destructor.
Definition: tiffimage_int.cpp:1776
virtual void print(std::ostream &os, const std::string &prefix="") const
Print debug info for the image header to os.
Definition: tiffimage_int.cpp:1819
virtual ByteOrder byteOrder() const
Return the byte order (little or big endian).
Definition: tiffimage_int.cpp:1836
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:1780
virtual void setOffset(uint32_t offset)
Set the offset to the start of the root directory.
Definition: tiffimage_int.cpp:1851
virtual uint32_t offset() const
Return the offset to the start of the root directory.
Definition: tiffimage_int.cpp:1846
Standard TIFF header structure.
Definition: tiffimage_int.hpp:149
~TiffHeader()
Destructor.
Definition: tiffimage_int.cpp:1965
TiffHeader(ByteOrder byteOrder=littleEndian, uint32_t offset=0x00000008, bool hasImageTags=true)
Default constructor.
Definition: tiffimage_int.cpp:1959
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:1969
Table of TIFF decoding and encoding functions and find functions. This class is separated from the me...
Definition: tiffimage_int.hpp:379
static DecoderFct findDecoder(const std::string &make, uint32_t extendedTag, IfdId group)
Find the decoder function for a key.
Definition: tiffimage_int.cpp:1520
static EncoderFct findEncoder(const std::string &make, uint32_t extendedTag, IfdId group)
Find special encoder function for a key.
Definition: tiffimage_int.cpp:1534
Stateless parser class for data in TIFF format. Images use this class to decode and encode TIFF-based...
Definition: tiffimage_int.hpp:281
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:1597
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:1627
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition: iptc.hpp:173
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition: xmp_exiv2.hpp:173
const uint32_t root
Special tag: root IFD.
Definition: tiffcomposite_int.hpp:80
const uint32_t all
Special tag: all tags in a group.
Definition: tiffcomposite_int.hpp:82
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:92
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:108
void(TiffEncoder::* EncoderFct)(TiffEntryBase *, const Exifdatum *)
Function pointer type for a TiffDecoder member function to decode a TIFF component.
Definition: tifffwd_int.hpp:88
void(TiffDecoder::* DecoderFct)(const TiffEntryBase *)
Function pointer type for a TiffDecoder member function to decode a TIFF component.
Definition: tifffwd_int.hpp:83
std::vector< IfdId > PrimaryGroups
Type for a list of primary image groups.
Definition: tifffwd_int.hpp:114
std::stack< TiffPathItem > TiffPath
Stack to hold a path from the TIFF root element to a TIFF entry.
Definition: tifffwd_int.hpp:111
IfdId
Type to specify the IFD to which a metadata belongs.
Definition: tags_int.hpp:54
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:98
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:1873
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
@ string
IPTC string type.
Definition: types.hpp:147
EXIV2API ExifData::const_iterator make(const ExifData &ed)
Return the camera make.
Definition: easyaccess.cpp:428
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:113
WriteMethod
Type to indicate write method used by TIFF parsers.
Definition: types.hpp:116
Search key for TIFF group structure.
Definition: tiffimage_int.hpp:201
uint32_t e_
Extended tag.
Definition: tiffimage_int.hpp:204
Key(uint32_t e, IfdId g)
Constructor.
Definition: tiffimage_int.hpp:203
IfdId g_
Group
Definition: tiffimage_int.hpp:205
Data structure used as a row (element) of a table (array) defining the TIFF component used for each t...
Definition: tiffimage_int.hpp:199
IfdId group_
Group that contains the tag.
Definition: tiffimage_int.hpp:219
uint32_t extendedTag_
Tag (32 bit so that it can contain special tags)
Definition: tiffimage_int.hpp:218
bool operator==(const Key &key) const
Comparison operator to compare a TiffGroupStruct with a TiffGroupStruct::Key.
Definition: tiffimage_int.hpp:209
uint16_t tag() const
Return the tag corresponding to the extended tag.
Definition: tiffimage_int.hpp:215
NewTiffCompFct newTiffCompFct_
Function to create the correct TIFF component.
Definition: tiffimage_int.hpp:220
Search key for TIFF image tag structure.
Definition: tiffimage_int.hpp:177
Key(uint16_t t, IfdId g)
Constructor.
Definition: tiffimage_int.hpp:179
uint16_t t_
Tag
Definition: tiffimage_int.hpp:180
IfdId g_
Group
Definition: tiffimage_int.hpp:181
Data structure used to list image tags for TIFF and TIFF-like images.
Definition: tiffimage_int.hpp:175
bool operator==(const Key &key) const
Comparison operator to compare a TiffImgTagStruct with a TiffImgTagStruct::Key.
Definition: tiffimage_int.hpp:185
IfdId group_
Group that contains the image tag.
Definition: tiffimage_int.hpp:192
uint16_t tag_
Image tag.
Definition: tiffimage_int.hpp:191
TIFF mapping table for functions to decode special cases.
Definition: tiffcomposite_int.hpp:376
Search key for TIFF tree structure.
Definition: tiffimage_int.hpp:241
IfdId g_
Group
Definition: tiffimage_int.hpp:245
uint32_t r_
Root.
Definition: tiffimage_int.hpp:244
Key(uint32_t r, IfdId g)
Constructor.
Definition: tiffimage_int.hpp:243
Data structure used as a row of the table which describes TIFF trees. Multiple trees are needed as TI...
Definition: tiffimage_int.hpp:228
IfdId group_
Each group is a node in the tree.
Definition: tiffimage_int.hpp:235
bool operator==(const Key &key) const
Comparison operator to compare a TiffTreeStruct with a TiffTreeStruct::Key.
Definition: tiffimage_int.cpp:1550
uint32_t parentExtTag_
Parent tag (32 bit so that it can contain special tags)
Definition: tiffimage_int.hpp:237
uint32_t root_
Tree root element, identifies a tree.
Definition: tiffimage_int.hpp:234
IfdId parentGroup_
Parent group.
Definition: tiffimage_int.hpp:236
Internal Exif tag and type information.
Internal classes used in a TIFF composite structure.
Internal TIFF parser related typedefs and forward definitions.
Type definitions for Exiv2 and related functionality.