|
1 /* |
|
2 * LIBOIL - Library of Optimized Inner Loops |
|
3 * Copyright (c) 2003 David A. Schleef <ds@schleef.org> |
|
4 * All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions |
|
8 * are met: |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * 2. Redistributions in binary form must reproduce the above copyright |
|
12 * notice, this list of conditions and the following disclaimer in the |
|
13 * documentation and/or other materials provided with the distribution. |
|
14 * |
|
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
|
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
|
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
25 * POSSIBILITY OF SUCH DAMAGE. |
|
26 */ |
|
27 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
28 |
|
29 #ifdef HAVE_CONFIG_H |
|
30 #include "config.h" |
|
31 #endif |
|
32 |
|
33 #include <liboil/liboilfunction.h> |
|
34 #include "liboil/dct/dct.h" |
|
35 #include <math.h> |
|
36 |
|
37 /** |
|
38 * oil_fdct8_f64: |
|
39 * @d_8: |
|
40 * @s_8: |
|
41 * @dstr: |
|
42 * @sstr: |
|
43 * |
|
44 * Performs a Forward Discrete Cosine Transform on @s_8 and places |
|
45 * the result in @d_8. |
|
46 */ |
|
47 OIL_DEFINE_CLASS (fdct8_f64, "double *d_8, double *s_8, int dstr, int sstr"); |
|
48 |
|
49 #define C0_9808 0.980785280 |
|
50 #define C0_9239 0.923879532 |
|
51 #define C0_8315 0.831469612 |
|
52 #define C0_7071 0.707106781 |
|
53 #define C0_5556 0.555570233 |
|
54 #define C0_3827 0.382683432 |
|
55 #define C0_1951 0.195090322 |
|
56 |
|
57 static void |
|
58 fdct8_f64_ref (double *dest, const double *src, int dstr, int sstr) |
|
59 { |
|
60 static double fdct_coeff[8][8]; |
|
61 static int fdct_coeff_init = 0; |
|
62 int i,j; |
|
63 double x; |
|
64 |
|
65 if(!fdct_coeff_init){ |
|
66 double scale; |
|
67 |
|
68 for(i=0;i<8;i++){ |
|
69 scale = (i==0) ? sqrt(0.125) : 0.5; |
|
70 for(j=0;j<8;j++){ |
|
71 fdct_coeff[j][i] = scale * |
|
72 cos((M_PI/8)*i*(j+0.5)); |
|
73 } |
|
74 } |
|
75 fdct_coeff_init = 1; |
|
76 } |
|
77 |
|
78 for(i=0;i<8;i++){ |
|
79 x = 0; |
|
80 for(j=0;j<8;j++){ |
|
81 x += fdct_coeff[j][i] * OIL_GET(src,sstr*j, double); |
|
82 } |
|
83 OIL_GET(dest,dstr*i, double) = x; |
|
84 } |
|
85 } |
|
86 |
|
87 OIL_DEFINE_IMPL_REF (fdct8_f64_ref, fdct8_f64); |
|
88 |
|
89 /* |
|
90 * This algorithm is roughly similar to a Fast-Fourier transform, |
|
91 * taking advantage of the symmeties of the base vectors. For |
|
92 * reference, the base vectors are (horizontally): |
|
93 * |
|
94 * 0: 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 |
|
95 * 1: 0.9808 0.8315 0.5556 0.1951 -0.1951 -0.5556 -0.8315 -0.9808 |
|
96 * 2: 0.9239 0.3827 -0.3827 -0.9239 -0.9239 -0.3827 0.3827 0.9239 |
|
97 * 3: 0.8315 -0.1951 -0.9808 -0.5556 0.5556 0.9808 0.1951 -0.8315 |
|
98 * 4: 0.7071 -0.7071 -0.7071 0.7071 0.7071 -0.7071 -0.7071 0.7071 |
|
99 * 5: 0.5556 -0.9808 0.1951 0.8315 -0.8315 -0.1951 0.9808 -0.5556 |
|
100 * 6: 0.3827 -0.9239 0.9239 -0.3827 -0.3827 0.9239 -0.9239 0.3827 |
|
101 * 7: 0.1951 -0.5556 0.8315 -0.9808 0.9808 -0.8315 0.5556 -0.1951 |
|
102 * |
|
103 * The symmetries of note: |
|
104 * - even vectors are symmetric around 4 (the middle) |
|
105 * - odd vectors are antisymmetric around 4 |
|
106 * - 0,4 are symmertic around 2 and 6 |
|
107 * - 2,6 are antisymmetic around 2 and 6 |
|
108 * |
|
109 * f0 = (x0 + x7) + (x1 + x6) + (x2 + x5) + (x3 + x4); |
|
110 * f1 = 0.9808*(x0 - x7) + 0.8315*(x1 - x6) + 0.5556*(x2 - x5) + 0.1951*(x3 - x4) |
|
111 * f2 = 0.9239*(x0 + x7) + 0.3827*(x1 + x6) - 0.3827*(x2 + x5) - 0.9239*(x3 + x4) |
|
112 * f3 = 0.8315*(x0 - x7) - 0.1951*(x1 - x6) - 0.9808*(x2 - x5) - 0.5556*(x3 - x4) |
|
113 * f4 = 0.7071*((x0 + x7) - (x1 + x6) - (x2 + x5) + (x3 + x4)) |
|
114 * f5 = 0.5556*(x0 - x7) - 0.9808*(x1 - x6) + 0.1951*(x2 - x5) + 0.8315*(x3 - x4) |
|
115 * f6 = 0.3827*(x0 + x7) - 0.9239*(x1 + x6) + 0.9239*(x2 + x5) - 0.3827*(x3 + x4) |
|
116 * f7 = 0.1951*(x0 - x7) - 0.5556*(x1 - x6) + 0.8315*(x2 - x5) - 0.9808*(x3 - x4) |
|
117 * |
|
118 * The even vectors can be further simplified: |
|
119 * |
|
120 * f0 = ((x0 + x7) + (x3 + x4)) + ((x1 + x6) + (x2 + x5)); |
|
121 * f2 = 0.9239*((x0 + x7) - (x3 + x4)) + 0.3827*((x1 + x6) - (x2 + x5)) |
|
122 * f4 = 0.7071*((x0 + x7) + (x3 + x4)) - 0.7071*((x1 + x6) + (x2 + x5)) |
|
123 * f6 = 0.3827*((x0 + x7) - (x3 + x4)) - 0.9239*((x1 + x6) - (x2 + x5)) |
|
124 * |
|
125 * Some implementations move some of the normalization to a later |
|
126 * stage of processing, saving a few multiplies which get absorbed |
|
127 * into later multiplies. However, this incurs a bit of error in |
|
128 * the integer versions of this function. Also, if the CPU has a |
|
129 * multiply-and-add function, you don't gain anything. |
|
130 */ |
|
131 |
|
132 static void |
|
133 fdct8_f64_fast(double *dest, const double *src, int dstr, int sstr) |
|
134 { |
|
135 double s07, s16, s25, s34; |
|
136 double d07, d16, d25, d34; |
|
137 double ss07s34, ds07s34, ss16s25, ds16s25; |
|
138 |
|
139 s07 = OIL_GET(src,sstr*0,double) + OIL_GET(src,sstr*7,double); |
|
140 d07 = OIL_GET(src,sstr*0,double) - OIL_GET(src,sstr*7,double); |
|
141 s16 = OIL_GET(src,sstr*1,double) + OIL_GET(src,sstr*6,double); |
|
142 d16 = OIL_GET(src,sstr*1,double) - OIL_GET(src,sstr*6,double); |
|
143 s25 = OIL_GET(src,sstr*2,double) + OIL_GET(src,sstr*5,double); |
|
144 d25 = OIL_GET(src,sstr*2,double) - OIL_GET(src,sstr*5,double); |
|
145 s34 = OIL_GET(src,sstr*3,double) + OIL_GET(src,sstr*4,double); |
|
146 d34 = OIL_GET(src,sstr*3,double) - OIL_GET(src,sstr*4,double); |
|
147 |
|
148 ss07s34 = s07 + s34; |
|
149 ds07s34 = s07 - s34; |
|
150 ss16s25 = s16 + s25; |
|
151 ds16s25 = s16 - s25; |
|
152 |
|
153 OIL_GET(dest,dstr*0,double) = 0.5*C0_7071*(ss07s34 + ss16s25); |
|
154 OIL_GET(dest,dstr*2,double) = 0.5*(C0_9239*ds07s34 + C0_3827*ds16s25); |
|
155 OIL_GET(dest,dstr*4,double) = 0.5*C0_7071*(ss07s34 - ss16s25); |
|
156 OIL_GET(dest,dstr*6,double) = 0.5*(C0_3827*ds07s34 - C0_9239*ds16s25); |
|
157 |
|
158 OIL_GET(dest,dstr*1,double) = 0.5*(C0_9808*d07 + C0_8315*d16 |
|
159 + C0_5556*d25 + C0_1951*d34); |
|
160 OIL_GET(dest,dstr*3,double) = 0.5*(C0_8315*d07 - C0_1951*d16 |
|
161 - C0_9808*d25 - C0_5556*d34); |
|
162 OIL_GET(dest,dstr*5,double) = 0.5*(C0_5556*d07 - C0_9808*d16 |
|
163 + C0_1951*d25 + C0_8315*d34); |
|
164 OIL_GET(dest,dstr*7,double) = 0.5*(C0_1951*d07 - C0_5556*d16 |
|
165 + C0_8315*d25 - C0_9808*d34); |
|
166 |
|
167 #if 0 |
|
168 z1 = (ds1 tmp12 + tmp13) * 0.707106781; |
|
169 OIL_GET(dest,dstr*2,double) = (tmp13 + z1)*(0.25*M_SQRT2)*0.765366864; |
|
170 OIL_GET(dest,dstr*6,double) = (tmp13 - z1)*(0.25*M_SQRT2)*1.847759066; |
|
171 |
|
172 tmp10 = tmp4 + tmp5; |
|
173 tmp11 = tmp5 + tmp6; |
|
174 tmp12 = tmp6 + tmp7; |
|
175 |
|
176 z5 = (tmp10 - tmp12) * 0.382683433; |
|
177 z2 = 0.541196100 * tmp10 + z5; |
|
178 z4 = 1.306562965 * tmp12 + z5; |
|
179 z3 = tmp11 * 0.707106781; |
|
180 |
|
181 z11 = tmp7 + z3; |
|
182 z13 = tmp7 - z3; |
|
183 |
|
184 OIL_GET(dest,dstr*5,double) = (z13 + z2)*(0.25*M_SQRT2)*1.2728; |
|
185 OIL_GET(dest,dstr*3,double) = (z13 - z2)*(0.25*M_SQRT2)*0.8504; |
|
186 OIL_GET(dest,dstr*1,double) = (z11 + z4)*(0.25*M_SQRT2)*0.7209; |
|
187 OIL_GET(dest,dstr*7,double) = (z11 - z4)*(0.25*M_SQRT2)*3.6245; |
|
188 #endif |
|
189 } |
|
190 OIL_DEFINE_IMPL (fdct8_f64_fast, fdct8_f64); |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 #ifdef __SYMBIAN32__ |
|
198 |
|
199 OilFunctionClass* __oil_function_class_fdct8_f64() { |
|
200 return &_oil_function_class_fdct8_f64; |
|
201 } |
|
202 #endif |
|
203 |
|
204 |
|
205 |
|
206 #ifdef __SYMBIAN32__ |
|
207 |
|
208 OilFunctionImpl* __oil_function_impl_fdct8_f64_ref() { |
|
209 return &_oil_function_impl_fdct8_f64_ref; |
|
210 } |
|
211 #endif |
|
212 |
|
213 #ifdef __SYMBIAN32__ |
|
214 |
|
215 OilFunctionImpl* __oil_function_impl_fdct8_f64_fast() { |
|
216 return &_oil_function_impl_fdct8_f64_fast; |
|
217 } |
|
218 #endif |
|
219 |
|
220 |
|
221 |
|
222 #ifdef __SYMBIAN32__ |
|
223 |
|
224 EXPORT_C void** _oil_function_class_ptr_fdct8_f64 () { |
|
225 oil_function_class_ptr_fdct8_f64 = __oil_function_class_fdct8_f64(); |
|
226 return &oil_function_class_ptr_fdct8_f64->func; |
|
227 } |
|
228 #endif |
|
229 |