From 8b3562b019794802f26ceb4f0761b47c876b2e08 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Fri, 8 Jan 2010 09:23:32 +0100 Subject: Preview (thumbnail) extraction. Read-only at the moment. --- src/exiv2wrapper.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/exiv2wrapper.cpp') diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp index 914657a..3dbd8b2 100644 --- a/src/exiv2wrapper.cpp +++ b/src/exiv2wrapper.cpp @@ -398,6 +398,24 @@ void Image::deleteXmpTag(std::string key) throw Exiv2::Error(KEY_NOT_FOUND, key); } +boost::python::list Image::previews() +{ + CHECK_METADATA_READ + + boost::python::list previews; + Exiv2::PreviewManager pm(*_image); + Exiv2::PreviewPropertiesList props = pm.getPreviewProperties(); + for (Exiv2::PreviewPropertiesList::const_iterator i = props.begin(); + i != props.end(); + ++i) + { + previews.append(Preview(pm.getPreviewImage(*i))); + } + + return previews; +} + + /* boost::python::tuple Image::getThumbnailData() { @@ -774,6 +792,29 @@ const boost::python::dict XmpTag::getLangAltValue() } +Preview::Preview(const Exiv2::PreviewImage& previewImage) +{ + _mimeType = previewImage.mimeType(); + _extension = previewImage.extension(); + _size = previewImage.size(); + _dimensions = boost::python::make_tuple(previewImage.width(), + previewImage.height()); + // 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*) previewImage.pData()); + // because it would be truncated after the first occurence of a null + // character. Therefore, it has to be copied character by character. + const Exiv2::byte* pData = previewImage.pData(); + // First allocate the memory for the whole string... + _data = std::string(_size, ' '); + // ... then fill it with the raw data. + for(unsigned int i = 0; i < _size; ++i) + { + _data[i] = pData[i]; + } +} + + // TODO: update the errors code to reflect changes from src/error.cpp in libexiv2 void translateExiv2Error(Exiv2::Error const& error) { -- cgit