Skip to content

Commit

Permalink
Merge #221
Browse files Browse the repository at this point in the history
221: Feature/cieluv r=Ogeon a=masonium

Implements the CIELUV color space, translating directly to and from `Xyz`.

First step towards `Hsluv` implementation. 


Co-authored-by: Mason Smith <masonium@gmail.com>
  • Loading branch information
bors[bot] and masonium committed May 10, 2021
2 parents ba8ef28 + 9fd69e2 commit b1bdbc1
Show file tree
Hide file tree
Showing 12 changed files with 1,028 additions and 6 deletions.
22 changes: 21 additions & 1 deletion palette/src/convert.rs
Expand Up @@ -529,7 +529,7 @@ mod tests {
use crate::encoding::linear::Linear;
use crate::luma::{Luma, LumaStandard};
use crate::rgb::{Rgb, RgbSpace};
use crate::{Alpha, Hsl, Hsv, Hwb, Lab, Lch, Xyz, Yxy};
use crate::{Alpha, Hsl, Hsv, Hwb, Lab, Lch, Luv, Xyz, Yxy};
use crate::{Clamp, FloatComponent};

#[derive(FromColorUnclamped, WithAlpha)]
Expand Down Expand Up @@ -675,6 +675,9 @@ mod tests {
let lch: Lch<_, f64> = Default::default();
WithXyz::<crate::encoding::Srgb>::from_color(lch);

let luv: Hsl<_, f64> = Default::default();
WithXyz::<crate::encoding::Srgb>::from_color(luv);

let rgb: Rgb<_, f64> = Default::default();
WithXyz::<crate::encoding::Srgb>::from_color(rgb);

Expand Down Expand Up @@ -709,6 +712,9 @@ mod tests {
let lch: Alpha<Lch<_, f64>, u8> = Alpha::from(Lch::default());
WithXyz::<crate::encoding::Srgb>::from_color(lch);

let luv: Alpha<Luv<_, f64>, u8> = Alpha::from(Luv::default());
WithXyz::<crate::encoding::Srgb>::from_color(luv);

let rgb: Alpha<Rgb<_, f64>, u8> = Alpha::from(Rgb::default());
WithXyz::<crate::encoding::Srgb>::from_color(rgb);

Expand Down Expand Up @@ -743,6 +749,9 @@ mod tests {
let lch: Lch<_, f64> = Default::default();
Alpha::<WithXyz<crate::encoding::Srgb>, u8>::from_color(lch);

let luv: Hsl<_, f64> = Default::default();
Alpha::<WithXyz<crate::encoding::Srgb>, u8>::from_color(luv);

let rgb: Rgb<_, f64> = Default::default();
Alpha::<WithXyz<crate::encoding::Srgb>, u8>::from_color(rgb);

Expand Down Expand Up @@ -777,6 +786,9 @@ mod tests {
let lch: Lch<_, f64> = Default::default();
Alpha::<WithXyz<crate::encoding::Srgb>, u8>::from_color(lch);

let luv: Luv<_, f64> = Default::default();
Alpha::<WithXyz<crate::encoding::Srgb>, u8>::from_color(luv);

let rgb: Rgb<_, f64> = Default::default();
Alpha::<WithXyz<crate::encoding::Srgb>, u8>::from_color(rgb);

Expand All @@ -802,6 +814,7 @@ mod tests {
let _yxy: Yxy<_, f64> = color.into_color();
let _lab: Lab<_, f64> = color.into_color();
let _lch: Lch<_, f64> = color.into_color();
let _luv: Luv<_, f64> = color.into_color();
let _rgb: Rgb<_, f64> = color.into_color();
let _hsl: Hsl<_, f64> = color.into_color();
let _hsv: Hsv<_, f64> = color.into_color();
Expand All @@ -819,6 +832,7 @@ mod tests {
let _yxy: Yxy<_, f64> = color.into_color();
let _lab: Lab<_, f64> = color.into_color();
let _lch: Lch<_, f64> = color.into_color();
let _luv: Luv<_, f64> = color.into_color();
let _rgb: Rgb<_, f64> = color.into_color();
let _hsl: Hsl<_, f64> = color.into_color();
let _hsv: Hsv<_, f64> = color.into_color();
Expand All @@ -835,6 +849,7 @@ mod tests {
let _yxy: Alpha<Yxy<_, f64>, u8> = color.into_color();
let _lab: Alpha<Lab<_, f64>, u8> = color.into_color();
let _lch: Alpha<Lch<_, f64>, u8> = color.into_color();
let _luv: Alpha<Luv<_, f64>, u8> = color.into_color();
let _rgb: Alpha<Rgb<_, f64>, u8> = color.into_color();
let _hsl: Alpha<Hsl<_, f64>, u8> = color.into_color();
let _hsv: Alpha<Hsv<_, f64>, u8> = color.into_color();
Expand All @@ -852,6 +867,7 @@ mod tests {
let _yxy: Alpha<Yxy<_, f64>, u8> = color.into_color();
let _lab: Alpha<Lab<_, f64>, u8> = color.into_color();
let _lch: Alpha<Lch<_, f64>, u8> = color.into_color();
let _luv: Alpha<Luv<_, f64>, u8> = color.into_color();
let _rgb: Alpha<Rgb<_, f64>, u8> = color.into_color();
let _hsl: Alpha<Hsl<_, f64>, u8> = color.into_color();
let _hsv: Alpha<Hsv<_, f64>, u8> = color.into_color();
Expand All @@ -876,6 +892,9 @@ mod tests {
let lch: Lch<crate::white_point::E, f64> = Default::default();
WithoutXyz::<f64>::from_color(lch);

let luv: Luv<crate::white_point::E, f64> = Default::default();
WithoutXyz::<f64>::from_color(luv);

let rgb: Rgb<_, f64> = Default::default();
WithoutXyz::<f64>::from_color(rgb);

Expand All @@ -901,6 +920,7 @@ mod tests {
let _yxy: Yxy<crate::white_point::E, f64> = color.into_color();
let _lab: Lab<crate::white_point::E, f64> = color.into_color();
let _lch: Lch<crate::white_point::E, f64> = color.into_color();
let _luv: Luv<crate::white_point::E, f64> = color.into_color();
let _rgb: Rgb<_, f64> = color.into_color();
let _hsl: Hsl<_, f64> = color.into_color();
let _hsv: Hsv<_, f64> = color.into_color();
Expand Down
3 changes: 2 additions & 1 deletion palette/src/equality.rs
Expand Up @@ -2,7 +2,7 @@ use approx::{AbsDiffEq, RelativeEq, UlpsEq};

use crate::float::Float;
use crate::white_point::WhitePoint;
use crate::{from_f64, FloatComponent, FromF64, Lab, LabHue, Lch, RgbHue, Xyz, Yxy};
use crate::{from_f64, FloatComponent, FromF64, Lab, LabHue, Lch, Luv, RgbHue, Xyz, Yxy};

macro_rules! impl_eq {
( $self_ty: ident , [$($element: ident),+]) => {
Expand Down Expand Up @@ -64,6 +64,7 @@ macro_rules! impl_eq {
impl_eq!(Xyz, [x, y, z]);
impl_eq!(Yxy, [y, x, luma]);
impl_eq!(Lab, [l, a, b]);
impl_eq!(Luv, [l, u, v]);
impl_eq!(Lch, [l, chroma, hue]);

// For hues, the difference is calculated and compared to zero. However due to
Expand Down
3 changes: 3 additions & 0 deletions palette/src/hues.rs
Expand Up @@ -270,6 +270,9 @@ make_hues! {
/// different from the hue of RGB based color spaces.
struct LabHue;

/// A hue type for the CIE L\*u\*v\* family of color spaces.
struct LuvHue;

/// A hue type for the RGB family of color spaces.
///
/// It's measured in degrees and uses the three additive primaries _red_,
Expand Down
4 changes: 3 additions & 1 deletion palette/src/lib.rs
Expand Up @@ -243,6 +243,7 @@ pub use hwb::{Hwb, Hwba};
pub use lab::{Lab, Laba};
pub use lch::{Lch, Lcha};
pub use luma::{GammaLuma, GammaLumaa, LinLuma, LinLumaa, SrgbLuma, SrgbLumaa};
pub use luv::{Luv, Luva};
pub use rgb::{GammaSrgb, GammaSrgba, LinSrgb, LinSrgba, Packed, RgbChannels, Srgb, Srgba};
pub use xyz::{Xyz, Xyza};
pub use yxy::{Yxy, Yxya};
Expand All @@ -251,7 +252,7 @@ pub use color_difference::ColorDifference;
pub use component::*;
pub use convert::{FromColor, IntoColor};
pub use encoding::pixel::Pixel;
pub use hues::{LabHue, RgbHue};
pub use hues::{LabHue, LuvHue, RgbHue};
pub use matrix::Mat3;
pub use relative_contrast::{contrast_ratio, RelativeContrast};

Expand Down Expand Up @@ -426,6 +427,7 @@ mod hwb;
mod lab;
mod lch;
pub mod luma;
mod luv;
pub mod rgb;
mod xyz;
mod yxy;
Expand Down

0 comments on commit b1bdbc1

Please sign in to comment.