@@ -2,29 +2,24 @@ use num::Float;
2
2
3
3
use { Alpha , Rgb , Luma , Xyz , Yxy , Lab , Lch , Hsv , Hsl , Color } ;
4
4
5
- ///FromColor provides conversion between the colors. It requires from_xyz
6
- ///and derives conversion to other colors as a default from this.
7
- ///
8
- ///This is not optimal in all cases. For example Hsl -> Rgb using this method will
9
- ///result in Hsl -> Rgb -> Xyz -> Rgb. To avoid this the Rgb derivatives
10
- ///like Hsl and Hsv, convert through Rgb as default and Lab derivatives
11
- ///like Lch convert through Lab as default.
5
+ ///FromColor provides conversion between the colors. It requires from_xyz and derives conversion
6
+ ///to other colors as a default from this. These defaults must be overridden when direct
7
+ ///conversion exists between colors. For example, Luma has direct conversion to Rgb.
8
+ ///So from_rgb conversion for Luma and from_luma for Rgb is implemented directly.
12
9
pub trait FromColor < T > : Sized
13
10
where T : Float ,
14
11
{
15
12
//To implement ColorConvert for a type, a few things must by kept in mind.
16
13
//
17
- //First, derived colors like Hsl must override into_rgb and from_rgb and
18
- //convert into_xyz and from_xyz via Rgb, as discussed above.
14
+ //First, derived colors like Hsl must override from_rgb and convert from_xyz via Rgb.
19
15
//
20
- //Second, the from for the same color must override the default.
21
- //For example, from_rgb and into_rgb for Rgb will convert via Xyz which
22
- //needs to be overridden with *input_color and *self to avoid the unnecessary
23
- //converison.
16
+ //Second, the from for the same color must override the default. For example,
17
+ //from_rgb for Rgb will convert via Xyz which needs to be overridden with self to
18
+ //avoid the unnecessary converison.
24
19
//
25
20
//Third, if a direct transform exists between the colors, then it should be
26
21
//overridden. For example, Luma has direct conversion to Rgb. So from_rgb conversion
27
- //for Luma is implemented.
22
+ //for Luma and from_luma for Rgb is implemented directly .
28
23
29
24
///Convert from XYZ color space
30
25
fn from_xyz ( Xyz < T > ) -> Self ;
@@ -68,29 +63,11 @@ pub trait FromColor<T>: Sized
68
63
69
64
70
65
///IntoColor provides conversion between the colors. It requires into into_xyz
71
- ///and derives conversion to other colors as a default from this.
72
- ///
73
- ///This is not optimal in all cases. For example Hsl -> Rgb using this method will
74
- ///result in Hsl -> Rgb -> Xyz -> Rgb. To avoid this the Rgb derivatives
75
- ///like Hsl and Hsv, convert through Rgb as default and Lab derivatives
76
- ///like Lch convert through Lab as default.
66
+ ///and derives conversion to other colors as a default from this. These defaults
67
+ ///must be overridden when direct conversion exists between colors.
77
68
pub trait IntoColor < T > : Sized
78
69
where T : Float ,
79
70
{
80
- //To implement ColorConvert for a type, a few things must by kept in mind.
81
- //
82
- //First, derived colors like Hsl must override into_rgb and from_rgb and
83
- //convert into_xyz and from_xyz via Rgb, as discussed above.
84
- //
85
- //Second, the from and into for the same color must override the default.
86
- //For example, from_rgb and into_rgb for Rgb will convert via Xyz which
87
- //needs to be overridden with *input_color and *self to avoid the unnecessary
88
- //converison.
89
- //
90
- //Third, if a direct transform exists between the colors, then it should be
91
- //overridden in both the colors. For example, Luma has direct conversion to
92
- //Rgb. So into_rgb and from_rgb conversion is implemented in Luma and into_luma
93
- //and from_luma is overridden in Rgb to use the conversion from Luma.
94
71
95
72
///Convert into XYZ space
96
73
fn into_xyz ( self ) -> Xyz < T > ;
0 commit comments