Ogeon / palette

A Rust library for linear color calculations and conversion
Apache License 2.0
748 stars 60 forks source link

Add a `Wcag21RelativeContrast` trait and deprecate `RelativeContrast` #326

Closed Ogeon closed 1 year ago

Ogeon commented 1 year ago

Similar to #316, this replaces the unspecific RelativeContrast trait with the more specific Wcag21RelativeContrast under the color_difference module. I did also try to make it a bit more straight forward to implement, but also implemented it for a more limited set of color spaces (essentially sRGB and D65 grayscale). The new trait is almost a drop-in replacement of the old.

github-actions[bot] commented 1 year ago

Benchmark for 4cb3592

Click to view benchmark | Test | Base | PR | % | |------|--------------|------------------|---| | Cie family/lab to lch | 3.3±0.11µs | **3.2±0.05µs** | **-3.03%** | | Cie family/lab to xyz | 762.5±7.90ns | 764.3±17.86ns | +0.24% | | Cie family/lch to lab | 2.5±0.04µs | 2.5±0.05µs | 0.00% | | Cie family/linsrgb to xyz | **308.0±8.04ns** | 313.3±4.41ns | **+1.72%** | | Cie family/linsrgb to xyz - wide::f32x8 | 99.7±1.44ns | 100.8±1.46ns | +1.10% | | Cie family/xyz to lab | 17.9±0.28µs | 18.0±0.39µs | +0.56% | | Cie family/xyz to yxy | 628.4±9.08ns | 631.7±7.19ns | +0.53% | | Cie family/yxy to xyz | 699.0±12.47ns | 699.3±36.27ns | +0.04% | | Matrix functions/matrix_inverse | 10.7±0.16ns | 10.7±0.13ns | 0.00% | | Matrix functions/multiply_3x3 | 9.6±0.13ns | 9.6±0.11ns | 0.00% | | Matrix functions/multiply_rgb_to_xyz | **6.0±0.09ns** | 6.1±0.17ns | **+1.67%** | | Matrix functions/multiply_xyz | 6.0±0.07ns | 6.0±0.08ns | 0.00% | | Matrix functions/multiply_xyz_to_rgb | 6.0±0.09ns | 6.0±0.12ns | 0.00% | | Matrix functions/rgb_to_xyz_matrix | 24.9±0.55ns | 24.9±0.42ns | 0.00% | | Rgb family/hsl to hsv | 648.1±11.58ns | 651.4±8.86ns | +0.51% | | Rgb family/hsl to linear hsl | 13.5±0.28µs | 13.5±0.28µs | 0.00% | | Rgb family/hsl to rgb | 2.1±0.04µs | 2.1±0.06µs | 0.00% | | Rgb family/hsv to hsl | 822.9±13.24ns | 818.0±10.47ns | -0.60% | | Rgb family/hsv to hwb | **232.9±3.68ns** | 237.2±6.28ns | **+1.85%** | | Rgb family/hsv to linear hsv | 12.3±0.17µs | **11.7±0.20µs** | **-4.88%** | | Rgb family/hsv to rgb | 1915.8±19.97ns | 1919.2±25.26ns | +0.18% | | Rgb family/hwb to hsv | 482.5±7.37ns | 481.5±12.59ns | -0.21% | | Rgb family/hwb to linear hwb | 12.9±0.15µs | **12.4±0.34µs** | **-3.88%** | | Rgb family/linear hsl to hsl | **11.2±0.27µs** | 11.7±0.18µs | **+4.46%** | | Rgb family/linear hsv to hsv | 10.6±0.12µs | **10.2±0.13µs** | **-3.77%** | | Rgb family/linear hwb to hwb | 11.5±0.19µs | **11.2±0.20µs** | **-2.61%** | | Rgb family/linsrgb to rgb | 6.7±0.08µs | **5.9±0.08µs** | **-11.94%** | | Rgb family/linsrgb to rgb - wide::f32x8 | 5.1±0.07µs | 5.1±0.07µs | 0.00% | | Rgb family/linsrgb_f32 to rgb_u8 | 954.1±14.16ns | 952.3±13.22ns | -0.19% | | Rgb family/linsrgb_f64 to rgb_u8 | 1217.7±16.47ns | 1214.2±11.82ns | -0.29% | | Rgb family/rgb to hsl | 852.9±10.40ns | 853.1±10.89ns | +0.02% | | Rgb family/rgb to hsl - wide::f32x8 | 470.3±6.83ns | 469.6±6.41ns | -0.15% | | Rgb family/rgb to hsv | 518.8±8.02ns | 515.9±8.70ns | -0.56% | | Rgb family/rgb to hsv - wide::f32x8 | 427.0±8.25ns | 426.0±5.09ns | -0.23% | | Rgb family/rgb to linsrgb | 9.3±0.09µs | **8.3±0.10µs** | **-10.75%** | | Rgb family/rgb to linsrgb - wide::f32x8 | 3.3±0.05µs | 3.3±0.04µs | 0.00% | | Rgb family/rgb_u8 to linsrgb_f32 | 307.0±4.94ns | 307.1±3.50ns | +0.03% | | Rgb family/rgb_u8 to linsrgb_f64 | 311.5±6.03ns | 311.3±4.07ns | -0.06% | | Rgb family/xyz to linsrgb | **353.1±4.13ns** | 359.3±10.23ns | **+1.76%** | | Rgb family/xyz to linsrgb - wide::f32x8 | 106.4±3.25ns | 106.4±1.84ns | 0.00% |
Ogeon commented 1 year ago

bors r+

bors[bot] commented 1 year ago

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here. For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.