Skip to content

feat(color): let HD108 consume the device drive too (P8, #4042/#4326) - #4387

Merged
zackees merged 2 commits into
masterfrom
feat/4042-hd108-wide
Sep 12, 2026
Merged

zackees merged 2 commits into
masterfrom
feat/4042-hd108-wide

Conversation

@zackees

@zackees zackees commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

Completes the wide-output work #4368 started, for the other native 16-bit chipset. Part of #4034 P8 (#4042), "encoders consume wide output directly".

#4326 called HD108 "the same shape and worse". hd108GammaCorrect is a hardcoded 2.8 inside the encoder, so unlike UCS7604's mGamma.value_or(2.8f) no caller could ever have chosen otherwise — and writeHD108 took no settings at all, so the information needed to suppress it was not in scope.

Measured

On a managed channel HD108 put 849 on the wire where the device solve asked for 13933 — the identical number the UCS7604 path produced before #4368. It now puts 13935.

Confirmed causally rather than by inspection: disabling the wide branch returns the case to 849 > 13900 failing.

Notes

  • isManaged(), not hasColorProfile() — the distinction established in feat(color): let the 16-bit encoder consume the device drive (P8, #4042/#4326) #4368's review. A rejected binding leaves the legacy controller in place while the options still report a profile; taking the no-gamma path over its 8-bit pixels would drop a stage that path still needs.
  • The loop is inline in writeHD108 rather than an encodeHD108_wide in hd108.h. That header is included by pixel_iterator.h, before the class exists, and a concrete PixelIterator& parameter is not a dependent type — so the body would be checked there and fail. That is the same property that made the UCS7604 wide encoder a hard compile error on TINY until it was guarded, so it is worth stating rather than rediscovering.
  • TINY pays 0 B — verified by compiling the header with FL_PLATFORM_HAS_TINY_MEMORY=1.

Flash

+240 B, baseline moved to 342954 with the symbol diff recorded in the file:

+255  PixelIterator::writeHD108<vector_psram<u8>>
 +72  PixelIterator::loadAndScaleRGB16
      (minus ~87 B recovered elsewhere)

loadAndScaleRGB16 was inlined into its single caller; with a second one it is emitted once and called twice, which is the cheaper arrangement. Measured with fbuild symbols on the ELF the build produced — bash bloat --build used to analyse a different one, fixed in #4386.

Tests

Two cases: the managed path emits the drive while the unbound path still saturates at 65535 through the legacy curve, and black stays black on both — so a difference above can only be shaping, not an offset.

bash lint clean; 305/305 unit, 84/84 examples.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Summary by CodeRabbit

  • Bug Fixes

    • Improved HD108 LED output for color-managed streams, providing more accurate brightness and color handling.
    • Preserved existing encoding behavior for unbound or legacy color streams.
    • Ensured black output remains correctly represented as zero across both color-processing paths.
  • Tests

    • Added coverage validating HD108 output for managed, legacy, and black-pixel scenarios.
    • Updated embedded build-size tracking to reflect the encoding improvements.

zackees and others added 2 commits September 11, 2026 21:25
The other native 16-bit chipset, and #4326 called it "the same shape and
worse". `hd108GammaCorrect` is a hardcoded 2.8 inside the encoder, so unlike
UCS7604's `mGamma.value_or(2.8f)` no caller could ever have chosen otherwise,
and `writeHD108` took no settings at all -- the information needed to suppress
it was not in scope.

Measured on a managed channel it put 849 on the wire where the device solve
asked for 13933, the identical number the UCS7604 path produced before #4368.
It now puts 13935. Confirmed causally: disabling the wide branch returns the
case to 849.

`writeHD108` takes the iterator's own `isManaged()` -- not
`settings.hasColorProfile()`, for the reason established in #4368: a rejected
binding leaves the legacy controller in place while the options still report a
profile, and taking the no-gamma path over 8-bit pixels would drop a stage that
path still needs.

The wide loop is inline in `writeHD108` rather than an `encodeHD108_wide` in
hd108.h. That header is included *by* pixel_iterator.h, before the class
exists, and a concrete `PixelIterator&` parameter is not a dependent type, so
the body would be checked there and fail -- the same property that made the
UCS7604 wide encoder a hard error on TINY until it was guarded.

+240 B on an ESP32-S3 Blink build, baseline moved with the symbol diff
recorded: +255 B for the inlined loop, +72 B for `loadAndScaleRGB16` which now
has two callers and is emitted once rather than inlined into one. A
tiny-memory target pays 0 B, verified by compiling the header with
FL_PLATFORM_HAS_TINY_MEMORY=1.

Two tests: the managed path emits the drive and the unbound path still
saturates at 65535 through the legacy curve, and black stays black on both so
a difference can only be shaping rather than an offset.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Sep 12, 2026
@zackees
zackees merged commit 522dedf into master Sep 12, 2026
24 checks passed
@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 1647f927-b2b7-4a47-842e-79da52d565e5

📥 Commits

Reviewing files that changed from the base of the PR and between 46537ca and 7440ca6.

📒 Files selected for processing (4)
  • src/fl/channels/channel.cpp.hpp
  • src/fl/chipsets/encoders/pixel_iterator.h
  • tests/data/esp32s3_bloat_baseline.txt
  • tests/fl/channels/channel.cpp

📝 Walkthrough

Walkthrough

HD108 encoding now receives color-management state. Managed sources use direct 16-bit RGB encoding with brightness scaling, while unmanaged sources retain legacy gamma encoding. Tests compare both paths and validate black output. The ESP32-S3 size baseline records the measured increase.

Changes

HD108 encoding

Layer / File(s) Summary
Managed HD108 encoding path
src/fl/chipsets/encoders/pixel_iterator.h, src/fl/channels/channel.cpp.hpp
writeHD108 accepts a managed-source flag. Managed sources use loadAndScaleRGB16, brightness scaling, and HD108 frames without fixed gamma correction. The channel passes iterator.isManaged().
Encoding validation and size baseline
tests/fl/channels/channel.cpp, tests/data/esp32s3_bloat_baseline.txt
Tests compare managed and legacy red output and verify black output. The ESP32-S3 baseline records the 240-byte image-size increase and implementation details.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Channel
  participant PixelIterator
  participant MockEngine
  Channel->>PixelIterator: Pass iterator.isManaged()
  PixelIterator->>PixelIterator: Encode managed RGB16 or legacy gamma path
  PixelIterator->>MockEngine: Emit HD108 frames
  MockEngine-->>Channel: Capture encoded bytes
Loading
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/4042-hd108-wide

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 12, 2026
zackees added a commit that referenced this pull request Sep 12, 2026
…ution (#4042) (#4388)

P8 owns "native 16-bit encoders consume wide output; monotonic; low-light
resolution". #4368 and #4387 did the first clause for UCS7604-16 and HD108;
nothing measured the other two.

Swept all 256 source codes through the UCS7604-16 path, managed and unbound
side by side. Both are monotonic -- a rising source code never lowers the
emitted value, zero violations either way -- so the wide path did not buy that
at the cost of ordering.

Where they part company is resolution. In the bottom 32 codes the managed path
keeps all 32 distinguishable; the gamma LUT collapses four pairs, so 28. Across
the full range, 256 against 252.

Worth stating plainly in the test, because the number invites a wrong reading:
this is not more *reachable* levels. An 8-bit CRGB can only ask for 256 things,
and it still can. It is that none of them are discarded on the way out. Turning
the 16-bit wire into more than 256 levels needs a wide source -- .fled
rgb16_linear -- and this is the half that stops throwing them away first.

The counts are measured, not assumed. Narrowing the managed drive to 8 bits and
widening it again fails these, as does disabling the wide branch.


Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Sep 12, 2026
…tial #4402) (#4403)

* perf(hd108): stop computing a constant brightness header per LED (#4402)

`hd108BrightnessHeader` discards its argument -- `(void)brightness_8bit`,
then three `constexpr` gains of 31 -- and returns 0xFF 0xFF for every
input. Both HD108 encode paths were doing work to feed it anyway.

`encodeHD108_HD` carried a per-LED cache (`lastBrightness8`, `lastF0`,
`lastF1`, plus a compare/branch) guarding against recomputing a value that
cannot change, and dereferenced `brightness_first` once per LED to feed it.
That read was the expensive half: the sole in-tree caller passes
`ScaledPixelIteratorBrightness`, whose `load()` is out of line, so it was a
function call per LED to fetch a number that reached nothing.

`writeHD108`'s managed path built that whole adapter -- `makeScaledBrightness`
plus a `load()` -- for the single purpose of passing a value into the same
discarding function.

Both are gone. The header is computed once per strip. Output is unchanged
by construction, not by measurement: every removed value fed only an
argument that is cast to void.

Why now: the esp32dev size gate has been red on master since #4387 at
340235 B against a frozen 340000 B ceiling. `ci/lint/check_size_thresholds.py`
exists because "CI agents have repeatedly tried to fix red size-check
workflows by raising the thresholds instead of fixing the underlying
regression", so the ceiling stays and the bytes come out of the code.
#4402 has the full diagnosis.

A new test pins the premise: HD108 output is byte-identical across
brightness 0, 255 and a 0->255 ramp, and the header really is the pinned
maximum rather than merely constant. Verified load-bearing -- making
`hd108BrightnessHeader` honour its argument fails it by name, along with
ten siblings that assert the pinned header.

The stale "brightness caching optimization" case is renamed to what it
actually checks, since the cache it was named for no longer exists.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

* perf(hd108): call one encoder, not two copies of the same one (#4402)

With the per-LED brightness read and its cache gone, `encodeHD108_HD` is
`encodeHD108` with an extra argument. Both walk `makeScaledPixelRangeRGB`,
both widen through `hd108GammaCorrect`, both frame with the same start and
latch, and both headers come from `hd108BrightnessHeader`, which pins every
gain at 31 whatever it is handed.

So a build with FASTLED_HD_COLOR_MIXING was carrying a second copy of one
function. `writeHD108` now calls `encodeHD108` on either branch and the
`#if` around the call site goes away.

`encodeHD108_HD` stays in hd108.h for source compatibility. A new test
asserts the two agree byte for byte across five pixels and five brightness
values, so the collapse cannot quietly stop being true -- if a real
per-LED brightness ever lands, that test fails and says so.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

* chore(bloat): lock in the 66 B the HD108 cleanup recovered (#4402)

The gate fails on an unexplained *drop* past its 64 B tolerance, which is
the ratchet asking for the win to be recorded rather than left as headroom.
342957 -> 342891.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@zackees
zackees deleted the feat/4042-hd108-wide branch November 5, 2026 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant