kolunmi / sandbar

dwm-like bar for the river wayland compositor
Other
40 stars 4 forks source link

RGBA handling #2

Closed jeLee6gi closed 1 year ago

jeLee6gi commented 1 year ago

This might not be a bug but I didn't expect this behavior. When I set the alpha channel of a color to 0, it's transparent only when I also set RGB to 0. Here are some examples, the background color is #008080.

A 00 A 80 A FF
RGB 000000 sandbar_00000000_crop sandbar_00000080_crop sandbar_000000ff_crop
RGB 808080 sandbar_80808000_crop sandbar_80808080_crop sandbar_808080ff_crop
RGB FFFFFF sandbar_ffffff00_crop sandbar_ffffff80_crop sandbar_ffffffff_crop
kolunmi commented 1 year ago

Hello! This has to do with pixman using pre-multiplied alpha. To get the desired effect you need to multiply the RGB components by alpha / FF. So for 80808000: 80 * 00 / FF = 00 and thus 00000000. I'm not sure how to address this issue since converting this way can introduce some inaccuracy.

jeLee6gi commented 1 year ago

Oh I was not familiar with premultiplied alpha. Thank you for the explanation, TIL.