Illuminants Developer Reference
Architecture and maintenance notes for the standalone Illuminants Lab tool, including the HTML shell, state model, standard illuminant registry, SPD synthesis, CIE colorimetry integration, CRI and metamerism approximations, chromatic adaptation, exports, URL state, public API, and Library binding.
Overview
Illuminants Lab is implemented as a self-contained browser IIFE in js/tool/illuminants.js.
The page shell provides the controls, canvases, actions, standards, formulas, and research panels. The
JS module owns the 380-780 nm spectral grid, standard illuminant data, blackbody and daylight synthesis,
CIE XYZ integration, CRI approximation, surface Delta E output, metamerism comparison, chromatic
adaptation preview, exports, URL restore, and window.AAIlluminants integration surface.
1. File map
+- Tool shell:
tool/general/colorimetry/illuminants/index.htmlcontains metadata, hero content, guide text, tab navigation, controls, canvases, action buttons, standards, formulas, references, research content, and fullscreen chart overlay. - Tool engine:
js/tool/illuminants.jscontains the standalone IIFE that implements state, spectral data, colorimetry math, rendering, exports, URL restore, and the public API. - Library integration:
js/library/tool-bindings.jsregisters the illuminants tool path and also includes runtime state capture/restore hooks forwindow.AAIlluminants. - Generated inline helpers: the page loads generated inline scripts for shared shell behavior, canvas accessibility, and unified interactions.
- Discovery metadata: documentation pages are indexed from
data/documentation.jsonand then generated into RSS, sitemaps, PWA cache manifest, and search index outputs.
2. Page shell and UI contract
+- App root:
#il-appwraps the Illuminants Lab application. - Tabs: buttons use
data-il-tab; panels usep-il-lab,p-il-actions,p-il-standards,p-il-formulas,p-il-refs, andp-il-research. - Source controls: radio inputs named
il-modeselectstandardorblackbody;il-illum-selectstores the selected standard illuminant. - CCT controls:
il-cct,il-cct-input,il-cct-val, andil-link-cctmanage custom CCT and standard-source metadata linking. - Comparison controls:
il-compare-toggleandil-compare-illumdrive the blue SPD overlay and comparison metrics. - Surface controls:
il-surfaces-togglesstores checkboxes forwhite,gray,red,green,blue,skin,yellow, andcyan. - Adaptation controls:
il-adapt-from,il-adapt-to,il-swap-adapt, and radio inputs namedil-adapt-modelmanage Bradford, Von Kries, and identity adaptation. - Primary outputs:
il-info-panel,il-spd-canvas,il-spd-probe,il-cri-canvas,il-surfaces-output,il-adapt-output,il-matrix-output, andil-compare-output. - Action outputs:
il-share-urlandil-multi-outputhold generated share URLs and all-illuminant comparison tables.
3. State model
+
The module-level state object is the single runtime source of truth. Event handlers
update state, call syncUI() where controls need to be refreshed, and call
refresh() or a focused renderer for outputs.
- Defaults: mode
standard, illuminantD65, CCT6500, linked CCT enabled, adaptationD65toD50, modelbradford, surfaceswhite,gray,red,green, andskin, comparison illuminantA, comparison hidden. - Mode behavior: changing the CCT slider or number input sets
state.modetoblackbody. - Illuminant behavior: changing the standard illuminant can update
state.cctwhenstate.linkCCTis true and the metadata has a CCT. - Surface behavior: the surface checkbox group rebuilds
state.surfaceKeysand re-renders only the surface section. - Share state: URL restore reads only mode, selected illuminant, CCT, adaptation source, adaptation destination, and adaptation model.
- API restore:
restoreState(saved)merges the saved object intostate, syncs UI, and performs a full refresh.
4. Illuminant registry and SPD generation
+- Wavelength grid:
LAMBDAspans 380 nm through 780 nm in 5 nm increments, producingNL= 81 samples. - Standard data object:
SPD_DATAstores A, D50, D55, D65, D75, E, and F1-F12 spectra. - Illuminant A: generated as a Planckian radiator at 2856 K, normalized around the 560 nm reference used in the implementation.
- Blackbody mode:
planck(w, T)andblackbodySPD(T)generate custom CCT spectra and normalize to the spectrum peak. - Daylight mode:
daylightSPD(T)computes CIE daylight chromaticity, derives M1 and M2, combines S0/S1/S2 basis vectors, and normalizes to 100 at 560 nm. - Equal-energy source: E is a constant 100 relative power across the wavelength grid.
- Fluorescent approximations: F1-F12 use
fluorGauss(peaks)with Gaussian emission peaks. These are practical approximations for the browser tool, not official normative tables. - Metadata:
ILLUM_METAstores label, type, and CCT for the 18 standard illuminants;ILLUM_KEYSdrives the all-illuminant comparison table. - Lookup:
getSPD(name)returns the named standard spectrum or falls back to D65.
5. Colorimetry pipeline
+- Observer data:
CMF_X,CMF_Y_CORRECT, andCMF_Zprovide CIE 1931 2-degree color matching functions on the same 5 nm grid. - SPD to XYZ:
spdToXYZ(spd)integrates spectral power against the CMFs and normalizes Y to 100. - Chromaticity:
xyzToXy(X, Y, Z)derives CIE x and y from XYZ, with D65 fallback for zero sums. - CCT:
cctFromXy(x, y)uses the McCamy approximation for correlated color temperature. - Duv:
duvFromXy(x, y)estimates distance in CIE 1960 UCS style coordinates against a simplified locus reference. - Lab:
xyzToLab()uses a D65 reference white and supports surface, CRI, and metamerism differences. - Delta E:
deltaE00()implements CIEDE2000 and is reused by CRI approximation, surface output, and metamerism comparison. - sRGB preview:
xyzToSrgb()andrgbToHex()convert normalized XYZ values into clipped display HEX swatches for UI feedback. - White points:
WHITE_XYstores named CIE white chromaticities for A, B, C, D50, D55, D65, D75, and E.whiteXYZ(name)converts them to Y = 100 XYZ or falls back to SPD integration.
6. Rendering, surfaces, and adaptation
+- Refresh:
refresh()callsrenderInfoPanel(),renderSPDChart(),renderCRIChart(),renderSurfaces(),renderAdaptation(),renderMatrixPanel(), andrenderComparison(). - Canvas setup:
setupCanvas(id)sizes canvas buffers for the current device pixel ratio and scales the drawing context. - SPD chart:
renderSPDChart()draws grid lines, axes, rainbow fill, gold primary trace, optional blue comparison trace, and legend. - CRI chart:
renderCRIChart()computes CRI for the active source and draws R1-R14 bars with Ra label. - CRI computation:
computeCRI(spd)estimates reference SPD from CCT, multiplies 14 Gaussian TCS reflectance approximations by test and reference spectra, adapts by simple per-channel scaling, converts to Lab, and derives R values from Delta E. - Surfaces:
SURFACESstores eight educational reflectance presets.renderSurfaces()multiplies selected surface curves by the active SPD and D65 SPD, adapts to D65, converts to sRGB, and reports Delta E 2000. - Comparison:
renderComparison()computes CCT, xy, CRI, and average Delta E 2000 metamerism across the 14 TCS approximations when comparison mode is enabled. - Adaptation:
adaptXYZ()supports Bradford, Von Kries, and identity.renderAdaptation()adapts a 24-patch sRGB set from source white to destination white. - Matrix output:
renderMatrixPanel()prints the active CAT matrix, source and destination LMS values, and destination/source LMS scale factors. - Probe: clicking
il-spd-canvasmaps x-position to wavelength index and writes wavelength, relative power, and visible color chip intoil-spd-probe.
7. Exports, share URL, and events
+- CSV export:
exportCSV()writes wavelength and relative power rows for the active source and downloads*-spd.csv. - JSON export:
exportJSON()writes active label, CCT, xy, XYZ, CRI, and SPD array. - PNG export:
exportPNG()usesHTMLCanvasElement.toBlob()onil-spd-canvas. - Clipboard:
copyWhiteCSS()writes the active white HEX vianavigator.clipboard.writeText(). Share URL copy uses the same clipboard API. - Share URL builder:
buildShareURL()encodesmode,illumorcct,af,at, andam. - URL restore:
restoreURL()reads those query parameters before the firstsyncUI()andrefresh(). - Multi comparison:
renderMultiCompare()iteratesILLUM_KEYSand writes table rows for CCT, x, y, CRI Ra, and swatch. - Keyboard shortcuts: the page documents S for swap, R for reset, C for compare, and E for export CSV. When extending shortcuts, keep input focus behavior in mind.
- Toast:
toast(msg)targetsil-toastif present, so missing toast markup is tolerated.
8. Public API and library binding
+- Namespace: the tool exposes
window.AAIlluminantsafterboot(). - getState: returns a JSON-cloned copy of the internal
stateobject. - restoreState: validates an object, merges it into
state, syncs UI, refreshes outputs, and returnstruewhen applied. - Generic binding:
js/library/tool-bindings.jshas an illuminants path matcher for/tool/general/colorimetry/illuminants/with idilluminants, nameIlluminants, href/tool/general/colorimetry/illuminants/, categoryColorimetry, and asset typepreset. - Runtime capture: shared Library state capture includes
illuminants: window.AAIlluminants?.getState. - Runtime restore: shared Library restore routes include
["illuminants", window.AAIlluminants?.restoreState]. - Compatibility fallback: the simple binding checks legacy ids
ill-selectandilluminant-select, then snapshots form inputs. The current page usesil-illum-select, so prefer the runtime API for exact state. - Integration note: if the Library binding is modernized, update the simple
capture ids to
il-illum-select,il-compare-illum,il-adapt-from, and related controls or delegate directly towindow.AAIlluminants.getState().
9. Extension checklist
+- Add new standard sources to
SPD_DATAon the 380-780 nm, 5 nm grid. - Add matching metadata to
ILLUM_METAso labels, type, CCT, linked CCT, and comparison tables remain consistent. - Update the standard illuminant dropdown and comparison dropdown HTML when new user-visible sources are added.
- Keep all spectrum arrays the same length as
LAMBDA, or add validation before colorimetry functions consume them. - When replacing fluorescent approximations with official tables, document the table source, interval, interpolation rule, and normalization policy.
- When adding a new CAT method, add matrices, update
adaptXYZ(), UI radio inputs, matrix output, share URL handling, docs, and tests. - When adding custom uploaded SPD or reflectance data, define parsing, normalization, wavelength interpolation, export behavior, URL behavior, and Library save behavior before shipping.
- Update JSON export and share URL behavior whenever the persistent state surface changes.
- Regenerate docs discovery outputs after any documentation addition:
scripts/generate-discovery.mjs,scripts/generate-pwa-cache-manifest.mjs, andsearch/client/build-index.js. - Keep the research tab explicit when a method is approximate and not a replacement for official CIE or IES compliance software.
10. Testing and risk notes
+- Boot: the page loads, the guide appears, Lab tab is active, summary populates, SPD canvas renders, CRI canvas renders, surface rows appear, and adaptation patches appear.
- Controls: test standard illuminant changes, blackbody CCT slider, CCT input, Link to select, reset, comparison toggle, comparison source changes, surface toggles, adaptation pair, adaptation model, and swap.
- Actions: test CSV, JSON, PNG, copy white HEX, generate share URL, copy share URL, and multi-illuminant table generation after multiple state changes.
- URL restore: smoke test standard mode URLs with
illum, blackbody URLs withcct, and adaptation paramsaf,at, andam. - Library: save and restore through runtime state when available, and confirm the fallback form capture does not break older saved presets.
- Numerical risk: changes to CMFs, normalization, daylight basis vectors, fluorescent approximations, Lab reference white, or Delta E implementation will shift visible charts, exports, CRI values, metamerism index, and saved expectations.
- Performance risk: CRI, surface, and comparison calculations repeatedly iterate over 81 wavelength samples and 14 TCS approximations. Larger future sample sets should be measured on mobile before release.
- Compliance risk: current fluorescent spectra, TCS reflectances, CRI, TM-30, and metamerism calculations are educational approximations. Avoid labeling generated output as certified CIE or IES data unless the engine is replaced with normative tables and validated algorithms.