Loading...
Searching...
No Matches
tiffimage_int.hpp
// ***************************************************************** -*- C++ -*-
/*
* Copyright (C) 2004-2021 Exiv2 authors
* This program is part of the Exiv2 distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
*/
#ifndef TIFFIMAGE_INT_HPP_
#define TIFFIMAGE_INT_HPP_
// *****************************************************************************
// included header files
#include "tifffwd_int.hpp"
#include "tiffcomposite_int.hpp"
#include "image.hpp"
#include "tags_int.hpp"
#include "types.hpp"
// + standard includes
#include <map>
#include <utility>
// *****************************************************************************
// namespace extensions
namespace Exiv2 {
namespace Internal {
// *****************************************************************************
// class definitions
class TiffHeaderBase {
public:
TiffHeaderBase(uint16_t tag,
uint32_t size,
ByteOrder byteOrder,
uint32_t offset);
virtual ~TiffHeaderBase() =0;
virtual bool read(const byte* pData, uint32_t size);
virtual void setByteOrder(ByteOrder byteOrder);
virtual void setOffset(uint32_t offset);
virtual DataBuf write() const;
virtual void print(std::ostream& os, const std::string& prefix ="") const;
virtual ByteOrder byteOrder() const;
virtual uint32_t offset() const;
virtual uint32_t size() const;
virtual uint16_t tag() const;
virtual bool isImageTag( uint16_t tag,
IfdId group,
const PrimaryGroups* pPrimaryGroups) const;
private:
// DATA
const uint16_t tag_;
const uint32_t size_;
ByteOrder byteOrder_;
uint32_t offset_;
}; // class TiffHeaderBase
bool isTiffImageTag(uint16_t tag, IfdId group);
class TiffHeader : public TiffHeaderBase {
public:
TiffHeader(ByteOrder byteOrder =littleEndian,
uint32_t offset =0x00000008,
bool hasImageTags =true);
~TiffHeader();
bool isImageTag( uint16_t tag,
IfdId group,
const PrimaryGroups* pPrimaryGroups) const;
private:
// DATA
bool hasImageTags_;
}; // class TiffHeader
struct TiffImgTagStruct {
struct Key {
Key(uint16_t t, IfdId g) : t_(t), g_(g) {}
uint16_t t_;
IfdId g_;
};
bool operator==(const Key& key) const
{
return key.g_ == group_ && key.t_ == tag_;
}
// DATA
uint16_t tag_;
IfdId group_;
}; // struct TiffImgTagStruct
struct TiffGroupStruct {
struct Key {
Key(uint32_t e, IfdId g) : e_(e), g_(g) {}
uint32_t e_;
IfdId g_;
};
bool operator==(const Key& key) const
{
return key.g_ == group_
&& (Tag::all == extendedTag_ || key.e_ == extendedTag_);
}
uint16_t tag() const { return static_cast<uint16_t>(extendedTag_ & 0xffff); }
// DATA
uint32_t extendedTag_;
IfdId group_;
NewTiffCompFct newTiffCompFct_;
};
struct TiffTreeStruct {
struct Key;
bool operator==(const Key& key) const;
// DATA
uint32_t root_;
IfdId group_;
IfdId parentGroup_;
uint32_t parentExtTag_;
};
struct TiffTreeStruct::Key {
Key(uint32_t r, IfdId g) : r_(r), g_(g) {}
uint32_t r_;
IfdId g_;
};
class TiffCreator {
public:
static std::auto_ptr<TiffComponent> create(uint32_t extendedTag,
IfdId group);
static void getPath(TiffPath& tiffPath,
uint32_t extendedTag,
IfdId group,
uint32_t root);
private:
static const TiffTreeStruct tiffTreeStruct_[]; //<! TIFF tree structure
static const TiffGroupStruct tiffGroupStruct_[]; //<! TIFF group structure
}; // class TiffCreator
class TiffParserWorker {
public:
static ByteOrder decode(
ExifData& exifData,
IptcData& iptcData,
XmpData& xmpData,
const byte* pData,
uint32_t size,
uint32_t root,
FindDecoderFct findDecoderFct,
TiffHeaderBase* pHeader =0
);
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
);
private:
static std::auto_ptr<TiffComponent> parse(
const byte* pData,
uint32_t size,
uint32_t root,
TiffHeaderBase* pHeader
);
static void findPrimaryGroups(
PrimaryGroups& primaryGroups,
TiffComponent* pSourceDir
);
}; // class TiffParserWorker
class TiffMapping {
public:
static DecoderFct findDecoder(const std::string& make,
uint32_t extendedTag,
IfdId group);
static EncoderFct findEncoder(
const std::string& make,
uint32_t extendedTag,
IfdId group
);
private:
static const TiffMappingInfo tiffMappingInfo_[]; //<! TIFF mapping table
}; // class TiffMapping
class OffsetWriter {
public:
enum OffsetId {
cr2RawIfdOffset
};
void setOrigin(OffsetId id, uint32_t origin, ByteOrder byteOrder);
void setTarget(OffsetId id, uint32_t target);
void writeOffsets(BasicIo& io) const;
private:
struct OffsetData {
OffsetData() : origin_(0), target_(0), byteOrder_(littleEndian) {}
OffsetData(uint32_t origin, ByteOrder byteOrder) : origin_(origin), target_(0), byteOrder_(byteOrder) {}
// DATA
uint32_t origin_;
uint32_t target_;
ByteOrder byteOrder_;
};
typedef std::map<OffsetId, OffsetData> OffsetList;
// DATA
OffsetList offsetList_;
}; // class OffsetWriter
// Todo: Move this class to metadatum_int.hpp or tags_int.hpp
class FindExifdatum {
public:
explicit FindExifdatum(Exiv2::Internal::IfdId ifdId) : ifdId_(ifdId) {}
bool operator()(const Exiv2::Exifdatum& md) const { return ifdId_ == md.ifdId(); }
private:
Exiv2::Internal::IfdId ifdId_;
}; // class FindExifdatum
}} // namespace Internal, Exiv2
#endif // #ifndef TIFFIMAGE_INT_HPP_
Exiv2::BasicIo
An interface for simple binary IO.
Definition basicio.hpp:55
Exiv2::DataBuf
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition types.hpp:193
Exiv2::ExifData
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition exif.hpp:434
Exiv2::Exifdatum
An Exif metadatum, consisting of an ExifKey and a Value and methods to manipulate these.
Definition exif.hpp:59
Exiv2::Exifdatum::ifdId
int ifdId() const
Return the IFD id as an integer. (Do not use, this is meant for library internal use....
Definition exif.cpp:365
Exiv2::Internal::FindExifdatum
Unary predicate that matches an Exifdatum with a given IfdId.
Definition tiffimage_int.hpp:469
Exiv2::Internal::FindExifdatum::FindExifdatum
FindExifdatum(Exiv2::Internal::IfdId ifdId)
Constructor, initializes the object with the IfdId to look for.
Definition tiffimage_int.hpp:472
Exiv2::Internal::FindExifdatum::operator()
bool operator()(const Exiv2::Exifdatum &md) const
Returns true if IFD id matches.
Definition tiffimage_int.hpp:474
Exiv2::Internal::OffsetWriter
Class to insert pointers or offsets to computed addresses at specific locations in an image....
Definition tiffimage_int.hpp:419
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:2132
Exiv2::Internal::OffsetWriter::OffsetId
OffsetId
Identifiers for supported offsets.
Definition tiffimage_int.hpp:422
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:423
Exiv2::Internal::OffsetWriter::writeOffsets
void writeOffsets(BasicIo &io) const
Write the offsets to the IO instance io.
Definition tiffimage_int.cpp:2138
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:2127
Exiv2::Internal::TiffComponent
Interface class for components of a TIFF directory hierarchy (Composite pattern). Both TIFF directori...
Definition tiffcomposite_int.hpp:171
Exiv2::Internal::TiffCreator
TIFF component factory.
Definition tiffimage_int.hpp:244
Exiv2::Internal::TiffCreator::getPath
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
Exiv2::Internal::TiffCreator::create
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
Exiv2::Internal::TiffHeaderBase
Abstract base class defining the interface of an image header. Used internally by classes for TIFF-ba...
Definition tiffimage_int.hpp:52
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:1986
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:1981
Exiv2::Internal::TiffHeaderBase::size
virtual uint32_t size() const
Return the size (in bytes) of the image header.
Definition tiffimage_int.cpp:1976
Exiv2::Internal::TiffHeaderBase::setByteOrder
virtual void setByteOrder(ByteOrder byteOrder)
Set the byte order.
Definition tiffimage_int.cpp:1961
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:1919
Exiv2::Internal::TiffHeaderBase::~TiffHeaderBase
virtual ~TiffHeaderBase()=0
Virtual destructor.
Definition tiffimage_int.cpp:1896
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:1939
Exiv2::Internal::TiffHeaderBase::byteOrder
virtual ByteOrder byteOrder() const
Return the byte order (little or big endian).
Definition tiffimage_int.cpp:1956
Exiv2::Internal::TiffHeaderBase::read
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
Exiv2::Internal::TiffHeaderBase::setOffset
virtual void setOffset(uint32_t offset)
Set the offset to the start of the root directory.
Definition tiffimage_int.cpp:1971
Exiv2::Internal::TiffHeaderBase::offset
virtual uint32_t offset() const
Return the offset to the start of the root directory.
Definition tiffimage_int.cpp:1966
Exiv2::Internal::TiffHeader
Standard TIFF header structure.
Definition tiffimage_int.hpp:142
Exiv2::Internal::TiffHeader::~TiffHeader
~TiffHeader()
Destructor.
Definition tiffimage_int.cpp:2085
Exiv2::Internal::TiffHeader::isImageTag
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
Exiv2::Internal::TiffMapping
Table of TIFF decoding and encoding functions and find functions. This class is separated from the me...
Definition tiffimage_int.hpp:372
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:1640
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:1654
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:274
Exiv2::Internal::TiffParserWorker::decode
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
Exiv2::Internal::TiffParserWorker::encode
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
Exiv2::IptcData
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition iptc.hpp:170
Exiv2::XmpData
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition xmp_exiv2.hpp:166
Exiv2::Internal::Tag::all
const uint32_t all
Special tag: all tags in a group.
Definition tiffcomposite_int.hpp:75
Exiv2::Internal::FindDecoderFct
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
Exiv2::Internal::NewTiffCompFct
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
Exiv2::Internal::EncoderFct
void(TiffEncoder::* EncoderFct)(TiffEntryBase *, const Exifdatum *)
Function pointer type for a TiffDecoder member function to decode a TIFF component.
Definition tifffwd_int.hpp:81
Exiv2::Internal::DecoderFct
void(TiffDecoder::* DecoderFct)(const TiffEntryBase *)
Function pointer type for a TiffDecoder member function to decode a TIFF component.
Definition tifffwd_int.hpp:76
Exiv2::Internal::PrimaryGroups
std::vector< IfdId > PrimaryGroups
Type for a list of primary image groups.
Definition tifffwd_int.hpp:107
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:104
Exiv2::Internal::IfdId
IfdId
Type to specify the IFD to which a metadata belongs.
Definition tags_int.hpp:46
Exiv2::Internal::FindEncoderFct
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
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:1993
Exiv2
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition asfvideo.hpp:36
Exiv2::make
EXIV2API ExifData::const_iterator make(const ExifData &ed)
Return the camera make.
Definition easyaccess.cpp:437
Exiv2::ByteOrder
ByteOrder
Type to express the byte order (little or big endian)
Definition types.hpp:102
Exiv2::WriteMethod
WriteMethod
Type to indicate write method used by TIFF parsers.
Definition types.hpp:105
Exiv2::Internal::TiffGroupStruct::Key
Search key for TIFF group structure.
Definition tiffimage_int.hpp:194
Exiv2::Internal::TiffGroupStruct::Key::e_
uint32_t e_
Extended tag.
Definition tiffimage_int.hpp:197
Exiv2::Internal::TiffGroupStruct::Key::Key
Key(uint32_t e, IfdId g)
Constructor.
Definition tiffimage_int.hpp:196
Exiv2::Internal::TiffGroupStruct::Key::g_
IfdId g_
Group
Definition tiffimage_int.hpp:198
Exiv2::Internal::TiffGroupStruct
Data structure used as a row (element) of a table (array) defining the TIFF component used for each t...
Definition tiffimage_int.hpp:192
Exiv2::Internal::TiffGroupStruct::group_
IfdId group_
Group that contains the tag.
Definition tiffimage_int.hpp:212
Exiv2::Internal::TiffGroupStruct::extendedTag_
uint32_t extendedTag_
Tag (32 bit so that it can contain special tags)
Definition tiffimage_int.hpp:211
Exiv2::Internal::TiffGroupStruct::operator==
bool operator==(const Key &key) const
Comparison operator to compare a TiffGroupStruct with a TiffGroupStruct::Key.
Definition tiffimage_int.hpp:202
Exiv2::Internal::TiffGroupStruct::tag
uint16_t tag() const
Return the tag corresponding to the extended tag.
Definition tiffimage_int.hpp:208
Exiv2::Internal::TiffGroupStruct::newTiffCompFct_
NewTiffCompFct newTiffCompFct_
Function to create the correct TIFF component.
Definition tiffimage_int.hpp:213
Exiv2::Internal::TiffImgTagStruct::Key
Search key for TIFF image tag structure.
Definition tiffimage_int.hpp:170
Exiv2::Internal::TiffImgTagStruct::Key::Key
Key(uint16_t t, IfdId g)
Constructor.
Definition tiffimage_int.hpp:172
Exiv2::Internal::TiffImgTagStruct::Key::t_
uint16_t t_
Tag
Definition tiffimage_int.hpp:173
Exiv2::Internal::TiffImgTagStruct::Key::g_
IfdId g_
Group
Definition tiffimage_int.hpp:174
Exiv2::Internal::TiffImgTagStruct
Data structure used to list image tags for TIFF and TIFF-like images.
Definition tiffimage_int.hpp:168
Exiv2::Internal::TiffImgTagStruct::operator==
bool operator==(const Key &key) const
Comparison operator to compare a TiffImgTagStruct with a TiffImgTagStruct::Key.
Definition tiffimage_int.hpp:178
Exiv2::Internal::TiffImgTagStruct::group_
IfdId group_
Group that contains the image tag.
Definition tiffimage_int.hpp:185
Exiv2::Internal::TiffImgTagStruct::tag_
uint16_t tag_
Image tag.
Definition tiffimage_int.hpp:184
Exiv2::Internal::TiffMappingInfo
TIFF mapping table for functions to decode special cases.
Definition tiffcomposite_int.hpp:373
Exiv2::Internal::TiffTreeStruct::Key
Search key for TIFF tree structure.
Definition tiffimage_int.hpp:234
Exiv2::Internal::TiffTreeStruct::Key::g_
IfdId g_
Group
Definition tiffimage_int.hpp:238
Exiv2::Internal::TiffTreeStruct::Key::r_
uint32_t r_
Root.
Definition tiffimage_int.hpp:237
Exiv2::Internal::TiffTreeStruct::Key::Key
Key(uint32_t r, IfdId g)
Constructor.
Definition tiffimage_int.hpp:236
Exiv2::Internal::TiffTreeStruct
Data structure used as a row of the table which describes TIFF trees. Multiple trees are needed as TI...
Definition tiffimage_int.hpp:221
Exiv2::Internal::TiffTreeStruct::group_
IfdId group_
Each group is a node in the tree.
Definition tiffimage_int.hpp:228
Exiv2::Internal::TiffTreeStruct::operator==
bool operator==(const Key &key) const
Comparison operator to compare a TiffTreeStruct with a TiffTreeStruct::Key.
Definition tiffimage_int.cpp:1670
Exiv2::Internal::TiffTreeStruct::parentExtTag_
uint32_t parentExtTag_
Parent tag (32 bit so that it can contain special tags)
Definition tiffimage_int.hpp:230
Exiv2::Internal::TiffTreeStruct::root_
uint32_t root_
Tree root element, identifies a tree.
Definition tiffimage_int.hpp:227
Exiv2::Internal::TiffTreeStruct::parentGroup_
IfdId parentGroup_
Parent group.
Definition tiffimage_int.hpp:229