diff options
author | cc <cc@localhost> | 2025-08-20 18:23:35 -0700 |
---|---|---|
committer | cc <cc@localhost> | 2025-08-20 18:50:49 -0700 |
commit | 27d77b602e2d43a8bab413d69b86c38e53435a8e (patch) | |
tree | 98baf568c9ec75b5197776e8f4aa5eddc1fa8740 | |
parent | cee14c71e3eaf36d948738c555f5806dbc8ca567 (diff) |
Add standardization of mask
Update project name to more specific one
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | src/lib.rs | 19 | ||||
-rw-r--r-- | src/tiff.rs | 31 |
3 files changed, 50 insertions, 2 deletions
@@ -3,5 +3,5 @@ version = 4 [[package]] -name = "r_lib" +name = "simple_tiff_binding" version = "0.0.1" @@ -1,6 +1,7 @@ pub mod tiff; pub const TEST_IMAGE_PATH: &str = "../test.tif"; +pub const TEST_OUTPUT_PATH: &str = "../test.bin"; #[cfg(test)] mod tests { @@ -64,7 +65,7 @@ mod tests { } #[test] - fn tiff_read() { + fn tiff_read_test() { tiff::ignore_warnings(); if let Some(t_handle) = tiff::open(TEST_IMAGE_PATH) { let _data = tiff::read(t_handle); @@ -73,4 +74,20 @@ mod tests { assert!(false); } } + + #[test] + fn tiff_data_dump_test() { + use std::fs::File; + use std::io::Write; + tiff::ignore_warnings(); + if let Some(standard_format) = tiff::as_standard_format(TEST_IMAGE_PATH) { + if let Ok(mut file) = File::create(TEST_OUTPUT_PATH) { + for value in standard_format { + let _ = file.write_all(&value.to_le_bytes()); + } + } + } else { + assert!(false); + } + } } diff --git a/src/tiff.rs b/src/tiff.rs index b9bdad5..f23e978 100644 --- a/src/tiff.rs +++ b/src/tiff.rs @@ -172,3 +172,34 @@ mod tests { } } } + +pub fn as_standard_format(tiff_file_name: &str) -> Option<Vec<u32>> { + if let Some(tiff) = open(tiff_file_name) { + let width_opt = get_image_width(tiff); + let height_opt = get_image_height(tiff); + let channels = get_image_channels(tiff); + if width_opt == None { + return None; + } + if height_opt == None { + return None; + } + let width = width_opt.expect("Width Prechecked"); + let height = height_opt.expect("Height Prechecked"); + let mut standard_buffer = vec![0u32; (width*height) as usize]; + let tiff_data = read(tiff); + for x in 0..width { + for y in 0..height { + for c in 0..channels { + let data: u8 = tiff_data[c + channels * (x + width * y)]; + let data: u32 = (data << (8 * c)) as u32; + standard_buffer[x + width*y] += data; + } + } + } + close(tiff); + return Some(standard_buffer); + } + // Otherwise + return None; +} |