Add sRGB <-> linear color conversion utilities and precomputed LUT generation.
This commit is contained in:
1 parent
2833f1e1a8
commit
b39daa61c2
4 files changed
+60
No files matched your search
@@ -0,0 +1,27 @@
|
||||
use std::{
|
||||
env, fs,
|
||||
path::Path
|
||||
};
|
||||
|
||||
/// Writes the sRGB → linear table for every `u8` channel value to `OUT_DIR`,
|
||||
/// so `color::transfer` can include it as a plain array.
|
||||
fn main()
|
||||
{
|
||||
println!("cargo::rerun-if-changed=NULL");
|
||||
|
||||
// `{:?}` prints the shortest literal that parses back to the exact same f32.
|
||||
let values: Vec<String> = (0..=255u8).map(
|
||||
|c| format!("{:?}", srgb_to_linear(c as f32 / 255.0))
|
||||
).collect();
|
||||
|
||||
let table = format!("[{}]", values.join(", "));
|
||||
let out = Path::new(&env::var_os("OUT_DIR").unwrap()).join("srgb_lut.rs");
|
||||
|
||||
fs::write(out, table).unwrap();
|
||||
}
|
||||
|
||||
/// A copy of `color::transfer::srgb_to_linear`.
|
||||
fn srgb_to_linear(c: f32) -> f32
|
||||
{
|
||||
if c <= 0.04045 { c / 12.92 } else { ((c + 0.055) / 1.055).powf(2.4) }
|
||||
}
|
||||
Reference in new issue
Block a user