@pbroom/color-kitGamut

isLinearRgbInGamut

Returns whether unclamped linear-light RGB channels (linear sRGB or linear Display P3, which share the sRGB transfer function) lie inside the unit cube, allowing GAMUT_EPSILON of slack on the gamma-encoded channels: each channel must be within [GAMUT_LINEAR_MIN, GAMUT_LINEAR_MAX].

functionimport { isLinearRgbInGamut } from '@pbroom/color-kit';membership.ts:93
function isLinearRgbInGamut(  r: number, ,  g: number, ,  b: number,): boolean;

This is the membership rule behind inSrgbGamut / inP3Gamut, exposed for hot loops (e.g. per-pixel canvas rendering) that already hold linear channels and want to avoid re-converting from OKLCH. Allocation-free.

Parameters

rnumber
Linear red channel.
gnumber
Linear green channel.
bnumber
Linear blue channel.

Returns

boolean

Example

TypeScript
import { isLinearRgbInGamut } from '@pbroom/color-kit';

isLinearRgbInGamut(0, 0.5, 1); // → true
isLinearRgbInGamut(1.0001, 0.5, 0.2); // → true (within the epsilon slack)
isLinearRgbInGamut(-0.001, 0, 0); // → false