|
1 | 1 | # Specification & Plan: Modular LMS Cone Fundamentals & Chromaticity Diagrams |
2 | 2 |
|
3 | | -This specification outlines the modularization of **LMS Cone Fundamentals** and the implementation of **Multiple Chromaticity Diagrams** in COLOR LAB. It addresses the tail divergence of the current analytical fits, maps the user's custom curve to its experimental origins, and details the impact on active and planned color pipelines. |
| 3 | +This specification outlines the modularization of **LMS Cone Fundamentals** and the implementation of **Multiple Chromaticity Diagrams** in COLOR LAB. It replaces the current analytical wavelength fits with reference observer data as the source of truth, maps the user's custom curve to its experimental origins, and details the impact on active and planned color pipelines. |
4 | 4 |
|
5 | 5 | --- |
6 | 6 |
|
@@ -48,10 +48,29 @@ Each fundamental model will define: |
48 | 48 | 2. **Stockman & Sharpe (2000) 10°**: Large-field physiological model. |
49 | 49 | 3. **Smith & Pokorny (1975)**: Derived from the Judd-modified CIE 1931 CMFs. |
50 | 50 |
|
51 | | -#### Resolving Tail Instability: |
52 | | -To achieve stable analytical evaluation down to 380nm and up to 780nm, we will support two approaches: |
53 | | -- **Cubic Spline Interpolation**: Read official 1nm/5nm tables from CVRL and perform natural cubic spline interpolation. This is mathematically analytical, matches the experimental data exactly, decays naturally to zero, and is highly stable. |
54 | | -- **Asymmetrical Gaussian/Log-Normal Models**: If a closed-form formula is preferred, replace the Gaussian-derivative fits with an asymmetrical log-normal formulation (e.g., the Govardovskii template) that guarantees asymptotic decay to zero at the bounds. |
| 51 | +#### Reference-Validated Evaluator Requirement |
| 52 | +The first implementation must not hide the current edge artifacts by clamping, |
| 53 | +windowing, or otherwise cosmetically stabilizing an evaluator that is wrong at |
| 54 | +the edges. Range extremes are colorimetrically meaningful for spectral locus and |
| 55 | +observer work, so the evaluator must be validated against authoritative |
| 56 | +measured/tabulated data across the full visible range. |
| 57 | + |
| 58 | +Recommended approach: |
| 59 | + |
| 60 | +- Use CVRL / CIE-published table data for the selected observer model at the |
| 61 | + finest practical wavelength interval available as the benchmark. |
| 62 | +- Evaluate both table-based interpolation and continuous analytical fits against |
| 63 | + that benchmark. A good continuous fit can be preferable between tabulated |
| 64 | + samples if its error is lower than interpolation and it behaves correctly at |
| 65 | + the extremes. |
| 66 | +- For interpolation, prefer monotone or shape-preserving methods where possible. |
| 67 | + Natural cubic splines are acceptable only if they do not overshoot low-energy |
| 68 | + tails or create negative lobes. |
| 69 | +- For analytical fits, require explicit error thresholds, correct non-negative |
| 70 | + tail behavior, and no oscillation/divergence outside the fitted core range. |
| 71 | +- Keep the current analytical fit as a candidate/comparison fixture. If it is |
| 72 | + within acceptable error over a documented subrange, keep using it there and |
| 73 | + replace only the failing region with a better reference-validated evaluator. |
55 | 74 |
|
56 | 75 | ### B. Chromaticity Diagrams (`fe/src/lib/color/diagrams.ts`) |
57 | 76 | Each diagram defines: |
@@ -117,17 +136,20 @@ This means the UI should not introduce a ramp-local or theme-local |
117 | 136 | Recommended split: |
118 | 137 |
|
119 | 138 | - `observerModel`: document-level only once it affects saved analysis or CVD |
120 | | - behavior. Until then, keep it fixed at the current default and use the new |
121 | | - registry internally to stabilize tails. |
| 139 | + behavior. Until then, keep it fixed at the current default and move that |
| 140 | + default onto reference data internally. |
122 | 141 | - `chromaticityDiagram`: local UI preference if it only changes the xy/u'v' |
123 | 142 | instrument view; document-level only if diagram selection becomes semantic |
124 | 143 | for picking, saved annotations, or exported analysis. |
125 | 144 |
|
126 | 145 | ### Sequencing with the Current Roadmap |
127 | 146 |
|
128 | | -1. **Tail stabilization can ship first without a schema bump.** Replacing the |
129 | | - unstable analytical tails with table/spline data behind the current default |
130 | | - observer is a correctness fix for existing behavior. |
| 147 | +1. **Reference-validated evaluator work can ship first without a schema bump.** |
| 148 | + Replacing or segmenting the unstable analytical evaluator behind the current |
| 149 | + default observer is a correctness fix for existing behavior. The replacement |
| 150 | + may be table-interpolated or analytical, but it must be benchmarked against |
| 151 | + reference data and preserve colorimetric outputs at range extremes rather |
| 152 | + than merely suppress visible artifacts. |
131 | 153 | 2. **Chromatic adaptation should precede exposed observer/profile choices.** |
132 | 154 | The same shared `DerivedMatrices` path should carry white-point adaptation |
133 | 155 | and observer/display matrices so CPU, GPU, picking, and panels agree. |
@@ -160,29 +182,35 @@ The CVD simulation is performed by projecting RGB colors into the LMS color spac |
160 | 182 | - **Impact**: Exposing user-selectable observer/diagram settings may require |
161 | 183 | persistence, but only after deciding whether each setting is document semantic |
162 | 184 | or local preference. |
163 | | -- **Resolution**: Do **not** bump the schema for the tail-stability fix. If a |
164 | | - later phase persists document-level observer choices, store them under the |
| 185 | +- **Resolution**: Do **not** bump the schema for evaluator replacement while the |
| 186 | + selected observer identity stays the same. If a later phase persists |
| 187 | + document-level observer choices, store them under the |
165 | 188 | global color/observer context, not `theme`, and then follow the document |
166 | 189 | persistence playbook with an explicit migration. |
167 | 190 |
|
168 | 191 | --- |
169 | 192 |
|
170 | 193 | ## 6. Detailed Implementation Plan |
171 | 194 |
|
172 | | -### Phase 1: Experimental Data & Fit Comparison |
173 | | -1. Write a scratch script under `fe/src/lib/color/scratch/compare-fundamentals.ts` to load CVRL datasets. |
174 | | -2. Compare the user's custom Gaussian formula from `pipeline.ts` to identify its exact source data (e.g., Stockman & Sharpe 2°). |
175 | | -3. Evaluate the fit MSE and determine stable bounds. |
176 | | -4. Replace only the current default evaluator if the comparison confirms a |
177 | | - drop-in table/spline fix; this phase should not add UI or persistence. |
| 195 | +### Phase 1: Reference Data & Fit Audit |
| 196 | +1. Write a scratch script under `fe/src/lib/color/scratch/compare-fundamentals.ts` to load CVRL/CIE reference datasets. |
| 197 | +2. Compare the current Gaussian-derivative formula from `pipeline.ts` against the relevant reference data to identify its closest source model and quantify errors across the full visible range, with special attention to the low-energy tails. |
| 198 | +3. Select the reference dataset that should define the current default observer. Prefer newer physiological observer measurements where they match the intended model; document any mismatch with CIE 1931/1964 diagram geometry. |
| 199 | +4. Compare evaluator strategies: |
| 200 | + - current analytical fit over any range where it remains accurate; |
| 201 | + - shape-preserving interpolation from reference samples; |
| 202 | + - continuous analytical alternatives or segmented fits. |
| 203 | +5. Implement the default evaluator from the strategy with the best documented accuracy/behavior tradeoff. Reject interpolation or analytical methods that overshoot, go negative, oscillate, diverge, or distort spectral-locus extremes. |
| 204 | +6. Keep this phase UI-free and persistence-free: it changes the numeric evaluator for the same observer identity, not the saved document shape. |
178 | 205 |
|
179 | 206 | ### Phase 2: Registry & Mathematical Foundation |
180 | 207 | 1. Implement `fe/src/lib/color/fundamentals.ts` containing: |
181 | | - - Analytical spline evaluators for Stockman-Sharpe 2°/10° and Smith-Pokorny 2°. |
| 208 | + - Reference-validated evaluators for Stockman-Sharpe 2°/10° and Smith-Pokorny 2°. |
182 | 209 | - Matrices for LMS $\leftrightarrow$ XYZ mapping. |
183 | 210 | 2. Implement `fe/src/lib/color/diagrams.ts` containing the coordinate projection math for CIE 1931 xy, CIE 1976 UCS u'v', and CIE 2006 xy. |
184 | | -3. Keep the active runtime default identical to current behavior until CVD and |
185 | | - panel parity are ready. |
| 211 | +3. Keep the selected default observer identity unchanged until CVD and panel |
| 212 | + parity are ready, but preserve only evaluator segments that meet the |
| 213 | + documented reference-data error and tail-behavior criteria. |
186 | 214 |
|
187 | 215 | ### Phase 3: WebGL & CVD Updates |
188 | 216 | 1. Modify `rebuildMatrices` in `fe/src/lib/renderer/uniforms.ts` to compute `RGB2LMS` and `LMS2RGB` dynamically using the active LMS model. |
|
0 commit comments