linearToSrgbChannel
sRGB / Display P3 transfer function (gamma encoding): linear light to gamma-encoded, for one channel.
import { linearToSrgbChannel } from '@pbroom/color-kit';index.ts:164function linearToSrgbChannel( c: number,): number;Extended range, as in CSS Color 4 and colorjs.io: negative inputs are mirrored (f(-x) = -f(x)) and values above 1 follow the same curve, so out-of-gamut linear values stay invertible instead of being folded or clipped. In-range [0, 1] inputs are unaffected. Callers that need a displayable channel clamp the result themselves.
Parameters
- c
number - Linear-light channel value (nominally
0-1)
Returns
numberGamma-encoded channel value
Example
import { linearToSrgbChannel } from '@pbroom/color-kit';
linearToSrgbChannel(0.5).toFixed(4); // → '0.7354'
linearToSrgbChannel(-0.5).toFixed(4); // → '-0.7354'