Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ArraysAs, AsArrays, and corresponding traits for components and uints #345

Merged
merged 3 commits into from
Aug 10, 2023

Conversation

Ogeon
Copy link
Owner

@Ogeon Ogeon commented Aug 8, 2023

This adds more casting traits, in addition to #338. These traits fulfill the same purpose as AsRef and AsMut, such as:

use palette::{Srgb, cast::ComponentsAsMut};

let mut image_buffer: Vec<u8> = /* ... */;
let color_buffer: &mut [Srgb<u8>] = image_buffer.components_as_mut();

@github-actions
Copy link

github-actions bot commented Aug 8, 2023

Benchmark for 4ff5c50

Click to view benchmark
Test Base PR %
Cie family/lab to lch 3.3±0.00µs 3.3±0.01µs 0.00%
Cie family/lab to xyz 772.7±1.21ns 773.3±0.77ns +0.08%
Cie family/lch to lab 1220.6±0.62ns 1208.7±0.75ns -0.97%
Cie family/linsrgb to xyz 319.4±0.34ns 305.6±4.33ns -4.32%
Cie family/linsrgb to xyz - wide::f32x8 251.3±0.48ns 251.4±0.29ns +0.04%
Cie family/xyz to lab 8.6±0.01µs 8.6±0.02µs 0.00%
Cie family/xyz to yxy 673.2±0.38ns 681.0±0.50ns +1.16%
Cie family/yxy to xyz 624.1±0.34ns 619.8±0.33ns -0.69%
Matrix functions/matrix_inverse 13.9±0.01ns 14.3±0.01ns +2.88%
Matrix functions/multiply_3x3 9.8±0.01ns 9.8±0.01ns 0.00%
Matrix functions/multiply_rgb_to_xyz 8.4±0.02ns 8.4±0.01ns 0.00%
Matrix functions/multiply_xyz 6.0±0.04ns 6.0±0.04ns 0.00%
Matrix functions/multiply_xyz_to_rgb 6.0±0.03ns 6.0±0.03ns 0.00%
Matrix functions/rgb_to_xyz_matrix 26.1±0.01ns 26.0±0.02ns -0.38%
Rgb family/hsl to hsv 739.2±4.27ns 737.4±1.34ns -0.24%
Rgb family/hsl to linear hsl 7.5±0.01µs 7.5±0.01µs 0.00%
Rgb family/hsl to rgb 2.4±0.00µs 2.4±0.00µs 0.00%
Rgb family/hsv to hsl 968.7±1.87ns 985.3±0.55ns +1.71%
Rgb family/hsv to hwb 231.6±2.40ns 231.7±2.02ns +0.04%
Rgb family/hsv to linear hsv 6.9±0.01µs 7.0±0.00µs +1.45%
Rgb family/hsv to rgb 2.1±0.00µs 2.1±0.00µs 0.00%
Rgb family/hwb to hsv 556.7±1.12ns 557.6±0.40ns +0.16%
Rgb family/hwb to linear hwb 8.3±0.01µs 8.1±0.01µs -2.41%
Rgb family/linear hsl to hsl 7.5±0.01µs 7.5±0.01µs 0.00%
Rgb family/linear hsv to hsv 7.0±0.00µs 6.9±0.01µs -1.43%
Rgb family/linear hwb to hwb 8.2±0.02µs 8.2±0.00µs 0.00%
Rgb family/linsrgb to rgb 3.7±0.00µs 3.7±0.00µs 0.00%
Rgb family/linsrgb to rgb - wide::f32x8 5.0±0.00µs 5.1±0.00µs +2.00%
Rgb family/linsrgb_f32 to rgb_u8 1274.0±0.53ns 1274.1±0.66ns +0.01%
Rgb family/linsrgb_f64 to rgb_u8 1365.1±3.57ns 1365.2±3.10ns +0.01%
Rgb family/rgb to hsl 631.4±0.36ns 640.0±2.72ns +1.36%
Rgb family/rgb to hsl - wide::f32x8 456.1±0.22ns 456.5±0.25ns +0.09%
Rgb family/rgb to hsv 488.7±0.21ns 497.5±0.26ns +1.80%
Rgb family/rgb to hsv - wide::f32x8 415.9±1.51ns 416.1±0.23ns +0.05%
Rgb family/rgb to linsrgb 3.8±0.00µs 3.8±0.01µs 0.00%
Rgb family/rgb to linsrgb - wide::f32x8 3.1±0.00µs 3.1±0.00µs 0.00%
Rgb family/rgb_u8 to linsrgb_f32 303.4±1.09ns 303.4±1.10ns 0.00%
Rgb family/rgb_u8 to linsrgb_f64 309.5±1.41ns 310.6±1.43ns +0.36%
Rgb family/xyz to linsrgb 362.0±0.20ns 352.3±0.58ns -2.68%
Rgb family/xyz to linsrgb - wide::f32x8 248.7±0.24ns 248.9±1.70ns +0.08%

@github-actions
Copy link

github-actions bot commented Aug 8, 2023

Benchmark for e823a25

Click to view benchmark
Test Base PR %
Cie family/lab to lch 3.5±0.25µs 3.8±0.11µs +8.57%
Cie family/lab to xyz 808.4±41.32ns 750.7±28.13ns -7.14%
Cie family/lch to lab 1385.3±37.71ns 1335.3±90.23ns -3.61%
Cie family/linsrgb to xyz 309.8±21.70ns 330.3±23.89ns +6.62%
Cie family/linsrgb to xyz - wide::f32x8 275.0±13.78ns 245.3±11.80ns -10.80%
Cie family/xyz to lab 9.7±1.28µs 9.5±0.38µs -2.06%
Cie family/xyz to yxy 767.0±48.17ns 745.0±33.54ns -2.87%
Cie family/yxy to xyz 639.5±45.29ns 612.1±26.88ns -4.28%
Matrix functions/matrix_inverse 13.3±0.62ns 15.0±0.75ns +12.78%
Matrix functions/multiply_3x3 9.5±0.47ns 10.4±0.70ns +9.47%
Matrix functions/multiply_rgb_to_xyz 8.3±0.40ns 8.5±0.46ns +2.41%
Matrix functions/multiply_xyz 6.0±0.38ns 6.4±0.36ns +6.67%
Matrix functions/multiply_xyz_to_rgb 5.9±0.30ns 6.2±0.29ns +5.08%
Matrix functions/rgb_to_xyz_matrix 26.8±1.73ns 27.6±1.38ns +2.99%
Rgb family/hsl to hsv 796.5±35.23ns 816.3±37.85ns +2.49%
Rgb family/hsl to linear hsl 7.9±0.30µs 7.3±0.33µs -7.59%
Rgb family/hsl to rgb 2.5±0.12µs 2.4±0.15µs -4.00%
Rgb family/hsv to hsl 1090.6±56.20ns 978.8±67.81ns -10.25%
Rgb family/hsv to hwb 240.0±11.13ns 261.5±8.47ns +8.96%
Rgb family/hsv to linear hsv 7.4±0.43µs 6.8±0.36µs -8.11%
Rgb family/hsv to rgb 2.2±0.09µs 2.1±0.12µs -4.55%
Rgb family/hwb to hsv 596.0±30.02ns 579.0±49.95ns -2.85%
Rgb family/hwb to linear hwb 9.1±0.36µs 8.2±0.39µs -9.89%
Rgb family/linear hsl to hsl 8.0±0.40µs 7.5±0.44µs -6.25%
Rgb family/linear hsv to hsv 7.5±0.24µs 7.0±0.40µs -6.67%
Rgb family/linear hwb to hwb 9.0±0.30µs 8.0±0.43µs -11.11%
Rgb family/linsrgb to rgb 4.2±0.12µs 3.7±0.18µs -11.90%
Rgb family/linsrgb to rgb - wide::f32x8 5.7±0.18µs 5.0±0.24µs -12.28%
Rgb family/linsrgb_f32 to rgb_u8 1345.5±85.14ns 1344.5±95.20ns -0.07%
Rgb family/linsrgb_f64 to rgb_u8 1360.0±76.62ns 1397.7±135.06ns +2.77%
Rgb family/rgb to hsl 689.8±38.94ns 638.2±41.31ns -7.48%
Rgb family/rgb to hsl - wide::f32x8 510.8±24.33ns 454.2±25.77ns -11.08%
Rgb family/rgb to hsv 520.9±23.55ns 491.3±31.69ns -5.68%
Rgb family/rgb to hsv - wide::f32x8 455.9±22.71ns 466.0±28.06ns +2.22%
Rgb family/rgb to linsrgb 4.1±0.23µs 4.2±0.16µs +2.44%
Rgb family/rgb to linsrgb - wide::f32x8 3.3±0.20µs 3.4±0.15µs +3.03%
Rgb family/rgb_u8 to linsrgb_f32 345.9±12.55ns 311.1±12.53ns -10.06%
Rgb family/rgb_u8 to linsrgb_f64 314.3±17.95ns 338.6±14.34ns +7.73%
Rgb family/xyz to linsrgb 371.0±23.45ns 359.7±25.67ns -3.05%
Rgb family/xyz to linsrgb - wide::f32x8 265.2±12.92ns 244.9±13.42ns -7.65%

@Ogeon
Copy link
Owner Author

Ogeon commented Aug 10, 2023

bors r+

@bors
Copy link
Contributor

bors bot commented Aug 10, 2023

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.

  • ci

@bors bors bot merged commit 201943f into master Aug 10, 2023
15 checks passed
@bors bors bot deleted the as_ref_cast_traits branch August 10, 2023 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant