summaryrefslogtreecommitdiff
path: root/src/tiff.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tiff.rs')
-rw-r--r--src/tiff.rs74
1 files changed, 3 insertions, 71 deletions
diff --git a/src/tiff.rs b/src/tiff.rs
index 2baba80..67d4aec 100644
--- a/src/tiff.rs
+++ b/src/tiff.rs
@@ -1,26 +1,8 @@
use std::os::raw::{c_char, c_uint, c_void, c_longlong, c_long};
use std::ffi::CString;
-pub struct StandardOutput {
- pub buffer: Vec<u32>,
- pub width: usize,
- pub height: usize,
-}
-
-pub struct CompressedOutput {
- pub buffer: Vec<u16>,
- pub width: usize,
- pub height: usize,
-}
+use crate::label_formats::LargeLabelFormat;
-impl std::fmt::Debug for StandardOutput {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- f.debug_struct("StandardOutput")
- .field("width", &self.width)
- .field("height", &self.height)
- .finish()
- }
-}
/// # TIFF Internal Structure
/// An opaque type
@@ -154,7 +136,7 @@ pub fn read(tiff_ptr: *mut TIFF) -> Vec<u8> {
total_buf
}
-pub fn as_standard_format(tiff_file_name: &str) -> Option<StandardOutput> {
+pub fn to_large_labels(tiff_file_name: &str) -> Option<LargeLabelFormat> {
if let Some(tiff) = open(tiff_file_name) {
let width_opt = get_image_width(tiff);
let height_opt = get_image_height(tiff);
@@ -183,7 +165,7 @@ pub fn as_standard_format(tiff_file_name: &str) -> Option<StandardOutput> {
}
}
close(tiff);
- return Some(StandardOutput {
+ return Some(LargeLabelFormat {
buffer: standard_buffer,
width,
height,
@@ -193,56 +175,6 @@ pub fn as_standard_format(tiff_file_name: &str) -> Option<StandardOutput> {
return None;
}
-fn flood(source: &StandardOutput, destination: &mut Vec<u16>,
- x: usize, y: usize,
- from_color: u32, to_color: u16) {
- let width = source.width;
- let destination_color = destination[x + y * width];
- if destination_color != 0 {
- return;
- }
- let source_color = source.buffer[x + y * width];
- if source_color != from_color {
- return;
- }
- destination[x + y * width] = to_color;
- if x > 0 {
- flood(source, destination, x-1, y, from_color, to_color);
- }
- if (x+1) < width {
- flood(source, destination, x+1, y, from_color, to_color);
- }
- if y > 0 {
- flood(source, destination, x, y-1, from_color, to_color);
- }
- if (y+1) < source.height {
- flood(source, destination, x, y+1, from_color, to_color);
- }
-}
-
-pub fn standard_to_labels(buffer: StandardOutput) -> CompressedOutput {
- let mut label: u16 = 1;
- let mut output_buffer: Vec<u16> = vec![0u16; buffer.buffer.len()];
- for y in 0..buffer.height {
- for x in 0..buffer.width {
- let index = x + y*buffer.width;
- if buffer.buffer[index] == 0 {
- continue;
- }
- if output_buffer[index] == 0 {
- let color = buffer.buffer[index];
- flood(&buffer, &mut output_buffer, x, y, color, label);
- label += 1;
- }
- }
- }
- return CompressedOutput {
- buffer: output_buffer,
- width: buffer.width,
- height: buffer.height,
- };
-}
-
#[cfg(test)]
mod tests {
use super::*;