Update contrib.
2 * LIBOIL - Library of Optimized Inner Loops
3 * Copyright (c) 2003 David A. Schleef <ds@schleef.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
27 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
33 #include <liboil/liboilfunction.h>
34 #include "liboil/dct/dct.h"
44 * Performs a Forward Discrete Cosine Transform on @s_8 and places
47 OIL_DEFINE_CLASS (fdct8_f64, "double *d_8, double *s_8, int dstr, int sstr");
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
58 fdct8_f64_ref (double *dest, const double *src, int dstr, int sstr)
60 static double fdct_coeff[8][8];
61 static int fdct_coeff_init = 0;
69 scale = (i==0) ? sqrt(0.125) : 0.5;
71 fdct_coeff[j][i] = scale *
72 cos((M_PI/8)*i*(j+0.5));
81 x += fdct_coeff[j][i] * OIL_GET(src,sstr*j, double);
83 OIL_GET(dest,dstr*i, double) = x;
87 OIL_DEFINE_IMPL_REF (fdct8_f64_ref, fdct8_f64);
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):
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
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
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)
118 * The even vectors can be further simplified:
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))
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.
133 fdct8_f64_fast(double *dest, const double *src, int dstr, int sstr)
135 double s07, s16, s25, s34;
136 double d07, d16, d25, d34;
137 double ss07s34, ds07s34, ss16s25, ds16s25;
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);
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);
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);
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;
176 z5 = (tmp10 - tmp12) * 0.382683433;
177 z2 = 0.541196100 * tmp10 + z5;
178 z4 = 1.306562965 * tmp12 + z5;
179 z3 = tmp11 * 0.707106781;
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;
190 OIL_DEFINE_IMPL (fdct8_f64_fast, fdct8_f64);
199 OilFunctionClass* __oil_function_class_fdct8_f64() {
200 return &_oil_function_class_fdct8_f64;
208 OilFunctionImpl* __oil_function_impl_fdct8_f64_ref() {
209 return &_oil_function_impl_fdct8_f64_ref;
215 OilFunctionImpl* __oil_function_impl_fdct8_f64_fast() {
216 return &_oil_function_impl_fdct8_f64_fast;
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;