summaryrefslogtreecommitdiff
path: root/src/tiff.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tiff.rs')
-rw-r--r--src/tiff.rs89
1 files changed, 79 insertions, 10 deletions
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<u8> {
+fn read_strip(tiff_ptr: *mut TIFF, strip: u32) -> Vec<u8> {
let strip_size = get_strip_size(tiff_ptr);
assert!(strip_size>0);
let mut buf: Vec<u8> = 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<u8> {
}
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);
+ }
+ }
+}