diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2010-11-23 20:49:04 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2010-11-23 20:49:04 +0100 |
commit | 2517ce2efcdea061e4a267f7ede70b15cee2a0f3 (patch) | |
tree | cd41b643afdae8e3e669cb7e23a14fff88ddec59 /src/exiv2wrapper.cpp | |
parent | cc86aa2c24b3c53444c108b82295aae2085904db (diff) | |
parent | 17689217344b7875fd2e701035e814e172af9630 (diff) | |
download | pyexiv2-2517ce2efcdea061e4a267f7ede70b15cee2a0f3.tar.gz |
Read/write access to the EXIF thumbnail.
Diffstat (limited to 'src/exiv2wrapper.cpp')
-rw-r--r-- | src/exiv2wrapper.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp index a5ae4aa..0d80e05 100644 --- a/src/exiv2wrapper.cpp +++ b/src/exiv2wrapper.cpp @@ -44,6 +44,8 @@ namespace exiv2wrapper void Image::_instantiate_image() { + _exifThumbnail = 0; + // If an exception is thrown, it has to be done outside of the // Py_{BEGIN,END}_ALLOW_THREADS block. Exiv2::Error error(0); @@ -117,6 +119,10 @@ Image::~Image() { delete[] _data; } + if (_exifThumbnail != 0) + { + delete _exifThumbnail; + } } void Image::readMetadata() @@ -444,6 +450,65 @@ std::string Image::getDataBuffer() const return buffer; } +Exiv2::ExifThumb* Image::_getExifThumbnail() +{ + CHECK_METADATA_READ + if (_exifThumbnail == 0) + { + _exifThumbnail = new Exiv2::ExifThumb(*_exifData); + } + return _exifThumbnail; +} + +const std::string Image::getExifThumbnailMimeType() +{ + return std::string(_getExifThumbnail()->mimeType()); +} + +const std::string Image::getExifThumbnailExtension() +{ + return std::string(_getExifThumbnail()->extension()); +} + +void Image::writeExifThumbnailToFile(const std::string& path) +{ + _getExifThumbnail()->writeFile(path); +} + +const std::string Image::getExifThumbnailData() +{ + Exiv2::DataBuf buffer = _getExifThumbnail()->copy(); + // Copy the data buffer in a string. Since the data buffer can contain null + // characters ('\x00'), the string cannot be simply constructed like that: + // data = std::string((char*) buffer.pData_); + // 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 data = std::string(buffer.size_, ' '); + // ... then fill it with the raw data. + for(unsigned int i = 0; i < buffer.size_; ++i) + { + data[i] = buffer.pData_[i]; + } + return data; +} + +void Image::eraseExifThumbnail() +{ + _getExifThumbnail()->erase(); +} + +void Image::setExifThumbnailFromFile(const std::string& path) +{ + _getExifThumbnail()->setJpegThumbnail(path); +} + +void Image::setExifThumbnailFromData(const std::string& data) +{ + const Exiv2::byte* buffer = (const Exiv2::byte*) data.c_str(); + _getExifThumbnail()->setJpegThumbnail(buffer, data.size()); +} + ExifTag::ExifTag(const std::string& key, Exiv2::Exifdatum* datum, Exiv2::ExifData* data): _key(key) { |