Commit 71c72db1 authored by Jonas Ådahl's avatar Jonas Ådahl Committed by Camilla Berglund
Browse files

wayland: Pre-multiply custom cursor image alpha

Since the Wayland SHM buffer format is implicitly premultiplied and the
GLFWimage pixels are defined to be non-premultiplied, we need to
convert the non-premultiplied pixels to premultiplied when filling the
buffer.

Related to #707.
parent cb08dc57
......@@ -233,6 +233,13 @@ typedef VkResult (APIENTRY * PFN_vkEnumerateInstanceExtensionProperties)(const c
y = t; \
}
// Helper for non-premultiplied alpha to premultiplied alpha conversion
static inline unsigned char _glfwMultiplyAlpha(unsigned char alpha,
unsigned char value)
{
return (unsigned char) ((value * (unsigned int) alpha) / 255);
}
//========================================================================
// Platform-independent structures
......
......@@ -588,10 +588,12 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
unsigned char* target = data;
for (i = 0; i < image->width * image->height; i++, source += 4)
{
*target++ = source[2];
*target++ = source[1];
*target++ = source[0];
*target++ = source[3];
unsigned char alpha = source[3];
*target++ = _glfwMultiplyAlpha(alpha, source[2]);
*target++ = _glfwMultiplyAlpha(alpha, source[1]);
*target++ = _glfwMultiplyAlpha(alpha, source[0]);
*target++ = alpha;
}
cursor->wl.buffer =
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment