Skip to content

Commit

Permalink
Merge #119
Browse files Browse the repository at this point in the history
119: Remove the color enum r=Ogeon a=Veykril

This PR removes the color type enum as described in #72. I do not know if this has any side effects tough, everything compiles fine on my end, tests and examples compile and run as well. The only difference i noticed is in the `readme_examples/readme_manipulation` example part. The latter two colors arent the same but im not sure why.

Closes #72.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
  • Loading branch information
bors[bot] and Veykril committed Oct 2, 2018
2 parents d1acf02 + 62d95b7 commit ec0e482
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 706 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -82,11 +82,11 @@ The following example shows how the `Color` type is used to make a lighter and a

```Rust
extern crate palette;
use palette::{Color, Srgb, Shade, Saturate};
use palette::{Saturate, Shade, Srgb, Lch};

let color: Color = Srgb::new(0.8, 0.2, 0.1).into_linear().into();
let color = Srgb::new(0.8, 0.2, 0.1).into_linear();
let lighter = color.lighten(0.1);
let desaturated = color.desaturate(0.5);
let desaturated = Lch::from(color).desaturate(0.5);
```

This results in the following three colors:
Expand Down
18 changes: 9 additions & 9 deletions palette/examples/color_scheme.rs
Expand Up @@ -2,7 +2,7 @@ extern crate clap;
extern crate image;
extern crate palette;

use palette::{Color, Hue, Pixel, Shade, Srgb};
use palette::{Hue, Pixel, Shade, Lch, Srgb, LinSrgb};

use image::{GenericImage, RgbImage, SubImage};

Expand Down Expand Up @@ -93,8 +93,8 @@ fn main() {
.and_then(|r| r.parse().ok())
.expect("the blue channel must be a number in the range [0-255]");

let primary: Color = Srgb::new(red, green, blue)
.into_format()
let primary: Lch = Srgb::new(red, green, blue)
.into_format::<f32>()
.into_linear()
.into();

Expand Down Expand Up @@ -154,12 +154,12 @@ fn main() {
let mut image = RgbImage::new((secondary.len() as u32 + 1) * SWATCH_SIZE, SWATCH_SIZE);

//Draw the primary swatches
blit_shades(primary, image.sub_image(0, 0, SWATCH_SIZE, SWATCH_SIZE));
blit_shades(primary.into(), image.sub_image(0, 0, SWATCH_SIZE, SWATCH_SIZE));

//Draw the secondary swatches
for (n, color) in secondary.into_iter().enumerate() {
blit_shades(
color,
color.into(),
image.sub_image((n as u32 + 1) * SWATCH_SIZE, 0, SWATCH_SIZE, SWATCH_SIZE),
);
}
Expand All @@ -170,14 +170,14 @@ fn main() {
}
}

fn blit_shades<I: GenericImage<Pixel = image::Rgb<u8>> + 'static>(
color: Color,
fn blit_shades<I>(
color: LinSrgb<f32>,
mut canvas: SubImage<I>,
) {
) where I: GenericImage<Pixel = image::Rgb<u8>> + 'static {
let width = canvas.width();
let height = canvas.height();

let primary = Srgb::from_linear(color.into()).into_format().into_raw();
let primary = Srgb::from_linear(color).into_format().into_raw();

//Generate one lighter and two darker versions of the color
let light = Srgb::from_linear(color.lighten(0.1).into())
Expand Down
6 changes: 3 additions & 3 deletions palette/examples/readme_examples.rs
Expand Up @@ -27,13 +27,13 @@ mod color_spaces {
}

mod manipulation {
use palette::{Color, Saturate, Shade, Srgb};
use palette::{Saturate, Shade, Srgb, Lch};
use display_colors;

pub fn run() {
let color: Color = Srgb::new(0.8, 0.2, 0.1).into_linear().into();
let color = Srgb::new(0.8, 0.2, 0.1).into_linear();
let lighter = color.lighten(0.1);
let desaturated = color.desaturate(0.5);
let desaturated = Lch::from(color).desaturate(0.5);

display_colors(
"examples/readme_manipulation.png",
Expand Down
10 changes: 5 additions & 5 deletions palette/src/blend/test.rs
@@ -1,12 +1,12 @@
use {Blend, Color, Colora, ComponentWise, LinSrgb, LinSrgba};
use {Blend, ComponentWise, LinSrgb, LinSrgba};
use rgb::Rgb;
use encoding::Linear;
use blend::PreAlpha;

#[test]
fn blend_color() {
let a = Color::linear_rgb(1.0, 0.0, 0.0);
let b = Color::linear_rgb(0.0, 0.0, 1.0);
let a = LinSrgb::new(1.0, 0.0, 0.0);
let b = LinSrgb::new(0.0, 0.0, 1.0);

let c: LinSrgb = a.blend(
b,
Expand All @@ -19,8 +19,8 @@ fn blend_color() {

#[test]
fn blend_alpha_color() {
let a = Colora::linear_rgb(1.0, 0.0, 0.0, 0.2);
let b = Colora::linear_rgb(0.0, 0.0, 1.0, 0.2);
let a = LinSrgba::new(1.0, 0.0, 0.0, 0.2);
let b = LinSrgba::new(0.0, 0.0, 1.0, 0.2);

let c: LinSrgba = a.blend(
b,
Expand Down
13 changes: 2 additions & 11 deletions palette/src/convert.rs
Expand Up @@ -556,7 +556,6 @@ pub trait ConvertInto<T>: Into<T> {
///let rgb: Srgb = Lch::new(50.0, 100.0, -175.0).convert_unclamped_into();
///assert!(!rgb.is_valid());
///```
#[inline]
fn convert_unclamped_into(self) -> T;

///Convert into T, returning ok if the color is inside of its defined range,
Expand Down Expand Up @@ -762,10 +761,10 @@ mod tests {
use core::marker::PhantomData;
use float::Float;
use Component;
use Linear;
use encoding::linear::Linear;
use rgb::{Rgb, RgbSpace};
use luma::Luma;
use {Color, Hsl, Hsv, Hwb, Lab, Lch, Xyz, Yxy};
use {Hsl, Hsv, Hwb, Lab, Lch, Xyz, Yxy};

#[derive(Copy, Clone, FromColor, IntoColor)]
#[palette_manual_from(Xyz, Luma = "from_luma_internal")]
Expand Down Expand Up @@ -857,9 +856,6 @@ mod tests {

let luma: Luma<::encoding::Srgb, f64> = Default::default();
WithXyz::<::encoding::Srgb>::from(luma);

let color: Color<_, f64> = Default::default();
WithXyz::<::encoding::Srgb>::from(color);
}

#[test]
Expand All @@ -875,7 +871,6 @@ mod tests {
let _hsv: Hsv<_, f64> = color.into();
let _hwb: Hwb<_, f64> = color.into();
let _luma: Luma<::encoding::Srgb, f64> = color.into();
let _color: Color<::encoding::Srgb, f64> = color.into();
}

#[test]
Expand Down Expand Up @@ -906,9 +901,6 @@ mod tests {

let luma: Luma<Linear<::white_point::E>, f64> = Default::default();
WithoutXyz::<f64>::from(luma);

let color: Color<_, f64> = Default::default();
WithoutXyz::<f64>::from(color);
}

#[test]
Expand All @@ -924,6 +916,5 @@ mod tests {
let _hsv: Hsv<_, f64> = color.into();
let _hwb: Hwb<_, f64> = color.into();
let _luma: Luma<Linear<::white_point::E>, f64> = color.into();
let _color: Color<_, f64> = color.into();
}
}

0 comments on commit ec0e482

Please sign in to comment.