Skip to content

Commit 06ebb91

Browse files
committed
added ExtraTags index impl and actually add the tags in ifd::from_tags impl
1 parent 21d6b51 commit 06ebb91

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/ifd.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,13 @@ impl ImageFileDirectory {
267267
// Tag::GdalNodata
268268
// Tags for which the tiff crate doesn't have a hard-coded enum variant
269269
Tag::Unknown(DOCUMENT_NAME) => document_name = Some(value.into_string()?),
270-
_ => {
271-
other_tags.insert(tag, value);
270+
t => {
271+
if extra_tags_registry.contains(&t) {
272+
extra_tags_registry[&t].process_tag(t, value);
273+
} else {
274+
other_tags.insert(tag, value);
275+
}
276+
272277
}
273278
};
274279
Ok::<_, TiffError>(())

src/metadata/extra_tags.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::tiff::Value;
44
use std::any::Any;
55
use std::collections::{HashMap, HashSet};
66
use std::fmt::Debug;
7+
use std::ops::Index;
78
use std::sync::Arc;
89

910
/// Trait to implement for custom tags, such as Geo, EXIF, OME, etc
@@ -13,8 +14,8 @@ pub trait ExtraTags: ExtraTagsBlankets + Any + Debug + Send + Sync {
1314
/// a list of tags this entry processes
1415
/// e.g. for Geo this would be [34735, 34736, 34737]
1516
fn tags(&self) -> &'static [Tag];
16-
/// process a single tag
17-
fn process_tag(&mut self, tag: u16, value: Value) -> AsyncTiffResult<()>;
17+
/// process a single tag, using internal mutability if needed
18+
fn process_tag(&self, tag: Tag, value: Value) -> AsyncTiffResult<()>;
1819
}
1920

2021
// we need to do a little dance to do an object-safe deep clone
@@ -48,6 +49,10 @@ impl ExtraTagsRegistry {
4849
pub fn new() -> Self {
4950
Self(HashMap::new())
5051
}
52+
/// checks if we have an entry for this tag
53+
pub fn contains(&self, tag: &Tag) -> bool {
54+
self.0.contains_key(tag)
55+
}
5156
/// Register an ExtraTags so their tags are parsed and stored in the ifd's `extra_tags``
5257
pub fn register(&mut self, tags: Arc<dyn ExtraTags>) -> AsyncTiffResult<()> {
5358
// check for duplicates
@@ -91,6 +96,13 @@ impl Default for ExtraTagsRegistry {
9196
}
9297
}
9398

99+
impl Index<&Tag> for ExtraTagsRegistry {
100+
type Output = Arc<dyn ExtraTags>;
101+
fn index(&self, index: &Tag) -> &Self::Output {
102+
&self.0[index]
103+
}
104+
}
105+
94106
#[cfg(test)]
95107
mod tests {
96108
use super::*;
@@ -112,8 +124,8 @@ mod tests {
112124
}
113125

114126
fn process_tag(
115-
&mut self,
116-
tag: u16,
127+
&self,
128+
tag: Tag,
117129
value: crate::tiff::Value,
118130
) -> crate::error::AsyncTiffResult<()> {
119131
println!("received {tag:?}: {value:?}");

0 commit comments

Comments
 (0)