… | |
… | |
629 | } |
629 | } |
630 | |
630 | |
631 | rxvt_img * |
631 | rxvt_img * |
632 | rxvt_img::transform (nv matrix[3][3]) |
632 | rxvt_img::transform (nv matrix[3][3]) |
633 | { |
633 | { |
634 | // find new offset |
|
|
635 | int ox = mat_apply (matrix, 0, -x, -y); |
|
|
636 | int oy = mat_apply (matrix, 1, -x, -y); |
|
|
637 | |
|
|
638 | // calculate new pixel bounding box coordinates |
634 | // calculate new pixel bounding box coordinates |
639 | nv d [2], rmin[2], rmax[2]; |
635 | nv rmin[2], rmax[2]; |
640 | |
636 | |
641 | for (int i = 0; i < 2; ++i) |
637 | for (int i = 0; i < 2; ++i) |
642 | { |
638 | { |
643 | nv v; |
639 | nv v; |
|
|
640 | |
644 | v = mat_apply (matrix, i, 0, 0); rmin [i] = rmax [i] = v; d [i] = v; |
641 | v = mat_apply (matrix, i, 0+x, 0+y); rmin [i] = rmax [i] = v; |
645 | v = mat_apply (matrix, i, w, 0); min_it (rmin [i], v); max_it (rmax [i], v); |
642 | v = mat_apply (matrix, i, w+x, 0+y); min_it (rmin [i], v); max_it (rmax [i], v); |
646 | v = mat_apply (matrix, i, 0, h); min_it (rmin [i], v); max_it (rmax [i], v); |
643 | v = mat_apply (matrix, i, 0+x, h+y); min_it (rmin [i], v); max_it (rmax [i], v); |
647 | v = mat_apply (matrix, i, w, h); min_it (rmin [i], v); max_it (rmax [i], v); |
644 | v = mat_apply (matrix, i, w+x, h+y); min_it (rmin [i], v); max_it (rmax [i], v); |
648 | } |
645 | } |
649 | |
646 | |
|
|
647 | // TODO: adjust matrix for subpixel accuracy |
650 | int dx = floor (rmin [0]); |
648 | int dx = floor (rmin [0]); |
651 | int dy = floor (rmin [1]); |
649 | int dy = floor (rmin [1]); |
652 | |
650 | |
653 | int new_width = ceil (rmax [0] - dx); |
651 | int new_width = ceil (rmax [0] - dx); |
654 | int new_height = ceil (rmax [1] - dy); |
652 | int new_height = ceil (rmax [1] - dy); |
655 | |
653 | |
656 | nv inv[3][3]; |
654 | nv inv[3][3]; |
657 | mat_invert (matrix, inv); |
655 | mat_invert (matrix, inv); |
658 | |
656 | |
659 | rxvt_img *img = new rxvt_img (s, format, ox - dx - d [0], oy - dy - d [1], new_width, new_height, repeat); |
657 | rxvt_img *img = new rxvt_img (s, format, dx, dy, new_width, new_height, repeat); |
660 | img->alloc (); |
658 | img->alloc (); |
661 | |
659 | |
662 | Display *dpy = s->display->dpy; |
660 | Display *dpy = s->display->dpy; |
663 | Picture src = picture (); |
661 | Picture src = picture (); |
664 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
662 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
… | |
… | |
707 | { |
705 | { |
708 | nv s = sin (phi); |
706 | nv s = sin (phi); |
709 | nv c = cos (phi); |
707 | nv c = cos (phi); |
710 | |
708 | |
711 | nv matrix[3][3] = { |
709 | nv matrix[3][3] = { |
712 | { c, -s, cx - c * cx + s * cy }, |
710 | { c, -s, cx - c * cx + s * cy + 200 }, |
713 | { s, c, cy - s * cx - c * cy }, |
711 | { s, c, cy - s * cx - c * cy }, |
714 | { 0, 0, 1 } |
712 | { 0, 0, 1 } |
715 | //{ c, -s, 0 }, |
713 | //{ c, -s, 0 }, |
716 | //{ s, c, 0 }, |
714 | //{ s, c, 0 }, |
717 | //{ 0, 0, 1 } |
715 | //{ 0, 0, 1 } |