diff options
author | cc <cc@localhost> | 2025-08-20 17:47:38 -0700 |
---|---|---|
committer | cc <cc@localhost> | 2025-08-20 17:47:38 -0700 |
commit | 079dc54c945f12380b7b935a0765dba76fac257f (patch) | |
tree | 3e270c03d0943992ee153231d027099f2e8fb5e8 | |
parent | 972a413ebf54edbdd777379f1db7ebb6731f5ecc (diff) |
Read Entire TIFF data
-rw-r--r-- | src/lib.rs | 11 | ||||
-rw-r--r-- | src/tiff.rs | 16 |
2 files changed, 27 insertions, 0 deletions
@@ -94,6 +94,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(); if let Some(t_handle) = tiff::open("../test.tif") { 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<u8> { } buf } + +pub fn read(tiff_ptr: *mut TIFF) -> Vec<u8> { + let strip_size = get_strip_size(tiff_ptr); + let strip_count = get_strip_count(tiff_ptr); + let mut total_buf: Vec<u8> = vec![0u8; (strip_size * strip_count) as usize]; + for strip_index in 0..strip_count { + let sub_buffer: Vec<u8> = 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 +} |