Skip to content

wip: Extension tag registry#182

Draft
kylebarron wants to merge 1 commit intomainfrom
kyle/extension-registry
Draft

wip: Extension tag registry#182
kylebarron wants to merge 1 commit intomainfrom
kyle/extension-registry

Conversation

@kylebarron
Copy link
Member

@kylebarron kylebarron commented Jan 26, 2026

Added some thoughts inline

Closes #100

/// A registry for extensions that extend the set of tags able to be parsed from the TIFF
/// [`ImageFileDirectory``].
#[derive(Debug)]
pub struct ExtensionRegistry(HashMap<String, Box<dyn TiffExtensionFactory>>);
Copy link
Member Author

Choose a reason for hiding this comment

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

The idea is for the user to define one or more TiffExtensionFactory to be used when parsing a TIFF, where one defines how to create a new struct to hold parsed TIFF tag data

/// The name of the extension.
fn name(&self) -> &str;

fn from_tags(&self, tag_data: HashMap<Tag, TagValue>) -> Box<dyn TiffExtension>;
Copy link
Member Author

Choose a reason for hiding this comment

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

Defines how the factory creates a new TiffExtension instance from tags of

One difficult thing is that the tags here are provided by value,

Really we want an API where the TiffExtensionFactory builds up extension information iteratively. Where it defines the tags that it claims how to support, and then when a tag with that key is found, the IFD parser delegates to this extension builder.

So perhaps we need three things: TiffExtensionFactory, TiffExtensionBuilder, and TiffExtension. A factory defines how to create a builder. A builder receives tag data one-by-one. Then after the last tag a builder is "finished" into a standalone metadata instance.

Copy link
Contributor

@feefladder feefladder Jan 27, 2026

Choose a reason for hiding this comment

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

So perhaps we need three things: TiffExtensionFactory, TiffExtensionBuilder, and TiffExtension. A factory defines how to create a builder. A builder receives tag data one-by-one. Then after the last tag a builder is "finished" into a standalone metadata instance.

Hi Kyle, this seems great, also nice to see a lot is happening again. Just to summarize, that would look something like this:

pub trait TiffExtensionFactory: std::fmt::Debug + Send + Sync {
    fn name(&self) -> &str;
    fn create_builder(&self) -> Box<dyn TiffExtensionBuilder>
}

pub trait TiffExtensionBuilder: std::fmt::Debug + Send + Sync {
  fn supported_tags(&self) -> &HashSet<u16>;
  /// insert the tag into self
  fn insert(&mut self, tag: u16, value: TagValue);
  /// Finish parsing self, returning the TiffExtension on success
  fn finish(&mut self) -> Result<Box<dyn TiffExtension>, AsyncTiffError>
}

/// the main thing is that it can be put in a HashMap. supertrait `std::any::Any` to get the underlying data structure through a `downcast_ref()`
pub trait TiffExtension: std::any::Any {
  fn as_any(&self) -> &dyn std::any::Any;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, pretty much

Copy link
Contributor

Choose a reason for hiding this comment

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

One thought was that it may very well happen that an IFD does not contain any supported tags. As in a COG only the first ifd contains geo data (now I can only find this section ) So maybe finish()->Option<> should handle that (quite common?) case?

}

#[derive(Debug)]
pub struct GeoTIFFExtension {
Copy link
Member Author

Choose a reason for hiding this comment

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

An example of a parsed GeoTIFF extension. This will then expose the parsed information to the end user.

@kylebarron kylebarron marked this pull request as draft January 26, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extension tag registry

2 participants