diff options
author | cc <cc@localhost> | 2025-08-20 22:14:13 -0700 |
---|---|---|
committer | cc <cc@localhost> | 2025-08-20 22:19:01 -0700 |
commit | 15df0fec1e368599487e1faeaf8ecebd87980781 (patch) | |
tree | 94c9aba0cf1ba340e77b0c773e6869035ad9c8aa /src/large_label_format.rs |
Initial commit
Diffstat (limited to 'src/large_label_format.rs')
-rw-r--r-- | src/large_label_format.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/large_label_format.rs b/src/large_label_format.rs new file mode 100644 index 0000000..5aef6b3 --- /dev/null +++ b/src/large_label_format.rs @@ -0,0 +1,45 @@ +use crate::{LabelFormat,flood}; + +pub struct LargeLabelFormat { + pub buffer: Vec<u32>, + pub width: usize, + pub height: usize, +} + +impl std::fmt::Debug for LargeLabelFormat { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("LargeLabelFormat") + .field("width", &self.width) + .field("height", &self.height) + .finish() + } +} + +impl LargeLabelFormat { + pub fn compress(&self) -> LabelFormat { + let mut label: u16 = 1; + let mut output_buffer: Vec<u16> = vec![0u16; self.buffer.len()]; + for y in 0..self.height { + for x in 0..self.width { + let index = x + y*self.width; + if self.buffer[index] == 0 { + continue; + } + if output_buffer[index] == 0 { + let color = self.buffer[index]; + flood(&self, &mut output_buffer, x, y, color, label); + label += 1; + } + } + } + return LabelFormat { + buffer: output_buffer, + width: self.width, + height: self.height, + }; + } + + pub fn dump(&self, filename: &str) -> Result<(), std::io::Error> { + crate::binfile::dump_u32_vec(filename, self.buffer.clone()) + } +} |