Fix test for bug #32625
[gnash.git] / libcore / SWFMatrix.h
blobc3ba1debd53c187a95e6e6aab5159f11ec24f8ae
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 //
21 // Original author: Thatcher Ulrich <tu@tulrich.com> 2003
25 #ifndef GNASH_MATRIX_H
26 #define GNASH_MATRIX_H
28 #include "dsodefs.h" // for DSOEXPORT
30 #include <ostream>
31 #include <boost/cstdint.hpp>
33 // Forward declarations
34 namespace gnash {
35 class SWFRect;
36 namespace geometry {
37 class Point2d;
38 template<typename T> class Range2d;
43 namespace gnash {
45 /// The SWF SWFMatrix record.
46 ///
47 /// Conceptually, it represents a 3*3 linear transformation SWFMatrix like this:
48 ///
49 /// | scale_x rotateSkew_y translate_x |
50 /// | rotateSkey_x scale_y traslate_y |
51 /// | 0 0 1 |
52 ///
53 class DSOEXPORT SWFMatrix
55 public:
57 /// Construct an identity SWFMatrix
58 SWFMatrix()
60 _a(65536),
61 _b(0),
62 _c(0),
63 _d(65536),
64 _tx(0),
65 _ty(0)
68 /// Construct a SWFMatrix with all values.
69 SWFMatrix(int a, int b, int c, int d, int x, int y)
71 _a(a),
72 _b(b),
73 _c(c),
74 _d(d),
75 _tx(x),
76 _ty(y)
79 boost::int32_t a() const {
80 return _a;
83 boost::int32_t b() const {
84 return _b;
87 boost::int32_t c() const {
88 return _c;
91 boost::int32_t d() const {
92 return _d;
95 boost::int32_t tx() const {
96 return _tx;
99 boost::int32_t ty() const {
100 return _ty;
103 /// Set the SWFMatrix to identity.
104 void set_identity();
106 /// Concatenate m's transform onto ours.
108 /// When transforming points, m happens first,
109 /// then our original xform.
110 void concatenate(const SWFMatrix& m);
112 /// Concatenate a translation onto the front of our SWFMatrix.
114 /// When transforming points, the translation
115 /// happens first, then our original xform.
116 void concatenate_translation(int _tx, int _ty);
118 /// Concatenate scale x and y to the front of our SWFMatrix
120 /// When transforming points, these scales happen first, then
121 /// our original SWFMatrix.
122 void concatenate_scale(double x, double y);
124 /// Set this SWFMatrix to a blend of m1 and m2, parameterized by t.
125 void set_lerp(const SWFMatrix& m1, const SWFMatrix& m2, float t);
127 /// Set the scale & rotation part of the SWFMatrix. angle in radians.
128 void set_scale_rotation(double x_scale, double y_scale, double rotation);
130 /// Set x and y scales, rotation is unchanged.
131 void set_scale(double x_scale, double y_scale);
133 /// Set x scale, rotation any y scale are unchanged.
134 void set_x_scale(double scale);
136 /// Set y scale, rotation and x scale are unchanged.
137 void set_y_scale(double scale);
139 /// Set rotation in radians, scales component are unchanged.
140 void set_rotation(double rotation);
142 /// Set x translation in TWIPS
143 void set_x_translation(int x) {
144 _tx = x;
147 /// Set y translation in TWIPS.
148 void set_y_translation(int y) {
149 _ty = y;
152 /// Set x and y translation in TWIPS.
153 void set_translation(int x, int y) {
154 _tx = x;
155 _ty = y;
158 /// Transform a given point by our SWFMatrix
159 void transform(geometry::Point2d& p) const;
161 /// Transform the given point by our SWFMatrix.
162 void transform(boost::int32_t& x, boost::int32_t& y) const;
164 /// Transform point 'p' by our SWFMatrix.
166 /// Put the result in *result.
168 void transform(geometry::Point2d* result, const geometry::Point2d& p) const;
170 /// Transform Range2d<float> 'r' by our SWFMatrix.
172 /// NULL and WORLD ranges are untouched.
174 void transform(geometry::Range2d<boost::int32_t>& r) const;
176 void transform(SWFRect& r) const;
178 /// Invert this SWFMatrix and return the result.
179 SWFMatrix& invert();
181 /// return the magnitude scale of our x coord output
182 double get_x_scale() const;
184 /// return the magnitude scale of our y coord output
185 double get_y_scale() const;
187 /// return rotation component in radians.
188 double get_rotation() const;
190 /// return x translation n TWIPS unit.
191 int get_x_translation() const {
192 return _tx;
195 /// return y translation in TWIPS unit.
196 int get_y_translation() const {
197 return _ty;
200 /// Allow direct access to values for equality
201 friend bool operator==(const SWFMatrix& a, const SWFMatrix& b);
203 private:
205 /// Return the determinant of this SWFMatrix in 32.32 fixed point format.
206 boost::int64_t determinant() const;
208 /// Xscale, 16.16 fixed point. xx in swfdec. 'a' in AS Matrix.
209 boost::int32_t _a;
211 /// Xshear, 16.16 fixed point. yx in swfdec. 'b' in AS Matrix.
212 boost::int32_t _b;
214 /// Yshear, 16.16 fixed point. xy in swfdec. 'c' in AS Matrix.
215 boost::int32_t _c;
217 /// Yscale, 16.16 fixed point. yy in swfdec. 'd' in AS Matrix.
218 boost::int32_t _d;
220 /// Xtranslation, TWIPS. x0 in swfdec. '_tx' in AS Matrix.
221 boost::int32_t _tx;
223 /// Ytranslation, TWIPS. y0 in swfdec. '_ty' in AS Matrix.
224 boost::int32_t _ty;
227 }; //end of SWFMatrix
229 inline bool
230 operator==(const SWFMatrix& a, const SWFMatrix& b)
232 return
233 a.a() == b._a &&
234 a._b == b._b &&
235 a._tx == b._tx &&
236 a._d == b._d &&
237 a._c == b._c &&
238 a._ty == b._ty;
241 std::ostream& operator<<(std::ostream& o, const SWFMatrix& m);
243 } // namespace gnash
245 #endif
248 // Local Variables:
249 // mode: C++
250 // indent-tabs-mode: t
251 // End: