Function tryRgbPercentileStretchLut

Build a per-channel RGB8 contrast-stretch lookup table from two observed nearest-rank percentiles. Each channel maps its lower observed byte to 0, its upper observed byte to 255, and clamps outside that interval. Interior bytes use linear interpolation rounded to nearest integer, with ties up. If both percentiles select the same byte in a channel, that channel's entire table is the identity: no arbitrary black/white choice is made.

bool tryRgbPercentileStretchLut(
  ref const(RgbHistogram256) histogram,
  uint lowerPercentile,
  uint upperPercentile,
  ref ubyte[256][3] published
) pure nothrow @nogc @safe;

The histogram's binary mask, if any, selects pixels only for estimating these three pairs of thresholds. This table has no pixel-selection rule: a consumer decides which image pixels to transform. Applying it to stored RGB bytes does not perform colour management, gamma correction or alpha processing. The table is a fixed-size value; no raster is read and no allocation occurs. Invalid percentile order, an empty selection or a malformed public histogram record returns false and preserves published.

Parameters

NameDescription
histogram Completed RGB histogram returned by tryRgbHistogram256.
lowerPercentile Integer lower nearest-rank percentile in [0, 100].
upperPercentile Integer upper nearest-rank percentile in [0, 100], strictly greater than lowerPercentile.
published Mapping indexed as [channel][storedByte], assigned on success.

Returns

true when the full lookup table is published.