os/ossrv/genericopenlibs/liboil/src/dct/fdct8x8_f64.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2  * LIBOIL - Library of Optimized Inner Loops
     3  * Copyright (c) 2003,2004 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/liboilfuncs.h>
    35 #include "liboil/dct/dct.h"
    36 #include <math.h>
    37 
    38 
    39 /**
    40  * oil_fdct8x8_f64:
    41  * @d_8x8:
    42  * @dstr:
    43  * @s_8x8:
    44  * @sstr:
    45  *
    46  * Performs a 2-D Forward Discrete Cosine Transform on @s_8x8 and places
    47  * the result in @d_8x8.
    48  */
    49 OIL_DEFINE_CLASS(fdct8x8_f64,
    50     "double *d_8x8, int dstr, double *s_8x8, int sstr");
    51 
    52 
    53 static void
    54 fdct8x8_f64_ref(double *dest, int dstr, const double *src, int sstr)
    55 {
    56 	static double fdct_coeff[8][8];
    57 	static int fdct_coeff_init = 0;
    58 	int i,j,k,l;
    59 	double tmp1,tmp2;
    60 
    61 	if(!fdct_coeff_init){
    62 		double scale;
    63 
    64 		for(i=0;i<8;i++){
    65 			scale = (i==0) ? sqrt(0.125) : 0.5;
    66 			for(j=0;j<8;j++){
    67 				fdct_coeff[j][i] = scale *
    68 					cos((M_PI/8)*i*(j+0.5));
    69 			}
    70 		}
    71 		fdct_coeff_init = 1;
    72 	}
    73 
    74 	for(i=0;i<8;i++){
    75 		for(j=0;j<8;j++){
    76 			tmp1 = 0;
    77 			for(k=0;k<8;k++){
    78 				tmp2 = 0;
    79 				for(l=0;l<8;l++){
    80 					tmp2 += fdct_coeff[l][j] *
    81 					  OIL_GET (src, sstr*k + l * sizeof(double),
    82                                               double);
    83 				}
    84 				tmp1 += fdct_coeff[k][i] * tmp2;
    85 			}
    86 			OIL_GET (dest, dstr*i + j*sizeof(double), double) =
    87                           tmp1;
    88 		}
    89 	}
    90 }
    91 
    92 OIL_DEFINE_IMPL_REF (fdct8x8_f64_ref, fdct8x8_f64);
    93 
    94 static void
    95 fdct8x8_f64_ref2(double *dest, int dstr, const double *src, int sstr)
    96 {
    97 	static double fdct_coeff[8][8];
    98 	static int fdct_coeff_init = 0;
    99 	int i,j,k;
   100 	double x;
   101 	double tmp[64];
   102 
   103 	if(!fdct_coeff_init){
   104 		double scale;
   105 
   106 		for(i=0;i<8;i++){
   107 			scale = (i==0) ? sqrt(0.125) : 0.5;
   108 			for(j=0;j<8;j++){
   109 				fdct_coeff[j][i] = scale *
   110 					cos((M_PI/8)*i*(j+0.5));
   111 			}
   112 		}
   113 		fdct_coeff_init = 1;
   114 	}
   115 
   116 	for(i=0;i<8;i++){
   117 		for(j=0;j<8;j++){
   118 			x = 0;
   119 			for(k=0;k<8;k++){
   120 				x += fdct_coeff[k][j] *
   121 				  OIL_GET (src, sstr*i + k * sizeof(double), double);
   122 			}
   123 			tmp[8*i+j] = x;
   124 		}
   125 	}
   126 
   127 	for(j=0;j<8;j++){
   128 		for(i=0;i<8;i++){
   129 			x = 0;
   130 			for(k=0;k<8;k++){
   131 				x += fdct_coeff[k][i] * tmp[8*k + j];
   132 			}
   133 			OIL_GET (dest,dstr*i+j*sizeof(double), double) = x;
   134 		}
   135 	}
   136 }
   137 
   138 OIL_DEFINE_IMPL (fdct8x8_f64_ref2, fdct8x8_f64);
   139 
   140 #ifdef oil_fdct8_f64
   141 static void
   142 fdct8x8_f64_1d (double *dest, int dstr, const double *src, int sstr)
   143 {
   144 	int i;
   145 	double tmp[64];
   146 
   147 	for(i=0;i<8;i++){
   148 		oil_fdct8_f64(tmp + i*8, OIL_OFFSET(src,sstr*i),
   149                     sizeof (double), sizeof(double));
   150 	}
   151 
   152 	for(i=0;i<8;i++){
   153 		oil_fdct8_f64(dest + i, tmp + i,
   154                     dstr, 8*sizeof(double));
   155 	}
   156 }
   157 OIL_DEFINE_IMPL (fdct8x8_f64_1d, fdct8x8_f64);
   158 #endif
   159 
   160 
   161 
   162 
   163 #ifdef	__SYMBIAN32__
   164  
   165 OilFunctionClass* __oil_function_class_fdct8x8_f64() {
   166 		return &_oil_function_class_fdct8x8_f64;
   167 }
   168 #endif
   169 
   170 
   171 
   172 #ifdef	__SYMBIAN32__
   173  
   174 OilFunctionImpl* __oil_function_impl_fdct8x8_f64_ref() {
   175 		return &_oil_function_impl_fdct8x8_f64_ref;
   176 }
   177 #endif
   178 
   179 #ifdef	__SYMBIAN32__
   180  
   181 OilFunctionImpl* __oil_function_impl_fdct8x8_f64_ref2() {
   182 		return &_oil_function_impl_fdct8x8_f64_ref2;
   183 }
   184 #endif
   185 
   186 #ifdef	__SYMBIAN32__
   187  
   188 OilFunctionImpl* __oil_function_impl_fdct8x8_f64_1d() {
   189 		return &_oil_function_impl_fdct8x8_f64_1d;
   190 }
   191 #endif
   192 
   193 
   194 
   195 #ifdef	__SYMBIAN32__
   196  
   197 EXPORT_C void** _oil_function_class_ptr_fdct8x8_f64 ()	{
   198 	oil_function_class_ptr_fdct8x8_f64 = __oil_function_class_fdct8x8_f64();
   199 	return &oil_function_class_ptr_fdct8x8_f64->func;
   200 	}
   201 #endif
   202