diff --git a/exif/exif.h b/exif/exif.h index 0d0d706..4813428 100644 --- a/exif/exif.h +++ b/exif/exif.h @@ -23,6 +23,8 @@ typedef struct ExifDataItor ExifDataItor; typedef struct ExifDatumRef ExifDatumRef; ///
typedef struct ExifValueRef ExifValueRef; +/// +typedef struct ExifDataMutItor ExifDataMutItor; #if defined _WIN32 && defined WIN32_DLL #if BUILD_DLL #define EXIF_API __declspec(dllexport) @@ -65,7 +67,7 @@ EXIF_API char* exif_value_to_string2(ExifValueRef* value, size_t* len, long i); EXIF_API int64_t exif_value_to_int64(ExifValueRef* value, long i); EXIF_API ExifValue* exif_value_ref_clone(ExifValueRef* value); EXIF_API ExifData* exif_data_new(); -EXIF_API int exif_data_ref_add(ExifDataRef* d, ExifKey* key, ExifValue* value); +EXIF_API int exif_data_ref_add(ExifDataRef* d, ExifKey* key, ExifValueRef* value); EXIF_API int exif_data_ref_clear(ExifDataRef* d); EXIF_API ExifDataRef* exif_data_get_ref(ExifData* d); EXIF_API ExifData* exif_data_ref_clone(ExifDataRef* d); @@ -74,13 +76,18 @@ EXIF_API long exif_data_ref_get_count(ExifDataRef* d); EXIF_API void exif_data_ref_sort_by_key(ExifDataRef* d); EXIF_API void exif_data_ref_sort_by_tag(ExifDataRef* d); EXIF_API ExifDataItor* exif_data_ref_iter(ExifDataRef* d); +EXIF_API ExifDataMutItor* exif_data_ref_iter_mut(ExifDataRef* d); EXIF_API ExifDatumRef* exif_data_itor_next(ExifDataItor* itor); EXIF_API ExifDatumRef* exif_data_itor_next_back(ExifDataItor* itor); +EXIF_API ExifDatumRef* exif_data_mutitor_next(ExifDataMutItor* itor); +EXIF_API ExifDatumRef* exif_data_mutitor_next_back(ExifDataMutItor* itor); EXIF_API char* exif_datum_key(ExifDatumRef* d); EXIF_API ExifValueRef* exif_datum_value(ExifDatumRef *d); +EXIF_API void exif_datum_set_value(ExifDatumRef* d, ExifValueRef* v); EXIF_API void exif_free_value(ExifValue* value); EXIF_API void exif_free_data(ExifData* d); EXIF_API void exif_free_data_itor(ExifDataItor* itor); +EXIF_API void exif_free_data_mutitor(ExifDataMutItor* itor); #ifdef __cplusplus } #endif diff --git a/exif/src/exif.cpp b/exif/src/exif.cpp index 9de3513..c85a4aa 100644 --- a/exif/src/exif.cpp +++ b/exif/src/exif.cpp @@ -283,10 +283,11 @@ ExifData* exif_data_new() { return new ExifData; } -int exif_data_ref_add(ExifDataRef* d, ExifKey* key, ExifValue* value) { +int exif_data_ref_add(ExifDataRef* d, ExifKey* key, ExifValueRef* value) { if (!d || !key || !value || !key->key) return 0; auto data = (Exiv2::ExifData*)d; - data->add(*key->key, value->value.get()); + auto v = (Exiv2::Value*)value; + data->add(*key->key, v); return 1; } @@ -362,6 +363,15 @@ ExifDataItor* exif_data_ref_iter(ExifDataRef* d) { return re; } +ExifDataMutItor* exif_data_ref_iter_mut(ExifDataRef* d) { + if (!d) return nullptr; + auto re = new ExifDataMutItor; + re->ref = (Exiv2::ExifData*)d; + re->itor = re->ref->begin(); + re->end = re->ref->end(); + return re; +} + void exif_free_data_itor(ExifDataItor* itor) { if (!itor) return; delete itor; @@ -383,6 +393,22 @@ ExifDatumRef* exif_data_itor_next_back(ExifDataItor* itor) { return (ExifDatumRef*)&data; } +ExifDatumRef* exif_data_mutitor_next(ExifDataMutItor* itor) { + if (!itor->ref) return nullptr; + if (itor->itor == itor->end) return nullptr; + auto& data = (*itor->itor); + itor->itor++; + return (ExifDatumRef*)&data; +} + +ExifDatumRef* exif_data_mutitor_next_back(ExifDataMutItor* itor) { + if (!itor->ref) return nullptr; + if (itor->itor == itor->end) return nullptr; + itor->end--; + auto& data = (*itor->end); + return (ExifDatumRef*)&data; +} + char* exif_datum_key(ExifDatumRef* d) { if (!d) return nullptr; auto data = (Exiv2::Exifdatum*)d; @@ -401,3 +427,15 @@ ExifValueRef* exif_datum_value(ExifDatumRef *d) { return nullptr; } } + +void exif_free_data_mutitor(ExifDataMutItor* itor) { + if (!itor) return; + delete itor; +} + +void exif_datum_set_value(ExifDatumRef* d, ExifValueRef* v) { + if (!d || !v) return; + auto da = (Exiv2::Exifdatum*)d; + auto va = (Exiv2::Value*)v; + da->setValue(va); +} diff --git a/exif/src/exif_priv.h b/exif/src/exif_priv.h index cea32d7..7a1a4f9 100644 --- a/exif/src/exif_priv.h +++ b/exif/src/exif_priv.h @@ -22,4 +22,9 @@ typedef struct ExifDataItor { Exiv2::ExifMetadata::const_iterator itor; Exiv2::ExifMetadata::const_iterator end; } ExifDataItor; +typedef struct ExifDataMutItor { + Exiv2::ExifData* ref; + Exiv2::ExifMetadata::iterator itor; + Exiv2::ExifMetadata::iterator end; +} ExifDataMutItor; #endif diff --git a/src/exif.rs b/src/exif.rs index 248c057..e76106c 100644 --- a/src/exif.rs +++ b/src/exif.rs @@ -1,5 +1,5 @@ use crate::_exif; -use crate::_exif::{ExifDataRef, ExifDatumRef, ExifValueRef}; +pub use crate::_exif::{ExifDataRef, ExifDatumRef, ExifValueRef}; use crate::ext::rawhandle::FromRawHandle; use crate::ext::rawhandle::ToRawHandle; use c_fixed_string::CFixedStr; @@ -16,7 +16,7 @@ use std::ffi::OsStr; use std::fs::copy; #[cfg(test)] use std::fs::create_dir; -use std::iter::{DoubleEndedIterator, Iterator}; +use std::iter::{DoubleEndedIterator, ExactSizeIterator, Iterator}; use std::marker::PhantomData; use std::ops::Deref; use std::ops::DerefMut; @@ -595,6 +595,16 @@ impl ExifDatumRef { Some(s.to_owned()) } + /// Set the value. + pub fn set_value<'a>(&'a mut self, value: &ExifValueRef) { + let data = unsafe { self.to_raw_handle() }; + let v = unsafe { value.to_raw_handle() }; + if data.is_null() || v.is_null() { + return; + } + unsafe { _exif::exif_datum_set_value(data, v) } + } + /// Return a constant reference to the value. /// /// This method is provided mostly for convenient and versatile output of the value which can (to some extent) be formatted through standard stream manipulators. @@ -689,7 +699,7 @@ impl ToRawHandle<_exif::ExifData> for ExifData { impl ExifDataRef { /// Add a data from the supplied key and value pair. /// No duplicate checks are performed, i.e., it is possible to add multiple metadata with the same key. - pub fn add(&mut self, key: &ExifKey, value: &ExifValue) -> Result<(), ()> { + pub fn add(&mut self, key: &ExifKey, value: &ExifValueRef) -> Result<(), ()> { let data = unsafe { self.to_raw_handle() }; let k = unsafe { key.to_raw_handle() }; let v = unsafe { value.to_raw_handle() }; @@ -750,12 +760,44 @@ impl ExifDataRef { pub fn iter<'a>(&'a self) -> Option