polygon intersector: added horizontal line reconstruction
[swftools.git] / lib / lame / tools.h
1 /*
2  *    LAME tools library include file
3  *    Simple context free functions
4  *      - no references to gfc, to gfp, or to any other function not defined
5  *        in this module
6  * 
7  *    Copyright (c) 2000 Frank Klemm
8  *    Copyright (c) 2001 John Dahlstrom
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */
25
26 /* $Id: tools.h,v 1.1 2002/04/28 17:30:30 kramm Exp $ */
27
28 #ifndef LAME_TOOLS_H
29 #define LAME_TOOLS_H
30
31 #include "machine.h"
32
33
34
35 /***********************************************************************
36 *  Function Prototype Declarations
37 ***********************************************************************/
38
39 static inline void qinterp_cf_42( const FLOAT y[4], FLOAT c[3] );
40 static inline void qinterp_cf_3( const FLOAT y[3], FLOAT c[3] );
41 static inline FLOAT qinterp_eval( const FLOAT c[3], FLOAT x, 
42                                   FLOAT xtrans, FLOAT xratio );
43
44
45
46 /***********************************************************************
47 *  Macros and Static Inline Function Definitions
48 ***********************************************************************/
49
50 /* qinterp_cf_42 - Given 4 points, find the coefficients for a quadratic
51                    that connects the 2 center points.  -jd
52   in: y    coordinate values, paired with constant x coordinates, -1, 0, 1, 2
53  out: c    coefficients ordered for quadratic, (c[2] * x*x + c[1] * x + c[0])
54 design note:
55   Utilize the inverse of two constant 3x3 matrices to compute two quadratics,
56   one from the points at (-1,0,1), and the other from the points at (0,1,2).
57   The mean of the two yields a quadratic between the points at 0 and 1.
58 */
59 static inline void
60 qinterp_cf_42( const FLOAT y[4], FLOAT c[3] )
61 {
62   c[2] = ( y[0] - y[1] - y[2] + y[3]) * 0.25; /* ([1 -1 -1 1] .* Y) * 0.25 */
63   c[1] = y[2] - y[1] - c[2];    /* ([-1 -3 5 -1] .* Y) * 0.25 */
64   c[0] = y[1];
65 }
66
67 /* qinterp_cf_3 - Given 3 points, find the coefficients for a quadratic
68                   that connects the 3 points.  -jd
69   in: y    coordinate values, paired with constant x coordinates, 0, 1, 2
70  out: c    coefficients ordered for quadratic, (c[2] * x*x + c[1] * x + c[0])
71 */
72 static inline void
73 qinterp_cf_3( const FLOAT y[3], FLOAT c[3] )
74 {
75   c[2] = ( y[0] + y[2]) * 0.5 - y[1]; /* ([1 -2 1] .* Y) * 0.5 */
76   c[1] = y[1] - y[0] - c[2];    /* ([-3 4 -1] .* Y) * 0.5 */
77   c[0] = y[0];
78 }
79
80
81
82 /* qinterp_eval - Evaluate a quadratic at a point, given polynomial 
83                   coefficients, and an x coordinate with translation and scale
84                   ratio values.  This function evaluates the quadratic at the
85                   transformed x coordinate ((x - xtrans) * xratio)).  -jd
86  in: c       quadratic coefficients, for (c[2] * x * x + c[1] * x + c[0])
87      x
88      xtrans
89      xratio
90 returns: y coordinate (the quadratic evaluated)
91 */
92 static inline FLOAT
93 qinterp_eval( const FLOAT c[3], FLOAT x, FLOAT xtrans, FLOAT xratio )
94 {
95   x = (x - xtrans) * xratio;
96   return( (c[2] * x + c[1]) * x + c[0] );
97 }
98
99
100
101 #endif /* LAME_TOOLS_H */