From 59643bd4e1eca750e93c46d6b7890e5fa87d4b2c Mon Sep 17 00:00:00 2001 From: Andreas Huggel Date: Sun, 7 Mar 2004 02:52:15 +0000 Subject: [PATCH] Fixed IFD to update internal offsets on copy() --- src/ifd.cpp | 19 ++++++++++--------- src/ifd.hpp | 14 +++++++------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/ifd.cpp b/src/ifd.cpp index cea72f19..f85fac26 100644 --- a/src/ifd.cpp +++ b/src/ifd.cpp @@ -20,14 +20,14 @@ */ /* File: ifd.cpp - Version: $Name: $ $Revision: 1.2 $ + Version: $Name: $ $Revision: 1.3 $ 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.2 $ $RCSfile: ifd.cpp,v $") +EXIV2_RCSID("@(#) $Name: $ $Revision: 1.3 $ $RCSfile: ifd.cpp,v $") // ***************************************************************************** // included header files @@ -271,9 +271,9 @@ namespace Exif { return rc; } // 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 us2Data(buf, entries_.size(), byteOrder); @@ -281,16 +281,17 @@ namespace Exif { // Add all directory entries to the data buffer long dataSize = 0; - const const_iterator b = entries_.begin(); - const const_iterator e = entries_.end(); - const_iterator i = b; + const iterator b = entries_.begin(); + const iterator e = entries_.end(); + iterator i = b; for (; i != e; ++i) { us2Data(buf+o, i->tag(), byteOrder); us2Data(buf+o+2, i->type(), byteOrder); ul2Data(buf+o+4, i->count(), byteOrder); if (i->size() > 4) { - // Calculate offset, data immediately follows the IFD - ul2Data(buf+o+8, offset + size() + dataSize, byteOrder); + // Set the offset of the entry, data immediately follows the IFD + i->setOffset(size() + dataSize); + ul2Data(buf+o+8, offset_ + i->offset(), byteOrder); dataSize += i->size(); } else { diff --git a/src/ifd.hpp b/src/ifd.hpp index 249f97d9..a625e7c2 100644 --- a/src/ifd.hpp +++ b/src/ifd.hpp @@ -21,7 +21,7 @@ /*! @file ifd.hpp @brief Encoding and decoding of IFD (Image File Directory) data - @version $Name: $ $Revision: 1.4 $ + @version $Name: $ $Revision: 1.5 $ @author Andreas Huggel (ahu) ahuggel@gmx.net @date 09-Jan-04, ahu: created @@ -137,7 +137,7 @@ namespace Exif { bytes unless it is 0. */ 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_; } /*! @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 ) const; /*! - @brief Copy the IFD to a data array, return the number of bytes - written. + @brief Copy the IFD to a data array, update the offsets of the IFD and + all its entries, return the number of bytes written. First the number of IFD entries is written (2 bytes), followed by all directory entries: tag (2), type (2), number of data @@ -310,14 +310,14 @@ namespace Exif { data array. The IFD offsets will be adjusted as necessary. If not given, then it is assumed that the IFD will remain at its 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 //@{ //! Ifd id of the IFD 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_; } //! Get the offset to the next IFD from the start of the TIFF header long next() const { return next_; }