aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-11-12 19:48:39 +0100
committerOlivier Tilloy <olivier@tilloy.net>2009-11-12 19:48:39 +0100
commit7a354b4495f7940f75b2bdf61732a0e166b7b2a0 (patch)
treebd0028cc22853a878fc2ea3ce34446b746342795 /src
parenta7f87eeba9cfd16e15e58a1cbc8d9e588b6432a9 (diff)
downloadpyexiv2-7a354b4495f7940f75b2bdf61732a0e166b7b2a0.tar.gz
Make Image::getExifTag return an ExifTag.
Diffstat (limited to 'src')
-rw-r--r--src/exiv2wrapper.cpp59
-rw-r--r--src/exiv2wrapper.hpp139
-rw-r--r--src/exiv2wrapper_python.cpp62
3 files changed, 129 insertions, 131 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp
index 34abd6d..792b72c 100644
--- a/src/exiv2wrapper.cpp
+++ b/src/exiv2wrapper.cpp
@@ -94,33 +94,21 @@ boost::python::list Image::exifKeys()
}
}
-boost::python::tuple Image::getExifTag(std::string key)
+const ExifTag Image::getExifTag(std::string key)
{
- if(_dataRead)
+ if (!_dataRead)
{
- Exiv2::ExifKey exifKey = Exiv2::ExifKey(key);
- if(_exifData.findKey(exifKey) != _exifData.end())
- {
- Exiv2::Exifdatum exifDatum = _exifData[key];
- std::string sTagName = exifDatum.tagName();
- std::string sTagLabel = exifDatum.tagLabel();
- std::string sTagDesc(Exiv2::ExifTags::tagDesc(exifKey.tag(), exifKey.ifdId()));
- std::string sTagType = exifDatum.typeName();
- std::string sTagValue = exifDatum.toString();
- std::ostringstream sTagStringValueBuffer;
- sTagStringValueBuffer << exifDatum;
- std::string sTagStringValue = sTagStringValueBuffer.str();
- return boost::python::make_tuple(key, sTagName, sTagLabel, sTagDesc, sTagType, sTagValue, sTagStringValue);
- }
- else
- {
- throw Exiv2::Error(KEY_NOT_FOUND, key);
- }
+ throw Exiv2::Error(METADATA_NOT_READ);
}
- else
+
+ Exiv2::ExifKey exifKey = Exiv2::ExifKey(key);
+
+ if(_exifData.findKey(exifKey) == _exifData.end())
{
- throw Exiv2::Error(METADATA_NOT_READ);
+ throw Exiv2::Error(KEY_NOT_FOUND, key);
}
+
+ return ExifTag(key, &_exifData[key]);
}
void Image::setExifTagValue(std::string key, std::string value)
@@ -469,10 +457,19 @@ void Image::setThumbnailFromJpegFile(const std::string path)
*/
-ExifTag::ExifTag(const std::string& key): _key(key), _datum(_key)
+ExifTag::ExifTag(const std::string& key, Exiv2::Exifdatum* datum): _key(key)
{
- const uint16_t tag = _datum.tag();
- const Exiv2::IfdId ifd = _datum.ifdId();
+ if (datum != 0)
+ {
+ _datum = datum;
+ }
+ else
+ {
+ _datum = new Exiv2::Exifdatum(_key);
+ }
+
+ const uint16_t tag = _datum->tag();
+ const Exiv2::IfdId ifd = _datum->ifdId();
_type = Exiv2::TypeInfo::typeName(Exiv2::ExifTags::tagType(tag, ifd));
_name = Exiv2::ExifTags::tagName(tag, ifd);
_title = Exiv2::ExifTags::tagTitle(tag, ifd);
@@ -480,21 +477,21 @@ ExifTag::ExifTag(const std::string& key): _key(key), _datum(_key)
_description = Exiv2::ExifTags::tagDesc(tag, ifd);
_sectionName = Exiv2::ExifTags::sectionName(tag, ifd);
_sectionDescription = Exiv2::ExifTags::sectionDesc(tag, ifd);
- _raw_value = _datum.toString();
- if(_datum.getValue().get() != 0)
+ _raw_value = _datum->toString();
+ if(_datum->getValue().get() != 0)
{
std::ostringstream buffer;
- buffer << _datum;
+ buffer << *_datum;
_human_value = buffer.str();
}
}
void ExifTag::setRawValue(const std::string& value)
{
- _datum.setValue(value);
- _raw_value = _datum.toString();
+ _datum->setValue(value);
+ _raw_value = _datum->toString();
std::ostringstream buffer;
- buffer << _datum;
+ buffer << *_datum;
_human_value = buffer.str();
}
diff --git a/src/exiv2wrapper.hpp b/src/exiv2wrapper.hpp
index 4098123..34dca80 100644
--- a/src/exiv2wrapper.hpp
+++ b/src/exiv2wrapper.hpp
@@ -37,6 +37,74 @@
namespace exiv2wrapper
{
+class ExifTag
+{
+public:
+ // Constructor
+ ExifTag(const std::string& key, Exiv2::Exifdatum* datum=0);
+
+ void setRawValue(const std::string& value);
+
+ const std::string getKey();
+ const std::string getType();
+ const std::string getName();
+ const std::string getTitle();
+ const std::string getLabel();
+ const std::string getDescription();
+ const std::string getSectionName();
+ const std::string getSectionDescription();
+ const std::string getRawValue();
+ const std::string getHumanValue();
+
+private:
+ Exiv2::ExifKey _key;
+ Exiv2::Exifdatum* _datum;
+ std::string _type;
+ std::string _name;
+ std::string _title;
+ std::string _label;
+ std::string _description;
+ std::string _sectionName;
+ std::string _sectionDescription;
+ std::string _raw_value;
+ std::string _human_value;
+};
+
+
+class IptcTag
+{
+public:
+ // Constructor
+ IptcTag(const std::string& key);
+
+ void setValue(const std::string& value);
+
+ const std::string getKey();
+ const std::string getType();
+ const std::string getName();
+ const std::string getTitle();
+ const std::string getDescription();
+ const std::string getPhotoshopName();
+ const bool isRepeatable();
+ const std::string getRecordName();
+ const std::string getRecordDescription();
+ const std::string getValue();
+
+private:
+ Exiv2::IptcKey _key;
+ Exiv2::Iptcdatum _datum;
+ std::string _type;
+ std::string _name;
+ std::string _title;
+ std::string _description;
+ std::string _photoshopName;
+ bool _repeatable;
+ std::string _recordName;
+ std::string _recordDescription;
+ std::string _value;
+};
+
+
class Image
{
public:
@@ -65,7 +133,8 @@ public:
// type
// tagvalue
// tagvalue (human-readable)
- boost::python::tuple getExifTag(std::string key);
+ //boost::python::tuple getExifTag(std::string key);
+ const ExifTag getExifTag(std::string key);
// Set the EXIF tag's value. If the tag was not previously set, it is
// created.
@@ -156,74 +225,6 @@ private:
};
-class ExifTag
-{
-public:
- // Constructor
- ExifTag(const std::string& key);
-
- void setRawValue(const std::string& value);
-
- const std::string getKey();
- const std::string getType();
- const std::string getName();
- const std::string getTitle();
- const std::string getLabel();
- const std::string getDescription();
- const std::string getSectionName();
- const std::string getSectionDescription();
- const std::string getRawValue();
- const std::string getHumanValue();
-
-private:
- Exiv2::ExifKey _key;
- Exiv2::Exifdatum _datum;
- std::string _type;
- std::string _name;
- std::string _title;
- std::string _label;
- std::string _description;
- std::string _sectionName;
- std::string _sectionDescription;
- std::string _raw_value;
- std::string _human_value;
-};
-
-
-class IptcTag
-{
-public:
- // Constructor
- IptcTag(const std::string& key);
-
- void setValue(const std::string& value);
-
- const std::string getKey();
- const std::string getType();
- const std::string getName();
- const std::string getTitle();
- const std::string getDescription();
- const std::string getPhotoshopName();
- const bool isRepeatable();
- const std::string getRecordName();
- const std::string getRecordDescription();
- const std::string getValue();
-
-private:
- Exiv2::IptcKey _key;
- Exiv2::Iptcdatum _datum;
- std::string _type;
- std::string _name;
- std::string _title;
- std::string _description;
- std::string _photoshopName;
- bool _repeatable;
- std::string _recordName;
- std::string _recordDescription;
- std::string _value;
-};
-
-
// Translate an Exiv2 generic exception into a Python exception
void translateExiv2Error(Exiv2::Error const& error);
diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp
index 11c0eb9..0ff5e32 100644
--- a/src/exiv2wrapper_python.cpp
+++ b/src/exiv2wrapper_python.cpp
@@ -45,37 +45,6 @@ BOOST_PYTHON_MODULE(libexiv2python)
register_exception_translator<Exiv2::Error>(&translateExiv2Error);
- class_<Image>("Image", init<std::string>())
-
- .def("readMetadata", &Image::readMetadata)
- .def("writeMetadata", &Image::writeMetadata)
-
- .def("exifKeys", &Image::exifKeys)
- .def("getExifTag", &Image::getExifTag)
- .def("setExifTagValue", &Image::setExifTagValue)
- .def("deleteExifTag", &Image::deleteExifTag)
-
- .def("iptcKeys", &Image::iptcKeys)
- .def("getIptcTag", &Image::getIptcTag)
- .def("setIptcTagValues", &Image::setIptcTagValues)
- .def("deleteIptcTag", &Image::deleteIptcTag)
-
- .def("xmpKeys", &Image::xmpKeys)
- .def("getXmpTag", &Image::getXmpTag)
- .def("setXmpTagValue", &Image::setXmpTagValue)
- .def("deleteXmpTag", &Image::deleteXmpTag)
-
-// .def("getThumbnailData", &Image::getThumbnailData)
-// .def("setThumbnailData", &Image::setThumbnailData)
-// .def("deleteThumbnail", &Image::deleteThumbnail)
-// .def("dumpThumbnailToFile", &Image::dumpThumbnailToFile)
-// .def("setThumbnailFromJpegFile", &Image::setThumbnailFromJpegFile)
-
-// .def("getComment", &Image::getComment)
-// .def("setComment", &Image::setComment)
-// .def("clearComment", &Image::clearComment)
- ;
-
class_<ExifTag>("ExifTag", init<std::string>())
.def("_setRawValue", &ExifTag::setRawValue)
@@ -107,5 +76,36 @@ BOOST_PYTHON_MODULE(libexiv2python)
.def("_getRecordDescription", &IptcTag::getRecordDescription)
.def("_getValue", &IptcTag::getValue)
;
+
+ class_<Image>("Image", init<std::string>())
+
+ .def("readMetadata", &Image::readMetadata)
+ .def("writeMetadata", &Image::writeMetadata)
+
+ .def("exifKeys", &Image::exifKeys)
+ .def("getExifTag", &Image::getExifTag)
+ .def("setExifTagValue", &Image::setExifTagValue)
+ .def("deleteExifTag", &Image::deleteExifTag)
+
+ .def("iptcKeys", &Image::iptcKeys)
+ .def("getIptcTag", &Image::getIptcTag)
+ .def("setIptcTagValues", &Image::setIptcTagValues)
+ .def("deleteIptcTag", &Image::deleteIptcTag)
+
+ .def("xmpKeys", &Image::xmpKeys)
+ .def("getXmpTag", &Image::getXmpTag)
+ .def("setXmpTagValue", &Image::setXmpTagValue)
+ .def("deleteXmpTag", &Image::deleteXmpTag)
+
+// .def("getThumbnailData", &Image::getThumbnailData)
+// .def("setThumbnailData", &Image::setThumbnailData)
+// .def("deleteThumbnail", &Image::deleteThumbnail)
+// .def("dumpThumbnailToFile", &Image::dumpThumbnailToFile)
+// .def("setThumbnailFromJpegFile", &Image::setThumbnailFromJpegFile)
+
+// .def("getComment", &Image::getComment)
+// .def("setComment", &Image::setComment)
+// .def("clearComment", &Image::clearComment)
+ ;
}