--- rxvt-unicode/src/rxvtimg.C 2012/06/07 19:06:26 1.47 +++ rxvt-unicode/src/rxvtimg.C 2012/06/08 17:22:48 1.62 @@ -16,13 +16,6 @@ ++ref->cnt; } -#if 0 -rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) -: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap) -{ -} -#endif - rxvt_img * rxvt_img::new_from_root (rxvt_screen *s) { @@ -61,6 +54,8 @@ rxvt_img * rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb) { + Display *dpy = s->display->dpy; + int width = gdk_pixbuf_get_width (pb); int height = gdk_pixbuf_get_height (pb); @@ -71,22 +66,27 @@ // that both 24 and 32 bpp MUST be supported by any screen that supports xrender int depth = gdk_pixbuf_get_has_alpha (pb) ? 32 : 24; + int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; + XImage xi; xi.width = width; xi.height = height; xi.xoffset = 0; xi.format = ZPixmap; - xi.byte_order = MSBFirst; // maybe go for host byte order, because servers are usually local? - xi.bitmap_unit = 32; - xi.bitmap_bit_order = MSBFirst; - xi.bitmap_pad = 32; + xi.byte_order = ImageByteOrder (dpy); + xi.bitmap_unit = 0; //XY only, unused + xi.bitmap_bit_order = 0; //XY only, unused + xi.bitmap_pad = BitmapPad (dpy); xi.depth = depth; xi.bytes_per_line = 0; - xi.bits_per_pixel = 32; - xi.red_mask = 0x00ff0000; - xi.green_mask = 0x0000ff00; - xi.blue_mask = 0x000000ff; + xi.bits_per_pixel = 32; //Z only + xi.red_mask = 0x00000000; //Z only, unused + xi.green_mask = 0x00000000; //Z only, unused + xi.blue_mask = 0x00000000; //Z only, unused + xi.obdata = 0; // probably unused + + bool byte_order_mismatch = byte_order != xi.byte_order; if (!XInitImage (&xi)) rxvt_fatal ("unable to initialise ximage, please report.\n"); @@ -104,38 +104,43 @@ for (int y = 0; y < height; y++) { - unsigned char r, g, b, a; - unsigned char *data = row; + unsigned char *src = row; + uint32_t *dst = (uint32_t *)line; if (depth == 24) for (int x = 0; x < width; x++) { - r = *data++; - g = *data++; - b = *data++; - *line++ = 0; - *line++ = r; - *line++ = g; - *line++ = b; + uint8_t r = *src++; + uint8_t g = *src++; + uint8_t b = *src++; + + uint32_t v = (r << 16) | (g << 8) | b; + + if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) + v = ecb_bswap32 (v); + + *dst++ = v; } else for (int x = 0; x < width; x++) { - r = *data++; - g = *data++; - b = *data++; - a = *data++; - *line++ = a; - *line++ = r; - *line++ = g; - *line++ = b; + uint32_t v = *(uint32_t *)src; src += 4; + + if (ecb_big_endian ()) + v = ecb_bswap32 (v); + + v = ecb_rotl32 (v, 8); // abgr to bgra + + if (!byte_order_mismatch) + v = ecb_bswap32 (v); + + *dst++ = v; } row += rowstride; + line += xi.bytes_per_line; } - Display *dpy = s->display->dpy; - rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height); img->alloc (); @@ -262,11 +267,10 @@ rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); img->alloc (); - Picture src = src_picture (); - XRenderPictureAttributes pa; pa.repeat = RepeatPad; - Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); + Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); + Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); @@ -292,7 +296,7 @@ get_gaussian_kernel (rv, size, kernel, params); ::swap (params[0], params[1]); - XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); + XRenderSetPictureFilter (dpy, tmp, FilterConvolution, params, size+2); XRenderComposite (dpy, PictOpSrc, tmp, @@ -405,9 +409,10 @@ Display *dpy = s->display->dpy; - bool alpha = !format->direct.alphaMask - && (x || y) - && repeat == RepeatNone; + // add an alpha channel if... + bool alpha = !format->direct.alphaMask // pixmap has none yet + && (x || y) // we need one because of non-zero offset + && repeat == RepeatNone; // and we have no good pixels to fill with rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); img->alloc ();