… | |
… | |
16 | |
16 | |
17 | mat3x3 () |
17 | mat3x3 () |
18 | { |
18 | { |
19 | } |
19 | } |
20 | |
20 | |
21 | mat3x3 (nv matrix[3][3]) |
21 | mat3x3 (const nv *matrix) |
22 | { |
22 | { |
23 | memcpy (v, matrix, sizeof (v)); |
23 | memcpy (v, matrix, sizeof (v)); |
24 | } |
24 | } |
25 | |
25 | |
26 | mat3x3 (nv v11, nv v12, nv v13, nv v21, nv v22, nv v23, nv v31, nv v32, nv v33) |
26 | mat3x3 (nv v11, nv v12, nv v13, nv v21, nv v22, nv v23, nv v31, nv v32, nv v33) |
… | |
… | |
33 | mat3x3 invert (); |
33 | mat3x3 invert (); |
34 | |
34 | |
35 | nv *operator [](int i) { return &v[i][0]; } |
35 | nv *operator [](int i) { return &v[i][0]; } |
36 | const nv *operator [](int i) const { return &v[i][0]; } |
36 | const nv *operator [](int i) const { return &v[i][0]; } |
37 | |
37 | |
|
|
38 | operator const nv * () const { return &v[0][0]; } |
|
|
39 | operator nv * () { return &v[0][0]; } |
|
|
40 | |
38 | // quite inefficient, hopefully gcc pulls the w calc out of any loops |
41 | // quite inefficient, hopefully gcc pulls the w calc out of any loops |
39 | nv apply1 (int i, nv x, nv y) |
42 | nv apply1 (int i, nv x, nv y) |
40 | { |
43 | { |
41 | mat3x3 &m = *this; |
44 | mat3x3 &m = *this; |
42 | |
45 | |
… | |
… | |
45 | |
48 | |
46 | return v * (1. / w); |
49 | return v * (1. / w); |
47 | } |
50 | } |
48 | |
51 | |
49 | static mat3x3 translate (nv x, nv y); |
52 | static mat3x3 translate (nv x, nv y); |
|
|
53 | static mat3x3 scale (nv s, nv t); |
|
|
54 | static mat3x3 rotate (nv phi); |
50 | }; |
55 | }; |
51 | |
56 | |
52 | mat3x3 |
57 | mat3x3 |
53 | mat3x3::invert () |
58 | mat3x3::invert () |
54 | { |
59 | { |
… | |
… | |
95 | { |
100 | { |
96 | return mat3x3 ( |
101 | return mat3x3 ( |
97 | 1, 0, x, |
102 | 1, 0, x, |
98 | 0, 1, y, |
103 | 0, 1, y, |
99 | 0, 0, 1 |
104 | 0, 0, 1 |
|
|
105 | ); |
|
|
106 | } |
|
|
107 | |
|
|
108 | mat3x3 |
|
|
109 | mat3x3::scale (nv s, nv t) |
|
|
110 | { |
|
|
111 | return mat3x3 ( |
|
|
112 | s, 0, 0, |
|
|
113 | 0, t, 0, |
|
|
114 | 0, 0, 1 |
|
|
115 | ); |
|
|
116 | } |
|
|
117 | |
|
|
118 | // clockwise |
|
|
119 | mat3x3 |
|
|
120 | mat3x3::rotate (nv phi) |
|
|
121 | { |
|
|
122 | nv s = sin (phi); |
|
|
123 | nv c = cos (phi); |
|
|
124 | |
|
|
125 | return mat3x3 ( |
|
|
126 | c, -s, 0, |
|
|
127 | s, c, 0, |
|
|
128 | 0, 0, 1 |
100 | ); |
129 | ); |
101 | } |
130 | } |
102 | |
131 | |
103 | } |
132 | } |
104 | |
133 | |
… | |
… | |
694 | |
723 | |
695 | return img; |
724 | return img; |
696 | } |
725 | } |
697 | |
726 | |
698 | rxvt_img * |
727 | rxvt_img * |
699 | rxvt_img::transform (nv matrix[3][3]) |
728 | rxvt_img::transform (const nv matrix[3][3]) |
700 | { |
729 | { |
|
|
730 | return transform (mat3x3 (&matrix[0][0])); |
|
|
731 | } |
|
|
732 | |
|
|
733 | rxvt_img * |
|
|
734 | rxvt_img::transform (const nv *matrix) |
|
|
735 | { |
|
|
736 | mat3x3 m (matrix); |
|
|
737 | |
701 | // calculate new pixel bounding box coordinates |
738 | // calculate new pixel bounding box coordinates |
702 | nv r[2], rmin[2], rmax[2]; |
739 | nv r[2], rmin[2], rmax[2]; |
703 | |
|
|
704 | mat3x3 m (matrix); |
|
|
705 | |
740 | |
706 | for (int i = 0; i < 2; ++i) |
741 | for (int i = 0; i < 2; ++i) |
707 | { |
742 | { |
708 | nv v; |
743 | nv v; |
709 | |
744 | |
… | |
… | |
741 | xfrm.matrix [i][j] = XDoubleToFixed (inv [i][j]); |
776 | xfrm.matrix [i][j] = XDoubleToFixed (inv [i][j]); |
742 | |
777 | |
743 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
778 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
744 | XRenderSetPictureTransform (dpy, src, &xfrm); |
779 | XRenderSetPictureTransform (dpy, src, &xfrm); |
745 | XRenderComposite (dpy, PictOpSrc, src, None, dst, sx, sy, 0, 0, 0, 0, new_width, new_height); |
780 | XRenderComposite (dpy, PictOpSrc, src, None, dst, sx, sy, 0, 0, 0, 0, new_width, new_height); |
746 | #if 1 |
|
|
747 | { |
|
|
748 | XRenderColor rc = { 65535,0,0,65535 }; |
|
|
749 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, new_width, new_height); |
|
|
750 | }{ |
|
|
751 | XRenderColor rc = { 0,0,0,65535 }; |
|
|
752 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 1, 1, new_width - 2, new_height - 2); |
|
|
753 | } |
|
|
754 | XRenderComposite (dpy, PictOpOver, src, None, dst, sx, sy, 0, 0, 0, 0, new_width, new_height); |
|
|
755 | #endif |
|
|
756 | |
781 | |
757 | XRenderFreePicture (dpy, src); |
782 | XRenderFreePicture (dpy, src); |
758 | XRenderFreePicture (dpy, dst); |
783 | XRenderFreePicture (dpy, dst); |
759 | |
784 | |
760 | return img; |
785 | return img; |
… | |
… | |
764 | rxvt_img::scale (int new_width, int new_height) |
789 | rxvt_img::scale (int new_width, int new_height) |
765 | { |
790 | { |
766 | if (w == new_width && h == new_height) |
791 | if (w == new_width && h == new_height) |
767 | return clone (); |
792 | return clone (); |
768 | |
793 | |
769 | nv matrix[3][3] = { |
|
|
770 | { new_width / (nv)w, 0, 0 }, |
|
|
771 | { 0, new_height / (nv)h, 0 }, |
|
|
772 | { 0, 0, 1 } |
|
|
773 | }; |
|
|
774 | |
|
|
775 | int old_repeat_mode = repeat; |
794 | int old_repeat_mode = repeat; |
776 | repeat = RepeatPad; // not right, but xrender can't properly scale it seems |
795 | repeat = RepeatPad; // not right, but xrender can't properly scale it seems |
777 | |
796 | |
778 | rxvt_img *img = transform (matrix); |
797 | rxvt_img *img = transform (mat3x3::scale (new_width / (nv)w, new_height / (nv)h)); |
779 | |
798 | |
780 | repeat = old_repeat_mode; |
799 | repeat = old_repeat_mode; |
781 | img->repeat = repeat; |
800 | img->repeat = repeat; |
782 | |
801 | |
783 | return img; |
802 | return img; |
784 | } |
803 | } |
785 | |
804 | |
786 | rxvt_img * |
805 | rxvt_img * |
787 | rxvt_img::rotate (int cx, int cy, nv phi) |
806 | rxvt_img::rotate (int cx, int cy, nv phi) |
788 | { |
807 | { |
789 | nv s = sin (phi); |
|
|
790 | nv c = cos (phi); |
|
|
791 | |
|
|
792 | nv matrix[3][3] = { |
|
|
793 | #if 0 |
808 | #if 0 |
794 | { c, -s, cx - c * cx + s * cy }, |
809 | { c, -s, cx - c * cx + s * cy }, |
795 | { s, c, cy - s * cx - c * cy }, |
810 | { s, c, cy - s * cx - c * cy }, |
796 | { 0, 0, 1 } |
811 | { 0, 0, 1 } |
797 | #else |
|
|
798 | { c, -s, 0 }, |
|
|
799 | { s, c, 0 }, |
|
|
800 | { 0, 0, 1 } |
|
|
801 | #endif |
812 | #endif |
802 | }; |
|
|
803 | |
813 | |
804 | move (-cx, -cy); |
814 | move (-cx, -cy); |
805 | rxvt_img *img = transform (matrix); |
815 | rxvt_img *img = transform (mat3x3::rotate (phi)); |
806 | move ( cx, cy); |
816 | move ( cx, cy); |
807 | img->move (cx, cy); |
817 | img->move (cx, cy); |
808 | |
818 | |
809 | return img; |
819 | return img; |
810 | } |
820 | } |