add hsv to rgb, not better looking
This commit is contained in:
parent
831322e44a
commit
ca742aa204
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -2979,6 +2979,12 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "216080ab382b992234dda86873c18d4c48358f5cfcb70fd693d7f6f2131b628b"
|
checksum = "216080ab382b992234dda86873c18d4c48358f5cfcb70fd693d7f6f2131b628b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rgb_hsv"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fec0123e8720dcbc31a22f3ecb7dc5cb41f4b73e361eca37d4acf0b04f572589"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.23"
|
version = "0.1.23"
|
||||||
|
@ -3366,6 +3372,7 @@ dependencies = [
|
||||||
"pcap-parser",
|
"pcap-parser",
|
||||||
"png",
|
"png",
|
||||||
"pyo3",
|
"pyo3",
|
||||||
|
"rgb_hsv",
|
||||||
"serde",
|
"serde",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
|
|
@ -19,6 +19,7 @@ pcap = { version = "1.2.0", features = ["capture-stream"] }
|
||||||
pcap-parser = { version = "0.14.1", features = ["data"] }
|
pcap-parser = { version = "0.14.1", features = ["data"] }
|
||||||
png = "0.17.10"
|
png = "0.17.10"
|
||||||
pyo3 = { version = "0.20.0", "features" = ["extension-module"] }
|
pyo3 = { version = "0.20.0", "features" = ["extension-module"] }
|
||||||
|
rgb_hsv = "1.0.1"
|
||||||
serde = { version = "1.0.193", features = ["derive", "serde_derive", "alloc"] }
|
serde = { version = "1.0.193", features = ["derive", "serde_derive", "alloc"] }
|
||||||
tokio = { version = "1.36.0", features = ["full"] }
|
tokio = { version = "1.36.0", features = ["full"] }
|
||||||
tracing-subscriber = "0.3.18"
|
tracing-subscriber = "0.3.18"
|
||||||
|
|
|
@ -26,6 +26,18 @@ fn pixel_to_celcius(x: u16) -> u16 {
|
||||||
(t * 256.0) as 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<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
@ -121,12 +133,13 @@ fn main() -> anyhow::Result<()> {
|
||||||
let cutoff = args.red_cutoff.unwrap();
|
let cutoff = args.red_cutoff.unwrap();
|
||||||
let (r, g, b) = if pixel > (256.0 * cutoff) as u16 {
|
let (r, g, b) = if pixel > (256.0 * cutoff) as u16 {
|
||||||
let p = pixel - (256.0 * cutoff) as u16;
|
let p = pixel - (256.0 * cutoff) as u16;
|
||||||
let p = (p / 256).max(127);
|
let (r, g, b) = rgb_hsv::hsv_to_rgb((0.0, p as f32, 0.0));
|
||||||
((128 + p) as u8, 0, 0)
|
(r as u8, g as u8, b as u8)
|
||||||
} else {
|
} else {
|
||||||
let g = frame[i * 2];
|
let h = frame[i * 2] as f32;
|
||||||
let b = frame[i * 2 + 1];
|
let v = frame[i * 2 + 1] as f32;
|
||||||
(0, g, b)
|
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;
|
let out_i = ((HEIGHT - 1 - y) + (WIDTH - 1 - x) * HEIGHT) * 4;
|
||||||
swapped[out_i..out_i + 4].copy_from_slice(&[0, r, g, b]);
|
swapped[out_i..out_i + 4].copy_from_slice(&[0, r, g, b]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user