@pbroom/color-kitConversion

srgbToLinearInto

Convert sRGB (0-255) to linear RGB (0-1), writing into out (allocation-free). out may be the same object as rgb.

functionimport { srgbToLinearInto } from '@pbroom/color-kit';srgb.ts:27
function srgbToLinearInto(  out: LinearRgb, ,  rgb: Rgb,): LinearRgb;

Parameters

outLinearRgb
Object to write the result into
rgbRgb
sRGB color (0-255; not clamped)

Returns

LinearRgbout

Example

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

const linear = { r: 0, g: 0, b: 0, alpha: 1 };
srgbToLinearInto(linear, { r: 255, g: 128, b: 0, alpha: 1 });
linear.g; // → ≈ 0.2159

See also