Loading...
Searching...
No Matches
image.hpp
// ***************************************************************** -*- C++ -*-
/*
* Copyright (C) 2004-2021 Exiv2 authors
* This program is part of the Exiv2 distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
*/
#ifndef IMAGE_HPP_
#define IMAGE_HPP_
// *****************************************************************************
#include "exiv2lib_export.h"
// included header files
#include "basicio.hpp"
#include "exif.hpp"
#include "iptc.hpp"
#include "xmp_exiv2.hpp"
// + standard includes
#include <string>
#include <vector>
// *****************************************************************************
// namespace extensions
namespace Exiv2 {
// *****************************************************************************
// class definitions
namespace ImageType {
const int none = 0;
}
struct NativePreview {
long position_;
uint32_t size_;
uint32_t width_;
uint32_t height_;
std::string filter_;
std::string mimeType_;
};
typedef std::vector<NativePreview> NativePreviewList;
typedef enum { kpsNone, kpsBasic, kpsXMP, kpsRecursive
, kpsIccProfile , kpsIptcErase
} PrintStructureOption;
class EXIV2API Image {
public:
typedef std::auto_ptr<Image> AutoPtr;
Image(int imageType,
uint16_t supportedMetadata,
BasicIo::AutoPtr io);
virtual ~Image();
virtual void printStructure(std::ostream& out, PrintStructureOption option =kpsNone, int 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_.size_?true:false;}
virtual DataBuf* iccProfile() { 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,int depth,size_t offset=0);
void printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStructureOption option,uint32_t start,bool bSwap,char c,int depth);
bool isBigEndianPlatform();
bool isLittleEndianPlatform();
bool isStringType(uint16_t type);
bool isShortType(uint16_t type);
bool isLongType(uint16_t type);
bool isLongLongType(uint16_t type);
bool isRationalType(uint16_t type);
bool is2ByteType(uint16_t type);
bool is4ByteType(uint16_t type);
bool is8ByteType(uint16_t type);
bool isPrintXMP(uint16_t type, Exiv2::PrintStructureOption option);
bool isPrintICC(uint16_t type, Exiv2::PrintStructureOption option);
uint64_t byteSwap(uint64_t value,bool bSwap) const;
uint32_t byteSwap(uint32_t value,bool bSwap) const;
uint16_t byteSwap(uint16_t value,bool bSwap) const;
uint16_t byteSwap2(const DataBuf& buf,size_t offset,bool bSwap) const;
uint32_t byteSwap4(const DataBuf& buf,size_t offset,bool bSwap) const;
uint64_t byteSwap8(const DataBuf& buf,size_t offset,bool bSwap) const;
ByteOrder byteOrder() const;
bool good() const;
virtual std::string mimeType() const =0;
virtual int pixelWidth() const;
virtual int pixelHeight() const;
virtual const ExifData& exifData() const;
virtual const IptcData& iptcData() const;
virtual const XmpData& xmpData() const;
virtual std::string comment() const;
virtual const std::string& xmpPacket() const;
virtual BasicIo& io() const;
AccessMode checkMode(MetadataId metadataId) const;
bool supportsMetadata(MetadataId metadataId) const;
bool writeXmpFromPacket() const;
const NativePreviewList& nativePreviews() const;
void setTypeSupported(
int imageType,
uint16_t supportedMetadata
) {
imageType_ = imageType;
supportedMetadata_ = supportedMetadata;
}
int imageType() const { return imageType_; }
protected:
// DATA
BasicIo::AutoPtr io_;
ExifData exifData_;
IptcData iptcData_;
XmpData xmpData_;
DataBuf iccProfile_;
std::string comment_;
std::string xmpPacket_;
int pixelWidth_;
int pixelHeight_;
NativePreviewList nativePreviews_;
const std::string& tagName(uint16_t tag);
const char* typeName(uint16_t tag) const;
private:
Image(const Image& rhs);
Image& operator=(const Image& rhs);
// DATA
int imageType_;
uint16_t supportedMetadata_;
bool writeXmpFromPacket_;
ByteOrder byteOrder_;
std::map<int,std::string> tags_;
bool init_;
}; // class Image
typedef Image::AutoPtr (*NewInstanceFct)(BasicIo::AutoPtr io, bool create);
typedef bool (*IsThisTypeFct)(BasicIo& iIo, bool advance);
class EXIV2API ImageFactory {
friend bool Image::good() const;
public:
static BasicIo::AutoPtr createIo(const std::string& path, bool useCurl = true);
#ifdef EXV_UNICODE_PATH
static BasicIo::AutoPtr createIo(const std::wstring& wpath, bool useCurl = true);
#endif
static Image::AutoPtr open(const std::string& path, bool useCurl = true);
#ifdef EXV_UNICODE_PATH
static Image::AutoPtr open(const std::wstring& wpath, bool useCurl = true);
#endif
static Image::AutoPtr open(const byte* data, long size);
static Image::AutoPtr open(BasicIo::AutoPtr io);
static Image::AutoPtr create(int type, const std::string& path);
#ifdef EXV_UNICODE_PATH
static Image::AutoPtr create(int type, const std::wstring& wpath);
#endif
static Image::AutoPtr create(int type);
static Image::AutoPtr create(int type, BasicIo::AutoPtr io);
static int getType(const std::string& path);
#ifdef EXV_UNICODE_PATH
static int getType(const std::wstring& wpath);
#endif
static int getType(const byte* data, long size);
static int getType(BasicIo& io);
static AccessMode checkMode(int type, MetadataId metadataId);
static bool checkType(int type, BasicIo& io, bool advance);
private:
ImageFactory();
ImageFactory(const ImageFactory& rhs);
}; // class ImageFactory
// *****************************************************************************
// template, inline and free functions
EXIV2API void append(Exiv2::Blob& blob, const byte* buf, uint32_t len);
} // namespace Exiv2
#endif // #ifndef IMAGE_HPP_
Exiv2::BasicIo
An interface for simple binary IO.
Definition basicio.hpp:55
Exiv2::BasicIo::AutoPtr
std::auto_ptr< BasicIo > AutoPtr
BasicIo auto_ptr type.
Definition basicio.hpp:58
Exiv2::DataBuf
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition types.hpp:193
Exiv2::ExifData
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition exif.hpp:434
Exiv2::ImageFactory
Returns an Image instance of the specified type.
Definition image.hpp:531
Exiv2::Image
Abstract base class defining the interface for an image. This is the top-level interface to the Exiv2...
Definition image.hpp:78
Exiv2::Image::pixelHeight_
int pixelHeight_
image pixel height
Definition image.hpp:492
Exiv2::Image::pixelWidth_
int pixelWidth_
image pixel width
Definition image.hpp:491
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::io_
BasicIo::AutoPtr io_
Image data IO pointer.
Definition image.hpp:484
Exiv2::Image::setTypeSupported
void setTypeSupported(int imageType, uint16_t supportedMetadata)
set type support for this image format
Definition image.hpp:471
Exiv2::Image::mimeType
virtual std::string mimeType() const =0
Return the MIME type of the image.
Exiv2::Image::nativePreviews_
NativePreviewList nativePreviews_
list of native previews
Definition image.hpp:493
Exiv2::Image::AutoPtr
std::auto_ptr< Image > AutoPtr
Image auto_ptr type.
Definition image.hpp:81
Exiv2::Image::imageType
int imageType() const
set type support for this image format
Definition image.hpp:480
Exiv2::Image::exifData_
ExifData exifData_
Exif data container.
Definition image.hpp:485
Exiv2::Image::xmpPacket_
std::string xmpPacket_
XMP packet.
Definition image.hpp:490
Exiv2::Image::iccProfile
virtual DataBuf * iccProfile()
return iccProfile
Definition image.hpp:240
Exiv2::Image::iccProfileDefined
virtual bool iccProfileDefined()
Erase iccProfile. the profile is not removed from the actual image until the writeMetadata() method i...
Definition image.hpp:235
Exiv2::Image::iptcData_
IptcData iptcData_
IPTC data container.
Definition image.hpp:486
Exiv2::Image::comment_
std::string comment_
User comment.
Definition image.hpp:489
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:488
Exiv2::Image::xmpData_
XmpData xmpData_
XMP data container.
Definition image.hpp:487
Exiv2::IptcData
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition iptc.hpp:170
Exiv2::XmpData
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition xmp_exiv2.hpp:166
exif.hpp
Encoding and decoding of Exif data.
iptc.hpp
Encoding and decoding of IPTC data.
Exiv2::ImageType::none
const int none
Not an image.
Definition image.hpp:45
Exiv2
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition asfvideo.hpp:36
Exiv2::PrintStructureOption
PrintStructureOption
Options for printStructure.
Definition image.hpp:64
Exiv2::comment
@ comment
Exiv2 type for the Exif user comment.
Definition types.hpp:139
Exiv2::Blob
std::vector< byte > Blob
Container for binary data.
Definition types.hpp:151
Exiv2::append
EXIV2API void append(Exiv2::Blob &blob, const byte *buf, uint32_t len)
Append len bytes pointed to by buf to blob.
Definition image.cpp:1015
Exiv2::ByteOrder
ByteOrder
Type to express the byte order (little or big endian)
Definition types.hpp:102
Exiv2::IsThisTypeFct
bool(* IsThisTypeFct)(BasicIo &iIo, bool advance)
Type for function pointer that checks image types.
Definition image.hpp:524
Exiv2::MetadataId
MetadataId
An identifier for each type of metadata.
Definition types.hpp:108
Exiv2::getType
TypeId getType()
Template to determine the TypeId for a type T.
Exiv2::AccessMode
AccessMode
An identifier for each mode of metadata support.
Definition types.hpp:111
Exiv2::NativePreviewList
std::vector< NativePreview > NativePreviewList
List of native previews. This is meant to be used only by the PreviewManager.
Definition image.hpp:59
Exiv2::NewInstanceFct
Image::AutoPtr(* NewInstanceFct)(BasicIo::AutoPtr io, bool create)
Type for function pointer that creates new Image instances.
Definition image.hpp:522
Exiv2::NativePreview
Native preview information. This is meant to be used only by the PreviewManager.
Definition image.hpp:49
Exiv2::NativePreview::filter_
std::string filter_
Filter.
Definition image.hpp:54
Exiv2::NativePreview::width_
uint32_t width_
Width.
Definition image.hpp:52
Exiv2::NativePreview::size_
uint32_t size_
Size.
Definition image.hpp:51
Exiv2::NativePreview::mimeType_
std::string mimeType_
MIME type.
Definition image.hpp:55
Exiv2::NativePreview::height_
uint32_t height_
Height.
Definition image.hpp:53
Exiv2::NativePreview::position_
long position_
Position.
Definition image.hpp:50