diff options
author | cc <cc@localhost> | 2025-08-20 20:31:50 -0700 |
---|---|---|
committer | cc <cc@localhost> | 2025-08-20 20:31:50 -0700 |
commit | bf8287a0a663048aeff2aaf079202b96cc9e0721 (patch) | |
tree | 4762c061784a7c9affa198554df54d76f469cfcf /src/label_formats/large_label_format.rs | |
parent | d459729f67e4a83ce361dcf2bc6d5d75f427e23d (diff) |
Add dilation funcitonality to compressed representation
Diffstat (limited to 'src/label_formats/large_label_format.rs')
-rw-r--r-- | src/label_formats/large_label_format.rs | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/label_formats/large_label_format.rs b/src/label_formats/large_label_format.rs index f717ac5..244c7d3 100644 --- a/src/label_formats/large_label_format.rs +++ b/src/label_formats/large_label_format.rs @@ -42,25 +42,27 @@ fn flood(source: &LargeLabelFormat, destination: &mut Vec<u16>, } } -pub fn compress_large_labels(largelabels: LargeLabelFormat) -> LabelFormat { - let mut label: u16 = 1; - let mut output_buffer: Vec<u16> = vec![0u16; largelabels.buffer.len()]; - for y in 0..largelabels.height { - for x in 0..largelabels.width { - let index = x + y*largelabels.width; - if largelabels.buffer[index] == 0 { - continue; - } - if output_buffer[index] == 0 { - let color = largelabels.buffer[index]; - flood(&largelabels, &mut output_buffer, x, y, color, label); - label += 1; +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, + }; } - return LabelFormat { - buffer: output_buffer, - width: largelabels.width, - height: largelabels.height, - }; } |