diff --git a/include/exiv2/CMakeLists.txt b/include/exiv2/CMakeLists.txt
index f07ddaca84..9dcfcdcd30 100644
--- a/include/exiv2/CMakeLists.txt
+++ b/include/exiv2/CMakeLists.txt
@@ -15,6 +15,7 @@ install(FILES
gifimage.hpp
http.hpp
image.hpp
+ image_types.hpp
ini.hpp
iptc.hpp
jp2image.hpp
diff --git a/include/exiv2/bigtiffimage.hpp b/include/exiv2/bigtiffimage.hpp
index 9fe6a1742a..76541e925f 100644
--- a/include/exiv2/bigtiffimage.hpp
+++ b/include/exiv2/bigtiffimage.hpp
@@ -5,11 +5,6 @@
namespace Exiv2
{
-namespace ImageType
-{
- const int bigtiff = 25;
-}
-
Image::UniquePtr newBigTiffInstance(BasicIo::UniquePtr, bool);
bool isBigTiffType(BasicIo &, bool);
diff --git a/include/exiv2/bmpimage.hpp b/include/exiv2/bmpimage.hpp
index 34e822aa40..2047fe03b7 100644
--- a/include/exiv2/bmpimage.hpp
+++ b/include/exiv2/bmpimage.hpp
@@ -40,11 +40,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Add Windows Bitmap (BMP) to the supported image formats
- namespace ImageType {
- const int bmp = 14; //!< Windows bitmap (bmp) image type (see class BmpImage)
- }
-
/*!
@brief Class to access Windows bitmaps. This is just a stub - we only
read width and height.
diff --git a/include/exiv2/cr2image.hpp b/include/exiv2/cr2image.hpp
index 6dea5012ca..197ef7a17d 100644
--- a/include/exiv2/cr2image.hpp
+++ b/include/exiv2/cr2image.hpp
@@ -40,11 +40,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Add CR2 to the supported image formats
- namespace ImageType {
- const int cr2 = 7; //!< CR2 image type (see class Cr2Image)
- }
-
/*!
@brief Class to access raw Canon CR2 images. Exif metadata
is supported directly, IPTC is read from the Exif data, if present.
diff --git a/include/exiv2/crwimage.hpp b/include/exiv2/crwimage.hpp
index 8653d718c4..5268115aca 100644
--- a/include/exiv2/crwimage.hpp
+++ b/include/exiv2/crwimage.hpp
@@ -47,11 +47,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Add CRW to the supported image formats
- namespace ImageType {
- const int crw = 3; //!< CRW image type (see class CrwImage)
- }
-
/*!
@brief Class to access raw Canon CRW images. Only Exif metadata and a
comment are supported. CRW format does not contain IPTC metadata.
diff --git a/include/exiv2/gifimage.hpp b/include/exiv2/gifimage.hpp
index 6bb5049ee8..01f4ab0242 100644
--- a/include/exiv2/gifimage.hpp
+++ b/include/exiv2/gifimage.hpp
@@ -41,11 +41,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Add GIF to the supported image formats
- namespace ImageType {
- const int gif = 11; //!< GIF image type (see class GifImage)
- }
-
/*!
@brief Class to access raw GIF images. Exif/IPTC metadata are supported
directly.
diff --git a/include/exiv2/image.hpp b/include/exiv2/image.hpp
index 3e0fdfdc57..db78651c6a 100644
--- a/include/exiv2/image.hpp
+++ b/include/exiv2/image.hpp
@@ -30,6 +30,7 @@
#include "basicio.hpp"
#include "exif.hpp"
#include "iptc.hpp"
+#include "image_types.hpp"
#include "xmp_exiv2.hpp"
// + standard includes
@@ -43,11 +44,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- //! Supported image formats
- namespace ImageType {
- const int none = 0; //!< Not an image
- }
-
//! Native preview information. This is meant to be used only by the PreviewManager.
struct NativePreview {
long position_; //!< Position
@@ -90,9 +86,7 @@ namespace Exiv2 {
metadata types and an auto-pointer that owns an IO instance.
See subclass constructor doc.
*/
- Image(int imageType,
- uint16_t supportedMetadata,
- BasicIo::UniquePtr io);
+ Image(ImageType type, uint16_t supportedMetadata, BasicIo::UniquePtr io);
//! Virtual Destructor
virtual ~Image();
//@}
@@ -471,16 +465,14 @@ namespace Exiv2 {
//@}
//! set type support for this image format
- void setTypeSupported(
- int imageType,
- uint16_t supportedMetadata
- ) {
+ void setTypeSupported(ImageType imageType, uint16_t supportedMetadata)
+ {
imageType_ = imageType;
supportedMetadata_ = supportedMetadata;
}
//! set type support for this image format
- int imageType() const { return imageType_; }
+ ImageType imageType() const { return imageType_; }
protected:
// DATA
@@ -509,7 +501,7 @@ namespace Exiv2 {
private:
// DATA
- int imageType_; //!< Image type
+ ImageType imageType_; //!< Image type
uint16_t supportedMetadata_; //!< Bitmap with all supported metadata types
bool writeXmpFromPacket_;//!< Determines the source when writing XMP
ByteOrder byteOrder_; //!< Byte order
@@ -614,13 +606,13 @@ namespace Exiv2 {
type.
@throw Error If the image type is not supported.
*/
- static Image::UniquePtr create(int type, const std::string& path);
+ static Image::UniquePtr create(ImageType type, const std::string& path);
#ifdef EXV_UNICODE_PATH
/*!
@brief Like create() but accepts a unicode path in an std::wstring.
@note This function is only available on Windows.
*/
- static Image::UniquePtr create(int type, const std::wstring& wpath);
+ static Image::UniquePtr create(ImageType type, const std::wstring& wpath);
#endif
/*!
@brief Create an Image subclass of the requested type by creating a
@@ -630,7 +622,8 @@ namespace Exiv2 {
type.
@throw Error If the image type is not supported
*/
- static Image::UniquePtr create(int type);
+ static Image::UniquePtr create(ImageType type);
+
/*!
@brief Create an Image subclass of the requested type by writing a
new image to a BasicIo instance. If the BasicIo instance already
@@ -645,20 +638,22 @@ namespace Exiv2 {
@return An auto-pointer that owns an Image instance of the requested
type. If the image type is not supported, the pointer is 0.
*/
- static Image::UniquePtr create(int type, BasicIo::UniquePtr io);
+
+ static Image::UniquePtr create(ImageType type, BasicIo::UniquePtr io);
/*!
@brief Returns the image type of the provided file.
@param path %Image file. The contents of the file are tested to
determine the image type. File extension is ignored.
@return %Image type or Image::none if the type is not recognized.
*/
- static int getType(const std::string& path);
+ static ImageType getType(const std::string& path);
+
#ifdef EXV_UNICODE_PATH
/*!
@brief Like getType() but accepts a unicode path in an std::wstring.
@note This function is only available on Windows.
*/
- static int getType(const std::wstring& wpath);
+ static ImageType getType(const std::wstring& wpath);
#endif
/*!
@brief Returns the image type of the provided data buffer.
@@ -667,7 +662,7 @@ namespace Exiv2 {
@param size Number of bytes pointed to by \em data.
@return %Image type or Image::none if the type is not recognized.
*/
- static int getType(const byte* data, long size);
+ static ImageType getType(const byte* data, long size);
/*!
@brief Returns the image type of data provided by a BasicIo instance.
The passed in \em io instance is (re)opened by this method.
@@ -675,7 +670,7 @@ namespace Exiv2 {
of the image data are tested to determine the type.
@return %Image type or Image::none if the type is not recognized.
*/
- static int getType(BasicIo& io);
+ static ImageType getType(BasicIo& io);
/*!
@brief Returns the access mode or supported metadata functions for an
image type and a metadata type.
@@ -684,7 +679,7 @@ namespace Exiv2 {
@return Access mode for the requested image type and metadata identifier.
@throw Error(kerUnsupportedImageType) if the image type is not supported.
*/
- static AccessMode checkMode(int type, MetadataId metadataId);
+ static AccessMode checkMode(ImageType type, MetadataId metadataId);
/*!
@brief Determine if the content of \em io is an image of \em type.
@@ -705,12 +700,10 @@ namespace Exiv2 {
@return true if the data matches the type of this class;
false if the data does not match
*/
- static bool checkType(int type, BasicIo& io, bool advance);
+ static bool checkType(ImageType type, BasicIo& io, bool advance);
ImageFactory& operator=(const ImageFactory& rhs) = delete;
- ImageFactory& operator=(const ImageFactory&& rhs) = delete;
ImageFactory(const ImageFactory& rhs) = delete;
- ImageFactory(const ImageFactory&& rhs) = delete;
}; // class ImageFactory
// *****************************************************************************
diff --git a/include/exiv2/image_types.hpp b/include/exiv2/image_types.hpp
new file mode 100644
index 0000000000..e9b9201afc
--- /dev/null
+++ b/include/exiv2/image_types.hpp
@@ -0,0 +1,58 @@
+// ***************************************************************** -*- C++ -*-
+/*
+ * Copyright (C) 2004-2019 Exiv2 authors
+ * This program is part of the Exiv2 distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDE_EXIV2_IMAGE_TYPES_H
+#define INCLUDE_EXIV2_IMAGE_TYPES_H
+
+namespace Exiv2
+{
+ /// Supported Image Formats
+ enum class ImageType
+ {
+ none,
+ arw,
+ bigtiff,
+ bmp, ///< Windows bitmap
+ cr2,
+ crw,
+ dng,
+ exv,
+ gif, ///< GIF
+ jp2, ///< JPEG-2000
+ jpeg,
+ mrw,
+ nef,
+ orf,
+ pef,
+ png,
+ pgf,
+ psd, ///< Photoshop (PSD)
+ raf,
+ rw2,
+ sr2,
+ srw,
+ tga,
+ tiff,
+ webp,
+ xmp, ///< XMP sidecar files
+ };
+} // namespace Exiv2
+
+#endif // INCLUDE_EXIV2_IMAGE_TYPES_H
diff --git a/include/exiv2/jp2image.hpp b/include/exiv2/jp2image.hpp
index cbf8439c58..a1fb23edd0 100644
--- a/include/exiv2/jp2image.hpp
+++ b/include/exiv2/jp2image.hpp
@@ -39,12 +39,6 @@ namespace Exiv2
// *****************************************************************************
// class definitions
- // Add JPEG-2000 to the supported image formats
- namespace ImageType
- {
- const int jp2 = 15; //!< JPEG-2000 image type
- }
-
/*!
@brief Class to access JPEG-2000 images.
*/
diff --git a/include/exiv2/jpgimage.hpp b/include/exiv2/jpgimage.hpp
index f1dac2033f..8795923a4b 100644
--- a/include/exiv2/jpgimage.hpp
+++ b/include/exiv2/jpgimage.hpp
@@ -46,12 +46,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Supported JPEG image formats
- namespace ImageType {
- const int jpeg = 1; //!< JPEG image type (see class JpegImage)
- const int exv = 2; //!< EXV image type (see class ExvImage)
- }
-
/*!
@brief Helper class, has methods to deal with %Photoshop "Information
Resource Blocks" (IRBs).
@@ -178,7 +172,7 @@ namespace Exiv2 {
valid image of the calling subclass.
@param dataSize Size of initData in bytes.
*/
- JpegBase(int type,
+ JpegBase(ImageType type,
BasicIo::UniquePtr io,
bool create,
const byte initData[],
diff --git a/include/exiv2/mrwimage.hpp b/include/exiv2/mrwimage.hpp
index c70570369f..2c090b9945 100644
--- a/include/exiv2/mrwimage.hpp
+++ b/include/exiv2/mrwimage.hpp
@@ -41,11 +41,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Add MRW to the supported image formats
- namespace ImageType {
- const int mrw = 5; //!< MRW image type (see class MrwImage)
- }
-
/*!
@brief Class to access raw Minolta MRW images. Exif metadata is supported
directly, IPTC is read from the Exif data, if present.
diff --git a/include/exiv2/orfimage.hpp b/include/exiv2/orfimage.hpp
index 94c48e4093..026c8abf0f 100644
--- a/include/exiv2/orfimage.hpp
+++ b/include/exiv2/orfimage.hpp
@@ -40,11 +40,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Add ORF to the supported image formats
- namespace ImageType {
- const int orf = 9; //!< ORF image type (see class OrfImage)
- }
-
/*!
@brief Class to access raw Olympus ORF images. Exif metadata is supported
directly, IPTC is read from the Exif data, if present.
diff --git a/include/exiv2/pgfimage.hpp b/include/exiv2/pgfimage.hpp
index 5093f97a47..3524e7778e 100644
--- a/include/exiv2/pgfimage.hpp
+++ b/include/exiv2/pgfimage.hpp
@@ -44,12 +44,6 @@ namespace Exiv2
// *****************************************************************************
// class definitions
- // Add PGF to the supported image formats
- namespace ImageType
- {
- const int pgf = 17; //!< PGF image type (see class PgfImage)
- }
-
/*!
@brief Class to access PGF images. Exif and IPTC metadata are supported
directly.
diff --git a/include/exiv2/pngimage.hpp b/include/exiv2/pngimage.hpp
index e3e849ecbe..821b30f14c 100644
--- a/include/exiv2/pngimage.hpp
+++ b/include/exiv2/pngimage.hpp
@@ -45,12 +45,6 @@ namespace Exiv2
// *****************************************************************************
// class definitions
- // Add PNG to the supported image formats
- namespace ImageType
- {
- const int png = 6; //!< PNG image type (see class PngImage)
- }
-
/*!
@brief Class to access PNG images. Exif and IPTC metadata are supported
directly.
diff --git a/include/exiv2/psdimage.hpp b/include/exiv2/psdimage.hpp
index 5038b7aaee..c674f2f528 100644
--- a/include/exiv2/psdimage.hpp
+++ b/include/exiv2/psdimage.hpp
@@ -43,11 +43,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Add PSD to the supported image formats
- namespace ImageType {
- const int psd = 12; //!< Photoshop (PSD) image type (see class PsdImage)
- }
-
/*!
@brief Class to access raw Photoshop images.
*/
diff --git a/include/exiv2/rafimage.hpp b/include/exiv2/rafimage.hpp
index 6f68001a61..844f8f12e9 100644
--- a/include/exiv2/rafimage.hpp
+++ b/include/exiv2/rafimage.hpp
@@ -45,11 +45,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Add RAF to the supported image formats
- namespace ImageType {
- const int raf = 8; //!< RAF image type (see class RafImage)
- }
-
/*!
@brief Class to access raw Fujifilm RAF images. Exif metadata is
supported directly, IPTC is read from the Exif data, if present.
diff --git a/include/exiv2/rw2image.hpp b/include/exiv2/rw2image.hpp
index 3cce5f193e..438fc45e60 100644
--- a/include/exiv2/rw2image.hpp
+++ b/include/exiv2/rw2image.hpp
@@ -40,11 +40,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Add RW2 to the supported image formats
- namespace ImageType {
- const int rw2 = 16; //!< RW2 image type (see class Rw2Image)
- }
-
/*!
@brief Class to access raw Panasonic RW2 images. Exif metadata is
supported directly, IPTC and XMP are read from the Exif data, if
diff --git a/include/exiv2/tgaimage.hpp b/include/exiv2/tgaimage.hpp
index 1dee6d4434..b42e483cfc 100644
--- a/include/exiv2/tgaimage.hpp
+++ b/include/exiv2/tgaimage.hpp
@@ -42,11 +42,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Add TARGA to the supported image formats
- namespace ImageType {
- const int tga = 13; //!< Truevision TARGA (tga) image type (see class TgaImage)
- }
-
/*!
@brief Class to access raw TARGA images. This is just a stub - we only
read width and height.
diff --git a/include/exiv2/tiffimage.hpp b/include/exiv2/tiffimage.hpp
index 2e4bcf534e..6e3154043a 100644
--- a/include/exiv2/tiffimage.hpp
+++ b/include/exiv2/tiffimage.hpp
@@ -37,17 +37,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Add TIFF to the supported image formats
- namespace ImageType {
- const int tiff = 4; //!< TIFF image type (see class TiffImage)
- const int dng = 4; //!< DNG image type (see class TiffImage)
- const int nef = 4; //!< NEF image type (see class TiffImage)
- const int pef = 4; //!< PEF image type (see class TiffImage)
- const int arw = 4; //!< ARW image type (see class TiffImage)
- const int sr2 = 4; //!< SR2 image type (see class TiffImage)
- const int srw = 4; //!< SRW image type (see class TiffImage)
- }
-
/*!
@brief Class to access TIFF images. Exif metadata is
supported directly, IPTC is read from the Exif data, if present.
diff --git a/include/exiv2/types.hpp b/include/exiv2/types.hpp
index e8aa008d37..1de91ccec1 100644
--- a/include/exiv2/types.hpp
+++ b/include/exiv2/types.hpp
@@ -90,16 +90,39 @@ namespace Exiv2 {
typedef std::pair Rational;
//! Type to express the byte order (little or big endian)
- enum ByteOrder { invalidByteOrder, littleEndian, bigEndian };
+ enum ByteOrder
+ {
+ invalidByteOrder,
+ littleEndian,
+ bigEndian,
+ };
//! Type to indicate write method used by TIFF parsers
- enum WriteMethod { wmIntrusive, wmNonIntrusive };
+ enum WriteMethod
+ {
+ wmIntrusive,
+ wmNonIntrusive,
+ };
//! An identifier for each type of metadata
- enum MetadataId { mdNone=0, mdExif=1, mdIptc=2, mdComment=4, mdXmp=8, mdIccProfile=16 };
+ enum MetadataId
+ {
+ mdNone = 0,
+ mdExif = 1,
+ mdIptc = 2,
+ mdComment = 4,
+ mdXmp = 8,
+ mdIccProfile = 16,
+ };
//! An identifier for each mode of metadata support
- enum AccessMode { amNone=0, amRead=1, amWrite=2, amReadWrite=3 };
+ enum AccessMode
+ {
+ amNone = 0,
+ amRead = 1,
+ amWrite = 2,
+ amReadWrite = 3,
+ };
/*!
@brief %Exiv2 value type identifiers.
@@ -488,7 +511,7 @@ namespace Exiv2 {
const T* find(T (&src)[N], const K& key)
{
const T* rc = std::find(src, src + N, key);
- return rc == src + N ? 0 : rc;
+ return rc == src + N ? nullptr : rc;
}
//! Template used in the COUNTOF macro to determine the size of an array
diff --git a/include/exiv2/webpimage.hpp b/include/exiv2/webpimage.hpp
index ebb2abdc44..dbeb68c7b0 100644
--- a/include/exiv2/webpimage.hpp
+++ b/include/exiv2/webpimage.hpp
@@ -40,11 +40,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Add WEBP to the supported image formats
- namespace ImageType {
- const int webp = 23; //!< Treating webp as an image type>
- }
-
/*!
@brief Class to access WEBP video files.
*/
diff --git a/include/exiv2/xmpsidecar.hpp b/include/exiv2/xmpsidecar.hpp
index 5136072bf5..a4c30b6395 100644
--- a/include/exiv2/xmpsidecar.hpp
+++ b/include/exiv2/xmpsidecar.hpp
@@ -40,11 +40,6 @@ namespace Exiv2 {
// *****************************************************************************
// class definitions
- // Add XMP to the supported image formats
- namespace ImageType {
- const int xmp = 10; //!< XMP sidecar files (see class XmpSidecar)
- }
-
/*!
@brief Class to access XMP sidecar files. They contain only XMP metadata.
*/
diff --git a/src/actions.cpp b/src/actions.cpp
index b921b17dcf..ce160bd862 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -115,7 +115,7 @@ namespace {
*/
int metacopy(const std::string& source,
const std::string& target,
- int targetType,
+ Exiv2::ImageType targetType,
bool preserve);
/*!
@@ -2073,7 +2073,7 @@ namespace {
int metacopy(const std::string& source,
const std::string& tgt,
- int targetType,
+ Exiv2::ImageType targetType,
bool preserve)
{
#ifdef DEBUG
diff --git a/src/basicio.cpp b/src/basicio.cpp
index fae2d4fc88..b334e1d29a 100644
--- a/src/basicio.cpp
+++ b/src/basicio.cpp
@@ -1369,9 +1369,13 @@ namespace Exiv2 {
{
long avail = EXV_MAX(p_->size_ - p_->idx_, 0);
long allow = EXV_MIN(rcount, avail);
+ if (p_->data_ == nullptr) {
+ throw Error(kerCallFailed, "std::memcpy with src == nullptr");
+ }
std::memcpy(buf, &p_->data_[p_->idx_], allow);
p_->idx_ += allow;
- if (rcount > avail) p_->eof_ = true;
+ if (rcount > avail)
+ p_->eof_ = true;
return allow;
}
diff --git a/src/image.cpp b/src/image.cpp
index 9814319b13..c06c4416ce 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -82,10 +82,11 @@ namespace {
//! Struct for storing image types and function pointers.
struct Registry {
//! Comparison operator to compare a Registry structure with an image type
- bool operator==(const int& imageType) const { return imageType == imageType_; }
+ bool operator==(const ImageType& imageType) const
+ { return imageType == imageType_; }
// DATA
- int imageType_;
+ ImageType imageType_;
NewInstanceFct newInstance_;
IsThisTypeFct isThisType_;
AccessMode exifSupport_;
@@ -94,6 +95,7 @@ namespace {
AccessMode commentSupport_;
};
+ /// \todo Use std::unordered_map for implementing the registry. Avoid to use ImageType::none
const Registry registry[] = {
//image type creation fct type check Exif mode IPTC mode XMP mode Comment mode
//--------------- --------------- ---------- ----------- ----------- ----------- ------------
@@ -134,13 +136,11 @@ namespace {
// class member definitions
namespace Exiv2 {
- Image::Image(int imageType,
- uint16_t supportedMetadata,
- BasicIo::UniquePtr io)
+ Image::Image(ImageType type, uint16_t supportedMetadata, BasicIo::UniquePtr io)
: io_(std::move(io)),
pixelWidth_(0),
pixelHeight_(0),
- imageType_(imageType),
+ imageType_(type),
supportedMetadata_(supportedMetadata),
#ifdef EXV_HAVE_XMP_TOOLKIT
writeXmpFromPacket_(false),
@@ -759,10 +759,11 @@ namespace Exiv2 {
return tags_[tag] ;
}
- AccessMode ImageFactory::checkMode(int type, MetadataId metadataId)
+ AccessMode ImageFactory::checkMode(ImageType type, MetadataId metadataId)
{
const Registry* r = find(registry, type);
- if (!r) throw Error(kerUnsupportedImageType, type);
+ if (!r)
+ throw Error(kerUnsupportedImageType, static_cast(type));
AccessMode am = amNone;
switch (metadataId) {
case mdNone:
@@ -786,38 +787,39 @@ namespace Exiv2 {
return am;
}
- bool ImageFactory::checkType(int type, BasicIo& io, bool advance)
+ bool ImageFactory::checkType(ImageType type, BasicIo& io, bool advance)
{
const Registry* r = find(registry, type);
if (0 != r) {
return r->isThisType_(io, advance);
}
return false;
- } // ImageFactory::checkType
+ }
- int ImageFactory::getType(const std::string& path)
+ ImageType ImageFactory::getType(const std::string& path)
{
FileIo fileIo(path);
return getType(fileIo);
}
#ifdef EXV_UNICODE_PATH
- int ImageFactory::getType(const std::wstring& wpath)
+ ImageType ImageFactory::getType(const std::wstring& wpath)
{
FileIo fileIo(wpath);
return getType(fileIo);
}
#endif
- int ImageFactory::getType(const byte* data, long size)
+ ImageType ImageFactory::getType(const byte* data, long size)
{
MemIo memIo(data, size);
return getType(memIo);
}
- int ImageFactory::getType(BasicIo& io)
+ ImageType ImageFactory::getType(BasicIo& io)
{
- if (io.open() != 0) return ImageType::none;
+ if (io.open() != 0)
+ return ImageType::none;
IoCloser closer(io);
for (unsigned int i = 0; registry[i].imageType_ != ImageType::none; ++i) {
if (registry[i].isThisType_(io, false)) {
@@ -825,7 +827,7 @@ namespace Exiv2 {
}
}
return ImageType::none;
- } // ImageFactory::getType
+ }
BasicIo::UniquePtr ImageFactory::createIo(const std::string& path, bool useCurl)
{
@@ -853,7 +855,7 @@ namespace Exiv2 {
return BasicIo::UniquePtr(new FileIo(path));
(void)(useCurl);
- } // ImageFactory::createIo
+ }
#ifdef EXV_UNICODE_PATH
BasicIo::UniquePtr ImageFactory::createIo(const std::wstring& wpath, bool useCurl)
@@ -876,7 +878,7 @@ namespace Exiv2 {
if (fProt == pStdin || fProt == pDataUri)
return BasicIo::UniquePtr(new XPathIo(wpath)); // may throw
return BasicIo::UniquePtr(new FileIo(wpath));
- } // ImageFactory::createIo
+ }
#endif
Image::UniquePtr ImageFactory::open(const std::string& path, bool useCurl)
{
@@ -913,10 +915,9 @@ namespace Exiv2 {
}
}
return Image::UniquePtr();
- } // ImageFactory::open
+ }
- Image::UniquePtr ImageFactory::create(int type,
- const std::string& path)
+ Image::UniquePtr ImageFactory::create(ImageType type, const std::string& path)
{
std::unique_ptr fileIo(new FileIo(path));
// Create or overwrite the file, then close it
@@ -927,12 +928,12 @@ namespace Exiv2 {
BasicIo::UniquePtr io(std::move(fileIo));
Image::UniquePtr image = create(type, std::move(io));
if (!image)
- throw Error(kerUnsupportedImageType, type);
+ throw Error(kerUnsupportedImageType, static_cast(type));
return image;
}
#ifdef EXV_UNICODE_PATH
- Image::UniquePtr ImageFactory::create(int type,
+ Image::UniquePtr ImageFactory::create(ImageType type,
const std::wstring& wpath)
{
std::unique_ptr fileIo(new FileIo(wpath));
@@ -943,29 +944,32 @@ namespace Exiv2 {
fileIo->close();
BasicIo::UniquePtr io(std::move(fileIo));
Image::UniquePtr image = create(type, std::move(io));
- if (image.get() == 0) throw Error(kerUnsupportedImageType, type);
+ if (image.get() == 0) throw Error(kerUnsupportedImageType, static_cast(type));
return image;
}
#endif
- Image::UniquePtr ImageFactory::create(int type)
+ Image::UniquePtr ImageFactory::create(ImageType type)
{
BasicIo::UniquePtr io(new MemIo);
Image::UniquePtr image = create(type, std::move(io));
- if (image.get() == 0) throw Error(kerUnsupportedImageType, type);
+ if (image.get() == 0) {
+ throw Error(kerUnsupportedImageType, static_cast(type));
+ }
return image;
}
- Image::UniquePtr ImageFactory::create(int type,
- BasicIo::UniquePtr io)
+ Image::UniquePtr ImageFactory::create(ImageType type, BasicIo::UniquePtr io)
{
// BasicIo instance does not need to be open
const Registry* r = find(registry, type);
- if (0 != r) {
- return r->newInstance_(std::move(io), true);
+
+ if (r == nullptr || type == ImageType::none) {
+ return Image::UniquePtr();
}
- return Image::UniquePtr();
- } // ImageFactory::create
+
+ return r->newInstance_(std::move(io), true);
+ }
// *****************************************************************************
// template, inline and free functions
@@ -981,6 +985,6 @@ namespace Exiv2 {
blob.resize(size + len);
std::memcpy(&blob[size], buf, len);
}
- } // append
+ }
} // namespace Exiv2
diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp
index 4f216fb5f6..ffe92432a9 100644
--- a/src/jpgimage.cpp
+++ b/src/jpgimage.cpp
@@ -301,7 +301,7 @@ namespace Exiv2 {
} // Photoshop::setIptcIrb
- JpegBase::JpegBase(int type, BasicIo::UniquePtr io, bool create,
+ JpegBase::JpegBase(ImageType type, BasicIo::UniquePtr io, bool create,
const byte initData[], long dataSize)
: Image(type, mdExif | mdIptc | mdXmp | mdComment, std::move(io))
{
diff --git a/unitTests/CMakeLists.txt b/unitTests/CMakeLists.txt
index 7b6b8414ea..ef6e058124 100644
--- a/unitTests/CMakeLists.txt
+++ b/unitTests/CMakeLists.txt
@@ -14,10 +14,15 @@ add_executable(unit_tests mainTestRunner.cpp
test_helper_functions.cpp
test_slice.cpp
test_image_int.cpp
+ test_ImageFactory.cpp
$
)
-#TODO Use GTest::GTest once we upgrade the minimum CMake version required
+target_compile_definitions(unit_tests
+ PRIVATE
+ TESTDATA_PATH="${PROJECT_SOURCE_DIR}/test/data"
+)
+
target_link_libraries(unit_tests
PRIVATE
exiv2lib
diff --git a/unitTests/test_ImageFactory.cpp b/unitTests/test_ImageFactory.cpp
new file mode 100644
index 0000000000..da3c69babf
--- /dev/null
+++ b/unitTests/test_ImageFactory.cpp
@@ -0,0 +1,395 @@
+#include // Unit under test
+
+#include // Need to include this header for the Exiv2::Error exception
+
+#include
+
+using namespace Exiv2;
+
+TEST(TheImageFactory, createsInstancesForFewSupportedTypesInMemory)
+{
+ // Note that the constructor of these Image classes take an 'create' argument
+ ASSERT_NO_THROW(ImageFactory::create(ImageType::jp2));
+ ASSERT_NO_THROW(ImageFactory::create(ImageType::jpeg));
+ ASSERT_NO_THROW(ImageFactory::create(ImageType::exv));
+ ASSERT_NO_THROW(ImageFactory::create(ImageType::pgf));
+ ASSERT_NO_THROW(ImageFactory::create(ImageType::png));
+}
+
+TEST(TheImageFactory, cannotCreateInstancesForMostTypesInMemory)
+{
+ // Note that the constructor of these Image classes does not take an 'create' argument
+
+ ASSERT_THROW(ImageFactory::create(ImageType::bmp), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::cr2), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::crw), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::gif), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::mrw), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::orf), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::psd), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::raf), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::rw2), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::tga), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::webp), Error);
+
+ // TIFF
+ ASSERT_THROW(ImageFactory::create(ImageType::tiff), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::dng), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::nef), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::pef), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::arw), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::sr2), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::srw), Error);
+}
+
+TEST(TheImageFactory, throwsWithImageTypeNone)
+{
+ ASSERT_THROW(ImageFactory::create(ImageType::none), Error);
+}
+
+TEST(TheImageFactory, throwsWithNonExistingImageTypes)
+{
+ ASSERT_THROW(ImageFactory::create(static_cast(666)), Error);
+}
+
+
+TEST(TheImageFactory, createsInstancesForFewSupportedTypesInFiles)
+{
+ const std::string filePath("./here");
+
+ // Note that the constructor of these Image classes take an 'create' argument
+ ASSERT_NO_THROW(ImageFactory::create(ImageType::jp2, filePath));
+ ASSERT_NO_THROW(ImageFactory::create(ImageType::jpeg, filePath));
+ ASSERT_NO_THROW(ImageFactory::create(ImageType::exv, filePath));
+ ASSERT_NO_THROW(ImageFactory::create(ImageType::pgf, filePath));
+ ASSERT_NO_THROW(ImageFactory::create(ImageType::png, filePath));
+
+ ASSERT_EQ(0, std::remove(filePath.c_str()));
+}
+
+TEST(TheImageFactory, cannotCreateInstancesForSomeTypesInFiles)
+{
+ const std::string filePath("./here");
+
+ // Note that the constructor of these Image classes does not take an 'create' argument
+ ASSERT_THROW(ImageFactory::create(ImageType::bmp, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::cr2, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::crw, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::gif, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::mrw, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::orf, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::psd, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::raf, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::rw2, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::tga, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::webp, filePath), Error);
+
+ // TIFF
+ ASSERT_THROW(ImageFactory::create(ImageType::tiff, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::dng, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::nef, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::pef, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::arw, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::sr2, filePath), Error);
+ ASSERT_THROW(ImageFactory::create(ImageType::srw, filePath), Error);
+}
+
+TEST(TheImageFactory, loadInstancesDifferentImageTypes)
+{
+ /// \todo use filesystem library with C++17
+ std::string testData(TESTDATA_PATH);
+
+ ASSERT_EQ(ImageType::jpeg, ImageFactory::getType(testData + "/DSC_3079.jpg"));
+ ASSERT_NO_THROW(ImageFactory::open(testData + "/DSC_3079.jpg", false));
+
+ ASSERT_EQ(ImageType::exv, ImageFactory::getType(testData + "/exiv2-bug1108.exv"));
+ ASSERT_NO_THROW(ImageFactory::open(testData + "/exiv2-bug1108.exv", false));
+
+ ASSERT_EQ(ImageType::crw, ImageFactory::getType(testData + "/exiv2-canon-powershot-s40.crw"));
+ ASSERT_NO_THROW(ImageFactory::open(testData + "/exiv2-canon-powershot-s40.crw", false));
+
+ ASSERT_EQ(ImageType::tiff, ImageFactory::getType(testData + "/exiv2-bug1044.tif"));
+ ASSERT_NO_THROW(ImageFactory::open(testData + "/exiv2-bug1044.tif", false));
+
+ ASSERT_EQ(ImageType::png, ImageFactory::getType(testData + "/exiv2-bug1074.png"));
+ ASSERT_NO_THROW(ImageFactory::open(testData + "/exiv2-bug1074.png", false));
+
+ ASSERT_EQ(ImageType::xmp, ImageFactory::getType(testData + "/BlueSquare.xmp"));
+ ASSERT_NO_THROW(ImageFactory::open(testData + "/BlueSquare.xmp", false));
+
+ ASSERT_EQ(ImageType::psd, ImageFactory::getType(testData + "/exiv2-photoshop.psd"));
+ ASSERT_NO_THROW(ImageFactory::open(testData + "/exiv2-photoshop.psd", false));
+
+ ASSERT_EQ(ImageType::webp, ImageFactory::getType(testData + "/cve_2017_1000126_stack-oob-read.webp"));
+ ASSERT_NO_THROW(ImageFactory::open(testData + "/cve_2017_1000126_stack-oob-read.webp", false));
+
+ ASSERT_EQ(ImageType::pgf, ImageFactory::getType(testData + "/imagemagick.pgf"));
+ ASSERT_NO_THROW(ImageFactory::open(testData + "/imagemagick.pgf", false));
+
+ ASSERT_EQ(ImageType::jp2, ImageFactory::getType(testData + "/Reagan.jp2"));
+ ASSERT_NO_THROW(ImageFactory::open(testData + "/Reagan.jp2", false));
+}
+
+TEST(TheImageFactory, getsExpectedModesForJp2Images)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::jp2, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::jp2, mdExif));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::jp2, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::jp2, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::jp2, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::jp2, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForJpegImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::jpeg, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::jpeg, mdExif));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::jpeg, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::jpeg, mdXmp));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::jpeg, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::jpeg, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForExvImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::exv, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::exv, mdExif));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::exv, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::exv, mdXmp));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::exv, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::exv, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForPgfImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::pgf, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::pgf, mdExif));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::pgf, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::pgf, mdXmp));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::pgf, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::pgf, mdIccProfile));
+}
+
+#ifdef EXV_HAVE_LIBZ
+TEST(TheImageFactory, getsExpectedModesForPngImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::png, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::png, mdExif));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::png, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::png, mdXmp));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::png, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::png, mdIccProfile));
+}
+#endif
+
+TEST(TheImageFactory, getsExpectedModesForBmpImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::bmp, mdNone));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::bmp, mdExif));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::bmp, mdIptc));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::bmp, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::bmp, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::bmp, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForCr2Images)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::cr2, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::cr2, mdExif));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::cr2, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::cr2, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::cr2, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::cr2, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForCrwImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::crw, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::crw, mdExif));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::crw, mdIptc));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::crw, mdXmp));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::crw, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::crw, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForGifImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::gif, mdNone));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::gif, mdExif));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::gif, mdIptc));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::gif, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::gif, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::gif, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForMrwImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::mrw, mdNone));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::mrw, mdExif));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::mrw, mdIptc));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::mrw, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::mrw, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::mrw, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForOrfImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::orf, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::orf, mdExif));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::orf, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::orf, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::orf, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::orf, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForPsdImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::psd, mdNone));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::psd, mdExif));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::psd, mdIptc));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::psd, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::psd, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::psd, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForRafImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::raf, mdNone));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::raf, mdExif));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::raf, mdIptc));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::raf, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::raf, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::raf, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForRw2Images)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::rw2, mdNone));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::rw2, mdExif));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::rw2, mdIptc));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::rw2, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::rw2, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::rw2, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForTgaImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::tga, mdNone));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::tga, mdExif));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::tga, mdIptc));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::tga, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::tga, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::tga, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForWebpImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::webp, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::webp, mdExif));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::webp, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::webp, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::webp, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::webp, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForTiffImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::tiff, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::tiff, mdExif));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::tiff, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::tiff, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::tiff, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::tiff, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForDngImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::dng, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::dng, mdExif));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::dng, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::dng, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::dng, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::dng, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForNefImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::nef, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::nef, mdExif));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::nef, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::nef, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::nef, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::nef, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForPefImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::pef, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::pef, mdExif));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::pef, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::pef, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::pef, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::pef, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForArwImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::arw, mdNone));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::arw, mdExif));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::arw, mdIptc));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::arw, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::arw, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::arw, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForSr2Images)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::sr2, mdNone));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::sr2, mdExif));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::sr2, mdIptc));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::sr2, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::sr2, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::sr2, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForSrwImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::srw, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::srw, mdExif));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::srw, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::srw, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::srw, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::srw, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForXmpImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::xmp, mdNone));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::xmp, mdExif));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::xmp, mdIptc));
+ ASSERT_EQ(amReadWrite, ImageFactory::checkMode(ImageType::xmp, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::xmp, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::xmp, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForBigTiffImages)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::bigtiff, mdNone));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::bigtiff, mdExif));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::bigtiff, mdIptc));
+ ASSERT_EQ(amRead, ImageFactory::checkMode(ImageType::bigtiff, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::bigtiff, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::bigtiff, mdIccProfile));
+}
+
+TEST(TheImageFactory, getsExpectedModesForNoneValue)
+{
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdNone));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdExif));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdIptc));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdXmp));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdComment));
+ ASSERT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdIccProfile));
+}
+
+/// \todo check why JpegBase is taking ImageType in the constructor