… | |
… | |
63 | if (width > 32767 || height > 32767) // well, we *could* upload in chunks |
63 | if (width > 32767 || height > 32767) // well, we *could* upload in chunks |
64 | rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n"); |
64 | rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n"); |
65 | |
65 | |
66 | // since we require rgb24/argb32 formats from xrender we assume |
66 | // since we require rgb24/argb32 formats from xrender we assume |
67 | // that both 24 and 32 bpp MUST be supported by any screen that supports xrender |
67 | // that both 24 and 32 bpp MUST be supported by any screen that supports xrender |
68 | int depth = gdk_pixbuf_get_has_alpha (pb) ? 32 : 24; |
|
|
69 | |
68 | |
70 | int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
69 | int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
71 | |
70 | |
72 | XImage xi; |
71 | XImage xi; |
73 | |
72 | |
… | |
… | |
77 | xi.format = ZPixmap; |
76 | xi.format = ZPixmap; |
78 | xi.byte_order = ImageByteOrder (dpy); |
77 | xi.byte_order = ImageByteOrder (dpy); |
79 | xi.bitmap_unit = 0; //XY only, unused |
78 | xi.bitmap_unit = 0; //XY only, unused |
80 | xi.bitmap_bit_order = 0; //XY only, unused |
79 | xi.bitmap_bit_order = 0; //XY only, unused |
81 | xi.bitmap_pad = BitmapPad (dpy); |
80 | xi.bitmap_pad = BitmapPad (dpy); |
82 | xi.depth = depth; |
81 | xi.depth = 32; |
83 | xi.bytes_per_line = 0; |
82 | xi.bytes_per_line = 0; |
84 | xi.bits_per_pixel = 32; //Z only |
83 | xi.bits_per_pixel = 32; //Z only |
85 | xi.red_mask = 0x00000000; //Z only, unused |
84 | xi.red_mask = 0x00000000; //Z only, unused |
86 | xi.green_mask = 0x00000000; //Z only, unused |
85 | xi.green_mask = 0x00000000; //Z only, unused |
87 | xi.blue_mask = 0x00000000; //Z only, unused |
86 | xi.blue_mask = 0x00000000; //Z only, unused |
… | |
… | |
96 | rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big for Xlib.\n"); |
95 | rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big for Xlib.\n"); |
97 | |
96 | |
98 | xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line); |
97 | xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line); |
99 | |
98 | |
100 | int rowstride = gdk_pixbuf_get_rowstride (pb); |
99 | int rowstride = gdk_pixbuf_get_rowstride (pb); |
101 | |
100 | bool pb_has_alpha = gdk_pixbuf_get_has_alpha (pb); |
102 | assert (3 + (depth == 32) == gdk_pixbuf_get_n_channels (pb)); |
|
|
103 | unsigned char *row = gdk_pixbuf_get_pixels (pb); |
101 | unsigned char *row = gdk_pixbuf_get_pixels (pb); |
|
|
102 | |
104 | char *line = xi.data; |
103 | char *line = xi.data; |
105 | |
104 | |
106 | for (int y = 0; y < height; y++) |
105 | for (int y = 0; y < height; y++) |
107 | { |
106 | { |
108 | unsigned char *src = row; |
107 | unsigned char *src = row; |
109 | uint32_t *dst = (uint32_t *)line; |
108 | uint32_t *dst = (uint32_t *)line; |
110 | |
109 | |
111 | if (depth == 24) |
110 | if (!pb_has_alpha) |
112 | for (int x = 0; x < width; x++) |
111 | for (int x = 0; x < width; x++) |
113 | { |
112 | { |
114 | uint8_t r = *src++; |
113 | uint8_t r = *src++; |
115 | uint8_t g = *src++; |
114 | uint8_t g = *src++; |
116 | uint8_t b = *src++; |
115 | uint8_t b = *src++; |
117 | |
116 | |
118 | uint32_t v = (r << 16) | (g << 8) | b; |
117 | uint32_t v = (255 << 24) | (r << 16) | (g << 8) | b; |
119 | |
118 | |
120 | if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) |
119 | if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) |
121 | v = ecb_bswap32 (v); |
120 | v = ecb_bswap32 (v); |
122 | |
121 | |
123 | *dst++ = v; |
122 | *dst++ = v; |
… | |
… | |
140 | |
139 | |
141 | row += rowstride; |
140 | row += rowstride; |
142 | line += xi.bytes_per_line; |
141 | line += xi.bytes_per_line; |
143 | } |
142 | } |
144 | |
143 | |
145 | rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height); |
144 | rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, PictStandardARGB32), 0, 0, width, height); |
146 | img->alloc (); |
145 | img->alloc (); |
147 | |
146 | |
148 | GC gc = XCreateGC (dpy, img->pm, 0, 0); |
147 | GC gc = XCreateGC (dpy, img->pm, 0, 0); |
149 | XPutImage (dpy, img->pm, gc, &xi, 0, 0, 0, 0, width, height); |
148 | XPutImage (dpy, img->pm, gc, &xi, 0, 0, 0, 0, width, height); |
150 | XFreeGC (dpy, gc); |
149 | XFreeGC (dpy, gc); |
… | |
… | |
317 | |
316 | |
318 | return img; |
317 | return img; |
319 | } |
318 | } |
320 | |
319 | |
321 | static Picture |
320 | static Picture |
322 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb) |
321 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha) |
323 | { |
322 | { |
324 | Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); |
323 | Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); |
325 | |
324 | |
326 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); |
325 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); |
327 | XRenderPictureAttributes pa; |
326 | XRenderPictureAttributes pa; |
328 | pa.repeat = RepeatNormal; |
327 | pa.repeat = RepeatNormal; |
|
|
328 | pa.component_alpha = component_alpha; |
329 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
329 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa); |
330 | |
330 | |
331 | XFreePixmap (dpy, pixmap); |
331 | XFreePixmap (dpy, pixmap); |
332 | |
332 | |
333 | return mask; |
333 | return mask; |
334 | } |
334 | } |
… | |
… | |
407 | |
407 | |
408 | Display *dpy = s->display->dpy; |
408 | Display *dpy = s->display->dpy; |
409 | |
409 | |
410 | Picture src = src_picture (); |
410 | Picture src = src_picture (); |
411 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); |
411 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); |
412 | Picture mul = create_xrender_mask (dpy, pm, True); |
412 | Picture mul = create_xrender_mask (dpy, pm, True, True); |
413 | |
|
|
414 | XRenderPictureAttributes pa; |
|
|
415 | pa.component_alpha = 1; |
|
|
416 | XRenderChangePicture (dpy, mul, CPComponentAlpha, &pa); |
|
|
417 | |
413 | |
418 | //TODO: this operator does not yet implement some useful contrast |
414 | //TODO: this operator does not yet implement some useful contrast |
419 | while (r | g | b | a) |
415 | while (r | g | b | a) |
420 | { |
416 | { |
421 | unsigned short xr, xg, xb, xa; |
417 | unsigned short xr, xg, xb, xa; |
… | |
… | |
625 | { |
621 | { |
626 | rxvt_img *img2 = clone (); |
622 | rxvt_img *img2 = clone (); |
627 | Display *dpy = s->display->dpy; |
623 | Display *dpy = s->display->dpy; |
628 | Picture src = img->src_picture (); |
624 | Picture src = img->src_picture (); |
629 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
625 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
630 | |
626 | Picture mask = create_xrender_mask (dpy, img->pm, False, False); |
631 | Pixmap pixmap = XCreatePixmap (dpy, img->pm, 1, 1, 8); |
|
|
632 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, PictStandardA8); |
|
|
633 | XRenderPictureAttributes pa; |
|
|
634 | pa.repeat = True; |
|
|
635 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
|
|
636 | XFreePixmap (dpy, pixmap); |
|
|
637 | |
627 | |
638 | XRenderColor mask_c; |
628 | XRenderColor mask_c; |
639 | |
629 | |
640 | mask_c.alpha = float_to_component (factor); |
630 | mask_c.alpha = float_to_component (factor); |
641 | mask_c.red = |
631 | mask_c.red = |