| Exiv2

Loading...
Searching...
No Matches
exif.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2
10#ifndef EXIF_HPP_
11#define EXIF_HPP_
12
13// *****************************************************************************
14#include "exiv2lib_export.h"
15
16// included header files
17#include "metadatum.hpp"
18#include "tags.hpp"
19
20// + standard includes
21#include <list>
22
23// *****************************************************************************
24// namespace extensions
29 namespace Exiv2 {
30// *****************************************************************************
31// class declarations
32 class ExifData;
33
34// *****************************************************************************
35// class definitions
36
41 class EXIV2API Exifdatum : public Metadatum {
42 template <typename T>
43 friend Exifdatum& setValue(Exifdatum&, const T&);
44
45 public:
47
48
59 explicit Exifdatum(const ExifKey& key, const Value* pValue = nullptr);
61 Exifdatum(const Exifdatum& rhs);
63 ~Exifdatum() override = default;
65
67
68
69 Exifdatum& operator=(const Exifdatum& rhs);
74 Exifdatum& operator=(const uint16_t& value);
79 Exifdatum& operator=(const uint32_t& value);
84 Exifdatum& operator=(const URational& value);
89 Exifdatum& operator=(const int16_t& value);
94 Exifdatum& operator=(const int32_t& value);
99 Exifdatum& operator=(const Rational& value);
104 Exifdatum& operator=(const std::string& value);
109 Exifdatum& operator=(const Value& value);
110 void setValue(const Value* pValue) override;
118 int setValue(const std::string& value) override;
132 int setDataArea(const byte* buf, size_t len) const;
134
136
137
138 [[nodiscard]] std::string key() const override;
139 [[nodiscard]] const char* familyName() const override;
140 [[nodiscard]] std::string groupName() const override;
141 [[nodiscard]] std::string tagName() const override;
142 [[nodiscard]] std::string tagLabel() const override;
143 [[nodiscard]] std::string tagDesc() const override;
144 [[nodiscard]] uint16_t tag() const override;
146 [[nodiscard]] IfdId ifdId() const;
148 [[nodiscard]] const char* ifdName() const;
150 [[nodiscard]] int idx() const;
162 size_t copy(byte* buf, ByteOrder byteOrder) const override;
163 std::ostream& write(std::ostream& os, const ExifData* pMetadata = nullptr) const override;
165 [[nodiscard]] TypeId typeId() const override;
167 [[nodiscard]] const char* typeName() const override;
169 [[nodiscard]] size_t typeSize() const override;
171 [[nodiscard]] size_t count() const override;
173 [[nodiscard]] size_t size() const override;
175 [[nodiscard]] std::string toString() const override;
176 [[nodiscard]] std::string toString(size_t n) const override;
177 [[nodiscard]] int64_t toInt64(size_t n = 0) const override;
178 [[nodiscard]] float toFloat(size_t n = 0) const override;
179 [[nodiscard]] Rational toRational(size_t n = 0) const override;
180 [[nodiscard]] Value::UniquePtr getValue() const override;
181 [[nodiscard]] const Value& value() const override;
183 [[nodiscard]] size_t sizeDataArea() const;
196 [[nodiscard]] DataBuf dataArea() const;
198
199 private:
200 // DATA
201 ExifKey::UniquePtr key_;
202 Value::UniquePtr value_;
203
204}; // class Exifdatum
205
217 class EXIV2API ExifThumbC {
218 public:
220
221
222 explicit ExifThumbC(const ExifData& exifData);
224
226
227
231 [[nodiscard]] DataBuf copy() const;
232#ifdef EXV_ENABLE_FILESYSTEM
243 [[nodiscard]] size_t writeFile(const std::string& path) const;
244#endif
249 [[nodiscard]] const char* mimeType() const;
254 [[nodiscard]] const char* extension() const;
256
257 private:
258 // DATA
259 const ExifData& exifData_;
260
261}; // class ExifThumb
262
274 class EXIV2API ExifThumb : public ExifThumbC {
275 public:
277
278
279 explicit ExifThumb(ExifData& exifData);
281
283
284#ifdef EXV_ENABLE_FILESYSTEM
302 void setJpegThumbnail(const std::string& path, URational xres, URational yres, uint16_t unit);
303#endif
321 void setJpegThumbnail(const byte* buf, size_t size, URational xres, URational yres, uint16_t unit);
322#ifdef EXV_ENABLE_FILESYSTEM
336 void setJpegThumbnail(const std::string& path);
337#endif
350 void setJpegThumbnail(const byte* buf, size_t size);
355 void erase();
357
358 private:
359 // DATA
360 ExifData& exifData_;
361
362}; // class ExifThumb
363
365 using ExifMetadata = std::list<Exifdatum>;
366
379 class EXIV2API ExifData {
380 public:
382 using iterator = ExifMetadata::iterator;
384 using const_iterator = ExifMetadata::const_iterator;
385
387
388
396 Exifdatum& operator[](const std::string& key);
403 void add(const ExifKey& key, const Value* pValue);
411 void add(const Exifdatum& exifdatum);
418 iterator erase(iterator pos);
424 iterator erase(iterator beg, iterator end);
429 void clear();
431 void sortByKey();
433 void sortByTag();
435 iterator begin() {
436 return exifMetadata_.begin();
437 }
438
439 iterator end() {
440 return exifMetadata_.end();
441 }
442
446 iterator findKey(const ExifKey& key);
448
450
451
452 [[nodiscard]] const_iterator begin() const {
453 return exifMetadata_.begin();
454 }
455
456 [[nodiscard]] const_iterator end() const {
457 return exifMetadata_.end();
458 }
459
463 [[nodiscard]] const_iterator findKey(const ExifKey& key) const;
465 [[nodiscard]] bool empty() const {
466 return exifMetadata_.empty();
467 }
468
469 [[nodiscard]] size_t count() const {
470 return exifMetadata_.size();
471 }
472
473
474 private:
475 // DATA
476 ExifMetadata exifMetadata_;
477}; // class ExifData
478
485 class EXIV2API ExifParser {
486 public:
500 static ByteOrder decode(ExifData& exifData, const byte* pData, size_t size);
539 static WriteMethod encode(Blob& blob, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData);
560 static void encode(Blob& blob, ByteOrder byteOrder, ExifData& exifData) {
561 encode(blob, nullptr, 0, byteOrder, exifData);
562 }
563
564}; // class ExifParser
565
566} // namespace Exiv2
567
568#endif // #ifndef EXIF_HPP_
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::ExifData::empty
bool empty() const
Return true if there is no Exif metadata.
Definition exif.hpp:465
Exiv2::ExifData::count
size_t count() const
Get the number of metadata entries.
Definition exif.hpp:469
Exiv2::ExifData::erase
iterator erase(iterator pos)
Delete the Exifdatum at iterator position pos, return the position of the next exifdatum....
Definition exif.cpp:486
Exiv2::ExifData::sortByTag
void sortByTag()
Sort metadata by tag.
Definition exif.cpp:478
Exiv2::ExifData::clear
void clear()
Delete all Exifdatum instances resulting in an empty container. Note that this also removes thumbnail...
Definition exif.cpp:470
Exiv2::ExifData::iterator
ExifMetadata::iterator iterator
ExifMetadata iterator type.
Definition exif.hpp:382
Exiv2::ExifData::begin
iterator begin()
Begin of the metadata.
Definition exif.hpp:435
Exiv2::ExifData::operator[]
Exifdatum & operator[](const std::string &key)
Returns a reference to the Exifdatum that is associated with a particular key. If ExifData does not a...
Definition exif.cpp:443
Exiv2::ExifData::end
const_iterator end() const
End of the metadata.
Definition exif.hpp:456
Exiv2::ExifData::add
void add(const ExifKey &key, const Value *pValue)
Add an Exifdatum from the supplied key and value pair. This method copies (clones) key and value....
Definition exif.cpp:453
Exiv2::ExifData::sortByKey
void sortByKey()
Sort metadata by key.
Definition exif.cpp:474
Exiv2::ExifData::end
iterator end()
End of the metadata.
Definition exif.hpp:439
Exiv2::ExifData::const_iterator
ExifMetadata::const_iterator const_iterator
ExifMetadata const iterator type.
Definition exif.hpp:384
Exiv2::ExifData::begin
const_iterator begin() const
Begin of the metadata.
Definition exif.hpp:452
Exiv2::ExifKey
Concrete keys for Exif metadata and access to Exif tag reference data.
Definition tags.hpp:271
Exiv2::ExifKey::UniquePtr
std::unique_ptr< ExifKey > UniquePtr
Shortcut for an ExifKey auto pointer.
Definition tags.hpp:274
Exiv2::ExifParser
Stateless parser class for Exif data. Images use this class to decode and encode binary Exif data.
Definition exif.hpp:485
Exiv2::ExifParser::encode
static void encode(Blob &blob, ByteOrder byteOrder, ExifData &exifData)
Encode metadata from the provided metadata to Exif format.
Definition exif.hpp:560
Exiv2::ExifParser::decode
static ByteOrder decode(ExifData &exifData, const byte *pData, size_t size)
Decode metadata from a buffer pData of length size with binary Exif data to the provided metadata con...
Definition exif.cpp:490
Exiv2::ExifParser::encode
static WriteMethod encode(Blob &blob, const byte *pData, size_t size, ByteOrder byteOrder, ExifData &exifData)
Encode Exif metadata from the provided metadata to binary Exif format.
Definition exif.cpp:509
Exiv2::ExifThumbC::ExifThumbC
ExifThumbC(const ExifData &exifData)
Constructor.
Definition exif.cpp:368
Exiv2::ExifThumbC::extension
const char * extension() const
Return the file extension for the format of the thumbnail (".tif" or ".jpg").
Definition exif.cpp:400
Exiv2::ExifThumbC::copy
DataBuf copy() const
Return the thumbnail image in a DataBuf. The caller owns the data buffer and DataBuf ensures that it ...
Definition exif.cpp:371
Exiv2::ExifThumbC::writeFile
size_t writeFile(const std::string &path) const
Write the thumbnail image to a file.
Exiv2::ExifThumbC::mimeType
const char * mimeType() const
Return the MIME type of the thumbnail, either "image/tiff" or "image/jpeg".
Definition exif.cpp:393
Exiv2::ExifThumb::ExifThumb
ExifThumb(ExifData &exifData)
Constructor.
Definition exif.cpp:407
Exiv2::ExifThumb::erase
void erase()
Delete the thumbnail from the Exif data. Removes all Exif.Thumbnail.*, i.e., Exif IFD1 tags.
Definition exif.cpp:439
Exiv2::ExifThumb::setJpegThumbnail
void setJpegThumbnail(const std::string &path, URational xres, URational yres, uint16_t unit)
Set the Exif thumbnail to the JPEG image path. Set XResolution, YResolution and ResolutionUnit to xre...
Exiv2::ExifThumb::setJpegThumbnail
void setJpegThumbnail(const std::string &path)
Set the Exif thumbnail to the JPEG image path.
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::Exifdatum::typeSize
size_t typeSize() const override
Return the size in bytes of one component of this type.
Definition exif.cpp:324
Exiv2::Exifdatum::getValue
Value::UniquePtr getValue() const override
Return an auto-pointer to a copy (clone) of the value. The caller owns this copy and the auto-poiner ...
Definition exif.cpp:356
Exiv2::Exifdatum::groupName
std::string groupName() const override
Return the name of the metadata group (which is also the second part of the key).
Definition exif.cpp:280
Exiv2::Exifdatum::toFloat
float toFloat(size_t n=0) const override
Return the n-th component of the value converted to float. The return value is -1 if the value is not...
Definition exif.cpp:348
Exiv2::Exifdatum::dataArea
DataBuf dataArea() const
Return a copy of the data area of the value. The caller owns this copy and DataBuf ensures that it wi...
Definition exif.cpp:364
Exiv2::Exifdatum::setValue
friend Exifdatum & setValue(Exifdatum &, const T &)
Set the value of exifDatum to value. If the object already has a value, it is replaced....
Definition exif.cpp:147
Exiv2::Exifdatum::key
std::string key() const override
Return the key of the Exifdatum.
Definition exif.cpp:272
Exiv2::Exifdatum::size
size_t size() const override
Return the size of the value in bytes.
Definition exif.cpp:332
Exiv2::Exifdatum::tagDesc
std::string tagDesc() const override
Return a description for the tag.
Definition exif.cpp:292
Exiv2::Exifdatum::typeId
TypeId typeId() const override
Return the type id of the value.
Definition exif.cpp:316
Exiv2::Exifdatum::toString
std::string toString() const override
Return the value as a string.
Definition exif.cpp:336
Exiv2::Exifdatum::idx
int idx() const
Return the index (unique id of this key within the original IFD).
Definition exif.cpp:308
Exiv2::Exifdatum::familyName
const char * familyName() const override
Return the name of the metadata family (which is also the first part of the key).
Definition exif.cpp:276
Exiv2::Exifdatum::typeName
const char * typeName() const override
Return the name of the type.
Definition exif.cpp:320
Exiv2::Exifdatum::count
size_t count() const override
Return the number of components in the value.
Definition exif.cpp:328
Exiv2::Exifdatum::copy
size_t copy(byte *buf, ByteOrder byteOrder) const override
Write value to a data buffer and return the number of bytes written.
Definition exif.cpp:312
Exiv2::Exifdatum::Exifdatum
Exifdatum(const ExifKey &key, const Value *pValue=nullptr)
Constructor for new tags created by an application. The Exifdatum is created from a key / value pair....
Definition exif.cpp:154
Exiv2::Exifdatum::ifdName
const char * ifdName() const
Return the name of the IFD.
Definition exif.cpp:304
Exiv2::Exifdatum::write
std::ostream & write(std::ostream &os, const ExifData *pMetadata=nullptr) const override
Write the interpreted value to an output stream, return the stream.
Definition exif.cpp:166
Exiv2::Exifdatum::value
const Value & value() const override
Return a constant reference to the value.
Definition exif.cpp:198
Exiv2::Exifdatum::sizeDataArea
size_t sizeDataArea() const
Return the size of the data area.
Definition exif.cpp:360
Exiv2::Exifdatum::operator=
Exifdatum & operator=(const Exifdatum &rhs)
Assignment operator.
Definition exif.cpp:204
Exiv2::Exifdatum::tagName
std::string tagName() const override
Return the name of the tag (which is also the third part of the key).
Definition exif.cpp:284
Exiv2::Exifdatum::tag
uint16_t tag() const override
Return the tag.
Definition exif.cpp:296
Exiv2::Exifdatum::toInt64
int64_t toInt64(size_t n=0) const override
Return the n-th component of the value converted to int64_t. The return value is -1 if the value is n...
Definition exif.cpp:344
Exiv2::Exifdatum::toRational
Rational toRational(size_t n=0) const override
Return the n-th component of the value converted to Rational. The return value is -1/1 if the value i...
Definition exif.cpp:352
Exiv2::Exifdatum::tagLabel
std::string tagLabel() const override
Return a label for the tag.
Definition exif.cpp:288
Exiv2::Exifdatum::~Exifdatum
~Exifdatum() override=default
Destructor.
Exiv2::Exifdatum::setDataArea
int setDataArea(const byte *buf, size_t len) const
Set the data area by copying (cloning) the buffer pointed to by buf.
Definition exif.cpp:268
Exiv2::Value
Common interface for all types of values used with metadata.
Definition value.hpp:33
Exiv2::Value::UniquePtr
std::unique_ptr< Value > UniquePtr
Shortcut for a Value auto pointer.
Definition value.hpp:36
Exiv2
Class CrwImage to access Canon CRW images. References: The Canon RAW (CRW) File Format by Phil Harv...
Definition asfvideo.hpp:15
Exiv2::IfdId
IfdId
Type to specify the IFD to which a metadata belongs.
Definition tags.hpp:34
Exiv2::TypeId
TypeId
Exiv2 value type identifiers.
Definition types.hpp:70
Exiv2::Rational
std::pair< int32_t, int32_t > Rational
8 byte signed rational type.
Definition types.hpp:31
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::ExifMetadata
std::list< Exifdatum > ExifMetadata
Container type to hold all metadata.
Definition exif.hpp:365
Exiv2::Blob
std::vector< byte > Blob
Container for binary data.
Definition types.hpp:102
Exiv2::URational
std::pair< uint32_t, uint32_t > URational
8 byte unsigned rational type.
Definition types.hpp:29
Exiv2::DataBuf
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition types.hpp:124