Skip to content

feat(fled): let the builder emit video.color - #4164

Merged
zackees merged 1 commit into
masterfrom
feat/color-p4-producer
Sep 6, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/color-p4-producer

Conversation

@zackees

@zackees zackees commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

Completes the producer half of #4038 (Color pipeline P4), under #4034.

The gap

#4160 landed the parser half: .fled files carry video.color and the parser validates it against the header's pixel format. But FledBuilder had only setScreenMapJson() and setChannelsJson() — no way to declare a source color tuple. The only way to emit one was to hand-write the envelope JSON, which is precisely the producer/parser drift the spec exists to prevent.

#4038 names the producer in both halves of its definition:

Scope: bring mirror, builder, parser (src/fl/fled/detail/parser.cpp.hpp), and video consumer to the same contract

Acceptance: .fled spec/producer/mirror/parser/playback carry and honor video.color

What this adds

FledBuilder::setVideoColor(const VideoColor&), writing the tuple under video.color with the spelling FLED_FORMAT.md defines.

Three choices worth calling out, because each is a place this could rot:

  • Wire spellings are literals in the serializer, not derived from the enumerators. Renaming a C++ enum must not silently change the file format.
  • All four keys are always written, never a partial object. Inheritance of missing keys applies only to pixel formats that define a default tuple, and a producer should not have to reason about which those are.
  • matrix and range are emitted literally as the single value v1 permits for each, so producer and parser cannot drift apart.

Custom primaries serialize as CIE xy pairs at four decimals — enough for the D65 white point (0.3127, 0.3290) to round-trip exactly.

Tests

All build through the canonical Fled::loadFromVector() path and read back via Fled::videoColor(), so they exercise the real parse, not a private hook:

case asserts
each named primaries value bt709 / display-p3 / bt2020 survive with their transfer
custom primaries eight xy floats round-trip within 1e-4
no setVideoColor() call resolves to the default tuple with declared == false
rgb8 + linear transfer parser returns TransferConflictsWithFormat

That last one matters: a producer must not be able to emit a tuple its own parser rejects, and this proves the rejection is reachable from the builder.

Confirmed by mutation — spelling DisplayP3 as "bt709" in the serializer fails the round-trip test at fled_builder.cpp:81, so the tests genuinely exercise the serializer rather than passing vacuously.

Verification

  • bash test --cpp — 287/287 unit, 84/84 examples
  • bash lint — clean

Not in this PR

The canonical ledmapper v1 spec lives in another repo; this changes FastLED's mirror and producer only.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Summary by CodeRabbit

  • New Features

    • Added optional video color metadata configuration when building FLED content.
    • Video color information now supports primaries, transfer characteristics, matrix, range, and custom color coordinates.
    • Configured metadata is included in the generated video description and can be read back through the standard parsing flow.
  • Bug Fixes

    • Conflicting video color settings are rejected during parsing.
    • When no video color is specified, the metadata remains undeclared and uses default values.

#4160 landed the parser half of #4038: `.fled` files carry `video.color` and
the parser validates it. The producer half was missing. `FledBuilder` had
`setScreenMapJson()` and `setChannelsJson()` but no way to declare a source
color tuple, so the only way to emit one was to hand-write the envelope JSON
-- which is exactly the drift the spec exists to prevent.

#4038 lists the producer in both its scope ("bring mirror, builder, parser,
and video consumer to the same contract") and its acceptance criterion
(".fled spec/producer/mirror/parser/playback carry and honor video.color").

`setVideoColor(const VideoColor&)` writes the tuple under `video.color` with
the spelling FLED_FORMAT.md defines. Three choices worth stating:

  - The wire spellings are literals in the serializer, not derived from the
    enumerators, so renaming a C++ enum cannot silently change the format.
  - All four keys are always written. Partial-tuple inheritance applies only
    to pixel formats that define a default tuple, and a producer should not
    have to know which those are.
  - `matrix` and `range` are emitted literally as the single value v1 allows
    for each, so producer and parser cannot drift.

Custom primaries serialize as CIE xy pairs at four decimals, enough for the
D65 white point (0.3127, 0.3290) to survive the round trip exactly.

Tests build through the canonical Fled::loadFromVector() path and read back
with Fled::videoColor(), covering each named primaries value, custom
primaries, absent metadata resolving to the undeclared default, and a tuple
the producer can emit but the parser must reject (rgb8 + linear transfer).
Confirmed by mutation: spelling DisplayP3 as "bt709" fails the round-trip.

Verified: `bash test --cpp` 287/287 unit + 84/84 examples, `bash lint` clean.

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

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 9f28b13c-744f-4f59-a485-98bb6f7b6179

📥 Commits

Reviewing files that changed from the base of the PR and between b436035 and 3894fd1.

📒 Files selected for processing (3)
  • src/fl/fled/builder.cpp.hpp
  • src/fl/fled/builder.h
  • tests/fl/fled/fled_builder.cpp

Included review availability: Your plan provides up to 8 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

FledBuilder now accepts optional VideoColor metadata, serializes it into the JSON envelope, and tests named, custom, conflicting, and omitted color configurations.

Changes

Video color metadata

Layer / File(s) Summary
Builder contract and serialization
src/fl/fled/builder.h, src/fl/fled/builder.cpp.hpp
Adds setVideoColor, serializes standard and custom color values, and emits the optional video.color JSON section during build().
Video color round-trip validation
tests/fl/fled/fled_builder.cpp
Tests named and custom color round trips, transfer conflicts, and default behavior when no color is declared.

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

Merge Risk: ⚪ Minimal · up to 3894f

Fled producers can now declare video color metadata, including named and custom primaries, while existing undeclared-color behavior remains unchanged. No concrete merge-blocking risk remains.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant FledBuilder
  participant JSONEnvelope
  Caller->>FledBuilder: setVideoColor(VideoColor)
  FledBuilder->>FledBuilder: serializeVideoColor()
  Caller->>FledBuilder: build()
  FledBuilder->>JSONEnvelope: buildEnvelope(videoColorJson)
  JSONEnvelope-->>Caller: JSON with video.color
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: enabling the Fled builder to emit video.color metadata.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/color-p4-producer

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.

@zackees
zackees merged commit 870d9da into master Sep 6, 2026
32 checks passed
@zackees
zackees deleted the feat/color-p4-producer branch September 6, 2026 21:25
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 6, 2026
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