summaryrefslogtreecommitdiff
path: root/src/tiff.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tiff.rs')
-rw-r--r--src/tiff.rs22
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);
}