ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtimg.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtimg.C (file contents):
Revision 1.73 by sf-exg, Sat Jun 9 17:28:03 2012 UTC vs.
Revision 1.76 by root, Sun Jun 10 10:29:26 2012 UTC

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);
314 XRenderFreePicture (dpy, src); 313 XRenderFreePicture (dpy, src);
315 XRenderFreePicture (dpy, dst); 314 XRenderFreePicture (dpy, dst);
316 XRenderFreePicture (dpy, tmp); 315 XRenderFreePicture (dpy, tmp);
317 316
318 return img; 317 return img;
318}
319
320static Picture
321create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha)
322{
323 Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8);
324
325 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8);
326 XRenderPictureAttributes pa;
327 pa.repeat = RepeatNormal;
328 pa.component_alpha = component_alpha;
329 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa);
330
331 XFreePixmap (dpy, pixmap);
332
333 return mask;
319} 334}
320 335
321static void 336static void
322extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc) 337extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc)
323{ 338{
365 XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h); 380 XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h);
366 XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h); 381 XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h);
367 } 382 }
368 } 383 }
369 384
370
371 XRenderFreePicture (dpy, dst); 385 XRenderFreePicture (dpy, dst);
372} 386}
373 387
374void 388void
375rxvt_img::contrast (int32_t r, int32_t g, int32_t b, int32_t a) 389rxvt_img::contrast (int32_t r, int32_t g, int32_t b, int32_t a)
376{ 390{
377 if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL)) 391 if (r < 0 || g < 0 || b < 0 || a < 0)
392 rxvt_fatal ("rxvt_img::contrast does not support negative values.\n");
393
394 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat);
395 img->alloc ();
396
378 { 397 {
379 rxvt_warn ("rxvt_img::contrast operation not supported on this display, RENDER extension too old.\n"); 398 rxvt_color empty;
380 return; 399 empty.set (s, rgba (0, 0, 0, 0));
400 img->fill (empty);
381 } 401 }
382 402
383 unshare (); 403 // premultiply (yeah, these are not exact, sue me or fix it)
404 r = (r * (a >> 8)) >> 8;
405 g = (g * (a >> 8)) >> 8;
406 b = (b * (a >> 8)) >> 8;
384 407
385 Display *dpy = s->display->dpy; 408 Display *dpy = s->display->dpy;
409
410 Picture src = src_picture ();
386 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); 411 Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0);
412 Picture mul = create_xrender_mask (dpy, pm, True, True);
387 413
414 //TODO: this operator does not yet implement some useful contrast
415 while (r | g | b | a)
416 {
417 unsigned short xr, xg, xb, xa;
388 XRenderColor mask_c; 418 XRenderColor mask_c;
389 mask_c.red = r; 419
390 mask_c.green = g; 420 if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha))
391 mask_c.blue = b; 421 {
392 mask_c.alpha = a;
393 XRenderFillRectangle (dpy, PictOpMultiply, dst, &mask_c, 0, 0, w, h); 422 XRenderFillRectangle (dpy, PictOpSrc, mul, &mask_c, 0, 0, 1, 1);
423 XRenderComposite (dpy, PictOpAdd, src, mul, dst, 0, 0, 0, 0, 0, 0, w, h);
424 }
425 }
394 426
427 XRenderFreePicture (dpy, mul);
395 XRenderFreePicture (dpy, dst); 428 XRenderFreePicture (dpy, dst);
429 XRenderFreePicture (dpy, src);
430
431 ::swap (img->ref, ref);
432 ::swap (img->pm , pm );
433
434 delete img;
396} 435}
397 436
398rxvt_img * 437rxvt_img *
399rxvt_img::clone () 438rxvt_img::clone ()
400{ 439{
582{ 621{
583 rxvt_img *img2 = clone (); 622 rxvt_img *img2 = clone ();
584 Display *dpy = s->display->dpy; 623 Display *dpy = s->display->dpy;
585 Picture src = img->src_picture (); 624 Picture src = img->src_picture ();
586 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 625 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
587 626 Picture mask = create_xrender_mask (dpy, img->pm, False, False);
588 Pixmap pixmap = XCreatePixmap (dpy, img->pm, 1, 1, 8);
589 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, PictStandardA8);
590 XRenderPictureAttributes pa;
591 pa.repeat = True;
592 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
593 XFreePixmap (dpy, pixmap);
594 627
595 XRenderColor mask_c; 628 XRenderColor mask_c;
596 629
597 mask_c.alpha = float_to_component (factor); 630 mask_c.alpha = float_to_component (factor);
598 mask_c.red = 631 mask_c.red =

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines