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

Brush, with alpha. #27

Closed
simbleau opened this issue Mar 21, 2024 · 5 comments · Fixed by #40
Closed

Brush, with alpha. #27

simbleau opened this issue Mar 21, 2024 · 5 comments · Fixed by #40
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@simbleau
Copy link
Member

In Velato, there's a section @dfrg wrote stating we should move logic to peniko to allow alpha factors for brushes.

// TODO: probably move this to peniko. The better option is to add an alpha
// parameter to the draw methods in vello. This is already handled at the
// encoding level.
pub(crate) fn brush_with_alpha(brush: &Brush, alpha: f64) -> Brush {
    if alpha == 1.0 {
        brush.clone()
    } else {
        match brush {
            Brush::Solid(color) => color.with_alpha_factor(alpha as f32).into(),
            Brush::Gradient(gradient) => Brush::Gradient(peniko::Gradient {
                kind: gradient.kind,
                extend: gradient.extend,
                stops: gradient
                    .stops
                    .iter()
                    .map(|stop| stop.with_alpha_factor(alpha as f32))
                    .collect(),
            }),
            _ => unreachable!(),
        }
    }
}
@simbleau simbleau added enhancement New feature or request good first issue Good for newcomers labels Mar 21, 2024
@ratmice
Copy link
Contributor

ratmice commented May 25, 2024

Probably not going to get to this soon as i am sick 🤧. When lifted into peniko the unreachable arm of the match statement isn't actually unreachable. I guess first choice would be making it return a Result and failing that, switch Brush::Image(_) => panic!("Unsupported brush variant Image"), to at least give it a more useful error.

@waywardmonkeys
Copy link
Contributor

I confess to being a little confused since the comment says this could also go into Vello and that being a better option?

@simbleau
Copy link
Member Author

I confess to being a little confused since the comment says this could also go into Vello and that being a better option?

@dfrg can you clarify your comment?

@dfrg
Copy link
Contributor

dfrg commented May 25, 2024

Sure. The various brush methods in Encoding have support for applying an alpha modifier but this isn’t exposed by Scene. The parameter list is already quite long for the fill and stroke methods so I’m reluctant to tack on another one. Maybe this calls for a builder or an options parameter to capture the less frequently used properties.

I still think this would be useful in peniko.

@dfrg
Copy link
Contributor

dfrg commented May 25, 2024

Ah, I see the problem with the image brush. Seems like the best option there would be to add an alpha multiplier field to the image struct and then have vello (or other renderers) handle it.

github-merge-queue bot pushed a commit that referenced this issue Jul 3, 2024
Fixes #27

The key feature is adding `alpha` to `Image`. There were also a couple
of other papercuts which I've tweaked
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants