Fixed IFD to update internal offsets on copy()

v0.27.3
Andreas Huggel 22 years ago
parent 07b0657060
commit 59643bd4e1

@ -20,14 +20,14 @@
*/ */
/* /*
File: ifd.cpp File: ifd.cpp
Version: $Name: $ $Revision: 1.2 $ Version: $Name: $ $Revision: 1.3 $
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net> Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
History: 26-Jan-04, ahu: created History: 26-Jan-04, ahu: created
11-Feb-04, ahu: isolated as a component 11-Feb-04, ahu: isolated as a component
*/ */
// ***************************************************************************** // *****************************************************************************
#include "rcsid.hpp" #include "rcsid.hpp"
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.2 $ $RCSfile: ifd.cpp,v $") EXIV2_RCSID("@(#) $Name: $ $Revision: 1.3 $ $RCSfile: ifd.cpp,v $")
// ***************************************************************************** // *****************************************************************************
// included header files // included header files
@ -271,9 +271,9 @@ namespace Exif {
return rc; return rc;
} // Ifd::readSubIfd } // Ifd::readSubIfd
long Ifd::copy(char* buf, ByteOrder byteOrder, long offset) const long Ifd::copy(char* buf, ByteOrder byteOrder, long offset)
{ {
if (offset == 0) offset = offset_; if (offset != 0) offset_ = offset;
// Add the number of entries to the data buffer // Add the number of entries to the data buffer
us2Data(buf, entries_.size(), byteOrder); us2Data(buf, entries_.size(), byteOrder);
@ -281,16 +281,17 @@ namespace Exif {
// Add all directory entries to the data buffer // Add all directory entries to the data buffer
long dataSize = 0; long dataSize = 0;
const const_iterator b = entries_.begin(); const iterator b = entries_.begin();
const const_iterator e = entries_.end(); const iterator e = entries_.end();
const_iterator i = b; iterator i = b;
for (; i != e; ++i) { for (; i != e; ++i) {
us2Data(buf+o, i->tag(), byteOrder); us2Data(buf+o, i->tag(), byteOrder);
us2Data(buf+o+2, i->type(), byteOrder); us2Data(buf+o+2, i->type(), byteOrder);
ul2Data(buf+o+4, i->count(), byteOrder); ul2Data(buf+o+4, i->count(), byteOrder);
if (i->size() > 4) { if (i->size() > 4) {
// Calculate offset, data immediately follows the IFD // Set the offset of the entry, data immediately follows the IFD
ul2Data(buf+o+8, offset + size() + dataSize, byteOrder); i->setOffset(size() + dataSize);
ul2Data(buf+o+8, offset_ + i->offset(), byteOrder);
dataSize += i->size(); dataSize += i->size();
} }
else { else {

@ -21,7 +21,7 @@
/*! /*!
@file ifd.hpp @file ifd.hpp
@brief Encoding and decoding of IFD (Image File Directory) data @brief Encoding and decoding of IFD (Image File Directory) data
@version $Name: $ $Revision: 1.4 $ @version $Name: $ $Revision: 1.5 $
@author Andreas Huggel (ahu) @author Andreas Huggel (ahu)
<a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a> <a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
@date 09-Jan-04, ahu: created @date 09-Jan-04, ahu: created
@ -137,7 +137,7 @@ namespace Exif {
bytes unless it is 0. bytes unless it is 0.
*/ */
long size() const { return size_; } long size() const { return size_; }
//! Return the offset from the start of the IFD //! Return the offset from the start of the IFD to the data of the entry
uint32 offset() const { return offset_; } uint32 offset() const { return offset_; }
/*! /*!
@brief Return a pointer to the data area. Do not attempt to write @brief Return a pointer to the data area. Do not attempt to write
@ -288,8 +288,8 @@ namespace Exif {
Ifd& dest, const char* buf, ByteOrder byteOrder, uint16 tag Ifd& dest, const char* buf, ByteOrder byteOrder, uint16 tag
) const; ) const;
/*! /*!
@brief Copy the IFD to a data array, return the number of bytes @brief Copy the IFD to a data array, update the offsets of the IFD and
written. all its entries, return the number of bytes written.
First the number of IFD entries is written (2 bytes), followed First the number of IFD entries is written (2 bytes), followed
by all directory entries: tag (2), type (2), number of data by all directory entries: tag (2), type (2), number of data
@ -312,12 +312,12 @@ namespace Exif {
original position, i.e., the offset of the IFD will be used. original position, i.e., the offset of the IFD will be used.
@return Returns the number of characters written. @return Returns the number of characters written.
*/ */
long copy(char* buf, ByteOrder byteOrder, long offset =0) const; long copy(char* buf, ByteOrder byteOrder, long offset =0);
//! @name Accessors //! @name Accessors
//@{ //@{
//! Ifd id of the IFD //! Ifd id of the IFD
IfdId ifdId() const { return ifdId_; } IfdId ifdId() const { return ifdId_; }
//! Offset of the IFD from SOI //! Offset of the IFD from the start of the TIFF header
long offset() const { return offset_; } long offset() const { return offset_; }
//! Get the offset to the next IFD from the start of the TIFF header //! Get the offset to the next IFD from the start of the TIFF header
long next() const { return next_; } long next() const { return next_; }

Loading…
Cancel
Save