aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 46c7cd61ef05f953e8994b02cd07148399699337 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
mod large_label_format;
mod label_format;
pub mod binfile;

pub use large_label_format::LargeLabelFormat;
pub use label_format::LabelFormat;

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;
    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_u32(source, destination, x-1, y, from_color, to_color);
    }
    if (x+1) < width {
        flood_u32(source, destination, x+1, y, from_color, to_color);
    }
    if y > 0 {
        flood_u32(source, destination, x, y-1, from_color, to_color);
    }
    if (y+1) < source.height {
        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);
    }
}