Repository navigation
test(color): pin the HD encoders' monotonicity, P8's own criterion (#4042) - #4289
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
hd108BrightnessHeaderdiscards 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 throughmakeScaledPixelRangeRGB, 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 0xFFfor 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] & 0x1Fas 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
Full suite green: 302/302 unit, 84/84 examples.
bash lintclean.Noted, not fixed
encodeHD108'sglobal_brightnessparameter is accepted, documented at the public entry as "Global 8-bit brightness (0-255)", and never used — onlyencoder_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