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