os/ossrv/genericopenlibs/liboil/src/dct/fdct8_f64.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/dct/fdct8_f64.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,229 @@
     1.4 +/*
     1.5 + * LIBOIL - Library of Optimized Inner Loops
     1.6 + * Copyright (c) 2003 David A. Schleef <ds@schleef.org>
     1.7 + * All rights reserved.
     1.8 + *
     1.9 + * Redistribution and use in source and binary forms, with or without
    1.10 + * modification, are permitted provided that the following conditions
    1.11 + * are met:
    1.12 + * 1. Redistributions of source code must retain the above copyright
    1.13 + *    notice, this list of conditions and the following disclaimer.
    1.14 + * 2. Redistributions in binary form must reproduce the above copyright
    1.15 + *    notice, this list of conditions and the following disclaimer in the
    1.16 + *    documentation and/or other materials provided with the distribution.
    1.17 + * 
    1.18 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    1.19 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    1.20 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.21 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
    1.22 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    1.23 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    1.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.25 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    1.26 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
    1.27 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.28 + * POSSIBILITY OF SUCH DAMAGE.
    1.29 + */
    1.30 +//Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
    1.31 +
    1.32 +#ifdef HAVE_CONFIG_H
    1.33 +#include "config.h"
    1.34 +#endif
    1.35 +
    1.36 +#include <liboil/liboilfunction.h>
    1.37 +#include "liboil/dct/dct.h"
    1.38 +#include <math.h>
    1.39 +
    1.40 +/**
    1.41 + * oil_fdct8_f64:
    1.42 + * @d_8:
    1.43 + * @s_8:
    1.44 + * @dstr:
    1.45 + * @sstr:
    1.46 + *
    1.47 + * Performs a Forward Discrete Cosine Transform on @s_8 and places
    1.48 + * the result in @d_8.
    1.49 + */
    1.50 +OIL_DEFINE_CLASS (fdct8_f64, "double *d_8, double *s_8, int dstr, int sstr");
    1.51 +
    1.52 +#define C0_9808 0.980785280
    1.53 +#define C0_9239 0.923879532
    1.54 +#define C0_8315 0.831469612
    1.55 +#define C0_7071 0.707106781
    1.56 +#define C0_5556 0.555570233
    1.57 +#define C0_3827 0.382683432
    1.58 +#define C0_1951 0.195090322
    1.59 +
    1.60 +static void
    1.61 +fdct8_f64_ref (double *dest, const double *src, int dstr, int sstr)
    1.62 +{
    1.63 +	static double fdct_coeff[8][8];
    1.64 +	static int fdct_coeff_init = 0;
    1.65 +	int i,j;
    1.66 +	double x;
    1.67 +
    1.68 +	if(!fdct_coeff_init){
    1.69 +		double scale;
    1.70 +
    1.71 +		for(i=0;i<8;i++){
    1.72 +			scale = (i==0) ? sqrt(0.125) : 0.5;
    1.73 +			for(j=0;j<8;j++){
    1.74 +				fdct_coeff[j][i] = scale *
    1.75 +					cos((M_PI/8)*i*(j+0.5));
    1.76 +			}
    1.77 +		}
    1.78 +		fdct_coeff_init = 1;
    1.79 +	}
    1.80 +
    1.81 +	for(i=0;i<8;i++){
    1.82 +		x = 0;
    1.83 +		for(j=0;j<8;j++){
    1.84 +			x += fdct_coeff[j][i] * OIL_GET(src,sstr*j, double);
    1.85 +		}
    1.86 +		OIL_GET(dest,dstr*i, double) = x;
    1.87 +	}
    1.88 +}
    1.89 +
    1.90 +OIL_DEFINE_IMPL_REF (fdct8_f64_ref, fdct8_f64);
    1.91 +
    1.92 +/*
    1.93 + * This algorithm is roughly similar to a Fast-Fourier transform,
    1.94 + * taking advantage of the symmeties of the base vectors.  For
    1.95 + * reference, the base vectors are (horizontally):
    1.96 + *
    1.97 + * 0: 1.0000  1.0000  1.0000  1.0000  1.0000  1.0000  1.0000  1.0000 
    1.98 + * 1: 0.9808  0.8315  0.5556  0.1951 -0.1951 -0.5556 -0.8315 -0.9808 
    1.99 + * 2: 0.9239  0.3827 -0.3827 -0.9239 -0.9239 -0.3827  0.3827  0.9239 
   1.100 + * 3: 0.8315 -0.1951 -0.9808 -0.5556  0.5556  0.9808  0.1951 -0.8315 
   1.101 + * 4: 0.7071 -0.7071 -0.7071  0.7071  0.7071 -0.7071 -0.7071  0.7071 
   1.102 + * 5: 0.5556 -0.9808  0.1951  0.8315 -0.8315 -0.1951  0.9808 -0.5556 
   1.103 + * 6: 0.3827 -0.9239  0.9239 -0.3827 -0.3827  0.9239 -0.9239  0.3827 
   1.104 + * 7: 0.1951 -0.5556  0.8315 -0.9808  0.9808 -0.8315  0.5556 -0.1951 
   1.105 + *
   1.106 + * The symmetries of note: 
   1.107 + *  - even vectors are symmetric around 4 (the middle)
   1.108 + *  - odd vectors are antisymmetric around 4
   1.109 + *  - 0,4 are symmertic around 2 and 6
   1.110 + *  - 2,6 are antisymmetic around 2 and 6
   1.111 + *
   1.112 + * f0 = (x0 + x7) + (x1 + x6) + (x2 + x5) + (x3 + x4);
   1.113 + * f1 = 0.9808*(x0 - x7) + 0.8315*(x1 - x6) + 0.5556*(x2 - x5) + 0.1951*(x3 - x4)
   1.114 + * f2 = 0.9239*(x0 + x7) + 0.3827*(x1 + x6) - 0.3827*(x2 + x5) - 0.9239*(x3 + x4)
   1.115 + * f3 = 0.8315*(x0 - x7) - 0.1951*(x1 - x6) - 0.9808*(x2 - x5) - 0.5556*(x3 - x4)
   1.116 + * f4 = 0.7071*((x0 + x7) - (x1 + x6) - (x2 + x5) + (x3 + x4))
   1.117 + * f5 = 0.5556*(x0 - x7) - 0.9808*(x1 - x6) + 0.1951*(x2 - x5) + 0.8315*(x3 - x4)
   1.118 + * f6 = 0.3827*(x0 + x7) - 0.9239*(x1 + x6) + 0.9239*(x2 + x5) - 0.3827*(x3 + x4)
   1.119 + * f7 = 0.1951*(x0 - x7) - 0.5556*(x1 - x6) + 0.8315*(x2 - x5) - 0.9808*(x3 - x4)
   1.120 + *
   1.121 + * The even vectors can be further simplified:
   1.122 + *
   1.123 + * f0 = ((x0 + x7) + (x3 + x4)) + ((x1 + x6) + (x2 + x5));
   1.124 + * f2 = 0.9239*((x0 + x7) - (x3 + x4)) + 0.3827*((x1 + x6) - (x2 + x5))
   1.125 + * f4 = 0.7071*((x0 + x7) + (x3 + x4)) - 0.7071*((x1 + x6) + (x2 + x5))
   1.126 + * f6 = 0.3827*((x0 + x7) - (x3 + x4)) - 0.9239*((x1 + x6) - (x2 + x5))
   1.127 + *
   1.128 + * Some implementations move some of the normalization to a later
   1.129 + * stage of processing, saving a few multiplies which get absorbed
   1.130 + * into later multiplies.  However, this incurs a bit of error in
   1.131 + * the integer versions of this function.  Also, if the CPU has a
   1.132 + * multiply-and-add function, you don't gain anything.
   1.133 + */
   1.134 +
   1.135 +static void
   1.136 +fdct8_f64_fast(double *dest, const double *src, int dstr, int sstr)
   1.137 +{
   1.138 +	double s07, s16, s25, s34;
   1.139 +	double d07, d16, d25, d34;
   1.140 +	double ss07s34, ds07s34, ss16s25, ds16s25;
   1.141 +
   1.142 +	s07 = OIL_GET(src,sstr*0,double) + OIL_GET(src,sstr*7,double);
   1.143 +	d07 = OIL_GET(src,sstr*0,double) - OIL_GET(src,sstr*7,double);
   1.144 +	s16 = OIL_GET(src,sstr*1,double) + OIL_GET(src,sstr*6,double);
   1.145 +	d16 = OIL_GET(src,sstr*1,double) - OIL_GET(src,sstr*6,double);
   1.146 +	s25 = OIL_GET(src,sstr*2,double) + OIL_GET(src,sstr*5,double);
   1.147 +	d25 = OIL_GET(src,sstr*2,double) - OIL_GET(src,sstr*5,double);
   1.148 +	s34 = OIL_GET(src,sstr*3,double) + OIL_GET(src,sstr*4,double);
   1.149 +	d34 = OIL_GET(src,sstr*3,double) - OIL_GET(src,sstr*4,double);
   1.150 +
   1.151 +	ss07s34 = s07 + s34;
   1.152 +	ds07s34 = s07 - s34;
   1.153 +	ss16s25 = s16 + s25;
   1.154 +	ds16s25 = s16 - s25;
   1.155 +
   1.156 +	OIL_GET(dest,dstr*0,double) = 0.5*C0_7071*(ss07s34 + ss16s25);
   1.157 +	OIL_GET(dest,dstr*2,double) = 0.5*(C0_9239*ds07s34 + C0_3827*ds16s25);
   1.158 +	OIL_GET(dest,dstr*4,double) = 0.5*C0_7071*(ss07s34 - ss16s25);
   1.159 +	OIL_GET(dest,dstr*6,double) = 0.5*(C0_3827*ds07s34 - C0_9239*ds16s25);
   1.160 +
   1.161 +	OIL_GET(dest,dstr*1,double) = 0.5*(C0_9808*d07 + C0_8315*d16
   1.162 +			+ C0_5556*d25 + C0_1951*d34);
   1.163 +	OIL_GET(dest,dstr*3,double) = 0.5*(C0_8315*d07 - C0_1951*d16
   1.164 +			- C0_9808*d25 - C0_5556*d34);
   1.165 +	OIL_GET(dest,dstr*5,double) = 0.5*(C0_5556*d07 - C0_9808*d16
   1.166 +			+ C0_1951*d25 + C0_8315*d34);
   1.167 +	OIL_GET(dest,dstr*7,double) = 0.5*(C0_1951*d07 - C0_5556*d16
   1.168 +			+ C0_8315*d25 - C0_9808*d34);
   1.169 + 
   1.170 +#if 0
   1.171 +	z1 = (ds1  tmp12 + tmp13) * 0.707106781;
   1.172 +	OIL_GET(dest,dstr*2,double) = (tmp13 + z1)*(0.25*M_SQRT2)*0.765366864;
   1.173 +	OIL_GET(dest,dstr*6,double) = (tmp13 - z1)*(0.25*M_SQRT2)*1.847759066;
   1.174 +
   1.175 +	tmp10 = tmp4 + tmp5;
   1.176 +	tmp11 = tmp5 + tmp6;
   1.177 +	tmp12 = tmp6 + tmp7;
   1.178 +
   1.179 +	z5 = (tmp10 - tmp12) * 0.382683433;
   1.180 +	z2 = 0.541196100 * tmp10 + z5;
   1.181 +	z4 = 1.306562965 * tmp12 + z5;
   1.182 +	z3 = tmp11 * 0.707106781;
   1.183 +
   1.184 +	z11 = tmp7 + z3;
   1.185 +	z13 = tmp7 - z3;
   1.186 +
   1.187 +	OIL_GET(dest,dstr*5,double) = (z13 + z2)*(0.25*M_SQRT2)*1.2728;
   1.188 +	OIL_GET(dest,dstr*3,double) = (z13 - z2)*(0.25*M_SQRT2)*0.8504;
   1.189 +	OIL_GET(dest,dstr*1,double) = (z11 + z4)*(0.25*M_SQRT2)*0.7209;
   1.190 +	OIL_GET(dest,dstr*7,double) = (z11 - z4)*(0.25*M_SQRT2)*3.6245;
   1.191 +#endif
   1.192 +}
   1.193 +OIL_DEFINE_IMPL (fdct8_f64_fast, fdct8_f64);
   1.194 +
   1.195 +
   1.196 +
   1.197 +
   1.198 +
   1.199 +
   1.200 +#ifdef	__SYMBIAN32__
   1.201 + 
   1.202 +OilFunctionClass* __oil_function_class_fdct8_f64() {
   1.203 +		return &_oil_function_class_fdct8_f64;
   1.204 +}
   1.205 +#endif
   1.206 +
   1.207 +
   1.208 +
   1.209 +#ifdef	__SYMBIAN32__
   1.210 + 
   1.211 +OilFunctionImpl* __oil_function_impl_fdct8_f64_ref() {
   1.212 +		return &_oil_function_impl_fdct8_f64_ref;
   1.213 +}
   1.214 +#endif
   1.215 +
   1.216 +#ifdef	__SYMBIAN32__
   1.217 + 
   1.218 +OilFunctionImpl* __oil_function_impl_fdct8_f64_fast() {
   1.219 +		return &_oil_function_impl_fdct8_f64_fast;
   1.220 +}
   1.221 +#endif
   1.222 +
   1.223 +
   1.224 +
   1.225 +#ifdef	__SYMBIAN32__
   1.226 + 
   1.227 +EXPORT_C void** _oil_function_class_ptr_fdct8_f64 ()	{
   1.228 +	oil_function_class_ptr_fdct8_f64 = __oil_function_class_fdct8_f64();
   1.229 +	return &oil_function_class_ptr_fdct8_f64->func;
   1.230 +	}
   1.231 +#endif
   1.232 +