Switch to CIE XYZ lookup tables.
This commit is contained in:
parent
caed4c67de
commit
8bc6b24004
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -127,6 +127,12 @@ dependencies = [
|
||||||
name = "color"
|
name = "color"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorbox"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3d27d55561009760957654f467735e73806f8bc2d081cc4a22e93403ecd156fc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "compact"
|
name = "compact"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -329,6 +335,7 @@ dependencies = [
|
||||||
"bvh_order",
|
"bvh_order",
|
||||||
"clap",
|
"clap",
|
||||||
"color",
|
"color",
|
||||||
|
"colorbox",
|
||||||
"compact",
|
"compact",
|
||||||
"copy_in_place",
|
"copy_in_place",
|
||||||
"crossbeam",
|
"crossbeam",
|
||||||
|
|
|
@ -36,7 +36,7 @@ rustc-serialize = "0.3"
|
||||||
scoped_threadpool = "0.1"
|
scoped_threadpool = "0.1"
|
||||||
time = "0.1"
|
time = "0.1"
|
||||||
fastapprox = "0.3"
|
fastapprox = "0.3"
|
||||||
|
colorbox = "0.3"
|
||||||
|
|
||||||
|
|
||||||
# Local crate dependencies
|
# Local crate dependencies
|
||||||
|
|
47
src/color.rs
47
src/color.rs
|
@ -608,21 +608,46 @@ fn xyz_to_spectrum_4(xyz: (f32, f32, f32), wavelengths: Float4) -> Float4 {
|
||||||
/// From the paper "Simple Analytic Approximations to the CIE XYZ Color Matching
|
/// From the paper "Simple Analytic Approximations to the CIE XYZ Color Matching
|
||||||
/// Functions" by Wyman et al.
|
/// Functions" by Wyman et al.
|
||||||
pub fn x_1931(wavelength: f32) -> f32 {
|
pub fn x_1931(wavelength: f32) -> f32 {
|
||||||
let t1 = (wavelength - 442.0) * (if wavelength < 442.0 { 0.0624 } else { 0.0374 });
|
use colorbox::tables::cie_1931_xyz::{MAX_WAVELENGTH, MIN_WAVELENGTH, X};
|
||||||
let t2 = (wavelength - 599.8) * (if wavelength < 599.8 { 0.0264 } else { 0.0323 });
|
|
||||||
let t3 = (wavelength - 501.1) * (if wavelength < 501.1 { 0.0490 } else { 0.0382 });
|
let norm = 1.0 / (MAX_WAVELENGTH - MIN_WAVELENGTH);
|
||||||
(0.362 * fast_exp(-0.5 * t1 * t1)) + (1.056 * fast_exp(-0.5 * t2 * t2))
|
let n = (wavelength - MIN_WAVELENGTH) * norm;
|
||||||
- (0.065 * fast_exp(-0.5 * t3 * t3))
|
|
||||||
|
if n < 0.0 {
|
||||||
|
X[0]
|
||||||
|
} else if n > 1.0 {
|
||||||
|
*X.last().unwrap()
|
||||||
|
} else {
|
||||||
|
crate::lerp::lerp_slice(X, n)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn y_1931(wavelength: f32) -> f32 {
|
pub fn y_1931(wavelength: f32) -> f32 {
|
||||||
let t1 = (wavelength - 568.8) * (if wavelength < 568.8 { 0.0213 } else { 0.0247 });
|
use colorbox::tables::cie_1931_xyz::{MAX_WAVELENGTH, MIN_WAVELENGTH, Y};
|
||||||
let t2 = (wavelength - 530.9) * (if wavelength < 530.9 { 0.0613 } else { 0.0322 });
|
|
||||||
(0.821 * fast_exp(-0.5 * t1 * t1)) + (0.286 * fast_exp(-0.5 * t2 * t2))
|
let norm = 1.0 / (MAX_WAVELENGTH - MIN_WAVELENGTH);
|
||||||
|
let n = (wavelength - MIN_WAVELENGTH) * norm;
|
||||||
|
|
||||||
|
if n < 0.0 {
|
||||||
|
Y[0]
|
||||||
|
} else if n > 1.0 {
|
||||||
|
*Y.last().unwrap()
|
||||||
|
} else {
|
||||||
|
crate::lerp::lerp_slice(Y, n)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn z_1931(wavelength: f32) -> f32 {
|
pub fn z_1931(wavelength: f32) -> f32 {
|
||||||
let t1 = (wavelength - 437.0) * (if wavelength < 437.0 { 0.0845 } else { 0.0278 });
|
use colorbox::tables::cie_1931_xyz::{MAX_WAVELENGTH, MIN_WAVELENGTH, Z};
|
||||||
let t2 = (wavelength - 459.0) * (if wavelength < 459.0 { 0.0385 } else { 0.0725 });
|
|
||||||
(1.217 * fast_exp(-0.5 * t1 * t1)) + (0.681 * fast_exp(-0.5 * t2 * t2))
|
let norm = 1.0 / (MAX_WAVELENGTH - MIN_WAVELENGTH);
|
||||||
|
let n = (wavelength - MIN_WAVELENGTH) * norm;
|
||||||
|
|
||||||
|
if n < 0.0 {
|
||||||
|
Z[0]
|
||||||
|
} else if n > 1.0 {
|
||||||
|
*Z.last().unwrap()
|
||||||
|
} else {
|
||||||
|
crate::lerp::lerp_slice(Z, n)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user