diff options
Diffstat (limited to 'src/tiff.rs')
-rw-r--r-- | src/tiff.rs | 31 |
1 files changed, 31 insertions, 0 deletions
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; +} |