[PATCH 2/2] Fix for full and semi-transparency under negative image.
walter harms
wharms at bfs.de
Sun Apr 20 11:49:53 PDT 2014
Am 19.04.2014 19:55, schrieb Mattias Andrée:
> ---
> hw/xfree86/modes/xf86Cursors.c | 49 +++++++++++++++++++++++++++++++-----------
> 1 file changed, 37 insertions(+), 12 deletions(-)
>
> diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c
> index 3cb499f..5afd740 100644
> --- a/hw/xfree86/modes/xf86Cursors.c
> +++ b/hw/xfree86/modes/xf86Cursors.c
> @@ -209,6 +209,41 @@ set_bit(CARD8 *image, xf86CursorInfoPtr cursor_info, int x, int y, Bool mask)
> }
>
> /*
> + * Remap a cursor pixel according to the gamma ramps
> + */
> +static CARD32
> +cursor_gamma_correct(xf86CrtcPtr crtc, CARD32 bits)
> +{
> + float alpha;
> + CARD32 old_red, new_red;
> + CARD32 old_green, new_green;
> + CARD32 old_blue, new_blue;
> +
> + if (!(crtc->gamma_red && crtc->gamma_size == 256))
> + return bits;
> +
> + alpha = (float)((bits >> 24) & 255) / 255.f;
> +
> + old_red = (bits >> 16) & 255;
> + old_green = (bits >> 8) & 255;
> + old_blue = (bits >> 0) & 255;
> +
> + new_red = (crtc->gamma_red [old_red ]) >> 8;
> + new_green = (crtc->gamma_green[old_green]) >> 8;
> + new_blue = (crtc->gamma_blue [old_blue ]) >> 8;
> +
> + new_red = new_red * alpha + old_red * (1 - alpha);
> + new_green = new_green * alpha + old_green * (1 - alpha);
> + new_blue = new_blue * alpha + old_blue * (1 - alpha);
> +
> + new_red = new_red < 0 ? 0 : new_red > 255 ? 255 : new_red;
> + new_green = new_green < 0 ? 0 : new_green > 255 ? 255 : new_green;
> + new_blue = new_blue < 0 ? 0 : new_blue > 255 ? 255 : new_blue;
> +
ok, i know that i valid C, but do you think that a more readable version
is so much slower ?
if (val < 0 ) val=0;
if (val >255) val=255;
that will give everyone the opprotunity to understand what is going on.
just my two cents.
re,
wh
> + return (bits & 0xFF000000) | (new_red << 16) | (new_green << 8) | (new_blue << 0);
> +}
> +
> +/*
> * Load a two color cursor into a driver that supports only ARGB cursors
> */
> static void
> @@ -242,12 +277,7 @@ xf86_crtc_convert_cursor_to_argb(xf86CrtcPtr crtc, unsigned char *src)
> }
> else
> bits = 0;
> - if (crtc->gamma_red && crtc->gamma_size == 256) {
> - bits = (bits & 0xFF000000) |
> - ((crtc->gamma_red[(bits >> 16) & 255] >> 8) << 16) |
> - (crtc->gamma_green[(bits >> 8) & 255] & 0xFF00) |
> - (crtc->gamma_blue[bits & 255] >> 8);
> - }
> + bits = cursor_gamma_correct(crtc, bits);
> cursor_image[y * cursor_info->MaxWidth + x] = bits;
> }
> crtc->funcs->load_cursor_argb(crtc, cursor_image);
> @@ -547,12 +577,7 @@ xf86_crtc_load_cursor_argb(xf86CrtcPtr crtc, CursorPtr cursor)
> bits = cursor_source[yin * source_width + xin];
> else
> bits = 0;
> - if (crtc->gamma_red && crtc->gamma_size == 256) {
> - bits = (bits & 0xFF000000) |
> - ((crtc->gamma_red[(bits >> 16) & 255] >> 8) << 16) |
> - (crtc->gamma_green[(bits >> 8) & 255] & 0xFF00) |
> - (crtc->gamma_blue[bits & 255] >> 8);
> - }
> + bits = cursor_gamma_correct(crtc, bits);
> cursor_image[y * image_width + x] = bits;
> }
>
More information about the xorg-devel
mailing list