Premultiplied alpha handle for driver

Jonathan Morton jonathan.morton at movial.com
Fri Jun 4 02:39:59 PDT 2010


> If the screen depth is 16bit(for geode, RGB565). I think there must be some color lose in ARGB32 format to RGB565. So the result is a little color distortion. In general, how do you handle it?

It is not difficult to convert between RGB565 and ARGB8888.  In
principle the key thing is to keep the highest representable value in
each channel as equivalent to 1.0, and the lowest as 0.0.  The missing
alpha channel is treated as 1.0 (opaque).

The usual technique is to repeat the bits received from a smaller format:

a = 255;
r = (r << 3) | (r >> 2);
g = (g << 2) | (g >> 4);
b = (b << 3) | (b >> 2);

When converting to the smaller format, drop the alpha channel and
truncate the other components to fit.

 - Jonathan Morton


More information about the xorg-devel mailing list