Repository navigation
Description
Context
The follow-up discussion in #2748 identified a broader design problem beyond the immediate RGBW endpoint-scaling fixes: the reusable colorimetric solver pieces are currently tied to rgbw_colorimetric, and there is no explicit RGB-only entrypoint that guarantees the solve runs after correction/temperature/brightness/gamma decisions but before chipset output.
#3231 tracks this together with RGBW endpoint-scaling follow-ups. This issue splits out the shared solver/refactor and RGB entrypoint design so it can be planned independently of the remaining RGBW verifier work.
Problem
The current RGBW path already performs its colorimetric conversion late in the pixel load path, using the premixed color adjustment values. That is the right shape for RGBW because the solver sees adjusted source values before bytes are emitted.
For an RGB-only colorimetric path, the same ordering requirement matters:
input CRGB
-> correction / temperature / brightness / gamma policy
-> colorimetric RGB solve
-> chipset output bytes
Once a colorimetric solve produces final RGB channel values, later per-channel correction, temperature, brightness, or gamma mutation can invalidate the solved chromaticity. The integration point therefore needs to make post-solve mutation impossible or very explicit.
Proposal
Add a shared colorimetric_response layer for portable colorimetric primitives, then add an opt-in RGB colorimetric dispatch path at the final pixel load boundary.
Suggested implementation shape:
- Extract reusable math/profile helpers from
src/fl/gfx/rgbw_colorimetric.*intosrc/fl/gfx/colorimetric_response.*. - Keep RGBW-specific topology, W extraction, boosted mode, and RGBCCT logic in
rgbw_colorimetric.*. - Add an RGB-only colorimetric config/API separate from the existing RGBW/RGBWW white-channel config.
- Integrate RGB colorimetric solving near the existing RGB pixel load/scale path, not inside each chipset driver.
- Ensure solved RGB bytes are emitted directly without a second correction/brightness/temperature pass.
Acceptance criteria
- Shared helper extraction causes no intentional RGBW output changes.
- Existing RGBW tests continue to pass after the extraction.
- New tests cover the shared
colorimetric_responseprimitives independently of RGBW topology. - An opt-in RGB colorimetric mode has a clear API/config path and does not affect default RGB output.
- The RGB colorimetric solve runs after final source-value policy decisions and before chipset byte emission.
- Tests or a mock output path prove that no post-solve per-channel scaling/correction is applied.
- The design remains compile-time gated or otherwise MCU-friendly so boards that do not use colorimetric solving do not pay unnecessary binary-size cost.
Open questions
- Should the RGB-only mode share the existing
FASTLED_RGBW_COLORIMETRICgate initially, or get a dedicatedFASTLED_RGB_COLORIMETRICgate? - Should gamma/power policy be folded into the same pre-solve adjustment path, or should the RGB colorimetric entrypoint explicitly accept already-final linear/source values?
- What public API shape should expose the RGB source gamut and measured emitter profile without overloading the existing white-channel config?
Related issues
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Jun 18, 2026
Why the gate failed
/clud-fixis structured around a falsifiable reproduction: implement, merge, then re-run the reporter's reproduction case against mergedmain. This issue is a forward-looking design + refactor with three explicit "Open questions" that the issue itself flags as undecided. There is:So this run produces a planned-fix report instead of a PR. Once the open questions below are decided by the maintainer, a normal
/clud-prinvocation can land the implementation in well-bounded chunks.What the code actually looks like today
Solver layer (1,536 lines total)
src/fl/gfx/rgbw_colorimetric.h(461 lines)src/fl/gfx/rgbw_colorimetric.cpp.hpp(1,075 lines)Everything lives in
namespace fl::colorimetric_detail. The header inlines the leaf-level math (cct_to_xy,xyY_to_XYZ,invert3x3,matvec3,barycentric_xy,build_source_matrix,nnls3,hermite_basis,quantize_u8/lut_cell) and declares the heavier work:ProfileCache,LutTable,build_profile_cache,solve_strict_subgamut[_xy],solve_wx_lp_legacy,solve_wx_overdrive,build_lut,lookup_lut,solve_rgbcct. All function definitions and the heavyweight data types are gated byFASTLED_RGBW_COLORIMETRIC.Public RGBW config surface (
src/fl/gfx/rgbw.h)struct DiodeProfilecarries R/G/B chromaticity and W chromaticity, peak luminances includinglum_w,nominal_cct, plus the post-bug(rgbw): kRGBWColorimetric* skips source-RGB → LED-XYZ conversion — solver has no target white point #2705 source-space fields (input_xy_r/g/b/w).set_rgbw_colorimetric_profile(),enable_rgbw_colorimetric_lut(...),disable_rgbw_colorimetric_lut(),rgbw_colorimetric_lut_enabled(),rgbw_colorimetric_lut_memory_bytes(...).RGBW_MODE::kRGBWColorimetricandkRGBWColorimetricBoostedenumerators, dispatched through thergb_2_rgbw(MODE, ...)switch inrgbw.h:317.Pixel-load integration (
src/pixel_controller.h:591-629)The ordering called out as required in the issue already holds for RGBW, and the structural reason is the
mColorAdjustment.premixedfield:So the colorimetric solve already sees post-policy values, and the chipset side does not apply any further per-channel mutation between solver output and the wire. The structural invariant the issue asks for in the RGB path is exactly the one the RGBW path already enforces.
Where RGB-only would plug in (
src/pixel_controller.h:581-586)loadAndScale{0,1,2}already applymColorAdjustment.premixed. So the RGB-only colorimetric hook has a single, clean integration point: betweenloadAndScale*and the assignment tob*_out. Every chipset that drives RGB strips callsloadAndScaleRGB(src/fl/chipsets/hd108.h:62,src/platforms/adafruit/clockless_real.hpp:82,src/platforms/arm/teensy/teensy4_common/clockless_objectfled.cpp.hpp:143,src/platforms/arm/rp/rpcommon/clockless_rp_pio_auto.cpp.hpp:405, ...) so a single change there covers all chipsets without per-driver edits.Planned fix (assumes the open questions resolve as recommended below)
Land in three PRs, in order, each independently mergeable and each leaving the RGBW path bit-exact unless explicitly noted.
PR 1 — Extract
colorimetric_response(refactor only, zero behavior change)New files:
src/fl/gfx/colorimetric_response.h— movescct_to_xy,xyY_to_XYZ,invert3x3,matvec3,barycentric_xy,build_source_matrix,nnls3,hermite_basis,quantize_u8,quantize_lut_cell, thekLut*constants, theLutInterpenum, and a new RGB-onlyEmitterProfile(see below) intonamespace fl::colorimetric_response.src/fl/gfx/colorimetric_response.cpp.hpp— empty for now; reserved for shared cache-construction helpers if PR 2 needs them.rgbw_colorimetric.h/.cpp.hppkeep all RGBW-specific code:ProfileCache,solve_strict_subgamut*,solve_wx_lp_legacy,solve_wx_overdrive,solve_rgbcct, the W-extraction / boosted / RGBCCT logic. They#include "fl/gfx/colorimetric_response.h"and use the moved helpers viacolorimetric_response::xyY_to_XYZ(...)etc.Build-system: shared module compiles whenever either
FASTLED_RGBW_COLORIMETRICorFASTLED_RGB_COLORIMETRICis defined (new gate, see Open Question 1). With both undefined the file compiles to nothing (inline-only header). Existing_build.cpp.hppalready listsrgbw_colorimetric.cpp.hpp; add the new module the same way.Tests:
tests/fl/gfx/colorimetric_response.cpp— new. Exercises the moved helpers in isolation of any RGBW topology:cct_to_xyround-trip at 2700K/4000K/6500K against the gist's reference values,invert3x3/matvec3identities,build_source_matrixreproducing the published sRGB matrix from Rec.709 primaries + D65,nnls3on a known under-determined target,hermite_basisat t=0/0.5/1.tests/fl/gfx/rgbw_colorimetric.cpp— unchanged. Re-runs prove the extraction is bit-exact.Validation command:
bash test colorimetric_responseandbash test rgbw_colorimetric. Acceptance criterion #1 ("no intentional RGBW output changes") is met because every RGBW code path keeps calling the same functions via the new namespace.PR 2 — Split
EmitterProfileout ofDiodeProfileNew struct in
colorimetric_response.h:DiodeProfileinrgbw.his rewritten as the RGB profile plus the RGBW-only fields, preserving its current layout and field names so existing user code keeps compiling:The keep-current-layout constraint matters:
kRgbwDefaultProfileand user-built profiles get checked into firmware sketches; changing struct layout is a public-API break we should not take.as_rgb()is the public adapter for users who happen to have aDiodeProfileand want to drive an RGB strip with the same primaries.set_input_gamut(DiodeProfile*, InputGamut)gets anEmitterProfile*overload too, so the same named-gamut helper works for both profile shapes.Tests: extend
tests/fl/gfx/rgbw_colorimetric.cppwith one case provingDiodeProfile::as_rgb()produces the rightEmitterProfile. Existing tests untouched.PR 3 — RGB colorimetric solve + pixel-load integration
New solver entrypoint in
colorimetric_response.h(definition.cpp.hppgated byFASTLED_RGB_COLORIMETRIC):Implementation is small: with no W diode there is no LP / boosted / RGBCCT mode. The strict path is
out_rgb = P_RGB_inv * (M_src * source_rgb)with native single-axis identity and a non-negative clamp at the end. Reusebuild_source_matrix,invert3x3,matvec3from the shared module.Public surface in
rgbw.h(or a newcolorimetric.hif we want the symmetry):Pixel-load hook in
pixel_controller.h:581:This places the solve after correction/temperature/brightness/gamma (which are baked into
mColorAdjustment.premixedbeforeloadAndScale*runs) and before the chipset takes the bytes off the iterator — same shape the RGBW path already enforces. No driver edits required.Tests (
tests/fl/gfx/rgb_colorimetric.cpp, new):(255,0,0) -> (255,0,0), etc.loadAndScaleRGB; assert byte-for-byte equality withsolve_rgb_colorimetric(premixed)when brightness and correction are non-trivial. This is the closest thing to a falsifiable validation case the issue admits, and it directly proves the structural invariant the issue is asking for.Validation commands:
bash test rgb_colorimetric— unit-level pass.bash test --cpp— full host suite, proves RGBW path unchanged.bash compile uno --examples Blink— proves the RGB gate is off by default and the AVR build is unaffected (no float math leaks in).bash compile esp32dev --examples Blinkand similar — proves the gate works when enabled.Reproduction status
N/A. This is a design / new-feature issue, not a bug report. There is no reporter command, no error message, and no current behavior misbehaving. The acceptance-criterion #6 test described in PR 3 is the closest thing to a falsifiable validation hook, and it is constructive rather than reproductive.
Open questions for the maintainer
These are the three questions the issue itself raises; my recommendation on each, plus the rationale:
Compile gate. Recommend a new
FASTLED_RGB_COLORIMETRICgate distinct fromFASTLED_RGBW_COLORIMETRIC. The RGBW gate currently pulls in the LP / boosted / RGBCCT solvers + LUT machinery; an RGB-only user shouldn't pay that flash cost. The sharedcolorimetric_responsemodule compiles when either gate is on. Both gates default to undefined; today's RGBW behavior is preserved bit-exact.Gamma/power and what the RGB entrypoint accepts. Recommend the entrypoint accepts already-final linear source values. The solver model documented in
rgbw_colorimetric.h:11-15already says "Input RGB is treated as linear-light source-gamut coordinates," and the RGBW path inherits gamma + correction + temperature + brightness viamColorAdjustment.premixed. Re-applying gamma inside the solve would break linearity assumptions the math model depends on. The pixel-load hook in PR 3 above sits at the exact point where this is naturally true.Public API shape for RGB source gamut + measured emitter profile. Recommend a separate
EmitterProfilestruct (and a separateset_rgb_colorimetric_profile) rather than overloadingDiodeProfile.DiodeProfilecarriesxy_w/lum_w/nominal_cctwhich are meaningless for an RGB strip; conflating them encourages users to set ignored fields.DiodeProfilekeeps its current layout (public-API compatibility) and gets anas_rgb()adapter.set_input_gamut()gets anEmitterProfile*overload so the named-gamut machinery is shared.A fourth question that the issue doesn't pose but matters for binary cost:
NativeorRec709? Today's default RGBW profile (kRgbwDefaultProfile) ships asNativeso saturated inputs reach the LED at full drive. The same default is the right call forkRgbDefaultProfile—(255,0,0)lights the red diode at full power, no surprises for first-time users.Risks and alternatives considered
DiodeProfilebreaks user firmware. Mitigated by keepingDiodeProfile's field layout identical to today and introducingEmitterProfileas a separate, narrower struct.#if FASTLED_RGB_COLORIMETRICgate so sketches that don't define it pay literally zero cost; when defined, thergb_colorimetric_enabled()predicate is a single bool load that gc-sections folds out for sketches that never callenable_rgb_colorimetric().kColorimetricmode onRGBW_MODE(rejected). RGB strips don't have an RGBW mode enum to begin with — they're driven throughloadAndScaleRGB. The cleanest control surface is a separate enable/disable plus an installableEmitterProfile, mirroring how RGBW does it.Next step
I'd like a
+1 / -1on the four answers above (especially Q1 — the gate question — since it shapes how PR 1 lays the build files down). Once those land, the three PRs above can be implemented in order; PR 1 and PR 2 are safe refactors with zero behavior change and can ship first while we iterate on PR 3's exact public-surface naming.If any of those four feel like they need more thinking-time, happy to spin out a
feat-design:issue per question so the discussion isn't all stacked here.cc related: #2748, #3231.
zackees commentedon Jun 18, 2026
Follow-up to my report above: at @zackees's request, here are three candidate answers per open question, plus a recommendation. Each candidate is stated as a position someone could reasonably defend so the tradeoffs are explicit instead of buried in prose.
Q1 — Compile gate
A. Share the existing
FASTLED_RGBW_COLORIMETRICgate.The gate flips on the whole
colorimetric_*family; RGB is just a new entrypoint that compiles when the existing flag is on.src/fl/gfx/rgbww.cpp.hpp:170andexamples/RGBWW/RGBWW.ino:14keep working as-is).rgbw_colorimetric.cpp.hpp's 1,075 lines). On AVR/ESP8266 that's exactly the cost the gate exists to keep off the board.B. Dedicated new gate
FASTLED_RGB_COLORIMETRIC; shared module compiles when either gate is on.Each solver gates only itself. The new
colorimetric_responsemodule's gate is#if FASTLED_RGBW_COLORIMETRIC || FASTLED_RGB_COLORIMETRIC.FASTLED_HD_COLOR_MIXING,FASTLED_FORCE_SOFTWARE_SPI, etc. — one knob per feature).FASTLED_RGB_COLORIMETRICfind the RGB path, not the RGBW one.C. Umbrella gate
FASTLED_COLORIMETRICwith auto-derived sub-gates*_RGB / *_RGBW / *_RGBWW.One opt-in flips on the shared module; sub-gates select which solvers compile. The existing
FASTLED_RGBW_COLORIMETRICbecomes a backward-compat alias.Recommendation: B. Lowest-blast-radius option that satisfies the binary-size requirement in acceptance criterion #7 ("MCU-friendly, no unnecessary binary-size cost"). C is over-engineered for one feature; A leaks RGBW machinery into RGB-only sketches.
Q2 — Gamma/power and what the RGB entrypoint accepts
A. Accept already-final linear source values.
Solve sits between
loadAndScale{0,1,2}(which applymColorAdjustment.premixed= correction × temperature × brightness) and the chipset byte emit. This is the same structural position the RGBW path uses atsrc/pixel_controller.h:615.rgbw_colorimetric.h:11-15("Input RGB is treated as linear-light source-gamut coordinates") —mColorAdjustment.premixedis linear in 8-bit space, no gamma encoding is applied to it.loadAndScaleRGB.mColorAdjustmentstaying linear in the future. Mitigation: this risk already exists for RGBW and would need to be solved for both at once, not just for RGB.B. Fold gamma/power into an explicit pre-solve adjustment stage.
Introduce
pre_solve_adjust(CRGB&)insideloadAndScale*that applies brightness/correction/temperature/gamma in a documented order, then calls solve, then emits.loadAndScale*— HD color mixing applies a five-bit HD gamma at emit time (src/fl/gfx/five_bit_hd_gamma.h), and user-set gamma is applied earlier in user code. Forcing a pre-solve gamma stage requires reorganizing how HD color mixing interacts with the colorimetric path.pixel_controller.hto a reorganization ofmColorAdjustmentand HD gamma plumbing.C. Accept raw
CRGBand re-apply correction/temperature/brightness/gamma inside the solver.The solver becomes a single black box: feed it the user-set pixel and the active adjustment policy, get out the emitter drive.
loadAndScale*infrastructure that every chipset is wired to.mColorAdjustment+ brightness into the solver call site — a public-API expansion for the colorimetric API.Recommendation: A. Smallest mechanism that satisfies the issue's stated invariant. The solver's documented input model already says linear source-gamut coordinates,
mColorAdjustment.premixedalready is linear, and the hook point exists. B is the alternative-by-symmetry but the bigger refactor doesn't buy anything users can feel; C is strictly worse.Q3 — Public API shape for RGB source gamut + measured emitter profile
A. Separate
EmitterProfilestruct + parallelset_rgb_colorimetric_profile()API;DiodeProfilekeeps its current layout and gains anas_rgb()adapter.The RGB struct contains R/G/B chromaticity + luminance + source-space input_xy_*.
DiodeProfilekeepsxy_w/lum_w/nominal_cctfor RGBW use.xy_where even mean" question.set_rgb_colorimetric_profile,get_rgb_colorimetric_profile,kRgbDefaultProfileline up 1:1 with the RGBW equivalents.DiodeProfileget a one-call adapter (profile.as_rgb()).set_input_gamut()picks up anEmitterProfile*overload — trivial.B. Single
DiodeProfilefor both; the RGB solver simply ignoresxy_w/lum_w/nominal_cct.set_rgb_colorimetric_profile(const DiodeProfile*)reuses the same struct.xy_wfor my SK6812 RGB strip, why doesn't it change anything?".DiodeProfile's public surface has to think about both modes.C. New composite
ColorimetricProfilestruct with an explicithas_wdiscriminator; both solvers read from it.One struct, runtime-discriminated, prepared for RGBWW / RGBCCT extension.
DiodeProfile— every sketch withkRgbwDefaultProfilereferences either breaks or needs an alias.kRgbwDefaultProfileis already a non-trivial constant; doubling it for a discriminator users never read is wasteful.has_wfor every per-pixel call (cheap, but adds code on the hot path).Recommendation: A. Strict separation keeps each surface sharp; the one-line
as_rgb()adapter handles the "I already have aDiodeProfile" migration; named-gamut helper picks up an overload (trivial). B's silent-ignore behavior is the standard "ergonomic shortcut, future-maintenance trap" pattern; C is architecturally aspirational for a problem we don't have.Q4 — Default RGB profile gamut (not posed by the issue but matters)
A. Native LED gamut + D65 white (mirror today's
kRgbwDefaultProfile).(255,0,0)reaches full red diode drive; users get no surprise color shift when they enable the new mode.set_input_gamut(profile, InputGamut::Rec709)is called).B. Rec.709 / sRGB.
(255,0,0)no longer reaches full red diode drive — surprise color shift for users who enable the gate "just to try it."C. Track the active RGBW profile's input gamut when both gates are on; Native otherwise.
Recommendation: A. Consistency with the existing RGBW default outweighs out-of-the-box visible benefit, and users who want sRGB semantics already have
set_input_gamut(profile, InputGamut::Rec709)one call away. Defaulting to a behavior change is a quiet migration trap.Net answer
FASTLED_RGB_COLORIMETRIC, shared module compiles when either gate is onEmitterProfilestruct + parallel setter,DiodeProfile.as_rgb()adapterIf those four land, PR 1 (extract
colorimetric_response) and PR 2 (splitEmitterProfile) are pure refactors with byte-identical RGBW output, safe to ship while we iterate on PR 3's exact public-surface naming. Happy to open them in that order once you give a +/-1.cc related: #2748, #3231.
JChalka commentedon Jun 18, 2026
You should slow down a bit until I finish and verify my work, finding an RGB entrypoint makes sense but it should not bring in color temperature correction as the colrimetric response already handles this, I also already am handling the split from RGBW to a shared colorimetric_response.h/cpp.hpp : JChalka@2e2d051#diff-a299db0de2f120c537a91456ce343c396a95486adb04fd4ef5f19b58108ee6df
JChalka@a7a0cab
You do not have the means to verify this unless you have a colorimeter or spectrophotometer and this is work that needs to be verified with real measurements, I appreciate the excitement but these measurements take time and I'm already mid-implementation and have phases laid out
zackees commentedon Jun 19, 2026
Design discussion resolved. Implementation contract filed as #3255 — captures the consolidated plan (no compile gate, per-strip
fl::variant<RGBW_MODE, ColorimetricMode>+fl::shared_ptr<const DiodeProfile>, tier-gated onFL_PLATFORM_HAS_TINY_MEMORY, clean break on the enum entries, three-PR phasing). Closing this when #3255 lands.zackees commentedon Jun 28, 2026
Closing after pushing the current RGBW colorimetric codec/profile API and example in draft PR #3435: #3435