22 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
5- use std:: libc:: c_float;
65use std:: ascii:: StrAsciiExt ;
76
87use ast:: * ;
@@ -11,17 +10,14 @@ use self::color_data::{COLOR_KEYWORDS, COLOR_VALUES};
1110mod color_data;
1211
1312
14- // Try to match rust-azure’s AzFloat
15- pub type ColorFloat = c_float ;
16-
17-
1813#[ deriving( Clone , Eq ) ]
1914pub struct RGBA {
2015 // All in 0..1
21- red : ColorFloat ,
22- green : ColorFloat ,
23- blue : ColorFloat ,
24- alpha : ColorFloat ,
16+ // Use f32 to try and match rust-azure’s AzFloat
17+ red : f32 ,
18+ green : f32 ,
19+ blue : f32 ,
20+ alpha : f32 ,
2521}
2622
2723#[ deriving( Clone , Eq ) ]
@@ -70,9 +66,9 @@ fn parse_color_hash(value: &str) -> Option<Color> {
7066 )
7167 macro_rules! to_rgba(
7268 ( $r: expr, $g: expr, $b: expr, ) => {
73- Some ( RGBA ( RGBA { red: $r as ColorFloat / 255. ,
74- green: $g as ColorFloat / 255. ,
75- blue: $b as ColorFloat / 255. ,
69+ Some ( RGBA ( RGBA { red: $r as f32 / 255. ,
70+ green: $g as f32 / 255. ,
71+ blue: $b as f32 / 255. ,
7672 alpha: 1. } ) )
7773 } ;
7874 )
@@ -128,25 +124,25 @@ fn parse_color_function(name: &str, arguments: &[ComponentValue])
128124 } ) ;
129125 )
130126
131- let red: ColorFloat ;
132- let green: ColorFloat ;
133- let blue: ColorFloat ;
127+ let red: f32 ;
128+ let green: f32 ;
129+ let blue: f32 ;
134130 if is_rgb {
135131 // Either integers or percentages, but all the same type.
136132 match iter. next ( ) {
137133 Some ( & Number ( ref v) ) if v. int_value . is_some ( ) => {
138- red = ( v. value as ColorFloat / 255. ) as ColorFloat ;
134+ red = ( v. value / 255. ) as f32 ;
139135 expect_comma ! ( ) ;
140- green = ( expect_integer ! ( ) / 255. ) as ColorFloat ;
136+ green = ( expect_integer ! ( ) / 255. ) as f32 ;
141137 expect_comma ! ( ) ;
142- blue = ( expect_integer ! ( ) / 255. ) as ColorFloat ;
138+ blue = ( expect_integer ! ( ) / 255. ) as f32 ;
143139 }
144140 Some ( & Percentage ( ref v) ) => {
145- red = ( v. value as ColorFloat / 100. ) as ColorFloat ;
141+ red = ( v. value / 100. ) as f32 ;
146142 expect_comma ! ( ) ;
147- green = ( expect_percentage ! ( ) / 100. ) as ColorFloat ;
143+ green = ( expect_percentage ! ( ) / 100. ) as f32 ;
148144 expect_comma ! ( ) ;
149- blue = ( expect_percentage ! ( ) / 100. ) as ColorFloat ;
145+ blue = ( expect_percentage ! ( ) / 100. ) as f32 ;
150146 }
151147 _ => return None
152148 } ;
@@ -171,14 +167,14 @@ fn parse_color_function(name: &str, arguments: &[ComponentValue])
171167 let m2 = if lightness <= 0.5 { lightness * ( saturation + 1. ) }
172168 else { lightness + saturation - lightness * saturation } ;
173169 let m1 = lightness * 2. - m2;
174- red = hue_to_rgb ( m1, m2, hue + 1. / 3. ) as ColorFloat ;
175- green = hue_to_rgb ( m1, m2, hue) as ColorFloat ;
176- blue = hue_to_rgb ( m1, m2, hue - 1. / 3. ) as ColorFloat ;
170+ red = hue_to_rgb ( m1, m2, hue + 1. / 3. ) as f32 ;
171+ green = hue_to_rgb ( m1, m2, hue) as f32 ;
172+ blue = hue_to_rgb ( m1, m2, hue - 1. / 3. ) as f32 ;
177173 }
178174
179175 let alpha = if has_alpha {
180176 expect_comma ! ( ) ;
181- ( expect_number ! ( ) ) . max ( & 0. ) . min ( & 1. ) as ColorFloat
177+ ( expect_number ! ( ) ) . max ( & 0. ) . min ( & 1. ) as f32
182178 } else {
183179 1.
184180 } ;
0 commit comments