os/ossrv/genericopenlibs/liboil/src/dct/idct8x8_c.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/idct8x8_c.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,355 @@
     1.4 +/*
     1.5 + * LIBOIL - Library of Optimized Inner Loops
     1.6 + * Copyright (c) 2001,2002,2003,2004 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/liboil.h>
    1.37 +#include "liboil/dct/dct.h"
    1.38 +#include <math.h>
    1.39 +#include <liboil/liboiltest.h>
    1.40 +#include <liboil/liboilparameter.h>
    1.41 +#include <liboil/liboilrandom.h>
    1.42 +
    1.43 +/**
    1.44 + * SECTION:liboilfuncs-dct:
    1.45 + * @title: Direct Cosine Transform
    1.46 + * @short_description: DCT related functions
    1.47 + */
    1.48 +
    1.49 +#define BLOCK8x8_F64(ptr, stride, row, column) \
    1.50 +	(*((double *)((unsigned char *)ptr + stride*row) + column))
    1.51 +
    1.52 +#define BLOCK8x8_PTR_F64(ptr, stride, row, column) \
    1.53 +	((double *)((unsigned char *)ptr + stride*row) + column)
    1.54 +
    1.55 +#define BLOCK8x8_S16(ptr, stride, row, column) \
    1.56 +	(*((int16_t *)((unsigned char *)ptr + stride*row) + column))
    1.57 +
    1.58 +static void
    1.59 +idct8x8_test (OilTest *test)
    1.60 +{
    1.61 +  int16_t *data = oil_test_get_source_data (test, OIL_ARG_SRC1);
    1.62 +  int stride = oil_test_get_value (test, OIL_ARG_SSTR1);
    1.63 +  int i, j;
    1.64 +
    1.65 +  for(j=0;j<8;j++){
    1.66 +    for(i=0;i<8;i++){
    1.67 +      OIL_GET(data, i*2 + j*stride, int16_t) = (oil_rand_s16() & 0xfff) - 2048;
    1.68 +    }
    1.69 +  }
    1.70 +}
    1.71 +
    1.72 +/**
    1.73 + * oil_idct8x8_f64:
    1.74 + * @d_8x8:
    1.75 + * @dstr:
    1.76 + * @s_8x8:
    1.77 + * @sstr:
    1.78 + *
    1.79 + * Performs a 2-D Inverse Discrete Cosine Transform on @s_8x8 and places
    1.80 + * the result in @d_8x8.
    1.81 + */
    1.82 +OIL_DEFINE_CLASS (idct8x8_f64, "double *d_8x8, int dstr, double *s_8x8, int sstr");
    1.83 +/**
    1.84 + * oil_idct8x8lim10_f64:
    1.85 + * @d_8x8:
    1.86 + * @dstr:
    1.87 + * @s_8x8:
    1.88 + * @sstr:
    1.89 + *
    1.90 + * Performs a 2-D Inverse Discrete Cosine Transform on @s_8x8 and places
    1.91 + * the result in @d_8x8.
    1.92 + */
    1.93 +OIL_DEFINE_CLASS (idct8x8lim10_f64, "double *d_8x8, int dstr, double *s_8x8, int sstr");
    1.94 +/**
    1.95 + * oil_idct8x8_s16:
    1.96 + * @d_8x8:
    1.97 + * @dstr:
    1.98 + * @s_8x8:
    1.99 + * @sstr:
   1.100 + *
   1.101 + * Performs a limited 2-D Inverse Discrete Cosine Transform on @s_8x8
   1.102 + * and places the result in @d_8x8.
   1.103 + */
   1.104 +OIL_DEFINE_CLASS_FULL (idct8x8_s16, "int16_t *d_8x8, int dstr, int16_t *s_8x8, int sstr", idct8x8_test);
   1.105 +/**
   1.106 + * oil_idct8x8lim10_s16:
   1.107 + * @d_8x8:
   1.108 + * @dstr:
   1.109 + * @s_8x8:
   1.110 + * @sstr:
   1.111 + *
   1.112 + * Performs a limited 2-D Inverse Discrete Cosine Transform on @s_8x8
   1.113 + * and places the result in @d_8x8.  The source 8x8 block must be non-zero
   1.114 + * only in the 10 lowest-order components.
   1.115 + */
   1.116 +OIL_DEFINE_CLASS (idct8x8lim10_s16, "int16_t *d_8x8, int dstr, int16_t *s_8x8, int sstr");
   1.117 +
   1.118 +static void
   1.119 +idct8x8_f64_ref (double *dest, int dstr, const double *src, int sstr)
   1.120 +{
   1.121 +	static double idct_coeff[8][8];
   1.122 +	static int idct_coeff_init = 0;
   1.123 +	int i,j,k,l;
   1.124 +	double tmp1,tmp2;
   1.125 +
   1.126 +	if(!idct_coeff_init){
   1.127 +		double scale;
   1.128 +
   1.129 +		for(i=0;i<8;i++){
   1.130 +			scale = (i==0) ? sqrt(0.125) : 0.5;
   1.131 +			for(j=0;j<8;j++){
   1.132 +				idct_coeff[j][i] = scale *
   1.133 +					cos((M_PI/8)*i*(j+0.5));
   1.134 +			}
   1.135 +		}
   1.136 +		idct_coeff_init = 1;
   1.137 +	}
   1.138 +
   1.139 +	for(i=0;i<8;i++){
   1.140 +		for(j=0;j<8;j++){
   1.141 +			tmp1 = 0;
   1.142 +			for(k=0;k<8;k++){
   1.143 +				tmp2 = 0;
   1.144 +				for(l=0;l<8;l++){
   1.145 +					tmp2 += idct_coeff[j][l] *
   1.146 +						BLOCK8x8_F64(src,sstr,k,l);
   1.147 +				}
   1.148 +				tmp1 += idct_coeff[i][k] * tmp2;
   1.149 +			}
   1.150 +			BLOCK8x8_F64(dest,dstr,i,j) = tmp1;
   1.151 +		}
   1.152 +	}
   1.153 +}
   1.154 +OIL_DEFINE_IMPL_REF (idct8x8_f64_ref, idct8x8_f64);
   1.155 +
   1.156 +static void
   1.157 +idct8x8lim10_f64_ref (double *dest, int dstr, const double *src, int sstr)
   1.158 +{
   1.159 +	static double idct_coeff[8][8];
   1.160 +	static int idct_coeff_init = 0;
   1.161 +	int i,j,k,l;
   1.162 +	double tmp1,tmp2;
   1.163 +
   1.164 +	if(!idct_coeff_init){
   1.165 +		double scale;
   1.166 +
   1.167 +		for(i=0;i<8;i++){
   1.168 +			scale = (i==0) ? sqrt(0.125) : 0.5;
   1.169 +			for(j=0;j<8;j++){
   1.170 +				idct_coeff[j][i] = scale *
   1.171 +					cos((M_PI/8)*i*(j+0.5));
   1.172 +			}
   1.173 +		}
   1.174 +		idct_coeff_init = 1;
   1.175 +	}
   1.176 +
   1.177 +	for(i=0;i<8;i++){
   1.178 +		for(j=0;j<8;j++){
   1.179 +			tmp1 = 0;
   1.180 +			for(k=0;k<4;k++){
   1.181 +				tmp2 = 0;
   1.182 +				for(l=0;l<4;l++){
   1.183 +					tmp2 += idct_coeff[j][l] *
   1.184 +						BLOCK8x8_F64(src,sstr,k,l);
   1.185 +				}
   1.186 +				tmp1 += idct_coeff[i][k] * tmp2;
   1.187 +			}
   1.188 +			BLOCK8x8_F64(dest,dstr,i,j) = tmp1;
   1.189 +		}
   1.190 +	}
   1.191 +}
   1.192 +OIL_DEFINE_IMPL_REF (idct8x8lim10_f64_ref, idct8x8lim10_f64);
   1.193 +
   1.194 +#if defined(oil_idct8_f64)
   1.195 +static void
   1.196 +idct8x8_f64_c (double *dest, int dstr, const double *src, int sstr)
   1.197 +{
   1.198 +	int i;
   1.199 +	double tmp[64];
   1.200 +	int tmpstr = 8*sizeof(double);
   1.201 +
   1.202 +	for(i=0;i<8;i++){
   1.203 +		oil_idct8_f64(
   1.204 +			BLOCK8x8_PTR_F64(tmp,tmpstr,i,0), sizeof(double),
   1.205 +			BLOCK8x8_PTR_F64(src,sstr,i,0), sizeof(double));
   1.206 +	}
   1.207 +	for(i=0;i<8;i++){
   1.208 +		oil_idct8_f64(
   1.209 +			BLOCK8x8_PTR_F64(dest,dstr,0,i), dstr,
   1.210 +			BLOCK8x8_PTR_F64(tmp,tmpstr,0,i), tmpstr);
   1.211 +	}
   1.212 +}
   1.213 +
   1.214 +OIL_DEFINE_IMPL_DEPENDS (idct8x8_f64_c, idct8x8_f64, idct8_f64);
   1.215 +#endif
   1.216 +
   1.217 +#if defined(oil_conv8x8_f64_s16) && defined(oil_idct8x8_f64) && \
   1.218 +    defined(oil_conv8x8_s16_f64)
   1.219 +static void
   1.220 +idct8x8_s16_ref (int16_t *dest, int dstr, const int16_t *src, int sstr)
   1.221 +{
   1.222 +	double s[64], d[64];
   1.223 +
   1.224 +	oil_conv8x8_f64_s16 (s,8*sizeof(double),src,sstr);
   1.225 +	oil_idct8x8_f64 (d,8*sizeof(double),s,8*sizeof(double));
   1.226 +	oil_conv8x8_s16_f64 (dest,dstr,d,8*sizeof(double));
   1.227 +}
   1.228 +
   1.229 +OIL_DEFINE_IMPL_REF (idct8x8_s16_ref, idct8x8_s16);
   1.230 +#if 0
   1.231 +OIL_DEFINE_IMPL_DEPENDS (idct8x8_s16_ref, idct8x8_s16,
   1.232 +    conv8x8_f64_s16, idct8x8_f64, conv8x8_s16_f64);
   1.233 +#endif
   1.234 +#endif
   1.235 +
   1.236 +#if defined(oil_conv8x8_f64_s16) && defined(oil_idct8x8lim10_f64) && \
   1.237 +    defined(oil_conv8x8_s16_f64)
   1.238 +static void
   1.239 +idct8x8lim10_s16_ref (int16_t *dest, int dstr, const int16_t *src, int sstr)
   1.240 +{
   1.241 +	double s[64], d[64];
   1.242 +
   1.243 +	oil_conv8x8_f64_s16 (s,8*sizeof(double),src,sstr);
   1.244 +	oil_idct8x8lim10_f64 (d,8*sizeof(double),s,8*sizeof(double));
   1.245 +	oil_conv8x8_s16_f64 (dest,dstr,d,8*sizeof(double));
   1.246 +}
   1.247 +
   1.248 +OIL_DEFINE_IMPL_REF (idct8x8lim10_s16_ref, idct8x8lim10_s16);
   1.249 +#if 0
   1.250 +OIL_DEFINE_IMPL_DEPENDS (idct8x8_s16_ref, idct8x8_s16,
   1.251 +    conv8x8_f64_s16, idct8x8_f64, conv8x8_s16_f64);
   1.252 +#endif
   1.253 +#endif
   1.254 +
   1.255 +
   1.256 +
   1.257 +#ifdef	__SYMBIAN32__
   1.258 + 
   1.259 +OilFunctionClass* __oil_function_class_idct8x8_f64() {
   1.260 +		return &_oil_function_class_idct8x8_f64;
   1.261 +}
   1.262 +#endif
   1.263 +
   1.264 +#ifdef	__SYMBIAN32__
   1.265 + 
   1.266 +OilFunctionClass* __oil_function_class_idct8x8lim10_f64() {
   1.267 +		return &_oil_function_class_idct8x8lim10_f64;
   1.268 +}
   1.269 +#endif
   1.270 +
   1.271 +#ifdef	__SYMBIAN32__
   1.272 + 
   1.273 +OilFunctionClass* __oil_function_class_idct8x8_s16() {
   1.274 +		return &_oil_function_class_idct8x8_s16;
   1.275 +}
   1.276 +#endif
   1.277 +
   1.278 +#ifdef	__SYMBIAN32__
   1.279 + 
   1.280 +OilFunctionClass* __oil_function_class_idct8x8lim10_s16() {
   1.281 +		return &_oil_function_class_idct8x8lim10_s16;
   1.282 +}
   1.283 +#endif
   1.284 +
   1.285 +
   1.286 +
   1.287 +#ifdef	__SYMBIAN32__
   1.288 + 
   1.289 +OilFunctionImpl* __oil_function_impl_idct8x8_f64_ref() {
   1.290 +		return &_oil_function_impl_idct8x8_f64_ref;
   1.291 +}
   1.292 +#endif
   1.293 +
   1.294 +#ifdef	__SYMBIAN32__
   1.295 + 
   1.296 +OilFunctionImpl* __oil_function_impl_idct8x8lim10_f64_ref() {
   1.297 +		return &_oil_function_impl_idct8x8lim10_f64_ref;
   1.298 +}
   1.299 +#endif
   1.300 +
   1.301 +#ifdef	__SYMBIAN32__
   1.302 + 
   1.303 +OilFunctionImpl* __oil_function_impl_idct8x8_s16_ref() {
   1.304 +		return &_oil_function_impl_idct8x8_s16_ref;
   1.305 +}
   1.306 +#endif
   1.307 +
   1.308 +#ifdef	__SYMBIAN32__
   1.309 + 
   1.310 +OilFunctionImpl* __oil_function_impl_idct8x8lim10_s16_ref() {
   1.311 +		return &_oil_function_impl_idct8x8lim10_s16_ref;
   1.312 +}
   1.313 +#endif
   1.314 +
   1.315 +
   1.316 +
   1.317 +#ifdef	__SYMBIAN32__
   1.318 + 
   1.319 +OilFunctionImpl* __oil_function_impl_idct8x8_f64_c() {
   1.320 +		return &_oil_function_impl_idct8x8_f64_c;
   1.321 +}
   1.322 +#endif
   1.323 +
   1.324 +
   1.325 +
   1.326 +
   1.327 +#ifdef	__SYMBIAN32__
   1.328 + 
   1.329 +EXPORT_C void** _oil_function_class_ptr_idct8x8_f64 ()	{
   1.330 +	oil_function_class_ptr_idct8x8_f64 = __oil_function_class_idct8x8_f64();
   1.331 +	return &oil_function_class_ptr_idct8x8_f64->func;
   1.332 +	}
   1.333 +#endif
   1.334 +
   1.335 +#ifdef	__SYMBIAN32__
   1.336 + 
   1.337 +EXPORT_C void** _oil_function_class_ptr_idct8x8lim10_f64 ()	{
   1.338 +	oil_function_class_ptr_idct8x8lim10_f64 = __oil_function_class_idct8x8lim10_f64();
   1.339 +	return &oil_function_class_ptr_idct8x8lim10_f64->func;
   1.340 +	}
   1.341 +#endif
   1.342 +
   1.343 +#ifdef	__SYMBIAN32__
   1.344 + 
   1.345 +EXPORT_C void** _oil_function_class_ptr_idct8x8_s16 ()	{
   1.346 +	oil_function_class_ptr_idct8x8_s16 = __oil_function_class_idct8x8_s16();
   1.347 +	return &oil_function_class_ptr_idct8x8_s16->func;
   1.348 +	}
   1.349 +#endif
   1.350 +
   1.351 +#ifdef	__SYMBIAN32__
   1.352 + 
   1.353 +EXPORT_C void** _oil_function_class_ptr_idct8x8lim10_s16 ()	{
   1.354 +	oil_function_class_ptr_idct8x8lim10_s16 = __oil_function_class_idct8x8lim10_s16();
   1.355 +	return &oil_function_class_ptr_idct8x8lim10_s16->func;
   1.356 +	}
   1.357 +#endif
   1.358 +