Exiv2
webpimage.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 WEBPIMAGE_HPP
21 #define WEBPIMAGE_HPP
22 
23 // *****************************************************************************
24 #include "exiv2lib_export.h"
25 
26 // included header files
27 #include "image.hpp"
28 
29 // *****************************************************************************
30 // namespace extensions
31 namespace Exiv2 {
32 
33 // *****************************************************************************
34 // class definitions
35 
36  // Add WEBP to the supported image formats
37  namespace ImageType {
38  const int webp = 23;
39  }
40 
44  class EXIV2API WebPImage:public Image
45  {
46  public:
48 
49 
62 
64 
65  void readMetadata();
66  void writeMetadata();
67  void printStructure(std::ostream& out, PrintStructureOption option,int depth);
69 
73  void setComment(const std::string& comment);
74  void setIptcData(const IptcData& /*iptcData*/);
75 
77 
78  std::string mimeType() const;
80 
81  private:
82  void doWriteMetadata(BasicIo& outIo);
84 
85  long getHeaderOffset(byte *data, long data_size,
86  byte *header, long header_size);
87  bool equalsWebPTag(Exiv2::DataBuf& buf ,const char* str);
88  void debugPrintHex(byte *data, long size);
89  void decodeChunks(long filesize);
90  void inject_VP8X(BasicIo& iIo, bool has_xmp, bool has_exif,
91  bool has_alpha, bool has_icc, int width,
92  int height);
93 
95  WebPImage(const WebPImage& rhs);
97  WebPImage& operator=(const WebPImage& rhs);
99 
100  private:
101  const static byte WEBP_PAD_ODD;
102  const static int WEBP_TAG_SIZE;
103  const static int WEBP_VP8X_ICC_BIT;
104  const static int WEBP_VP8X_ALPHA_BIT;
105  const static int WEBP_VP8X_EXIF_BIT;
106  const static int WEBP_VP8X_XMP_BIT;
107  const static char* WEBP_CHUNK_HEADER_VP8X;
108  const static char* WEBP_CHUNK_HEADER_VP8L;
109  const static char* WEBP_CHUNK_HEADER_VP8;
110  const static char* WEBP_CHUNK_HEADER_ANMF;
111  const static char* WEBP_CHUNK_HEADER_ANIM;
112  const static char* WEBP_CHUNK_HEADER_ICCP;
113  const static char* WEBP_CHUNK_HEADER_EXIF;
114  const static char* WEBP_CHUNK_HEADER_XMP;
115 
116 
117  }; //Class WebPImage
118 
119 // *****************************************************************************
120 // template, inline and free functions
121 
122  // These could be static private functions on Image subclasses but then
123  // ImageFactory needs to be made a friend.
129  EXIV2API Image::AutoPtr newWebPInstance(BasicIo::AutoPtr io, bool create);
130 
132  EXIV2API bool isWebPType(BasicIo& iIo, bool advance);
133 
134 } // namespace Exiv2
135 
136 #endif // WEBPIMAGE_HPP
Exiv2::WebPImage::writeMetadata
void writeMetadata()
Write metadata back to the image.
Definition: webpimage.cpp:120
Exiv2::MemIo
Provides binary IO on blocks of memory by implementing the BasicIo interface. A copy-on-write impleme...
Definition: basicio.hpp:540
Exiv2::ExifData::clear
void clear()
Delete all Exifdatum instances resulting in an empty container. Note that this also removes thumbnail...
Definition: exif.cpp:611
Exiv2::ImageType::xmp
const int xmp
XMP sidecar files (see class XmpSidecar)
Definition: xmpsidecar.hpp:38
Exiv2::Image::xmpPacket_
std::string xmpPacket_
XMP packet.
Definition: image.hpp:490
Exiv2::BasicIo::isopen
virtual bool isopen() const =0
Returns true if the IO source is open, otherwise false.
Exiv2::DataBuf::pData_
byte * pData_
Pointer to the buffer, 0 if none has been allocated.
Definition: types.hpp:258
Exiv2::Internal::indent
std::string indent(int32_t d)
indent output for kpsRecursive in printStructure() .
Definition: image_int.cpp:106
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::Internal::binaryToHex
std::string binaryToHex(const byte *data, size_t size)
format binary for display of raw data .
Definition: image_int.cpp:60
Exiv2::XmpParser::omitAllFormatting
@ omitAllFormatting
Omit all formatting whitespace.
Definition: xmp_exiv2.hpp:278
Exiv2::WebPImage::readMetadata
void readMetadata()
Read all metadata supported by a specific image format from the image. Before this method is called,...
Definition: webpimage.cpp:502
Exiv2::WebPImage
Class to access WEBP video files.
Definition: webpimage.hpp:44
Exiv2::makeSlice
Slice< T > makeSlice(T &cont, size_t begin, size_t end)
Return a new slice with the given bounds.
Definition: slice.hpp:665
Exiv2::comment
@ comment
Exiv2 type for the Exif user comment.
Definition: types.hpp:139
Exiv2::WebPImage::WebPImage
WebPImage(BasicIo::AutoPtr io)
Constructor for a WebP video. Since the constructor can not return a result, callers should check the...
Definition: webpimage.cpp:71
Exiv2::strError
EXIV2API std::string strError()
Return a system error message and the error code (errno). See strerror(3).
Definition: futils.cpp:316
Exiv2::Image::exifData_
ExifData exifData_
Exif data container.
Definition: image.hpp:485
Exiv2::Internal::binaryToString
binaryToStringHelper< T > binaryToString(const Slice< T > sl)
format binary data for display in Image::printStructure()
Definition: image_int.hpp:118
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::pixelHeight_
int pixelHeight_
image pixel height
Definition: image.hpp:492
Exiv2::isWebPType
EXIV2API bool isWebPType(BasicIo &iIo, bool advance)
Check if the file iIo is a WebP Video.
Definition: webpimage.cpp:743
Exiv2::Image::clearMetadata
virtual void clearMetadata()
Erase all buffered metadata. Metadata is not removed from the actual image until the writeMetadata() ...
Definition: image.cpp:570
Exiv2::ExifParser::encode
static WriteMethod encode(Blob &blob, const byte *pData, uint32_t size, ByteOrder byteOrder, const ExifData &exifData)
Encode Exif metadata from the provided metadata to binary Exif format.
Definition: exif.cpp:668
Exiv2::Internal::stringFormat
std::string stringFormat(const char *format,...)
format a string in the pattern of sprintf .
Definition: image_int.cpp:32
Exiv2::Image::setByteOrder
void setByteOrder(ByteOrder byteOrder)
Set the byte order to encode the Exif metadata in.
Definition: image.cpp:707
Exiv2::WebPImage::printStructure
void printStructure(std::ostream &out, PrintStructureOption option, int depth)
Print out the structure of image file.
Definition: webpimage.cpp:436
Exiv2::Image::pixelWidth_
int pixelWidth_
image pixel width
Definition: image.hpp:491
Exiv2::Image::printTiffStructure
void printTiffStructure(BasicIo &io, std::ostream &out, PrintStructureOption option, int depth, size_t offset=0)
Print out the structure of image file.
Definition: image.cpp:552
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::us2Data
EXIV2API long us2Data(byte *buf, uint16_t s, ByteOrder byteOrder)
Convert an unsigned short to data, write the data to the buffer, return number of bytes written.
Definition: types.cpp:390
Exiv2::XmpParser::useCompactFormat
@ useCompactFormat
Use a compact form of RDF.
Definition: xmp_exiv2.hpp:274
Exiv2::XmpData::count
long count() const
Get the number of metadata entries.
Definition: xmp.cpp:533
Exiv2::DataBuf::size_
long size_
The current size of the buffer.
Definition: types.hpp:260
Exiv2::XmpParser::encode
static int encode(std::string &xmpPacket, const XmpData &xmpData, uint16_t formatFlags=useCompactFormat, uint32_t padding=0)
Encode (serialize) XMP metadata from xmpData into a string xmpPacket. The XMP packet returned in the ...
Definition: xmp.cpp:1000
Exiv2::ExifData::count
long count() const
Get the number of metadata entries.
Definition: exif.hpp:514
Exiv2
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
Exiv2::newWebPInstance
EXIV2API Image::AutoPtr newWebPInstance(BasicIo::AutoPtr io, bool create)
Create a new WebPImage instance and return an auto-pointer to it. Caller owns the returned object and...
Definition: webpimage.cpp:734
convert.hpp
Exif and IPTC conversions to and from XMP.
Exiv2::Image::io
virtual BasicIo & io() const
Return a reference to the BasicIo instance being used for Io.
Definition: image.cpp:752
Exiv2::ImageType::webp
const int webp
Treating webp as an image type>
Definition: webpimage.hpp:38
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::ul2Data
EXIV2API long ul2Data(byte *buf, uint32_t l, ByteOrder byteOrder)
Convert an unsigned long to data, write the data to the buffer, return number of bytes written.
Definition: types.cpp:403
Exiv2::ExifParser::decode
static ByteOrder decode(ExifData &exifData, const byte *pData, uint32_t size)
Decode metadata from a buffer pData of length size with binary Exif data to the provided metadata con...
Definition: exif.cpp:636
EXV_WARNING
#define EXV_WARNING
Shorthand for a temp warning log message object and return its ostringstream.
Definition: error.hpp:148
Exiv2::BasicIo::write
virtual long write(const byte *data, long wcount)=0
Write data to the IO source. Current IO position is advanced by the number of bytes written.
Exiv2::WebPImage::setComment
void setComment(const std::string &comment)
Not supported. Calling this function will throw an Error(kerInvalidSettingForImage).
Definition: webpimage.cpp:112
Exiv2::getUShort
EXIV2API uint16_t getUShort(const byte *buf, ByteOrder byteOrder)
Read a 2 byte unsigned short value from the data buffer.
Definition: types.cpp:273
Exiv2::Image::io_
BasicIo::AutoPtr io_
Image data IO pointer.
Definition: image.hpp:484
Exiv2::BasicIo::size
virtual size_t size() const =0
Get the current size of the IO source in bytes.
Exiv2::ByteOrder
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:102
Exiv2::Image::iccProfile_
DataBuf iccProfile_
ICC buffer (binary data)
Definition: image.hpp:488
Exiv2::Internal
Contains internal objects which are not published and are not part of the libexiv2 API.
Definition: slice.hpp:31
Exiv2::Image::AutoPtr
std::auto_ptr< Image > AutoPtr
Image auto_ptr type.
Definition: image.hpp:81
Exiv2::Image::xmpPacket
virtual std::string & xmpPacket()
Return a modifiable reference to the raw XMP packet.
Definition: image.cpp:595
Safe::add
T add(T summand_1, T summand_2)
Safe addition, throws an exception on overflow.
Definition: safe_op.hpp:288
Exiv2::BasicIo::AutoPtr
std::auto_ptr< BasicIo > AutoPtr
BasicIo auto_ptr type.
Definition: basicio.hpp:58
Exiv2::Image::writeXmpFromPacket
bool writeXmpFromPacket() const
Return the flag indicating the source when writing XMP metadata.
Definition: image.cpp:757
Exiv2::Error
BasicError< char > Error
Error class used for exceptions (std::string based)
Definition: error.hpp:324
Exiv2::IptcData
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition: iptc.hpp:170
Exiv2::PrintStructureOption
PrintStructureOption
Options for printStructure.
Definition: image.hpp:64
Exiv2::BasicIo::tell
virtual long tell() const =0
Get the current IO position.
Exiv2::BasicIo::seek
virtual int seek(long offset, Position pos)=0
Move the current IO position.
Exiv2::ErrorCode
ErrorCode
Complete list of all Exiv2 error codes.
Definition: error.hpp:191
Exiv2::BasicIo
An interface for simple binary IO.
Definition: basicio.hpp:55
Exiv2::WebPImage::mimeType
std::string mimeType() const
Return the MIME type of the image.
Definition: webpimage.cpp:76
Exiv2::Image::xmpData_
XmpData xmpData_
XMP data container.
Definition: image.hpp:487
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::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:692
Exiv2::XmpParser::decode
static int decode(XmpData &xmpData, const std::string &xmpPacket)
Decode XMP metadata from an XMP packet xmpPacket into xmpData. The format of the XMP packet must foll...
Definition: xmp.cpp:887
Exiv2::WebPImage::setIptcData
void setIptcData(const IptcData &)
Assign new IPTC data. The new IPTC data is not written to the image until the writeMetadata() method ...
Definition: webpimage.cpp:105
Exiv2::getULong
EXIV2API uint32_t getULong(const byte *buf, ByteOrder byteOrder)
Read a 4 byte unsigned long value from the data buffer.
Definition: types.cpp:278
Exiv2::Blob
std::vector< byte > Blob
Container for binary data.
Definition: types.hpp:151