From c8190c1a8931749ff6408a39d791ba99fc0266eb Mon Sep 17 00:00:00 2001 From: cc Date: Wed, 20 Aug 2025 18:08:40 -0700 Subject: Modularize Private Tests --- src/tiff.rs | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 10 deletions(-) (limited to 'src/tiff.rs') diff --git a/src/tiff.rs b/src/tiff.rs index 8e77233..53b8de9 100644 --- a/src/tiff.rs +++ b/src/tiff.rs @@ -60,40 +60,49 @@ pub fn close(tiff_ptr: *mut TIFF) { } } -pub fn get_width(tiff_ptr: *mut TIFF) -> u32 { +pub fn get_image_width(tiff_ptr: *mut TIFF) -> usize { let mut width: u32 = 0; unsafe { let status = TIFFGetField(tiff_ptr, TIFFTAG_IMAGEWIDTH, &mut width as *mut u32); } - return width; + return width as usize; } -pub fn get_height(tiff_ptr: *mut TIFF) -> u32 { +pub fn get_image_height(tiff_ptr: *mut TIFF) -> usize { let mut height: u32 = 0; unsafe { let status = TIFFGetField(tiff_ptr, TIFFTAG_IMAGEHEIGHT, &mut height as *mut u32); } - return height; + return height as usize; } -pub fn get_strip_size(tiff_ptr: *mut TIFF) -> i64 { + +pub fn get_image_channels(tiff_ptr: *mut TIFF) -> usize { + let strip_size = get_strip_size(tiff_ptr); + let strip_count = get_strip_count(tiff_ptr); + let width = get_image_width(tiff_ptr); + let height = get_image_height(tiff_ptr); + return (strip_size * strip_count) / (width * height); +} + +fn get_strip_size(tiff_ptr: *mut TIFF) -> usize { unsafe { - TIFFStripSize(tiff_ptr) + TIFFStripSize(tiff_ptr) as usize } } -pub fn get_strip_count(tiff_ptr: *mut TIFF) -> i64 { +fn get_strip_count(tiff_ptr: *mut TIFF) -> usize { unsafe { - TIFFNumberOfStrips(tiff_ptr) + TIFFNumberOfStrips(tiff_ptr) as usize } } -pub fn read_strip(tiff_ptr: *mut TIFF, strip: u32) -> Vec { +fn read_strip(tiff_ptr: *mut TIFF, strip: u32) -> Vec { let strip_size = get_strip_size(tiff_ptr); assert!(strip_size>0); let mut buf: Vec = vec![0u8; strip_size as usize]; unsafe { - TIFFReadRawStrip(tiff_ptr, strip, buf.as_mut_ptr() as *mut c_void, strip_size); + TIFFReadRawStrip(tiff_ptr, strip, buf.as_mut_ptr() as *mut c_void, strip_size as c_longlong); } buf } @@ -113,3 +122,63 @@ pub fn read(tiff_ptr: *mut TIFF) -> Vec { } total_buf } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn tiff_strip_size() { + ignore_warnings(); + if let Some(t_handle) = open(crate::TEST_IMAGE_PATH) { + let strip_size = get_strip_size(t_handle); + assert!(strip_size > 0); + close(t_handle); + } else { + assert!(false); + } + } + + #[test] + fn tiff_strip_count() { + ignore_warnings(); + if let Some(t_handle) = open(crate::TEST_IMAGE_PATH) { + let strip_count = get_strip_count(t_handle); + assert!(strip_count > 0); + close(t_handle); + } else { + assert!(false); + } + } + + #[test] + fn tiff_strip_read() { + ignore_warnings(); + if let Some(t_handle) = open(crate::TEST_IMAGE_PATH) { + let strip = read_strip(t_handle, 0); + close(t_handle); + } else { + assert!(false); + } + } + + #[test] + fn tiff_data_depth() { + ignore_warnings(); + if let Some(t_handle) = open(crate::TEST_IMAGE_PATH) { + let strip_size = get_strip_size(t_handle); + let strip_count = get_strip_count(t_handle); + let strip_depth = strip_size * strip_count; + assert!(strip_depth > 0); + let image_width = get_image_width(t_handle); + let image_height = get_image_height(t_handle); + let image_depth = image_width * image_height; + assert!(image_depth > 0); + let strip_depth = strip_depth as f64; + let image_depth = image_depth as f64; + close(t_handle); + } else { + assert!(false); + } + } +} -- cgit v1.2.1