~ubuntu-branches/ubuntu/karmic/gnash/karmic

« back to all changes in this revision

Viewing changes to libcore/matrix.h

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2008-10-13 14:29:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081013142949-f6qdvnu4mn05ltdc
Tags: 0.8.4~~bzr9980-0ubuntu1
* new upstream release 0.8.4 (LP: #240325)
* ship new lib usr/lib/gnash/libmozsdk.so.* in mozilla-plugin-gnash
  - update debian/mozilla-plugin-gnash.install
* ship new lib usr/lib/gnash/libgnashnet.so.* in gnash-common
  - update debian/gnash-common.install
* add basic debian/build_head script to build latest CVS head packages.
  - add debian/build_head
* new sound architecture requires build depend on libsdl1.2-dev
  - update debian/control
* head build script now has been completely migrated to bzr (upstream +
  ubuntu)
  - update debian/build_head
* disable kde gui until klash/qt4 has been fixed; keep kde packages as empty
  packages for now.
  - update debian/rules
  - debian/klash.install
  - debian/klash.links
  - debian/klash.manpages
  - debian/konqueror-plugin-gnash.install
* drop libkonq5-dev build dependency accordingly
  - update debian/control
* don't install headers manually anymore. gnash doesnt provide a -dev
  package after all
  - update debian/rules
* update libs installed in gnash-common; libgnashserver-*.so is not available
  anymore (removed); in turn we add the new libgnashcore-*.so
  - update debian/gnash-common.install
* use -Os for optimization and properly pass CXXFLAGS=$(CFLAGS) to configure
  - update debian/rules
* touch firefox .autoreg in postinst of mozilla plugin
  - update debian/mozilla-plugin-gnash.postinst
* link gnash in ubufox plugins directory for the plugin alternative switcher
  - add debian/mozilla-plugin-gnash.links
* suggest ubufox accordingly
  - update debian/control
* add new required build-depends on libgif-dev
  - update debian/control
* add Xb-Npp-Description and Xb-Npp-File as new plugin database meta data
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
3
// 
 
4
// This program is free software; you can redistribute it and/or modify
 
5
// it under the terms of the GNU General Public License as published by
 
6
// the Free Software Foundation; either version 3 of the License, or
 
7
// (at your option) any later version.
 
8
// 
 
9
// This program is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
// GNU General Public License for more details.
 
13
// 
 
14
// You should have received a copy of the GNU General Public License
 
15
// along with this program; if not, write to the Free Software
 
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 
 
18
// 
 
19
//
 
20
// Original author: Thatcher Ulrich <tu@tulrich.com> 2003
 
21
//
 
22
//
 
23
 
 
24
#ifndef GNASH_MATRIX_H
 
25
#define GNASH_MATRIX_H
 
26
 
 
27
#include "dsodefs.h" // for DSOEXPORT
 
28
#include "Range2d.h" // for transforming Range2d<float>
 
29
#include "rect.h"    // for rect 
 
30
#include "Point2d.h" // for Point2d
 
31
#include "utility.h" // for TRUST_FLOAT_TO_UINT32_CONVERSION
 
32
 
 
33
#include <iostream> 
 
34
#include <boost/cstdint.hpp>
 
35
 
 
36
// Forward declarations
 
37
namespace gnash {
 
38
    class SWFStream;
 
39
}
 
40
 
 
41
 
 
42
namespace gnash {
 
43
 
 
44
/// The SWF matrix record.
 
45
/// 
 
46
/// Conceptually, it represents a 3*3 linear transformation matrix like this:
 
47
/// 
 
48
///   | scale_x       rotateSkew_y  translate_x |
 
49
///   | rotateSkey_x  scale_y       traslate_y  |
 
50
///   | 0             0             1           |
 
51
/// 
 
52
class DSOEXPORT matrix
 
53
{
 
54
public:
 
55
 
 
56
    /// Xscale, 16.16 fixed point. xx in swfdec. 'a' in AS Matrix.
 
57
    int sx; 
 
58
 
 
59
    /// Xshear, 16.16 fixed point. yx in swfdec. 'b' in AS Matrix.
 
60
    int shx;
 
61
 
 
62
    /// Xtranslation, TWIPS. x0 in swfdec. 'tx' in AS Matrix.
 
63
    int tx; 
 
64
 
 
65
    /// Yscale, 16.16 fixed point. yy in swfdec. 'd' in AS Matrix.
 
66
    int sy; 
 
67
 
 
68
    /// Yshear, 16.16 fixed point. xy in swfdec. 'c' in AS Matrix.
 
69
    int shy;
 
70
 
 
71
    /// Ytranslation, TWIPS. y0 in swfdec. 'ty' in AS Matrix.
 
72
    int ty; 
 
73
             
 
74
    friend bool operator== (const matrix&, const matrix&);
 
75
    friend std::ostream& operator<< (std::ostream&, const matrix&);
 
76
    
 
77
    /// Defaults to identity
 
78
    matrix();
 
79
 
 
80
    /// Check validity of the matrix values
 
81
    bool    is_valid() const;
 
82
 
 
83
    /// Set the matrix to identity.
 
84
    void    set_identity();
 
85
 
 
86
    /// Concatenate m's transform onto ours. 
 
87
    //
 
88
    /// When transforming points, m happens first,
 
89
    /// then our original xform.
 
90
    ///
 
91
    void    concatenate(const matrix& m);
 
92
 
 
93
    /// Concatenate a translation onto the front of our matrix.
 
94
    //
 
95
    /// When transforming points, the translation
 
96
    /// happens first, then our original xform.
 
97
    ///
 
98
    void    concatenate_translation(int tx, int ty);
 
99
 
 
100
    /// Concatenate scale x and y to the front of our matrix 
 
101
    //
 
102
    /// When transforming points, these scales happen first, then
 
103
    /// our original matrix. 
 
104
    /// 
 
105
    void    concatenate_scale(double x, double y);
 
106
 
 
107
    /// Set this matrix to a blend of m1 and m2, parameterized by t.
 
108
    void    set_lerp(const matrix& m1, const matrix& m2, float t);
 
109
 
 
110
    /// Set the scale & rotation part of the matrix. angle in radians.
 
111
    void    set_scale_rotation(double x_scale, double y_scale, double rotation);
 
112
 
 
113
    /// Set x and y scales, rotation is unchanged.
 
114
    void    set_scale(double x_scale, double y_scale);
 
115
 
 
116
    /// Set x scale, rotation any y scale are unchanged.
 
117
    void    set_x_scale(double scale);
 
118
 
 
119
    /// Set y scale, rotation and x scale are unchanged.
 
120
    void    set_y_scale(double scale);
 
121
 
 
122
    /// Set rotation in radians, scales component are unchanged.
 
123
    void    set_rotation(double rotation);
 
124
 
 
125
    /// Set x translation in TWIPS
 
126
    void set_x_translation(int x)
 
127
    {
 
128
        tx = x;
 
129
    }
 
130
 
 
131
    /// Set y translation in TWIPS.
 
132
    void set_y_translation(int y)
 
133
    {
 
134
        ty = y;
 
135
    }
 
136
 
 
137
    /// Set x and y translation in TWIPS.
 
138
    void set_translation(int x, int y)
 
139
    {
 
140
        tx = x;
 
141
        ty = y;
 
142
    }
 
143
 
 
144
    /// Initialize from the SWF input stream.
 
145
    void    read(SWFStream& in);
 
146
 
 
147
    /// Transform a given point by our matrix
 
148
    void    transform(geometry::Point2d& p) const
 
149
    {
 
150
        boost::int32_t t0 = Fixed16Mul(sx, p.x) + Fixed16Mul(shy, p.y) + tx;
 
151
        boost::int32_t t1 = Fixed16Mul(shx,p.x) + Fixed16Mul(sy,  p.y) + ty;
 
152
        p.x = t0;
 
153
        p.y = t1;
 
154
    }
 
155
 
 
156
    /// Transform the given point by our matrix.
 
157
    void    transform(boost::int32_t& x, boost::int32_t& y) const
 
158
    {
 
159
        boost::int32_t  t0 = Fixed16Mul(sx, x) + Fixed16Mul(shy, y) + tx;
 
160
        boost::int32_t  t1 = Fixed16Mul(shx,x) + Fixed16Mul(sy,  y) + ty;
 
161
        x = t0;
 
162
        y = t1;
 
163
    }
 
164
    
 
165
    /// Transform point 'p' by our matrix. 
 
166
    //
 
167
    /// Put the result in *result.
 
168
    ///
 
169
    void    transform(point* result, const point& p) const;
 
170
 
 
171
    /// Transform Range2d<float> 'r' by our matrix. 
 
172
    //
 
173
    /// NULL and WORLD ranges are untouched.
 
174
    ///
 
175
    void    transform(geometry::Range2d<float>& r) const;
 
176
 
 
177
    void    transform(rect& r) const;
 
178
    
 
179
    /// Invert this matrix and return the result.
 
180
    const matrix& invert();
 
181
    
 
182
    /// return the magnitude scale of our x coord output
 
183
    double   get_x_scale() const;
 
184
 
 
185
    /// return the magnitude scale of our y coord output
 
186
    double   get_y_scale() const;
 
187
 
 
188
    /// return rotation component in radians.
 
189
    double   get_rotation() const;
 
190
 
 
191
    /// return x translation n TWIPS unit.
 
192
    int   get_x_translation() const
 
193
    {
 
194
        return tx;
 
195
    }
 
196
 
 
197
    /// return y translation in TWIPS unit.
 
198
    int   get_y_translation() const
 
199
    {
 
200
        return ty;
 
201
    }
 
202
 
 
203
private: 
 
204
    /// Return the determinant of this matrix in 32.32 fixed point format.
 
205
    boost::int64_t  determinant() const;
 
206
 
 
207
    inline boost::int32_t FloatToFixed16(float a)
 
208
    {
 
209
#ifdef TRUST_FLOAT_TO_UINT32_CONVERSION
 
210
        // truncate when overflow occurs.
 
211
        return static_cast<boost::int32_t>(static_cast<boost::uint32_t>(a * 65536.0f));
 
212
#else
 
213
        boost::int32_t  b;
 
214
        if(a >= 0)
 
215
        {
 
216
            b = static_cast<boost::uint32_t>(std::fmod(a * 65536.0, 4294967296.0));
 
217
        }
 
218
        else
 
219
        {
 
220
            b = -static_cast<boost::uint32_t>(std::fmod(-a * 65536.0, 4294967296.0));
 
221
        }
 
222
        return b;
 
223
#endif
 
224
    }
 
225
 
 
226
    inline boost::int32_t DoubleToFixed16(double a)
 
227
    {
 
228
#ifdef TRUST_FLOAT_TO_UINT32_CONVERSION
 
229
        // truncate when overflow occurs.
 
230
        return static_cast<boost::int32_t>(static_cast<boost::uint32_t>(a * 65536.0));
 
231
#else
 
232
        boost::int32_t  b;
 
233
        if(a >= 0)
 
234
        {
 
235
            b = static_cast<boost::uint32_t>(std::fmod(a * 65536.0, 4294967296.0));
 
236
        }
 
237
        else
 
238
        {
 
239
            b = -static_cast<boost::uint32_t>(std::fmod(-a * 65536.0, 4294967296.0));
 
240
        }
 
241
        return b;
 
242
#endif
 
243
    }
 
244
 
 
245
}; //end of matrix
 
246
 
 
247
inline bool operator== (const matrix& a, const matrix& b)
 
248
{
 
249
    return  
 
250
        a.sx  == b.sx  &&
 
251
        a.shx == b.shx &&
 
252
        a.tx  == b.tx  &&
 
253
        a.sy  == b.sy  &&
 
254
        a.shy == b.shy &&
 
255
        a.ty  == b.ty;
 
256
}
 
257
 
 
258
}   // namespace gnash
 
259
 
 
260
#endif // GNASH_MATRIX_H
 
261
 
 
262
 
 
263
// Local Variables:
 
264
// mode: C++
 
265
// indent-tabs-mode: t
 
266
// End:
 
267
//