From 335e575fe0167d1ac890ed3674c2a9d971b2931d Mon Sep 17 00:00:00 2001 From: Kitsu Date: Thu, 10 Dec 2020 11:31:12 +0300 Subject: [PATCH] fix: normalize colors at rgba_to_argb More info can be found at: https://github.com/jrmuizel/raqote/issues/167 --- src/icon.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/icon.rs b/src/icon.rs index e8d5047..c5365af 100644 --- a/src/icon.rs +++ b/src/icon.rs @@ -88,10 +88,13 @@ fn rgba_to_argb(buf: &[u8]) -> Vec { let mut data = vec![]; for chunk in buf.chunks(4) { - let a = u32::from(chunk[3]) << 24; - let r = u32::from(chunk[0]) << 16; - let g = u32::from(chunk[1]) << 8; - let b = u32::from(chunk[2]); + let src = + raqote::SolidSource::from_unpremultiplied_argb(chunk[3], chunk[0], chunk[1], chunk[2]); + + let a = u32::from(src.a) << 24; + let r = u32::from(src.r) << 16; + let g = u32::from(src.g) << 8; + let b = u32::from(src.b); data.push(a | r | g | b); }