Skip to content
New issue

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

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

Already on GitHub? # to your account

Add with_alpha and multiply_alpha on DynamicColor #71

Merged

Conversation

waywardmonkeys
Copy link
Collaborator

@waywardmonkeys waywardmonkeys commented Nov 26, 2024

If the alpha channel is missing, these operations will do nothing.

Additionally, mark some functions on Missing as const.

@waywardmonkeys
Copy link
Collaborator Author

waywardmonkeys commented Nov 26, 2024

For DynamicColor::multiply_alpha, I think that if the alpha is missing (and therefore 0.0), then the alpha remains missing.

But the interaction between that and DynamicColor::premultiply_split is not clear to me, since it treats a missing alpha as being opaque:

    fn premultiply_split(self) -> ([f32; 3], f32) {
        // Reference: §12.3 of Color 4 spec
        let (opaque, alpha) = split_alpha(self.components);
        let premul = if alpha == 1.0 || self.missing.contains(3) {
            opaque
        } else {
            self.cs.layout().scale(opaque, alpha)
        };
        (premul, alpha)
    }

So for the purposes of multiply_alpha, would we set it to not be missing and then set the alpha to the factor?

Same question for with_alpha where we're setting the alpha. Would we leave it missing or set it and clear the missing flag?

There's no code that clears missing flags, so maybe I'm wrong here and we should document that both things effectively do nothing when the alpha is explicitly missing?

@waywardmonkeys
Copy link
Collaborator Author

We need multiply_alpha for supporting using DynamicColor with peniko::ColorStop / peniko::Gradient.

@waywardmonkeys waywardmonkeys added this to the 0.2.0 milestone Nov 26, 2024
@waywardmonkeys waywardmonkeys force-pushed the alpha-ops-on-dynamic-color branch from 5d8a01f to 5888dfd Compare November 26, 2024 06:00
@waywardmonkeys
Copy link
Collaborator Author

I've answered my own question for now by leaving the color unchanged when modifying the alpha channel if the alpha channel is missing.

This is what would have happened if one had done the same operation via DynamicColor::map.

@waywardmonkeys waywardmonkeys force-pushed the alpha-ops-on-dynamic-color branch from 5888dfd to af45f25 Compare November 26, 2024 12:04
If the alpha channel is missing, these operations will do nothing.

Additionally, mark some functions on `Missing` as `const`.
@waywardmonkeys waywardmonkeys force-pushed the alpha-ops-on-dynamic-color branch from af45f25 to 270ff5c Compare November 26, 2024 17:02
Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@waywardmonkeys waywardmonkeys added this pull request to the merge queue Nov 26, 2024
Merged via the queue into linebender:main with commit c16a9ce Nov 26, 2024
15 checks passed
@waywardmonkeys waywardmonkeys deleted the alpha-ops-on-dynamic-color branch November 26, 2024 17:20
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants