aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2010-05-19 19:54:53 +0200
committerOlivier Tilloy <olivier@tilloy.net>2010-05-19 19:54:53 +0200
commit0c2a0abd2ee15ac0d239daa8656347b550bd1d9c (patch)
tree4f2a4721fb23d393ee4b3ec3e1c59f4c14ab0473 /src
parent42e685da4e1811455017914e6bfb01b0ceea3f76 (diff)
downloadpyexiv2-0c2a0abd2ee15ac0d239daa8656347b550bd1d9c.tar.gz
Attach the image's ExifData to a tag when it is assigned to an image.
Remove redundant code that would set the value of a tag twice (in the tag itself, and in the image). Remove the now useless metadata attribute.
Diffstat (limited to 'src')
-rw-r--r--src/exiv2wrapper.cpp16
-rw-r--r--src/exiv2wrapper.hpp11
-rw-r--r--src/exiv2wrapper_python.cpp2
-rw-r--r--src/pyexiv2/exif.py9
-rw-r--r--src/pyexiv2/metadata.py16
5 files changed, 21 insertions, 33 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp
index cc2d455..c579b87 100644
--- a/src/exiv2wrapper.cpp
+++ b/src/exiv2wrapper.cpp
@@ -281,13 +281,6 @@ const ExifTag Image::getExifTag(std::string key)
return ExifTag(key, &_exifData[key], &_exifData);
}
-void Image::setExifTagValue(std::string key, std::string value)
-{
- CHECK_METADATA_READ
-
- _exifData[key] = value;
-}
-
void Image::deleteExifTag(std::string key)
{
CHECK_METADATA_READ
@@ -571,6 +564,15 @@ void ExifTag::setRawValue(const std::string& value)
_datum->setValue(value);
}
+void ExifTag::setParentImage(Image& image)
+{
+ _data = image.getExifData();
+ std::string value = _datum->toString();
+ delete _datum;
+ _datum = &(*_data)[_key.key()];
+ _datum->setValue(value);
+}
+
const std::string ExifTag::getKey()
{
return _key.key();
diff --git a/src/exiv2wrapper.hpp b/src/exiv2wrapper.hpp
index 0408e1a..6ba62f9 100644
--- a/src/exiv2wrapper.hpp
+++ b/src/exiv2wrapper.hpp
@@ -36,6 +36,8 @@
namespace exiv2wrapper
{
+class Image;
+
class ExifTag
{
public:
@@ -45,6 +47,7 @@ public:
~ExifTag();
void setRawValue(const std::string& value);
+ void setParentImage(Image& image);
const std::string getKey();
const std::string getType();
@@ -186,10 +189,6 @@ public:
// Throw an exception if the tag is not set.
const ExifTag getExifTag(std::string key);
- // Set the EXIF tag's value.
- // If the tag was not previously set, it is created.
- void setExifTagValue(std::string key, std::string value);
-
// Delete the required EXIF tag.
// Throw an exception if the tag was not set.
void deleteExifTag(std::string key);
@@ -238,6 +237,10 @@ public:
// Return the image data buffer.
std::string getDataBuffer() const;
+ // Accessors
+ Exiv2::ExifData* getExifData() { return &_exifData; };
+ // ...
+
private:
std::string _filename;
Exiv2::byte* _data;
diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp
index 5a03132..e970c69 100644
--- a/src/exiv2wrapper_python.cpp
+++ b/src/exiv2wrapper_python.cpp
@@ -48,6 +48,7 @@ BOOST_PYTHON_MODULE(libexiv2python)
class_<ExifTag>("_ExifTag", init<std::string>())
.def("_setRawValue", &ExifTag::setRawValue)
+ .def("_setParentImage", &ExifTag::setParentImage)
.def("_getKey", &ExifTag::getKey)
.def("_getType", &ExifTag::getType)
@@ -130,7 +131,6 @@ BOOST_PYTHON_MODULE(libexiv2python)
.def("_exifKeys", &Image::exifKeys)
.def("_getExifTag", &Image::getExifTag)
- .def("_setExifTagValue", &Image::setExifTagValue)
.def("_deleteExifTag", &Image::deleteExifTag)
.def("_iptcKeys", &Image::iptcKeys)
diff --git a/src/pyexiv2/exif.py b/src/pyexiv2/exif.py
index 6964b4b..2c485e2 100644
--- a/src/pyexiv2/exif.py
+++ b/src/pyexiv2/exif.py
@@ -72,9 +72,6 @@ class ExifTag(ListenerInterface):
- Short, SShort: [list of] int
- Rational, SRational: [list of] :class:`pyexiv2.utils.Rational`
- Undefined: string
-
- :attribute metadata: the parent metadata if any, or None
- :type metadata: :class:`pyexiv2.metadata.ImageMetadata`
"""
# According to the EXIF specification, the only accepted format for an Ascii
@@ -100,13 +97,15 @@ class ExifTag(ListenerInterface):
self._tag = _tag
else:
self._tag = libexiv2python._ExifTag(key)
- self.metadata = None
self._raw_value = None
self._value = None
self._value_cookie = False
if value is not None:
self._set_value(value)
+ def _set_owner(self, metadata):
+ self._tag._setParentImage(metadata._image)
+
@staticmethod
def _from_existing_tag(_tag):
# Build a tag from an already existing libexiv2python._ExifTag.
@@ -159,8 +158,6 @@ class ExifTag(ListenerInterface):
def _set_raw_value(self, value):
self._tag._setRawValue(value)
- if self.metadata is not None:
- self.metadata._set_exif_tag_value(self.key, value)
self._raw_value = value
self._value_cookie = True
diff --git a/src/pyexiv2/metadata.py b/src/pyexiv2/metadata.py
index 730e99f..93ab4bb 100644
--- a/src/pyexiv2/metadata.py
+++ b/src/pyexiv2/metadata.py
@@ -138,7 +138,6 @@ class ImageMetadata(object):
except KeyError:
_tag = self._image._getExifTag(key)
tag = ExifTag._from_existing_tag(_tag)
- tag.metadata = self
self._tags['exif'][key] = tag
return tag
@@ -190,23 +189,10 @@ class ImageMetadata(object):
else:
# As a handy shortcut, accept direct value assignment.
tag = ExifTag(key, tag_or_value)
- self._image._setExifTagValue(tag.key, tag.raw_value)
+ tag._set_owner(self)
self._tags['exif'][tag.key] = tag
if tag.key not in self.exif_keys:
self._keys['exif'].append(tag.key)
- tag.metadata = self
-
- def _set_exif_tag_value(self, key, value):
- # Overwrite the tag value for an already existing tag.
- # The tag is already in cache.
- # Warning: this is not meant to be called directly as it doesn't update
- # the internal cache (which would leave the object in an inconsistent
- # state).
- if key not in self.exif_keys:
- raise KeyError('Cannot set the value of an inexistent tag')
- if type(value) is not str:
- raise TypeError('Expecting a string')
- self._image._setExifTagValue(key, value)
def _set_iptc_tag(self, key, tag_or_values):
# Set an IPTC tag. If the tag already exists, its values are