[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:14 UTC 2017
Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=2db819c
The following commit has been merged in the master branch:
commit 2db819ccb6e4de71df99871fe852a2d5f776a713
Author: Andreas Huggel <ahuggel at gmx.net>
Date: Thu Apr 1 08:34:50 2004 +0000
Implemented erase Exif data
---
src/actions.cpp | 24 +++++++++----
src/exif.cpp | 16 +++++++--
src/exif.hpp | 8 ++++-
src/image.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
src/image.hpp | 75 ++++++++++++++++++++++++++++++++++++++++-
5 files changed, 213 insertions(+), 13 deletions(-)
diff --git a/src/actions.cpp b/src/actions.cpp
index e4ccd5b..d84d9c3 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -20,13 +20,13 @@
*/
/*
File: actions.cpp
- Version: $Name: $ $Revision: 1.10 $
+ Version: $Name: $ $Revision: 1.11 $
Author(s): Andreas Huggel (ahu) <ahuggel at gmx.net>
History: 08-Dec-03, ahu: created
*/
// *****************************************************************************
#include "rcsid.hpp"
-EXIV2_RCSID("@(#) $Name: $ $Revision: 1.10 $ $RCSfile: actions.cpp,v $")
+EXIV2_RCSID("@(#) $Name: $ $Revision: 1.11 $ $RCSfile: actions.cpp,v $")
// *****************************************************************************
// included header files
@@ -462,9 +462,14 @@ namespace Action {
int Erase::eraseExifData(Exif::ExifData& exifData) const
{
- // Todo: implement me!
- std::cout << "Sorry, the erase action for Exif data has not been implemented yet.
";
- return 0;
+ if (Params::instance().verbose_) {
+ std::cout << "Erasing Exif data from the file
";
+ }
+ int rc = exifData.erase(path_);
+ if (rc) {
+ std::cerr << exifWriteError(rc, path_) << "
";
+ }
+ return rc;
}
Erase::AutoPtr Erase::clone() const
@@ -678,6 +683,9 @@ namespace {
case -1:
error = "Couldn't open file `" + path + "'";
break;
+ case -2:
+ error = "The file contains data of an unknown image type";
+ break;
case 1:
error = "Couldn't read from the input stream";
break;
@@ -705,9 +713,12 @@ namespace {
error = "Couldn't open file `" + path + "'";
break;
case -2:
- error = "Couldn't open temporary file";
+ error = "The file contains data of an unknown image type";
break;
case -3:
+ error = "Couldn't open temporary file";
+ break;
+ case -4:
error = "Renaming temporary file failed";
break;
case 1:
@@ -728,5 +739,4 @@ namespace {
}
return error;
} // exifWriteError
-
}
diff --git a/src/exif.cpp b/src/exif.cpp
index 56c07a9..64069d5 100644
--- a/src/exif.cpp
+++ b/src/exif.cpp
@@ -20,14 +20,14 @@
*/
/*
File: exif.cpp
- Version: $Name: $ $Revision: 1.35 $
+ Version: $Name: $ $Revision: 1.36 $
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.35 $ $RCSfile: exif.cpp,v $")
+EXIV2_RCSID("@(#) $Name: $ $Revision: 1.36 $ $RCSfile: exif.cpp,v $")
// *****************************************************************************
// included header files
@@ -577,6 +577,18 @@ namespace Exif {
return ret;
} // ExifData::read
+ int ExifData::erase(const std::string& path) const
+ {
+ std::ifstream is(path.c_str(), std::ios::binary);
+ if (!is) return -1;
+ Image* pImage = ImageFactory::instance().create(is);
+ if (pImage == 0) return -2;
+
+ int rc = pImage->eraseExifData(path, is);
+ delete pImage;
+ return rc;
+ } // ExifData::erase
+
int ExifData::write(const std::string& path)
{
std::ifstream is(path.c_str(), std::ios::binary);
diff --git a/src/exif.hpp b/src/exif.hpp
index 00530df..97bc46d 100644
--- a/src/exif.hpp
+++ b/src/exif.hpp
@@ -21,7 +21,7 @@
/*!
@file exif.hpp
@brief Encoding and decoding of %Exif data
- @version $Name: $ $Revision: 1.35 $
+ @version $Name: $ $Revision: 1.36 $
@author Andreas Huggel (ahu)
<a href="mailto:ahuggel at gmx.net">ahuggel at gmx.net</a>
@date 09-Jan-04, ahu: created
@@ -614,6 +614,12 @@ namespace Exif {
//! @name Accessors
//@{
+ /*!
+ @brief Erase the %Exif data section from file path.
+ @param path Path to the file.
+ @return 0 if successful.
+ */
+ int erase(const std::string& path) const;
//! Begin of the metadata
const_iterator begin() const { return metadata_.begin(); }
//! End of the metadata
diff --git a/src/image.cpp b/src/image.cpp
index 282edf6..27c4e05 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -20,14 +20,14 @@
*/
/*
File: image.cpp
- Version: $Name: $ $Revision: 1.8 $
+ Version: $Name: $ $Revision: 1.9 $
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.8 $ $RCSfile: image.cpp,v $")
+EXIV2_RCSID("@(#) $Name: $ $Revision: 1.9 $ $RCSfile: image.cpp,v $")
// *****************************************************************************
// included header files
@@ -187,6 +187,105 @@ namespace Exif {
return 0;
} // JpegImage::readExifData
+ int JpegImage::eraseExifData(const std::string& path) const
+ {
+ std::ifstream infile(path.c_str(), std::ios::binary);
+ if (!infile) return -1;
+ return eraseExifData(path, infile);
+ } // JpegImage::eraseExifData
+
+ int JpegImage::eraseExifData(const std::string& path, std::istream& is) const
+ {
+ // Write the output to a temporary file
+ pid_t pid = getpid();
+ std::string tmpname = path + toString(pid);
+ std::ofstream os(tmpname.c_str(), std::ios::binary);
+ if (!os) return -3;
+
+ int rc = eraseExifData(os, is);
+ os.close();
+ if (rc == 0) {
+ // rename temporary file
+ if (rename(tmpname.c_str(), path.c_str()) == -1) rc = -4;
+ }
+ if (rc != 0) {
+ // remove temporary file
+ unlink(tmpname.c_str());
+ }
+
+ return rc;
+ } // JpegImage::eraseExifData
+
+ // 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;
+ return 2;
+ }
+ // Read and check section marker and size
+ char tmpbuf[10];
+ is.read(tmpbuf, 10);
+ if (!is.good()) return 1;
+ uint16 marker = getUShort(tmpbuf, bigEndian);
+ uint16 size = getUShort(tmpbuf + 2, bigEndian);
+ if (size < 8) return 3;
+
+ long sizeJfifData = 9;
+ static char defaultJfifData[] =
+ { 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00 };
+ // Todo: Memory Leak! Use an auto pointer
+ char* pJfifData = 0;
+
+ 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;
+ }
+ // Read the beginning of the next segment
+ is.read(tmpbuf, 10);
+ if (!is.good()) return 1;
+ marker = getUShort(tmpbuf, bigEndian);
+ size = getUShort(tmpbuf + 2, bigEndian);
+ }
+ // Todo: Should we return 0 here (no Exif data found)
+ if (!(marker == app1_ && memcmp(tmpbuf + 4, exifId_, 6) == 0)) return 3;
+ // Skip the rest of the Exif APP1 segment
+ is.seekg(size - 8, std::ios::cur);
+ if (!is.good()) return 1;
+
+ // Write SOI and APP0 markers, size of APP0 field
+ us2Data(tmpbuf, soi_, bigEndian);
+ us2Data(tmpbuf + 2, app0_, bigEndian);
+ us2Data(tmpbuf + 4, 7 + sizeJfifData, 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;
+ }
+ else {
+ os.write(defaultJfifData, sizeJfifData);
+ }
+ if (!os.good()) return 4;
+
+ // Copy the rest of the input stream
+ os.flush();
+ is >> os.rdbuf();
+ if (!os.good()) return 4;
+
+ return 0;
+ } // JpegImage::eraseExifData
+
int JpegImage::writeExifData(const std::string& path) const
{
std::ifstream infile(path.c_str(), std::ios::binary);
diff --git a/src/image.hpp b/src/image.hpp
index 493b774..5ac6397 100644
--- a/src/image.hpp
+++ b/src/image.hpp
@@ -21,7 +21,7 @@
/*!
@file image.hpp
@brief Class JpegImage to access JPEG images
- @version $Name: $ $Revision: 1.8 $
+ @version $Name: $ $Revision: 1.9 $
@author Andreas Huggel (ahu)
<a href="mailto:ahuggel at gmx.net">ahuggel at gmx.net</a>
@date 09-Jan-04, ahu: created
@@ -112,6 +112,35 @@ namespace Exif {
*/
virtual bool isThisType(std::istream& is, bool advance =false) const =0;
/*!
+ @brief Erase the %Exif data from file path.
+ @param path Path to the file.
+ @return 0 if successful.
+ */
+ virtual int eraseExifData(const std::string& path) const =0;
+ /*!
+ @brief Erase the %Exif data from the image provided in the input
+ stream is and write the result to file path.
+ @param path Path to the file.
+ @param is Input stream with the image to erase the %Exif data from.
+ @return 0 if successful.
+ */
+ virtual int eraseExifData(const std::string& path,
+ std::istream& is) const =0;
+
+
+ /*!
+ @brief Read from the image input stream is, erase %Exif data from the
+ image, if there is any, and write the resulting image to the
+ output stream os.
+ @param os Output stream to write to (e.g., a temporary file).
+ @param is Input stream with the image from which the %Exif data
+ should be erased.
+ @return 0 if successful.
+ */
+ virtual int eraseExifData(std::ostream& os, std::istream& is) const =0;
+
+
+ /*!
@brief Write the %Exif data to file path.
@param path Path to the file.
@return 0 if successful.
@@ -302,6 +331,50 @@ namespace Exif {
*/
bool isThisType(std::istream& is, bool advance) const;
/*!
+ @brief Erase the %Exif data from file path, which must contain a JPEG
+ image. If an %Exif APP1 section exists in the file, it is
+ erased.
+ @param path Path to the file.
+ @return 0 if successful;<br>
+ -1 if the input file cannot be opened;<br>
+ the return code of
+ eraseExifData(const std::string& path, std::istream& is) const
+ if the call to this function fails.
+ */
+ int eraseExifData(const std::string& path) const;
+ /*!
+ @brief Erase the %Exif data from the JPEG image provided in the input
+ stream is and write the result to file path. If an %Exif APP1
+ section exists in input stream, it is erased.
+ @param path Path to the file.
+ @param is Input stream with the JPEG image to erase the %Exif data from.
+ @return 0 if successful;<br>
+ -3 if the temporary file cannot be opened;<br>
+ -4 if renaming the temporary file fails.
+ */
+ int eraseExifData(const std::string& path, std::istream& is) const;
+
+
+ /*!
+ @brief Erase %Exif data from the JPEG image is, write the resulting
+ image to the output stream os. If an %Exif APP1 section exists
+ in the input file, it is erased.
+ @param os Output stream to write to (e.g., a temporary file).
+ @param is Input stream with the JPEG image from which the %Exif data
+ should be erased.
+ @return 0 if successful;<BR>
+ 1 if reading from the input stream failed (consult the stream
+ state for more information);<BR>
+ 2 if the input stream does not contain a JPEG image;<BR>
+ 3 if neither a JFIF APP0 segment nor a %Exif APP1 segment was
+ found after SOI at the beginning of the input stream;<BR>
+ 4 if writing to the output stream failed (consult the stream
+ state for more information).
+ */
+ int eraseExifData(std::ostream& os, std::istream& is) const;
+
+
+ /*!
@brief Write the %Exif data to file path, which must contain a JPEG
image. If an %Exif APP1 section exists in the file, it is
replaced. Otherwise, an %Exif data section is created.
--
exiv2 packaging
More information about the pkg-kde-commits
mailing list