[SCM] exiv2 packaging branch, master, updated. debian/0.25-3.1-3734-gdcbc29a
Maximiliano Curia
maxy at moszumanska.debian.org
Thu Jul 13 17:37:46 UTC 2017
Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=ebe5bb0
The following commit has been merged in the master branch:
commit ebe5bb0a278121a36ee66bdfb1c6ed02753b99c1
Author: Andreas Huggel <ahuggel at gmx.net>
Date: Sun Jun 25 18:11:01 2006 +0000
Added experimental mmap support to improve read performance for TIFF and PNG images, barely tested and only on Linux
---
src/basicio.cpp | 32 +++++++++++++++++++++++++++++++-
src/basicio.hpp | 30 ++++++++++++++++++++++++++++++
src/pngimage.cpp | 8 +-------
src/tiffimage.cpp | 9 +--------
4 files changed, 63 insertions(+), 16 deletions(-)
diff --git a/src/basicio.cpp b/src/basicio.cpp
index 045a194..6424048 100644
--- a/src/basicio.cpp
+++ b/src/basicio.cpp
@@ -48,6 +48,7 @@ EXIV2_RCSID("@(#) $Id$")
#include <cstdlib> // for alloc(), realloc(), free()
#include <sys/types.h> // for stat()
#include <sys/stat.h> // for stat()
+#include <sys/mman.h> // for mmap() and munmap()
#ifdef EXV_HAVE_PROCESS_H
# include <process.h>
#endif
@@ -64,15 +65,44 @@ EXIV2_RCSID("@(#) $Id$")
namespace Exiv2 {
FileIo::FileIo(const std::string& path)
- : path_(path), fp_(0), opMode_(opSeek)
+ : path_(path), fp_(0), opMode_(opSeek), pMappedArea_(0), mappedLength_(0)
{
}
FileIo::~FileIo()
{
+ munmap();
close();
}
+
+// Todo: Experimental
+ void FileIo::munmap()
+ {
+ if (pMappedArea_ != 0) {
+ if (::munmap(pMappedArea_, mappedLength_) != 0) {
+ throw Error(2, path_, strError(), "munmap");
+ }
+ }
+ pMappedArea_ = 0;
+ mappedLength_ = 0;
+ }
+
+ const byte* FileIo::mmap()
+ {
+ assert(fp_ != 0);
+ munmap();
+ mappedLength_ = size();
+ void* rc = ::mmap(0, mappedLength_, PROT_READ, MAP_SHARED, fileno(fp_), 0);
+ if (MAP_FAILED == rc) {
+ throw Error(2, path_, strError(), "mmap");
+ }
+ pMappedArea_ = static_cast<byte*>(rc);
+ return pMappedArea_;
+ }
+
+
+
BasicIo::AutoPtr FileIo::temporary() const
{
BasicIo::AutoPtr basicIo;
diff --git a/src/basicio.hpp b/src/basicio.hpp
index 1726569..61fb2f6 100644
--- a/src/basicio.hpp
+++ b/src/basicio.hpp
@@ -172,6 +172,17 @@ namespace Exiv2 {
Nonzero if failure;
*/
virtual int seek(long offset, Position pos) = 0;
+ /*!
+ @brief Allow efficient direct access to the IO data by mapping it
+ into the process's address space.
+
+ Todo: This is currently only for read access.
+ */
+ virtual const byte* mmap() =0;
+ /*!
+ @brief Remove a mapping established with mmap().
+ */
+ virtual void munmap() =0;
//@}
//! @name Accessors
@@ -393,6 +404,12 @@ namespace Exiv2 {
Nonzero if failure;
*/
virtual int seek(long offset, Position pos);
+ /*!
+ @brief Map the file into the process's address space. The file must
+ be open before mmap() is called.
+ */
+ virtual const byte* mmap();
+ virtual void munmap();
//@}
//! @name Accessors
@@ -446,6 +463,12 @@ namespace Exiv2 {
FILE *fp_;
OpMode opMode_;
+
+// Todo: Experimental
+ byte* pMappedArea_;
+ size_t mappedLength_;
+
+
// METHODS
/*!
@brief Switch to a new access mode, reopening the file if needed.
@@ -589,6 +612,13 @@ namespace Exiv2 {
Nonzero if failure;
*/
virtual int seek(long offset, Position pos);
+ /*!
+ @brief Allow direct access to the underlying data buffer. The buffer
+ is not protected against write access except for the const
+ specifier.
+ */
+ virtual const byte* mmap() { return data_; }
+ virtual void munmap() {}
//@}
//! @name Accessors
diff --git a/src/pngimage.cpp b/src/pngimage.cpp
index 5174c98..a5d692e 100644
--- a/src/pngimage.cpp
+++ b/src/pngimage.cpp
@@ -126,20 +126,14 @@ namespace Exiv2 {
throw Error(9, io_->path(), strError());
}
IoCloser closer(*io_);
-
// Ensure that this is the correct image type
if (!isThisType(*io_, false))
{
if (io_->error() || io_->eof()) throw Error(14);
throw Error(3, "PNG");
}
-
clearMetadata();
-
- DataBuf buf = io_->read(io_->size());
- if (io_->error() || io_->eof()) throw Error(14);
-
- PngChunk::decode(this, buf.pData_, buf.size_);
+ PngChunk::decode(this, io_->mmap(), io_->size());
} // PngImage::readMetadata
diff --git a/src/tiffimage.cpp b/src/tiffimage.cpp
index a2444b3..7ff0eb3 100644
--- a/src/tiffimage.cpp
+++ b/src/tiffimage.cpp
@@ -126,14 +126,7 @@ namespace Exiv2 {
throw Error(33);
}
clearMetadata();
-
- // Read the image into a memory buffer
- long len = io_->size();
- DataBuf buf(len);
- io_->read(buf.pData_, len);
- if (io_->error() || io_->eof()) throw Error(14);
-
- TiffParser::decode(this, buf.pData_, buf.size_,
+ TiffParser::decode(this, io_->mmap(), io_->size(),
TiffCreator::create, TiffDecoder::findDecoder);
} // TiffImage::readMetadata
--
exiv2 packaging
More information about the pkg-kde-commits
mailing list