Coverage Report

Created: 2026-02-14 06:59

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