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.94 by root, Fri Jun 15 18:10:40 2012 UTC vs.
Revision 1.95 by root, Fri Jun 15 18:36:26 2012 UTC

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
698rxvt_img * 727rxvt_img *
699rxvt_img::transform (nv matrix[3][3]) 728rxvt_img::transform (const nv matrix[3][3])
700{ 729{
730 return transform (mat3x3 (&matrix[0][0]));
731}
732
733rxvt_img *
734rxvt_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
754rxvt_img::scale (int new_width, int new_height) 789rxvt_img::scale (int new_width, int new_height)
755{ 790{
756 if (w == new_width && h == new_height) 791 if (w == new_width && h == new_height)
757 return clone (); 792 return clone ();
758 793
759 nv matrix[3][3] = {
760 { new_width / (nv)w, 0, 0 },
761 { 0, new_height / (nv)h, 0 },
762 { 0, 0, 1 }
763 };
764
765 int old_repeat_mode = repeat; 794 int old_repeat_mode = repeat;
766 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
767 796
768 rxvt_img *img = transform (matrix); 797 rxvt_img *img = transform (mat3x3::scale (new_width / (nv)w, new_height / (nv)h));
769 798
770 repeat = old_repeat_mode; 799 repeat = old_repeat_mode;
771 img->repeat = repeat; 800 img->repeat = repeat;
772 801
773 return img; 802 return img;
774} 803}
775 804
776rxvt_img * 805rxvt_img *
777rxvt_img::rotate (int cx, int cy, nv phi) 806rxvt_img::rotate (int cx, int cy, nv phi)
778{ 807{
779 nv s = sin (phi);
780 nv c = cos (phi);
781
782 nv matrix[3][3] = {
783#if 0 808#if 0
784 { c, -s, cx - c * cx + s * cy }, 809 { c, -s, cx - c * cx + s * cy },
785 { s, c, cy - s * cx - c * cy }, 810 { s, c, cy - s * cx - c * cy },
786 { 0, 0, 1 } 811 { 0, 0, 1 }
787#else
788 { c, -s, 0 },
789 { s, c, 0 },
790 { 0, 0, 1 }
791#endif 812#endif
792 };
793 813
794 move (-cx, -cy); 814 move (-cx, -cy);
795 rxvt_img *img = transform (matrix); 815 rxvt_img *img = transform (mat3x3::rotate (phi));
796 move ( cx, cy); 816 move ( cx, cy);
797 img->move (cx, cy); 817 img->move (cx, cy);
798 818
799 return img; 819 return img;
800} 820}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines