Exiv2
webpimage.hpp
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 #ifndef WEBPIMAGE_HPP
4 #define WEBPIMAGE_HPP
5 
6 // *****************************************************************************
7 #include "exiv2lib_export.h"
8 
9 // included header files
10 #include "image.hpp"
11 
12 // *****************************************************************************
13 // namespace extensions
14 namespace Exiv2 {
15 // *****************************************************************************
16 // class definitions
17 
21 class EXIV2API WebPImage : public Image {
22  public:
24 
25 
36  explicit WebPImage(BasicIo::UniquePtr io);
38 
40 
41  void readMetadata() override;
42  void writeMetadata() override;
43  void printStructure(std::ostream& out, PrintStructureOption option, size_t depth) override;
45 
49  void setComment(const std::string&) override;
50  void setIptcData(const IptcData& /*iptcData*/) override;
51 
53 
54  [[nodiscard]] std::string mimeType() const override;
56 
57  private:
58  void doWriteMetadata(BasicIo& outIo);
59 
61  static size_t getHeaderOffset(const byte* data, size_t data_size, const byte* header, size_t header_size);
62 
63  static bool equalsWebPTag(const Exiv2::DataBuf& buf, const char* str);
64  void debugPrintHex(byte* data, size_t size);
65  void decodeChunks(uint32_t filesize);
66  void inject_VP8X(BasicIo& iIo, bool has_xmp, bool has_exif, bool has_alpha, bool has_icc, uint32_t width,
67  uint32_t height) const;
68  /* Misc. */
69  static constexpr byte WEBP_PAD_ODD = 0;
70  static constexpr int WEBP_TAG_SIZE = 0x4;
71  /* VP8X feature flags */
72  static constexpr int WEBP_VP8X_ICC_BIT = 0x20;
73  static constexpr int WEBP_VP8X_ALPHA_BIT = 0x10;
74  static constexpr int WEBP_VP8X_EXIF_BIT = 0x8;
75  static constexpr int WEBP_VP8X_XMP_BIT = 0x4;
76  /* Chunk header names */
77  static constexpr auto WEBP_CHUNK_HEADER_VP8X = "VP8X";
78  static constexpr auto WEBP_CHUNK_HEADER_VP8L = "VP8L";
79  static constexpr auto WEBP_CHUNK_HEADER_VP8 = "VP8 ";
80  static constexpr auto WEBP_CHUNK_HEADER_ANMF = "ANMF";
81  static constexpr auto WEBP_CHUNK_HEADER_ANIM = "ANIM";
82  static constexpr auto WEBP_CHUNK_HEADER_ICCP = "ICCP";
83  static constexpr auto WEBP_CHUNK_HEADER_EXIF = "EXIF";
84  static constexpr auto WEBP_CHUNK_HEADER_XMP = "XMP ";
85 }; // Class WebPImage
86 
87 // *****************************************************************************
88 // template, inline and free functions
89 
90 // These could be static private functions on Image subclasses but then
91 // ImageFactory needs to be made a friend.
97 EXIV2API Image::UniquePtr newWebPInstance(BasicIo::UniquePtr io, bool create);
98 
100 EXIV2API bool isWebPType(BasicIo& iIo, bool advance);
101 
102 } // namespace Exiv2
103 
104 #endif // WEBPIMAGE_HPP
std::unique_ptr< Image > UniquePtr
Image auto_ptr type.
Definition: image.hpp:53
An interface for simple binary IO.
Definition: basicio.hpp:35
EXIV2API Image::UniquePtr newWebPInstance(BasicIo::UniquePtr io, bool create)
Create a new WebPImage instance and return an auto-pointer to it. Caller owns the returned object and...
Definition: webpimage.cpp:680
EXIV2API bool isWebPType(BasicIo &iIo, bool advance)
Check if the file iIo is a WebP Video.
Definition: webpimage.cpp:688
uint8_t byte
1 byte unsigned integer type.
Definition: types.hpp:26
Abstract base class defining the interface for an image. This is the top-level interface to the Exiv2...
Definition: image.hpp:50
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition: types.hpp:124
PrintStructureOption
Options for printStructure.
Definition: image.hpp:38
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition: iptc.hpp:153
List of TIFF compression to MIME type mappings.
Definition: tiffimage.cpp:47
std::unique_ptr< BasicIo > UniquePtr
BasicIo auto_ptr type.
Definition: basicio.hpp:38
Class CrwImage to access Canon CRW images. References: The Canon RAW (CRW) File Format by Phil Harv...
Definition: asfvideo.hpp:15
Class to access WEBP video files.
Definition: webpimage.hpp:21