aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorcc <cc@localhost>2025-08-20 22:43:06 -0700
committercc <cc@localhost>2025-08-20 22:50:10 -0700
commit68103ad891520db55d8f84a8f938a37aca4f29d4 (patch)
treeb46836b3c1e6dee4bee9ff86aa16f3790766eb71 /src/lib.rs
parent15df0fec1e368599487e1faeaf8ecebd87980781 (diff)
Label Combination Routine
Label Refresh Routine
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index e47bca8..46c7cd6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,7 +5,7 @@ pub mod binfile;
pub use large_label_format::LargeLabelFormat;
pub use label_format::LabelFormat;
-pub(crate) fn flood(source: &LargeLabelFormat, destination: &mut Vec<u16>,
+pub(crate) fn flood_u32(source: &LargeLabelFormat, destination: &mut Vec<u16>,
x: usize, y: usize,
from_color: u32, to_color: u16) {
let width = source.width;
@@ -19,15 +19,42 @@ pub(crate) fn flood(source: &LargeLabelFormat, destination: &mut Vec<u16>,
}
destination[x + y * width] = to_color;
if x > 0 {
- flood(source, destination, x-1, y, from_color, to_color);
+ flood_u32(source, destination, x-1, y, from_color, to_color);
}
if (x+1) < width {
- flood(source, destination, x+1, y, from_color, to_color);
+ flood_u32(source, destination, x+1, y, from_color, to_color);
}
if y > 0 {
- flood(source, destination, x, y-1, from_color, to_color);
+ flood_u32(source, destination, x, y-1, from_color, to_color);
}
if (y+1) < source.height {
- flood(source, destination, x, y+1, from_color, to_color);
+ flood_u32(source, destination, x, y+1, from_color, to_color);
+ }
+}
+
+pub(crate) fn flood_u16(source: &LabelFormat, destination: &mut Vec<u16>,
+ x: usize, y: usize,
+ from_color: u16, 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_u16(source, destination, x-1, y, from_color, to_color);
+ }
+ if (x+1) < width {
+ flood_u16(source, destination, x+1, y, from_color, to_color);
+ }
+ if y > 0 {
+ flood_u16(source, destination, x, y-1, from_color, to_color);
+ }
+ if (y+1) < source.height {
+ flood_u16(source, destination, x, y+1, from_color, to_color);
}
}