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.88 by root, Thu Jun 14 19:42:01 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_p)
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 };
509 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles 567 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles
510 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h); 568 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, x, y, ref->w, ref->h);
511 } 569 }
512 else 570 else
513 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); 571 XRenderComposite (dpy, PictOpSrc, src, None, dst, -x, -y, 0, 0, 0, 0, w, h);
514 572
515 XRenderFreePicture (dpy, src); 573 XRenderFreePicture (dpy, src);
516 XRenderFreePicture (dpy, dst); 574 XRenderFreePicture (dpy, dst);
517 575
518 return img; 576 return img;
521rxvt_img * 579rxvt_img *
522rxvt_img::sub_rect (int x, int y, int width, int height) 580rxvt_img::sub_rect (int x, int y, int width, int height)
523{ 581{
524 rxvt_img *img = clone (); 582 rxvt_img *img = clone ();
525 583
526 img->x += x; 584 img->x -= x;
527 img->y += y; 585 img->y -= y;
528 586
529 if (w != width || h != height) 587 if (w != width || h != height)
530 { 588 {
531 img->w = width; 589 img->w = width;
532 img->h = height; 590 img->h = height;
571} 629}
572 630
573rxvt_img * 631rxvt_img *
574rxvt_img::transform (nv matrix[3][3]) 632rxvt_img::transform (nv matrix[3][3])
575{ 633{
576 // find new offset
577 int ox = mat_apply (matrix, 0, x, y);
578 int oy = mat_apply (matrix, 1, x, y);
579
580 // calculate new pixel bounding box coordinates 634 // calculate new pixel bounding box coordinates
581 nv d [2], rmin[2], rmax[2]; 635 nv rmin[2], rmax[2];
582 636
583 for (int i = 0; i < 2; ++i) 637 for (int i = 0; i < 2; ++i)
584 { 638 {
585 nv v; 639 nv v;
586 v = mat_apply (matrix, i, 0, 0); rmin [i] = rmax [i] = v; d [i] = v; 640 v = mat_apply (matrix, i, 0+x, 0+y); rmin [i] = rmax [i] = v;
587 v = mat_apply (matrix, i, w, 0); min_it (rmin [i], v); max_it (rmax [i], v); 641 v = mat_apply (matrix, i, w+x, 0+y); min_it (rmin [i], v); max_it (rmax [i], v);
588 v = mat_apply (matrix, i, 0, h); min_it (rmin [i], v); max_it (rmax [i], v); 642 v = mat_apply (matrix, i, 0+x, h+y); min_it (rmin [i], v); max_it (rmax [i], v);
589 v = mat_apply (matrix, i, w, h); min_it (rmin [i], v); max_it (rmax [i], v); 643 v = mat_apply (matrix, i, w+x, h+y); min_it (rmin [i], v); max_it (rmax [i], v);
590 } 644 }
591 645
592 int dx = floor (rmin [0]); 646 int dx = floor (rmin [0]);
593 int dy = floor (rmin [1]); 647 int dy = floor (rmin [1]);
594 648
596 int new_height = ceil (rmax [1] - dy); 650 int new_height = ceil (rmax [1] - dy);
597 651
598 nv inv[3][3]; 652 nv inv[3][3];
599 mat_invert (matrix, inv); 653 mat_invert (matrix, inv);
600 654
601 rxvt_img *img = new rxvt_img (s, format, ox - dx - d [0], oy - dy - d [1], new_width, new_height, repeat); 655 rxvt_img *img = new rxvt_img (s, format, dx, dy, new_width, new_height, repeat);
602 img->alloc (); 656 img->alloc ();
603 657
604 Display *dpy = s->display->dpy; 658 Display *dpy = s->display->dpy;
605 Picture src = src_picture (); 659 Picture src = picture ();
606 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 660 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
607 661
608 XTransform xfrm; 662 XTransform xfrm;
609 663
610 for (int i = 0; i < 3; ++i) 664 for (int i = 0; i < 3; ++i)
649{ 703{
650 nv s = sin (phi); 704 nv s = sin (phi);
651 nv c = cos (phi); 705 nv c = cos (phi);
652 706
653 nv matrix[3][3] = { 707 nv matrix[3][3] = {
654 { c, -s, cx - c * cx + s * cy }, 708 { c, -s, cx - c * cx + s * cy + 200 },
655 { s, c, cy - s * cx - c * cy }, 709 { s, c, cy - s * cx - c * cy },
656 { 0, 0, 1 } 710 { 0, 0, 1 }
657 //{ c, -s, 0 }, 711 //{ c, -s, 0 },
658 //{ s, c, 0 }, 712 //{ s, c, 0 },
659 //{ 0, 0, 1 } 713 //{ 0, 0, 1 }
675 729
676 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat); 730 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat);
677 img->alloc (); 731 img->alloc ();
678 732
679 Display *dpy = s->display->dpy; 733 Display *dpy = s->display->dpy;
680 Picture src = src_picture (); 734 Picture src = picture ();
681 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 735 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
682 int op = PictOpSrc; 736 int op = PictOpSrc;
683 737
684 if (format->direct.alphaMask && !new_format->direct.alphaMask) 738 if (format->direct.alphaMask && !new_format->direct.alphaMask)
685 { 739 {
701rxvt_img * 755rxvt_img *
702rxvt_img::blend (rxvt_img *img, nv factor) 756rxvt_img::blend (rxvt_img *img, nv factor)
703{ 757{
704 rxvt_img *img2 = clone (); 758 rxvt_img *img2 = clone ();
705 Display *dpy = s->display->dpy; 759 Display *dpy = s->display->dpy;
706 Picture src = img->src_picture (); 760 Picture src = img->picture ();
707 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 761 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
708 Picture mask = create_xrender_mask (dpy, img->pm, False, False); 762 Picture mask = create_xrender_mask (dpy, img->pm, False, False);
709 763
710 XRenderColor mask_c; 764 XRenderColor mask_c;
711 765

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines