Expose interacting with secondary IFDs

This commit is contained in:
A. Molzer committed 2025-07-11 14:12:36 +02:00
1 parent f33c7be21c
commit f5ab3b363b
2 files changed
+69 -1

No files matched your search

+38
View File
@@ -765,6 +765,13 @@ impl<R: Read + Seek> Decoder<R> {
self.value_reader.reader.goto_offset(offset)
}
/// Read a directory from a known offset.
///
/// This may always modify the position of the reader.
pub fn read_directory(&mut self, ptr: IfdPointer) -> TiffResult<Directory> {
self.value_reader.read_directory(ptr)
}
fn check_chunk_type(&self, expected: ChunkType) -> TiffResult<()> {
if expected != self.image().chunk_type {
return Err(TiffError::UsageError(UsageError::InvalidChunkType(
@@ -985,6 +992,37 @@ impl<R: Read + Seek> Decoder<R> {
}
}
/// Prepare reading tag values for some externally given directory.
///
/// # Examples
///
/// This method may be used to read the values of tags in directories that have been previously
/// read with [`Decoder::read_directory`].
///
/// ```no_run
/// use tiff::decoder::Decoder;
/// use tiff::tags::Tag;
///
/// # use std::io::Cursor;
/// # let mut data = Cursor::new(vec![0]);
/// let mut decoder = Decoder::new(&mut data).unwrap();
/// let sub_ifds = decoder.get_tag(Tag::SubIfd)?.into_ifd_vec()?;
///
/// for ifd in sub_ifds {
/// let subdir = decoder.read_directory(ifd)?;
/// let subfile = decoder.with_ifd(&subdir).find_tag(Tag::SubfileType)?;
/// // todo: handle the subfiles, e.g. thumbnails
/// }
///
/// # Ok::<_, tiff::TiffError>(())
/// ```
pub fn with_ifd<'ifd>(&'ifd mut self, ifd: &'ifd Directory) -> IfdDecoder<'ifd> {
IfdDecoder {
decoder: &mut self.value_reader,
ifd,
}
}
/// Tries to retrieve a tag from the current image directory.
/// Return `Ok(None)` if the tag is not present.
pub fn find_tag(&mut self, tag: Tag) -> TiffResult<Option<ifd::Value>> {