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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
mod annotations;
pub mod utils;
mod fonts;
mod colors;
mod heatmap;
mod shades;
mod outlines;
mod labels;
mod prefixes;
mod crop;
mod mask;
use crate::annotations::AnnotationCollection;
use crate::colors::{WHITE, BLACK};
use clap::Parser;
use ril::{Image};
use anyhow::{Result, anyhow};
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
#[clap(short, long, default_value_t = String::from("cividis"))]
palette: String,
#[clap(short, long)]
invert: bool,
#[clap(short, long)]
reverse: bool,
#[clap(short, long, default_value_t = String::from("ips.txt"))]
filename: String,
#[clap(short, long, default_value_t = String::from("map.png"))]
output: String,
#[clap(short, long)]
annotations: Option<String>,
#[clap(short, long)]
legend_file: Option<String>,
#[clap(short, long)]
crop: Option<String>,
#[clap(short, long)]
mask: Option<String>,
}
fn main() -> Result<()> {
let args = Args::parse();
let mut img = Image::new(4096, 4096, if args.reverse { WHITE } else { BLACK });
heatmap::render_heatmap(&mut img, args.filename, args.palette.to_owned(), args.invert)?;
if let Some(annotations) = args.annotations {
let ann: AnnotationCollection = annotations::load_config(annotations)?;
shades::shade_cidrs(&mut img, ann.shades)?;
outlines::outline_cidrs(&mut img, ann.outlines)?;
labels::annotate_cidrs(&mut img, ann.labels)?;
prefixes::annotate_prefixes(&mut img, ann.prefixes)?;
}
mask::mask_cidrs(&mut img, args.mask);
crop::crop_cidrs(&mut img, args.crop);
match img.save_inferred(args.output) {
Ok(_) => utils::output_legend(args.legend_file, &args.palette, args.invert)?,
Err(e) => return Err(anyhow!("Error saving heatmap image file: {e}."))
}
Ok(())
}