Exiv2
jpgimage.hpp
1// ***************************************************************** -*- C++ -*-
2/*
3 * Copyright (C) 2004-2021 Exiv2 authors
4 * This program is part of the Exiv2 distribution.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
19 */
20
21#ifndef JPGIMAGE_HPP_
22#define JPGIMAGE_HPP_
23
24// *****************************************************************************
25#include "exiv2lib_export.h"
26
27#include <array>
28
29// included header files
30#include "image.hpp"
31#include "error.hpp"
32
33// *****************************************************************************
34// namespace extensions
35namespace Exiv2 {
36
37// *****************************************************************************
38// class definitions
39
40 // Supported JPEG image formats
41 namespace ImageType {
42 const int jpeg = 1;
43 const int exv = 2;
44 }
45
50 struct EXIV2API Photoshop {
51 // Todo: Public for now
52 static const char* const ps3Id_;
53 static const std::array<const char*, 4> irbId_;
54 static const char* const bimId_;
55 static const uint16_t iptc_;
56 static const uint16_t preview_;
57
66 static bool isIrb(const byte* pPsData,
67 long sizePsData);
76 static bool valid(const byte* pPsData,
77 long sizePsData);
95 static int locateIrb(const byte *pPsData,
96 long sizePsData,
97 uint16_t psTag,
98 const byte **record,
99 uint32_t *const sizeHdr,
100 uint32_t *const sizeData);
104 static int locateIptcIrb(const byte *pPsData,
105 long sizePsData,
106 const byte **record,
107 uint32_t *const sizeHdr,
108 uint32_t *const sizeData);
112 static int locatePreviewIrb(const byte *pPsData,
113 long sizePsData,
114 const byte **record,
115 uint32_t *const sizeHdr,
116 uint32_t *const sizeData);
126 static DataBuf setIptcIrb(const byte* pPsData,
127 long sizePsData,
128 const IptcData& iptcData);
129
130 }; // class Photoshop
131
135 class EXIV2API JpegBase : public Image {
136 public:
138
139 void readMetadata() override;
140 void writeMetadata() override;
141
148 void printStructure(std::ostream& out, PrintStructureOption option, int depth) override;
150
152
153
154 JpegBase() = delete;
156 JpegBase(const JpegBase& rhs) = delete;
158 JpegBase& operator=(const JpegBase& rhs) = delete;
160
161 protected:
163
164
182 JpegBase(int type,
184 bool create,
185 const byte initData[],
186 long dataSize);
188
190
191
210 virtual bool isThisType(BasicIo& iIo, bool advance) const =0;
212
214
215
221 virtual int writeHeader(BasicIo& oIo) const =0;
223
224 // Constant Data
225 static const byte dht_;
226 static const byte dqt_;
227 static const byte dri_;
228 static const byte sos_;
229 static const byte eoi_;
230 static const byte app0_;
231 static const byte app1_;
232 static const byte app2_;
233 static const byte app13_;
234 static const byte com_;
235 static const byte sof0_;
236 static const byte sof1_;
237 static const byte sof2_;
238 static const byte sof3_;
239 static const byte sof5_;
240 static const byte sof6_;
241 static const byte sof7_;
242 static const byte sof9_;
243 static const byte sof10_;
244 static const byte sof11_;
245 static const byte sof13_;
246 static const byte sof14_;
247 static const byte sof15_;
248 static const char* const exifId_;
249 static const char* const jfifId_;
250 static const char* const xmpId_;
251 static const char* const iccId_;
252
253 private:
255
256
263 int initImage(const byte initData[], long dataSize);
271 void doWriteMetadata(BasicIo& outIo);
273
275
276
285 byte advanceToMarker(ErrorCode err) const;
287
293 static bool markerHasLength(byte marker);
294 }; // class JpegBase
295
299 class EXIV2API JpegImage : public JpegBase {
300 friend EXIV2API bool isJpegType(BasicIo& iIo, bool advance);
301 public:
303
304
319 JpegImage(BasicIo::UniquePtr io, bool create);
321
323 std::string mimeType() const override;
325
326 // NOT Implemented
328 JpegImage() = delete;
330 JpegImage(const JpegImage& rhs) = delete;
332 JpegImage& operator=(const JpegImage& rhs) = delete;
333
334 protected:
336
337 bool isThisType(BasicIo& iIo, bool advance) const override;
339
341
349 int writeHeader(BasicIo& outIo) const override;
351
352 private:
353 // Constant data
354 static const byte soi_; // SOI marker
355 static const byte blank_[]; // Minimal Jpeg image
356 }; // class JpegImage
357
359 class EXIV2API ExvImage : public JpegBase {
360 friend EXIV2API bool isExvType(BasicIo& iIo, bool advance);
361 public:
363
364
379 ExvImage(BasicIo::UniquePtr io, bool create);
381
383 std::string mimeType() const override;
385
386 // NOT Implemented
388 ExvImage() = delete;
390 ExvImage(const ExvImage& rhs) = delete;
392 ExvImage& operator=(const ExvImage& rhs) = delete;
393
394 protected:
396
397 bool isThisType(BasicIo& iIo, bool advance) const override;
399
401 int writeHeader(BasicIo& outIo) const override;
403
404 private:
405 // Constant data
406 static const char exiv2Id_[]; // EXV identifier
407 static const byte blank_[]; // Minimal exiv2 file
408
409 }; // class ExvImage
410
411// *****************************************************************************
412// template, inline and free functions
413
414 // These could be static private functions on Image subclasses but then
415 // ImageFactory needs to be made a friend.
421 EXIV2API Image::UniquePtr newJpegInstance(BasicIo::UniquePtr io, bool create);
423 EXIV2API bool isJpegType(BasicIo& iIo, bool advance);
429 EXIV2API Image::UniquePtr newExvInstance(BasicIo::UniquePtr io, bool create);
431 EXIV2API bool isExvType(BasicIo& iIo, bool advance);
432
433} // namespace Exiv2
434
435#endif // #ifndef JPGIMAGE_HPP_
An interface for simple binary IO.
Definition: basicio.hpp:55
std::unique_ptr< BasicIo > UniquePtr
BasicIo auto_ptr type.
Definition: basicio.hpp:58
Helper class to access Exiv2 files.
Definition: jpgimage.hpp:359
ExvImage & operator=(const ExvImage &rhs)=delete
Assignment operator.
ExvImage(const ExvImage &rhs)=delete
Copy constructor.
ExvImage()=delete
Default constructor.
Abstract base class defining the interface for an image. This is the top-level interface to the Exiv2...
Definition: image.hpp:78
std::unique_ptr< Image > UniquePtr
Image auto_ptr type.
Definition: image.hpp:81
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition: iptc.hpp:169
Abstract helper base class to access JPEG images.
Definition: jpgimage.hpp:135
static const byte app1_
JPEG APP1 marker.
Definition: jpgimage.hpp:231
static const char *const exifId_
Exif identifier.
Definition: jpgimage.hpp:248
static const byte app13_
JPEG APP13 marker.
Definition: jpgimage.hpp:233
virtual int writeHeader(BasicIo &oIo) const =0
Writes the image header (aka signature) to the BasicIo instance.
static const byte sof9_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:242
static const byte sof1_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:236
static const byte dqt_
JPEG DQT marker.
Definition: jpgimage.hpp:226
static const char *const iccId_
ICC profile identifier.
Definition: jpgimage.hpp:251
static const byte sof13_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:245
static const byte sof2_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:237
static const byte sof11_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:244
static const byte eoi_
JPEG EOI marker.
Definition: jpgimage.hpp:229
JpegBase & operator=(const JpegBase &rhs)=delete
Assignment operator.
static const byte sof10_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:243
static const byte sof3_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:238
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.
static const byte sof0_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:235
JpegBase()=delete
Default constructor.
static const byte app2_
JPEG APP2 marker.
Definition: jpgimage.hpp:232
static const char *const xmpId_
XMP packet identifier.
Definition: jpgimage.hpp:250
static const byte com_
JPEG Comment marker.
Definition: jpgimage.hpp:234
static const byte dri_
JPEG DRI marker.
Definition: jpgimage.hpp:227
static const byte sos_
JPEG SOS marker.
Definition: jpgimage.hpp:228
static const byte sof5_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:239
static const char *const jfifId_
JFIF identifier.
Definition: jpgimage.hpp:249
JpegBase(const JpegBase &rhs)=delete
Copy constructor.
static const byte dht_
JPEG DHT marker.
Definition: jpgimage.hpp:225
static const byte sof14_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:246
static const byte sof6_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:240
static const byte sof7_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:241
static const byte app0_
JPEG APP0 marker.
Definition: jpgimage.hpp:230
static const byte sof15_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:247
Class to access JPEG images.
Definition: jpgimage.hpp:299
JpegImage()=delete
Default constructor.
JpegImage(const JpegImage &rhs)=delete
Copy constructor.
JpegImage & operator=(const JpegImage &rhs)=delete
Assignment operator.
Error class for exceptions, log message class.
const int exv
EXV image type (see class ExvImage)
Definition: jpgimage.hpp:43
const int jpeg
JPEG image type (see class JpegImage)
Definition: jpgimage.hpp:42
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: basicio.hpp:43
PrintStructureOption
Options for printStructure.
Definition: image.hpp:64
EXIV2API bool isExvType(BasicIo &iIo, bool advance)
Check if the file iIo is an EXV file.
Definition: jpgimage.cpp:1384
ErrorCode
Complete list of all Exiv2 error codes.
Definition: error.hpp:191
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:1323
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:1376
EXIV2API bool isJpegType(BasicIo &iIo, bool advance)
Check if the file iIo is a JPEG image.
Definition: jpgimage.cpp:1332
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition: types.hpp:162
Helper class, has methods to deal with Photoshop "Information Resource Blocks" (IRBs).
Definition: jpgimage.hpp:50
static const char *const ps3Id_
Photoshop marker
Definition: jpgimage.hpp:52
static const char *const bimId_
Photoshop IRB marker (deprecated)
Definition: jpgimage.hpp:54
static const std::array< const char *, 4 > irbId_
Photoshop IRB markers
Definition: jpgimage.hpp:53
static const uint16_t preview_
Photoshop preview marker
Definition: jpgimage.hpp:56
static const uint16_t iptc_
Photoshop IPTC marker
Definition: jpgimage.hpp:55