bunt converts colors between gamma-encoded RGB, linear RGB, CIE 1931 XYZ, and
CIE 1931 xy chromaticity coordinates.
The crate is intentionally small and focuses on the conversion path commonly needed by lighting and device-control software:
Rgb -> LinearRgb -> Xyz -> Xy
[dependencies]
bunt = "0.1"Enable the optional serde feature when color values need to be serialized or
deserialized:
[dependencies]
bunt = { version = "0.1", features = ["serde"] }Convert an 8-bit RGB color directly into fixed-point xy coordinates:
use bunt::{Rgb, Xy};
let xy = Xy::from(Rgb::new(255, 0, 0));
assert_eq!(xy, Xy::new(0xB35A, 0x4C9F));Use the intermediate color spaces when an application needs to inspect or reuse the conversion steps:
use bunt::{LinearRgb, Rgb, Xy, Xyz};
let rgb = Rgb::new(128, 64, 32);
let linear = LinearRgb::from(rgb);
let xyz = Xyz::from(linear);
let xy = Xy::from(xyz);
assert!(linear.red() > linear.green());
assert!(xy.x() > 0);Rgbstores gamma-encoded 8-bit red, green, and blue channels.LinearRgbstores normalized linear-light red, green, and blue intensities.Xyzstores CIE 1931 XYZ tristimulus values.Xystores CIE 1931 xy chromaticity as twou16fixed-point channels scaled over0..=u16::MAX.
Xy uses the full u16 range because many compact protocols exchange
chromaticity as integer channel values. To recover normalized coordinates,
divide each channel by u16::MAX:
use bunt::Xy;
let xy = Xy::new(0x8000, 0x4000);
let normalized_x = f32::from(xy.x()) / f32::from(u16::MAX);
let normalized_y = f32::from(xy.y()) / f32::from(u16::MAX);
assert!(normalized_x > normalized_y);