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.77 by root, Sun Jun 10 10:35:03 2012 UTC

50 50
51 return img; 51 return img;
52} 52}
53 53
54# if HAVE_PIXBUF 54# if HAVE_PIXBUF
55
55rxvt_img * 56rxvt_img *
56rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb) 57rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb)
57{ 58{
58 Display *dpy = s->display->dpy; 59 Display *dpy = s->display->dpy;
59 60
63 if (width > 32767 || height > 32767) // well, we *could* upload in chunks 64 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"); 65 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n");
65 66
66 // since we require rgb24/argb32 formats from xrender we assume 67 // 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 68 // 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 69
70 int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 70 int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
71 71
72 XImage xi; 72 XImage xi;
73 73
77 xi.format = ZPixmap; 77 xi.format = ZPixmap;
78 xi.byte_order = ImageByteOrder (dpy); 78 xi.byte_order = ImageByteOrder (dpy);
79 xi.bitmap_unit = 0; //XY only, unused 79 xi.bitmap_unit = 0; //XY only, unused
80 xi.bitmap_bit_order = 0; //XY only, unused 80 xi.bitmap_bit_order = 0; //XY only, unused
81 xi.bitmap_pad = BitmapPad (dpy); 81 xi.bitmap_pad = BitmapPad (dpy);
82 xi.depth = depth; 82 xi.depth = 32;
83 xi.bytes_per_line = 0; 83 xi.bytes_per_line = 0;
84 xi.bits_per_pixel = 32; //Z only 84 xi.bits_per_pixel = 32; //Z only
85 xi.red_mask = 0x00000000; //Z only, unused 85 xi.red_mask = 0x00000000; //Z only, unused
86 xi.green_mask = 0x00000000; //Z only, unused 86 xi.green_mask = 0x00000000; //Z only, unused
87 xi.blue_mask = 0x00000000; //Z only, unused 87 xi.blue_mask = 0x00000000; //Z only, unused
96 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big for Xlib.\n"); 96 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big for Xlib.\n");
97 97
98 xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line); 98 xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line);
99 99
100 int rowstride = gdk_pixbuf_get_rowstride (pb); 100 int rowstride = gdk_pixbuf_get_rowstride (pb);
101 101 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); 102 unsigned char *row = gdk_pixbuf_get_pixels (pb);
103
104 char *line = xi.data; 104 char *line = xi.data;
105 105
106 for (int y = 0; y < height; y++) 106 for (int y = 0; y < height; y++)
107 { 107 {
108 unsigned char *src = row; 108 unsigned char *src = row;
109 uint32_t *dst = (uint32_t *)line; 109 uint32_t *dst = (uint32_t *)line;
110 110
111 if (depth == 24) 111 if (!pb_has_alpha)
112 for (int x = 0; x < width; x++) 112 for (int x = 0; x < width; x++)
113 { 113 {
114 uint8_t r = *src++; 114 uint8_t r = *src++;
115 uint8_t g = *src++; 115 uint8_t g = *src++;
116 uint8_t b = *src++; 116 uint8_t b = *src++;
117 117
118 uint32_t v = (r << 16) | (g << 8) | b; 118 uint32_t v = (255 << 24) | (r << 16) | (g << 8) | b;
119 119
120 if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) 120 if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch)
121 v = ecb_bswap32 (v); 121 v = ecb_bswap32 (v);
122 122
123 *dst++ = v; 123 *dst++ = v;
140 140
141 row += rowstride; 141 row += rowstride;
142 line += xi.bytes_per_line; 142 line += xi.bytes_per_line;
143 } 143 }
144 144
145 rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height); 145 rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, PictStandardARGB32), 0, 0, width, height);
146 img->alloc (); 146 img->alloc ();
147 147
148 GC gc = XCreateGC (dpy, img->pm, 0, 0); 148 GC gc = XCreateGC (dpy, img->pm, 0, 0);
149 XPutImage (dpy, img->pm, gc, &xi, 0, 0, 0, 0, width, height); 149 XPutImage (dpy, img->pm, gc, &xi, 0, 0, 0, 0, width, height);
150 XFreeGC (dpy, gc); 150 XFreeGC (dpy, gc);
167 167
168 g_object_unref (pb); 168 g_object_unref (pb);
169 169
170 return img; 170 return img;
171} 171}
172
172# endif 173# endif
173 174
174void 175void
175rxvt_img::destroy () 176rxvt_img::destroy ()
176{ 177{
225} 226}
226 227
227void 228void
228rxvt_img::fill (const rxvt_color &c) 229rxvt_img::fill (const rxvt_color &c)
229{ 230{
230 XGCValues gcv; 231 rgba cc;
231 gcv.foreground = c; 232 c.get (cc);
232 GC gc = XCreateGC (s->display->dpy, pm, GCForeground, &gcv); 233 XRenderColor rc = { cc.r, cc.g, cc.b, cc.a };
233 XFillRectangle (s->display->dpy, pm, gc, 0, 0, w, h); 234
234 XFreeGC (s->display->dpy, gc); 235 Display *dpy = s->display->dpy;
236 Picture src = src_picture ();
237 XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h);
238 XRenderFreePicture (dpy, src);
235} 239}
236 240
237static void 241static void
238get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) 242get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params)
239{ 243{
309 w, h); 313 w, h);
310 } 314 }
311 315
312 free (kernel); 316 free (kernel);
313 free (params); 317 free (params);
318
314 XRenderFreePicture (dpy, src); 319 XRenderFreePicture (dpy, src);
315 XRenderFreePicture (dpy, dst); 320 XRenderFreePicture (dpy, dst);
316 XRenderFreePicture (dpy, tmp); 321 XRenderFreePicture (dpy, tmp);
317 322
318 return img; 323 return img;
324}
325
326static Picture
327create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha)
328{
329 Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8);
330
331 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8);
332 XRenderPictureAttributes pa;
333 pa.repeat = RepeatNormal;
334 pa.component_alpha = component_alpha;
335 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa);
336
337 XFreePixmap (dpy, pixmap);
338
339 return mask;
319} 340}
320 341
321static void 342static void
322extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc) 343extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc)
323{ 344{
365 XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h); 386 XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h);
366 XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h); 387 XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h);
367 } 388 }
368 } 389 }
369 390
370
371 XRenderFreePicture (dpy, dst); 391 XRenderFreePicture (dpy, dst);
372} 392}
373 393
374void 394void
375rxvt_img::contrast (int32_t r, int32_t g, int32_t b, int32_t a) 395rxvt_img::contrast (int32_t r, int32_t g, int32_t b, int32_t a)
376{ 396{
377 if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL)) 397 if (r < 0 || g < 0 || b < 0 || a < 0)
398 rxvt_fatal ("rxvt_img::contrast does not support negative values.\n");
399
400 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat);
401 img->alloc ();
402
378 { 403 {
379 rxvt_warn ("rxvt_img::contrast operation not supported on this display, RENDER extension too old.\n"); 404 rxvt_color empty;
380 return; 405 empty.set (s, rgba (0, 0, 0, 0));
406 img->fill (empty);
381 } 407 }
382 408
383 unshare (); 409 // premultiply (yeah, these are not exact, sue me or fix it)
410 r = (r * (a >> 8)) >> 8;
411 g = (g * (a >> 8)) >> 8;
412 b = (b * (a >> 8)) >> 8;
384 413
385 Display *dpy = s->display->dpy; 414 Display *dpy = s->display->dpy;
415
416 Picture src = src_picture ();
386 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); 417 Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0);
418 Picture mul = create_xrender_mask (dpy, pm, True, True);
387 419
420 //TODO: this operator does not yet implement some useful contrast
421 while (r | g | b | a)
422 {
423 unsigned short xr, xg, xb, xa;
388 XRenderColor mask_c; 424 XRenderColor mask_c;
389 mask_c.red = r; 425
390 mask_c.green = g; 426 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; 427 {
392 mask_c.alpha = a;
393 XRenderFillRectangle (dpy, PictOpMultiply, dst, &mask_c, 0, 0, w, h); 428 XRenderFillRectangle (dpy, PictOpSrc, mul, &mask_c, 0, 0, 1, 1);
429 XRenderComposite (dpy, PictOpAdd, src, mul, dst, 0, 0, 0, 0, 0, 0, w, h);
430 }
431 }
394 432
433 XRenderFreePicture (dpy, mul);
395 XRenderFreePicture (dpy, dst); 434 XRenderFreePicture (dpy, dst);
435 XRenderFreePicture (dpy, src);
436
437 ::swap (img->ref, ref);
438 ::swap (img->pm , pm );
439
440 delete img;
396} 441}
397 442
398rxvt_img * 443rxvt_img *
399rxvt_img::clone () 444rxvt_img::clone ()
400{ 445{
582{ 627{
583 rxvt_img *img2 = clone (); 628 rxvt_img *img2 = clone ();
584 Display *dpy = s->display->dpy; 629 Display *dpy = s->display->dpy;
585 Picture src = img->src_picture (); 630 Picture src = img->src_picture ();
586 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 631 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
587 632 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 633
595 XRenderColor mask_c; 634 XRenderColor mask_c;
596 635
597 mask_c.alpha = float_to_component (factor); 636 mask_c.alpha = float_to_component (factor);
598 mask_c.red = 637 mask_c.red =

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines