diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | src/tiff.rs | 22 |
2 files changed, 18 insertions, 8 deletions
@@ -31,7 +31,7 @@ mod tests { fn tiff_width_test() { tiff::ignore_warnings(); if let Some(t_handle) = tiff::open(TEST_IMAGE_PATH) { - let width = tiff::get_image_width(t_handle); + let width = tiff::get_image_width(t_handle).expect("Image should have width!"); assert!(width > 0); tiff::close(t_handle); } else { @@ -43,7 +43,7 @@ mod tests { fn tiff_height_test() { tiff::ignore_warnings(); if let Some(t_handle) = tiff::open(TEST_IMAGE_PATH) { - let height = tiff::get_image_height(t_handle); + let height = tiff::get_image_height(t_handle).expect("Image should have height!"); assert!(height > 0); tiff::close(t_handle); } else { 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); } |