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 returnsBackend::CpuSimd.wasm(optional): wasm-bindgen exports for building the npm drop-in replacement viawasm-pack build --target nodejs --features wasm.
§Public API
- [
convert] /convert_rounded: single-color any-to-any conversion Model: the 17 supported color modelsColor: the color value type (array or string depending on model)Error: the library error typesimd::*_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.rgbin color-convert@3.1.3conversions.js(lines 701–725). - ansi256
- ANSI‑256 colour-code decoder — ported from
convert.ansi256.rgbin color-convert@3.1.3conversions.js(lines 727–745). - apple
- Apple RGB source routes.
- batch
- Stride-aware batch color conversion for raw pixel buffers.
- cmyk
- Conversions FROM the
cmykcolour model into other colour spaces — ported fromconvert.cmyk.*in color-convert@3.1.3conversions.js. - convert
- Public
convertAPI — colour-space routing graph with BFS multi-hop pathfinding, mirroringroute.jsin color-convert@3.1.3. - gray
- Grayscale (single-channel) source routes.
- hcg
- Conversions FROM the
hcgcolour model into other colour spaces — ported fromconvert.hcg.*in color-convert@3.1.3conversions.js. - hex
- Hex colour-string decoder — ported from
convert.hex.rgbin color-convert@3.1.3conversions.js(lines 757–777). - hsl
- Conversions FROM the
hslcolour model into other colour spaces — ported fromconvert.hsl.*in color-convert@3.1.3conversions.js. - hsv
- Conversions FROM the
hsvcolour model into other colour spaces — ported fromconvert.hsv.*in color-convert@3.1.3conversions.js. - hwb
- Conversions FROM the
hwbcolour model into other colour spaces — ported fromconvert.hwb.*in color-convert@3.1.3conversions.js. - keyword
- Keyword (CSS named color) source routes.
- lab
- Conversions FROM the
labcolour model into other colour spaces — ported fromconvert.lab.*in color-convert@3.1.3conversions.js. - lch
- Conversions FROM the
lchcolour model into other colour spaces — ported fromconvert.lch.*in color-convert@3.1.3conversions.js. - oklab
- Conversions FROM the
oklabcolour model into other colour spaces — ported fromconvert.oklab.*in color-convert@3.1.3conversions.js. - oklch
- Conversions FROM the
oklchcolour model into other colour spaces — ported fromconvert.oklch.*in color-convert@3.1.3conversions.js. - probe
- Runtime GPU capability probe.
- rgb
- Conversions FROM the
rgbcolour model into other colour spaces, string encodings, and terminal codes — ported fromconvert.rgb.*in color-convert@3.1.3conversions.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
xyzcolour model into other colour spaces — ported fromconvert.xyz.*in color-convert@3.1.3conversions.js.
Enums§
- Error
- Library error for all conversion routes.