1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Core TIFF data structures
use crate::tiff::ifd::IFD;
use std::fmt;
/// Represents a TIFF file with its Image File Directories (IFDs)
#[derive(Debug)]
pub struct TIFF {
/// Image File Directories in the TIFF file
pub ifds: Vec<IFD>,
/// Whether this is a BigTIFF format
pub is_big_tiff: bool,
}
impl TIFF {
/// Creates a new empty TIFF structure
pub fn new(is_big_tiff: bool) -> Self {
TIFF {
ifds: Vec::new(),
is_big_tiff,
}
}
/// Returns the main (first) IFD if available
pub fn main_ifd(&self) -> Option<&IFD> {
self.ifds.first()
}
/// Returns the number of IFDs in the TIFF file
pub fn ifd_count(&self) -> usize {
self.ifds.len()
}
/// Returns a reference to all overview IFDs (subfile type 1)
pub fn overviews(&self) -> Vec<&IFD> {
self.ifds.iter()
.filter(|ifd| {
if let Some(subfile_type) = ifd.get_tag_value(254) {
subfile_type & 1 == 1 // Check if it's a reduced resolution subfile
} else {
false
}
})
.collect()
}
}
impl fmt::Display for TIFF {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "TIFF File:")?;
writeln!(f, " Format: {}", if self.is_big_tiff { "BigTIFF" } else { "TIFF" })?;
writeln!(f, " Number of IFDs: {}", self.ifds.len())?;
if let Some(ifd) = self.main_ifd() {
write!(f, "{}", ifd)?;
}
Ok(())
}
}