Exiv2
preview.hpp
1 // ***************************************************************** -*- C++ -*-
2 /*
3  * Copyright (C) 2004-2021 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  */
20 #ifndef PREVIEW_HPP_
21 #define PREVIEW_HPP_
22 
23 // *****************************************************************************
24 #include "exiv2lib_export.h"
25 
26 #include "image.hpp"
27 
28 // *****************************************************************************
29 // namespace extensions
30 namespace Exiv2 {
31 
32 // *****************************************************************************
33 // class definitions
34 
36  typedef int PreviewId;
37 
41  struct EXIV2API PreviewProperties {
43  std::string mimeType_;
45  std::string extension_;
46 #ifdef EXV_UNICODE_PATH
47  std::wstring wextension_;
49 #endif
50  uint32_t size_;
53  uint32_t width_;
55  uint32_t height_;
58  };
59 
61  typedef std::vector<PreviewProperties> PreviewPropertiesList;
62 
66  class EXIV2API PreviewImage {
67  friend class PreviewManager;
68  public:
70 
71  PreviewImage(const PreviewImage& rhs);
74  ~PreviewImage();
76 
78 
79  PreviewImage& operator=(const PreviewImage& rhs);
82 
84 
85 
89  DataBuf copy() const;
93  const byte* pData() const;
97  uint32_t size() const;
108  long writeFile(const std::string& path) const;
109 #ifdef EXV_UNICODE_PATH
110 
114  long writeFile(const std::wstring& wpath) const;
115 #endif
116 
120  std::string mimeType() const;
125  std::string extension() const;
126 #ifdef EXV_UNICODE_PATH
127 
132  std::wstring wextension() const;
133 #endif
134 
137  uint32_t width() const;
141  uint32_t height() const;
145  PreviewId id() const;
147 
148  private:
150  PreviewImage(const PreviewProperties& properties, DataBuf data);
151 
152  PreviewProperties properties_;
153  byte* pData_;
154  uint32_t size_;
155 
156  }; // class PreviewImage
157 
161  class EXIV2API PreviewManager {
162  public:
164 
165  explicit PreviewManager(const Image& image);
168 
170 
171 
176  PreviewPropertiesList getPreviewProperties() const;
180  PreviewImage getPreviewImage(const PreviewProperties& properties) const;
182 
183  private:
184  const Image& image_;
185 
186  }; // class PreviewManager
187 } // namespace Exiv2
188 
189 #endif // #ifndef PREVIEW_HPP_
Exiv2::BasicIo::open
virtual int open()=0
Open the IO source using the default access mode. The default mode should allow for reading and writi...
Exiv2::MemIo
Provides binary IO on blocks of memory by implementing the BasicIo interface. A copy-on-write impleme...
Definition: basicio.hpp:540
Exiv2::DataBuf::pData_
byte * pData_
Pointer to the buffer, 0 if none has been allocated.
Definition: types.hpp:258
Exiv2::IoCloser
Utility class that closes a BasicIo instance upon destruction. Meant to be used as a stack variable i...
Definition: basicio.hpp:264
Exiv2::ExifData::findKey
iterator findKey(const ExifKey &key)
Find the first Exifdatum with the given key, return an iterator to it.
Definition: exif.cpp:605
Exiv2::Value
Common interface for all types of values used with metadata.
Definition: value.hpp:51
Exiv2::ExifData::add
void add(const ExifKey &key, const Value *pValue)
Add an Exifdatum from the supplied key and value pair. This method copies (clones) key and value....
Definition: exif.cpp:588
Exiv2::PreviewImage::id
PreviewId id() const
Return the preview image type identifier.
Definition: preview.cpp:1136
Exiv2::ExifData::begin
iterator begin()
Begin of the metadata.
Definition: exif.hpp:490
Exiv2::PreviewManager::PreviewManager
PreviewManager(const Image &image)
Constructor.
Definition: preview.cpp:1141
Exiv2::ExifData::const_iterator
ExifMetadata::const_iterator const_iterator
ExifMetadata const iterator type.
Definition: exif.hpp:439
Exiv2::PreviewImage::writeFile
long writeFile(const std::string &path) const
Write the thumbnail image to a file.
Definition: preview.cpp:1076
Exiv2::undefined
@ undefined
Exif UNDEFINED type, an 8-bit byte that may contain anything.
Definition: types.hpp:126
Exiv2::DataBuf::release
EXV_WARN_UNUSED_RESULT std::pair< byte *, long > release()
Release ownership of the buffer to the caller. Returns the buffer as a data pointer and size pair,...
Definition: types.cpp:167
Exiv2::NativePreview
Native preview information. This is meant to be used only by the PreviewManager.
Definition: image.hpp:49
Exiv2::writeFile
EXIV2API long writeFile(const DataBuf &buf, const std::string &path)
Write DataBuf buf to file path.
Definition: basicio.cpp:2703
Exiv2::AnyError
Error class interface. Allows the definition and use of a hierarchy of error classes which can all be...
Definition: error.hpp:174
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:762
Exiv2::strError
EXIV2API std::string strError()
Return a system error message and the error code (errno). See strerror(3).
Definition: futils.cpp:316
Exiv2::PreviewProperties::height_
uint32_t height_
Preview image height in pixels or 0 for unknown height.
Definition: preview.hpp:55
Exiv2::PreviewPropertiesList
std::vector< PreviewProperties > PreviewPropertiesList
Container type to hold all preview images metadata.
Definition: preview.hpp:61
Exiv2::PreviewProperties
Preview image properties.
Definition: preview.hpp:41
Exiv2::Value::count
virtual long count() const =0
Return the number of components of the value.
Exiv2::ExifData::end
iterator end()
End of the metadata.
Definition: exif.hpp:492
Exiv2::XmpKey
Concrete keys for XMP metadata.
Definition: properties.hpp:230
cr2image.hpp
Class Cr2Image.
Exiv2::PreviewImage::~PreviewImage
~PreviewImage()
Destructor.
Definition: preview.cpp:1050
Exiv2::PreviewImage::width
uint32_t width() const
Return the width of the preview image in pixels.
Definition: preview.cpp:1126
Exiv2::PreviewImage::height
uint32_t height() const
Return the height of the preview image in pixels.
Definition: preview.cpp:1131
Exiv2::XmpData::findKey
iterator findKey(const XmpKey &key)
Find the first Xmpdatum with the given key, return an iterator to it.
Definition: xmp.cpp:502
Exiv2::ImageFactory::open
static Image::AutoPtr 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:922
Exiv2::PreviewImage::pData
const byte * pData() const
Return a pointer to the image data for read-only access.
Definition: preview.cpp:1099
Exiv2::PreviewProperties::size_
uint32_t size_
Preview image size in bytes.
Definition: preview.hpp:51
Exiv2::byte
uint8_t byte
1 byte unsigned integer type.
Definition: types.hpp:94
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::PreviewManager::getPreviewProperties
PreviewPropertiesList getPreviewProperties() const
Return the properties of all preview images in a list sorted by preview width * height,...
Definition: preview.cpp:1146
Exiv2::ExifKey
Concrete keys for Exif metadata and access to Exif tag reference data.
Definition: tags.hpp:140
Exiv2::PreviewId
int PreviewId
Type of preview image.
Definition: preview.hpp:36
Exiv2::DataBuf::size_
long size_
The current size of the buffer.
Definition: types.hpp:260
Exiv2::Value::toLong
virtual long toLong(long n=0) const =0
Convert the n-th component of the value to a long. The behaviour of this method may be undefined if t...
Exiv2::Value::setDataArea
virtual int setDataArea(const byte *buf, long len)
Set the data area, if the value has one by copying (cloning) the buffer pointed to by buf.
Definition: value.cpp:163
Exiv2
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
Exiv2::XmpData
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition: xmp_exiv2.hpp:166
Exiv2::Internal::isTiffImageTag
bool isTiffImageTag(uint16_t tag, IfdId group)
Convenience function to check if tag, group is in the list of TIFF image tags.
Definition: tiffimage_int.cpp:1993
Exiv2::PreviewImage::PreviewImage
PreviewImage(const PreviewImage &rhs)
Copy constructor.
Definition: preview.cpp:1055
Exiv2::PreviewProperties::width_
uint32_t width_
Preview image width in pixels or 0 for unknown width.
Definition: preview.hpp:53
Exiv2::BasicIo::path
virtual std::string path() const =0
Return the path to the IO resource. Often used to form comprehensive error messages where only a Basi...
Exiv2::PreviewManager::getPreviewImage
PreviewImage getPreviewImage(const PreviewProperties &properties) const
Return the preview image for the given preview properties.
Definition: preview.cpp:1163
Exiv2::TiffParser::encode
static WriteMethod encode(BasicIo &io, const byte *pData, uint32_t size, ByteOrder byteOrder, const ExifData &exifData, const IptcData &iptcData, const XmpData &xmpData)
Encode metadata from the provided metadata to TIFF format.
Definition: tiffimage.cpp:275
EXV_WARNING
#define EXV_WARNING
Shorthand for a temp warning log message object and return its ostringstream.
Definition: error.hpp:148
Exiv2::XmpData::const_iterator
XmpMetadata::const_iterator const_iterator
XmpMetadata const iterator type.
Definition: xmp_exiv2.hpp:174
Exiv2::PreviewImage
Class that holds preview image properties and data buffer.
Definition: preview.hpp:66
Exiv2::BasicIo::mmap
virtual byte * mmap(bool isWriteable=false)=0
Direct access to the IO data. For files, this is done by mapping the file into the process's address ...
Exiv2::BasicIo::size
virtual size_t size() const =0
Get the current size of the IO source in bytes.
Exiv2::PreviewProperties::extension_
std::string extension_
Preview image extension.
Definition: preview.hpp:45
Exiv2::Image::AutoPtr
std::auto_ptr< Image > AutoPtr
Image auto_ptr type.
Definition: image.hpp:81
Safe::add
T add(T summand_1, T summand_2)
Safe addition, throws an exception on overflow.
Definition: safe_op.hpp:288
Exiv2::Error
BasicError< char > Error
Error class used for exceptions (std::string based)
Definition: error.hpp:324
Exiv2::Value::sizeDataArea
virtual long sizeDataArea() const
Return the size of the data area, 0 if there is none.
Definition: value.cpp:181
Exiv2::MemIo::mmap
virtual byte * mmap(bool=false)
Allow direct access to the underlying data buffer. The buffer is not protected against write access i...
Definition: basicio.cpp:1338
Exiv2::IptcData
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition: iptc.hpp:170
Exiv2::PreviewImage::mimeType
std::string mimeType() const
Return the MIME type of the preview image, usually either "image/tiff" or "image/jpeg".
Definition: preview.cpp:1109
Exiv2::PreviewProperties::mimeType_
std::string mimeType_
Preview image mime type.
Definition: preview.hpp:43
Exiv2::PreviewImage::copy
DataBuf copy() const
Return a copy of the preview image data. The caller owns this copy and DataBuf ensures that it will b...
Definition: preview.cpp:1094
Exiv2::PreviewImage::extension
std::string extension() const
Return the file extension for the format of the preview image (".tif" or ".jpg").
Definition: preview.cpp:1114
Exiv2::PreviewManager
Class for extracting preview images from image metadata.
Definition: preview.hpp:161
Exiv2::MemIo::size
virtual size_t size() const
Get the current memory buffer size in bytes.
Definition: basicio.cpp:1353
Exiv2::Image::mimeType
virtual std::string mimeType() const =0
Return the MIME type of the image.
Exiv2::PreviewProperties::id_
PreviewId id_
Identifies type of preview image.
Definition: preview.hpp:57
Exiv2::toString
std::string toString(const T &arg)
Utility function to convert the argument of any type to a string.
Definition: types.hpp:510
Exiv2::PreviewImage::size
uint32_t size() const
Return the size of the preview image in bytes.
Definition: preview.cpp:1104
Exiv2::BasicIo
An interface for simple binary IO.
Definition: basicio.hpp:55
Exiv2::Image::xmpData
virtual XmpData & xmpData()
Returns an XmpData instance containing currently buffered XMP data.
Definition: image.cpp:590
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::XmpData::end
iterator end()
End of the metadata.
Definition: xmp.cpp:523
Exiv2::Photoshop::locatePreviewIrb
static int locatePreviewIrb(const byte *pPsData, long sizePsData, const byte **record, uint32_t *const sizeHdr, uint32_t *const sizeData)
Forwards to locatePreviewIrb() with psTag = preview_.
Definition: jpgimage.cpp:239
Exiv2::Image::exifData
virtual ExifData & exifData()
Returns an ExifData instance containing currently buffered Exif data.
Definition: image.cpp:580
Exiv2::PreviewImage::operator=
PreviewImage & operator=(const PreviewImage &rhs)
Assignment operator.
Definition: preview.cpp:1063
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