File tree 2 files changed +12
-4
lines changed
2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change 1
1
[package ]
2
2
3
3
name = " cssparser"
4
- version = " 0.13.1 "
4
+ version = " 0.13.2 "
5
5
authors = [ " Simon Sapin <simon.sapin@exyr.org>" ]
6
6
7
7
description = " Rust implementation of CSS Syntax Level 3"
Original file line number Diff line number Diff line change @@ -386,13 +386,21 @@ fn parse_color_hash(value: &str) -> Result<Color, ()> {
386
386
}
387
387
388
388
fn clamp_unit_f32 ( val : f32 ) -> u8 {
389
- // Scale by 256, not 255, so that each of the 256 u8 values has an equal range
390
- // of f32 values mapping to it. Floor before clamping.
389
+ // Whilst scaling by 256 and flooring would provide
390
+ // an equal distribution of integers to percentage inputs,
391
+ // this is not what Gecko does so we instead multiply by 255
392
+ // and round (adding 0.5 and flooring is equivalent to rounding)
391
393
//
392
- // Clamping to 256 and flooring after would let 1.0 map to 256, and
394
+ // Chrome does something similar for the alpha value, but not
395
+ // the rgb values.
396
+ //
397
+ // See https://bugzilla.mozilla.org/show_bug.cgi?id=1340484
398
+ //
399
+ // Clamping to 256 and rounding after would let 1.0 map to 256, and
393
400
// `256.0_f32 as u8` is undefined behavior:
394
401
//
395
402
// https://github.com/rust-lang/rust/issues/10184
403
+ clamp_256_f32 ( val * 255. + 0.5 )
396
404
clamp_256_f32 ( val * 256. )
397
405
}
398
406
You can’t perform that action at this time.
0 commit comments