From 27d77b602e2d43a8bab413d69b86c38e53435a8e Mon Sep 17 00:00:00 2001 From: cc Date: Wed, 20 Aug 2025 18:23:35 -0700 Subject: Add standardization of mask Update project name to more specific one --- src/tiff.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/tiff.rs') 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> { + 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; +} -- cgit v1.2.1