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

Split and rework the Blend trait and bump MSRV to 1.55.0 #273

Merged
merged 1 commit into from
Mar 10, 2022
Merged

Conversation

Ogeon
Copy link
Owner

@Ogeon Ogeon commented Mar 6, 2022

The Blend trait has been split into Compose, Blend and BlendWith, to allow more color spaces to be composed. The trait implementations were also changed from a default implementation to blanket implementations. Having blanket implementations allows users to only require the trait to be implemented without having to specify the trait's requirements. For example, it's only required to specify where C: Blend instead of listing all the mathematical requirements.

The PreAlpha type has also been changed a lot to get rid of the alpha type parameter and to leave premultiplication to the color types. A lot of it was developed in tandem with changing how the blending was implemented to make those implementations make more sense.

Closed Issues

Breaking Change

The Blend trait, the PreAlpha type and a lot of associated API has been changed. Most users should not notice too much, except for needing a different trait or getting it from the blend module. The ComponentWise trait is also gone, since all colors can be cast to arrays for iteration

MSRV is changed to 1.55.0 to be able to use [T; N]::map.

@Ogeon
Copy link
Owner Author

Ogeon commented Mar 6, 2022

This is what I have been up to for the past few weeks. At least to and from. There is still room for improvement but it should at least be more useful and less confusing than before. And the examples helps with verifying the implementation. Note, when looking at them, that they use linear colors. Many applications will not do that, so they may differ a bit. I'm considering allowing any RGB encoding for that reason.

@github-actions
Copy link

github-actions bot commented Mar 6, 2022

Benchmark for 017b4d7

Click to view benchmark
Test Base PR %
Cie family/lab to lch 3.0±0.15µs 3.0±0.22µs 0.00%
Cie family/lab to xyz 800.4±46.74ns 796.5±38.49ns -0.49%
Cie family/lch to lab 2.3±0.10µs 2.2±0.11µs -4.35%
Cie family/linsrgb to xyz 3.3±0.07µs 3.3±0.16µs 0.00%
Cie family/xyz to lab 18.1±1.01µs 17.3±0.97µs -4.42%
Cie family/xyz to yxy 662.3±27.83ns 669.0±19.98ns +1.01%
Cie family/yxy to xyz 507.5±25.95ns 491.9±31.01ns -3.07%
Matrix functions/matrix_inverse 10.0±0.54ns 9.4±0.31ns -6.00%
Matrix functions/multiply_3x3 13.8±0.72ns 13.7±0.81ns -0.72%
Matrix functions/multiply_rgb_to_xyz 6.4±0.26ns 6.3±0.34ns -1.56%
Matrix functions/multiply_xyz 6.3±0.40ns 6.2±0.32ns -1.59%
Matrix functions/multiply_xyz_to_rgb 6.3±0.31ns 6.2±0.34ns -1.59%
Matrix functions/rgb_to_xyz_matrix 21.6±1.16ns 20.4±1.16ns -5.56%
Rgb family/hsl to hsv 637.1±8.59ns 564.3±14.98ns -11.43%
Rgb family/hsl to linear hsl 9.9±0.57µs 10.6±0.18µs +7.07%
Rgb family/hsl to rgb 2.2±0.11µs 2.1±0.18µs -4.55%
Rgb family/hsv to hsl 913.4±54.56ns 861.5±18.40ns -5.68%
Rgb family/hsv to hwb 223.2±12.03ns 208.2±7.41ns -6.72%
Rgb family/hsv to linear hsv 9.5±1.57µs 9.9±0.15µs +4.21%
Rgb family/hsv to rgb 2.1±0.13µs 2.2±0.07µs +4.76%
Rgb family/hwb to hsv 621.6±16.89ns 561.1±22.96ns -9.73%
Rgb family/hwb to linear hwb 10.7±0.63µs 10.2±0.55µs -4.67%
Rgb family/linear hsl to hsl 10.6±0.41µs 9.9±0.57µs -6.60%
Rgb family/linear hsv to hsv 9.6±0.51µs 9.8±0.55µs +2.08%
Rgb family/linear hwb to hwb 11.1±0.51µs 10.4±0.63µs -6.31%
Rgb family/linsrgb to rgb 5.8±0.33µs 6.0±0.36µs +3.45%
Rgb family/linsrgb_f32 to rgb_u8 6.4±0.36µs 6.9±0.09µs +7.81%
Rgb family/rgb to hsl 818.4±42.63ns 762.7±31.88ns -6.81%
Rgb family/rgb to hsv 677.0±17.32ns 654.3±37.36ns -3.35%
Rgb family/rgb to linsrgb 5.6±0.31µs 5.5±0.30µs -1.79%
Rgb family/rgb_u8 to linsrgb_f32 6.1±0.34µs 6.4±0.15µs +4.92%
Rgb family/xyz to linsrgb 5.4±0.29µs 5.6±0.20µs +3.70%

@Ogeon Ogeon mentioned this pull request Mar 6, 2022
@Ogeon Ogeon changed the title Split and rework the Blend trait Split and rework the Blend trait and bump MSRV to 1.55.0 Mar 6, 2022
@github-actions
Copy link

github-actions bot commented Mar 6, 2022

Benchmark for 656865a

Click to view benchmark
Test Base PR %
Cie family/lab to lch 4.0±0.18µs 4.0±0.25µs 0.00%
Cie family/lab to xyz 1008.0±32.54ns 1010.0±46.70ns +0.20%
Cie family/lch to lab 2.9±0.13µs 2.9±0.11µs 0.00%
Cie family/linsrgb to xyz 4.4±0.18µs 4.4±0.16µs 0.00%
Cie family/xyz to lab 22.5±1.23µs 22.4±0.75µs -0.44%
Cie family/xyz to yxy 813.9±28.18ns 825.0±38.47ns +1.36%
Cie family/yxy to xyz 643.3±22.95ns 649.0±29.66ns +0.89%
Matrix functions/matrix_inverse 13.0±0.77ns 12.6±0.49ns -3.08%
Matrix functions/multiply_3x3 17.5±0.68ns 17.4±0.78ns -0.57%
Matrix functions/multiply_rgb_to_xyz 8.1±0.51ns 8.0±0.27ns -1.23%
Matrix functions/multiply_xyz 8.1±0.43ns 8.0±0.25ns -1.23%
Matrix functions/multiply_xyz_to_rgb 8.1±0.41ns 8.0±0.27ns -1.23%
Matrix functions/rgb_to_xyz_matrix 27.4±1.27ns 27.0±0.88ns -1.46%
Rgb family/hsl to hsv 782.0±53.23ns 767.4±21.38ns -1.87%
Rgb family/hsl to linear hsl 12.8±0.53µs 12.9±0.66µs +0.78%
Rgb family/hsl to rgb 2.8±0.17µs 2.8±0.13µs 0.00%
Rgb family/hsv to hsl 1175.1±49.37ns 1187.0±54.04ns +1.01%
Rgb family/hsv to hwb 281.2±9.68ns 280.6±8.63ns -0.21%
Rgb family/hsv to linear hsv 12.5±0.70µs 12.1±0.44µs -3.20%
Rgb family/hsv to rgb 2.7±0.12µs 2.7±0.09µs 0.00%
Rgb family/hwb to hsv 766.6±46.66ns 759.0±25.24ns -0.99%
Rgb family/hwb to linear hwb 13.8±0.52µs 13.7±0.88µs -0.72%
Rgb family/linear hsl to hsl 13.3±0.42µs 12.9±0.52µs -3.01%
Rgb family/linear hsv to hsv 12.7±0.50µs 12.4±0.71µs -2.36%
Rgb family/linear hwb to hwb 14.0±0.66µs 13.9±0.41µs -0.71%
Rgb family/linsrgb to rgb 7.5±0.32µs 7.4±0.21µs -1.33%
Rgb family/linsrgb_f32 to rgb_u8 8.4±0.25µs 8.4±0.34µs 0.00%
Rgb family/rgb to hsl 1040.3±55.57ns 1036.5±40.14ns -0.37%
Rgb family/rgb to hsv 816.5±24.03ns 823.7±45.41ns +0.88%
Rgb family/rgb to linsrgb 7.2±0.29µs 7.1±0.23µs -1.39%
Rgb family/rgb_u8 to linsrgb_f32 7.8±0.54µs 7.8±0.45µs 0.00%
Rgb family/xyz to linsrgb 6.8±0.25µs 6.9±0.64µs +1.47%

@github-actions
Copy link

github-actions bot commented Mar 6, 2022

Benchmark for 05ac1dc

Click to view benchmark
Test Base PR %
Cie family/lab to lch 3.3±0.05µs 3.3±0.04µs 0.00%
Cie family/lab to xyz 825.9±9.96ns 825.8±13.16ns -0.01%
Cie family/lch to lab 2.3±0.03µs 2.4±0.04µs +4.35%
Cie family/linsrgb to xyz 3.7±0.09µs 3.7±0.06µs 0.00%
Cie family/xyz to lab 18.5±0.34µs 18.6±0.81µs +0.54%
Cie family/xyz to yxy 671.1±9.98ns 672.3±10.39ns +0.18%
Cie family/yxy to xyz 533.1±11.29ns 533.2±9.82ns +0.02%
Matrix functions/matrix_inverse 10.9±0.19ns 10.6±0.16ns -2.75%
Matrix functions/multiply_3x3 14.5±0.18ns 14.5±0.26ns 0.00%
Matrix functions/multiply_rgb_to_xyz 6.6±0.11ns 6.6±0.09ns 0.00%
Matrix functions/multiply_xyz 6.6±0.20ns 6.6±0.09ns 0.00%
Matrix functions/multiply_xyz_to_rgb 6.6±0.10ns 6.6±0.13ns 0.00%
Matrix functions/rgb_to_xyz_matrix 22.5±0.29ns 22.5±0.32ns 0.00%
Rgb family/hsl to hsv 639.7±14.07ns 636.6±11.35ns -0.48%
Rgb family/hsl to linear hsl 10.5±0.17µs 10.5±0.23µs 0.00%
Rgb family/hsl to rgb 2.3±0.05µs 2.3±0.03µs 0.00%
Rgb family/hsv to hsl 981.8±21.49ns 971.3±11.38ns -1.07%
Rgb family/hsv to hwb 231.9±3.17ns 233.6±7.84ns +0.73%
Rgb family/hsv to linear hsv 10.0±0.13µs 10.0±0.22µs 0.00%
Rgb family/hsv to rgb 2.2±0.04µs 2.2±0.06µs 0.00%
Rgb family/hwb to hsv 626.1±10.39ns 625.3±10.36ns -0.13%
Rgb family/hwb to linear hwb 11.2±0.13µs 11.2±0.19µs 0.00%
Rgb family/linear hsl to hsl 10.6±0.18µs 10.6±0.17µs 0.00%
Rgb family/linear hsv to hsv 10.2±0.17µs 10.1±0.14µs -0.98%
Rgb family/linear hwb to hwb 11.4±0.23µs 11.4±0.19µs 0.00%
Rgb family/linsrgb to rgb 6.2±0.16µs 6.2±0.08µs 0.00%
Rgb family/linsrgb_f32 to rgb_u8 6.9±0.13µs 6.8±0.11µs -1.45%
Rgb family/rgb to hsl 848.0±13.02ns 847.8±11.98ns -0.02%
Rgb family/rgb to hsv 681.5±9.57ns 688.4±15.37ns +1.01%
Rgb family/rgb to linsrgb 6.0±0.07µs 5.9±0.09µs -1.67%
Rgb family/rgb_u8 to linsrgb_f32 6.4±0.11µs 6.4±0.11µs 0.00%
Rgb family/xyz to linsrgb 5.6±0.08µs 5.7±0.08µs +1.79%

@Ogeon
Copy link
Owner Author

Ogeon commented Mar 10, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 10, 2022

Build succeeded:

@bors bors bot merged commit 563370c into master Mar 10, 2022
@bors bors bot deleted the blend_traits branch March 10, 2022 19:13
@Ogeon Ogeon changed the title Split and rework the Blend trait and bump MSRV to 1.55.0 Split and rework the Blend trait and bump MSRV to 1.55.0 Mar 19, 2023
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.

Improve the blend traits and minimize their dependencies
1 participant