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§
- Candidate
Constraints - Optional validated bounds applied when constructing candidate colors.
- Chroma
Range - Validated inclusive OKLCH chroma bounds.
- Distance
Weights - Relative weights for squared distance in OKLab space.
- HueRange
- Validated inclusive OKLCH hue bounds, which may wrap around zero.
- Label
Palette Request - Input for position-aware label palette generation.
- Lightness
Range - Validated inclusive OKLab lightness bounds.
- Oklab
- A color in OKLab space.
- Oklch
- A color in cylindrical OKLCH space.
- Palette
Generator - Configuration for generating palettes.
- Rgb8
- An 8-bit sRGB color.
Enums§
- Background
Contrast - The strategy used to keep generated colors distinct from a background.
- Colorblind
Mode - Color-vision-deficiency simulations included when comparing colors.
- Grid
Size - Resolution of the RGB candidate grid searched by a
PaletteGenerator. - OkPalette
Error - 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#RRGGBBASCII 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§
- Glasbey
Error - Backward-compatible name for
OkPaletteError. - Result
- Result type returned by
okpaletteoperations.