Replace ImageType namespace by a enum class

This commit is contained in:
Luis Díaz Más 2019-03-03 16:33:14 +01:00
parent c499d02dbf
commit 5a9799ffb2
24 changed files with 98 additions and 151 deletions

View File

@ -53,12 +53,6 @@ namespace Exiv2
// *****************************************************************************
// class definitions
// Add Base Media File Format to the supported image formats
namespace ImageType
{
const int bmff = 19; //!< BMFF (bmff) image type (see class BMFF)
}
/*!
@brief Class to access BMFF images.
*/

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -48,11 +48,6 @@ namespace Exiv2
// *****************************************************************************
// class definitions
// Add EPS to the supported image formats
namespace ImageType {
const int eps = 18; //!< EPS image type
}
/*!
@brief Class to access EPS images.
*/

View File

@ -33,11 +33,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.

View File

@ -27,6 +27,7 @@
#include "basicio.hpp"
#include "exif.hpp"
#include "iptc.hpp"
#include "image_types.hpp"
#include "xmp_exiv2.hpp"
// + standard includes
@ -40,11 +41,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
@ -87,9 +83,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() = default;
//@}
@ -470,16 +464,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_; }
//! @name NOT implemented
//@{
@ -510,7 +502,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
@ -603,8 +595,7 @@ 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);
/*!
@brief Create an Image subclass of the requested type by creating a
new image in memory.
@ -613,7 +604,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
@ -628,15 +620,15 @@ 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);
/*!
@brief Returns the image type of the provided data buffer.
@param data Pointer to a data buffer containing an image. The contents
@ -644,7 +636,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.
@ -652,7 +644,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.
@ -661,7 +653,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.
@ -682,7 +674,7 @@ namespace Exiv2 {
@return true if the data matches the type of this class;<BR>
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);
//! @name Creators
//@{

View File

@ -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 IMAGE_TYPES_H
#define IMAGE_TYPES_H
namespace Exiv2 {
/// Supported Image Formats
enum class ImageType{
none, ///<
jpeg, ///<
exv, ///<
crw, ///<
tiff, ///<
dng,
nef,
pef,
arw,
sr2,
srw,
mrw, ///<
png, ///<
cr2, ///<
raf, ///<
orf, ///<
xmp, ///< XMP sidecar files
gif, ///< GIF
psd, ///< Photoshop (PSD)
tga, ///<
bmp, ///< Windows bitmap
jp2, ///< JPEG-2000
rw2, ///<
pgf, ///<
webp, ///<
bigtiff, ///<
eps,
bmff,
};
}
#endif // IMAGE_TYPES_H

View File

@ -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.
*/

View File

@ -37,12 +37,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).
@ -179,7 +173,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[],

View File

@ -33,11 +33,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.

View File

@ -33,11 +33,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.

View File

@ -34,12 +34,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.

View File

@ -34,12 +34,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.

View File

@ -33,11 +33,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.
*/

View File

@ -38,11 +38,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.

View File

@ -33,11 +33,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

View File

@ -33,11 +33,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.

View File

@ -34,17 +34,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.

View File

@ -33,11 +33,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.
*/

View File

@ -33,11 +33,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.
*/

View File

@ -118,7 +118,7 @@ namespace {
be kept.
@return 0 if successful, else an error code
*/
int metacopy(const std::string& source, const std::string& tgt, int targetType, bool preserve);
int metacopy(const std::string& source, const std::string& tgt, Exiv2::ImageType targetType, bool preserve);
/*!
@brief Rename a file according to a timestamp value.
@ -1811,7 +1811,7 @@ namespace {
int metacopy(const std::string& source,
const std::string& tgt,
int targetType,
Exiv2::ImageType targetType,
bool preserve)
{
#ifdef EXIV2_DEBUG_MESSAGES

View File

@ -84,10 +84,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_;
@ -138,11 +139,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),
@ -776,10 +777,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<int>(type));
AccessMode am = amNone;
switch (metadataId) {
case mdNone:
@ -803,7 +805,7 @@ 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 (nullptr != r) {
@ -812,21 +814,22 @@ namespace Exiv2 {
return false;
}
int ImageFactory::getType(const std::string& path)
ImageType ImageFactory::getType(const std::string& path)
{
FileIo fileIo(path);
return getType(fileIo);
}
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)) {
@ -834,7 +837,7 @@ namespace Exiv2 {
}
}
return ImageType::none;
} // ImageFactory::getType
}
BasicIo::UniquePtr ImageFactory::createIo(const std::string& path, bool useCurl)
{
@ -888,7 +891,7 @@ namespace Exiv2 {
return nullptr;
}
Image::UniquePtr ImageFactory::create(int type, const std::string& path)
Image::UniquePtr ImageFactory::create(ImageType type, const std::string& path)
{
auto fileIo = std::make_unique<FileIo>(path);
// Create or overwrite the file, then close it
@ -900,20 +903,20 @@ namespace Exiv2 {
BasicIo::UniquePtr io(std::move(fileIo));
auto image = create(type, std::move(io));
if (!image)
throw Error(kerUnsupportedImageType, type);
throw Error(kerUnsupportedImageType, static_cast<int>(type));
return image;
}
Image::UniquePtr ImageFactory::create(int type)
Image::UniquePtr ImageFactory::create(ImageType type)
{
auto io = std::make_unique<MemIo>();
auto image = create(type, std::move(io));
if (!image)
throw Error(kerUnsupportedImageType, type);
throw Error(kerUnsupportedImageType, static_cast<int>(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);

View File

@ -305,7 +305,7 @@ namespace Exiv2 {
marker == sos_;
}
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))
{