Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few characterisation tests for ImageFactory and ImageType as enum class #732

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/exiv2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ install(FILES
gifimage.hpp
http.hpp
image.hpp
image_types.hpp
ini.hpp
iptc.hpp
jp2image.hpp
Expand Down
5 changes: 0 additions & 5 deletions include/exiv2/bigtiffimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
namespace Exiv2
{

namespace ImageType
{
const int bigtiff = 25;
}

Image::UniquePtr newBigTiffInstance(BasicIo::UniquePtr, bool);
bool isBigTiffType(BasicIo &, bool);

Expand Down
5 changes: 0 additions & 5 deletions include/exiv2/bmpimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions include/exiv2/cr2image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions include/exiv2/crwimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions include/exiv2/gifimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
86 changes: 34 additions & 52 deletions include/exiv2/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "basicio.hpp"
#include "exif.hpp"
#include "iptc.hpp"
#include "image_types.hpp"
#include "xmp_exiv2.hpp"

// + standard includes
Expand All @@ -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
Expand Down Expand Up @@ -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();
//@}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -605,32 +597,25 @@ namespace Exiv2 {
@throw Error If opening the BasicIo fails
*/
static Image::UniquePtr open(BasicIo::UniquePtr io);
/*!
@brief Create an Image subclass of the requested type by creating a
new image file. If the file already exists, it will be overwritten.
@param type Type of the image to be created.
@param path %Image file to create. File extension is ignored.
@return An auto-pointer that owns an Image instance of the requested
type.
@throw Error If the image type is not supported.
*/
static Image::UniquePtr create(int type, const std::string& path);

/// @brief Create an Image subclass of the requested type by creating a new image file.
/// If the file already exists, it will be overwritten.
/// @param type Type of the image to be created.
/// @param path %Image file to create. File extension is ignored.
/// @return An auto-pointer that owns an Image instance of the requested type.
/// @throws Error If the image type is not supported.
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);
/// @brief Like create() but accepts a unicode path in an std::wstring. Only available on Windows.
static Image::UniquePtr create(ImageType type, const std::wstring& wpath);
#endif
/*!
@brief Create an Image subclass of the requested type by creating a
new image in memory.
@param type Type of the image to be created.
@return An auto-pointer that owns an Image instance of the requested
type.
@throw Error If the image type is not supported
*/
static Image::UniquePtr create(int type);
/// @brief Create an Image subclass of the requested type by creating a new image in memory.
/// @param type Type of the image to be created.
/// @return An auto-pointer that owns an Image instance of the requested type.
/// @throws Error If the image type is not supported
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
Expand All @@ -645,14 +630,13 @@ 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);
/*!
@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 Image::UniquePtr create(ImageType type, BasicIo::UniquePtr io);

/// @brief Returns the image type of the provided file.
/// @param path The contents of the file are tested to determine the image type. File extension is ignored.
/// @return Image type or none if the type is not recognized.
static ImageType getType(const std::string& path);

#ifdef EXV_UNICODE_PATH
/*!
@brief Like getType() but accepts a unicode path in an std::wstring.
Expand All @@ -667,15 +651,15 @@ 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.
@param io A BasicIo instance that provides image data. The contents
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.
Expand All @@ -684,7 +668,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.

Expand All @@ -705,12 +689,10 @@ 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);

ImageFactory& operator=(const ImageFactory& rhs) = delete;
ImageFactory& operator=(const ImageFactory&& rhs) = delete;
ImageFactory(const ImageFactory& rhs) = delete;
ImageFactory(const ImageFactory&& rhs) = delete;
}; // class ImageFactory

// *****************************************************************************
Expand Down
58 changes: 58 additions & 0 deletions include/exiv2/image_types.hpp
Original file line number Diff line number Diff line change
@@ -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, // 0
jpeg, // 1 JPEG
exv, // 2 EXV
crw, // 3 CRW

tiff, // 4
dng,
nef,
pef,
arw,
sr2,
srw,

mrw, // 5 MRW
png, // 6
cr2, // 7 CR2
raf, // 8
orf, // 9 ORF
xmp, // 10 XMP sidecar files
gif, // 11 GIF
psd, // 12 Photoshop (PSD)
tga, // 13
bmp, // 14 Windows bitmap
jp2, // 15 JPEG-2000
rw2, // 16
pgf, // 17
webp, // 23
bigtiff, // 25
};
}

#endif // IMAGE_TYPES_H
6 changes: 0 additions & 6 deletions include/exiv2/jp2image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
41 changes: 12 additions & 29 deletions include/exiv2/jpgimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,7 @@ 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).
*/
/// @brief Helper class, has methods to deal with %Photoshop "Information Resource Blocks" (IRBs).
struct EXIV2API Photoshop {
// Todo: Public for now
static const char ps3Id_[]; //!< %Photoshop marker
Expand All @@ -64,26 +55,18 @@ namespace Exiv2 {
static const uint16_t iptc_; //!< %Photoshop IPTC marker
static const uint16_t preview_; //!< %Photoshop preview marker

/*!
@brief Checks an IRB
/// @brief Checks an IRB
/// @param pPsData Existing IRB buffer
/// @param sizePsData Size of the IRB buffer
/// @return true if the IRB marker is known and the buffer is big enough to check this. False otherwise
static bool isIrb(const byte* pPsData, long sizePsData);

@param pPsData Existing IRB buffer
@param sizePsData Size of the IRB buffer
@return true if the IRB marker is known and the buffer is big enough to check this;<BR>
false otherwise
*/
static bool isIrb(const byte* pPsData,
long sizePsData);
/*!
@brief Validates all IRBs
/// @brief Validates all IRBs
/// @param pPsData Existing IRB buffer
/// @param sizePsData Size of the IRB buffer, may be 0
/// @return true if all IRBs are valid. False otherwise
static bool valid(const byte* pPsData, long sizePsData);

@param pPsData Existing IRB buffer
@param sizePsData Size of the IRB buffer, may be 0
@return true if all IRBs are valid;<BR>
false otherwise
*/
static bool valid(const byte* pPsData,
long sizePsData);
/*!
@brief Locates the data for a %Photoshop tag in a %Photoshop formated memory
buffer. Operates on raw data to simplify reuse.
Expand Down Expand Up @@ -178,7 +161,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[],
Expand Down
5 changes: 0 additions & 5 deletions include/exiv2/mrwimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading