summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcc <cc@localhost>2025-08-20 19:08:40 -0700
committercc <cc@localhost>2025-08-20 19:08:40 -0700
commitab88d233dcb23a56cb76929a2c804a8dd4198c13 (patch)
tree3bf41c61b1949e98df633e3a397ce2cc4a1bcb3e /src
parent7da0f116c0b3bb50157d2aa028906eb923c57b2a (diff)
Reordering functions
Diffstat (limited to 'src')
-rw-r--r--src/tiff.rs62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/tiff.rs b/src/tiff.rs
index 11755b6..34430ab 100644
--- a/src/tiff.rs
+++ b/src/tiff.rs
@@ -133,6 +133,37 @@ pub fn read(tiff_ptr: *mut TIFF) -> Vec<u8> {
total_buf
}
+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) || (height_opt == None) {
+ return None;
+ }
+ if (channels == 0) || (channels > 4) {
+ 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;
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -172,34 +203,3 @@ 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) || (height_opt == None) {
- return None;
- }
- if (channels == 0) || (channels > 4) {
- 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;
-}