colortypes

crates.io Documentation

A type safe color conversion library

This crate provides many methods for converting between color types.

Everything is implemented abstractly, and is easily extensible by the user.

When converting you call the from_color method of the colortype struct on your color!

Implemented conversions:

| From | To | Method | | ---------- | ---------- | ------------- | | RGB | XYZ | Directly | | RGB | HSV | Directly | | RGB | HSL | Directly | | RGB | LCH | Through XYZ | | RGB | LAB | Through XYZ | | LAB | LCH | Directly |

Example usage

```rust use colortypes::methods::{Rgba, Xyza}; use colortypes::types::{Color, FromColorType, RefWhite::*};

fn main() { // You can directly call Rgba this way (defaults to D65) let color = Rgba::new([0.0, 0.0, 0.0, 1.0]); // You can directly call Rgba this way and specify white reference let color = Rgba::new_w::<{ D65 }>([0.0, 0.0, 0.0, 1.0]); // Or can call Color and specify Rgba this way let color = Color::

// To convert to Xyza
let new_color = Xyza::from_color(color);

} ```

Images

This crate also provides a type for dealing with images, it's still work in progress ```rust use colortypes::methods::; use colortypes::types::;

fn main() { let mut img = Image::

img.put_pixel((0, 0), Rgba::new([0.7, 0.3, 0.2, 1.0]));

let new_img = img.convert::<Xyya>();
let new_img_b = img.convert::<Xyya>();
let mut new_img = ((new_img + new_img_b) / 2.0).convert::<Rgba>();

new_img.crop_align((Align::Front, Align::Front), (256, 256));

let my_col = new_img.get_pixel((0, 0));

} ```