Loading...
Searching...
No Matches
image.hpp
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef IMAGE_HPP_
#define IMAGE_HPP_
// *****************************************************************************
#include "exiv2lib_export.h"
// included header files
#include "basicio.hpp"
#include "exif.hpp"
#include "image_types.hpp"
#include "iptc.hpp"
#include "xmp_exiv2.hpp"
// *****************************************************************************
// namespace extensions
namespace Exiv2 {
// *****************************************************************************
// class definitions
struct NativePreview {
size_t position_{};
size_t size_{};
size_t width_{};
size_t height_{};
std::string filter_;
std::string mimeType_;
};
using NativePreviewList = std::vector<NativePreview>;
enum PrintStructureOption { kpsNone, kpsBasic, kpsXMP, kpsRecursive, kpsIccProfile, kpsIptcErase };
class EXIV2API Image {
public:
using UniquePtr = std::unique_ptr<Image>;
Image(ImageType type, uint16_t supportedMetadata, BasicIo::UniquePtr io);
virtual ~Image() = default;
virtual void printStructure(std::ostream& out, PrintStructureOption option = kpsNone, size_t depth = 0);
virtual void readMetadata() = 0;
virtual void writeMetadata() = 0;
virtual void setExifData(const ExifData& exifData);
virtual void clearExifData();
virtual void setIptcData(const IptcData& iptcData);
virtual void clearIptcData();
virtual void setXmpPacket(const std::string& xmpPacket);
virtual void clearXmpPacket();
virtual void setXmpData(const XmpData& xmpData);
virtual void clearXmpData();
virtual void setComment(const std::string& comment);
virtual void clearComment();
virtual void setIccProfile(DataBuf&& iccProfile, bool bTestValid = true);
virtual void clearIccProfile();
virtual bool iccProfileDefined() {
return !iccProfile_.empty();
}
[[nodiscard]] virtual const DataBuf& iccProfile() const {
return iccProfile_;
}
virtual void setMetadata(const Image& image);
virtual void clearMetadata();
virtual ExifData& exifData();
virtual IptcData& iptcData();
virtual XmpData& xmpData();
virtual std::string& xmpPacket();
void writeXmpFromPacket(bool flag);
void setByteOrder(ByteOrder byteOrder);
void printTiffStructure(BasicIo& io, std::ostream& out, PrintStructureOption option, size_t depth, size_t offset = 0);
void printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStructureOption option, size_t start, bool bSwap,
char c, size_t depth);
static bool isBigEndianPlatform();
static bool isLittleEndianPlatform();
static bool isStringType(uint16_t type);
static bool isShortType(uint16_t type);
static bool isLongType(uint16_t type);
static bool isLongLongType(uint16_t type);
static bool isRationalType(uint16_t type);
static bool is2ByteType(uint16_t type);
static bool is4ByteType(uint16_t type);
static bool is8ByteType(uint16_t type);
static bool isPrintXMP(uint16_t type, Exiv2::PrintStructureOption option);
static bool isPrintICC(uint16_t type, Exiv2::PrintStructureOption option);
static uint64_t byteSwap(uint64_t value, bool bSwap);
static uint32_t byteSwap(uint32_t value, bool bSwap);
static uint16_t byteSwap(uint16_t value, bool bSwap);
static uint16_t byteSwap2(const DataBuf& buf, size_t offset, bool bSwap);
static uint32_t byteSwap4(const DataBuf& buf, size_t offset, bool bSwap);
static uint64_t byteSwap8(const DataBuf& buf, size_t offset, bool bSwap);
[[nodiscard]] ByteOrder byteOrder() const;
[[nodiscard]] bool good() const;
[[nodiscard]] virtual std::string mimeType() const = 0;
[[nodiscard]] virtual uint32_t pixelWidth() const;
[[nodiscard]] virtual uint32_t pixelHeight() const;
[[nodiscard]] virtual const ExifData& exifData() const;
[[nodiscard]] virtual const IptcData& iptcData() const;
[[nodiscard]] virtual const XmpData& xmpData() const;
[[nodiscard]] virtual std::string comment() const;
[[nodiscard]] virtual const std::string& xmpPacket() const;
[[nodiscard]] virtual BasicIo& io() const;
[[nodiscard]] AccessMode checkMode(MetadataId metadataId) const;
[[nodiscard]] bool supportsMetadata(MetadataId metadataId) const;
[[nodiscard]] bool writeXmpFromPacket() const;
[[nodiscard]] const NativePreviewList& nativePreviews() const;
void setTypeSupported(ImageType imageType, uint16_t supportedMetadata) {
imageType_ = imageType;
supportedMetadata_ = supportedMetadata;
}
[[nodiscard]] ImageType imageType() const {
return imageType_;
}
Image(const Image&) = delete;
Image& operator=(const Image&) = delete;
protected:
// DATA
BasicIo::UniquePtr io_;
ExifData exifData_;
IptcData iptcData_;
XmpData xmpData_;
DataBuf iccProfile_;
std::string comment_;
std::string xmpPacket_;
uint32_t pixelWidth_{0};
uint32_t pixelHeight_{0};
NativePreviewList nativePreviews_;
const std::string& tagName(uint16_t tag);
static const char* typeName(uint16_t tag);
private:
// DATA
ImageType imageType_;
uint16_t supportedMetadata_;
#ifdef EXV_HAVE_XMP_TOOLKIT
bool writeXmpFromPacket_{false};
#else
bool writeXmpFromPacket_{true};
#endif
ByteOrder byteOrder_{invalidByteOrder};
std::map<int, std::string> tags_;
bool init_{true};
}; // class Image
using NewInstanceFct = Image::UniquePtr (*)(BasicIo::UniquePtr io, bool create);
using IsThisTypeFct = bool (*)(BasicIo& iIo, bool advance);
class EXIV2API ImageFactory {
friend bool Image::good() const;
public:
static BasicIo::UniquePtr createIo(const std::string& path, bool useCurl = true);
static Image::UniquePtr open(const std::string& path, bool useCurl = true);
static Image::UniquePtr open(const byte* data, size_t size);
static Image::UniquePtr open(BasicIo::UniquePtr io);
static Image::UniquePtr create(ImageType type, const std::string& path);
static Image::UniquePtr create(ImageType type);
static Image::UniquePtr create(ImageType type, BasicIo::UniquePtr io);
static ImageType getType(const std::string& path);
static ImageType getType(const byte* data, size_t size);
static ImageType getType(BasicIo& io);
static AccessMode checkMode(ImageType type, MetadataId metadataId);
static bool checkType(ImageType type, BasicIo& io, bool advance);
}; // class ImageFactory
// *****************************************************************************
// template, inline and free functions
EXIV2API void append(Exiv2::Blob& blob, const byte* buf, size_t len);
} // namespace Exiv2
#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:506
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...
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:449
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::operator=
Image & operator=(const Image &)=delete
Assignment operator.
Exiv2::Image::mimeType
virtual std::string mimeType() const =0
Return the MIME type of the image.
Exiv2::Image::io_
BasicIo::UniquePtr io_
Image data IO pointer.
Definition image.hpp:463
Exiv2::Image::iccProfile
virtual const DataBuf & iccProfile() const
return iccProfile
Definition image.hpp:209
Exiv2::Image::nativePreviews_
NativePreviewList nativePreviews_
list of native previews
Definition image.hpp:472
Exiv2::Image::~Image
virtual ~Image()=default
Virtual Destructor.
Exiv2::Image::exifData_
ExifData exifData_
Exif data container.
Definition image.hpp:464
Exiv2::Image::xmpPacket_
std::string xmpPacket_
XMP packet.
Definition image.hpp:469
Exiv2::Image::iccProfileDefined
virtual bool iccProfileDefined()
Returns the status of the ICC profile in the image instance.
Definition image.hpp:202
Exiv2::Image::Image
Image(const Image &)=delete
Copy constructor.
Exiv2::Image::iptcData_
IptcData iptcData_
IPTC data container.
Definition image.hpp:465
Exiv2::Image::setTypeSupported
void setTypeSupported(ImageType imageType, uint16_t supportedMetadata)
set type support for this image format
Definition image.hpp:443
Exiv2::Image::comment_
std::string comment_
User comment.
Definition image.hpp:468
Exiv2::Image::UniquePtr
std::unique_ptr< Image > UniquePtr
Image auto_ptr type.
Definition image.hpp:53
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:467
Exiv2::Image::xmpData_
XmpData xmpData_
XMP data container.
Definition image.hpp:466
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:497
Exiv2::comment
@ comment
Exiv2 type for the Exif user comment.
Definition types.hpp:90
Exiv2::IsThisTypeFct
bool(*)(BasicIo &iIo, bool advance) IsThisTypeFct
Type for function pointer that checks image types.
Definition image.hpp:499
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:866
Exiv2::ByteOrder
ByteOrder
Type to express the byte order (little or big endian)
Definition types.hpp:34
Exiv2::ImageType
ImageType
Supported Image Formats.
Definition image_types.hpp:8
Exiv2::MetadataId
MetadataId
An identifier for each type of metadata.
Definition types.hpp:47
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::getType
TypeId getType()
Template to determine the TypeId for a type T.
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