| 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
18 namespace Exiv2 {
19// *****************************************************************************
20// class definitions
21
23 struct NativePreview {
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
33 using NativePreviewList = std::vector<NativePreview>;
34
38 enum PrintStructureOption { kpsNone, kpsBasic, kpsXMP, kpsRecursive, kpsIccProfile, kpsIptcErase };
39
50 class 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);
200 void appendIccProfile(const uint8_t* bytes, size_t size, bool bTestValid);
204 void checkIccProfile();
209 virtual void clearIccProfile();
213 [[nodiscard]] virtual bool iccProfileDefined() const {
214 return !iccProfile_.empty();
215 }
216
220 [[nodiscard]] virtual const DataBuf& iccProfile() const {
221 return iccProfile_;
222 }
223
230 virtual void setMetadata(const Image& image);
235 virtual void clearMetadata();
247 virtual ExifData& exifData();
259 virtual IptcData& iptcData();
271 virtual XmpData& xmpData();
275 virtual std::string& xmpPacket();
290 void writeXmpFromPacket(bool flag);
300 void setByteOrder(ByteOrder byteOrder);
301
307 void printTiffStructure(BasicIo& io, std::ostream& out, PrintStructureOption option, size_t depth, size_t offset = 0);
308
312 void printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStructureOption option, size_t start, bool bSwap,
313 char c, size_t depth);
314
318 static bool isBigEndianPlatform();
319
323 static bool isLittleEndianPlatform();
324
325 static bool isStringType(uint16_t type);
326 static bool isShortType(uint16_t type);
327 static bool isLongType(uint16_t type);
328 static bool isLongLongType(uint16_t type);
329 static bool isRationalType(uint16_t type);
330 static bool is2ByteType(uint16_t type);
331 static bool is4ByteType(uint16_t type);
332 static bool is8ByteType(uint16_t type);
333 static bool isPrintXMP(uint16_t type, Exiv2::PrintStructureOption option);
334 static bool isPrintICC(uint16_t type, Exiv2::PrintStructureOption option);
335
336 static uint64_t byteSwap(uint64_t value, bool bSwap);
337 static uint32_t byteSwap(uint32_t value, bool bSwap);
338 static uint16_t byteSwap(uint16_t value, bool bSwap);
339 static uint16_t byteSwap2(const DataBuf& buf, size_t offset, bool bSwap);
340 static uint32_t byteSwap4(const DataBuf& buf, size_t offset, bool bSwap);
341 static uint64_t byteSwap8(const DataBuf& buf, size_t offset, bool bSwap);
342
344
346
347
351 [[nodiscard]] ByteOrder byteOrder() const;
352
356 [[nodiscard]] bool good() const;
367 [[nodiscard]] virtual std::string mimeType() const = 0;
371 [[nodiscard]] virtual uint32_t pixelWidth() const;
375 [[nodiscard]] virtual uint32_t pixelHeight() const;
387 [[nodiscard]] virtual const ExifData& exifData() const;
399 [[nodiscard]] virtual const IptcData& iptcData() const;
411 [[nodiscard]] virtual const XmpData& xmpData() const;
415 [[nodiscard]] virtual std::string comment() const;
419 [[nodiscard]] virtual const std::string& xmpPacket() const;
434 [[nodiscard]] virtual BasicIo& io() const;
441 [[nodiscard]] AccessMode checkMode(MetadataId metadataId) const;
446 [[nodiscard]] bool supportsMetadata(MetadataId metadataId) const;
448 [[nodiscard]] bool writeXmpFromPacket() const;
450 [[nodiscard]] const NativePreviewList& nativePreviews() const;
452
454 void setTypeSupported(ImageType imageType, uint16_t supportedMetadata) {
455 imageType_ = imageType;
456 supportedMetadata_ = supportedMetadata;
457 }
458
460 [[nodiscard]] ImageType imageType() const {
461 return imageType_;
462 }
463
465
466
467 Image(const Image&) = delete;
469 Image& operator=(const Image&) = delete;
471
472 protected:
473 // DATA
474 BasicIo::UniquePtr io_;
475 ExifData exifData_;
476 IptcData iptcData_;
477 XmpData xmpData_;
478 DataBuf iccProfile_;
479 std::string comment_;
480 std::string xmpPacket_;
481 uint32_t pixelWidth_{0};
482 uint32_t pixelHeight_{0};
483 NativePreviewList nativePreviews_;
484
486 const std::string& tagName(uint16_t tag);
487
489 static const char* typeName(uint16_t tag);
490
491 private:
492 // DATA
493 ImageType imageType_;
494 uint16_t supportedMetadata_;
495#ifdef EXV_HAVE_XMP_TOOLKIT
496 bool writeXmpFromPacket_{false};
497#else
498 bool writeXmpFromPacket_{true};
499#endif
500 ByteOrder byteOrder_{invalidByteOrder};
501
502 std::map<int, std::string> tags_;
503 bool init_{true};
504
505}; // class Image
506
508 using NewInstanceFct = Image::UniquePtr (*)(BasicIo::UniquePtr io, bool create);
510 using IsThisTypeFct = bool (*)(BasicIo& iIo, bool advance);
511
517 class EXIV2API ImageFactory {
518 friend bool Image::good() const;
519
520 public:
535 static BasicIo::UniquePtr createIo(const std::string& path, bool useCurl = true);
536
550 static Image::UniquePtr open(const std::string& path, bool useCurl = true);
551
563 static Image::UniquePtr open(const byte* data, size_t size);
581 static Image::UniquePtr open(BasicIo::UniquePtr io);
591 static Image::UniquePtr create(ImageType type, const std::string& path);
600 static Image::UniquePtr create(ImageType type);
601
616
617 static Image::UniquePtr create(ImageType type, BasicIo::UniquePtr io);
624 static ImageType getType(const std::string& path);
632 static ImageType getType(const byte* data, size_t size);
640 static ImageType getType(BasicIo& io);
649 static AccessMode checkMode(ImageType type, MetadataId metadataId);
670 static bool checkType(ImageType type, BasicIo& io, bool advance);
671}; // class ImageFactory
672
673// *****************************************************************************
674// template, inline and free functions
675
677EXIV2API void append(Exiv2::Blob& blob, const byte* buf, size_t len);
678
679} // namespace Exiv2
680
681#endif // #ifndef IMAGE_HPP_
Exiv2::BasicIo
An interface for simple binary IO.
Definition basicio.hpp:35
Exiv2::BasicIo::UniquePtr
std::unique_ptr< BasicIo > UniquePtr
BasicIo auto_ptr type.
Definition basicio.hpp:38
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::ImageFactory
Returns an Image instance of the specified type.
Definition image.hpp:517
Exiv2::ImageFactory::checkType
static bool checkType(ImageType type, BasicIo &io, bool advance)
Determine if the content of io is an image of type.
Definition image.cpp:763
Exiv2::ImageFactory::open
static Image::UniquePtr open(const std::string &path, bool useCurl=true)
Create an Image subclass of the appropriate type by reading the specified file. Image type is derived...
Definition image.cpp:820
Exiv2::ImageFactory::checkMode
static AccessMode checkMode(ImageType type, MetadataId metadataId)
Returns the access mode or supported metadata functions for an image type and a metadata type.
Definition image.cpp:748
Exiv2::ImageFactory::createIo
static BasicIo::UniquePtr createIo(const std::string &path, bool useCurl=true)
Create the appropriate class type implemented BasicIo based on the protocol of the input.
Definition image.cpp:795
Exiv2::ImageFactory::create
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...
Definition image.cpp:847
Exiv2::ImageFactory::getType
static ImageType getType(const std::string &path)
Returns the image type of the provided file.
Definition image.cpp:769
Exiv2::Image
Abstract base class defining the interface for an image. This is the top-level interface to the Exiv2...
Definition image.hpp:50
Exiv2::Image::imageType
ImageType imageType() const
set type support for this image format
Definition image.hpp:460
Exiv2::Image::typeName
static const char * typeName(uint16_t tag)
Return tag type for given tag id.
Definition image.cpp:240
Exiv2::Image::clearIccProfile
virtual void clearIccProfile()
Erase iccProfile. the profile is not removed from the actual image until the writeMetadata() method i...
Definition image.cpp:656
Exiv2::Image::readMetadata
virtual void readMetadata()=0
Read all metadata supported by a specific image format from the image. Before this method is called,...
Exiv2::Image::setIptcData
virtual void setIptcData(const IptcData &iptcData)
Assign new IPTC data. The new IPTC data is not written to the image until the writeMetadata() method ...
Definition image.cpp:584
Exiv2::Image::operator=
Image & operator=(const Image &)=delete
Assignment operator.
Exiv2::Image::iccProfileDefined
virtual bool iccProfileDefined() const
Returns the status of the ICC profile in the image instance.
Definition image.hpp:213
Exiv2::Image::supportsMetadata
bool supportsMetadata(MetadataId metadataId) const
Check if image supports a particular type of metadata. This method is deprecated. Use checkMode() ins...
Definition image.cpp:716
Exiv2::Image::xmpPacket
virtual std::string & xmpPacket()
Return a modifiable reference to the raw XMP packet.
Definition image.cpp:544
Exiv2::Image::Image
Image(ImageType type, uint16_t supportedMetadata, BasicIo::UniquePtr io)
Constructor taking the image type, a bitmap of the supported metadata types and an auto-pointer that ...
Definition image.cpp:132
Exiv2::Image::pixelHeight
virtual uint32_t pixelHeight() const
Return the pixel height of the image.
Definition image.cpp:672
Exiv2::Image::setExifData
virtual void setExifData(const ExifData &exifData)
Assign new Exif data. The new Exif data is not written to the image until the writeMetadata() method ...
Definition image.cpp:576
Exiv2::Image::pixelWidth
virtual uint32_t pixelWidth() const
Return the pixel width of the image.
Definition image.cpp:668
Exiv2::Image::good
bool good() const
Check if the Image instance is valid. Use after object construction.
Definition image.cpp:708
Exiv2::Image::mimeType
virtual std::string mimeType() const =0
Return the MIME type of the image.
Exiv2::Image::setXmpData
virtual void setXmpData(const XmpData &xmpData)
Assign new XMP data. The new XMP data is not written to the image until the writeMetadata() method is...
Definition image.cpp:605
Exiv2::Image::comment
virtual std::string comment() const
Return a copy of the image comment. May be an empty string.
Definition image.cpp:688
Exiv2::Image::clearComment
virtual void clearComment()
Erase any buffered comment. Comment is not removed from the actual image until the writeMetadata() me...
Definition image.cpp:619
Exiv2::Image::tagName
const std::string & tagName(uint16_t tag)
Return tag name for given tag id.
Definition image.cpp:724
Exiv2::Image::clearExifData
virtual void clearExifData()
Erase any buffered Exif data. Exif data is not removed from the actual image until the writeMetadata(...
Definition image.cpp:572
Exiv2::Image::printStructure
virtual void printStructure(std::ostream &out, PrintStructureOption option=kpsNone, size_t depth=0)
Print out the structure of image file.
Definition image.cpp:136
Exiv2::Image::io_
BasicIo::UniquePtr io_
Image data IO pointer.
Definition image.hpp:474
Exiv2::Image::iccProfile
virtual const DataBuf & iccProfile() const
return iccProfile
Definition image.hpp:220
Exiv2::Image::setIccProfile
virtual void setIccProfile(DataBuf &&iccProfile, bool bTestValid=true)
Set the image iccProfile. The new profile is not written to the image until the writeMetadata() metho...
Definition image.cpp:627
Exiv2::Image::clearXmpPacket
virtual void clearXmpPacket()
Erase the buffered XMP packet. XMP data is not removed from the actual image until the writeMetadata(...
Definition image.cpp:588
Exiv2::Image::nativePreviews_
NativePreviewList nativePreviews_
list of native previews
Definition image.hpp:483
Exiv2::Image::io
virtual BasicIo & io() const
Return a reference to the BasicIo instance being used for Io.
Definition image.cpp:696
Exiv2::Image::clearIptcData
virtual void clearIptcData()
Erase any buffered IPTC data. IPTC data is not removed from the actual image until the writeMetadata(...
Definition image.cpp:580
Exiv2::Image::setXmpPacket
virtual void setXmpPacket(const std::string &xmpPacket)
Assign a raw XMP packet. The new XMP packet is not written to the image until the writeMetadata() met...
Definition image.cpp:593
Exiv2::Image::checkIccProfile
void checkIccProfile()
Throw an exception if the size at the beginning of the iccProfile isn't correct.
Definition image.cpp:646
Exiv2::Image::checkMode
AccessMode checkMode(MetadataId metadataId) const
Returns the access mode, i.e., the metadata functions, which this image supports for the metadata typ...
Definition image.cpp:720
Exiv2::Image::clearXmpData
virtual void clearXmpData()
Erase any buffered XMP data. XMP data is not removed from the actual image until the writeMetadata() ...
Definition image.cpp:600
Exiv2::Image::~Image
virtual ~Image()=default
Virtual Destructor.
Exiv2::Image::exifData_
ExifData exifData_
Exif data container.
Definition image.hpp:475
Exiv2::Image::xmpData
virtual XmpData & xmpData()
Returns an XmpData instance containing currently buffered XMP data.
Definition image.cpp:540
Exiv2::Image::xmpPacket_
std::string xmpPacket_
XMP packet.
Definition image.hpp:480
Exiv2::Image::writeXmpFromPacket
void writeXmpFromPacket(bool flag)
Determine the source when writing XMP.
Definition image.cpp:611
Exiv2::Image::Image
Image(const Image &)=delete
Copy constructor.
Exiv2::Image::iptcData_
IptcData iptcData_
IPTC data container.
Definition image.hpp:476
Exiv2::Image::iptcData
virtual IptcData & iptcData()
Returns an IptcData instance containing currently buffered IPTC data.
Definition image.cpp:536
Exiv2::Image::exifData
virtual ExifData & exifData()
Returns an ExifData instance containing currently buffered Exif data.
Definition image.cpp:532
Exiv2::Image::pixelHeight_
uint32_t pixelHeight_
image pixel height
Definition image.hpp:482
Exiv2::Image::setTypeSupported
void setTypeSupported(ImageType imageType, uint16_t supportedMetadata)
set type support for this image format
Definition image.hpp:454
Exiv2::Image::comment_
std::string comment_
User comment.
Definition image.hpp:479
Exiv2::Image::UniquePtr
std::unique_ptr< Image > UniquePtr
Image auto_ptr type.
Definition image.hpp:53
Exiv2::Image::pixelWidth_
uint32_t pixelWidth_
image pixel width
Definition image.hpp:481
Exiv2::Image::appendIccProfile
void appendIccProfile(const uint8_t *bytes, size_t size, bool bTestValid)
Append more bytes to the iccProfile.
Definition image.cpp:634
Exiv2::Image::setComment
virtual void setComment(const std::string &comment)
Set the image comment. The comment is written to the image when writeMetadata() is called.
Definition image.cpp:623
Exiv2::Image::writeMetadata
virtual void writeMetadata()=0
Write metadata back to the image.
Exiv2::Image::iccProfile_
DataBuf iccProfile_
ICC buffer (binary data).
Definition image.hpp:478
Exiv2::Image::nativePreviews
const NativePreviewList & nativePreviews() const
Return list of native previews. This is meant to be used only by the PreviewManager.
Definition image.cpp:704
Exiv2::Image::xmpData_
XmpData xmpData_
XMP data container.
Definition image.hpp:477
Exiv2::IptcData
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition iptc.hpp:153
Exiv2::XmpData
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition xmp_exiv2.hpp:138
exif.hpp
Encoding and decoding of Exif data.
iptc.hpp
Encoding and decoding of IPTC data.
Exiv2
Class CrwImage to access Canon CRW images. References: The Canon RAW (CRW) File Format by Phil Harv...
Definition asfvideo.hpp:15
Exiv2::PrintStructureOption
PrintStructureOption
Options for printStructure.
Definition image.hpp:38
Exiv2::NewInstanceFct
Image::UniquePtr(*)(BasicIo::UniquePtr io, bool create) NewInstanceFct
Type for function pointer that creates new Image instances.
Definition image.hpp:508
Exiv2::append
EXIV2API void append(Exiv2::Blob &blob, const byte *buf, size_t len)
Append len bytes pointed to by buf to blob.
Definition image.cpp:882
Exiv2::ByteOrder
ByteOrder
Type to express the byte order (little or big endian).
Definition types.hpp:34
Exiv2::IsThisTypeFct
bool(*)(BasicIo &iIo, bool advance) IsThisTypeFct
Type for function pointer that checks image types.
Definition image.hpp:510
Exiv2::ImageType
ImageType
Supported Image Formats.
Definition image_types.hpp:8
Exiv2::NativePreviewList
std::vector< NativePreview > NativePreviewList
List of native previews. This is meant to be used only by the PreviewManager.
Definition image.hpp:33
Exiv2::MetadataId
MetadataId
An identifier for each type of metadata.
Definition types.hpp:47
Exiv2::Blob
std::vector< byte > Blob
Container for binary data.
Definition types.hpp:102
Exiv2::AccessMode
AccessMode
An identifier for each mode of metadata support.
Definition types.hpp:57
Exiv2::DataBuf
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition types.hpp:124
Exiv2::NativePreview
Native preview information. This is meant to be used only by the PreviewManager.
Definition image.hpp:23
Exiv2::NativePreview::filter_
std::string filter_
Filter.
Definition image.hpp:28
Exiv2::NativePreview::height_
size_t height_
Height.
Definition image.hpp:27
Exiv2::NativePreview::position_
size_t position_
Position.
Definition image.hpp:24
Exiv2::NativePreview::width_
size_t width_
Width.
Definition image.hpp:26
Exiv2::NativePreview::mimeType_
std::string mimeType_
MIME type.
Definition image.hpp:29
Exiv2::NativePreview::size_
size_t size_
Size.
Definition image.hpp:25