2 stable releases

1.0.1 Aug 30, 2024
1.0.0 Aug 29, 2024

#904 in Images

Download history 235/week @ 2024-08-28 4/week @ 2024-09-04 26/week @ 2024-09-11 19/week @ 2024-09-18 14/week @ 2024-09-25 12/week @ 2024-10-02 18/week @ 2024-10-09 68/week @ 2024-10-16 79/week @ 2024-10-23 24/week @ 2024-10-30 61/week @ 2024-11-06 65/week @ 2024-11-13 122/week @ 2024-11-20 121/week @ 2024-11-27 144/week @ 2024-12-04

473 downloads per month

MIT and CC-PDDC licenses

36KB
673 lines

Convert sRGB to Okhsl/Okhsv (Oklab-based) perceptual color space

A simple Rust implementation of Okhsl and Okhsv color conversion routines based on the reference implementation in the blog post.

Okhsl and Okhsv color spaces are meant to have more orhogonal hue, saturation, and lightness than the basic HSL/HSV colors.

API

use okhsl::*;

let lab = Oklab::from(Rgb {r: 1, g: 127, b: 255});
let Oklab {l, a, b} = lab;

let hsv = Okhsv::from(lab);
let Okhsv {h, s, v} = hsv;

let lab = hsv.to_oklab();
let rgb = hsv.to_srgb();

Oklab components are floats. l is in range 0 to 1, and a/b are small numbers that can be negative.

Okhsv/Okhsl components are floats. HSL values are approximately in range 0 to 1 (inclusive). You can expect to roundtrip OkhslOklab and OkhsvOklab with little loss of precision.

Examples

Usage examples

cargo run -r --example invert -- some_image.jpeg

Dependencies

~170KB