Skip to main content

Crate okpalette

Crate okpalette 

Source
Expand description

Fast, deterministic categorical color palette generation.

Use generate_palette and extend_palette for the common defaults, or configure a reusable PaletteGenerator. Colors are returned as Rgb8 values so callers can choose their own serialization or rendering format.

use okpalette::{BackgroundContrast, PaletteGenerator, Rgb8};

let palette = PaletteGenerator::new()
    .backgrounds([Rgb8::new(255, 255, 255)], BackgroundContrast::Normal)
    ?
    .generate(8)?;

Structs§

CandidateConstraints
Optional validated bounds applied when constructing candidate colors.
ChromaRange
Validated inclusive OKLCH chroma bounds.
DistanceWeights
Relative weights for squared distance in OKLab space.
HueRange
Validated inclusive OKLCH hue bounds, which may wrap around zero.
LabelPaletteRequest
Input for position-aware label palette generation.
LightnessRange
Validated inclusive OKLab lightness bounds.
Oklab
A color in OKLab space.
Oklch
A color in cylindrical OKLCH space.
PaletteGenerator
Configuration for generating palettes.
Rgb8
An 8-bit sRGB color.

Enums§

BackgroundContrast
The strategy used to keep generated colors distinct from a background.
ColorblindMode
Color-vision-deficiency simulations included when comparing colors.
GridSize
Resolution of the RGB candidate grid searched by a PaletteGenerator.
OkPaletteError
Errors returned while validating inputs, generating palettes, or rendering previews.

Functions§

extend_palette
Extend a palette with the same defaults as the Python API and CLI.
generate_palette
Generate a palette with the same defaults as the Python API and CLI.
parse_hex_color
Parse RGB, #RGB, RRGGBB, or #RRGGBB ASCII hexadecimal notation.
render_palette_png
Render a palette as RGB PNG bytes containing equal-width color swatches.
render_palette_svg
Render a palette as an SVG string containing equal-width color swatches.

Type Aliases§

GlasbeyError
Backward-compatible name for OkPaletteError.
Result
Result type returned by okpalette operations.