Exiv2
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  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  [[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  explicit ExifThumbC(const ExifData& exifData);
224 
226 
227 
231  [[nodiscard]] DataBuf copy() const;
242  [[nodiscard]] size_t writeFile(const std::string& path) const;
247  [[nodiscard]] const char* mimeType() const;
252  [[nodiscard]] const char* extension() const;
254 
255  private:
256  // DATA
257  const ExifData& exifData_;
258 
259 }; // class ExifThumb
260 
272 class EXIV2API ExifThumb : public ExifThumbC {
273  public:
275 
276  explicit ExifThumb(ExifData& exifData);
279 
281 
282 
299  void setJpegThumbnail(const std::string& path, URational xres, URational yres, uint16_t unit);
317  void setJpegThumbnail(const byte* buf, size_t size, URational xres, URational yres, uint16_t unit);
331  void setJpegThumbnail(const std::string& path);
344  void setJpegThumbnail(const byte* buf, size_t size);
349  void erase();
351 
352  private:
353  // DATA
354  ExifData& exifData_;
355 
356 }; // class ExifThumb
357 
359 using ExifMetadata = std::list<Exifdatum>;
360 
373 class EXIV2API ExifData {
374  public:
376  using iterator = ExifMetadata::iterator;
378  using const_iterator = ExifMetadata::const_iterator;
379 
381 
382 
390  Exifdatum& operator[](const std::string& key);
397  void add(const ExifKey& key, const Value* pValue);
405  void add(const Exifdatum& exifdatum);
412  iterator erase(iterator pos);
418  iterator erase(iterator beg, iterator end);
423  void clear();
425  void sortByKey();
427  void sortByTag();
430  return exifMetadata_.begin();
431  }
434  return exifMetadata_.end();
435  }
440  iterator findKey(const ExifKey& key);
442 
444 
445  [[nodiscard]] const_iterator begin() const {
447  return exifMetadata_.begin();
448  }
450  [[nodiscard]] const_iterator end() const {
451  return exifMetadata_.end();
452  }
457  [[nodiscard]] const_iterator findKey(const ExifKey& key) const;
459  [[nodiscard]] bool empty() const {
460  return exifMetadata_.empty();
461  }
463  [[nodiscard]] size_t count() const {
464  return exifMetadata_.size();
465  }
467 
468  private:
469  // DATA
470  ExifMetadata exifMetadata_;
471 }; // class ExifData
472 
479 class EXIV2API ExifParser {
480  public:
494  static ByteOrder decode(ExifData& exifData, const byte* pData, size_t size);
533  static WriteMethod encode(Blob& blob, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData);
554  static void encode(Blob& blob, ByteOrder byteOrder, ExifData& exifData) {
555  encode(blob, nullptr, 0, byteOrder, exifData);
556  }
557 
558 }; // class ExifParser
559 
560 } // namespace Exiv2
561 
562 #endif // #ifndef EXIF_HPP_
const char * ifdName(IfdId ifdId)
Return the name of the IFD.
Definition: tags_int.cpp:2471
bool empty() const
Return true if there is no Exif metadata.
Definition: exif.hpp:459
std::list< Exifdatum > ExifMetadata
Container type to hold all metadata.
Definition: exif.hpp:359
Concrete keys for Exif metadata and access to Exif tag reference data.
Definition: tags.hpp:271
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition: exif.hpp:373
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:34
T getValue(const byte *buf, ByteOrder byteOrder)
Read a value of type T from the data buffer.
Definition: value.hpp:1332
Access and modify an Exif thumbnail image. This class implements manipulators to set and erase the th...
Definition: exif.hpp:272
TypeId
Exiv2 value type identifiers.
Definition: types.hpp:70
uint8_t byte
1 byte unsigned integer type.
Definition: types.hpp:26
ExifMetadata::const_iterator const_iterator
ExifMetadata const iterator type.
Definition: exif.hpp:378
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition: types.hpp:124
iterator begin()
Begin of the metadata.
Definition: exif.hpp:429
IfdId
Type to specify the IFD to which a metadata belongs.
Definition: tags.hpp:34
WriteMethod
Type to indicate write method used by TIFF parsers.
Definition: types.hpp:41
std::pair< int32_t, int32_t > Rational
8 byte signed rational type.
Definition: types.hpp:31
Stateless parser class for Exif data. Images use this class to decode and encode binary Exif data...
Definition: exif.hpp:479
iterator end()
End of the metadata.
Definition: exif.hpp:433
List of TIFF compression to MIME type mappings.
Definition: tiffimage.cpp:47
size_t count() const
Get the number of metadata entries.
Definition: exif.hpp:463
Exiv2::Exifdatum & setValue(Exiv2::Exifdatum &exifDatum, const T &value)
Set the value of exifDatum to value. If the object already has a value, it is replaced. Otherwise a new ValueType value is created and set to value.
Definition: exif.cpp:147
EXIV2API size_t writeFile(const DataBuf &buf, const std::string &path)
Write DataBuf buf to file path.
Definition: basicio.cpp:1746
const char * groupName(IfdId ifdId)
Return the group name for a group id.
Definition: tags_int.cpp:2477
std::unique_ptr< ExifKey > UniquePtr
Shortcut for an ExifKey auto pointer.
Definition: tags.hpp:274
Common interface for all types of values used with metadata.
Definition: value.hpp:33
static void encode(Blob &blob, ByteOrder byteOrder, ExifData &exifData)
Encode metadata from the provided metadata to Exif format.
Definition: exif.hpp:554
ExifMetadata::iterator iterator
ExifMetadata iterator type.
Definition: exif.hpp:376
Class CrwImage to access Canon CRW images. References: The Canon RAW (CRW) File Format by Phil Harv...
Definition: asfvideo.hpp:15
std::pair< uint32_t, uint32_t > URational
8 byte unsigned rational type.
Definition: types.hpp:29
An Exif metadatum, consisting of an ExifKey and a Value and methods to manipulate these...
Definition: exif.hpp:41
Abstract base class defining the interface to access information related to one metadata tag...
Definition: metadatum.hpp:103
std::vector< byte > Blob
Container for binary data.
Definition: types.hpp:102
const_iterator end() const
End of the metadata.
Definition: exif.hpp:450
Access to a Exif thumbnail image. This class provides higher level accessors to the thumbnail image t...
Definition: exif.hpp:217
std::unique_ptr< Value > UniquePtr
Shortcut for a Value auto pointer.
Definition: value.hpp:36