[SCM] exiv2 packaging branch, master, updated. debian/0.25-3.1-3734-gdcbc29a
Maximiliano Curia
maxy at moszumanska.debian.org
Thu Jul 13 17:36:15 UTC 2017
Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=20bcdef
The following commit has been merged in the master branch:
commit 20bcdef9496a0a034669867b3ad1a15b3206a99f
Author: Andreas Huggel <ahuggel at gmx.net>
Date: Sat Apr 3 03:47:41 2004 +0000
Use DataBuf for temporary data buffers
---
src/actions.cpp | 12 +++----
src/exif.cpp | 106 ++++++++++++++++++++++++++------------------------------
src/image.cpp | 65 +++++++++++++++-------------------
src/tags.cpp | 11 +++---
4 files changed, 89 insertions(+), 105 deletions(-)
diff --git a/src/actions.cpp b/src/actions.cpp
index 9c19543..77df3c4 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -20,19 +20,20 @@
*/
/*
File: actions.cpp
- Version: $Name: $ $Revision: 1.13 $
+ Version: $Name: $ $Revision: 1.14 $
Author(s): Andreas Huggel (ahu) <ahuggel at gmx.net>
History: 08-Dec-03, ahu: created
*/
// *****************************************************************************
#include "rcsid.hpp"
-EXIV2_RCSID("@(#) $Name: $ $Revision: 1.13 $ $RCSfile: actions.cpp,v $")
+EXIV2_RCSID("@(#) $Name: $ $Revision: 1.14 $ $RCSfile: actions.cpp,v $")
// *****************************************************************************
// included header files
#include "actions.hpp"
#include "exiv2.hpp"
#include "utils.hpp"
+#include "types.hpp"
#include "exif.hpp"
#include "canonmn.hpp"
@@ -314,8 +315,6 @@ namespace Action {
{
Exif::ExifData::const_iterator md;
for (md = exifData.begin(); md != exifData.end(); ++md) {
- char *buf = new char[md->size()];
- md->copy(buf, exifData.byteOrder());
std::cout << std::setw(4) << std::setfill(' ') << std::left
<< md->ifdName() << " "
<< "0x" << std::setw(4) << std::setfill('0') << std::right
@@ -330,8 +329,9 @@ namespace Action {
<< md->size() << " "
<< std::setw(27) << std::setfill(' ') << std::left
<< md->tagName() << "
";
- Exif::hexdump(std::cout, buf, md->size());
- delete[] buf;
+ Exif::DataBuf buf(md->size());
+ md->copy(buf.pData_, exifData.byteOrder());
+ Exif::hexdump(std::cout, buf.pData_, buf.size_);
}
} // Print::printHexdump
diff --git a/src/exif.cpp b/src/exif.cpp
index 02acde1..32ef94a 100644
--- a/src/exif.cpp
+++ b/src/exif.cpp
@@ -20,14 +20,17 @@
*/
/*
File: exif.cpp
- Version: $Name: $ $Revision: 1.37 $
+ Version: $Name: $ $Revision: 1.38 $
Author(s): Andreas Huggel (ahu) <ahuggel at gmx.net>
History: 26-Jan-04, ahu: created
11-Feb-04, ahu: isolated as a component
*/
// *****************************************************************************
#include "rcsid.hpp"
-EXIV2_RCSID("@(#) $Name: $ $Revision: 1.37 $ $RCSfile: exif.cpp,v $")
+EXIV2_RCSID("@(#) $Name: $ $Revision: 1.38 $ $RCSfile: exif.cpp,v $")
+
+// Define DEBUG_MAKERNOTE to output debug information to std::cerr
+#undef DEBUG_MAKERNOTE
// *****************************************************************************
// included header files
@@ -197,13 +200,14 @@ namespace Exif {
const ExifData& exifData,
ByteOrder byteOrder)
{
- char* data = new char[64*1024]; // temporary buffer Todo: handle larger
- memset(data, 0x0, 64*1024); // images (which violate the Exif Std)
- long len = 0; // number of bytes in the buffer
+ DataBuf img; // temporary buffer Todo: handle larger
+ img.alloc(64*1024); // images (which violate the Exif Std)
+ memset(img.pData_, 0x0, img.size_);
+ long len = 0; // number of bytes in the buffer
// Copy the TIFF header
TiffHeader tiffHeader(byteOrder);
- len += tiffHeader.copy(data);
+ len += tiffHeader.copy(img.pData_);
// Create IFD (without Exif and GPS tags) from metadata
Ifd ifd1(ifd1);
@@ -228,7 +232,7 @@ namespace Exif {
for (long k = 0; k < offsets->count(); ++k) {
long offset = offsets->toLong(k);
long size = sizes->toLong(k);
- memcpy(data + len, buf + offset, size);
+ memcpy(img.pData_ + len, buf + offset, size);
os << len << " ";
len += size;
}
@@ -242,16 +246,15 @@ namespace Exif {
// Finally, sort and copy the IFD
ifd1.sortByTag();
- ifd1.copy(data + ifdOffset, tiffHeader.byteOrder(), ifdOffset);
+ ifd1.copy(img.pData_ + ifdOffset, tiffHeader.byteOrder(), ifdOffset);
delete[] pImage_;
pImage_ = new char[len];
- memcpy(pImage_, data, len);
+ memcpy(pImage_, img.pData_, len);
size_ = len;
tiffHeader_.read(pImage_);
ifd_.read(pImage_ + tiffHeader_.offset(),
tiffHeader_.byteOrder(), tiffHeader_.offset());
- delete[] data;
return 0;
} // TiffThumbnail::read
@@ -605,13 +608,11 @@ namespace Exif {
Image* pImage = ImageFactory::instance().create(is);
if (pImage == 0) return -2;
- long size = this->size();
- char* buf = new char[size];
- long actualSize = copy(buf);
- assert(actualSize <= size);
+ DataBuf buf(size());
+ long actualSize = copy(buf.pData_);
+ assert(actualSize <= buf.size_);
- pImage->setExifData(buf, actualSize);
- delete[] buf;
+ pImage->setExifData(buf.pData_, actualSize);
int rc = pImage->writeExifData(path, is);
delete pImage;
return rc;
@@ -624,19 +625,17 @@ namespace Exif {
// from the metadata without changing the data size, then it is enough
// to copy the data buffer.
if (updateEntries()) {
-
-//ahu Todo: remove debugging output
-std::cerr << "->>>>>> using non-intrusive writing <<<<<<-
";
-
+#ifdef DEBUG_MAKERNOTE
+ std::cerr << "->>>>>> using non-intrusive writing <<<<<<-
";
+#endif
memcpy(buf, pData_, size_);
size = size_;
}
// Else we have to do it the hard way...
else {
-
-//ahu Todo: remove debugging output
-std::cerr << "->>>>>> writing from metadata <<<<<<-
";
-
+#ifdef DEBUG_MAKERNOTE
+ std::cerr << "->>>>>> writing from metadata <<<<<<-
";
+#endif
size = copyFromMetadata(buf);
}
return size;
@@ -665,12 +664,10 @@ std::cerr << "->>>>>> writing from metadata <<<<<<-
";
Entry e;
e.setIfdId(exifIfd.ifdId());
e.setTag(0x927c);
- long size = makerNote->size();
- char* buf = new char[size];
- memset(buf, 0x0, size);
- e.setValue(undefined, size, buf, size);
+ DataBuf buf(makerNote->size());
+ memset(buf.pData_, 0x0, buf.size_);
+ e.setValue(undefined, buf.size_, buf.pData_, buf.size_);
exifIfd.add(e);
- delete[] buf;
}
// Set the offset to the Exif IFD in IFD0
@@ -782,14 +779,12 @@ std::cerr << "->>>>>> writing from metadata <<<<<<-
";
int ExifData::writeExifData(const std::string& path)
{
- long size = this->size();
- char* buf = new char[size];
- long actualSize = copy(buf);
- assert(actualSize <= size);
+ DataBuf buf(this->size());
+ long actualSize = copy(buf.pData_);
+ assert(actualSize <= buf.size_);
ExvFile exvFile;
- exvFile.setExifData(buf, actualSize);
- delete[] buf;
+ exvFile.setExifData(buf.pData_, actualSize);
return exvFile.writeExifData(path);
} // ExifData::writeExifData
@@ -936,10 +931,9 @@ std::cerr << "->>>>>> writing from metadata <<<<<<-
";
// if the metadatum was not changed.
}
else {
- char* buf = new char[md->size()];
- md->copy(buf, byteOrder);
- entry->setValue(md->typeId(), md->count(), buf, md->size());
- delete[] buf;
+ DataBuf buf(md->size());
+ md->copy(buf.pData_, byteOrder);
+ entry->setValue(md->typeId(), md->count(), buf.pData_, md->size());
}
}
return compatible;
@@ -1037,20 +1031,20 @@ std::cerr << "->>>>>> writing from metadata <<<<<<-
";
}
} // addToIfd
- void addToIfd(Ifd& ifd, const Metadatum& metadatum, ByteOrder byteOrder)
+ void addToIfd(Ifd& ifd, const Metadatum& md, ByteOrder byteOrder)
{
assert(ifd.alloc());
Entry e;
- e.setIfdId(metadatum.ifdId());
- e.setIdx(metadatum.idx());
- e.setTag(metadatum.tag());
+ e.setIfdId(md.ifdId());
+ e.setIdx(md.idx());
+ e.setTag(md.tag());
e.setOffset(0); // will be calculated when the IFD is written
- char* buf = new char[metadatum.size()];
- metadatum.copy(buf, byteOrder);
- e.setValue(metadatum.typeId(), metadatum.count(), buf, metadatum.size());
+
+ DataBuf buf(md.size());
+ md.copy(buf.pData_, byteOrder);
+ e.setValue(md.typeId(), md.count(), buf.pData_, md.size());
ifd.add(e);
- delete[] buf;
} // addToIfd
void addToMakerNote(MakerNote* makerNote,
@@ -1066,20 +1060,20 @@ std::cerr << "->>>>>> writing from metadata <<<<<<-
";
}
} // addToMakerNote
- void addToMakerNote(MakerNote* makerNote,
- const Metadatum& metadatum,
+ void addToMakerNote(MakerNote* makerNote,
+ const Metadatum& md,
ByteOrder byteOrder)
{
Entry e;
- e.setIfdId(metadatum.ifdId());
- e.setIdx(metadatum.idx());
- e.setTag(metadatum.tag());
+ e.setIfdId(md.ifdId());
+ e.setIdx(md.idx());
+ e.setTag(md.tag());
e.setOffset(0); // will be calculated when the makernote is written
- char* buf = new char[metadatum.size()];
- metadatum.copy(buf, byteOrder);
- e.setValue(metadatum.typeId(), metadatum.count(), buf, metadatum.size());
+
+ DataBuf buf(md.size());
+ md.copy(buf.pData_, byteOrder);
+ e.setValue(md.typeId(), md.count(), buf.pData_, md.size());
makerNote->add(e);
- delete[] buf;
} // addToMakerNote
bool cmpMetadataByTag(const Metadatum& lhs, const Metadatum& rhs)
diff --git a/src/image.cpp b/src/image.cpp
index 6047aab..e2af863 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -20,14 +20,14 @@
*/
/*
File: image.cpp
- Version: $Name: $ $Revision: 1.10 $
+ Version: $Name: $ $Revision: 1.11 $
Author(s): Andreas Huggel (ahu) <ahuggel at gmx.net>
History: 26-Jan-04, ahu: created
11-Feb-04, ahu: isolated as a component
*/
// *****************************************************************************
#include "rcsid.hpp"
-EXIV2_RCSID("@(#) $Name: $ $Revision: 1.10 $ $RCSfile: image.cpp,v $")
+EXIV2_RCSID("@(#) $Name: $ $Revision: 1.11 $ $RCSfile: image.cpp,v $")
// *****************************************************************************
// included header files
@@ -219,6 +219,7 @@ namespace Exif {
// Todo: implement this properly: skip unknown APP0 and APP1 segments
int JpegImage::eraseExifData(std::ostream& os, std::istream& is) const
{
+
// Check if this is a JPEG image in the first place
if (!isThisType(is, true)) {
if (!is.good()) return 1;
@@ -232,23 +233,17 @@ namespace Exif {
uint16 size = getUShort(tmpbuf + 2, bigEndian);
if (size < 8) return 3;
- long sizeJfifData = 9;
- static char defaultJfifData[] =
+ const long defaultJfifSize = 9;
+ static const char defaultJfifData[] =
{ 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00 };
- // Todo: Memory Leak! Use an auto pointer
- char* pJfifData = 0;
+ DataBuf jfif;
if (marker == app0_ && memcmp(tmpbuf + 4, jfifId_, 5) == 0) {
// Read the remainder of the JFIF APP0 segment
is.seekg(-1, std::ios::cur);
- sizeJfifData = size - 7;
- pJfifData = new char[sizeJfifData];
- is.read(pJfifData, sizeJfifData);
- if (!is.good()) {
- delete[] pJfifData;
- pJfifData = 0;
- return 1;
- }
+ jfif.alloc(size - 7);
+ is.read(jfif.pData_, jfif.size_);
+ if (!is.good()) return 1;
// Read the beginning of the next segment
is.read(tmpbuf, 10);
if (!is.good()) return 1;
@@ -264,17 +259,20 @@ namespace Exif {
// Write SOI and APP0 markers, size of APP0 field
us2Data(tmpbuf, soi_, bigEndian);
us2Data(tmpbuf + 2, app0_, bigEndian);
- us2Data(tmpbuf + 4, 7 + sizeJfifData, bigEndian);
+ if (jfif.pData_) {
+ us2Data(tmpbuf + 4, 7 + jfif.size_, bigEndian);
+ }
+ else {
+ us2Data(tmpbuf + 4, 7 + defaultJfifSize, bigEndian);
+ }
memcpy(tmpbuf + 6, jfifId_, 5);
os.write(tmpbuf, 11);
// Write JFIF APP0 data, use that from the input stream if available
- if (pJfifData) {
- os.write(pJfifData, sizeJfifData);
- delete pJfifData;
- pJfifData = 0;
+ if (jfif.pData_) {
+ os.write(jfif.pData_, jfif.size_);
}
else {
- os.write(defaultJfifData, sizeJfifData);
+ os.write(defaultJfifData, defaultJfifSize);
}
if (!os.good()) return 4;
@@ -333,19 +331,13 @@ namespace Exif {
if (size < 8) return 3;
bool validFile = false;
- long sizeJfifData = 0;
- char* pJfifData = 0; // Todo: Memory Leak! Use an auto pointer
+ DataBuf jfif;
if (marker == app0_ && memcmp(tmpbuf + 4, jfifId_, 5) == 0) {
// Read the remainder of the JFIF APP0 segment
is.seekg(-1, std::ios::cur);
- sizeJfifData = size - 7;
- pJfifData = new char[sizeJfifData];
- is.read(pJfifData, sizeJfifData);
- if (!is.good()) {
- delete[] pJfifData;
- pJfifData = 0;
- return 1;
- }
+ jfif.alloc(size -7);
+ is.read(jfif.pData_, jfif.size_);
+ if (!is.good()) return 1;
// Read the beginning of the next segment
is.read(tmpbuf, 10);
if (!is.good()) return 1;
@@ -363,21 +355,20 @@ namespace Exif {
is.seekg(-10, std::ios::cur);
}
if (!validFile) return 3;
-
// Write SOI marker
us2Data(tmpbuf, soi_, bigEndian);
os.write(tmpbuf, 2);
if (!os.good()) return 4;
- if (pJfifData) {
+ if (jfif.pData_) {
// Write APP0 marker, size of APP0 field and JFIF data
us2Data(tmpbuf, app0_, bigEndian);
- us2Data(tmpbuf + 2, 7 + sizeJfifData, bigEndian);
+ us2Data(tmpbuf + 2, 7 + jfif.size_, bigEndian);
memcpy(tmpbuf + 4, jfifId_, 5);
os.write(tmpbuf, 9);
- os.write(pJfifData, sizeJfifData);
- if (!os.good()) return 4;
- delete pJfifData;
- pJfifData = 0;
+ os.write(jfif.pData_, jfif.size_);
+ if (!os.good()) {
+ return 4;
+ }
}
// Write APP1 marker, size of APP1 field, Exif id and Exif data
us2Data(tmpbuf, app1_, bigEndian);
diff --git a/src/tags.cpp b/src/tags.cpp
index 005f818..b799b25 100644
--- a/src/tags.cpp
+++ b/src/tags.cpp
@@ -20,13 +20,13 @@
*/
/*
File: tags.cpp
- Version: $Name: $ $Revision: 1.21 $
+ Version: $Name: $ $Revision: 1.22 $
Author(s): Andreas Huggel (ahu) <ahuggel at gmx.net>
History: 15-Jan-04, ahu: created
*/
// *****************************************************************************
#include "rcsid.hpp"
-EXIV2_RCSID("@(#) $Name: $ $Revision: 1.21 $ $RCSfile: tags.cpp,v $")
+EXIV2_RCSID("@(#) $Name: $ $Revision: 1.22 $ $RCSfile: tags.cpp,v $")
// *****************************************************************************
// included header files
@@ -753,13 +753,12 @@ namespace Exif {
std::ostream& print0x9286(std::ostream& os, const Value& value)
{
if (value.size() > 8) {
- char* buf = new char[value.size()];
- value.copy(buf, bigEndian);
+ DataBuf buf(value.size());
+ value.copy(buf.pData_, bigEndian);
// Hack: Simply skip the leading 8-Byte character code and let
// the stream handle the comment
- std::string userComment(buf+8, value.size() - 8);
+ std::string userComment(buf.pData_ + 8, buf.size_ - 8);
os << userComment;
- delete[] buf;
}
return os;
}
--
exiv2 packaging
More information about the pkg-kde-commits
mailing list