Skip to content

WasmGPU.color

Summary

WasmGPU.color provides continuous colormaps, categorical palettes and color-space helpers. Access the same namespace through WasmGPU.color or wgpu.color. Standalone helpers such as parseColor are also available as named package exports.

Syntax

const color = WasmGPU.color;
const map = color.map.viridis();

Available APIs

Example

import WasmGPU from "@zushah/wasmgpu";

const map = WasmGPU.color.map.viridis();
const color = map.sampleCPU(0.5); // Linear RGBA
console.log(color);

Notes

Use the named Colormap class for the equivalent static factories. The class constructor accepts an options object with label, a positive integer width, a filter and optional lut or external data. For a CPU-backed map, lut is a Uint8Array of exactly width * 4 bytes in RGBA order, with sRGB RGB and linear alpha. Keep that input array immutable after construction. Prefer fromGPUTextureView for borrowed GPU resources.

Material and plot colors use linear RGB. Colormap input tables can accept sRGB colors, and CPU samples default to linear RGB so they match shader samples. Request sRGB samples from a map for display in CSS.

See Also