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// included header files
28#include "image.hpp"
29
30// *****************************************************************************
31// namespace extensions
32namespace Exiv2 {
33
34// *****************************************************************************
35// class definitions
36
37 // Supported JPEG image formats
38 namespace ImageType {
39 const int jpeg = 1;
40 const int exv = 2;
41 }
42
47 struct EXIV2API Photoshop {
48 // Todo: Public for now
49 static const char ps3Id_[];
50 static const char* irbId_[];
51 static const char bimId_[];
52 static const uint16_t iptc_;
53 static const uint16_t preview_;
54
63 static bool isIrb(const byte* pPsData,
64 long sizePsData);
73 static bool valid(const byte* pPsData,
74 long sizePsData);
92 static int locateIrb(const byte *pPsData,
93 long sizePsData,
94 uint16_t psTag,
95 const byte **record,
96 uint32_t *const sizeHdr,
97 uint32_t *const sizeData);
101 static int locateIptcIrb(const byte *pPsData,
102 long sizePsData,
103 const byte **record,
104 uint32_t *const sizeHdr,
105 uint32_t *const sizeData);
109 static int locatePreviewIrb(const byte *pPsData,
110 long sizePsData,
111 const byte **record,
112 uint32_t *const sizeHdr,
113 uint32_t *const sizeData);
123 static DataBuf setIptcIrb(const byte* pPsData,
124 long sizePsData,
125 const IptcData& iptcData);
126
127 }; // class Photoshop
128
132 class EXIV2API JpegBase : public Image {
133 public:
135
136 void readMetadata();
137 void writeMetadata();
138
145 void printStructure(std::ostream& out, PrintStructureOption option,int depth);
147
148 protected:
150
151
169 JpegBase(int type,
171 bool create,
172 const byte initData[],
173 long dataSize);
175
177
178
197 virtual bool isThisType(BasicIo& iIo, bool advance) const =0;
199
201
202
208 virtual int writeHeader(BasicIo& oIo) const =0;
210
211 // Constant Data
212 static const byte dht_;
213 static const byte dqt_;
214 static const byte dri_;
215 static const byte sos_;
216 static const byte eoi_;
217 static const byte app0_;
218 static const byte app1_;
219 static const byte app2_;
220 static const byte app13_;
221 static const byte com_;
222 static const byte sof0_;
223 static const byte sof1_;
224 static const byte sof2_;
225 static const byte sof3_;
226 static const byte sof5_;
227 static const byte sof6_;
228 static const byte sof7_;
229 static const byte sof9_;
230 static const byte sof10_;
231 static const byte sof11_;
232 static const byte sof13_;
233 static const byte sof14_;
234 static const byte sof15_;
235 static const char exifId_[];
236 static const char jfifId_[];
237 static const char xmpId_[];
238 static const char iccId_[];
239
240 private:
242
243
244 JpegBase();
246 JpegBase(const JpegBase& rhs);
248 JpegBase& operator=(const JpegBase& rhs);
250
252
253
260 int initImage(const byte initData[], long dataSize);
268 void doWriteMetadata(BasicIo& oIo);
270
272
273
281 int advanceToMarker() const;
283
284 }; // class JpegBase
285
289 class EXIV2API JpegImage : public JpegBase {
290 friend EXIV2API bool isJpegType(BasicIo& iIo, bool advance);
291 public:
293
294
309 JpegImage(BasicIo::AutoPtr io, bool create);
311
313 std::string mimeType() const;
315
316 protected:
318
319 bool isThisType(BasicIo& iIo, bool advance) const;
321
323
331 int writeHeader(BasicIo& oIo) const;
333
334 private:
335 // Constant data
336 static const byte soi_; // SOI marker
337 static const byte blank_[]; // Minimal Jpeg image
338
339 // NOT Implemented
341 JpegImage();
343 JpegImage(const JpegImage& rhs);
345 JpegImage& operator=(const JpegImage& rhs);
346
347 }; // class JpegImage
348
350 class EXIV2API ExvImage : public JpegBase {
351 friend EXIV2API bool isExvType(BasicIo& iIo, bool advance);
352 public:
354
355
370 ExvImage(BasicIo::AutoPtr io, bool create);
372
374 std::string mimeType() const;
376
377 protected:
379
380 bool isThisType(BasicIo& iIo, bool advance) const;
382
384 int writeHeader(BasicIo& oIo) const;
386
387 private:
388 // Constant data
389 static const char exiv2Id_[]; // EXV identifier
390 static const byte blank_[]; // Minimal exiv2 file
391
392 // NOT Implemented
394 ExvImage();
396 ExvImage(const ExvImage& rhs);
398 ExvImage& operator=(const ExvImage& rhs);
399
400 }; // class ExvImage
401
402// *****************************************************************************
403// template, inline and free functions
404
405 // These could be static private functions on Image subclasses but then
406 // ImageFactory needs to be made a friend.
412 EXIV2API Image::AutoPtr newJpegInstance(BasicIo::AutoPtr io, bool create);
414 EXIV2API bool isJpegType(BasicIo& iIo, bool advance);
420 EXIV2API Image::AutoPtr newExvInstance(BasicIo::AutoPtr io, bool create);
422 EXIV2API bool isExvType(BasicIo& iIo, bool advance);
423
424} // namespace Exiv2
425
426#endif // #ifndef JPGIMAGE_HPP_
An interface for simple binary IO.
Definition: basicio.hpp:55
std::auto_ptr< BasicIo > AutoPtr
BasicIo auto_ptr type.
Definition: basicio.hpp:58
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition: types.hpp:193
Helper class to access Exiv2 files.
Definition: jpgimage.hpp:350
Abstract base class defining the interface for an image. This is the top-level interface to the Exiv2...
Definition: image.hpp:78
std::auto_ptr< Image > AutoPtr
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:170
Abstract helper base class to access JPEG images.
Definition: jpgimage.hpp:132
static const byte app0_
JPEG APP0 marker.
Definition: jpgimage.hpp:217
virtual int writeHeader(BasicIo &oIo) const =0
Writes the image header (aka signature) to the BasicIo instance.
static const byte com_
JPEG Comment marker.
Definition: jpgimage.hpp:221
static const byte sof2_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:224
static const byte dri_
JPEG DRI marker.
Definition: jpgimage.hpp:214
static const byte sof14_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:233
static const byte sof7_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:228
static const byte sof9_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:229
static const byte sof13_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:232
static const byte sof6_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:227
static const byte sof15_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:234
static const byte app1_
JPEG APP1 marker.
Definition: jpgimage.hpp:218
static const byte sof1_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:223
static const byte sof11_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:231
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 dqt_
JPEG DQT marker.
Definition: jpgimage.hpp:213
static const byte dht_
JPEG DHT marker.
Definition: jpgimage.hpp:212
static const byte sof0_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:222
static const byte app2_
JPEG APP2 marker.
Definition: jpgimage.hpp:219
static const byte sos_
JPEG SOS marker.
Definition: jpgimage.hpp:215
static const byte sof3_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:225
static const byte sof10_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:230
static const byte sof5_
JPEG Start-Of-Frame marker.
Definition: jpgimage.hpp:226
static const byte eoi_
JPEG EOI marker.
Definition: jpgimage.hpp:216
static const byte app13_
JPEG APP13 marker.
Definition: jpgimage.hpp:220
Class to access JPEG images.
Definition: jpgimage.hpp:289
const int exv
EXV image type (see class ExvImage)
Definition: jpgimage.hpp:40
const int jpeg
JPEG image type (see class JpegImage)
Definition: jpgimage.hpp:39
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
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:1410
EXIV2API Image::AutoPtr newExvInstance(BasicIo::AutoPtr io, bool create)
Create a new ExvImage instance and return an auto-pointer to it. Caller owns the returned object and ...
Definition: jpgimage.cpp:1402
EXIV2API bool isJpegType(BasicIo &iIo, bool advance)
Check if the file iIo is a JPEG image.
Definition: jpgimage.cpp:1358
EXIV2API Image::AutoPtr newJpegInstance(BasicIo::AutoPtr io, bool create)
Create a new JpegImage instance and return an auto-pointer to it. Caller owns the returned object and...
Definition: jpgimage.cpp:1349
Helper class, has methods to deal with Photoshop "Information Resource Blocks" (IRBs).
Definition: jpgimage.hpp:47
static const uint16_t iptc_
Photoshop IPTC marker
Definition: jpgimage.hpp:52
static const uint16_t preview_
Photoshop preview marker
Definition: jpgimage.hpp:53