feat: generate RGB(A) image based on intensity

This commit is contained in:
Luca 2025-06-05 00:20:56 +02:00
parent c79c471415
commit 60ea19f2c4
1 changed files with 27 additions and 9 deletions

View File

@ -3,7 +3,7 @@ mod data;
use data::Rv; use data::Rv;
use image::imageops; use image::imageops;
use image::GrayAlphaImage; use image::RgbaImage;
use proj::Proj; use proj::Proj;
@ -12,23 +12,41 @@ use std::io::BufReader;
const PROJ_WGS84_DE1200: &'static str = "+proj=stere +lat_0=90 +lat_ts=60 +lon_0=10 +a=6378137 +b=6356752.3142451802 +no_defs +x_0=543196.83521776402 +y_0=3622588.8619310018"; const PROJ_WGS84_DE1200: &'static str = "+proj=stere +lat_0=90 +lat_ts=60 +lon_0=10 +a=6378137 +b=6356752.3142451802 +no_defs +x_0=543196.83521776402 +y_0=3622588.8619310018";
#[repr(u32)]
enum Intensity {
None = 0xffffff00,
Light = 0x80d0d080,
Moderate = 0x50a0e080,
Heavy = 0x1030f080,
Unknown = 0xd0d0d080,
}
fn main() { fn main() {
let rv = Rv::parse(BufReader::new(File::open("input").unwrap())).unwrap(); let rv = Rv::parse(BufReader::new(File::open("input").unwrap())).unwrap();
rv.expect_version(5).unwrap(); rv.expect_version(5).unwrap();
let mut data = Vec::with_capacity(1100 * 1200 * 2); let mut data = Vec::with_capacity(1100 * 1200 * 4);
for v in rv.data() { for v in rv.data() {
if *v == 0x29c4 { let intensity = if *v == 0x29c4 {
data.push(0); Intensity::Unknown
data.push(255);
} else { } else {
data.push(if *v > 0 { 255 } else { 127 }); let mm_per_h = *v as f64 * rv.scale() * 12.0; // 12 * 5 min intervals per hour
data.push(255); if mm_per_h < 0.1 {
Intensity::None
} else if mm_per_h < 5.0 {
Intensity::Light
} else if mm_per_h < 15.0 {
Intensity::Moderate
} else {
Intensity::Heavy
} }
};
data.extend_from_slice(&(intensity as u32).to_be_bytes());
} }
let mut img = GrayAlphaImage::from_raw(1100, 1200, data).unwrap(); let mut img = RgbaImage::from_raw(1100, 1200, data).unwrap();
imageops::flip_vertical_in_place(&mut img); imageops::flip_vertical_in_place(&mut img);
img.save("rv.png").unwrap(); img.save("rv.png").unwrap();