Merge pull request #1841 from wash2/fix-svg-color-filter

fix: tiny-skia svg premultiply final filtered color
This commit is contained in:
Héctor Ramón 2023-05-10 01:56:25 +02:00 committed by GitHub
commit 422b4dedcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -141,18 +141,19 @@ impl Cache {
image.as_mut(),
)?;
if let Some([r, g, b, a]) = key.color {
// TODO: Blend alpha
let color = tiny_skia::ColorU8::from_rgba(b, g, r, a)
.premultiply()
.get()
& 0x00FFFFFF;
if let Some([r, g, b, _]) = key.color {
// Apply color filter
for pixel in
bytemuck::cast_slice_mut::<u8, u32>(image.data_mut())
{
*pixel = *pixel & 0xFF000000 | color;
*pixel = tiny_skia::ColorU8::from_rgba(
b,
g,
r,
(*pixel >> 24) as u8,
)
.premultiply()
.get();
}
} else {
// Swap R and B channels for `softbuffer` presentation