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¶
Available APIs¶
- color.map.builtin and its convenience methods return continuous maps.
- color.map.fromStops, color.map.fromPalette and color.map.fromGPUTextureView create maps from caller data.
- color.palette.builtin supplies categorical maps and color.palette.swatch selects an individual color.
- color.parse, color.srgbToLinear and linearToSrgb and color.toOklab and fromOklab convert color representations.
- color.domain maps a complex value to a color.
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.