/src/exiv2/include/exiv2/bmffimage.hpp
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | | |
3 | | #pragma once |
4 | | |
5 | | // ***************************************************************************** |
6 | | #include "exiv2lib_export.h" |
7 | | |
8 | | // included header files |
9 | | #include "image.hpp" |
10 | | |
11 | | #include <set> |
12 | | |
13 | | // ***************************************************************************** |
14 | | // namespace extensions |
15 | | namespace Exiv2 { |
16 | | [[deprecated]] EXIV2API bool enableBMFF(bool enable = true); |
17 | | } // namespace Exiv2 |
18 | | |
19 | | #ifdef EXV_ENABLE_BMFF |
20 | | namespace Exiv2 { |
21 | | struct Iloc { |
22 | 13.8k | explicit Iloc(uint32_t ID = 0, uint32_t start = 0, uint32_t length = 0) : ID_(ID), start_(start), length_(length) { |
23 | 13.8k | } |
24 | | |
25 | | uint32_t ID_; |
26 | | uint32_t start_; |
27 | | uint32_t length_; |
28 | | |
29 | | [[nodiscard]] std::string toString() const; |
30 | | }; // class Iloc |
31 | | |
32 | | // ***************************************************************************** |
33 | | // class definitions |
34 | | |
35 | | /*! |
36 | | @brief Class to access BMFF images. |
37 | | */ |
38 | | class EXIV2API BmffImage : public Image { |
39 | | public: |
40 | | //! @name Creators |
41 | | //@{ |
42 | | /*! |
43 | | @brief Constructor to open a BMFF image. Since the |
44 | | constructor can not return a result, callers should check the |
45 | | good() method after object construction to determine success |
46 | | or failure. |
47 | | @param io An auto-pointer that owns a BasicIo instance used for |
48 | | reading and writing image metadata. \b Important: The constructor |
49 | | takes ownership of the passed in BasicIo instance through the |
50 | | auto-pointer. Callers should not continue to use the BasicIo |
51 | | instance after it is passed to this method. Use the Image::io() |
52 | | method to get a temporary reference. |
53 | | @param create Specifies if an existing image should be read (false) |
54 | | or if a new file should be created (true). |
55 | | */ |
56 | | BmffImage(BasicIo::UniquePtr io, bool create, size_t max_box_depth = 1000); |
57 | | //@} |
58 | | |
59 | | //@{ |
60 | | void parseTiff(uint32_t root_tag, uint64_t length); |
61 | | /*! |
62 | | @brief parse embedded tiff file (Exif metadata) |
63 | | @param root_tag root of parse tree Tag::root, Tag::cmt2 etc. |
64 | | @param length tiff block length |
65 | | @param start offset in file (default, io_->tell()) |
66 | | @ |
67 | | */ |
68 | | void parseTiff(uint32_t root_tag, uint64_t length, uint64_t start); |
69 | | //@} |
70 | | |
71 | | //@{ |
72 | | /*! |
73 | | @brief parse embedded xmp/xml |
74 | | @param length xmp block length |
75 | | @param start offset in file |
76 | | @ |
77 | | */ |
78 | | void parseXmp(uint64_t length, uint64_t start); |
79 | | //@} |
80 | | |
81 | | //@{ |
82 | | /*! |
83 | | @brief Parse a Canon PRVW or THMB box and add an entry to the set |
84 | | of native previews. |
85 | | @param data Buffer containing the box |
86 | | @param out Logging stream |
87 | | @param bTrace Controls logging |
88 | | @param width_offset Index of image width field in data |
89 | | @param height_offset Index of image height field in data |
90 | | @param size_offset Index of image size field in data |
91 | | @param relative_position Location of the start of image data in the file, |
92 | | relative to the current file position indicator. |
93 | | */ |
94 | | void parseCr3Preview(const DataBuf& data, std::ostream& out, bool bTrace, uint8_t version, size_t width_offset, |
95 | | size_t height_offset, size_t size_offset, size_t relative_position); |
96 | | //@} |
97 | | |
98 | | //! @name Manipulators |
99 | | //@{ |
100 | | void readMetadata() override; |
101 | | void writeMetadata() override; |
102 | | void setExifData(const ExifData&) override; |
103 | | void setIptcData(const IptcData&) override; |
104 | | void setXmpData(const XmpData&) override; |
105 | | void setComment(const std::string& comment) override; |
106 | | void printStructure(std::ostream& out, Exiv2::PrintStructureOption option, size_t depth) override; |
107 | | //@} |
108 | | |
109 | | //! @name Accessors |
110 | | //@{ |
111 | | [[nodiscard]] std::string mimeType() const override; |
112 | | [[nodiscard]] uint32_t pixelWidth() const override; |
113 | | [[nodiscard]] uint32_t pixelHeight() const override; |
114 | | //@} |
115 | | |
116 | | static constexpr Exiv2::ByteOrder endian_{Exiv2::bigEndian}; |
117 | | |
118 | | private: |
119 | | void openOrThrow() const; |
120 | | /*! |
121 | | @brief recursiveBoxHandler |
122 | | @throw Error if we visit a box more than once |
123 | | @param pbox_end The end location of the parent box. Boxes are |
124 | | nested, so we must not read beyond this. |
125 | | @return address of next box |
126 | | @warning This function should only be called by readMetadata() |
127 | | */ |
128 | | uint64_t boxHandler(std::ostream& out, Exiv2::PrintStructureOption option, uint64_t pbox_end, size_t depth); |
129 | | |
130 | | uint32_t fileType_{0}; |
131 | | std::set<size_t> visits_; |
132 | | uint64_t visits_max_{0}; |
133 | | uint16_t unknownID_{0xffff}; |
134 | | uint16_t exifID_{0xffff}; |
135 | | uint16_t xmpID_{0}; |
136 | | std::map<uint32_t, Iloc> ilocs_; |
137 | | bool bReadMetadata_{false}; |
138 | | const size_t max_box_depth_; |
139 | | //@} |
140 | | |
141 | | /*! |
142 | | @brief box utilities |
143 | | */ |
144 | | static std::string toAscii(uint32_t n); |
145 | | std::string boxName(uint32_t box); |
146 | | static bool superBox(uint32_t box); |
147 | | static bool fullBox(uint32_t box); |
148 | | static std::string uuidName(const Exiv2::DataBuf& uuid); |
149 | | |
150 | | /*! |
151 | | @brief Wrapper around brotli to uncompress JXL brob content. |
152 | | */ |
153 | | #ifdef EXV_HAVE_BROTLI |
154 | | static void brotliUncompress(const byte* compressedBuf, size_t compressedBufSize, DataBuf& arr); |
155 | | #endif |
156 | | |
157 | | }; // class BmffImage |
158 | | |
159 | | // ***************************************************************************** |
160 | | // template, inline and free functions |
161 | | |
162 | | // These could be static private functions on Image subclasses but then |
163 | | // ImageFactory needs to be made a friend. |
164 | | /*! |
165 | | @brief Create a new BMFF instance and return an auto-pointer to it. |
166 | | Caller owns the returned object and the auto-pointer ensures that |
167 | | it will be deleted. |
168 | | */ |
169 | | EXIV2API Image::UniquePtr newBmffInstance(BasicIo::UniquePtr io, bool create); |
170 | | |
171 | | //! Check if the file iIo is a BMFF image. |
172 | | EXIV2API bool isBmffType(BasicIo& iIo, bool advance); |
173 | | } // namespace Exiv2 |
174 | | #endif // EXV_ENABLE_BMFF |