Exiv2
Loading...
Searching...
No Matches
image.hpp
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3#ifndef IMAGE_HPP_
4#define IMAGE_HPP_
5
6// *****************************************************************************
7#include "exiv2lib_export.h"
8
9// included header files
10#include "basicio.hpp"
11#include "exif.hpp"
12#include "image_types.hpp"
13#include "iptc.hpp"
14#include "xmp_exiv2.hpp"
15
16// *****************************************************************************
17// namespace extensions
18namespace Exiv2 {
19// *****************************************************************************
20// class definitions
21
24 size_t position_{};
25 size_t size_{};
26 size_t width_{};
27 size_t height_{};
28 std::string filter_;
29 std::string mimeType_;
30};
31
33using NativePreviewList = std::vector<NativePreview>;
34
38enum PrintStructureOption { kpsNone, kpsBasic, kpsXMP, kpsRecursive, kpsIccProfile, kpsIptcErase };
39
50class EXIV2API Image {
51 public:
53 using UniquePtr = std::unique_ptr<Image>;
54
56
57
62 Image(ImageType type, uint16_t supportedMetadata, BasicIo::UniquePtr io);
64 virtual ~Image() = default;
66
68
69
76 virtual void printStructure(std::ostream& out, PrintStructureOption option = kpsNone, size_t depth = 0);
90 virtual void readMetadata() = 0;
103 virtual void writeMetadata() = 0;
109 virtual void setExifData(const ExifData& exifData);
114 virtual void clearExifData();
120 virtual void setIptcData(const IptcData& iptcData);
125 virtual void clearIptcData();
137 virtual void setXmpPacket(const std::string& xmpPacket);
150 virtual void clearXmpPacket();
163 virtual void setXmpData(const XmpData& xmpData);
177 virtual void clearXmpData();
178
180 virtual void setComment(const std::string& comment);
181
186 virtual void clearComment();
193 virtual void setIccProfile(DataBuf&& iccProfile, bool bTestValid = true);
198 virtual void clearIccProfile();
202 virtual bool iccProfileDefined() {
203 return !iccProfile_.empty();
204 }
205
209 [[nodiscard]] virtual const DataBuf& iccProfile() const {
210 return iccProfile_;
211 }
212
219 virtual void setMetadata(const Image& image);
224 virtual void clearMetadata();
236 virtual ExifData& exifData();
248 virtual IptcData& iptcData();
260 virtual XmpData& xmpData();
264 virtual std::string& xmpPacket();
279 void writeXmpFromPacket(bool flag);
289 void setByteOrder(ByteOrder byteOrder);
290
296 void printTiffStructure(BasicIo& io, std::ostream& out, PrintStructureOption option, size_t depth, size_t offset = 0);
297
301 void printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStructureOption option, size_t start, bool bSwap,
302 char c, size_t depth);
303
307 static bool isBigEndianPlatform();
308
312 static bool isLittleEndianPlatform();
313
314 static bool isStringType(uint16_t type);
315 static bool isShortType(uint16_t type);
316 static bool isLongType(uint16_t type);
317 static bool isLongLongType(uint16_t type);
318 static bool isRationalType(uint16_t type);
319 static bool is2ByteType(uint16_t type);
320 static bool is4ByteType(uint16_t type);
321 static bool is8ByteType(uint16_t type);
322 static bool isPrintXMP(uint16_t type, Exiv2::PrintStructureOption option);
323 static bool isPrintICC(uint16_t type, Exiv2::PrintStructureOption option);
324
325 static uint64_t byteSwap(uint64_t value, bool bSwap);
326 static uint32_t byteSwap(uint32_t value, bool bSwap);
327 static uint16_t byteSwap(uint16_t value, bool bSwap);
328 static uint16_t byteSwap2(const DataBuf& buf, size_t offset, bool bSwap);
329 static uint32_t byteSwap4(const DataBuf& buf, size_t offset, bool bSwap);
330 static uint64_t byteSwap8(const DataBuf& buf, size_t offset, bool bSwap);
331
333
335
336
340 [[nodiscard]] ByteOrder byteOrder() const;
341
345 [[nodiscard]] bool good() const;
356 [[nodiscard]] virtual std::string mimeType() const = 0;
360 [[nodiscard]] virtual uint32_t pixelWidth() const;
364 [[nodiscard]] virtual uint32_t pixelHeight() const;
376 [[nodiscard]] virtual const ExifData& exifData() const;
388 [[nodiscard]] virtual const IptcData& iptcData() const;
400 [[nodiscard]] virtual const XmpData& xmpData() const;
404 [[nodiscard]] virtual std::string comment() const;
408 [[nodiscard]] virtual const std::string& xmpPacket() const;
423 [[nodiscard]] virtual BasicIo& io() const;
430 [[nodiscard]] AccessMode checkMode(MetadataId metadataId) const;
435 [[nodiscard]] bool supportsMetadata(MetadataId metadataId) const;
437 [[nodiscard]] bool writeXmpFromPacket() const;
439 [[nodiscard]] const NativePreviewList& nativePreviews() const;
441
443 void setTypeSupported(ImageType imageType, uint16_t supportedMetadata) {
444 imageType_ = imageType;
445 supportedMetadata_ = supportedMetadata;
446 }
447
449 [[nodiscard]] ImageType imageType() const {
450 return imageType_;
451 }
452
454
455
456 Image(const Image&) = delete;
458 Image& operator=(const Image&) = delete;
460
461 protected:
462 // DATA
468 std::string comment_;
469 std::string xmpPacket_;
470 uint32_t pixelWidth_{0};
471 uint32_t pixelHeight_{0};
473
475 const std::string& tagName(uint16_t tag);
476
478 static const char* typeName(uint16_t tag);
479
480 private:
481 // DATA
482 ImageType imageType_;
483 uint16_t supportedMetadata_;
484#ifdef EXV_HAVE_XMP_TOOLKIT
485 bool writeXmpFromPacket_{false};
486#else
487 bool writeXmpFromPacket_{true};
488#endif
489 ByteOrder byteOrder_{invalidByteOrder};
490
491 std::map<int, std::string> tags_;
492 bool init_{true};
493
494}; // class Image
495
499using IsThisTypeFct = bool (*)(BasicIo& iIo, bool advance);
500
506class EXIV2API ImageFactory {
507 friend bool Image::good() const;
508
509 public:
524 static BasicIo::UniquePtr createIo(const std::string& path, bool useCurl = true);
525
539 static Image::UniquePtr open(const std::string& path, bool useCurl = true);
540
552 static Image::UniquePtr open(const byte* data, size_t size);
570 static Image::UniquePtr open(BasicIo::UniquePtr io);
580 static Image::UniquePtr create(ImageType type, const std::string& path);
589 static Image::UniquePtr create(ImageType type);
590
606 static Image::UniquePtr create(ImageType type, BasicIo::UniquePtr io);
613 static ImageType getType(const std::string& path);
621 static ImageType getType(const byte* data, size_t size);
629 static ImageType getType(BasicIo& io);
638 static AccessMode checkMode(ImageType type, MetadataId metadataId);
659 static bool checkType(ImageType type, BasicIo& io, bool advance);
660}; // class ImageFactory
661
662// *****************************************************************************
663// template, inline and free functions
664
666EXIV2API void append(Exiv2::Blob& blob, const byte* buf, size_t len);
667
668} // namespace Exiv2
669
670#endif // #ifndef IMAGE_HPP_
An interface for simple binary IO.
Definition basicio.hpp:35
std::unique_ptr< BasicIo > UniquePtr
BasicIo auto_ptr type.
Definition basicio.hpp:38
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition exif.hpp:379
Returns an Image instance of the specified type.
Definition image.hpp:506
static Image::UniquePtr create(ImageType type, const std::string &path)
Create an Image subclass of the requested type by creating a new image file. If the file already exis...
Abstract base class defining the interface for an image. This is the top-level interface to the Exiv2...
Definition image.hpp:50
ImageType imageType() const
set type support for this image format
Definition image.hpp:449
virtual void readMetadata()=0
Read all metadata supported by a specific image format from the image. Before this method is called,...
Image & operator=(const Image &)=delete
Assignment operator.
virtual std::string mimeType() const =0
Return the MIME type of the image.
BasicIo::UniquePtr io_
Image data IO pointer.
Definition image.hpp:463
virtual const DataBuf & iccProfile() const
return iccProfile
Definition image.hpp:209
NativePreviewList nativePreviews_
list of native previews
Definition image.hpp:472
virtual ~Image()=default
Virtual Destructor.
ExifData exifData_
Exif data container.
Definition image.hpp:464
std::string xmpPacket_
XMP packet.
Definition image.hpp:469
virtual bool iccProfileDefined()
Returns the status of the ICC profile in the image instance.
Definition image.hpp:202
Image(const Image &)=delete
Copy constructor.
IptcData iptcData_
IPTC data container.
Definition image.hpp:465
void setTypeSupported(ImageType imageType, uint16_t supportedMetadata)
set type support for this image format
Definition image.hpp:443
std::string comment_
User comment.
Definition image.hpp:468
std::unique_ptr< Image > UniquePtr
Image auto_ptr type.
Definition image.hpp:53
virtual void writeMetadata()=0
Write metadata back to the image.
DataBuf iccProfile_
ICC buffer (binary data)
Definition image.hpp:467
XmpData xmpData_
XMP data container.
Definition image.hpp:466
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition iptc.hpp:153
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition xmp_exiv2.hpp:138
Encoding and decoding of Exif data.
Encoding and decoding of IPTC data.
Class CrwImage to access Canon CRW images. References: The Canon RAW (CRW) File Format by Phil Harv...
Definition asfvideo.hpp:15
PrintStructureOption
Options for printStructure.
Definition image.hpp:38
Image::UniquePtr(*)(BasicIo::UniquePtr io, bool create) NewInstanceFct
Type for function pointer that creates new Image instances.
Definition image.hpp:497
@ comment
Exiv2 type for the Exif user comment.
Definition types.hpp:90
bool(*)(BasicIo &iIo, bool advance) IsThisTypeFct
Type for function pointer that checks image types.
Definition image.hpp:499
EXIV2API void append(Exiv2::Blob &blob, const byte *buf, size_t len)
Append len bytes pointed to by buf to blob.
Definition image.cpp:866
ByteOrder
Type to express the byte order (little or big endian)
Definition types.hpp:34
ImageType
Supported Image Formats.
Definition image_types.hpp:8
MetadataId
An identifier for each type of metadata.
Definition types.hpp:47
std::vector< NativePreview > NativePreviewList
List of native previews. This is meant to be used only by the PreviewManager.
Definition image.hpp:33
TypeId getType()
Template to determine the TypeId for a type T.
std::vector< byte > Blob
Container for binary data.
Definition types.hpp:102
AccessMode
An identifier for each mode of metadata support.
Definition types.hpp:57
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition types.hpp:124
Native preview information. This is meant to be used only by the PreviewManager.
Definition image.hpp:23
std::string filter_
Filter.
Definition image.hpp:28
size_t height_
Height.
Definition image.hpp:27
size_t position_
Position.
Definition image.hpp:24
size_t width_
Width.
Definition image.hpp:26
std::string mimeType_
MIME type.
Definition image.hpp:29
size_t size_
Size.
Definition image.hpp:25