diff --git a/SpectrumColorShift/Spectrum.cs b/SpectrumColorShift/Spectrum.cs index 83cda86..a7a200e 100644 --- a/SpectrumColorShift/Spectrum.cs +++ b/SpectrumColorShift/Spectrum.cs @@ -16,7 +16,7 @@ namespace SpectrumColorShift public static float ClampReference(float wavelength) => float.IsNaN(wavelength) ? DefaultReferenceWavelength : Math.Clamp(wavelength, ShortestWavelength, LongestWavelength); - public static Vector3 Weights(double wavelength) + public static (double X, double Y, double Z) ColorMatching(double wavelength) { var x = 0.362 * Lobe(wavelength, 442.0, 0.0624, 0.0374) + 1.056 * Lobe(wavelength, 599.8, 0.0264, 0.0323) @@ -26,6 +26,13 @@ namespace SpectrumColorShift var z = 1.217 * Lobe(wavelength, 437.0, 0.0845, 0.0278) + 0.681 * Lobe(wavelength, 459.0, 0.0385, 0.0725); + return (x, y, z); + } + + public static Vector3 Weights(double wavelength) + { + var (x, y, z) = ColorMatching(wavelength); + return new Vector3( (float)Math.Max(3.2404542 * x - 1.5371385 * y - 0.4985314 * z, 0.0), (float)Math.Max(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z, 0.0),