From 079dc54c945f12380b7b935a0765dba76fac257f Mon Sep 17 00:00:00 2001 From: cc Date: Wed, 20 Aug 2025 17:47:38 -0700 Subject: Read Entire TIFF data --- src/lib.rs | 11 +++++++++++ src/tiff.rs | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 4493a14..457eadc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,6 +93,17 @@ mod tests { } } + #[test] + fn tiff_read() { + tiff::ignore_warnings(); + if let Some(t_handle) = tiff::open("../test.tif") { + let data = tiff::read(t_handle); + tiff::close(t_handle); + } else { + assert!(false); + } + } + #[test] fn tiff_strip_read() { tiff::ignore_warnings(); diff --git a/src/tiff.rs b/src/tiff.rs index 08f4d54..8e77233 100644 --- a/src/tiff.rs +++ b/src/tiff.rs @@ -97,3 +97,19 @@ pub fn read_strip(tiff_ptr: *mut TIFF, strip: u32) -> Vec { } buf } + +pub fn read(tiff_ptr: *mut TIFF) -> Vec { + let strip_size = get_strip_size(tiff_ptr); + let strip_count = get_strip_count(tiff_ptr); + let mut total_buf: Vec = vec![0u8; (strip_size * strip_count) as usize]; + for strip_index in 0..strip_count { + let sub_buffer: Vec = read_strip(tiff_ptr, strip_index as u32); + let base_index = strip_index * strip_size; + for data_index in 0..strip_size { + let total_index = base_index + data_index; + let data = sub_buffer[data_index as usize]; + total_buf[total_index as usize] = data; + } + } + total_buf +} -- cgit v1.2.1