`stretch_linear()` clips to quantile bounds then linearly rescales, this is
the workhorse default.
`stretch_log()` applies `log1p` after shifting values to be non-negative,
then linearly rescales. Useful for data with high dynamic range (e.g.
overview-resolution satellite imagery where integer counts span several
orders of magnitude).
`stretch_sqrt()` applies square-root after shifting, gentler compression
than log, a good middle ground.
`stretch_histeq()` maps values to their empirical quantile rank, producing
an approximately uniform distribution. Good for scenes with detail in both
deep shadow and bright areas simultaneously.
By default the clip bounds are quantiles of the data itself, so the result
is scene-dependent. Use 'lim' to give absolute bounds in data units instead
(for example 'lim = c(0, 3000)' for Sentinel-2 surface reflectance), which
fixes the mapping so that it is stable across tiles and timesteps (no seams
in mosaics, no flicker in animations). When 'lim' is set the quantile
arguments are ignored.
Values that stretch outside [0, 1] are clamped. Non-finite input values
(NA, NaN) are returned as NA; constant input maps to 0.5.
For multi-band data (e.g. RGB), apply per-band for maximum per-channel
contrast, or pool all bands into one vector for a joint stretch that
preserves inter-band luminance relationships.