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.84 by root, Thu Jun 14 18:19:11 2012 UTC vs.
Revision 1.85 by root, Thu Jun 14 18:59:39 2012 UTC

1#include <math.h> 1#include <math.h>
2#include "../config.h" 2#include "../config.h"
3#include "rxvt.h" 3#include "rxvt.h"
4 4
5#if HAVE_IMG 5#if HAVE_IMG
6
7#if 0
8struct pict
9{
10 Display *dpy;
11 Picture pic;
12
13 operator Picture () const
14 {
15 return pic;
16 }
17
18 pict ()
19 : pic (0)
20 {
21 }
22
23 pict (rxvt_img *img, XRenderPictFormat *format = 0)
24 : dpy (img->s->display->dpy)
25 {
26 XRenderPictureAttributes pa;
27 pa.repeat = img->repeat;
28 pic = XRenderCreatePicture (dpy, img->pm, format ? format : img->format, CPRepeat, &pa);
29 }
30
31 ~pict ()
32 {
33 if (pic)
34 XRenderFreePicture (dpy, pic);
35 }
36};
37#endif
6 38
7static XRenderPictFormat * 39static XRenderPictFormat *
8find_alpha_format_for (Display *dpy, XRenderPictFormat *format) 40find_alpha_format_for (Display *dpy, XRenderPictFormat *format)
9{ 41{
10 if (format->direct.alphaMask) 42 if (format->direct.alphaMask)
215 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); 247 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth);
216 ref = new pixref (w, h); 248 ref = new pixref (w, h);
217} 249}
218 250
219Picture 251Picture
220rxvt_img::src_picture () 252rxvt_img::picture ()
221{ 253{
222 Display *dpy = s->display->dpy; 254 Display *dpy = s->display->dpy;
223 255
224 XRenderPictureAttributes pa; 256 XRenderPictureAttributes pa;
225 pa.repeat = repeat; 257 pa.repeat = repeat;
249rxvt_img::fill (const rgba &c) 281rxvt_img::fill (const rgba &c)
250{ 282{
251 XRenderColor rc = { c.r, c.g, c.b, c.a }; 283 XRenderColor rc = { c.r, c.g, c.b, c.a };
252 284
253 Display *dpy = s->display->dpy; 285 Display *dpy = s->display->dpy;
254 Picture src = src_picture (); 286 Picture src = picture ();
255 XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); 287 XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h);
256 XRenderFreePicture (dpy, src); 288 XRenderFreePicture (dpy, src);
257} 289}
258 290
259void 291void
265 Display *dpy = s->display->dpy; 297 Display *dpy = s->display->dpy;
266 298
267 rxvt_img *img = new rxvt_img (s, find_alpha_format_for (dpy, format), x, y, w, h, repeat); 299 rxvt_img *img = new rxvt_img (s, find_alpha_format_for (dpy, format), x, y, w, h, repeat);
268 img->alloc (); 300 img->alloc ();
269 301
270 Picture src = src_picture (); 302 Picture src = picture ();
271 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 303 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
272 304
273 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 305 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
274 306
275 XRenderFreePicture (dpy, src); 307 XRenderFreePicture (dpy, src);
449 g = (g * (a >> 8)) >> 8; 481 g = (g * (a >> 8)) >> 8;
450 b = (b * (a >> 8)) >> 8; 482 b = (b * (a >> 8)) >> 8;
451 483
452 Display *dpy = s->display->dpy; 484 Display *dpy = s->display->dpy;
453 485
454 Picture src = src_picture (); 486 Picture src = picture ();
455 Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); 487 Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0);
456 Picture mul = create_xrender_mask (dpy, pm, True, True); 488 Picture mul = create_xrender_mask (dpy, pm, True, True);
457 489
458 //TODO: this operator does not yet implement some useful contrast 490 //TODO: this operator does not yet implement some useful contrast
459 while (r | g | b | a) 491 while (r | g | b | a)
476 ::swap (img->pm , pm ); 508 ::swap (img->pm , pm );
477 509
478 delete img; 510 delete img;
479} 511}
480 512
513void
514rxvt_img::draw (rxvt_img *img, int op, nv mask)
515{
516 unshare ();
517
518 Display *dpy = s->display->dpy;
519 Picture src = img->picture ();
520 Picture dst = picture ();
521 Picture mask_p = 0;
522
523 if (mask != 1.)
524 {
525 mask_p = create_xrender_mask (dpy, img->pm, False, False);
526 XRenderColor mask_c = { 0, 0, 0, float_to_component (mask) };
527 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
528 }
529
530 XRenderComposite (dpy, op, src, mask_p, dst, x - img->x, y - img->y, 0, 0, 0, 0, w, h);
531
532 XRenderFreePicture (dpy, src);
533 XRenderFreePicture (dpy, dst);
534
535 if (mask)
536 XRenderFreePicture (dpy, mask_p);
537}
538
481rxvt_img * 539rxvt_img *
482rxvt_img::clone () 540rxvt_img::clone ()
483{ 541{
484 return new rxvt_img (*this); 542 return new rxvt_img (*this);
485} 543}
498 && repeat == RepeatNone; // and we have no good pixels to fill with 556 && repeat == RepeatNone; // and we have no good pixels to fill with
499 557
500 rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); 558 rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat);
501 img->alloc (); 559 img->alloc ();
502 560
503 Picture src = src_picture (); 561 Picture src = picture ();
504 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 562 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
505 563
506 if (alpha) 564 if (alpha)
507 { 565 {
508 XRenderColor rc = { 0, 0, 0, 0 }; 566 XRenderColor rc = { 0, 0, 0, 0 };
600 658
601 rxvt_img *img = new rxvt_img (s, format, ox - dx - d [0], oy - dy - d [1], new_width, new_height, repeat); 659 rxvt_img *img = new rxvt_img (s, format, ox - dx - d [0], oy - dy - d [1], new_width, new_height, repeat);
602 img->alloc (); 660 img->alloc ();
603 661
604 Display *dpy = s->display->dpy; 662 Display *dpy = s->display->dpy;
605 Picture src = src_picture (); 663 Picture src = picture ();
606 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 664 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
607 665
608 XTransform xfrm; 666 XTransform xfrm;
609 667
610 for (int i = 0; i < 3; ++i) 668 for (int i = 0; i < 3; ++i)
675 733
676 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat); 734 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat);
677 img->alloc (); 735 img->alloc ();
678 736
679 Display *dpy = s->display->dpy; 737 Display *dpy = s->display->dpy;
680 Picture src = src_picture (); 738 Picture src = picture ();
681 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 739 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
682 int op = PictOpSrc; 740 int op = PictOpSrc;
683 741
684 if (format->direct.alphaMask && !new_format->direct.alphaMask) 742 if (format->direct.alphaMask && !new_format->direct.alphaMask)
685 { 743 {
701rxvt_img * 759rxvt_img *
702rxvt_img::blend (rxvt_img *img, nv factor) 760rxvt_img::blend (rxvt_img *img, nv factor)
703{ 761{
704 rxvt_img *img2 = clone (); 762 rxvt_img *img2 = clone ();
705 Display *dpy = s->display->dpy; 763 Display *dpy = s->display->dpy;
706 Picture src = img->src_picture (); 764 Picture src = img->picture ();
707 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 765 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
708 Picture mask = create_xrender_mask (dpy, img->pm, False, False); 766 Picture mask = create_xrender_mask (dpy, img->pm, False, False);
709 767
710 XRenderColor mask_c; 768 XRenderColor mask_c;
711 769

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines