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 unsigned integer casting to cast and make Packed general purpose #255

Merged
merged 2 commits into from
Aug 22, 2021

Conversation

Ogeon
Copy link
Owner

@Ogeon Ogeon commented Aug 21, 2021

I have added a UintCast trait and casting functions, similar to what I did for arrays in #254, to make it less awkward when casting collections of unsigned integers. I have also made Packed a part of cast and made it work with any color space and any storage format (including arrays and other unsigned integers). It implements ArrayCast if it wraps an array and UintCast if it wraps an unsigned integer.

There's also a bunch of related QoL changes for Rgb and Luma (which has gotten Packed compatibility), as well as some code that has been moved around.

Breaking Change

The Packed struct takes its storage format as a type parameter, is no longer specific to RGB, and has moved into cast. RgbChannels has been renamed to ComponentOrder and has been moved into cast.

@github-actions
Copy link

Benchmark for dbeb343

Click to view benchmark
Test PR Benchmark Master Benchmark %
Cie family/lab to lch 3.2±0.11µs 3.2±0.13µs 0.00%
Cie family/lab to xyz 903.4±39.67ns 880.3±34.74ns +2.62%
Cie family/lch to lab 2.3±0.08µs 2.2±0.07µs +4.55%
Cie family/linsrgb to xyz 3.7±0.11µs 3.7±0.14µs 0.00%
Cie family/xyz to lab 9.9±0.37µs 9.6±0.43µs +3.13%
Cie family/xyz to yxy 730.9±24.58ns 705.5±30.03ns +3.60%
Cie family/yxy to xyz 664.2±28.39ns 650.3±22.19ns +2.14%
Matrix functions/matrix_inverse 12.5±0.48ns 12.3±0.62ns +1.63%
Matrix functions/multiply_3x3 9.9±0.42ns 9.5±0.39ns +4.21%
Matrix functions/multiply_rgb_to_xyz 4.3±0.17ns 4.3±0.17ns 0.00%
Matrix functions/multiply_xyz 4.5±0.13ns 4.3±0.20ns +4.65%
Matrix functions/multiply_xyz_to_rgb 4.3±0.17ns 4.3±0.22ns 0.00%
Matrix functions/rgb_to_xyz_matrix 22.6±0.92ns 22.2±1.01ns +1.80%
Rgb family/hsl to hsv 682.4±35.84ns 700.6±29.44ns -2.60%
Rgb family/hsl to linear hsl 8.4±0.32µs 8.5±0.40µs -1.18%
Rgb family/hsl to rgb 2.3±0.09µs 2.4±0.14µs -4.17%
Rgb family/hsv to hsl 1144.3±42.34ns 1149.9±38.04ns -0.49%
Rgb family/hsv to hwb 245.5±9.81ns 268.1±6.12ns -8.43%
Rgb family/hsv to linear hsv 7.8±0.41µs 7.9±0.37µs -1.27%
Rgb family/hsv to rgb 2.2±0.09µs 2.2±0.08µs 0.00%
Rgb family/hwb to hsv 610.2±26.55ns 606.6±25.65ns +0.59%
Rgb family/hwb to linear hwb 8.4±0.36µs 8.6±0.30µs -2.33%
Rgb family/linear hsl to hsl 9.5±0.44µs 9.1±0.38µs +4.40%
Rgb family/linear hsv to hsv 8.9±0.37µs 8.5±0.33µs +4.71%
Rgb family/linear hwb to hwb 9.3±0.39µs 9.3±0.38µs 0.00%
Rgb family/linsrgb to rgb 4.2±0.18µs 4.2±0.18µs 0.00%
Rgb family/linsrgb_f32 to rgb_u8 5.8±0.22µs 5.7±0.24µs +1.75%
Rgb family/rgb to hsl 788.6±32.38ns 781.2±32.15ns +0.95%
Rgb family/rgb to hsv 579.0±23.27ns 595.3±23.92ns -2.74%
Rgb family/rgb to linsrgb 4.6±0.22µs 4.5±0.22µs +2.22%
Rgb family/rgb_u8 to linsrgb_f32 5.1±0.34µs 4.9±0.18µs +4.08%
Rgb family/xyz to linsrgb 6.9±0.27µs 8.1±0.32µs -14.81%

@github-actions
Copy link

Benchmark for 6cc2632

Click to view benchmark
Test PR Benchmark Master Benchmark %
Cie family/lab to lch 3.3±0.22µs 3.2±0.21µs +3.12%
Cie family/lab to xyz 912.3±57.51ns 903.7±52.65ns +0.95%
Cie family/lch to lab 2.8±0.14µs 2.8±0.16µs 0.00%
Cie family/linsrgb to xyz 3.9±0.23µs 3.9±0.24µs 0.00%
Cie family/xyz to lab 10.4±0.74µs 10.1±1.14µs +2.97%
Cie family/xyz to yxy 720.5±57.50ns 732.9±45.25ns -1.69%
Cie family/yxy to xyz 675.4±35.93ns 654.4±41.07ns +3.21%
Matrix functions/matrix_inverse 13.1±0.84ns 13.6±1.03ns -3.68%
Matrix functions/multiply_3x3 11.1±0.72ns 11.3±0.64ns -1.77%
Matrix functions/multiply_rgb_to_xyz 4.6±0.33ns 4.6±0.27ns 0.00%
Matrix functions/multiply_xyz 4.7±0.24ns 4.8±0.24ns -2.08%
Matrix functions/multiply_xyz_to_rgb 4.6±0.27ns 4.6±0.28ns 0.00%
Matrix functions/rgb_to_xyz_matrix 25.0±1.15ns 24.5±1.86ns +2.04%
Rgb family/hsl to hsv 786.7±110.36ns 785.3±63.60ns +0.18%
Rgb family/hsl to linear hsl 9.4±0.57µs 9.5±0.60µs -1.05%
Rgb family/hsl to rgb 2.4±0.18µs 2.4±0.14µs 0.00%
Rgb family/hsv to hsl 1136.7±59.88ns 1179.7±75.96ns -3.64%
Rgb family/hsv to hwb 288.3±23.20ns 281.2±14.59ns +2.52%
Rgb family/hsv to linear hsv 8.8±0.45µs 9.0±0.48µs -2.22%
Rgb family/hsv to rgb 2.4±0.17µs 2.4±0.13µs 0.00%
Rgb family/hwb to hsv 692.9±55.23ns 653.7±39.26ns +6.00%
Rgb family/hwb to linear hwb 9.6±0.60µs 9.6±0.59µs 0.00%
Rgb family/linear hsl to hsl 10.2±0.67µs 9.8±0.78µs +4.08%
Rgb family/linear hsv to hsv 9.5±0.52µs 9.5±0.56µs 0.00%
Rgb family/linear hwb to hwb 10.0±0.56µs 10.0±0.75µs 0.00%
Rgb family/linsrgb to rgb 5.0±0.39µs 4.9±0.38µs +2.04%
Rgb family/linsrgb_f32 to rgb_u8 6.6±0.48µs 6.8±0.59µs -2.94%
Rgb family/rgb to hsl 921.4±68.77ns 940.9±58.70ns -2.07%
Rgb family/rgb to hsv 674.3±32.61ns 685.2±42.12ns -1.59%
Rgb family/rgb to linsrgb 5.5±0.34µs 5.3±0.37µs +3.77%
Rgb family/rgb_u8 to linsrgb_f32 5.8±0.47µs 5.6±0.50µs +3.57%
Rgb family/xyz to linsrgb 7.5±0.43µs 7.3±0.38µs +2.74%

@github-actions
Copy link

Benchmark for e62bc8f

Click to view benchmark
Test PR Benchmark Master Benchmark %
Cie family/lab to lch 3.5±0.29µs 3.3±0.21µs +6.06%
Cie family/lab to xyz 963.5±58.15ns 935.0±51.36ns +3.05%
Cie family/lch to lab 2.8±0.24µs 2.9±0.12µs -3.45%
Cie family/linsrgb to xyz 4.2±0.16µs 4.0±0.14µs +5.00%
Cie family/xyz to lab 10.8±0.64µs 10.6±0.61µs +1.89%
Cie family/xyz to yxy 734.5±58.88ns 753.8±93.94ns -2.56%
Cie family/yxy to xyz 686.9±23.33ns 681.2±25.99ns +0.84%
Matrix functions/matrix_inverse 14.2±0.73ns 14.3±1.22ns -0.70%
Matrix functions/multiply_3x3 11.7±0.87ns 11.7±0.72ns 0.00%
Matrix functions/multiply_rgb_to_xyz 4.8±0.24ns 4.9±0.29ns -2.04%
Matrix functions/multiply_xyz 5.0±0.26ns 4.8±0.28ns +4.17%
Matrix functions/multiply_xyz_to_rgb 4.8±0.27ns 4.8±0.22ns 0.00%
Matrix functions/rgb_to_xyz_matrix 25.0±1.03ns 24.8±1.74ns +0.81%
Rgb family/hsl to hsv 799.6±21.63ns 817.9±25.01ns -2.24%
Rgb family/hsl to linear hsl 9.9±0.52µs 10.1±0.63µs -1.98%
Rgb family/hsl to rgb 2.5±0.48µs 2.4±0.11µs +4.17%
Rgb family/hsv to hsl 1252.1±128.38ns 1231.6±53.95ns +1.66%
Rgb family/hsv to hwb 297.1±13.10ns 292.5±10.85ns +1.57%
Rgb family/hsv to linear hsv 9.3±0.50µs 9.6±0.65µs -3.12%
Rgb family/hsv to rgb 2.4±0.12µs 2.4±0.11µs 0.00%
Rgb family/hwb to hsv 694.4±31.82ns 712.1±37.49ns -2.49%
Rgb family/hwb to linear hwb 9.9±0.51µs 10.0±0.43µs -1.00%
Rgb family/linear hsl to hsl 10.5±1.12µs 10.2±0.38µs +2.94%
Rgb family/linear hsv to hsv 9.8±0.37µs 10.1±0.68µs -2.97%
Rgb family/linear hwb to hwb 10.4±0.32µs 10.2±0.40µs +1.96%
Rgb family/linsrgb to rgb 5.2±0.24µs 5.1±0.31µs +1.96%
Rgb family/linsrgb_f32 to rgb_u8 7.0±0.36µs 6.9±0.38µs +1.45%
Rgb family/rgb to hsl 990.1±73.44ns 957.9±34.84ns +3.36%
Rgb family/rgb to hsv 713.1±25.91ns 696.1±22.28ns +2.44%
Rgb family/rgb to linsrgb 5.6±0.34µs 5.4±0.14µs +3.70%
Rgb family/rgb_u8 to linsrgb_f32 5.8±0.20µs 5.8±0.29µs 0.00%
Rgb family/xyz to linsrgb 7.8±0.36µs 7.7±1.12µs +1.30%

@Ogeon
Copy link
Owner Author

Ogeon commented Aug 22, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Aug 22, 2021

Build succeeded:

@bors bors bot merged commit a57a054 into master Aug 22, 2021
@bors bors bot deleted the uint_cast branch August 22, 2021 13:28
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