Expand description
Simple colorspace conversions in pure Rust.
All conversions are in-place, except when converting to/from integer and hexadecimal. Formulas are generally taken from Wikipedia with correctness verified against both https://www.easyrgb.com and BABL.
Helmholtz-Kohlrausch compensation formulae sourced from https://onlinelibrary.wiley.com/doi/10.1002/col.22839
Currently, everything seems to check out except CIE XYZ. The Wikipedia formula matches EasyRGB, but BABL uses something different.
This crate references Standard Illuminant D65
when converting to/from the CIE colorspace.
The feature flag D50 changes this to Illuminant D50,
used by BABL (GIMP) and possibly other programs.
Enums
- Defines colorspace pixels will take.
Constants
- Illuminant D50, aka “printing” illuminant. Used by BABL/GIMP + others over D65, not sure why.
- ‘Standard’ Illuminant D65.
- Mean value of the HK delta, High et al 2023 implementation. Measured with 36000 steps in the hk_exmample file @ 100 C(ab) Cannot make a const fn: https://github.com/rust-lang/rust/issues/57241
Functions
- Runs conversion functions to convert
pixelfrom oneSpaceto another in the least possible moves. - Same as
convert_space, ignores the 4th value inpixel. Just a convenience function. - Gamma corrects a single linear light value
- Expand gamma of a single value to linear light
- Create integer RGB set from hex string. Not RGB specific, but other formats typically aren’t represented as hexadecimal.
- Compensates LCH’s L value for the Helmholtz-Kohlrausch effect. High et al 2023 implementation.
- Returns difference in perceptual lightness based on hue, aka the Helmholtz-Kohlrausch effect. High et al 2023 implementation.
- Convert from HSV to sRGB.
- Create a hexadecimal string from integer RGB. Not RGB specific, but other formats typically aren’t represented as hexadecimal.
- Convert integer (0..255) RGB to floating (0.0..1.0) RGB. Not RGB specific, but other formats typically aren’t represented as integers.
- Convert from CIE LAB to CIE LCH. https://en.wikipedia.org/wiki/CIELAB_color_space#Cylindrical_model
- Convert from CIE LAB to CIE XYZ. https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIELAB_to_CIEXYZ
- Convert from CIE LCH to CIE LAB. https://en.wikipedia.org/wiki/CIELAB_color_space#Cylindrical_model
- Convert from Linear Light RGB to sRGB. https://en.wikipedia.org/wiki/SRGB#From_CIE_XYZ_to_sRGB
- Convert from Linear Light RGB to CIE XYZ. https://en.wikipedia.org/wiki/SRGB#From_sRGB_to_CIE_XYZ
- Convert from sRGB to HSV.
- Convert floating (0.0..1.0) RGB to integer (0..255) RGB. Simply clips values > 1.0 && < 0.0. Not RGB specific, but other formats typically aren’t represented as integers.
- Convert from sRGB to Linear Light RGB. https://en.wikipedia.org/wiki/SRGB#From_sRGB_to_CIE_XYZ
- Convert from CIE XYZ to CIE LAB. https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB
- Convert from CIE XYZ to Linear Light RGB. https://en.wikipedia.org/wiki/SRGB#From_CIE_XYZ_to_sRGB