diff mbox series

[1/3] Cursor: 8 -> 1 bit alpha downsampling improvement

Message ID 20240608202045.2815-2-phil@philjordan.eu
State New
Headers show
Series Mouse cursor improvements on macOS and VNC | expand

Commit Message

Phil Dennis-Jordan June 8, 2024, 8:20 p.m. UTC
Mouse cursors with 8 bit alpha were downsampled to 1-bit opacity maps by
turning alpha values of 255 into 1 and everything else into 0. This
means that mostly-opaque pixels ended up completely invisible.

This patch changes the behaviour so that only pixels with less than 50%
alpha (0-127) are treated as transparent when converted to 1-bit alpha.

This greatly improves the subjective appearance of anti-aliased mouse
cursors, such as those used by macOS, when using a front-end UI without
support for alpha-blended cursors, such as some VNC clients.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
 ui/cursor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Akihiko Odaki June 9, 2024, 8:52 a.m. UTC | #1
On 2024/06/09 5:20, Phil Dennis-Jordan wrote:
> Mouse cursors with 8 bit alpha were downsampled to 1-bit opacity maps by
> turning alpha values of 255 into 1 and everything else into 0. This
> means that mostly-opaque pixels ended up completely invisible.
> 
> This patch changes the behaviour so that only pixels with less than 50%
> alpha (0-127) are treated as transparent when converted to 1-bit alpha.
> 
> This greatly improves the subjective appearance of anti-aliased mouse
> cursors, such as those used by macOS, when using a front-end UI without
> support for alpha-blended cursors, such as some VNC clients.
> 
> Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
> ---
>   ui/cursor.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/ui/cursor.c b/ui/cursor.c
> index 29717b3ecb..4c05e5555c 100644
> --- a/ui/cursor.c
> +++ b/ui/cursor.c
> @@ -232,7 +232,7 @@ void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask)
>       for (y = 0; y < c->height; y++) {
>           bit = 0x80;
>           for (x = 0; x < c->width; x++, data++) {
> -            if ((*data & 0xff000000) != 0xff000000) {
> +            if ((*data & 0xff000000) < 0x80000000) {

You can just evaluate: !(*data & 0x80000000)
diff mbox series

Patch

diff --git a/ui/cursor.c b/ui/cursor.c
index 29717b3ecb..4c05e5555c 100644
--- a/ui/cursor.c
+++ b/ui/cursor.c
@@ -232,7 +232,7 @@  void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask)
     for (y = 0; y < c->height; y++) {
         bit = 0x80;
         for (x = 0; x < c->width; x++, data++) {
-            if ((*data & 0xff000000) != 0xff000000) {
+            if ((*data & 0xff000000) < 0x80000000) {
                 if (transparent != 0) {
                     mask[x/8] |= bit;
                 }