From 3f1c8a8d288d823529e81124bd514f626e84c610 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Tue, 9 May 2023 14:57:50 -0400 Subject: fix: tiny-skia svg premultiply final filtered color --- tiny_skia/src/vector.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'tiny_skia/src/vector.rs') diff --git a/tiny_skia/src/vector.rs b/tiny_skia/src/vector.rs index fc411fdd..a3f3c2e3 100644 --- a/tiny_skia/src/vector.rs +++ b/tiny_skia/src/vector.rs @@ -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::(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 -- cgit