Changed behaviour of unsupport Image functions to throw. Added better method to query the supported metadata functions for each image type. Fixes bug #491.

v0.27.3
Andreas Huggel 19 years ago
parent cd4d2583e3
commit 8e85cea8d4

@ -66,7 +66,6 @@ CCSRC = basicio.cpp \
fujimn.cpp \ fujimn.cpp \
ifd.cpp \ ifd.cpp \
image.cpp \ image.cpp \
imgreg.cpp \
iptc.cpp \ iptc.cpp \
jpgimage.cpp \ jpgimage.cpp \
makernote.cpp \ makernote.cpp \

@ -103,16 +103,21 @@ namespace Exiv2 {
return isThisType(*io_, false); return isThisType(*io_, false);
} }
AccessMode Cr2Image::checkMode(MetadataId metadataId) const
{
return ImageFactory::checkMode(ImageType::cr2, metadataId);
}
void Cr2Image::clearMetadata() void Cr2Image::clearMetadata()
{ {
clearExifData(); clearExifData();
clearComment(); clearIptcData();
} }
void Cr2Image::setMetadata(const Image& image) void Cr2Image::setMetadata(const Image& image)
{ {
setExifData(image.exifData()); setExifData(image.exifData());
setComment(image.comment()); setIptcData(image.iptcData());
} }
void Cr2Image::clearExifData() void Cr2Image::clearExifData()
@ -137,12 +142,13 @@ namespace Exiv2 {
void Cr2Image::clearComment() void Cr2Image::clearComment()
{ {
comment_.erase(); // not supported, do nothing
} }
void Cr2Image::setComment(const std::string& comment) void Cr2Image::setComment(const std::string& /*comment*/)
{ {
comment_ = comment; // not supported
throw(Error(32, "Image comment", "CR2"));
} }
void Cr2Image::readMetadata() void Cr2Image::readMetadata()
@ -167,44 +173,10 @@ namespace Exiv2 {
void Cr2Image::writeMetadata() void Cr2Image::writeMetadata()
{ {
/* /*
Todo: implement me! Todo: implement me!
*/
#ifdef DEBUG throw(Error(31, "metadata", "CR2"));
std::cerr << "Writing CR2 file " << io_->path() << "\n";
#endif
// Read existing image
DataBuf buf;
if (io_->open() == 0) {
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (isThisType(*io_, false)) {
// Read the image into a memory buffer
buf.alloc(io_->size());
io_->read(buf.pData_, buf.size_);
if (io_->error() || io_->eof()) {
buf.reset();
}
}
}
// Parse image, starting with a CR2 header component
Cr2Header::AutoPtr head(new Cr2Header);
if (buf.size_ != 0) {
head->read(buf.pData_, buf.size_);
}
Blob blob;
Cr2Parser::encode(blob, head.get(), this);
// Write new buffer to file
BasicIo::AutoPtr tempIo(io_->temporary()); // may throw
assert (tempIo.get() != 0);
tempIo->write(&blob[0], static_cast<long>(blob.size()));
io_->close();
io_->transfer(*tempIo); // may throw
*/
} // Cr2Image::writeMetadata } // Cr2Image::writeMetadata
bool Cr2Image::isThisType(BasicIo& iIo, bool advance) const bool Cr2Image::isThisType(BasicIo& iIo, bool advance) const

@ -95,13 +95,17 @@ namespace Exiv2 {
void readMetadata(); void readMetadata();
/*! /*!
@brief Todo: Write metadata back to the image. This method is not @brief Todo: Write metadata back to the image. This method is not
yet implemented. yet implemented. Calling it will throw an Error(31).
*/ */
void writeMetadata(); void writeMetadata();
void setExifData(const ExifData& exifData); void setExifData(const ExifData& exifData);
void clearExifData(); void clearExifData();
void setIptcData(const IptcData& iptcData); void setIptcData(const IptcData& iptcData);
void clearIptcData(); void clearIptcData();
/*!
@brief Not supported. CR2 format does not contain a comment.
Calling this function will throw an Error(32).
*/
void setComment(const std::string& comment); void setComment(const std::string& comment);
void clearComment(); void clearComment();
void setMetadata(const Image& image); void setMetadata(const Image& image);
@ -117,6 +121,7 @@ namespace Exiv2 {
const IptcData& iptcData() const { return iptcData_; } const IptcData& iptcData() const { return iptcData_; }
std::string comment() const { return comment_; } std::string comment() const { return comment_; }
BasicIo& io() const { return *io_; } BasicIo& io() const { return *io_; }
AccessMode checkMode(MetadataId metadataId) const;
//@} //@}
private: private:

@ -182,6 +182,11 @@ namespace Exiv2 {
return isThisType(*io_, false); return isThisType(*io_, false);
} }
AccessMode CrwImage::checkMode(MetadataId metadataId) const
{
return ImageFactory::checkMode(ImageType::crw, metadataId);
}
void CrwImage::clearMetadata() void CrwImage::clearMetadata()
{ {
clearExifData(); clearExifData();
@ -206,12 +211,13 @@ namespace Exiv2 {
void CrwImage::clearIptcData() void CrwImage::clearIptcData()
{ {
// not supported // not supported, do nothing
} }
void CrwImage::setIptcData(const IptcData& /*iptcData*/) void CrwImage::setIptcData(const IptcData& /*iptcData*/)
{ {
// not supported // not supported
throw(Error(32, "IPTC metadata", "CRW"));
} }
void CrwImage::clearComment() void CrwImage::clearComment()

@ -83,7 +83,7 @@ namespace Exiv2 {
/*! /*!
@brief Class to access raw Canon Crw images. Only Exif metadata and a @brief Class to access raw Canon Crw images. Only Exif metadata and a
comment are supported. Crw format does not contain Iptc metadata. comment are supported. Crw format does not contain IPTC metadata.
*/ */
class CrwImage : public Image { class CrwImage : public Image {
friend bool isCrwType(BasicIo& iIo, bool advance); friend bool isCrwType(BasicIo& iIo, bool advance);
@ -122,22 +122,14 @@ namespace Exiv2 {
//! @name Manipulators //! @name Manipulators
//@{ //@{
void readMetadata(); void readMetadata();
/*!
@brief Todo: Write metadata back to the image. This method is not
yet implemented.
*/
void writeMetadata(); void writeMetadata();
void setExifData(const ExifData& exifData); void setExifData(const ExifData& exifData);
void clearExifData(); void clearExifData();
/*! /*!
@brief Not supported. Crw format does not contain Iptc metadata. @brief Not supported. CRW format does not contain IPTC metadata.
Calling this function will do nothing. Calling this function will throw an Error(32).
*/ */
void setIptcData(const IptcData& iptcData); void setIptcData(const IptcData& iptcData);
/*!
@brief Not supported. Crw format does not contain Iptc metadata.
Calling this function will do nothing.
*/
void clearIptcData(); void clearIptcData();
void setComment(const std::string& comment); void setComment(const std::string& comment);
void clearComment(); void clearComment();
@ -154,6 +146,7 @@ namespace Exiv2 {
const IptcData& iptcData() const { return iptcData_; } const IptcData& iptcData() const { return iptcData_; }
std::string comment() const { return comment_; } std::string comment() const { return comment_; }
BasicIo& io() const { return *io_; } BasicIo& io() const { return *io_; }
AccessMode checkMode(MetadataId metadataId) const;
//@} //@}
private: private:

@ -73,8 +73,8 @@ namespace Exiv2 {
ErrMsg( 28, N_("Invalid charset: `%1'")), // %1=charset name ErrMsg( 28, N_("Invalid charset: `%1'")), // %1=charset name
ErrMsg( 29, N_("Unsupported date format")), ErrMsg( 29, N_("Unsupported date format")),
ErrMsg( 30, N_("Unsupported time format")), ErrMsg( 30, N_("Unsupported time format")),
ErrMsg( 31, N_("%1: CRW images don't support IPTC metadata")), // %1=function ErrMsg( 31, N_("Writing %1 to %2 images is not supported")), // %1=metadata type, %2=image format
ErrMsg( 32, N_("%1: CRW images don't support JPEG comments")), // %1=function ErrMsg( 32, N_("%1 in %2 images is not supported")), // %1=metadata type, %2=image format
ErrMsg( 33, N_("This does not look like a CRW image")), ErrMsg( 33, N_("This does not look like a CRW image")),
ErrMsg( 34, N_("%1: Not supported")), // %1=function ErrMsg( 34, N_("%1: Not supported")), // %1=function
ErrMsg( 35, N_("ImageFactory registry full")), ErrMsg( 35, N_("ImageFactory registry full")),

@ -44,6 +44,15 @@ EXIV2_RCSID("@(#) $Id$")
#include "error.hpp" #include "error.hpp"
#include "futils.hpp" #include "futils.hpp"
#include "jpgimage.hpp"
#include "cr2image.hpp"
#include "crwimage.hpp"
#include "mrwimage.hpp"
#include "tiffimage.hpp"
#ifdef EXV_HAVE_LIBZ
# include "pngimage.hpp"
#endif // EXV_HAVE_LIBZ
// + standard includes // + standard includes
#include <cerrno> #include <cerrno>
#include <cstdio> #include <cstdio>
@ -62,31 +71,50 @@ EXIV2_RCSID("@(#) $Id$")
// class member definitions // class member definitions
namespace Exiv2 { namespace Exiv2 {
bool Image::supportsMetadata(MetadataId metadataId) const const ImageFactory::Registry ImageFactory::registry_[] = {
//image type creation fct type check Exif mode IPTC mode Comment mode
//--------------- --------------- ---------- ----------- ----------- ------------
{ ImageType::jpeg, newJpegInstance, isJpegType, amReadWrite, amReadWrite, amReadWrite },
{ ImageType::exv, newExvInstance, isExvType, amReadWrite, amReadWrite, amReadWrite },
{ ImageType::cr2, newCr2Instance, isCr2Type, amRead, amRead, amNone },
{ ImageType::crw, newCrwInstance, isCrwType, amReadWrite, amNone, amReadWrite },
{ ImageType::mrw, newMrwInstance, isMrwType, amRead, amRead, amNone },
{ ImageType::tiff, newTiffInstance, isTiffType, amRead, amRead, amNone },
#ifdef EXV_HAVE_LIBZ
{ ImageType::png, newPngInstance, isPngType, amRead, amRead, amNone },
#endif // EXV_HAVE_LIBZ
// End of list marker
{ ImageType::none, 0, 0, amNone, amNone, amNone }
};
bool ImageFactory::Registry::operator==(const int& imageType) const
{ {
return (supportedMetadata_ & metadataId) != 0; return imageType == imageType_;
} }
const ImageFactory::Registry* ImageFactory::find(int imageType) bool Image::supportsMetadata(MetadataId metadataId) const
{ {
for (unsigned int i = 0; registry_[i].imageType_ != ImageType::none; ++i) { return (supportedMetadata_ & metadataId) != 0;
if (registry_[i].imageType_ == imageType) return &registry_[i];
}
return 0;
} }
void ImageFactory::registerImage(int type, AccessMode ImageFactory::checkMode(int imageType, MetadataId metadataId)
NewInstanceFct newInst,
IsThisTypeFct isType)
{ {
unsigned int i = 0; const Registry* r = find(registry_, imageType);
for (; i < MAX_IMAGE_FORMATS; ++i) { if (!r) throw Error(13, imageType);
if (registry_[i].imageType_ == ImageType::none) { AccessMode am = amNone;
registry_[i] = Registry(type, newInst, isType); switch (metadataId) {
case mdExif:
am = r->exifSupport_;
break; break;
case mdIptc:
am = r->iptcSupport_;
break;
case mdComment:
am = r->commentSupport_;
break;
// no default: let the compiler complain
} }
} return am;
if (i == MAX_IMAGE_FORMATS) throw Error(35);
} }
int ImageFactory::getType(const std::string& path) int ImageFactory::getType(const std::string& path)
@ -169,7 +197,7 @@ namespace Exiv2 {
BasicIo::AutoPtr io) BasicIo::AutoPtr io)
{ {
// BasicIo instance does not need to be open // BasicIo instance does not need to be open
const Registry* r = find(type); const Registry* r = find(registry_, type);
if (0 != r) { if (0 != r) {
return r->newInstance_(io, true); return r->newInstance_(io, true);
} }

@ -235,9 +235,17 @@ namespace Exiv2 {
Image class will not see those changes until the readMetadata() Image class will not see those changes until the readMetadata()
method is called. method is called.
*/ */
virtual BasicIo& io() const = 0; virtual BasicIo& io() const =0;
/*!
@brief Returns the access mode, i.e., the metadata functions, which
this image supports for the metadata type \em metadataId.
@param metadataId The metadata identifier.
@return Access mode for the requested image type and metadata identifier.
*/
virtual AccessMode checkMode(MetadataId metadataId) const =0;
/*! /*!
@brief Check if image supports a particular type of metadata. @brief Check if image supports a particular type of metadata.
This method is deprecated. Use checkMode() instead.
*/ */
bool supportsMetadata(MetadataId metadataId) const; bool supportsMetadata(MetadataId metadataId) const;
//@} //@}
@ -274,27 +282,6 @@ namespace Exiv2 {
*/ */
class ImageFactory { class ImageFactory {
public: public:
//! @name Manipulators
//@{
/*!
@brief Register image type together with its function pointers.
The image factory creates new images by calling their associated
function pointer. Additional images can be added by registering
new type and function pointers. If called for a type that already
exists in the list, the corresponding functions are replaced.
@param type Image type.
@param newInst Function pointer for creating image instances.
@param isType Function pointer to test for matching image types.
*/
static void registerImage(int type,
NewInstanceFct newInst,
IsThisTypeFct isType);
//@}
//! @name Accessors
//@{
/*! /*!
@brief Create an Image subclass of the appropriate type by reading @brief Create an Image subclass of the appropriate type by reading
the specified file. %Image type is derived from the file the specified file. %Image type is derived from the file
@ -394,9 +381,31 @@ namespace Exiv2 {
@return %Image type or Image::none if the type is not recognized. @return %Image type or Image::none if the type is not recognized.
*/ */
static int getType(BasicIo& io); static int getType(BasicIo& io);
//@} /*!
@brief Returns the access mode or supported metadata functions for an
image type and a metadata type.
@param imageType The image type.
@param metadataId The metadata identifier.
@return Access mode for the requested image type and metadata identifier.
@throw Error(13) if the image type is not supported.
*/
static AccessMode checkMode(int imageType, MetadataId metadataId);
private: private:
//! 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;
// DATA
int imageType_;
NewInstanceFct newInstance_;
IsThisTypeFct isThisType_;
AccessMode exifSupport_;
AccessMode iptcSupport_;
AccessMode commentSupport_;
};
//! @name Creators //! @name Creators
//@{ //@{
//! Prevent construction: not implemented. //! Prevent construction: not implemented.
@ -405,35 +414,9 @@ namespace Exiv2 {
ImageFactory(const ImageFactory& rhs); ImageFactory(const ImageFactory& rhs);
//@} //@}
//! Struct for storing image types and function pointers.
struct Registry
{
//! Default constructor
Registry()
: imageType_(ImageType::none),
newInstance_(0),
isThisType_(0)
{}
//! Constructor
Registry(int imageType,
NewInstanceFct newInstance,
IsThisTypeFct isThisType)
: imageType_(imageType),
newInstance_(newInstance),
isThisType_(isThisType)
{}
int imageType_;
NewInstanceFct newInstance_;
IsThisTypeFct isThisType_;
};
//! Return the registry entry for type
static const Registry* find(int imageType);
// DATA // DATA
static const unsigned int MAX_IMAGE_FORMATS = 32; //! List of image types, creation functions and access modes
//! List of image types and corresponding creation functions. static const Registry registry_[];
static Registry registry_[MAX_IMAGE_FORMATS];
}; // class ImageFactory }; // class ImageFactory
//! Helper class modelling the TIFF header structure. //! Helper class modelling the TIFF header structure.

@ -1,62 +0,0 @@
// ***************************************************************** -*- C++ -*-
/*
* Copyright (C) 2005, 2006 Andreas Huggel <ahuggel@gmx.net>
*
* 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.
*/
/*
File: imgreg.cpp
Version: $Rev$
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
History: 19-Sep-05, ahu: created
*/
// *****************************************************************************
#include "rcsid.hpp"
EXIV2_RCSID("@(#) $Id$")
// *****************************************************************************
// included header files
#include "image.hpp"
#include "jpgimage.hpp"
#include "cr2image.hpp"
#include "crwimage.hpp"
#include "mrwimage.hpp"
#include "tiffimage.hpp"
#ifdef EXV_HAVE_LIBZ
# include "pngimage.hpp"
#endif // EXV_HAVE_LIBZ
// + standard includes
// *****************************************************************************
// class member definitions
namespace Exiv2 {
ImageFactory::Registry ImageFactory::registry_[] = {
Registry(ImageType::jpeg, newJpegInstance, isJpegType),
Registry(ImageType::exv, newExvInstance, isExvType),
Registry(ImageType::cr2, newCr2Instance, isCr2Type),
Registry(ImageType::crw, newCrwInstance, isCrwType),
Registry(ImageType::mrw, newMrwInstance, isMrwType),
Registry(ImageType::tiff, newTiffInstance, isTiffType),
#ifdef EXV_HAVE_LIBZ
Registry(ImageType::png, newPngInstance, isPngType)
#endif // EXV_HAVE_LIBZ
};
} // namespace Exiv2

@ -581,6 +581,11 @@ namespace Exiv2 {
{ {
} }
AccessMode JpegImage::checkMode(MetadataId metadataId) const
{
return ImageFactory::checkMode(ImageType::jpeg, metadataId);
}
int JpegImage::writeHeader(BasicIo& outIo) const int JpegImage::writeHeader(BasicIo& outIo) const
{ {
// Jpeg header // Jpeg header
@ -628,6 +633,11 @@ namespace Exiv2 {
{ {
} }
AccessMode ExvImage::checkMode(MetadataId metadataId) const
{
return ImageFactory::checkMode(ImageType::exv, metadataId);
}
int ExvImage::writeHeader(BasicIo& outIo) const int ExvImage::writeHeader(BasicIo& outIo) const
{ {
// Exv header // Exv header

@ -134,15 +134,15 @@ namespace Exiv2 {
void clearComment(); void clearComment();
void setMetadata(const Image& image); void setMetadata(const Image& image);
void clearMetadata(); void clearMetadata();
ExifData& exifData() { return exifData_; }
IptcData& iptcData() { return iptcData_; }
//@} //@}
//! @name Accessors //! @name Accessors
//@{ //@{
bool good() const; bool good() const;
const ExifData& exifData() const { return exifData_; } const ExifData& exifData() const { return exifData_; }
ExifData& exifData() { return exifData_; }
const IptcData& iptcData() const { return iptcData_; } const IptcData& iptcData() const { return iptcData_; }
IptcData& iptcData() { return iptcData_; }
std::string comment() const { return comment_; } std::string comment() const { return comment_; }
BasicIo& io() const { return *io_; } BasicIo& io() const { return *io_; }
//@} //@}
@ -283,6 +283,10 @@ namespace Exiv2 {
//! Destructor //! Destructor
~JpegImage() {} ~JpegImage() {}
//@} //@}
//! @name Accessors
//@{
AccessMode checkMode(MetadataId metadataId) const;
//@}
protected: protected:
//! @name Accessors //! @name Accessors
//@{ //@{
@ -339,6 +343,10 @@ namespace Exiv2 {
//! Destructor //! Destructor
~ExvImage() {} ~ExvImage() {}
//@} //@}
//! @name Accessors
//@{
AccessMode checkMode(MetadataId metadataId) const;
//@}
protected: protected:
//! @name Accessors //! @name Accessors
//@{ //@{

@ -70,14 +70,21 @@ namespace Exiv2 {
return isThisType(*io_, false); return isThisType(*io_, false);
} }
AccessMode MrwImage::checkMode(MetadataId metadataId) const
{
return ImageFactory::checkMode(ImageType::mrw, metadataId);
}
void MrwImage::clearMetadata() void MrwImage::clearMetadata()
{ {
clearExifData(); clearExifData();
clearIptcData();
} }
void MrwImage::setMetadata(const Image& image) void MrwImage::setMetadata(const Image& image)
{ {
setExifData(image.exifData()); setExifData(image.exifData());
setIptcData(image.iptcData());
} }
void MrwImage::clearExifData() void MrwImage::clearExifData()
@ -102,12 +109,13 @@ namespace Exiv2 {
void MrwImage::clearComment() void MrwImage::clearComment()
{ {
// not supported // not supported, do nothing
} }
void MrwImage::setComment(const std::string& /*comment*/) void MrwImage::setComment(const std::string& /*comment*/)
{ {
// not supported // not supported
throw(Error(32, "Image comment", "MRW"));
} }
void MrwImage::readMetadata() void MrwImage::readMetadata()
@ -161,44 +169,10 @@ namespace Exiv2 {
void MrwImage::writeMetadata() void MrwImage::writeMetadata()
{ {
/* /*
Todo: implement me! Todo: implement me!
*/
#ifdef DEBUG throw(Error(31, "metadata", "MRW"));
std::cerr << "Writing MRW file " << io_->path() << "\n";
#endif
// Read existing image
DataBuf buf;
if (io_->open() == 0) {
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (isThisType(*io_, false)) {
// Read the image into a memory buffer
buf.alloc(io_->size());
io_->read(buf.pData_, buf.size_);
if (io_->error() || io_->eof()) {
buf.reset();
}
}
}
// Parse image, starting with a MRW header component
TiffHeade2::AutoPtr head(new TiffHeade2);
if (buf.size_ != 0) {
head->read(buf.pData_, buf.size_);
}
Blob blob;
TiffParser::encode(blob, head.get(), this);
// Write new buffer to file
BasicIo::AutoPtr tempIo(io_->temporary()); // may throw
assert (tempIo.get() != 0);
tempIo->write(&blob[0], static_cast<long>(blob.size()));
io_->close();
io_->transfer(*tempIo); // may throw
*/
} // MrwImage::writeMetadata } // MrwImage::writeMetadata
bool MrwImage::isThisType(BasicIo& iIo, bool advance) const bool MrwImage::isThisType(BasicIo& iIo, bool advance) const

@ -94,7 +94,7 @@ namespace Exiv2 {
void readMetadata(); void readMetadata();
/*! /*!
@brief Todo: Write metadata back to the image. This method is not @brief Todo: Write metadata back to the image. This method is not
yet implemented. yet implemented. Calling it will throw an Error(31).
*/ */
void writeMetadata(); void writeMetadata();
void setExifData(const ExifData& exifData); void setExifData(const ExifData& exifData);
@ -103,13 +103,9 @@ namespace Exiv2 {
void clearIptcData(); void clearIptcData();
/*! /*!
@brief Not supported. MRW format does not contain a comment. @brief Not supported. MRW format does not contain a comment.
Calling this function will do nothing. Calling this function will throw an Error(32).
*/ */
void setComment(const std::string& comment); void setComment(const std::string& comment);
/*!
@brief Not supported. MRW format does not contain a comment.
Calling this function will do nothing.
*/
void clearComment(); void clearComment();
void setMetadata(const Image& image); void setMetadata(const Image& image);
void clearMetadata(); void clearMetadata();
@ -124,6 +120,7 @@ namespace Exiv2 {
const IptcData& iptcData() const { return iptcData_; } const IptcData& iptcData() const { return iptcData_; }
std::string comment() const { return comment_; } std::string comment() const { return comment_; }
BasicIo& io() const { return *io_; } BasicIo& io() const { return *io_; }
AccessMode checkMode(MetadataId metadataId) const;
//@} //@}
private: private:

@ -74,14 +74,21 @@ namespace Exiv2 {
return isThisType(*io_, false); return isThisType(*io_, false);
} }
AccessMode PngImage::checkMode(MetadataId metadataId) const
{
return ImageFactory::checkMode(ImageType::png, metadataId);
}
void PngImage::clearMetadata() void PngImage::clearMetadata()
{ {
clearExifData(); clearExifData();
clearIptcData();
} }
void PngImage::setMetadata(const Image& image) void PngImage::setMetadata(const Image& image)
{ {
setExifData(image.exifData()); setExifData(image.exifData());
setIptcData(image.iptcData());
} }
void PngImage::clearExifData() void PngImage::clearExifData()
@ -106,7 +113,7 @@ namespace Exiv2 {
void PngImage::clearComment() void PngImage::clearComment()
{ {
// not yet supported. // not yet supported, do nothing
// TODO : Add 'iTXt' chunk 'Description' tag support here // TODO : Add 'iTXt' chunk 'Description' tag support here
} }
@ -114,6 +121,7 @@ namespace Exiv2 {
{ {
// not yet supported // not yet supported
// TODO : Add 'iTXt' chunk 'Description' tag support here // TODO : Add 'iTXt' chunk 'Description' tag support here
throw(Error(32, "Image comment", "PNG"));
} }
void PngImage::readMetadata() void PngImage::readMetadata()
@ -152,8 +160,9 @@ namespace Exiv2 {
void PngImage::writeMetadata() void PngImage::writeMetadata()
{ {
/* /*
TODO: implement me! Todo: implement me!
*/ */
throw(Error(31, "metadata", "PNG"));
} // PngImage::writeMetadata } // PngImage::writeMetadata
bool PngImage::isThisType(BasicIo& iIo, bool advance) const bool PngImage::isThisType(BasicIo& iIo, bool advance) const

@ -97,7 +97,7 @@ namespace Exiv2 {
void readMetadata(); void readMetadata();
/*! /*!
@brief Todo: Write metadata back to the image. This method is not @brief Todo: Write metadata back to the image. This method is not
yet implemented. yet implemented. Calling it will throw an Error(31).
*/ */
void writeMetadata(); void writeMetadata();
void setExifData(const ExifData& exifData); void setExifData(const ExifData& exifData);
@ -106,13 +106,10 @@ namespace Exiv2 {
void clearIptcData(); void clearIptcData();
/*! /*!
@brief Not supported. PNG format does not contain a comment. @brief Not supported. PNG format does not contain a comment.
Calling this function will do nothing. Calling it will throw an Error(32).<br>
Todo: Add 'iTXt' chunk 'Description' tag support here.
*/ */
void setComment(const std::string& comment); void setComment(const std::string& comment);
/*!
@brief Not supported. PNG format does not contain a comment.
Calling this function will do nothing.
*/
void clearComment(); void clearComment();
void setMetadata(const Image& image); void setMetadata(const Image& image);
void clearMetadata(); void clearMetadata();
@ -127,6 +124,7 @@ namespace Exiv2 {
const IptcData& iptcData() const { return iptcData_; } const IptcData& iptcData() const { return iptcData_; }
std::string comment() const { return comment_; } std::string comment() const { return comment_; }
BasicIo& io() const { return *io_; } BasicIo& io() const { return *io_; }
AccessMode checkMode(MetadataId metadataId) const;
//@} //@}
private: private:

@ -70,16 +70,21 @@ namespace Exiv2 {
return isThisType(*io_, false); return isThisType(*io_, false);
} }
AccessMode TiffImage::checkMode(MetadataId metadataId) const
{
return ImageFactory::checkMode(ImageType::tiff, metadataId);
}
void TiffImage::clearMetadata() void TiffImage::clearMetadata()
{ {
clearExifData(); clearExifData();
clearComment(); clearIptcData();
} }
void TiffImage::setMetadata(const Image& image) void TiffImage::setMetadata(const Image& image)
{ {
setExifData(image.exifData()); setExifData(image.exifData());
setComment(image.comment()); setIptcData(image.iptcData());
} }
void TiffImage::clearExifData() void TiffImage::clearExifData()
@ -104,12 +109,13 @@ namespace Exiv2 {
void TiffImage::clearComment() void TiffImage::clearComment()
{ {
comment_.erase(); // not supported, do nothing
} }
void TiffImage::setComment(const std::string& comment) void TiffImage::setComment(const std::string& /*comment*/)
{ {
comment_ = comment; // not supported
throw(Error(32, "Image comment", "TIFF"));
} }
void TiffImage::readMetadata() void TiffImage::readMetadata()
@ -134,44 +140,10 @@ namespace Exiv2 {
void TiffImage::writeMetadata() void TiffImage::writeMetadata()
{ {
/* /*
Todo: implement me! Todo: implement me!
*/
#ifdef DEBUG throw(Error(31, "metadata", "TIFF"));
std::cerr << "Writing TIFF file " << io_->path() << "\n";
#endif
// Read existing image
DataBuf buf;
if (io_->open() == 0) {
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (isThisType(*io_, false)) {
// Read the image into a memory buffer
buf.alloc(io_->size());
io_->read(buf.pData_, buf.size_);
if (io_->error() || io_->eof()) {
buf.reset();
}
}
}
// Parse image, starting with a TIFF header component
TiffHeade2::AutoPtr head(new TiffHeade2);
if (buf.size_ != 0) {
head->read(buf.pData_, buf.size_);
}
Blob blob;
TiffParser::encode(blob, head.get(), this);
// Write new buffer to file
BasicIo::AutoPtr tempIo(io_->temporary()); // may throw
assert (tempIo.get() != 0);
tempIo->write(&blob[0], static_cast<long>(blob.size()));
io_->close();
io_->transfer(*tempIo); // may throw
*/
} // TiffImage::writeMetadata } // TiffImage::writeMetadata
bool TiffImage::isThisType(BasicIo& iIo, bool advance) const bool TiffImage::isThisType(BasicIo& iIo, bool advance) const

@ -93,13 +93,17 @@ namespace Exiv2 {
void readMetadata(); void readMetadata();
/*! /*!
@brief Todo: Write metadata back to the image. This method is not @brief Todo: Write metadata back to the image. This method is not
yet implemented. yet implemented. Calling it will throw an Error(31).
*/ */
void writeMetadata(); void writeMetadata();
void setExifData(const ExifData& exifData); void setExifData(const ExifData& exifData);
void clearExifData(); void clearExifData();
void setIptcData(const IptcData& iptcData); void setIptcData(const IptcData& iptcData);
void clearIptcData(); void clearIptcData();
/*!
@brief Not supported. TIFF format does not contain a comment.
Calling this function will throw an Error(32).
*/
void setComment(const std::string& comment); void setComment(const std::string& comment);
void clearComment(); void clearComment();
void setMetadata(const Image& image); void setMetadata(const Image& image);
@ -115,6 +119,7 @@ namespace Exiv2 {
const IptcData& iptcData() const { return iptcData_; } const IptcData& iptcData() const { return iptcData_; }
std::string comment() const { return comment_; } std::string comment() const { return comment_; }
BasicIo& io() const { return *io_; } BasicIo& io() const { return *io_; }
AccessMode checkMode(MetadataId metadataId) const;
//@} //@}
private: private:

@ -92,6 +92,9 @@ namespace Exiv2 {
//! An identifier for each type of metadata //! An identifier for each type of metadata
enum MetadataId { mdExif=1, mdIptc=2, mdComment=4 }; enum MetadataId { mdExif=1, mdIptc=2, mdComment=4 };
//! An identifier for each mode of metadata support
enum AccessMode { amNone=0, amRead=1, amWrite=2, amReadWrite=3 };
//! Type identifiers for IFD format types //! Type identifiers for IFD format types
enum TypeId { invalidTypeId, unsignedByte, asciiString, unsignedShort, enum TypeId { invalidTypeId, unsignedByte, asciiString, unsignedShort,
unsignedLong, unsignedRational, invalid6, undefined, unsignedLong, unsignedRational, invalid6, undefined,

Loading…
Cancel
Save