Skip to main content

Module spectral_kernel

Module spectral_kernel 

Source
Expand description

P7.0 — Spectral-space kernel: SPD/CMF POD types + CIE linear-projection. P7.0 — Spectral-space kernel: SPD/CMF POD types + the CIE linear-projection contract.

This module defines the foundational spectral types and the linear projection from a Spectral Power Distribution (SPD) to CIE 1931 XYZ tristimulus values via tabulated Colour Matching Functions (CMFs).

§EMF → Colour pipeline

The Qualia 10D tensor’s spectral axes [α, μ, σ] represent the EMF (electromagnetic field) payload:

  • α (amplitude): total radiant power scaling
  • μ (modulation): spectral bandwidth / phase modulation
  • σ (signature): peak wavelength selector (400–700 nm)

The pipeline is:

EMF [α, μ, σ] → SPD(λ) → CIE XYZ → linear sRGB → display sRGB
  1. emf_to_spd(α, μ, σ) constructs an SPD from the EMF payload.
  2. spd_to_xyz(spd) projects through the tabulated CIE 1931 CMFs.
  3. xyz_to_linear_srgb(xyz) applies the standard XYZ→sRGB matrix.

§CIE 1931 2-degree observer

The CMFs are tabulated at 10 nm intervals from 380–780 nm (41 samples). This replaces the Gaussian approximation in render/spectral.rs with the authoritative tabulated data. The ΔE between the two is documented.

§Determinism

All operations are deterministic: identical input → bit-identical output. The CMF tables are compile-time constants.

Structs§

LinearRgb
Linear sRGB (no gamma encoding). POD, f32.
Spd
Spectral Power Distribution: radiant power at 41 wavelength samples (380–780 nm, 10 nm steps). POD, zero-heap, stack-allocated.
Xyz
CIE XYZ tristimulus values. POD, f32.

Constants§

CIE_1931_CMF_X
CIE 1931 2-degree observer colour matching functions, tabulated at 10 nm intervals from 380–780 nm.
CIE_1931_CMF_Y
CIE_1931_CMF_Z
CIE_D65_X
CIE D65 illuminant white point (normalised, Y=1).
CIE_D65_Y
CIE_D65_Z
LAMBDA_MAX
Ending wavelength (nm).
LAMBDA_MIN
Starting wavelength (nm).
LAMBDA_STEP
Wavelength step (nm).
SPD_SAMPLES
Number of spectral samples (380–780 nm at 10 nm intervals).

Functions§

delta_e_76
CIE76 ΔE colour difference between two XYZ values (in Lab space).
emf_to_linear_rgb
Full EMF → linear sRGB pipeline.
emf_to_spd
Convert an EMF payload [α, μ, σ] to a Spectral Power Distribution.
flat_spd_to_xyz
Project a flat (equal-energy) SPD to verify the D65 white point.
gaussian_vs_tabulated_delta_e
Compute the ΔE between the tabulated CMF projection and the existing Gaussian approximation in render::spectral.rs.
linear_rgb_to_display
Convert linear sRGB to 8-bit display sRGB (gamma-encoded, normalised).
linear_to_srgb_channel
Apply sRGB gamma encoding to a single linear channel.
spd_to_xyz
Project an SPD through the CIE 1931 2-degree CMFs to obtain XYZ tristimulus values.
xyz_to_lab
Convert XYZ to CIELAB (D65 reference white).
xyz_to_linear_srgb
Convert CIE XYZ to linear sRGB using the standard sRGB matrix.