28 lines
783 B
Rust
28 lines
783 B
Rust
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) }
|
|
}
|