Coverage Report

Created: 2024-05-20 06:23

/src/exiv2/include/exiv2/image.hpp
Line
Count
Source (jump to first uncovered line)
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
3
#ifndef IMAGE_HPP_
4
#define IMAGE_HPP_
5
6
// *****************************************************************************
7
#include "exiv2lib_export.h"
8
9
// included header files
10
#include "basicio.hpp"
11
#include "exif.hpp"
12
#include "image_types.hpp"
13
#include "iptc.hpp"
14
#include "xmp_exiv2.hpp"
15
16
// *****************************************************************************
17
// namespace extensions
18
namespace Exiv2 {
19
// *****************************************************************************
20
// class definitions
21
22
//! Native preview information. This is meant to be used only by the PreviewManager.
23
struct NativePreview {
24
  size_t position_{};     //!< Position
25
  size_t size_{};         //!< Size
26
  size_t width_{};        //!< Width
27
  size_t height_{};       //!< Height
28
  std::string filter_;    //!< Filter
29
  std::string mimeType_;  //!< MIME type
30
};
31
32
//! List of native previews. This is meant to be used only by the PreviewManager.
33
using NativePreviewList = std::vector<NativePreview>;
34
35
/*!
36
  @brief Options for printStructure
37
 */
38
enum PrintStructureOption { kpsNone, kpsBasic, kpsXMP, kpsRecursive, kpsIccProfile, kpsIptcErase };
39
40
/*!
41
  @brief Abstract base class defining the interface for an image. This is
42
     the top-level interface to the Exiv2 library.
43
44
  Image has containers to store image metadata and subclasses implement
45
  read and save metadata from and to specific image formats.<BR>
46
  Most client apps will obtain an Image instance by calling a static
47
  ImageFactory method. The Image class can then be used to to read, write,
48
  and save metadata.
49
 */
50
class EXIV2API Image {
51
 public:
52
  //! Image auto_ptr type
53
  using UniquePtr = std::unique_ptr<Image>;
54
55
  //! @name Creators
56
  //@{
57
  /*!
58
    @brief Constructor taking the image type, a bitmap of the supported
59
        metadata types and an auto-pointer that owns an IO instance.
60
        See subclass constructor doc.
61
   */
62
  Image(ImageType type, uint16_t supportedMetadata, BasicIo::UniquePtr io);
63
  //! Virtual Destructor
64
10.5k
  virtual ~Image() = default;
65
  //@}
66
67
  //! @name Manipulators
68
  //@{
69
  /*!
70
    @brief Print out the structure of image file.
71
    @throw Error if reading of the file fails or the image data is
72
          not valid (does not look like data of the specific image type).
73
    @warning This function is not thread safe and intended for exiv2 -pS for debugging.
74
    @warning You may need to put the stream into binary mode (see src/actions.cpp)
75
   */
76
  virtual void printStructure(std::ostream& out, PrintStructureOption option = kpsNone, size_t depth = 0);
77
  /*!
78
    @brief Read all metadata supported by a specific image format from the
79
        image. Before this method is called, the image metadata will be
80
        cleared.
81
82
    This method returns success even if no metadata is found in the
83
    image. Callers must therefore check the size of individual metadata
84
    types before accessing the data.
85
86
    @throw Error if opening or reading of the file fails or the image
87
        data is not valid (does not look like data of the specific image
88
        type).
89
   */
90
  virtual void readMetadata() = 0;
91
  /*!
92
    @brief Write metadata back to the image.
93
94
    All existing metadata sections in the image are either created,
95
    replaced, or erased. If values for a given metadata type have been
96
    assigned, a section for that metadata type will either be created or
97
    replaced. If no values have been assigned to a given metadata type,
98
    any exists section for that metadata type will be removed from the
99
    image.
100
101
    @throw Error if the operation fails
102
   */
103
  virtual void writeMetadata() = 0;
104
  /*!
105
    @brief Assign new Exif data. The new Exif data is not written
106
        to the image until the writeMetadata() method is called.
107
    @param exifData An ExifData instance holding Exif data to be copied
108
   */
109
  virtual void setExifData(const ExifData& exifData);
110
  /*!
111
    @brief Erase any buffered Exif data. Exif data is not removed from
112
        the actual image until the writeMetadata() method is called.
113
   */
114
  virtual void clearExifData();
115
  /*!
116
    @brief Assign new IPTC data. The new IPTC data is not written
117
        to the image until the writeMetadata() method is called.
118
    @param iptcData An IptcData instance holding IPTC data to be copied
119
   */
120
  virtual void setIptcData(const IptcData& iptcData);
121
  /*!
122
    @brief Erase any buffered IPTC data. IPTC data is not removed from
123
        the actual image until the writeMetadata() method is called.
124
   */
125
  virtual void clearIptcData();
126
  /*!
127
    @brief Assign a raw XMP packet. The new XMP packet is not written
128
        to the image until the writeMetadata() method is called.
129
130
    Subsequent calls to writeMetadata() write the XMP packet from
131
    the buffered raw XMP packet rather than from buffered parsed XMP
132
    data. In order to write from parsed XMP data again, use
133
    either writeXmpFromPacket(false) or setXmpData().
134
135
    @param xmpPacket A string containing the raw XMP packet.
136
   */
137
  virtual void setXmpPacket(const std::string& xmpPacket);
138
  /*!
139
    @brief Erase the buffered XMP packet. XMP data is not removed from
140
        the actual image until the writeMetadata() method is called.
141
142
    This has the same effect as clearXmpData() but operates on the
143
    buffered raw XMP packet only, not the parsed XMP data.
144
145
    Subsequent calls to writeMetadata() write the XMP packet from
146
    the buffered raw XMP packet rather than from buffered parsed XMP
147
    data. In order to write from parsed XMP data again, use
148
    either writeXmpFromPacket(false) or setXmpData().
149
   */
150
  virtual void clearXmpPacket();
151
  /*!
152
    @brief Assign new XMP data. The new XMP data is not written
153
        to the image until the writeMetadata() method is called.
154
155
    Subsequent calls to writeMetadata() encode the XMP data to
156
    a raw XMP packet and write the newly encoded packet to the image.
157
    In the process, the buffered raw XMP packet is updated.
158
    In order to write directly from the raw XMP packet, use
159
    writeXmpFromPacket(true) or setXmpPacket().
160
161
    @param xmpData An XmpData instance holding XMP data to be copied
162
   */
163
  virtual void setXmpData(const XmpData& xmpData);
164
  /*!
165
    @brief Erase any buffered XMP data. XMP data is not removed from
166
        the actual image until the writeMetadata() method is called.
167
168
    This has the same effect as clearXmpPacket() but operates on the
169
    buffered parsed XMP data.
170
171
    Subsequent calls to writeMetadata() encode the XMP data to
172
    a raw XMP packet and write the newly encoded packet to the image.
173
    In the process, the buffered raw XMP packet is updated.
174
    In order to write directly from the raw XMP packet, use
175
    writeXmpFromPacket(true) or setXmpPacket().
176
   */
177
  virtual void clearXmpData();
178
179
  /// @brief Set the image comment. The comment is written to the image when writeMetadata() is called.
180
  virtual void setComment(const std::string& comment);
181
182
  /*!
183
    @brief Erase any buffered comment. Comment is not removed
184
        from the actual image until the writeMetadata() method is called.
185
   */
186
  virtual void clearComment();
187
  /*!
188
    @brief Set the image iccProfile. The new profile is not written
189
        to the image until the writeMetadata() method is called.
190
    @param iccProfile DataBuf containing profile (binary)
191
    @param bTestValid - tests that iccProfile contains credible data
192
   */
193
  virtual void setIccProfile(DataBuf&& iccProfile, bool bTestValid = true);
194
  /*!
195
    @brief Erase iccProfile. the profile is not removed from
196
        the actual image until the writeMetadata() method is called.
197
   */
198
  virtual void clearIccProfile();
199
  /*!
200
    @brief Returns the status of the ICC profile in the image instance
201
   */
202
373
  virtual bool iccProfileDefined() {
203
373
    return !iccProfile_.empty();
204
373
  }
205
206
  /*!
207
    @brief return iccProfile
208
   */
209
0
  [[nodiscard]] virtual const DataBuf& iccProfile() const {
210
0
    return iccProfile_;
211
0
  }
212
213
  /*!
214
    @brief Copy all existing metadata from source Image. The data is
215
        copied into internal buffers and is not written to the image
216
        until the writeMetadata() method is called.
217
    @param image Metadata source. All metadata types are copied.
218
   */
219
  virtual void setMetadata(const Image& image);
220
  /*!
221
    @brief Erase all buffered metadata. Metadata is not removed
222
        from the actual image until the writeMetadata() method is called.
223
   */
224
  virtual void clearMetadata();
225
  /*!
226
    @brief Returns an ExifData instance containing currently buffered
227
        Exif data.
228
229
    The contained Exif data may have been read from the image by
230
    a previous call to readMetadata() or added directly. The Exif
231
    data in the returned instance will be written to the image when
232
    writeMetadata() is called.
233
234
    @return modifiable ExifData instance containing Exif values
235
   */
236
  virtual ExifData& exifData();
237
  /*!
238
    @brief Returns an IptcData instance containing currently buffered
239
        IPTC data.
240
241
    The contained IPTC data may have been read from the image by
242
    a previous call to readMetadata() or added directly. The IPTC
243
    data in the returned instance will be written to the image when
244
    writeMetadata() is called.
245
246
    @return modifiable IptcData instance containing IPTC values
247
   */
248
  virtual IptcData& iptcData();
249
  /*!
250
    @brief Returns an XmpData instance containing currently buffered
251
        XMP data.
252
253
    The contained XMP data may have been read from the image by
254
    a previous call to readMetadata() or added directly. The XMP
255
    data in the returned instance will be written to the image when
256
    writeMetadata() is called.
257
258
    @return modifiable XmpData instance containing XMP values
259
   */
260
  virtual XmpData& xmpData();
261
  /*!
262
    @brief Return a modifiable reference to the raw XMP packet.
263
   */
264
  virtual std::string& xmpPacket();
265
  /*!
266
    @brief Determine the source when writing XMP.
267
268
    Depending on the setting of this flag, writeMetadata() writes
269
    XMP from the buffered raw XMP packet or from parsed XMP data.
270
    The default is to write from parsed XMP data. The switch is also
271
    set by all functions to set and clear the buffered raw XMP packet
272
    and parsed XMP data, so using this function should usually not be
273
    necessary.
274
275
    If %Exiv2 was compiled without XMP support, the default for this
276
    flag is true and it will never be changed in order to preserve
277
    access to the raw XMP packet.
278
   */
279
  void writeXmpFromPacket(bool flag);
280
  /*!
281
    @brief Set the byte order to encode the Exif metadata in.
282
283
    The setting is only used when new Exif metadata is created and may
284
    not be applicable at all for some image formats. If the target image
285
    already contains Exif metadata, the byte order of the existing data
286
    is used. If byte order is not set when writeMetadata() is called,
287
    little-endian byte order (II) is used by default.
288
   */
289
  void setByteOrder(ByteOrder byteOrder);
290
291
  /*!
292
    @brief Print out the structure of image file.
293
    @throw Error if reading of the file fails or the image data is
294
          not valid (does not look like data of the specific image type).
295
   */
296
  void printTiffStructure(BasicIo& io, std::ostream& out, PrintStructureOption option, size_t depth, size_t offset = 0);
297
298
  /*!
299
    @brief Print out the structure of a TIFF IFD
300
   */
301
  void printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStructureOption option, size_t start, bool bSwap,
302
                         char c, size_t depth);
303
304
  /*!
305
    @brief is the host platform bigEndian
306
   */
307
  static bool isBigEndianPlatform();
308
309
  /*!
310
    @brief is the host platform littleEndian
311
   */
312
  static bool isLittleEndianPlatform();
313
314
  static bool isStringType(uint16_t type);
315
  static bool isShortType(uint16_t type);
316
  static bool isLongType(uint16_t type);
317
  static bool isLongLongType(uint16_t type);
318
  static bool isRationalType(uint16_t type);
319
  static bool is2ByteType(uint16_t type);
320
  static bool is4ByteType(uint16_t type);
321
  static bool is8ByteType(uint16_t type);
322
  static bool isPrintXMP(uint16_t type, Exiv2::PrintStructureOption option);
323
  static bool isPrintICC(uint16_t type, Exiv2::PrintStructureOption option);
324
325
  static uint64_t byteSwap(uint64_t value, bool bSwap);
326
  static uint32_t byteSwap(uint32_t value, bool bSwap);
327
  static uint16_t byteSwap(uint16_t value, bool bSwap);
328
  static uint16_t byteSwap2(const DataBuf& buf, size_t offset, bool bSwap);
329
  static uint32_t byteSwap4(const DataBuf& buf, size_t offset, bool bSwap);
330
  static uint64_t byteSwap8(const DataBuf& buf, size_t offset, bool bSwap);
331
332
  //@}
333
334
  //! @name Accessors
335
  //@{
336
  /*!
337
    @brief Return the byte order in which the Exif metadata of the image is
338
           encoded. Initially, it is not set (\em invalidByteOrder).
339
   */
340
  [[nodiscard]] ByteOrder byteOrder() const;
341
342
  /*! @brief Check if the Image instance is valid. Use after object construction.
343
    @return true if the Image is in a valid state.
344
   */
345
  [[nodiscard]] bool good() const;
346
  /*!
347
    @brief Return the MIME type of the image.
348
349
    @note For each supported image format, the library knows only one MIME
350
    type.  This may not be the most specific MIME type for that format. In
351
    particular, several RAW formats are variants of the TIFF format with
352
    the same magic as TIFF itself. Class TiffImage handles most of them
353
    and thus they all have MIME type "image/tiff", although a more
354
    specific MIME type may exist (e.g., "image/x-nikon-nef").
355
   */
356
  [[nodiscard]] virtual std::string mimeType() const = 0;
357
  /*!
358
    @brief Return the pixel width of the image.
359
   */
360
  [[nodiscard]] virtual uint32_t pixelWidth() const;
361
  /*!
362
    @brief Return the pixel height of the image.
363
   */
364
  [[nodiscard]] virtual uint32_t pixelHeight() const;
365
  /*!
366
    @brief Returns an ExifData instance containing currently buffered
367
        Exif data.
368
369
    The Exif data may have been read from the image by
370
    a previous call to readMetadata() or added directly. The Exif
371
    data in the returned instance will be written to the image when
372
    writeMetadata() is called.
373
374
    @return read only ExifData instance containing Exif values
375
   */
376
  [[nodiscard]] virtual const ExifData& exifData() const;
377
  /*!
378
    @brief Returns an IptcData instance containing currently buffered
379
        IPTC data.
380
381
    The contained IPTC data may have been read from the image by
382
    a previous call to readMetadata() or added directly. The IPTC
383
    data in the returned instance will be written to the image when
384
    writeMetadata() is called.
385
386
    @return modifiable IptcData instance containing IPTC values
387
   */
388
  [[nodiscard]] virtual const IptcData& iptcData() const;
389
  /*!
390
    @brief Returns an XmpData instance containing currently buffered
391
        XMP data.
392
393
    The contained XMP data may have been read from the image by
394
    a previous call to readMetadata() or added directly. The XMP
395
    data in the returned instance will be written to the image when
396
    writeMetadata() is called.
397
398
    @return modifiable XmpData instance containing XMP values
399
   */
400
  [[nodiscard]] virtual const XmpData& xmpData() const;
401
  /*!
402
    @brief Return a copy of the image comment. May be an empty string.
403
   */
404
  [[nodiscard]] virtual std::string comment() const;
405
  /*!
406
    @brief Return the raw XMP packet as a string.
407
   */
408
  [[nodiscard]] virtual const std::string& xmpPacket() const;
409
  /*!
410
    @brief Return a reference to the BasicIo instance being used for Io.
411
412
    This reference is particularly useful to reading the results of
413
    operations on a MemIo instance. For example after metadata has
414
    been modified and the writeMetadata() method has been called,
415
    this method can be used to get access to the modified image.
416
417
    @return BasicIo instance that can be used to read or write image
418
       data directly.
419
    @note If the returned BasicIo is used to write to the image, the
420
       Image class will not see those changes until the readMetadata()
421
       method is called.
422
   */
423
  [[nodiscard]] virtual BasicIo& io() const;
424
  /*!
425
    @brief Returns the access mode, i.e., the metadata functions, which
426
       this image supports for the metadata type \em metadataId.
427
    @param metadataId The metadata identifier.
428
    @return Access mode for the requested image type and metadata identifier.
429
   */
430
  [[nodiscard]] AccessMode checkMode(MetadataId metadataId) const;
431
  /*!
432
    @brief Check if image supports a particular type of metadata.
433
    @deprecated This method is deprecated. Use checkMode() instead.
434
   */
435
  [[deprecated]] [[nodiscard]] bool supportsMetadata(MetadataId metadataId) const;
436
  //! Return the flag indicating the source when writing XMP metadata.
437
  [[nodiscard]] bool writeXmpFromPacket() const;
438
  //! Return list of native previews. This is meant to be used only by the PreviewManager.
439
  [[nodiscard]] const NativePreviewList& nativePreviews() const;
440
  //@}
441
442
  //! set type support for this image format
443
2
  void setTypeSupported(ImageType imageType, uint16_t supportedMetadata) {
444
2
    imageType_ = imageType;
445
2
    supportedMetadata_ = supportedMetadata;
446
2
  }
447
448
  //! set type support for this image format
449
10.4k
  [[nodiscard]] ImageType imageType() const {
450
10.4k
    return imageType_;
451
10.4k
  }
452
453
  //! @name NOT implemented
454
  //@{
455
  //! Copy constructor
456
  Image(const Image&) = delete;
457
  //! Assignment operator
458
  Image& operator=(const Image&) = delete;
459
  //@}
460
461
 protected:
462
  // DATA
463
  BasicIo::UniquePtr io_;             //!< Image data IO pointer
464
  ExifData exifData_;                 //!< Exif data container
465
  IptcData iptcData_;                 //!< IPTC data container
466
  XmpData xmpData_;                   //!< XMP data container
467
  DataBuf iccProfile_;                //!< ICC buffer (binary data)
468
  std::string comment_;               //!< User comment
469
  std::string xmpPacket_;             //!< XMP packet
470
  uint32_t pixelWidth_{0};            //!< image pixel width
471
  uint32_t pixelHeight_{0};           //!< image pixel height
472
  NativePreviewList nativePreviews_;  //!< list of native previews
473
474
  //! Return tag name for given tag id.
475
  const std::string& tagName(uint16_t tag);
476
477
  //! Return tag type for given tag id.
478
  static const char* typeName(uint16_t tag);
479
480
 private:
481
  // DATA
482
  ImageType imageType_;         //!< Image type
483
  uint16_t supportedMetadata_;  //!< Bitmap with all supported metadata types
484
#ifdef EXV_HAVE_XMP_TOOLKIT
485
  bool writeXmpFromPacket_{false};  //!< Determines the source when writing XMP
486
#else
487
  bool writeXmpFromPacket_{true};  //!< Determines the source when writing XMP
488
#endif
489
  ByteOrder byteOrder_{invalidByteOrder};  //!< Byte order
490
491
  std::map<int, std::string> tags_;  //!< Map of tags
492
  bool init_{true};                  //!< Flag marking if map of tags needs to be initialized
493
494
};  // class Image
495
496
//! Type for function pointer that creates new Image instances
497
using NewInstanceFct = Image::UniquePtr (*)(BasicIo::UniquePtr io, bool create);
498
//! Type for function pointer that checks image types
499
using IsThisTypeFct = bool (*)(BasicIo& iIo, bool advance);
500
501
/*!
502
  @brief Returns an Image instance of the specified type.
503
504
  The factory is implemented as a static class.
505
*/
506
class EXIV2API ImageFactory {
507
  friend bool Image::good() const;
508
509
 public:
510
  /*!
511
    @brief Create the appropriate class type implemented BasicIo based on the protocol of the input.
512
513
    "-" path implies the data from stdin and it is handled by StdinIo.
514
    Http path can be handled by either HttpIo or CurlIo. Https, ftp paths
515
    are handled by CurlIo. Ssh, sftp paths are handled by SshIo. Others are handled by FileIo.
516
517
    @param path %Image file.
518
    @param useCurl Indicate whether the libcurl is used or not.
519
          If it's true, http is handled by CurlIo. Otherwise it is handled by HttpIo.
520
    @return An auto-pointer that owns an BasicIo instance.
521
    @throw Error If the file is not found or it is unable to connect to the server to
522
          read the remote file.
523
   */
524
  static BasicIo::UniquePtr createIo(const std::string& path, bool useCurl = true);
525
526
  /*!
527
    @brief Create an Image subclass of the appropriate type by reading
528
        the specified file. %Image type is derived from the file
529
        contents.
530
    @param  path %Image file. The contents of the file are tested to
531
        determine the image type. File extension is ignored.
532
    @param useCurl Indicate whether the libcurl is used or not.
533
          If it's true, http is handled by CurlIo. Otherwise it is handled by HttpIo.
534
    @return An auto-pointer that owns an Image instance whose type
535
        matches that of the file.
536
    @throw Error If opening the file fails or it contains data of an
537
        unknown image type.
538
   */
539
  static Image::UniquePtr open(const std::string& path, bool useCurl = true);
540
541
  /*!
542
    @brief Create an Image subclass of the appropriate type by reading
543
        the provided memory. %Image type is derived from the memory
544
        contents.
545
    @param data Pointer to a data buffer containing an image. The contents
546
        of the memory are tested to determine the image type.
547
    @param size Number of bytes pointed to by \em data.
548
    @return An auto-pointer that owns an Image instance whose type
549
        matches that of the data buffer.
550
    @throw Error If the memory contains data of an unknown image type.
551
   */
552
  static Image::UniquePtr open(const byte* data, size_t size);
553
  /*!
554
    @brief Create an Image subclass of the appropriate type by reading
555
        the provided BasicIo instance. %Image type is derived from the
556
        data provided by \em io. The passed in \em io instance is
557
        (re)opened by this method.
558
    @param io An auto-pointer that owns a BasicIo instance that provides
559
        image data. The contents of the image data are tested to determine
560
        the type.
561
    @note This method takes ownership of the passed
562
        in BasicIo instance through the auto-pointer. Callers should not
563
        continue to use the BasicIo instance after it is passed to this method.
564
        Use the Image::io() method to get a temporary reference.
565
    @return An auto-pointer that owns an Image instance whose type
566
        matches that of the \em io data. If no image type could be
567
        determined, the pointer is 0.
568
    @throw Error If opening the BasicIo fails
569
   */
570
  static Image::UniquePtr open(BasicIo::UniquePtr io);
571
  /*!
572
    @brief Create an Image subclass of the requested type by creating a
573
        new image file. If the file already exists, it will be overwritten.
574
    @param type Type of the image to be created.
575
    @param path %Image file to create. File extension is ignored.
576
    @return An auto-pointer that owns an Image instance of the requested
577
        type.
578
    @throw Error If the image type is not supported.
579
   */
580
  static Image::UniquePtr create(ImageType type, const std::string& path);
581
  /*!
582
    @brief Create an Image subclass of the requested type by creating a
583
        new image in memory.
584
    @param type Type of the image to be created.
585
    @return An auto-pointer that owns an Image instance of the requested
586
        type.
587
    @throw Error If the image type is not supported
588
   */
589
  static Image::UniquePtr create(ImageType type);
590
591
  /*!
592
    @brief Create an Image subclass of the requested type by writing a
593
        new image to a BasicIo instance. If the BasicIo instance already
594
        contains data, it will be overwritten.
595
    @param type Type of the image to be created.
596
    @param io An auto-pointer that owns a BasicIo instance that will
597
        be written to when creating a new image.
598
    @note This method takes ownership of the passed in BasicIo instance
599
        through the auto-pointer. Callers should not continue to use the
600
        BasicIo instance after it is passed to this method.  Use the
601
        Image::io() method to get a temporary reference.
602
    @return An auto-pointer that owns an Image instance of the requested
603
        type. If the image type is not supported, the pointer is 0.
604
   */
605
606
  static Image::UniquePtr create(ImageType type, BasicIo::UniquePtr io);
607
  /*!
608
    @brief Returns the image type of the provided file.
609
    @param path %Image file. The contents of the file are tested to
610
        determine the image type. File extension is ignored.
611
    @return %Image type or Image::none if the type is not recognized.
612
   */
613
  static ImageType getType(const std::string& path);
614
  /*!
615
    @brief Returns the image type of the provided data buffer.
616
    @param data Pointer to a data buffer containing an image. The contents
617
        of the memory are tested to determine the image type.
618
    @param size Number of bytes pointed to by \em data.
619
    @return %Image type or Image::none if the type is not recognized.
620
   */
621
  static ImageType getType(const byte* data, size_t size);
622
  /*!
623
    @brief Returns the image type of data provided by a BasicIo instance.
624
        The passed in \em io instance is (re)opened by this method.
625
    @param io A BasicIo instance that provides image data. The contents
626
        of the image data are tested to determine the type.
627
    @return %Image type or Image::none if the type is not recognized.
628
   */
629
  static ImageType getType(BasicIo& io);
630
  /*!
631
    @brief Returns the access mode or supported metadata functions for an
632
        image type and a metadata type.
633
    @param type       The image type.
634
    @param metadataId The metadata identifier.
635
    @return Access mode for the requested image type and metadata identifier.
636
    @throw Error(kerUnsupportedImageType) if the image type is not supported.
637
   */
638
  static AccessMode checkMode(ImageType type, MetadataId metadataId);
639
  /*!
640
    @brief Determine if the content of \em io is an image of \em type.
641
642
    The \em advance flag determines if the read position in the
643
    stream is moved (see below). This applies only if the type
644
    matches and the function returns true. If the type does not
645
    match, the stream position is not changed. However, if
646
    reading from the stream fails, the stream position is
647
    undefined. Consult the stream state to obtain more
648
    information in this case.
649
650
    @param type Type of the image.
651
    @param io BasicIo instance to read from.
652
    @param advance Flag indicating whether the position of the io
653
        should be advanced by the number of characters read to
654
        analyse the data (true) or left at its original
655
        position (false). This applies only if the type matches.
656
    @return  true  if the data matches the type of this class;<BR>
657
             false if the data does not match
658
  */
659
  static bool checkType(ImageType type, BasicIo& io, bool advance);
660
};  // class ImageFactory
661
662
// *****************************************************************************
663
// template, inline and free functions
664
665
//! Append \em len bytes pointed to by \em buf to \em blob.
666
EXIV2API void append(Exiv2::Blob& blob, const byte* buf, size_t len);
667
668
}  // namespace Exiv2
669
670
#endif  // #ifndef IMAGE_HPP_