diff options
author | cc <cc@localhost> | 2025-08-20 18:17:32 -0700 |
---|---|---|
committer | cc <cc@localhost> | 2025-08-20 18:17:37 -0700 |
commit | 03d5bfae04eef01142436d098fe51c6dafeda39c (patch) | |
tree | 745f2ad9882e9115e6307f1de65a33b69203fb3d /src/tiff.rs | |
parent | b54ea6a51b16642dc59b2d2ba4d747cf683ec418 (diff) |
Capture Status Result
Diffstat (limited to 'src/tiff.rs')
-rw-r--r-- | src/tiff.rs | 22 |
1 files changed, 16 insertions, 6 deletions
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<usize> { 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<usize> { 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); } |