Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the color enum #119

Merged
merged 2 commits into from Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
}
}