Something went wrong. Try again.
HEXWORK - A Lantern in the Deep: 3D ASCII terminal roguelike RPG in Rust.
Entirely designed and built by Muse Spark 1.3 to evaluate if I like the model.
Something went wrong. Try again.
2.4 kB · 40 lines
Rust
at main
1234567891011121314151617181920212223242526272829303132333435363738394041//! Checked-in sRGB transfer cut points. For integer p=channel*light (0..6120),//! each entry is the first p yielding byte >= index+1. Generated by exhaustive//! enumeration: L=p/6120; S=12.92L if L<=0.0031308 else 1.055L^(1/2.4)-0.055;//! byte=floor(255S+0.5). This is positive round-half-up, matching the old f64//! exposure reference. Runtime performs no libm operation. Tests compare every p.const CUTS: [u16; 255] = [ 1, 3, 5, 7, 9, 11, 13, 14, 16, 18, 20, 22, 24, 26, 29, 31, 33, 36, 39, 42, 45, 48, 51, 55, 58, 62, 66, 70, 74, 78, 82, 87, 91, 96, 101, 106, 111, 116, 122, 127, 133, 139, 145, 151, 158, 164, 171, 178, 185, 192, 199, 207, 214, 222, 230, 238, 247, 255, 264, 273, 282, 291, 300, 309, 319, 329, 339, 349, 359, 370, 381, 392, 403, 414, 425, 437, 449, 461, 473, 485, 498, 510, 523, 536, 550, 563, 577, 591, 605, 619, 633, 648, 663, 678, 693, 709, 724, 740, 756, 772, 789, 805, 822, 839, 856, 874, 891, 909, 927, 946, 964, 983, 1002, 1021, 1040, 1060, 1079, 1099, 1119, 1140, 1160, 1181, 1202, 1223, 1245, 1266, 1288, 1310, 1333, 1355, 1378, 1401, 1424, 1448, 1471, 1495, 1519, 1544, 1568, 1593, 1618, 1643, 1669, 1694, 1720, 1746, 1773, 1799, 1826, 1853, 1881, 1908, 1936, 1964, 1992, 2021, 2049, 2078, 2108, 2137, 2167, 2197, 2227, 2257, 2288, 2319, 2350, 2381, 2413, 2445, 2477, 2509, 2542, 2574, 2607, 2641, 2674, 2708, 2742, 2776, 2811, 2846, 2881, 2916, 2952, 2988, 3024, 3060, 3096, 3133, 3170, 3208, 3245, 3283, 3321, 3360, 3398, 3437, 3476, 3516, 3555, 3595, 3635, 3676, 3716, 3757, 3798, 3840, 3882, 3924, 3966, 4008, 4051, 4094, 4138, 4181, 4225, 4269, 4313, 4358, 4403, 4448, 4494, 4539, 4585, 4632, 4678, 4725, 4772, 4819, 4867, 4915, 4963, 5012, 5060, 5109, 5159, 5208, 5258, 5308, 5358, 5409, 5460, 5511, 5563, 5615, 5667, 5719, 5772, 5825, 5878, 5931, 5985, 6039, 6093,];pub fn encode(product: u16) -> u8 { CUTS.partition_point(|cut| *cut <= product) as u8}#[cfg(test)]mod tests { #[test] fn ac7_transfer_lut_preserves_all_exposure_products() { for p in 0..=6120 { let l = f64::from(p) / 6120.0; let s = if l <= 0.0031308 { 12.92 * l } else { 1.055 * l.powf(1.0 / 2.4) - 0.055 }; assert_eq!(super::encode(p), (s * 255.0).round() as u8, "product {p}"); } }}