Skip to content

feat:extra_tags_registry #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/src/tiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl PyTIFF {
.map_err(|err| PyFileNotFoundError::new_err(err.to_string()))?;
let mut metadata_reader = TiffMetadataReader::try_open(&metadata_fetch).await.unwrap();
let ifds = metadata_reader
.read_all_ifds(&metadata_fetch)
.read_all_ifds(&metadata_fetch, Default::default())
.await
.unwrap();
let tiff = TIFF::new(ifds);
Expand Down
2 changes: 1 addition & 1 deletion src/cog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod test {
.await
.unwrap();
let ifds = metadata_reader
.read_all_ifds(&prefetch_reader)
.read_all_ifds(&prefetch_reader, Default::default())
.await
.unwrap();
let tiff = TIFF::new(ifds);
Expand Down
26 changes: 24 additions & 2 deletions src/ifd.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::collections::HashMap;
use std::fmt::Debug;
use std::ops::Range;

use bytes::Bytes;
use num_enum::TryFromPrimitive;

use crate::error::{AsyncTiffError, AsyncTiffResult};
use crate::geo::{GeoKeyDirectory, GeoKeyTag};
use crate::metadata::extra_tags::ExtraTagsRegistry;
use crate::predictor::PredictorInfo;
use crate::reader::{AsyncFileReader, Endianness};
use crate::tiff::tags::{
Expand Down Expand Up @@ -133,6 +135,8 @@ pub struct ImageFileDirectory {

pub(crate) copyright: Option<String>,

pub(crate) extra_tags: ExtraTagsRegistry,

// Geospatial tags
pub(crate) geo_key_directory: Option<GeoKeyDirectory>,
pub(crate) model_pixel_scale: Option<Vec<f64>>,
Expand All @@ -149,6 +153,7 @@ impl ImageFileDirectory {
pub fn from_tags(
tag_data: HashMap<Tag, Value>,
endianness: Endianness,
extra_tags_registry: ExtraTagsRegistry,
) -> AsyncTiffResult<Self> {
let mut new_subfile_type = None;
let mut image_width = None;
Expand Down Expand Up @@ -262,8 +267,19 @@ impl ImageFileDirectory {
// Tag::GdalNodata
// Tags for which the tiff crate doesn't have a hard-coded enum variant
Tag::Unknown(DOCUMENT_NAME) => document_name = Some(value.into_string()?),
_ => {
other_tags.insert(tag, value);
t => {
if extra_tags_registry.contains(&t) {
extra_tags_registry[&t].process_tag(t, value).map_err(|e| {
if let AsyncTiffError::InternalTIFFError(err) = e {
err
} else {
// TODO fix error handling. This is bad
TiffError::IntSizeError
}
Comment on lines +271 to +278
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For most purposes, the error will come from Value::into_<something>, which is InternalTiffError, so there it shouldn't be a problem. An alternative would be to panic!, or to do this outside of the match block.

})?;
} else {
other_tags.insert(tag, value);
}
}
};
Ok::<_, TiffError>(())
Expand Down Expand Up @@ -398,6 +414,7 @@ impl ImageFileDirectory {
geo_key_directory,
model_pixel_scale,
model_tiepoint,
extra_tags: extra_tags_registry,
other_tags,
})
}
Expand Down Expand Up @@ -634,6 +651,11 @@ impl ImageFileDirectory {
self.model_tiepoint.as_deref()
}

/// the registry holding extra tags
pub fn extra_tags(&self) -> &ExtraTagsRegistry {
&self.extra_tags
}

/// Tags for which the tiff crate doesn't have a hard-coded enum variant.
pub fn other_tags(&self) -> &HashMap<Tag, Value> {
&self.other_tags
Expand Down
Loading