Repository navigation
Add CRGB16 palette lookup API - #2373
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdded a high-precision palette lookup API, ColorFromPaletteHD, returning CRGB16; implemented HD palette readers, 16-bit per-channel interpolation, and HD brightness scaling; added overloads for existing palette families (including progmem variants) and tests validating sub-8-bit precision and wrap behavior. Changes
Sequence Diagram(s)(No sequence diagrams generated — changes are internal API/implementation additions without a multi-component runtime interaction that benefits from a sequence diagram.) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsTimed out fetching pipeline failures after 30000ms 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. Comment |
📊 Header Compilation PerformanceTotal Time: 986.54ms Top 5 Slowest Headers
Warnings
Full Report |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/fl/gfx/colorutils.h (1)
1380-1472: Consider centralizing thefl::u8brightness conversion.The
brightness == 255 ? 256 : brightnessconversion is repeated across all inline overloads. A small helper would keep the public overload semantics in one place if this mapping changes later.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/fl/gfx/colorutils.h` around lines 1380 - 1472, Create a small centralized helper (e.g., a static inline function brightness_to_u8x8 or brightness_raw) that takes fl::u8 and returns the proper fl::u8x8 (or the raw fl::u16 then call fl::u8x8::from_raw inside the helper) implementing the existing mapping (brightness == 255 ? 256 : brightness); then replace the repeated expression in all inline overloads of ColorFromPaletteHD (the overloads taking CRGBPalette16, CRGBPalette32, TProgmemRGBPalette16, TProgmemRGBPalette32, CRGBPalette256 and any similar inline wrappers) to call that helper and pass its result to ColorFromPaletteHD, keeping signatures and behavior identical.tests/fl/gfx/colorutils_palette.cpp (1)
226-251: Strengthen the family-coverage assertions.The current
> 0checks prove the overloads are callable, but they would still pass if inactive channels became non-zero or progmem channel order regressed. Prefer exact/channel-specific assertions for expected raw values, and consider onefl::u8brightness overload assertion to cover the inline conversion path.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/fl/gfx/colorutils_palette.cpp` around lines 226 - 251, Replace the loose >0 checks with exact channel-specific assertions: for CRGBPalette16/32/256 use ColorFromPaletteHD(pal16,1,fl::u8x8(1),LINEARBLEND).r.raw() == 255 (and analogous equality == 255 for .g on pal32 and .b on pal256) to verify the correct channel and value; do the same for the progmem palettes kProgmemRgb16 and kProgmemRgb32 using the channel you expect to be 255; additionally add one assertion that calls the brightness overload (ColorFromPaletteHD with a fl::u8 brightness argument) to cover the inline conversion path and assert the expected channel raw value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/colorutils.h`:
- Line 41: The header re-exports ColorFromPaletteHD which returns CRGB16 but
CRGB16 itself isn't re-exported; add a using declaration for fl::CRGB16 (e.g.,
"using fl::CRGB16;") alongside the other palette type aliases in
src/colorutils.h so callers using the legacy API surface can access CRGB16
directly; ensure the new using is placed near the existing palette aliases where
ColorFromPaletteHD is exposed.
---
Nitpick comments:
In `@src/fl/gfx/colorutils.h`:
- Around line 1380-1472: Create a small centralized helper (e.g., a static
inline function brightness_to_u8x8 or brightness_raw) that takes fl::u8 and
returns the proper fl::u8x8 (or the raw fl::u16 then call fl::u8x8::from_raw
inside the helper) implementing the existing mapping (brightness == 255 ? 256 :
brightness); then replace the repeated expression in all inline overloads of
ColorFromPaletteHD (the overloads taking CRGBPalette16, CRGBPalette32,
TProgmemRGBPalette16, TProgmemRGBPalette32, CRGBPalette256 and any similar
inline wrappers) to call that helper and pass its result to ColorFromPaletteHD,
keeping signatures and behavior identical.
In `@tests/fl/gfx/colorutils_palette.cpp`:
- Around line 226-251: Replace the loose >0 checks with exact channel-specific
assertions: for CRGBPalette16/32/256 use
ColorFromPaletteHD(pal16,1,fl::u8x8(1),LINEARBLEND).r.raw() == 255 (and
analogous equality == 255 for .g on pal32 and .b on pal256) to verify the
correct channel and value; do the same for the progmem palettes kProgmemRgb16
and kProgmemRgb32 using the channel you expect to be 255; additionally add one
assertion that calls the brightness overload (ColorFromPaletteHD with a fl::u8
brightness argument) to cover the inline conversion path and assert the expected
channel raw value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 77a121c0-ec74-458b-8b1d-b907e562b00b
📒 Files selected for processing (4)
src/colorutils.hsrc/fl/gfx/colorutils.cpp.hppsrc/fl/gfx/colorutils.htests/fl/gfx/colorutils_palette.cpp
| using fl::TBlendType; | ||
| using fl::ColorFromPalette; | ||
| using fl::ColorFromPaletteExtended; | ||
| using fl::ColorFromPaletteHD; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Check whether CRGB16 is already re-exported into the legacy/global API surface.
# Expected: If only the struct definition is found and no `using fl::CRGB16;` exists,
# add the alias in src/colorutils.h next to the other color/palette aliases.
rg -n -C2 '\busing\s+fl::CRGB16\b|typedef\s+.*\bCRGB16\b|struct\s+CRGB16\b' --iglob '*.{h,hpp,cpp,cc}'Repository: FastLED/FastLED
Length of output: 468
🏁 Script executed:
#!/bin/bash
# Read src/colorutils.h to see the current palette type aliases and context around line 41
cat -n src/colorutils.h | head -60Repository: FastLED/FastLED
Length of output: 1990
🏁 Script executed:
#!/bin/bash
# Find ColorFromPaletteHD declaration to verify return type
rg -n -A5 'ColorFromPaletteHD' src/fl/gfx/colorutils.h | head -20Repository: FastLED/FastLED
Length of output: 1248
Re-export CRGB16 with the legacy API surface.
ColorFromPaletteHD is now exposed globally but returns CRGB16, which is not re-exported. Add using fl::CRGB16; near the other palette type aliases.
Proposed diff
using fl::CRGBPalette16;
using fl::CRGBPalette32;
using fl::CRGBPalette256;
+using fl::CRGB16;
using fl::CHSVPalette16;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/colorutils.h` at line 41, The header re-exports ColorFromPaletteHD which
returns CRGB16 but CRGB16 itself isn't re-exported; add a using declaration for
fl::CRGB16 (e.g., "using fl::CRGB16;") alongside the other palette type aliases
in src/colorutils.h so callers using the legacy API surface can access CRGB16
directly; ensure the new using is placed near the existing palette aliases where
ColorFromPaletteHD is exposed.
e10bebd to
5a6d4fc
Compare
📊 Header Compilation PerformanceTotal Time: 958.27ms Top 5 Slowest Headers
Warnings
Full Report |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/fl/gfx/colorutils_palette.cpp`:
- Around line 246-251: The test currently checks kProgmemRgb32's blue channel
which is non-zero at entry 0 and can mask a broken lookup; update the second
assertion to use the first 32-entry anchor and a channel that starts at zero so
the lookup must advance: call ColorFromPaletteHD(kProgmemRgb32, 32, fl::u8x8(1),
LINEARBLEND) and assert .g.raw() is > 0 (replace the existing kProgmemRgb32 call
and .b.raw() check accordingly).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 88f964d7-9466-40a2-be25-3fee74020842
📒 Files selected for processing (4)
src/colorutils.hsrc/fl/gfx/colorutils.cpp.hppsrc/fl/gfx/colorutils.htests/fl/gfx/colorutils_palette.cpp
✅ Files skipped from review due to trivial changes (1)
- src/colorutils.h
🚧 Files skipped from review as they are similar to previous changes (2)
- src/fl/gfx/colorutils.cpp.hpp
- src/fl/gfx/colorutils.h
| FL_CHECK_GT( | ||
| ColorFromPaletteHD(kProgmemRgb16, 1, fl::u8x8(1), LINEARBLEND).r.raw(), | ||
| 0u); | ||
| FL_CHECK_GT( | ||
| ColorFromPaletteHD(kProgmemRgb32, 1, fl::u8x8(1), LINEARBLEND).b.raw(), | ||
| 0u); |
There was a problem hiding this comment.
Strengthen the progmem RGB32 assertion.
kProgmemRgb32[0].blue is already non-zero, so this can pass even if the lookup never advances past entry 0. Check a channel that starts at zero and use the first 32-entry anchor instead.
Proposed test tightening
FL_CHECK_GT(
- ColorFromPaletteHD(kProgmemRgb32, 1, fl::u8x8(1), LINEARBLEND).b.raw(),
+ ColorFromPaletteHD(kProgmemRgb32, 0x0800, fl::u8x8(1), LINEARBLEND)
+ .r.raw(),
0u);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@tests/fl/gfx/colorutils_palette.cpp` around lines 246 - 251, The test
currently checks kProgmemRgb32's blue channel which is non-zero at entry 0 and
can mask a broken lookup; update the second assertion to use the first 32-entry
anchor and a channel that starts at zero so the lookup must advance: call
ColorFromPaletteHD(kProgmemRgb32, 32, fl::u8x8(1), LINEARBLEND) and assert
.g.raw() is > 0 (replace the existing kProgmemRgb32 call and .b.raw() check
accordingly).
5a6d4fc to
d189e06
Compare
📊 Header Compilation PerformanceTotal Time: 1002.29ms Top 5 Slowest Headers
Warnings
Full Report |
d189e06 to
dfbc608
Compare
📊 Header Compilation PerformanceTotal Time: 1202.59ms Top 5 Slowest Headers
Warnings
Full Report |
Summary
Addresses the first PR-sized slice of #2372 by adding
ColorFromPaletteHD(...), a high-precision palette lookup path that returnsfl::CRGB16.ColorFromPaletteHDoverloads forCRGBPalette16,CRGBPalette32,CRGBPalette256,TProgmemRGBPalette16, andTProgmemRGBPalette32u8x8/ 8.8 fixed-point channel precisionColorFromPaletteandColorFromPaletteExtendedbehavior unchangedFixes #2372 for the initial lookup API slice.
Test
diff --check also passes.
Summary by CodeRabbit