-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.rs
51 lines (46 loc) · 1.36 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// build.rs Create look-up tables
//
// Copyright (c) 2020-2023 Douglas P Lau
//
use std::env;
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::Path;
include!("src/srgb_gamma.rs");
/// Create sRGB gamma look-up tables
fn gamma_lut() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("gamma_lut.rs");
let mut w = BufWriter::new(File::create(dest_path).unwrap());
writeln!(w, "const ENCODE_SRGB_U8: &[u8] = &[").unwrap();
for i in 0..256 {
if i % 8 == 0 {
write!(w, " ").unwrap();
}
let s = i as f32 / 255.0;
let v = (srgb_gamma_encode(s) * 255.0).round() as u8;
write!(w, "0x{v:02X?}, ").unwrap();
if i % 8 == 7 {
writeln!(w).unwrap();
}
}
writeln!(w, "];").unwrap();
writeln!(w, "const DECODE_SRGB_U8: &[u8] = &[").unwrap();
for i in 0..256 {
if i % 8 == 0 {
write!(w, " ").unwrap();
}
let s = i as f32 / 255.0;
let v = (srgb_gamma_decode(s) * 255.0).round() as u8;
write!(w, "0x{v:02X?}, ").unwrap();
if i % 8 == 7 {
writeln!(w).unwrap();
}
}
writeln!(w, "];").unwrap();
println!("cargo:rerun-if-changed=src/srgb_gamma.rs");
}
fn main() {
gamma_lut();
println!("cargo:rerun-if-changed=build.rs");
}