aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2010-03-17 12:04:48 +0100
committerOlivier Tilloy <olivier@tilloy.net>2010-03-17 12:04:48 +0100
commitb259ce32312e32c422dc252148c80a5b8892ced5 (patch)
tree87e2f54be39020e797e5247b22437cfcaa3cc540 /src
parenta9c2f0a1c0f2269df202d49f2b89cba8d2fe7ec2 (diff)
downloadpyexiv2-b259ce32312e32c422dc252148c80a5b8892ced5.tar.gz
getDataBuffer() now releases the GIL to allow other python threads to run
while reading image data.
Diffstat (limited to 'src')
-rw-r--r--src/exiv2wrapper.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp
index 8ee13de..c6a94de 100644
--- a/src/exiv2wrapper.cpp
+++ b/src/exiv2wrapper.cpp
@@ -486,6 +486,12 @@ void Image::copyMetadata(Image& other, bool exif, bool iptc, bool xmp) const
std::string Image::getDataBuffer() const
{
+ std::string buffer;
+
+ // Release the GIL to allow other python threads to run
+ // while reading the image data.
+ Py_BEGIN_ALLOW_THREADS
+
Exiv2::BasicIo& io = _image->io();
long size = io.size();
long pos = -1;
@@ -508,7 +514,7 @@ std::string Image::getDataBuffer() const
// because it would be truncated after the first occurence of a null
// character. Therefore, it has to be copied character by character.
// First allocate the memory for the whole string...
- std::string buffer(size, ' ');
+ buffer.resize(size, ' ');
// ... then fill it with the raw data.
for (unsigned long i = 0; i < size; ++i)
{
@@ -526,6 +532,9 @@ std::string Image::getDataBuffer() const
io.seek(pos, Exiv2::BasicIo::beg);
}
+ // Re-acquire the GIL
+ Py_END_ALLOW_THREADS
+
return buffer;
}