summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcc <cc@localhost>2025-08-20 21:01:36 -0700
committercc <cc@localhost>2025-08-20 21:01:36 -0700
commitb903f5a5e9250691bab6644200b244a0da961219 (patch)
tree5b5a84fb42e085a8646bf1443663cedc71a586a5 /src
parente85e125626fdc6d847bf07224577460e03879016 (diff)
Move flood fill
Make it crate-available
Diffstat (limited to 'src')
-rw-r--r--src/label_formats/large_label_format.rs29
-rw-r--r--src/label_formats/mod.rs28
2 files changed, 29 insertions, 28 deletions
diff --git a/src/label_formats/large_label_format.rs b/src/label_formats/large_label_format.rs
index 244c7d3..6ad19b3 100644
--- a/src/label_formats/large_label_format.rs
+++ b/src/label_formats/large_label_format.rs
@@ -1,4 +1,4 @@
-use super::LabelFormat;
+use super::{LabelFormat,flood};
pub struct LargeLabelFormat {
pub buffer: Vec<u32>,
@@ -15,33 +15,6 @@ impl std::fmt::Debug for LargeLabelFormat {
}
}
-fn flood(source: &LargeLabelFormat, 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);
- }
-}
-
impl LargeLabelFormat {
pub fn compress(&self) -> LabelFormat {
let mut label: u16 = 1;
diff --git a/src/label_formats/mod.rs b/src/label_formats/mod.rs
index 1e3e4ae..b48486a 100644
--- a/src/label_formats/mod.rs
+++ b/src/label_formats/mod.rs
@@ -3,3 +3,31 @@ mod label_format;
pub use large_label_format::LargeLabelFormat;
pub use label_format::LabelFormat;
+
+pub(crate) fn flood(source: &LargeLabelFormat, 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);
+ }
+}
+