File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change 11[package ]
22
33name = " cssparser"
4- version = " 0.13.1 "
4+ version = " 0.13.2 "
55authors = [ " Simon Sapin <simon.sapin@exyr.org>" ]
66
77description = " 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, ()> {
386386}
387387
388388fn 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)
391393 //
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
393400 // `256.0_f32 as u8` is undefined behavior:
394401 //
395402 // https://github.com/rust-lang/rust/issues/10184
403+ clamp_256_f32 ( val * 255. + 0.5 )
396404 clamp_256_f32 ( val * 256. )
397405}
398406
You can’t perform that action at this time.
0 commit comments