-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add support for iterating over all tags #255
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question I have is whether the strip/tile offsets and lengths should be included in the iteration over all tags. On one hand it is better for consistency, but they're also likely to be larger than the other tags and not especially helpful for users
src/decoder/mod.rs
Outdated
@@ -895,6 +898,18 @@ impl<R: Read + Seek> Decoder<R> { | |||
self.get_tag(tag)?.into_string() | |||
} | |||
|
|||
pub fn tag_iter(&mut self) -> impl Iterator<Item = TiffResult<(Tag, ifd::Value)>> + '_ { | |||
match self.image().ifd.as_ref() { | |||
None => Either::Left(std::iter::empty()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know when this case happens? Wondering if we should return None or an error rather than an empty iterator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea, honestly. I think from a developer perspective, it is more convenient to have an empty iterator instead of having to deal with an Option
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I went through the existing code. It should be impossible for ifd
to be None here, so please just .unwrap()
it
src/decoder/mod.rs
Outdated
pub fn tag_iter(&mut self) -> impl Iterator<Item = TiffResult<(Tag, ifd::Value)>> + '_ { | ||
match self.image().ifd.as_ref() { | ||
None => Either::Left(std::iter::empty()), | ||
Some(ifd) => Either::Right(TagIter::new( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than constructing a TagIter here, I think we could directly return:
ifd.clone().into_iter().map(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried but failed to make the borrow checker happy with this approach. Happy to change it if you can provide a working solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to get it to work with:
self.image.ifd.as_ref().unwrap().iter().map(|(tag, entry)| {
entry
.val(&self.limits, self.bigtiff, &mut self.reader)
.map(|value| (*tag, value))
})
(You have to directly access the self.image
field rather than calling the self.image()
method to make the borrow check happy. There was a reason why the two are separate, though I don't remember what it is right now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, cool, thx! I incorporated your changes and pushed the branch.
I noticed tests are failing on CI. However, they run fine on my local machine (MacBook Pro M1). Maybe something is architecture/platform-dependent in the decoder @fintelia? |
09f6d60
to
395a755
Compare
@@ -895,6 +898,18 @@ impl<R: Read + Seek> Decoder<R> { | |||
self.get_tag(tag)?.into_string() | |||
} | |||
|
|||
pub fn tag_iter(&mut self) -> impl Iterator<Item = TiffResult<(Tag, ifd::Value)>> + '_ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a short doc comment explaining what this method does? Something like "Returns an iterator over all tags in the current image"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
Thanks for pointing that out. I occasionally forget about that when I'm on a fork. |
e4c1fd2
to
fd2bd31
Compare
Thanks! |
Closes #243