add hsv to rgb, not better looking

This commit is contained in:
devdesk
2024-02-22 23:08:30 +02:00
parent 831322e44a
commit ca742aa204
3 changed files with 26 additions and 5 deletions

View File

@@ -26,6 +26,18 @@ fn pixel_to_celcius(x: u16) -> u16 {
(t * 256.0) as u16
}
/// https://en.wikipedia.org/wiki/HSL_and_HSV
/// convert to the expected dynamic range first. We insert values in [0..256)
/// h in [0, 360] degrees
/// s in [0, 1]
/// v in [0, 1]
fn once_upon_a_time_hsv2rgb(h: u8, s: u8, v: u8) -> (u8, u8, u8) {
let h = (h as f64) / 256.0 * 360.0;
let s = (s as f64) / 256.0;
let v = (v as f64) / 256.0;
(0, 0, 0)
}
fn main() -> anyhow::Result<()> {
let args = Args::parse();
dotenv().ok();
@@ -121,12 +133,13 @@ fn main() -> anyhow::Result<()> {
let cutoff = args.red_cutoff.unwrap();
let (r, g, b) = if pixel > (256.0 * cutoff) as u16 {
let p = pixel - (256.0 * cutoff) as u16;
let p = (p / 256).max(127);
((128 + p) as u8, 0, 0)
let (r, g, b) = rgb_hsv::hsv_to_rgb((0.0, p as f32, 0.0));
(r as u8, g as u8, b as u8)
} else {
let g = frame[i * 2];
let b = frame[i * 2 + 1];
(0, g, b)
let h = frame[i * 2] as f32;
let v = frame[i * 2 + 1] as f32;
let (r, g, b) = rgb_hsv::hsv_to_rgb((h, 0.0, v));
(r as u8, g as u8, b as u8)
};
let out_i = ((HEIGHT - 1 - y) + (WIDTH - 1 - x) * HEIGHT) * 4;
swapped[out_i..out_i + 4].copy_from_slice(&[0, r, g, b]);