Exiv2
image.hpp
Go to the documentation of this file.
1// ***************************************************************** -*- C++ -*-
2/*
3 * Copyright (C) 2004-2018 Exiv2 authors
4 * This program is part of the Exiv2 distribution.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
19 */
23#ifndef IMAGE_HPP_
24#define IMAGE_HPP_
25
26// *****************************************************************************
27#include "exiv2lib_export.h"
28
29// included header files
30#include "basicio.hpp"
31#include "exif.hpp"
32#include "iptc.hpp"
33#include "xmp_exiv2.hpp"
34
35// + standard includes
36#include <string>
37#include <vector>
38
39// *****************************************************************************
40// namespace extensions
41namespace Exiv2 {
42
43// *****************************************************************************
44// class definitions
45
47 namespace ImageType {
48 const int none = 0;
49 }
50
53 long position_;
54 uint32_t size_;
55 uint32_t width_;
56 uint32_t height_;
59 };
60
62 typedef std::vector<NativePreview> NativePreviewList;
63
67 typedef enum { kpsNone, kpsBasic, kpsXMP, kpsRecursive
68 , kpsIccProfile , kpsIptcErase
70
81 class EXIV2API Image {
82 public:
84 typedef std::auto_ptr<Image> AutoPtr;
85
87
88
93 Image(int imageType,
94 uint16_t supportedMetadata,
97 virtual ~Image();
99
101
102
109 virtual void printStructure(std::ostream& out, PrintStructureOption option =kpsNone, int depth=0);
123 virtual void readMetadata() =0;
136 virtual void writeMetadata() =0;
142 virtual void setExifData(const ExifData& exifData);
147 virtual void clearExifData();
153 virtual void setIptcData(const IptcData& iptcData);
158 virtual void clearIptcData();
170 virtual void setXmpPacket(const std::string& xmpPacket);
183 virtual void clearXmpPacket();
196 virtual void setXmpData(const XmpData& xmpData);
210 virtual void clearXmpData();
216 virtual void setComment(const std::string& comment);
221 virtual void clearComment();
228 virtual void setIccProfile(DataBuf& iccProfile,bool bTestValid=true);
233 virtual void clearIccProfile();
238 virtual bool iccProfileDefined() { return iccProfile_.size_?true:false;}
239
243 virtual DataBuf* iccProfile() { return &iccProfile_; }
250 virtual void setMetadata(const Image& image);
255 virtual void clearMetadata();
267 virtual ExifData& exifData();
279 virtual IptcData& iptcData();
291 virtual XmpData& xmpData();
295 virtual std::string& xmpPacket();
310 void writeXmpFromPacket(bool flag);
320 void setByteOrder(ByteOrder byteOrder);
321
327 void printTiffStructure(BasicIo& io,std::ostream& out, PrintStructureOption option,int depth,size_t offset=0);
328
332 void printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStructureOption option,uint32_t start,bool bSwap,char c,int depth);
333
337 bool isBigEndianPlatform();
338
342 bool isLittleEndianPlatform();
343
344 bool isStringType(uint16_t type);
345 bool isShortType(uint16_t type);
346 bool isLongType(uint16_t type);
347 bool isLongLongType(uint16_t type);
348 bool isRationalType(uint16_t type);
349 bool is2ByteType(uint16_t type);
350 bool is4ByteType(uint16_t type);
351 bool is8ByteType(uint16_t type);
352 bool isPrintXMP(uint16_t type, Exiv2::PrintStructureOption option);
353 bool isPrintICC(uint16_t type, Exiv2::PrintStructureOption option);
354
355 uint64_t byteSwap(uint64_t value,bool bSwap) const;
356 uint32_t byteSwap(uint32_t value,bool bSwap) const;
357 uint16_t byteSwap(uint16_t value,bool bSwap) const;
358 uint16_t byteSwap2(const DataBuf& buf,size_t offset,bool bSwap) const;
359 uint32_t byteSwap4(const DataBuf& buf,size_t offset,bool bSwap) const;
360 uint64_t byteSwap8(const DataBuf& buf,size_t offset,bool bSwap) const;
361
363
365
366
370 ByteOrder byteOrder() const;
376 bool good() const;
387 virtual std::string mimeType() const =0;
391 virtual int pixelWidth() const;
395 virtual int pixelHeight() const;
407 virtual const ExifData& exifData() const;
419 virtual const IptcData& iptcData() const;
431 virtual const XmpData& xmpData() const;
435 virtual std::string comment() const;
439 virtual const std::string& xmpPacket() const;
454 virtual BasicIo& io() const;
461 AccessMode checkMode(MetadataId metadataId) const;
466 bool supportsMetadata(MetadataId metadataId) const;
468 bool writeXmpFromPacket() const;
470 const NativePreviewList& nativePreviews() const;
472
475 int imageType,
476 uint16_t supportedMetadata
477 ) {
478 imageType_ = imageType;
479 supportedMetadata_ = supportedMetadata;
480 }
481
483 int imageType() const { return imageType_; }
484
485 protected:
486 // DATA
497
499 const std::string& tagName(uint16_t tag);
500
502 const char* typeName(uint16_t tag) const;
503
504 private:
506
507
508 Image(const Image& rhs);
510 Image& operator=(const Image& rhs);
512
513 // DATA
514 int imageType_;
515 uint16_t supportedMetadata_;
516 bool writeXmpFromPacket_;
517 ByteOrder byteOrder_;
518
519 std::map<int,std::string> tags_;
520 bool init_;
521
522 }; // class Image
523
525 typedef Image::AutoPtr (*NewInstanceFct)(BasicIo::AutoPtr io, bool create);
527 typedef bool (*IsThisTypeFct)(BasicIo& iIo, bool advance);
528
534 class EXIV2API ImageFactory {
535 friend bool Image::good() const;
536 public:
551 static BasicIo::AutoPtr createIo(const std::string& path, bool useCurl = true);
552#ifdef EXV_UNICODE_PATH
557 static BasicIo::AutoPtr createIo(const std::wstring& wpath, bool useCurl = true);
558#endif
572 static Image::AutoPtr open(const std::string& path, bool useCurl = true);
573#ifdef EXV_UNICODE_PATH
578 static Image::AutoPtr open(const std::wstring& wpath, bool useCurl = true);
579#endif
591 static Image::AutoPtr open(const byte* data, long size);
609 static Image::AutoPtr open(BasicIo::AutoPtr io);
619 static Image::AutoPtr create(int type, const std::string& path);
620#ifdef EXV_UNICODE_PATH
625 static Image::AutoPtr create(int type, const std::wstring& wpath);
626#endif
635 static Image::AutoPtr create(int type);
650 static Image::AutoPtr create(int type, BasicIo::AutoPtr io);
657 static int getType(const std::string& path);
658#ifdef EXV_UNICODE_PATH
663 static int getType(const std::wstring& wpath);
664#endif
672 static int getType(const byte* data, long size);
680 static int getType(BasicIo& io);
689 static AccessMode checkMode(int type, MetadataId metadataId);
710 static bool checkType(int type, BasicIo& io, bool advance);
711
712 private:
714
715
716 ImageFactory();
718 ImageFactory(const ImageFactory& rhs);
720
721 }; // class ImageFactory
722
723// *****************************************************************************
724// template, inline and free functions
725
727 EXIV2API void append(Exiv2::Blob& blob, const byte* buf, uint32_t len);
728
729} // namespace Exiv2
730
731#endif // #ifndef IMAGE_HPP_
An interface for simple binary IO.
Definition: basicio.hpp:55
std::auto_ptr< BasicIo > AutoPtr
BasicIo auto_ptr type.
Definition: basicio.hpp:58
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition: types.hpp:204
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition: exif.hpp:434
Returns an Image instance of the specified type.
Definition: image.hpp:534
Abstract base class defining the interface for an image. This is the top-level interface to the Exiv2...
Definition: image.hpp:81
int pixelHeight_
image pixel height
Definition: image.hpp:495
int pixelWidth_
image pixel width
Definition: image.hpp:494
virtual void readMetadata()=0
Read all metadata supported by a specific image format from the image. Before this method is called,...
BasicIo::AutoPtr io_
Image data IO pointer.
Definition: image.hpp:487
void setTypeSupported(int imageType, uint16_t supportedMetadata)
set type support for this image format
Definition: image.hpp:474
bool good() const
Check if the Image instance is valid. Use after object construction.
Definition: image.cpp:738
virtual std::string mimeType() const =0
Return the MIME type of the image.
NativePreviewList nativePreviews_
list of native previews
Definition: image.hpp:496
std::auto_ptr< Image > AutoPtr
Image auto_ptr type.
Definition: image.hpp:84
int imageType() const
set type support for this image format
Definition: image.hpp:483
ExifData exifData_
Exif data container.
Definition: image.hpp:488
std::string xmpPacket_
XMP packet.
Definition: image.hpp:493
virtual DataBuf * iccProfile()
return iccProfile
Definition: image.hpp:243
virtual bool iccProfileDefined()
Erase iccProfile. the profile is not removed from the actual image until the writeMetadata() method i...
Definition: image.hpp:238
IptcData iptcData_
IPTC data container.
Definition: image.hpp:489
std::string comment_
User comment.
Definition: image.hpp:492
virtual void writeMetadata()=0
Write metadata back to the image.
DataBuf iccProfile_
ICC buffer (binary data)
Definition: image.hpp:491
XmpData xmpData_
XMP data container.
Definition: image.hpp:490
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition: iptc.hpp:173
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition: xmp_exiv2.hpp:173
Encoding and decoding of Exif data.
Encoding and decoding of IPTC data.
const int none
Not an image.
Definition: image.hpp:48
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
PrintStructureOption
Options for printStructure.
Definition: image.hpp:67
@ string
IPTC string type.
Definition: types.hpp:147
@ comment
Exiv2 type for the Exif user comment.
Definition: types.hpp:150
std::vector< byte > Blob
Container for binary data.
Definition: types.hpp:162
EXIV2API void append(Exiv2::Blob &blob, const byte *buf, uint32_t len)
Append len bytes pointed to by buf to blob.
Definition: image.cpp:984
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:113
bool(* IsThisTypeFct)(BasicIo &iIo, bool advance)
Type for function pointer that checks image types.
Definition: image.hpp:527
MetadataId
An identifier for each type of metadata.
Definition: types.hpp:119
TypeId getType()
Template to determine the TypeId for a type T.
AccessMode
An identifier for each mode of metadata support.
Definition: types.hpp:122
std::vector< NativePreview > NativePreviewList
List of native previews. This is meant to be used only by the PreviewManager.
Definition: image.hpp:62
Image::AutoPtr(* NewInstanceFct)(BasicIo::AutoPtr io, bool create)
Type for function pointer that creates new Image instances.
Definition: image.hpp:525
Native preview information. This is meant to be used only by the PreviewManager.
Definition: image.hpp:52
std::string filter_
Filter.
Definition: image.hpp:57
uint32_t width_
Width.
Definition: image.hpp:55
uint32_t size_
Size.
Definition: image.hpp:54
std::string mimeType_
MIME type.
Definition: image.hpp:58
uint32_t height_
Height.
Definition: image.hpp:56
long position_
Position.
Definition: image.hpp:53