Added support to read from / write to *.exv files, made return values of writeThumbnail consistent with those of other write functions

This commit is contained in:
Andreas Huggel 2004-04-02 09:59:16 +00:00
parent ab9ee9da21
commit 57cdf19286
2 changed files with 47 additions and 14 deletions

View File

@ -20,14 +20,14 @@
*/
/*
File: exif.cpp
Version: $Name: $ $Revision: 1.36 $
Version: $Name: $ $Revision: 1.37 $
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
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)

View File

@ -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)
<a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
@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;<BR>
-1 if the file couldn't be open;<BR>
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.