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