Sfoglia il codice sorgente

x11: Premultiply custom cursor image alpha

As with Wayland, X11 expects cursor pixels to have the alpha
premultiplied, so lets convert the non-premultiplied pixels to
premultiplied pixels.

Fixes #353.
Closes #707.
Jonas Ådahl 9 anni fa
parent
commit
9160a7ceb3
1 ha cambiato i file con 6 aggiunte e 4 eliminazioni
  1. 6 4
      src/x11_init.c

+ 6 - 4
src/x11_init.c

@@ -690,10 +690,12 @@ Cursor _glfwCreateCursorX11(const GLFWimage* image, int xhot, int yhot)
 
 
     for (i = 0;  i < image->width * image->height;  i++, target++, source += 4)
     for (i = 0;  i < image->width * image->height;  i++, target++, source += 4)
     {
     {
-        *target = (source[3] << 24) |
-                  (source[0] << 16) |
-                  (source[1] <<  8) |
-                   source[2];
+        unsigned char alpha = source[3];
+
+        *target = (alpha << 24) |
+                  (_glfwMultiplyAlpha(alpha, source[0]) << 16) |
+                  (_glfwMultiplyAlpha(alpha, source[1]) <<  8) |
+                  _glfwMultiplyAlpha(alpha, source[2]);
     }
     }
 
 
     cursor = XcursorImageLoadCursor(_glfw.x11.display, native);
     cursor = XcursorImageLoadCursor(_glfw.x11.display, native);