sl@0: /* sl@0: * LIBOIL - Library of Optimized Inner Loops sl@0: * Copyright (c) 2003 David A. Schleef sl@0: * All rights reserved. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * 1. Redistributions of source code must retain the above copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in the sl@0: * documentation and/or other materials provided with the distribution. sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR sl@0: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED sl@0: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE sl@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, sl@0: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES sl@0: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR sl@0: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, sl@0: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING sl@0: * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE sl@0: * POSSIBILITY OF SUCH DAMAGE. sl@0: */ sl@0: //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: sl@0: #ifdef HAVE_CONFIG_H sl@0: #include "config.h" sl@0: #endif sl@0: sl@0: #include sl@0: #include "liboil/dct/dct.h" sl@0: #include sl@0: sl@0: /** sl@0: * oil_fdct8_f64: sl@0: * @d_8: sl@0: * @s_8: sl@0: * @dstr: sl@0: * @sstr: sl@0: * sl@0: * Performs a Forward Discrete Cosine Transform on @s_8 and places sl@0: * the result in @d_8. sl@0: */ sl@0: OIL_DEFINE_CLASS (fdct8_f64, "double *d_8, double *s_8, int dstr, int sstr"); sl@0: sl@0: #define C0_9808 0.980785280 sl@0: #define C0_9239 0.923879532 sl@0: #define C0_8315 0.831469612 sl@0: #define C0_7071 0.707106781 sl@0: #define C0_5556 0.555570233 sl@0: #define C0_3827 0.382683432 sl@0: #define C0_1951 0.195090322 sl@0: sl@0: static void sl@0: fdct8_f64_ref (double *dest, const double *src, int dstr, int sstr) sl@0: { sl@0: static double fdct_coeff[8][8]; sl@0: static int fdct_coeff_init = 0; sl@0: int i,j; sl@0: double x; sl@0: sl@0: if(!fdct_coeff_init){ sl@0: double scale; sl@0: sl@0: for(i=0;i<8;i++){ sl@0: scale = (i==0) ? sqrt(0.125) : 0.5; sl@0: for(j=0;j<8;j++){ sl@0: fdct_coeff[j][i] = scale * sl@0: cos((M_PI/8)*i*(j+0.5)); sl@0: } sl@0: } sl@0: fdct_coeff_init = 1; sl@0: } sl@0: sl@0: for(i=0;i<8;i++){ sl@0: x = 0; sl@0: for(j=0;j<8;j++){ sl@0: x += fdct_coeff[j][i] * OIL_GET(src,sstr*j, double); sl@0: } sl@0: OIL_GET(dest,dstr*i, double) = x; sl@0: } sl@0: } sl@0: sl@0: OIL_DEFINE_IMPL_REF (fdct8_f64_ref, fdct8_f64); sl@0: sl@0: /* sl@0: * This algorithm is roughly similar to a Fast-Fourier transform, sl@0: * taking advantage of the symmeties of the base vectors. For sl@0: * reference, the base vectors are (horizontally): sl@0: * sl@0: * 0: 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 sl@0: * 1: 0.9808 0.8315 0.5556 0.1951 -0.1951 -0.5556 -0.8315 -0.9808 sl@0: * 2: 0.9239 0.3827 -0.3827 -0.9239 -0.9239 -0.3827 0.3827 0.9239 sl@0: * 3: 0.8315 -0.1951 -0.9808 -0.5556 0.5556 0.9808 0.1951 -0.8315 sl@0: * 4: 0.7071 -0.7071 -0.7071 0.7071 0.7071 -0.7071 -0.7071 0.7071 sl@0: * 5: 0.5556 -0.9808 0.1951 0.8315 -0.8315 -0.1951 0.9808 -0.5556 sl@0: * 6: 0.3827 -0.9239 0.9239 -0.3827 -0.3827 0.9239 -0.9239 0.3827 sl@0: * 7: 0.1951 -0.5556 0.8315 -0.9808 0.9808 -0.8315 0.5556 -0.1951 sl@0: * sl@0: * The symmetries of note: sl@0: * - even vectors are symmetric around 4 (the middle) sl@0: * - odd vectors are antisymmetric around 4 sl@0: * - 0,4 are symmertic around 2 and 6 sl@0: * - 2,6 are antisymmetic around 2 and 6 sl@0: * sl@0: * f0 = (x0 + x7) + (x1 + x6) + (x2 + x5) + (x3 + x4); sl@0: * f1 = 0.9808*(x0 - x7) + 0.8315*(x1 - x6) + 0.5556*(x2 - x5) + 0.1951*(x3 - x4) sl@0: * f2 = 0.9239*(x0 + x7) + 0.3827*(x1 + x6) - 0.3827*(x2 + x5) - 0.9239*(x3 + x4) sl@0: * f3 = 0.8315*(x0 - x7) - 0.1951*(x1 - x6) - 0.9808*(x2 - x5) - 0.5556*(x3 - x4) sl@0: * f4 = 0.7071*((x0 + x7) - (x1 + x6) - (x2 + x5) + (x3 + x4)) sl@0: * f5 = 0.5556*(x0 - x7) - 0.9808*(x1 - x6) + 0.1951*(x2 - x5) + 0.8315*(x3 - x4) sl@0: * f6 = 0.3827*(x0 + x7) - 0.9239*(x1 + x6) + 0.9239*(x2 + x5) - 0.3827*(x3 + x4) sl@0: * f7 = 0.1951*(x0 - x7) - 0.5556*(x1 - x6) + 0.8315*(x2 - x5) - 0.9808*(x3 - x4) sl@0: * sl@0: * The even vectors can be further simplified: sl@0: * sl@0: * f0 = ((x0 + x7) + (x3 + x4)) + ((x1 + x6) + (x2 + x5)); sl@0: * f2 = 0.9239*((x0 + x7) - (x3 + x4)) + 0.3827*((x1 + x6) - (x2 + x5)) sl@0: * f4 = 0.7071*((x0 + x7) + (x3 + x4)) - 0.7071*((x1 + x6) + (x2 + x5)) sl@0: * f6 = 0.3827*((x0 + x7) - (x3 + x4)) - 0.9239*((x1 + x6) - (x2 + x5)) sl@0: * sl@0: * Some implementations move some of the normalization to a later sl@0: * stage of processing, saving a few multiplies which get absorbed sl@0: * into later multiplies. However, this incurs a bit of error in sl@0: * the integer versions of this function. Also, if the CPU has a sl@0: * multiply-and-add function, you don't gain anything. sl@0: */ sl@0: sl@0: static void sl@0: fdct8_f64_fast(double *dest, const double *src, int dstr, int sstr) sl@0: { sl@0: double s07, s16, s25, s34; sl@0: double d07, d16, d25, d34; sl@0: double ss07s34, ds07s34, ss16s25, ds16s25; sl@0: sl@0: s07 = OIL_GET(src,sstr*0,double) + OIL_GET(src,sstr*7,double); sl@0: d07 = OIL_GET(src,sstr*0,double) - OIL_GET(src,sstr*7,double); sl@0: s16 = OIL_GET(src,sstr*1,double) + OIL_GET(src,sstr*6,double); sl@0: d16 = OIL_GET(src,sstr*1,double) - OIL_GET(src,sstr*6,double); sl@0: s25 = OIL_GET(src,sstr*2,double) + OIL_GET(src,sstr*5,double); sl@0: d25 = OIL_GET(src,sstr*2,double) - OIL_GET(src,sstr*5,double); sl@0: s34 = OIL_GET(src,sstr*3,double) + OIL_GET(src,sstr*4,double); sl@0: d34 = OIL_GET(src,sstr*3,double) - OIL_GET(src,sstr*4,double); sl@0: sl@0: ss07s34 = s07 + s34; sl@0: ds07s34 = s07 - s34; sl@0: ss16s25 = s16 + s25; sl@0: ds16s25 = s16 - s25; sl@0: sl@0: OIL_GET(dest,dstr*0,double) = 0.5*C0_7071*(ss07s34 + ss16s25); sl@0: OIL_GET(dest,dstr*2,double) = 0.5*(C0_9239*ds07s34 + C0_3827*ds16s25); sl@0: OIL_GET(dest,dstr*4,double) = 0.5*C0_7071*(ss07s34 - ss16s25); sl@0: OIL_GET(dest,dstr*6,double) = 0.5*(C0_3827*ds07s34 - C0_9239*ds16s25); sl@0: sl@0: OIL_GET(dest,dstr*1,double) = 0.5*(C0_9808*d07 + C0_8315*d16 sl@0: + C0_5556*d25 + C0_1951*d34); sl@0: OIL_GET(dest,dstr*3,double) = 0.5*(C0_8315*d07 - C0_1951*d16 sl@0: - C0_9808*d25 - C0_5556*d34); sl@0: OIL_GET(dest,dstr*5,double) = 0.5*(C0_5556*d07 - C0_9808*d16 sl@0: + C0_1951*d25 + C0_8315*d34); sl@0: OIL_GET(dest,dstr*7,double) = 0.5*(C0_1951*d07 - C0_5556*d16 sl@0: + C0_8315*d25 - C0_9808*d34); sl@0: sl@0: #if 0 sl@0: z1 = (ds1 tmp12 + tmp13) * 0.707106781; sl@0: OIL_GET(dest,dstr*2,double) = (tmp13 + z1)*(0.25*M_SQRT2)*0.765366864; sl@0: OIL_GET(dest,dstr*6,double) = (tmp13 - z1)*(0.25*M_SQRT2)*1.847759066; sl@0: sl@0: tmp10 = tmp4 + tmp5; sl@0: tmp11 = tmp5 + tmp6; sl@0: tmp12 = tmp6 + tmp7; sl@0: sl@0: z5 = (tmp10 - tmp12) * 0.382683433; sl@0: z2 = 0.541196100 * tmp10 + z5; sl@0: z4 = 1.306562965 * tmp12 + z5; sl@0: z3 = tmp11 * 0.707106781; sl@0: sl@0: z11 = tmp7 + z3; sl@0: z13 = tmp7 - z3; sl@0: sl@0: OIL_GET(dest,dstr*5,double) = (z13 + z2)*(0.25*M_SQRT2)*1.2728; sl@0: OIL_GET(dest,dstr*3,double) = (z13 - z2)*(0.25*M_SQRT2)*0.8504; sl@0: OIL_GET(dest,dstr*1,double) = (z11 + z4)*(0.25*M_SQRT2)*0.7209; sl@0: OIL_GET(dest,dstr*7,double) = (z11 - z4)*(0.25*M_SQRT2)*3.6245; sl@0: #endif sl@0: } sl@0: OIL_DEFINE_IMPL (fdct8_f64_fast, fdct8_f64); sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: OilFunctionClass* __oil_function_class_fdct8_f64() { sl@0: return &_oil_function_class_fdct8_f64; sl@0: } sl@0: #endif sl@0: sl@0: sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: OilFunctionImpl* __oil_function_impl_fdct8_f64_ref() { sl@0: return &_oil_function_impl_fdct8_f64_ref; sl@0: } sl@0: #endif sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: OilFunctionImpl* __oil_function_impl_fdct8_f64_fast() { sl@0: return &_oil_function_impl_fdct8_f64_fast; sl@0: } sl@0: #endif sl@0: sl@0: sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: EXPORT_C void** _oil_function_class_ptr_fdct8_f64 () { sl@0: oil_function_class_ptr_fdct8_f64 = __oil_function_class_fdct8_f64(); sl@0: return &oil_function_class_ptr_fdct8_f64->func; sl@0: } sl@0: #endif sl@0: