ltk::theme

Module gradient_lut

Source
Expand description

CPU-side gradient sampling and LUT baking.

The GPU gradient path in gles_render shaders samples a 1D lookup texture baked on the CPU: for each gradient we precompute N equally spaced samples across an extended t domain (so stops outside [0, 1] are covered without extra shader logic), already colour-space converted, and upload those N × 4 bytes as an RGBA8 texture.

§Extrapolation

Stops whose position falls outside [0, 1] are supported by linear extrapolation: below the first stop we prolong the (first, second) slope, above the last stop we prolong the (last-1, last) slope. Values are not clamped. This is the physically correct behaviour for CSS linear-gradient stops defined with positions outside the visible range.

§Colour spaces

GradientSpace::Srgb interpolates raw sRGB channels (cheap, looks muddy on saturated gradients). GradientSpace::LinearRgb — the default — converts each stop to linear light, interpolates, and converts the result back to sRGB. GradientSpace::Oklab is not yet implemented and silently falls back to LinearRgb.

Constants§

  • Extended t domain the LUT covers. Wide enough to comfortably contain the typical out-of-[0, 1] stops produced by design-tool exports.
  • How many samples the LUT stores along the t axis.

Functions§

  • Build an RGBA8 LUT of LUT_SAMPLES equally spaced samples spanning LUT_DOMAIN. The returned vector has LUT_SAMPLES * 4 bytes in straight-alpha, row-major. The GPU shader expects this layout and premultiplies at sample time.
  • Convert one linear-light channel to sRGB gamma-encoded.
  • Sample the stops at position t using the requested interpolation space. Stops need not be sorted. t may fall outside [0, 1].
  • Convert one sRGB gamma-encoded channel to linear light.