Skip to main content

Crate color_convert_rs

Crate color_convert_rs 

Source
Expand description

A behavior-faithful Rust port of the npm color-convert library — CPU-SIMD accelerated with optional GPU (CubeCL) and npm drop-in replacement (wasm-pack) paths.

§Quick start

use color_convert_rs::{Color, Model, convert_rounded};

let orange = Color::Rgb([255.0, 128.0, 0.0]);
let lab = convert_rounded(Model::Rgb, Model::Lab, orange).unwrap();
assert_eq!(lab, Color::Lab([67.0, 43.0, 74.0]));

§Features

  • gpu (optional): CubeCL/wgpu GPU compute kernels with runtime capability probe. Without this feature, probe() always returns Backend::CpuSimd.
  • wasm (optional): wasm-bindgen exports for building the npm drop-in replacement via wasm-pack build --target nodejs --features wasm.

§Public API

  • [convert] / convert_rounded: single-color any-to-any conversion
  • Model: the 17 supported color models
  • Color: the color value type (array or string depending on model)
  • Error: the library error type
  • simd::*_batch: vectorized f32x8 SIMD batch functions for hot routes
  • [probe] / gpu_present / Backend: runtime GPU capability probe

Re-exports§

pub use convert::Color;
pub use convert::Model;
pub use convert::convert;
pub use convert::convert_rounded;
pub use probe::Backend;
pub use probe::gpu_present;
pub use probe::probe;

Modules§

ansi16
ANSI‑16 colour-code decoder — ported from convert.ansi16.rgb in color-convert@3.1.3 conversions.js (lines 701–725).
ansi256
ANSI‑256 colour-code decoder — ported from convert.ansi256.rgb in color-convert@3.1.3 conversions.js (lines 727–745).
apple
Apple RGB source routes.
batch
Stride-aware batch color conversion for raw pixel buffers.
cmyk
Conversions FROM the cmyk colour model into other colour spaces — ported from convert.cmyk.* in color-convert@3.1.3 conversions.js.
convert
Public convert API — colour-space routing graph with BFS multi-hop pathfinding, mirroring route.js in color-convert@3.1.3.
gray
Grayscale (single-channel) source routes.
hcg
Conversions FROM the hcg colour model into other colour spaces — ported from convert.hcg.* in color-convert@3.1.3 conversions.js.
hex
Hex colour-string decoder — ported from convert.hex.rgb in color-convert@3.1.3 conversions.js (lines 757–777).
hsl
Conversions FROM the hsl colour model into other colour spaces — ported from convert.hsl.* in color-convert@3.1.3 conversions.js.
hsv
Conversions FROM the hsv colour model into other colour spaces — ported from convert.hsv.* in color-convert@3.1.3 conversions.js.
hwb
Conversions FROM the hwb colour model into other colour spaces — ported from convert.hwb.* in color-convert@3.1.3 conversions.js.
keyword
Keyword (CSS named color) source routes.
lab
Conversions FROM the lab colour model into other colour spaces — ported from convert.lab.* in color-convert@3.1.3 conversions.js.
lch
Conversions FROM the lch colour model into other colour spaces — ported from convert.lch.* in color-convert@3.1.3 conversions.js.
oklab
Conversions FROM the oklab colour model into other colour spaces — ported from convert.oklab.* in color-convert@3.1.3 conversions.js.
oklch
Conversions FROM the oklch colour model into other colour spaces — ported from convert.oklch.* in color-convert@3.1.3 conversions.js.
probe
Runtime GPU capability probe.
rgb
Conversions FROM the rgb colour model into other colour spaces, string encodings, and terminal codes — ported from convert.rgb.* in color-convert@3.1.3 conversions.js.
simd
CPU-SIMD batch conversion routes for hot matrix-heavy paths.
simd_apple
CPU-SIMD batch conversion for rgb→apple using per-channel linear scale.
simd_cmyk
SIMD CMYK batch conversion from RGB using wide::f32x8.
simd_hcg
CPU-SIMD batch conversion for rgb↔hcg using mask-blend selection.
simd_hsl
CPU-SIMD batch conversion for rgb↔hsl using mask-blend selection.
simd_hsv
CPU-SIMD batch conversion for rgb→hsv using mask-blend selection.
simd_hsv_rgb
CPU-SIMD batch conversion for hsv→rgb using mask-blend hue-sector selection.
simd_hwb
CPU-SIMD batch conversion for rgb→hwb using mask-blend hue selection.
simd_lab_xyz
CPU-SIMD batch conversion for the lab→xyz (inverse) route.
simd_oklab
CPU-SIMD batch conversion for rgb→oklab.
simd_oklab_rgb
CPU-SIMD batch conversion for oklab→rgb (inverse) route.
simd_parallel
Multi-core parallelism for the SIMD batch routes via rayon.
simd_xyz
CPU-SIMD batch conversion for the xyz→rgb (inverse) route.
xyz
Conversions FROM the xyz colour model into other colour spaces — ported from convert.xyz.* in color-convert@3.1.3 conversions.js.

Enums§

Error
Library error for all conversion routes.