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
Version: $Name: $ $Revision: 1.2 $
Version: $Name: $ $Revision: 1.3 $
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.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 {

@ -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)
<a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
@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_; }

Loading…
Cancel
Save