@pbroom/color-kit/interopWriters
toP3Array
Write a color as gamma-encoded Display P3 [r, g, b], 0–1 in gamut, for display-p3 canvases and WebGPU contexts configured with colorSpace: 'display-p3'.
import { toP3Array } from '@pbroom/color-kit/interop';writers.ts:374function toP3Array(
color: Color,
out?: undefined,
offset?: number,
options?: ArrayWriteOptions,
): ColorTuple;
function toP3Array<T extends WritableArrayLike>(
color: Color,
out: T,
offset?: number,
options?: ArrayWriteOptions,
): T;
function toP3Array<T extends WritableArrayLike>(
color: Color,
out: T | undefined,
offset?: number,
options?: ArrayWriteOptions,
): ColorTuple | T;Values are unclamped floats by default, so out-of-gamut colors produce channels outside 0–1 (correct for HDR/linear pipelines, and what three.js does). Pass { clamp: true } to clip, or gamut-map first to reduce chroma instead: toP3Array(toSrgbGamut(color), out) (or toP3Gamut).
Overload 1 of 3
Parameters
- out?
undefined - Destination (
number[],Float32Array, ...). When omitted a newColorTupleis returned. - offset?
number - Index in
outof the first component to write. - options?
ArrayWriteOptions - Out-of-gamut handling (
clamp).
Returns
ColorTupleout, or a new tuple when out is omitted.
Overload 2 of 3
Parameters
- out
T - Destination (
number[],Float32Array, ...). When omitted a newColorTupleis returned. - offset?
number - Index in
outof the first component to write. - options?
ArrayWriteOptions - Out-of-gamut handling (
clamp).
Returns
Tout, or a new tuple when out is omitted.
Overload 3 of 3
Parameters
- out
T | undefined - Destination (
number[],Float32Array, ...). When omitted a newColorTupleis returned. - offset?
number - Index in
outof the first component to write. - options?
ArrayWriteOptions - Out-of-gamut handling (
clamp).
Returns
ColorTuple | Tout, or a new tuple when out is omitted.
Example
toP3Array(parse('#ff8800')); // => [c0, c1, c2]
// Write into an existing buffer, starting at element 6.
toP3Array(color, buffer, 6);Also exported from
@pbroom/color-kitthe same declaration, re-exported