-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix(cli): demultiply tiny skia pixels #14416
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
fix(cli): demultiply tiny skia pixels #14416
Conversation
Package Changes Through d3d498dThere are 2 changes which include tauri-cli with patch, @tauri-apps/cli with patch Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
| // Switch to use `Pixmap::take_demultiplied` in the future when it's published | ||
| // https://github.com/linebender/tiny-skia/blob/624257c0feb394bf6c4d0d688f8ea8030aae320f/src/pixmap.rs#L266 | ||
| let img_buffer = ImageBuffer::from_par_fn(size, size, |x, y| { | ||
| let pixel = pixmap.pixel(x, y).unwrap().demultiply(); | ||
| Rgba([pixel.red(), pixel.green(), pixel.blue(), pixel.alpha()]) | ||
| }); | ||
| DynamicImage::ImageRgba8(img_buffer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So skia by default has all pixels multiplied (whatever that means) so we demultiply all pixels to then be able to multiple the alpha channel specifically later in the same resize function that also multiplies the png alpha channel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like that tiny-skia does this, the documentation isn't clear here to be honest, but from the code and how they return &[PremultipliedColorU8], it looks like it (Skia marks this in SkPixmap, SkImageInfo, so it's a different story https://api.skia.org/SkAlphaType_8h.html#ad2e3e94ae1ad3b28c96802b77514ab45)
multiplied (whatever that means)
It's used for calculating filtering internally easier, but when we want the final value, we need to undo that
to then be able to multiple the alpha channel specifically later in the same resize function that also multiplies the png alpha channel
This can be optimized but I honestly don't care enough to do that 😂
Fix #14351 (comment)
Demultiply tiny skia
Pixmappixel alphas before converting toimage::ImageBuffer