Exiv2
Loading...
Searching...
No Matches
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
14namespace Exiv2 {
15// *****************************************************************************
16// class definitions
17
21class 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
91
92 private:
94
95
102 int initImage(const byte initData[], size_t dataSize);
110 void doWriteMetadata(BasicIo& outIo);
112
114
115
124 [[nodiscard]] byte advanceToMarker(ErrorCode err) const;
126
127 DataBuf readNextSegment(byte marker);
128};
129
133class EXIV2API JpegImage : public JpegBase {
134 friend EXIV2API bool isJpegType(BasicIo& iIo, bool advance);
135
136 public:
138
139
154 JpegImage(BasicIo::UniquePtr io, bool create);
156
158 [[nodiscard]] std::string mimeType() const override;
162 [[nodiscard]] int numColorComponents() const {
164 }
165
168 [[nodiscard]] std::string encodingProcess() const {
170 }
171
172
173 protected:
175
176 bool isThisType(BasicIo& iIo, bool advance) const override;
178
180
188 int writeHeader(BasicIo& outIo) const override;
190
191 private:
192 // Constant data
193 static const byte blank_[];
194};
195
197class EXIV2API ExvImage : public JpegBase {
198 friend EXIV2API bool isExvType(BasicIo& iIo, bool advance);
199
200 public:
202
203
218 ExvImage(BasicIo::UniquePtr io, bool create);
220
222 [[nodiscard]] std::string mimeType() const override;
224
225 protected:
227
228 bool isThisType(BasicIo& iIo, bool advance) const override;
230
232 int writeHeader(BasicIo& outIo) const override;
234
235 private:
236 // Constant data
237 static constexpr char exiv2Id_[] = "Exiv2"; // EXV identifier
238 static constexpr byte blank_[] = {0xff, 0x01, 'E', 'x', 'i', 'v', '2', 0xff, 0xd9}; // Minimal exiv2 file
239
240}; // class ExvImage
241
242// *****************************************************************************
243// template, inline and free functions
244
245// These could be static private functions on Image subclasses but then
246// ImageFactory needs to be made a friend.
252EXIV2API Image::UniquePtr newJpegInstance(BasicIo::UniquePtr io, bool create);
254EXIV2API bool isJpegType(BasicIo& iIo, bool advance);
260EXIV2API Image::UniquePtr newExvInstance(BasicIo::UniquePtr io, bool create);
262EXIV2API bool isExvType(BasicIo& iIo, bool advance);
263
264} // namespace Exiv2
265
266#endif // #ifndef JPGIMAGE_HPP_
An interface for simple binary IO.
Definition basicio.hpp:35
std::unique_ptr< BasicIo > UniquePtr
BasicIo auto_ptr type.
Definition basicio.hpp:38
friend EXIV2API bool isExvType(BasicIo &iIo, bool advance)
Check if the file iIo is an EXV file.
Definition jpgimage.cpp:1060
bool isThisType(BasicIo &iIo, bool advance) const override
Determine if the content of the BasicIo instance is of the type supported by this class.
Definition jpgimage.cpp:1049
std::string mimeType() const override
Return the MIME type of the image.
Definition jpgimage.cpp:1032
ExvImage(BasicIo::UniquePtr io, bool create)
Constructor that can either open an existing EXV image or create a new image from scratch....
Definition jpgimage.cpp:1028
int writeHeader(BasicIo &outIo) const override
Writes the image header (aka signature) to the BasicIo instance.
Definition jpgimage.cpp:1036
Image(ImageType type, uint16_t supportedMetadata, BasicIo::UniquePtr io)
Constructor taking the image type, a bitmap of the supported metadata types and an auto-pointer that ...
Definition image.cpp:132
virtual BasicIo & io() const
Return a reference to the BasicIo instance being used for Io.
Definition image.cpp:680
std::unique_ptr< Image > UniquePtr
Image auto_ptr type.
Definition image.hpp:53
virtual int writeHeader(BasicIo &oIo) const =0
Writes the image header (aka signature) to the BasicIo instance.
void writeMetadata() override
Write metadata back to the image.
Definition jpgimage.cpp:589
std::string sof_encoding_process_
image encoding process
Definition jpgimage.hpp:90
int num_color_components_
image number of color components
Definition jpgimage.hpp:89
JpegBase(ImageType type, BasicIo::UniquePtr io, bool create, const byte initData[], size_t dataSize)
Constructor that can either open an existing image or create a new image from scratch....
Definition jpgimage.cpp:121
void printStructure(std::ostream &out, PrintStructureOption option, size_t depth) override
Print out the structure of image file.
Definition jpgimage.cpp:334
virtual bool isThisType(BasicIo &iIo, bool advance) const =0
Determine if the content of the BasicIo instance is of the type supported by this class.
void readMetadata() override
Read all metadata supported by a specific image format from the image. Before this method is called,...
Definition jpgimage.cpp:156
JpegImage(BasicIo::UniquePtr io, bool create)
Constructor that can either open an existing Jpeg image or create a new image from scratch....
Definition jpgimage.cpp:981
std::string mimeType() const override
Return the MIME type of the image.
Definition jpgimage.cpp:985
friend EXIV2API bool isJpegType(BasicIo &iIo, bool advance)
Check if the file iIo is a JPEG image.
Definition jpgimage.cpp:1013
int numColorComponents() const
Get the number of color components of the JPEG Image.
Definition jpgimage.hpp:162
std::string encodingProcess() const
Get the encoding process of the JPEG Image derived from the Start of Frame (SOF) markers.
Definition jpgimage.hpp:168
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
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:1060
ErrorCode
Complete list of all Exiv2 error codes.
Definition error.hpp:162
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:1005
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:1053
ImageType
Supported Image Formats.
Definition image_types.hpp:8
EXIV2API bool isJpegType(BasicIo &iIo, bool advance)
Check if the file iIo is a JPEG image.
Definition jpgimage.cpp:1013
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition types.hpp:124