Skip to content

Conversation

@Legend-Master
Copy link
Contributor

Fix #14351 (comment)

Demultiply tiny skia Pixmap pixel alphas before converting to image::ImageBuffer

@Legend-Master Legend-Master requested a review from a team as a code owner November 5, 2025 00:30
@github-project-automation github-project-automation bot moved this to 📬Proposal in Roadmap Nov 5, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Package Changes Through d3d498d

There are 2 changes which include tauri-cli with patch, @tauri-apps/cli with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
@tauri-apps/cli 2.9.3 2.9.4
tauri-cli 2.9.3 2.9.4

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

Comment on lines +138 to +144
// 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)
Copy link
Member

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?

Copy link
Contributor Author

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 😂

@Legend-Master Legend-Master merged commit b586ecf into tauri-apps:dev Nov 6, 2025
13 checks passed
@github-project-automation github-project-automation bot moved this from 📬Proposal to 🔎 In audit in Roadmap Nov 6, 2025
@Legend-Master Legend-Master deleted the demultiply-alpha-svg-icon branch November 6, 2025 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 In audit

Development

Successfully merging this pull request may close these issues.

[bug] [CLI] Halo/gray fringe appears around icons generated by tauri icon when using transparent PNG/SVG input

2 participants