diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2007-01-03 22:45:33 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2007-01-03 22:45:33 +0100 |
commit | 3eb675871bec989b3027622f6d615140daf76d41 (patch) | |
tree | c8608150b9dce998b1960ca0727eb94d3cec3198 | |
parent | 02c86c9d2f109b4a5e7836e5bd9465724ab4c90e (diff) | |
download | pyexiv2-3eb675871bec989b3027622f6d615140daf76d41.tar.gz |
Implemented Image::getThumbnailData() that returns a string containing the raw data of the thumbnail embedded in an image.
-rw-r--r-- | src/libpyexiv2.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/libpyexiv2.cpp b/src/libpyexiv2.cpp index f203ec7..79e8959 100644 --- a/src/libpyexiv2.cpp +++ b/src/libpyexiv2.cpp @@ -23,6 +23,7 @@ Author(s): Olivier Tilloy <olivier@tilloy.net> History: 28-Dec-06, Olivier Tilloy: created 30-Dec-06, Olivier Tilloy: implemented IPTC-related methods + 03-Jan-07, Olivier Tilloy: implemented getThumbnailData() */ // ***************************************************************************** @@ -398,8 +399,39 @@ namespace LibPyExiv2 boost::python::tuple Image::getThumbnailData() { - //TODO - return boost::python::make_tuple(std::string(""), std::string("")); + if(_dataRead) + { + Exiv2::Thumbnail::AutoPtr thumbnail = _exifData.getThumbnail(); + if (thumbnail.get() != 0) + { + std::string format(_exifData.thumbnailFormat()); + // Copy the data buffer in a string. Since the data buffer can + // contain null char ('\x00'), the string cannot be simply + // constructed like that: + // std::string data((char*) dataBuffer.pData_); + // because it would be truncated after the first occurence of a + // null char. Therefore, it has to be copied char by char. + Exiv2::DataBuf dataBuffer = _exifData.copyThumbnail(); + char* charData = (char*) dataBuffer.pData_; + long dataLen = dataBuffer.size_; + std::string data; + for(long i = 0; i < dataLen; ++i) + { + data.append(1, charData[i]); + } + return boost::python::make_tuple(format, data); + } + else + { + std::cerr << ">>> Image::getThumbnailData(): cannot access thumbnail" << std::endl; + return boost::python::make_tuple(std::string(""), std::string("")); + } + } + else + { + std::cerr << ">>> Image::getThumbnailData(): metadata not read yet, call Image::readMetadata() first" << std::endl; + return boost::python::make_tuple(std::string(""), std::string("")); + } } bool Image::setThumbnailData(boost::python::tuple data) |