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.79 by root, Tue Jun 12 10:45:53 2012 UTC vs.
Revision 1.80 by root, Tue Jun 12 18:25:57 2012 UTC

519 } 519 }
520 520
521 return img; 521 return img;
522} 522}
523 523
524rxvt_img * 524static void
525rxvt_img::transform (double matrix[9], int new_width, int new_height) 525mat_invert (double mat[3][3], double (&inv)[3][3])
526{ 526{
527 double s0 = mat [2][2] * mat [1][1] - mat [2][1] * mat [1][2];
528 double s1 = mat [2][1] * mat [0][2] - mat [2][2] * mat [0][1];
529 double s2 = mat [1][2] * mat [0][1] - mat [1][1] * mat [0][2];
530
531 double invdet = 1. / (mat [0][0] * s0 + mat [1][0] * s1 + mat [2][0] * s2);
532
533 inv [0][0] = invdet * s0;
534 inv [0][1] = invdet * s1;
535 inv [0][2] = invdet * s2;
536
537 inv [1][0] = invdet * (mat [2][0] * mat [1][2] - mat [2][2] * mat [1][0]);
538 inv [1][1] = invdet * (mat [2][2] * mat [0][0] - mat [2][0] * mat [0][2]);
539 inv [1][2] = invdet * (mat [1][0] * mat [0][2] - mat [1][2] * mat [0][0]);
540
541 inv [2][0] = invdet * (mat [2][1] * mat [1][0] - mat [2][0] * mat [1][1]);
542 inv [2][1] = invdet * (mat [2][0] * mat [0][1] - mat [2][1] * mat [0][0]);
543 inv [2][2] = invdet * (mat [1][1] * mat [0][0] - mat [1][0] * mat [0][1]);
544}
545
546static double
547mat_apply (double mat[3][3], int i, double x, double y)
548{
549 double v = mat [i][0] * x + mat [i][1] * y + mat [i][2];
550 double w = mat [2][0] * x + mat [2][1] * y + mat [2][2];
551
552 return v * (1. / w);
553}
554
555rxvt_img *
556rxvt_img::transform (double matrix[3][3])
557{
558 // find new offset
559 int ox = mat_apply (matrix, 0, x, y);
560 int oy = mat_apply (matrix, 1, x, y);
561
562 // calculate new pixel bounding box coordinates
563 double rmin[2], rmax[2];
564
565 for (int i = 0; i < 2; ++i)
566 {
567 double v;
568 v = mat_apply (matrix, i, 0, 0); rmin [i] = rmax [i] = v;
569 v = mat_apply (matrix, i, w, 0); min_it (rmin [i], v); max_it (rmax [i], v);
570 v = mat_apply (matrix, i, 0, h); min_it (rmin [i], v); max_it (rmax [i], v);
571 v = mat_apply (matrix, i, w, h); min_it (rmin [i], v); max_it (rmax [i], v);
572 }
573
574 int dx = floor (rmin [0]);
575 int dy = floor (rmin [1]);
576
577 int new_width = ceil (rmax [0] - dx);
578 int new_height = ceil (rmax [1] - dy);
579
580 double inv[3][3];
581 mat_invert (matrix, inv);
582
527 rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height, repeat); 583 rxvt_img *img = new rxvt_img (s, format, ox - dx, oy - dy, new_width, new_height, repeat);
528 img->alloc (); 584 img->alloc ();
529 585
530 Display *dpy = s->display->dpy; 586 Display *dpy = s->display->dpy;
531 Picture src = src_picture (); 587 Picture src = src_picture ();
532 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 588 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
533 589
534 XTransform xfrm; 590 XTransform xfrm;
535 591
536 for (int i = 0; i < 3; ++i) 592 for (int i = 0; i < 3; ++i)
537 for (int j = 0; j < 3; ++j) 593 for (int j = 0; j < 3; ++j)
538 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 594 xfrm.matrix [i][j] = XDoubleToFixed (inv [i][j]);
539
540 xfrm.matrix [0][2] -= XDoubleToFixed (x);//TODO
541 xfrm.matrix [1][2] -= XDoubleToFixed (y);
542 595
543 XRenderSetPictureFilter (dpy, src, "good", 0, 0); 596 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
544 XRenderSetPictureTransform (dpy, src, &xfrm); 597 XRenderSetPictureTransform (dpy, src, &xfrm);
545 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); 598 XRenderComposite (dpy, PictOpSrc, src, None, dst, dx, dy, 0, 0, 0, 0, new_width, new_height);
546 599
547 XRenderFreePicture (dpy, src); 600 XRenderFreePicture (dpy, src);
548 XRenderFreePicture (dpy, dst); 601 XRenderFreePicture (dpy, dst);
549 602
550 return img; 603 return img;
554rxvt_img::scale (int new_width, int new_height) 607rxvt_img::scale (int new_width, int new_height)
555{ 608{
556 if (w == new_width && h == new_height) 609 if (w == new_width && h == new_height)
557 return clone (); 610 return clone ();
558 611
559 double matrix[9] = { 612 double matrix[3][3] = {
560 w / (double)new_width, 0, 0, 613 { new_width / (double)w, 0, 0 },
561 0, h / (double)new_height, 0, 614 { 0, new_height / (double)h, 0 },
562 0, 0, 1 615 { 0, 0, 1 }
563 }; 616 };
564 617
565 int old_repeat_mode = repeat; 618 int old_repeat_mode = repeat;
566 repeat = RepeatPad; // not right, but xrender can't properly scale it seems 619 repeat = RepeatPad; // not right, but xrender can't properly scale it seems
567 620
568 rxvt_img *img = transform (matrix, new_width, new_height); 621 rxvt_img *img = transform (matrix);
569 622
570 repeat = old_repeat_mode; 623 repeat = old_repeat_mode;
571 img->repeat = repeat; 624 img->repeat = repeat;
572 625
573 return img; 626 return img;
574} 627}
575 628
576rxvt_img * 629rxvt_img *
577rxvt_img::rotate (int x, int y, double phi, int new_width, int new_height) 630rxvt_img::rotate (int cx, int cy, double phi)
578{ 631{
579 double s = sin (phi); 632 double s = sin (phi);
580 double c = cos (phi); 633 double c = cos (phi);
581 634
582 double matrix[9] = { 635 double matrix[3][3] = {
583 c, -s, -c * x + s * y + x, 636 //{ c, -s, cx - c * cx + s * cy },
584 s, c, -s * x - c * y + y, 637 //{ s, c, cy - s * cx - c * cy },
585 0, 0, 1 638 //{ 0, 0, 1 }
639 { c, -s, 0 },
640 { s, c, 0 },
641 { 0, 0, 1 }
586 }; 642 };
587 643
588 return transform (matrix, new_width, new_height); 644 move (-cx, -cy);
645 rxvt_img *img = transform (matrix);
646 move ( cx, cy);
647 img->move (cx, cy);
648
649 return img;
589} 650}
590 651
591rxvt_img * 652rxvt_img *
592rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg) 653rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg)
593{ 654{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines