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
use crate::utils::{ bbox_from_cidr, BoundingBox };
use ril::{Rectangle, Image, L, Rgba};
pub fn mask_cidrs<S>(img: &mut Image<Rgba>, masks: Option<S>) where S: Into<String>, {
if let Some(masks) = masks {
let masks = masks.into();
let cidrs: Vec<BoundingBox> = masks.split(',').map(bbox_from_cidr).collect();
let mut img_mask = Image::new(4096, 4096, L(255));
for cidr in cidrs {
let rect = Rectangle::new()
.with_position(cidr.x() as u32, cidr.y() as u32)
.with_size(cidr.width() as u32, cidr.height() as u32)
.with_fill(L(0));
img_mask.draw(&rect);
img.mask_alpha(&img_mask);
}
img_mask.invert();
img.mask_alpha(&img_mask);
}
}