NM and RGB This algorithm is hugely perceptual and is not intended to be utilized for any scientific or measurement purposes. The purpose of x x x is to give the spectrum a visual falloff as the wavelength approches 380 and 800, such that, at a bit depth of 8, 380nm ≈ [8,0,8] and 800nm ≈ [16,0,0]. RGB values will sometimes fall out of [0,1] and should be clamped.
γ = 0.8 R ′ = { − λ − 440 440 − 380 380 ≤ λ < 440 λ − 510 580 − 510 510 ≤ λ < 580 1 580 ≤ λ ≤ 800 0 otherwise G ′ = { λ − 440 490 − 440 440 ≤ λ < 490 1 490 ≤ λ < 580 − λ − 645 645 − 580 580 ≤ λ < 645 0 otherwise B ′ = { 1 360 ≤ λ < 490 λ − 510 510 − 490 490 ≤ λ < 510 0 otherwise x = { 1 71 + 1 10 ( λ − 380 ) 420 − 380 380 ≤ λ < 400 1 5 + 5 7 ( λ − 400 ) 420 − 400 400 ≤ λ < 420 1 420 ≤ λ < 701 1 3 + 5 7 ⋅ ( 780 − λ ) 780 − 700 701 ≤ λ < 781 1 32 + 1 5 ( 800 − λ ) 800 − 781 781 ≤ λ ≤ 800 0 otherwise f ( y ) = y x γ ( R , G , B ) = ( f ( R ′ ) , f ( G ′ ) , f ( B ′ ) ) \begin{align*} \gamma &= 0.8 \\ \:\\ R' &= \begin{cases} -\frac{\lambda - 440}{440 - 380} & 380 \leq \lambda < 440 \\ \frac{\lambda - 510}{580 - 510} & 510 \leq \lambda < 580 \\ 1 & 580 \leq \lambda \leq 800 \\ 0 & \text{ otherwise } \end{cases} \\ \:\\ G' &= \begin{cases} \frac{\lambda - 440}{490 - 440} & 440 \leq \lambda < 490 \\ 1 & 490 \leq \lambda < 580 \\ -\frac{\lambda - 645}{645 - 580} & 580 \leq \lambda < 645 \\ 0 & \text{ otherwise } \end{cases} \\ \:\\ B' &= \begin{cases} 1 & 360 \leq \lambda < 490 \\ \frac{\lambda - 510}{510 - 490} & 490 \leq \lambda < 510 \\ 0 & \text{ otherwise } \end{cases} \\ \:\\ x &= \begin{cases} \frac{1}{71} + \frac{\frac{1}{10} (\lambda - 380)}{420 - 380} & 380 \leq \lambda < 400 \\ \frac{1}{5} + \frac{\frac{5}{7} (\lambda - 400)}{420 - 400} & 400 \leq \lambda < 420 \\ 1 & 420 \leq \lambda < 701 \\ \frac{1}{3} + \frac{\frac{5}{7} \cdot (780 - \lambda)}{780 - 700} & 701 \leq \lambda < 781 \\ \frac{1}{32} + \frac{\frac{1}{5} (800 - \lambda)}{800 - 781} & 781 \leq \lambda \leq 800 \\ 0 & \text{ otherwise } \end{cases} \\ \:\\ f(y) &= yx^\gamma \\ \:\\ (R,G,B) &= (f(R'),f(G'),f(B')) \end{align*} γ R ′ G ′ B ′ x f ( y ) ( R , G , B ) = 0.8 = ⎩ ⎨ ⎧ − 440 − 380 λ − 440 580 − 510 λ − 510 1 0 380 ≤ λ < 440 510 ≤ λ < 580 580 ≤ λ ≤ 800 otherwise = ⎩ ⎨ ⎧ 490 − 440 λ − 440 1 − 645 − 580 λ − 645 0 440 ≤ λ < 490 490 ≤ λ < 580 580 ≤ λ < 645 otherwise = ⎩ ⎨ ⎧ 1 510 − 490 λ − 510 0 360 ≤ λ < 490 490 ≤ λ < 510 otherwise = ⎩ ⎨ ⎧ 71 1 + 420 − 380 10 1 ( λ − 380 ) 5 1 + 420 − 400 7 5 ( λ − 400 ) 1 3 1 + 780 − 700 7 5 ⋅ ( 780 − λ ) 32 1 + 800 − 781 5 1 ( 800 − λ ) 0 380 ≤ λ < 400 400 ≤ λ < 420 420 ≤ λ < 701 701 ≤ λ < 781 781 ≤ λ ≤ 800 otherwise = y x γ = ( f ( R ′ ) , f ( G ′ ) , f ( B ′ ))