2
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
4
5
- use std:: libc:: c_float;
6
5
use std:: ascii:: StrAsciiExt ;
7
6
8
7
use ast:: * ;
@@ -11,17 +10,14 @@ use self::color_data::{COLOR_KEYWORDS, COLOR_VALUES};
11
10
mod color_data;
12
11
13
12
14
- // Try to match rust-azure’s AzFloat
15
- pub type ColorFloat = c_float ;
16
-
17
-
18
13
#[ deriving( Clone , Eq ) ]
19
14
pub struct RGBA {
20
15
// 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 ,
25
21
}
26
22
27
23
#[ deriving( Clone , Eq ) ]
@@ -70,9 +66,9 @@ fn parse_color_hash(value: &str) -> Option<Color> {
70
66
)
71
67
macro_rules! to_rgba(
72
68
( $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. ,
76
72
alpha: 1. } ) )
77
73
} ;
78
74
)
@@ -128,25 +124,25 @@ fn parse_color_function(name: &str, arguments: &[ComponentValue])
128
124
} ) ;
129
125
)
130
126
131
- let red: ColorFloat ;
132
- let green: ColorFloat ;
133
- let blue: ColorFloat ;
127
+ let red: f32 ;
128
+ let green: f32 ;
129
+ let blue: f32 ;
134
130
if is_rgb {
135
131
// Either integers or percentages, but all the same type.
136
132
match iter. next ( ) {
137
133
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 ;
139
135
expect_comma ! ( ) ;
140
- green = ( expect_integer ! ( ) / 255. ) as ColorFloat ;
136
+ green = ( expect_integer ! ( ) / 255. ) as f32 ;
141
137
expect_comma ! ( ) ;
142
- blue = ( expect_integer ! ( ) / 255. ) as ColorFloat ;
138
+ blue = ( expect_integer ! ( ) / 255. ) as f32 ;
143
139
}
144
140
Some ( & Percentage ( ref v) ) => {
145
- red = ( v. value as ColorFloat / 100. ) as ColorFloat ;
141
+ red = ( v. value / 100. ) as f32 ;
146
142
expect_comma ! ( ) ;
147
- green = ( expect_percentage ! ( ) / 100. ) as ColorFloat ;
143
+ green = ( expect_percentage ! ( ) / 100. ) as f32 ;
148
144
expect_comma ! ( ) ;
149
- blue = ( expect_percentage ! ( ) / 100. ) as ColorFloat ;
145
+ blue = ( expect_percentage ! ( ) / 100. ) as f32 ;
150
146
}
151
147
_ => return None
152
148
} ;
@@ -171,14 +167,14 @@ fn parse_color_function(name: &str, arguments: &[ComponentValue])
171
167
let m2 = if lightness <= 0.5 { lightness * ( saturation + 1. ) }
172
168
else { lightness + saturation - lightness * saturation } ;
173
169
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 ;
177
173
}
178
174
179
175
let alpha = if has_alpha {
180
176
expect_comma ! ( ) ;
181
- ( expect_number ! ( ) ) . max ( & 0. ) . min ( & 1. ) as ColorFloat
177
+ ( expect_number ! ( ) ) . max ( & 0. ) . min ( & 1. ) as f32
182
178
} else {
183
179
1.
184
180
} ;
0 commit comments