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

+31 -1
View File
@@ -6,7 +6,7 @@ use std::mem;
use std::str;
use super::stream::{ByteOrder, EndianReader};
use crate::tags::{Tag, Type};
use crate::tags::{IfdPointer, Tag, Type};
use crate::{TiffError, TiffFormatError, TiffResult};
use self::Value::{
@@ -130,6 +130,25 @@ impl Value {
}
}
/// Turn this value into an `IfdPointer`.
///
/// Notice that this does not take an argument, a 64-bit IFD is always allowed. If the
/// difference is crucial and you do not want to be permissive you're expected to filter this
/// out before.
///
/// For compatibility the smaller sized tags should always be allowed i.e. you might use a
/// non-bigtiff's directory and its tag types and move it straight to a bigtiff. For instance
/// the SubIFD tag is defined as `LONG or IFD`:
///
/// <https://web.archive.org/web/20181105221012/https://www.awaresystems.be/imaging/tiff/tifftags/subifds.html>
pub fn into_ifd_pointer(self) -> TiffResult<IfdPointer> {
match self {
Unsigned(val) | Ifd(val) => Ok(IfdPointer(val.into())),
IfdBig(val) => Ok(IfdPointer(val)),
_ => Err(TiffError::FormatError(TiffFormatError::InvalidTypeForTag)),
}
}
pub fn into_string(self) -> TiffResult<String> {
match self {
Ascii(val) => Ok(val),
@@ -300,6 +319,17 @@ impl Value {
_ => Err(TiffError::FormatError(TiffFormatError::InvalidTypeForTag)),
}
}
pub fn into_ifd_vec(self) -> TiffResult<Vec<IfdPointer>> {
let vec = match self {
Unsigned(val) | Ifd(val) => return Ok(vec![IfdPointer(val.into())]),
IfdBig(val) => return Ok(vec![IfdPointer(val)]),
List(vec) => vec,
_ => return Err(TiffError::FormatError(TiffFormatError::InvalidTypeForTag)),
};
vec.into_iter().map(Self::into_ifd_pointer).collect()
}
}
#[derive(Clone)]