Index: cairo-xlib-surface.c =================================================================== RCS file: /cvs/cairo/cairo/src/cairo-xlib-surface.c,v retrieving revision 1.116 diff -u -p -r1.116 cairo-xlib-surface.c --- cairo-xlib-surface.c 24 Aug 2005 04:36:08 -0000 1.116 +++ cairo-xlib-surface.c 28 Aug 2005 17:49:11 -0000 @@ -138,7 +138,7 @@ struct _cairo_xlib_surface { #define CAIRO_SURFACE_RENDER_HAS_PICTURE_TRANSFORM(surface) CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 6) #define CAIRO_SURFACE_RENDER_HAS_FILTERS(surface) CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 6) -static cairo_bool_t cairo_xlib_render_disabled = FALSE; +static cairo_bool_t cairo_xlib_render_disabled = TRUE; /** * cairo_test_xlib_disable_render: @@ -302,6 +302,25 @@ _CAIRO_MASK_FORMAT (cairo_format_masks_t return False; } +static void +swap_ximage (XImage *ximage) +{ + unsigned char *line = ximage->data; + int i, j; + + for (i = ximage->height; i; i--) { + uint32_t *p = (uint32_t *)line; + for (j = ximage->width; j; j--) { + uint32_t pixel = *p; + *p = (((pixel & 0x0000ff) << 16) | + ((pixel & 0x00ff00)) | + ((pixel & 0xff000) >> 16)); + p++; + } + line += ximage->bytes_per_line; + } +} + static cairo_status_t _get_image_surface (cairo_xlib_surface_t *surface, cairo_rectangle_t *interest_rect, @@ -442,14 +461,31 @@ _get_image_surface (cairo_xlib_surface_t */ if (_CAIRO_MASK_FORMAT (&masks, &format)) { - image = (cairo_image_surface_t*) - cairo_image_surface_create_for_data ((unsigned char *) ximage->data, - format, - ximage->width, - ximage->height, - ximage->bytes_per_line); - if (image->base.status) - goto FAIL; + if (format == CAIRO_FORMAT_RGB24 && surface->visual) { + unsigned long t = masks.red_mask; + masks.red_mask = masks.blue_mask; + masks.blue_mask = t; + + swap_ximage (ximage); + + image = (cairo_image_surface_t*) + _cairo_image_surface_create_with_masks ((unsigned char *) ximage->data, + &masks, + ximage->width, + ximage->height, + ximage->bytes_per_line); + if (image->base.status) + goto FAIL; + } else { + image = (cairo_image_surface_t*) + cairo_image_surface_create_for_data ((unsigned char *) ximage->data, + format, + ximage->width, + ximage->height, + ximage->bytes_per_line); + if (image->base.status) + goto FAIL; + } } else { @@ -570,10 +606,23 @@ _draw_image_surface (cairo_xlib_surface_ return CAIRO_STATUS_NO_MEMORY; _cairo_xlib_surface_ensure_gc (surface); + + if (surface->visual && + surface->visual->red_mask == 0xff0000 && + surface->visual->green_mask == 0xff00 && + surface->visual->blue_mask == 0xff) + swap_ximage (ximage); + XPutImage(surface->dpy, surface->drawable, surface->gc, ximage, 0, 0, dst_x, dst_y, image->width, image->height); - + + if (surface->visual && + surface->visual->red_mask == 0xff0000 && + surface->visual->green_mask == 0xff00 && + surface->visual->blue_mask == 0xff) + swap_ximage (ximage); + /* Foolish XDestroyImage thinks it can free my data, but I won't stand for it. */ ximage->data = NULL;