1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/dct/fdct8x8theora.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,334 @@
1.4 +/*
1.5 + * LIBOIL - Library of Optimized Inner Loops
1.6 + * Copyright (c) 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 +
1.31 +/********************************************************************
1.32 + * *
1.33 + * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
1.34 + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
1.35 + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
1.36 + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
1.37 + * *
1.38 + * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2003 *
1.39 + * by the Xiph.Org Foundation http://www.xiph.org/ *
1.40 + * *
1.41 + ********************************************************************
1.42 +
1.43 + function:
1.44 + last mod: $Id: fdct8x8theora.c,v 1.3 2005-12-16 17:30:40 ds Exp $
1.45 +
1.46 + ********************************************************************/
1.47 +//Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.48 +
1.49 +#ifdef HAVE_CONFIG_H
1.50 +#include "config.h"
1.51 +#endif
1.52 +
1.53 +#include <liboil/liboilfunction.h>
1.54 +#include <liboil/liboilfuncs.h>
1.55 +#include "liboil/dct/dct.h"
1.56 +#include <math.h>
1.57 +
1.58 +static int32_t xC1S7 = 64277;
1.59 +static int32_t xC2S6 = 60547;
1.60 +static int32_t xC3S5 = 54491;
1.61 +static int32_t xC4S4 = 46341;
1.62 +static int32_t xC5S3 = 36410;
1.63 +static int32_t xC6S2 = 25080;
1.64 +static int32_t xC7S1 = 12785;
1.65 +
1.66 +#define SIGNBITDUPPED(X) ((signed )(((X) & 0x80000000)) >> 31)
1.67 +#define DOROUND(X) ( (SIGNBITDUPPED(X) & (0xffff)) + (X) )
1.68 +
1.69 +/**
1.70 + * oil_fdct8x8theora:
1.71 + * @s_8x8:
1.72 + * @d_8x8:
1.73 + *
1.74 + * Calculates the FDCT transformation of @s_8x8 according to the Theora
1.75 + * specification and places the result in @d_8x8.
1.76 + *
1.77 + * Note that the source and destination arrays are reversed compared
1.78 + * to normal Liboil order.
1.79 + */
1.80 +OIL_DEFINE_CLASS(fdct8x8theora, "int16_t *s_8x8, int16_t *d_8x8");
1.81 +
1.82 +static void
1.83 +fdct8x8theora_ref(const int16_t *src, int16_t *dest)
1.84 +{
1.85 + int loop;
1.86 +
1.87 + int32_t is07, is12, is34, is56;
1.88 + int32_t is0734, is1256;
1.89 + int32_t id07, id12, id34, id56;
1.90 +
1.91 + int32_t irot_input_x, irot_input_y;
1.92 + int32_t icommon_product1; /* Re-used product (c4s4 * (s12 - s56)). */
1.93 + int32_t icommon_product2; /* Re-used product (c4s4 * (d12 + d56)). */
1.94 +
1.95 + int32_t temp1, temp2; /* intermediate variable for computation */
1.96 +
1.97 + int32_t InterData[64];
1.98 + int32_t *ip = InterData;
1.99 + int16_t * op = dest;
1.100 + for (loop = 0; loop < 8; loop++){
1.101 + /* Pre calculate some common sums and differences. */
1.102 + is07 = src[0] + src[7];
1.103 + is12 = src[1] + src[2];
1.104 + is34 = src[3] + src[4];
1.105 + is56 = src[5] + src[6];
1.106 +
1.107 + id07 = src[0] - src[7];
1.108 + id12 = src[1] - src[2];
1.109 + id34 = src[3] - src[4];
1.110 + id56 = src[5] - src[6];
1.111 +
1.112 + is0734 = is07 + is34;
1.113 + is1256 = is12 + is56;
1.114 +
1.115 + /* Pre-Calculate some common product terms. */
1.116 + icommon_product1 = xC4S4*(is12 - is56);
1.117 + icommon_product1 = DOROUND(icommon_product1);
1.118 + icommon_product1>>=16;
1.119 +
1.120 + icommon_product2 = xC4S4*(id12 + id56);
1.121 + icommon_product2 = DOROUND(icommon_product2);
1.122 + icommon_product2>>=16;
1.123 +
1.124 +
1.125 + ip[0] = (xC4S4*(is0734 + is1256));
1.126 + ip[0] = DOROUND(ip[0]);
1.127 + ip[0] >>= 16;
1.128 +
1.129 + ip[4] = (xC4S4*(is0734 - is1256));
1.130 + ip[4] = DOROUND(ip[4]);
1.131 + ip[4] >>= 16;
1.132 +
1.133 + /* Define inputs to rotation for outputs 2 and 6 */
1.134 + irot_input_x = id12 - id56;
1.135 + irot_input_y = is07 - is34;
1.136 +
1.137 + /* Apply rotation for outputs 2 and 6. */
1.138 + temp1=xC6S2*irot_input_x;
1.139 + temp1=DOROUND(temp1);
1.140 + temp1>>=16;
1.141 + temp2=xC2S6*irot_input_y;
1.142 + temp2=DOROUND(temp2);
1.143 + temp2>>=16;
1.144 + ip[2] = temp1 + temp2;
1.145 +
1.146 + temp1=xC6S2*irot_input_y;
1.147 + temp1=DOROUND(temp1);
1.148 + temp1>>=16;
1.149 + temp2=xC2S6*irot_input_x ;
1.150 + temp2=DOROUND(temp2);
1.151 + temp2>>=16;
1.152 + ip[6] = temp1 -temp2 ;
1.153 +
1.154 + /* Define inputs to rotation for outputs 1 and 7 */
1.155 + irot_input_x = icommon_product1 + id07;
1.156 + irot_input_y = -( id34 + icommon_product2 );
1.157 +
1.158 + /* Apply rotation for outputs 1 and 7. */
1.159 +
1.160 + temp1=xC1S7*irot_input_x;
1.161 + temp1=DOROUND(temp1);
1.162 + temp1>>=16;
1.163 + temp2=xC7S1*irot_input_y;
1.164 + temp2=DOROUND(temp2);
1.165 + temp2>>=16;
1.166 + ip[1] = temp1 - temp2;
1.167 +
1.168 + temp1=xC7S1*irot_input_x;
1.169 + temp1=DOROUND(temp1);
1.170 + temp1>>=16;
1.171 + temp2=xC1S7*irot_input_y ;
1.172 + temp2=DOROUND(temp2);
1.173 + temp2>>=16;
1.174 + ip[7] = temp1 + temp2 ;
1.175 +
1.176 + /* Define inputs to rotation for outputs 3 and 5 */
1.177 + irot_input_x = id07 - icommon_product1;
1.178 + irot_input_y = id34 - icommon_product2;
1.179 +
1.180 + /* Apply rotation for outputs 3 and 5. */
1.181 + temp1=xC3S5*irot_input_x;
1.182 + temp1=DOROUND(temp1);
1.183 + temp1>>=16;
1.184 + temp2=xC5S3*irot_input_y ;
1.185 + temp2=DOROUND(temp2);
1.186 + temp2>>=16;
1.187 + ip[3] = temp1 - temp2 ;
1.188 +
1.189 + temp1=xC5S3*irot_input_x;
1.190 + temp1=DOROUND(temp1);
1.191 + temp1>>=16;
1.192 + temp2=xC3S5*irot_input_y;
1.193 + temp2=DOROUND(temp2);
1.194 + temp2>>=16;
1.195 + ip[5] = temp1 + temp2;
1.196 +
1.197 + /* Increment data pointer for next row. */
1.198 + src += 8 ;
1.199 + ip += 8; /* advance pointer to next row */
1.200 +
1.201 + }
1.202 +
1.203 +
1.204 + /* Performed DCT on rows, now transform the columns */
1.205 + ip = InterData;
1.206 + for (loop = 0; loop < 8; loop++){
1.207 + /* Pre calculate some common sums and differences. */
1.208 + is07 = ip[0 * 8] + ip[7 * 8];
1.209 + is12 = ip[1 * 8] + ip[2 * 8];
1.210 + is34 = ip[3 * 8] + ip[4 * 8];
1.211 + is56 = ip[5 * 8] + ip[6 * 8];
1.212 +
1.213 + id07 = ip[0 * 8] - ip[7 * 8];
1.214 + id12 = ip[1 * 8] - ip[2 * 8];
1.215 + id34 = ip[3 * 8] - ip[4 * 8];
1.216 + id56 = ip[5 * 8] - ip[6 * 8];
1.217 +
1.218 + is0734 = is07 + is34;
1.219 + is1256 = is12 + is56;
1.220 +
1.221 + /* Pre-Calculate some common product terms. */
1.222 + icommon_product1 = xC4S4*(is12 - is56) ;
1.223 + icommon_product2 = xC4S4*(id12 + id56) ;
1.224 + icommon_product1 = DOROUND(icommon_product1);
1.225 + icommon_product2 = DOROUND(icommon_product2);
1.226 + icommon_product1>>=16;
1.227 + icommon_product2>>=16;
1.228 +
1.229 +
1.230 + temp1 = xC4S4*(is0734 + is1256) ;
1.231 + temp2 = xC4S4*(is0734 - is1256) ;
1.232 + temp1 = DOROUND(temp1);
1.233 + temp2 = DOROUND(temp2);
1.234 + temp1>>=16;
1.235 + temp2>>=16;
1.236 + op[0*8] = (int16_t) temp1;
1.237 + op[4*8] = (int16_t) temp2;
1.238 +
1.239 + /* Define inputs to rotation for outputs 2 and 6 */
1.240 + irot_input_x = id12 - id56;
1.241 + irot_input_y = is07 - is34;
1.242 +
1.243 + /* Apply rotation for outputs 2 and 6. */
1.244 + temp1=xC6S2*irot_input_x;
1.245 + temp1=DOROUND(temp1);
1.246 + temp1>>=16;
1.247 + temp2=xC2S6*irot_input_y;
1.248 + temp2=DOROUND(temp2);
1.249 + temp2>>=16;
1.250 + op[2*8] = (int16_t) (temp1 + temp2);
1.251 +
1.252 + temp1=xC6S2*irot_input_y;
1.253 + temp1=DOROUND(temp1);
1.254 + temp1>>=16;
1.255 + temp2=xC2S6*irot_input_x ;
1.256 + temp2=DOROUND(temp2);
1.257 + temp2>>=16;
1.258 + op[6*8] = (int16_t) (temp1 -temp2) ;
1.259 +
1.260 + /* Define inputs to rotation for outputs 1 and 7 */
1.261 + irot_input_x = icommon_product1 + id07;
1.262 + irot_input_y = -( id34 + icommon_product2 );
1.263 +
1.264 + /* Apply rotation for outputs 1 and 7. */
1.265 + temp1=xC1S7*irot_input_x;
1.266 + temp1=DOROUND(temp1);
1.267 + temp1>>=16;
1.268 + temp2=xC7S1*irot_input_y;
1.269 + temp2=DOROUND(temp2);
1.270 + temp2>>=16;
1.271 + op[1*8] = (int16_t) (temp1 - temp2);
1.272 +
1.273 + temp1=xC7S1*irot_input_x;
1.274 + temp1=DOROUND(temp1);
1.275 + temp1>>=16;
1.276 + temp2=xC1S7*irot_input_y ;
1.277 + temp2=DOROUND(temp2);
1.278 + temp2>>=16;
1.279 + op[7*8] = (int16_t) (temp1 + temp2);
1.280 +
1.281 + /* Define inputs to rotation for outputs 3 and 5 */
1.282 + irot_input_x = id07 - icommon_product1;
1.283 + irot_input_y = id34 - icommon_product2;
1.284 +
1.285 + /* Apply rotation for outputs 3 and 5. */
1.286 + temp1=xC3S5*irot_input_x;
1.287 + temp1=DOROUND(temp1);
1.288 + temp1>>=16;
1.289 + temp2=xC5S3*irot_input_y ;
1.290 + temp2=DOROUND(temp2);
1.291 + temp2>>=16;
1.292 + op[3*8] = (int16_t) (temp1 - temp2) ;
1.293 +
1.294 + temp1=xC5S3*irot_input_x;
1.295 + temp1=DOROUND(temp1);
1.296 + temp1>>=16;
1.297 + temp2=xC3S5*irot_input_y;
1.298 + temp2=DOROUND(temp2);
1.299 + temp2>>=16;
1.300 + op[5*8] = (int16_t) (temp1 + temp2);
1.301 +
1.302 + /* Increment data pointer for next column. */
1.303 + ip ++;
1.304 + op ++;
1.305 + }
1.306 +}
1.307 +
1.308 +OIL_DEFINE_IMPL_REF (fdct8x8theora_ref, fdct8x8theora);
1.309 +
1.310 +
1.311 +
1.312 +#ifdef __SYMBIAN32__
1.313 +
1.314 +OilFunctionClass* __oil_function_class_fdct8x8theora() {
1.315 + return &_oil_function_class_fdct8x8theora;
1.316 +}
1.317 +#endif
1.318 +
1.319 +
1.320 +
1.321 +#ifdef __SYMBIAN32__
1.322 +
1.323 +OilFunctionImpl* __oil_function_impl_fdct8x8theora_ref() {
1.324 + return &_oil_function_impl_fdct8x8theora_ref;
1.325 +}
1.326 +#endif
1.327 +
1.328 +
1.329 +
1.330 +#ifdef __SYMBIAN32__
1.331 +
1.332 +EXPORT_C void** _oil_function_class_ptr_fdct8x8theora () {
1.333 + oil_function_class_ptr_fdct8x8theora = __oil_function_class_fdct8x8theora();
1.334 + return &oil_function_class_ptr_fdct8x8theora->func;
1.335 + }
1.336 +#endif
1.337 +