Skip to content

Meta: high-precision palette pipeline with CRGB16 support #2372

Closed

Description

@zackees

Summary

Palette lookup currently has partial high-precision support through ColorFromPaletteExtended(..., u16 index, ...), but the palette pipeline still loses precision in two important places:

  1. palette lookup returns CRGB, so channel precision is truncated to 8-bit after interpolation;
  2. several noise/palette helper paths downsample 16-bit source data into u8 buffers before color mapping.

With fl::CRGB16 now available, we should define a coherent high-precision palette path that preserves low-end brightness resolution and supports smooth slow fades, noise maps, palette cycling, and HD chipset output.

Background / related history

Current state

Code locations from current master:

  • src/fl/gfx/crgb16.h: CRGB16 exists as 8.8 fixed-point RGB channels.
  • src/fl/gfx/colorutils.h: palette types are still CRGBPalette16, CRGBPalette32, and CRGBPalette256, all storing 8-bit CRGB entries.
  • src/fl/gfx/colorutils.cpp.hpp: ColorFromPaletteExtended accepts u16 index, but returns CRGB.
  • src/noise.cpp.hpp: fill_noise16() and fill_2dnoise16() still route through u8 intermediate buffers in common display paths.
  • src/fl/chipsets/encoders/pixel_iterator.h: the RGB16 output adapter maps already-8-bit CRGB values to 16-bit with map8_to_16(), so it cannot recover precision lost before output.

Problem

ColorFromPaletteExtended solves palette address precision, but not channel precision. A high-precision source signal can still be quantized to 8-bit before or immediately after palette lookup.

That means users working with high-resolution noise, very slow fades, HD chipsets, antialiased effects, or low-brightness gradients can still see stepping/banding even though we now have both u16 indexes and CRGB16 available elsewhere in the library.

Proposed implementation plan

  • Add a high-precision palette lookup API, likely named one of:
    • ColorFromPaletteHD(...)
    • ColorFromPalette16(...)
    • ColorFromPaletteExtended16(...)
  • Initial overloads should accept existing palette types:
    • const CRGBPalette16&
    • const CRGBPalette32&
    • const CRGBPalette256&
    • possibly TProgmemRGBPalette16 and TProgmemRGBPalette32
  • Return CRGB16 instead of CRGB.
  • Use 16-bit or 8.8 fixed-point channel interpolation internally instead of scale8 math that truncates to u8.
  • Support high-precision brightness scaling, probably via u8x8 brightness or a separate overload.
  • Preserve existing ColorFromPalette and ColorFromPaletteExtended behavior for source compatibility.
  • Add tests that demonstrate sub-8-bit channel preservation across palette interpolation and brightness scaling.
  • Audit noise/palette helper paths and add high-precision variants that avoid fill_raw_*noise16into8 when the caller wants HD output.
  • Decide whether to add true high-precision palette storage types, e.g. CRGB16Palette16/32/256, after the lookup API lands.
  • Update docs/examples to show when to use standard palette lookup, extended u16 index lookup, and full CRGB16 lookup.

API design questions

  • Should the first implementation promote existing 8-bit palette entries to CRGB16 during lookup, or should it introduce CRGB16Palette* storage immediately?
  • Should brightness use u8, u16, u8x8, or overloads for compatibility?
  • Should CRGB16 results be convertible back to CRGB explicitly, or should palette helpers provide both HD and legacy return paths?
  • Should Gradient support colorAt16(u16) and/or colorAtHD(u16)?
  • Should fill_palette, fill_palette_circular, and map_data_into_colors_through_palette get HD variants, or should we keep the first PR limited to lookup primitives?

Acceptance criteria for first PR

  • A caller can map a u16 palette index to CRGB16 without truncating interpolated channel values to 8-bit.
  • Existing palette APIs remain source-compatible.
  • Tests cover at least:
    • CRGBPalette16 HD lookup between adjacent entries;
    • low-brightness scaling that preserves fractional channel values;
    • behavior at wrap/no-wrap boundaries;
    • comparison against current ColorFromPaletteExtended after explicit downconversion to CRGB.

Notes

This is not just about making palettes larger. A practical first step is preserving precision through lookup and brightness scaling. True CRGB16Palette* storage can follow once the API shape is validated.

Activity

  1. added
    status: triage
    area: core
    on Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: corestatus: triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions