From 03d5bfae04eef01142436d098fe51c6dafeda39c Mon Sep 17 00:00:00 2001 From: cc Date: Wed, 20 Aug 2025 18:17:32 -0700 Subject: Capture Status Result --- src/tiff.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/tiff.rs') diff --git a/src/tiff.rs b/src/tiff.rs index 6d14e81..b9bdad5 100644 --- a/src/tiff.rs +++ b/src/tiff.rs @@ -60,28 +60,38 @@ pub fn close(tiff_ptr: *mut TIFF) { } } -pub fn get_image_width(tiff_ptr: *mut TIFF) -> usize { +pub fn get_image_width(tiff_ptr: *mut TIFF) -> Option { let mut width: u32 = 0; unsafe { let status = TIFFGetField(tiff_ptr, TIFFTAG_IMAGEWIDTH, &mut width as *mut u32); + if status < 0 { + return None; + } else { + return Some(width as usize); + } } - return width as usize; } -pub fn get_image_height(tiff_ptr: *mut TIFF) -> usize { +pub fn get_image_height(tiff_ptr: *mut TIFF) -> Option { let mut height: u32 = 0; unsafe { let status = TIFFGetField(tiff_ptr, TIFFTAG_IMAGEHEIGHT, &mut height as *mut u32); + if status < 0 { + return None; + } else { + return Some(height as usize); + } } - return height as usize; } 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); + let width = get_image_width(tiff_ptr) + .expect("Image should have width!"); + let height = get_image_height(tiff_ptr) + .expect("Image should have height!"); return (strip_size * strip_count) / (width * height); } -- cgit v1.2.1