Skip to content

test(color): pin the HD encoders' monotonicity, P8's own criterion (#4042) - #4289

Merged
zackees merged 1 commit into
masterfrom
test/4042-p8-hd-encoders-are-monotonic
Sep 10, 2026
Merged

zackees merged 1 commit into
masterfrom
test/4042-p8-hd-encoders-are-monotonic

Conversation

@zackees

@zackees zackees commented Sep 10, 2026

Copy link
Copy Markdown
Member

The one place monotonicity was not checked is the one place it could fail

P8 (#4042) owns the criterion "APA102/SK9822 HD + native 16-bit encoders consume wide output; monotonic; improved low-light resolution".

Monotonicity is already covered for the gamma LUTs (tests/fl/gfx/gamma_lut.cpp), the transfer functions and OKLab. It was not covered for the encoders — and they are where it is least obvious, because the five-bit path is a joint solve: an 8-bit code against a shared 5-bit current field. That shape is the classic source of reversal, since a one-step rise in the input can move the solver to a different field and land lower than it started.

It does not reverse

Measured over neutral ramps at six brightnesses, a channel rising under a pinned maximum, rising global brightness, and a non-uniform colors_scale: zero reversals.

What is measured is emitted light — code * field — not the code. An APA102-class part drives PWM duty times current field, so that product is the quantity a rising input must not reverse; checking the code alone would miss exactly the failure this is looking for.

And the joint solve is genuinely exercised: 31 of the 32 fields appear across a single neutral ramp. A vacuity case pins that, so the sweeps cannot quietly degrade into a test of the 8-bit code alone.

HD108 is a different shape, and saying so is half the value

hd108BrightnessHeader discards its brightness argument and pins all three gains to 31 — "maximum gain for all channels for maximum precision", with brightness applied to the 16-bit values before encoding. The only caller (pixel_iterator.h) passes 255 and pre-scales through makeScaledPixelRangeRGB, so the behaviour is correct.

But it means there is no field for a rising input to move, and HD108's monotonicity is that of its 16-bit code alone. The cases now assert that shape — the header is 0xFF 0xFF for gains of 31/31/31 — and then the code's monotonicity, read off the wire so byte order and offsets are covered too.

That distinction was not free. An earlier draft of this file read a gain nibble at encoded[8] & 0x1F as though HD108 had a per-input field. It is constant, so the sweep was trivially monotonic and passing. The vacuity guard is what caught it, and it is kept for that reason with the story in its comment.

Evidence

mutation result
drop the five-bit field by one on odd inputs 4 cases fail
pin the five-bit field constant 5 cases fail — the fifth is the vacuity guard, doing its job

Full suite green: 302/302 unit, 84/84 examples. bash lint clean.

Noted, not fixed

encodeHD108's global_brightness parameter is accepted, documented at the public entry as "Global 8-bit brightness (0-255)", and never used — only encoder_utils.h's helper says it is ignored. No live bug, since the sole caller passes 255 and pre-scales, but a caller using the template directly with another value would get no dimming. Left alone here rather than folded into a test PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

…4042)

P8 owns "APA102/SK9822 HD + native 16-bit encoders consume wide output;
monotonic; improved low-light resolution". Monotonicity was covered for the
gamma LUTs, the transfer functions and OKLab, but not for the encoders --
and they are where it is least obvious, because the five-bit path is a
*joint* solve of an 8-bit code against a shared 5-bit current field. That
shape is the classic source of reversal: a one-step rise in the input moves
the solver to a different field and lands lower than it started.

It does not reverse. Measured over neutral ramps at six brightnesses, a
channel rising under a pinned maximum, rising global brightness, and a
non-uniform `colors_scale`: zero reversals in emitted light, where emitted
light is `code * field` rather than the code, since an APA102-class part
drives PWM duty times current. The joint solve is genuinely exercised -- 31
of the 32 fields appear across a single neutral ramp, which a vacuity case
pins so the sweeps cannot quietly become a test of the 8-bit code alone.

HD108 turned out to be a different shape, and saying so is half the value
here. `hd108BrightnessHeader` discards its brightness argument and pins all
three gains to 31, with brightness applied to the 16-bit values before
encoding; the only caller passes 255 and pre-scales through
`makeScaledPixelRangeRGB`. So there is no field for a rising input to move,
and HD108's monotonicity is that of its 16-bit code alone. The cases assert
that shape -- the header is 0xFF 0xFF for gains of 31/31/31 -- and then the
code's monotonicity, read off the wire so byte order and offsets are covered
too.

That distinction was not free. An earlier draft read a gain nibble at
`encoded[8] & 0x1F` as though HD108 had a per-input field; it is constant,
so the sweep was trivially monotonic and passing. The vacuity guard caught
it, and is kept for that reason with the story in its comment.

Mutation-checked: dropping the five-bit field by one on odd inputs fails
four cases, and pinning the field constant fails five -- the fifth being the
vacuity guard, which is what it is for.

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 10, 2026
@zackees
zackees merged commit 0696290 into master Sep 10, 2026
4 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 10, 2026
@zackees
zackees deleted the test/4042-p8-hd-encoders-are-monotonic branch November 5, 2026 05:53
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