From 57cdf19286822ccb5a825078735a059ec0df20cd Mon Sep 17 00:00:00 2001 From: Andreas Huggel Date: Fri, 2 Apr 2004 09:59:16 +0000 Subject: [PATCH] Added support to read from / write to *.exv files, made return values of writeThumbnail consistent with those of other write functions --- src/exif.cpp | 44 +++++++++++++++++++++++++++++++++----------- src/exif.hpp | 17 ++++++++++++++--- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/exif.cpp b/src/exif.cpp index 64069d56..02acde1f 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -20,14 +20,14 @@ */ /* File: exif.cpp - Version: $Name: $ $Revision: 1.36 $ + Version: $Name: $ $Revision: 1.37 $ Author(s): Andreas Huggel (ahu) History: 26-Jan-04, ahu: created 11-Feb-04, ahu: isolated as a component */ // ***************************************************************************** #include "rcsid.hpp" -EXIV2_RCSID("@(#) $Name: $ $Revision: 1.36 $ $RCSfile: exif.cpp,v $") +EXIV2_RCSID("@(#) $Name: $ $Revision: 1.37 $ $RCSfile: exif.cpp,v $") // ***************************************************************************** // included header files @@ -270,9 +270,9 @@ namespace Exif { { std::string name = path + extension(); std::ofstream file(name.c_str(), std::ios::binary); - if (!file) return 1; + if (!file) return -1; file.write(pImage_, size_); - if (!file.good()) return 2; + if (!file.good()) return 4; return 0; } // TiffThumbnail::write @@ -410,9 +410,9 @@ namespace Exif { { std::string name = path + extension(); std::ofstream file(name.c_str(), std::ios::binary); - if (!file) return 1; + if (!file) return -1; file.write(pImage_, size_); - if (!file.good()) return 2; + if (!file.good()) return 4; return 0; } // JpegThumbnail::write @@ -483,11 +483,20 @@ namespace Exif { std::ifstream file(path.c_str(), std::ios::binary); if (!file) return -1; Image* pImage = ImageFactory::instance().create(file); - if (pImage == 0) return -2; - int rc = pImage->readExifData(file); - if (rc == 0) rc = read(pImage->exifData(), pImage->sizeExifData()); - delete pImage; - return rc; + if (pImage) { + int rc = pImage->readExifData(file); + if (rc == 0) rc = read(pImage->exifData(), pImage->sizeExifData()); + delete pImage; + return rc; + } + if (ExvFile::isThisType(file)) { + ExvFile exvFile; + int rc = exvFile.readExifData(file); + if (rc == 0) rc = read(exvFile.exifData(), exvFile.sizeExifData()); + return rc; + } + // We don't know this type of file + return -2; } int ExifData::read(const char* buf, long len) @@ -771,6 +780,19 @@ std::cerr << "->>>>>> writing from metadata <<<<<<-\n"; return size; } // ExifData::size + int ExifData::writeExifData(const std::string& path) + { + long size = this->size(); + char* buf = new char[size]; + long actualSize = copy(buf); + assert(actualSize <= size); + + ExvFile exvFile; + exvFile.setExifData(buf, actualSize); + delete[] buf; + return exvFile.writeExifData(path); + } // ExifData::writeExifData + void ExifData::add(Entries::const_iterator begin, Entries::const_iterator end, ByteOrder byteOrder) diff --git a/src/exif.hpp b/src/exif.hpp index 97bc46dc..47006b39 100644 --- a/src/exif.hpp +++ b/src/exif.hpp @@ -21,7 +21,7 @@ /*! @file exif.hpp @brief Encoding and decoding of %Exif data - @version $Name: $ $Revision: 1.36 $ + @version $Name: $ $Revision: 1.37 $ @author Andreas Huggel (ahu) ahuggel@gmx.net @date 09-Jan-04, ahu: created @@ -276,8 +276,10 @@ namespace Exif { //! @name Accessors //@{ /*! - @brief Write thumbnail to file path, return 0 if successful, -1 if - there is no thumbnail image to write. + @brief Write thumbnail to file path. + @return 0 if successful;
+ -1 if the file couldn't be open;
+ 4 if writing to the output stream failed. */ virtual int write(const std::string& path) const =0; /*! @@ -530,6 +532,15 @@ namespace Exif { @return 0 if successful. */ int write(const std::string& path); + /*! + @brief Write the %Exif data to a binary file. By convention, the + filename extension should be ".exv". This file format contains + the %Exif data as it is found in a JPEG file, starting with the + APP1 marker 0xffe1, the size of the data and the string + "Exif\0\0". Exv files can be read with + int read(const std::string& path) just like image %Exif data. + */ + int writeExifData(const std::string& path); /*! @brief Write the %Exif data to a data buffer, return number of bytes written. The copied data starts with the TIFF header.