Exiv2
jpgimage.hpp
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 #ifndef JPGIMAGE_HPP_
4 #define JPGIMAGE_HPP_
5 
6 #include "exiv2lib_export.h"
7 
8 // included header files
9 #include "error.hpp"
10 #include "image.hpp"
11 
12 // *****************************************************************************
13 // namespace extensions
14 namespace Exiv2 {
15 // *****************************************************************************
16 // class definitions
17 
21 class EXIV2API JpegBase : public Image {
22  public:
24 
25  void readMetadata() override;
26  void writeMetadata() override;
27  void printStructure(std::ostream& out, PrintStructureOption option, size_t depth) override;
29 
30  protected:
32 
33 
51  JpegBase(ImageType type, BasicIo::UniquePtr io, bool create, const byte initData[], size_t dataSize);
53 
55 
56 
75  virtual bool isThisType(BasicIo& iIo, bool advance) const = 0;
77 
79 
80 
86  virtual int writeHeader(BasicIo& oIo) const = 0;
88 
89  private:
91 
92 
99  int initImage(const byte initData[], size_t dataSize);
107  void doWriteMetadata(BasicIo& outIo);
109 
111 
112 
121  [[nodiscard]] byte advanceToMarker(ErrorCode err) const;
123 
124  DataBuf readNextSegment(byte marker);
125 };
126 
130 class EXIV2API JpegImage : public JpegBase {
131  friend EXIV2API bool isJpegType(BasicIo& iIo, bool advance);
132 
133  public:
135 
136 
151  JpegImage(BasicIo::UniquePtr io, bool create);
153 
155  [[nodiscard]] std::string mimeType() const override;
157 
158  protected:
160 
161  bool isThisType(BasicIo& iIo, bool advance) const override;
163 
165 
173  int writeHeader(BasicIo& outIo) const override;
175 
176  private:
177  // Constant data
178  static const byte blank_[];
179 };
180 
182 class EXIV2API ExvImage : public JpegBase {
183  friend EXIV2API bool isExvType(BasicIo& iIo, bool advance);
184 
185  public:
187 
188 
203  ExvImage(BasicIo::UniquePtr io, bool create);
205 
207  [[nodiscard]] std::string mimeType() const override;
209 
210  protected:
212 
213  bool isThisType(BasicIo& iIo, bool advance) const override;
215 
217  int writeHeader(BasicIo& outIo) const override;
219 
220  private:
221  // Constant data
222  static constexpr char exiv2Id_[] = "Exiv2"; // EXV identifier
223  static constexpr byte blank_[] = {0xff, 0x01, 'E', 'x', 'i', 'v', '2', 0xff, 0xd9}; // Minimal exiv2 file
224 
225 }; // class ExvImage
226 
227 // *****************************************************************************
228 // template, inline and free functions
229 
230 // These could be static private functions on Image subclasses but then
231 // ImageFactory needs to be made a friend.
237 EXIV2API Image::UniquePtr newJpegInstance(BasicIo::UniquePtr io, bool create);
239 EXIV2API bool isJpegType(BasicIo& iIo, bool advance);
245 EXIV2API Image::UniquePtr newExvInstance(BasicIo::UniquePtr io, bool create);
247 EXIV2API bool isExvType(BasicIo& iIo, bool advance);
248 
249 } // namespace Exiv2
250 
251 #endif // #ifndef JPGIMAGE_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 bool isJpegType(BasicIo &iIo, bool advance)
Check if the file iIo is a JPEG image.
Definition: jpgimage.cpp:974
EXIV2API Image::UniquePtr newExvInstance(BasicIo::UniquePtr io, bool create)
Create a new ExvImage instance and return an auto-pointer to it. Caller owns the returned object and ...
Definition: jpgimage.cpp:1014
Abstract helper base class to access JPEG images.
Definition: jpgimage.hpp:21
Helper class to access Exiv2 files.
Definition: jpgimage.hpp:182
EXIV2API Image::UniquePtr newJpegInstance(BasicIo::UniquePtr io, bool create)
Create a new JpegImage instance and return an auto-pointer to it. Caller owns the returned object and...
Definition: jpgimage.cpp:966
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
EXIV2API bool isExvType(BasicIo &iIo, bool advance)
Check if the file iIo is an EXV file.
Definition: jpgimage.cpp:1021
List of TIFF compression to MIME type mappings.
Definition: tiffimage.cpp:47
ImageType
Supported Image Formats.
Definition: image_types.hpp:8
std::unique_ptr< BasicIo > UniquePtr
BasicIo auto_ptr type.
Definition: basicio.hpp:38
Error class for exceptions, log message class.
Class CrwImage to access Canon CRW images. References: The Canon RAW (CRW) File Format by Phil Harv...
Definition: asfvideo.hpp:15
Class to access JPEG images.
Definition: jpgimage.hpp:130
ErrorCode
Complete list of all Exiv2 error codes.
Definition: error.hpp:162