blending stupidity
This commit is contained in:
parent
4cc5663070
commit
fbe4b57bb4
2 changed files with 81 additions and 20 deletions
|
@ -1,6 +1,7 @@
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::f64::consts::PI;
|
use std::f64::consts::PI;
|
||||||
use std::io::{BufWriter, Cursor, Read};
|
use std::io::{BufWriter, Cursor, Read};
|
||||||
|
use std::ops::{Add, Mul, Sub};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use actix_web::error::UrlencodedError::ContentType;
|
use actix_web::error::UrlencodedError::ContentType;
|
||||||
|
@ -97,9 +98,9 @@ pub async fn render(xtile: f64, ytile: f64, z: i32, tilesize: usize, pal: Palett
|
||||||
}).map(|u| u as f64);
|
}).map(|u| u as f64);
|
||||||
|
|
||||||
let color = match nearest {
|
let color = match nearest {
|
||||||
Some(c) if Some(c) == no_coverage => Color { red: 0, green: 0, blue: 0, alpha: 30 },
|
Some(c) if Some(c) == no_coverage => Color { red: 0, green: 0, blue: 0, alpha: 255 },
|
||||||
Some(c) if Some(c) == missing => Color { red: 0, green: 0, blue: 0, alpha: 0 },
|
Some(c) if Some(c) == missing => Color { red: 0, green: 0, blue: 0, alpha: 0 },
|
||||||
Some(c) if Some(c) == range_folded => Color { red: 141, green: 0, blue: 160, alpha: 0 },
|
Some(c) if Some(c) == range_folded => Color { red: 141, green: 0, blue: 160, alpha: 255 },
|
||||||
Some(value_at_pos) => {
|
Some(value_at_pos) => {
|
||||||
pal.colorize(value_at_pos)
|
pal.colorize(value_at_pos)
|
||||||
},
|
},
|
||||||
|
@ -126,30 +127,90 @@ fn coloru8(i: f64) -> u8 {
|
||||||
(i * u8::MAX as f64).floor() as u8
|
(i * u8::MAX as f64).floor() as u8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub struct ColorF64 {
|
||||||
|
pub red: f64,
|
||||||
|
pub green: f64,
|
||||||
|
pub blue: f64,
|
||||||
|
pub alpha: f64
|
||||||
|
}
|
||||||
|
impl From<Color> for ColorF64 {
|
||||||
|
fn from(value: Color) -> Self {
|
||||||
|
Self {
|
||||||
|
red: colorf64(value.red),
|
||||||
|
green: colorf64(value.green),
|
||||||
|
blue: colorf64(value.blue),
|
||||||
|
alpha: colorf64(value.alpha)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<ColorF64> for Color {
|
||||||
|
fn from(value: ColorF64) -> Self {
|
||||||
|
Self {
|
||||||
|
red: coloru8(value.red),
|
||||||
|
green: coloru8(value.green),
|
||||||
|
blue: coloru8(value.blue),
|
||||||
|
alpha: coloru8(value.alpha)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Add for ColorF64 {
|
||||||
|
type Output = ColorF64;
|
||||||
|
|
||||||
|
fn add(self, rhs: Self) -> Self::Output {
|
||||||
|
Self {
|
||||||
|
red: self.red + rhs.red,
|
||||||
|
green: self.green + rhs.green,
|
||||||
|
blue: self.blue + rhs.blue,
|
||||||
|
alpha: self.alpha + rhs.alpha
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Sub for ColorF64 {
|
||||||
|
type Output = ColorF64;
|
||||||
|
|
||||||
|
fn sub(self, rhs: Self) -> Self::Output {
|
||||||
|
Self {
|
||||||
|
red: self.red - rhs.red,
|
||||||
|
green: self.green - rhs.green,
|
||||||
|
blue: self.blue - rhs.blue,
|
||||||
|
alpha: self.alpha - rhs.alpha
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Mul for ColorF64 {
|
||||||
|
type Output = ColorF64;
|
||||||
|
|
||||||
|
fn mul(self, rhs: Self) -> Self::Output {
|
||||||
|
Self {
|
||||||
|
red: self.red * rhs.red,
|
||||||
|
green: self.green * rhs.green,
|
||||||
|
blue: self.blue * rhs.blue,
|
||||||
|
alpha: self.alpha * rhs.alpha
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn merge(base: Pixmap, data: Pixmap, settings: &TileRequestOptions) -> Pixmap {
|
pub fn merge(base: Pixmap, data: Pixmap, settings: &TileRequestOptions) -> Pixmap {
|
||||||
let mut new = Pixmap::new();
|
let mut new = Pixmap::new();
|
||||||
|
|
||||||
let a = settings.data_transparency;
|
|
||||||
|
|
||||||
for x in 0..256 {
|
for x in 0..256 {
|
||||||
for y in 0..256 {
|
for y in 0..256 {
|
||||||
let lower = base.get(x, y);
|
let mut lower: ColorF64 = base.get(x, y).into();
|
||||||
let upper = data.get(x, y);
|
lower.alpha = 1.0;
|
||||||
|
let mut upper: ColorF64 = data.get(x, y).into();
|
||||||
|
//upper.alpha = settings.data_transparency;
|
||||||
|
|
||||||
let lr = colorf64(lower.red);
|
if upper.red == 0.0 && upper.green == 0.0 && upper.blue == 0.0 && upper.alpha == 0.0 {
|
||||||
let lg = colorf64(lower.green);
|
lower.alpha = 1.0;
|
||||||
let lb = colorf64(lower.blue);
|
new.set(x, y, lower.into());
|
||||||
|
} else {
|
||||||
|
upper.alpha = 1.0;
|
||||||
|
new.set(x, y, upper.into());
|
||||||
|
}
|
||||||
|
|
||||||
let ur = colorf64(upper.red);
|
// new.set(x, y, ((ColorF64 { red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0 } - ColorF64 { red: 2.0, green: 2.0, blue: 2.0, alpha: 2.0 } * upper) * (lower * lower) + ColorF64 { red: 2.0, green: 2.0, blue: 2.0, alpha: 2.0 } * lower * upper).into());
|
||||||
let ug = colorf64(upper.green);
|
|
||||||
let ub = colorf64(upper.blue);
|
|
||||||
|
|
||||||
new.set(x, y, Color {
|
|
||||||
red: coloru8(lr - (lr - ur) * a),
|
|
||||||
green: coloru8(lg - (lg - ug) * a),
|
|
||||||
blue: coloru8(lb - (lb - ub) * a),
|
|
||||||
alpha: 255
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ impl WxboxApp {
|
||||||
baselayer: "osm".to_string(),
|
baselayer: "osm".to_string(),
|
||||||
|
|
||||||
data: "grib2/noaa_mrms_merged_composite_reflectivity_qc".to_string(),
|
data: "grib2/noaa_mrms_merged_composite_reflectivity_qc".to_string(),
|
||||||
data_transparency: 0.5,
|
data_transparency: 0.9,
|
||||||
}),
|
}),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
ctx.clone()
|
ctx.clone()
|
||||||
|
|
Loading…
Reference in a new issue