os/ossrv/genericopenlibs/liboil/src/dct/fdct8x8theora.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 
    28 /********************************************************************
    29  *                                                                  *
    30  * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE.   *
    31  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
    32  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
    33  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
    34  *                                                                  *
    35  * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2003                *
    36  * by the Xiph.Org Foundation http://www.xiph.org/                  *
    37  *                                                                  *
    38  ********************************************************************
    39 
    40   function:
    41   last mod: $Id: fdct8x8theora.c,v 1.3 2005-12-16 17:30:40 ds Exp $
    42 
    43  ********************************************************************/
    44 //Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
    45 
    46 #ifdef HAVE_CONFIG_H
    47 #include "config.h"
    48 #endif
    49 
    50 #include <liboil/liboilfunction.h>
    51 #include <liboil/liboilfuncs.h>
    52 #include "liboil/dct/dct.h"
    53 #include <math.h>
    54 
    55 static int32_t xC1S7 = 64277;
    56 static int32_t xC2S6 = 60547;
    57 static int32_t xC3S5 = 54491;
    58 static int32_t xC4S4 = 46341;
    59 static int32_t xC5S3 = 36410;
    60 static int32_t xC6S2 = 25080;
    61 static int32_t xC7S1 = 12785;
    62 
    63 #define SIGNBITDUPPED(X) ((signed )(((X) & 0x80000000)) >> 31)
    64 #define DOROUND(X) ( (SIGNBITDUPPED(X) & (0xffff)) + (X) )
    65 
    66 /**
    67  * oil_fdct8x8theora:
    68  * @s_8x8:
    69  * @d_8x8:
    70  *
    71  * Calculates the FDCT transformation of @s_8x8 according to the Theora
    72  * specification and places the result in @d_8x8.
    73  *
    74  * Note that the source and destination arrays are reversed compared
    75  * to normal Liboil order.
    76  */
    77 OIL_DEFINE_CLASS(fdct8x8theora, "int16_t *s_8x8, int16_t *d_8x8");
    78 
    79 static void
    80 fdct8x8theora_ref(const int16_t *src, int16_t *dest)
    81 {
    82   int loop;
    83 
    84   int32_t  is07, is12, is34, is56;
    85   int32_t  is0734, is1256;
    86   int32_t  id07, id12, id34, id56;
    87 
    88   int32_t  irot_input_x, irot_input_y;
    89   int32_t  icommon_product1;   /* Re-used product  (c4s4 * (s12 - s56)). */
    90   int32_t  icommon_product2;   /* Re-used product  (c4s4 * (d12 + d56)). */
    91 
    92   int32_t  temp1, temp2;         /* intermediate variable for computation */
    93 
    94   int32_t  InterData[64];
    95   int32_t *ip = InterData;
    96   int16_t * op = dest;
    97   for (loop = 0; loop < 8; loop++){
    98     /* Pre calculate some common sums and differences. */
    99     is07 = src[0] + src[7];
   100     is12 = src[1] + src[2];
   101     is34 = src[3] + src[4];
   102     is56 = src[5] + src[6];
   103 
   104     id07 = src[0] - src[7];
   105     id12 = src[1] - src[2];
   106     id34 = src[3] - src[4];
   107     id56 = src[5] - src[6];
   108 
   109     is0734 = is07 + is34;
   110     is1256 = is12 + is56;
   111 
   112     /* Pre-Calculate some common product terms. */
   113     icommon_product1 = xC4S4*(is12 - is56);
   114     icommon_product1 = DOROUND(icommon_product1);
   115     icommon_product1>>=16;
   116 
   117     icommon_product2 = xC4S4*(id12 + id56);
   118     icommon_product2 = DOROUND(icommon_product2);
   119     icommon_product2>>=16;
   120 
   121 
   122     ip[0] = (xC4S4*(is0734 + is1256));
   123     ip[0] = DOROUND(ip[0]);
   124     ip[0] >>= 16;
   125 
   126     ip[4] = (xC4S4*(is0734 - is1256));
   127     ip[4] = DOROUND(ip[4]);
   128     ip[4] >>= 16;
   129 
   130     /* Define inputs to rotation for outputs 2 and 6 */
   131     irot_input_x = id12 - id56;
   132     irot_input_y = is07 - is34;
   133 
   134     /* Apply rotation for outputs 2 and 6.  */
   135     temp1=xC6S2*irot_input_x;
   136     temp1=DOROUND(temp1);
   137     temp1>>=16;
   138     temp2=xC2S6*irot_input_y;
   139     temp2=DOROUND(temp2);
   140     temp2>>=16;
   141     ip[2] = temp1 + temp2;
   142 
   143     temp1=xC6S2*irot_input_y;
   144     temp1=DOROUND(temp1);
   145     temp1>>=16;
   146     temp2=xC2S6*irot_input_x ;
   147     temp2=DOROUND(temp2);
   148     temp2>>=16;
   149     ip[6] = temp1 -temp2 ;
   150 
   151     /* Define inputs to rotation for outputs 1 and 7  */
   152     irot_input_x = icommon_product1 + id07;
   153     irot_input_y = -( id34 + icommon_product2 );
   154 
   155     /* Apply rotation for outputs 1 and 7.  */
   156 
   157     temp1=xC1S7*irot_input_x;
   158     temp1=DOROUND(temp1);
   159     temp1>>=16;
   160     temp2=xC7S1*irot_input_y;
   161     temp2=DOROUND(temp2);
   162     temp2>>=16;
   163     ip[1] = temp1 - temp2;
   164 
   165     temp1=xC7S1*irot_input_x;
   166     temp1=DOROUND(temp1);
   167     temp1>>=16;
   168     temp2=xC1S7*irot_input_y ;
   169     temp2=DOROUND(temp2);
   170     temp2>>=16;
   171     ip[7] = temp1 + temp2 ;
   172 
   173     /* Define inputs to rotation for outputs 3 and 5 */
   174     irot_input_x = id07 - icommon_product1;
   175     irot_input_y = id34 - icommon_product2;
   176 
   177     /* Apply rotation for outputs 3 and 5. */
   178     temp1=xC3S5*irot_input_x;
   179     temp1=DOROUND(temp1);
   180     temp1>>=16;
   181     temp2=xC5S3*irot_input_y ;
   182     temp2=DOROUND(temp2);
   183     temp2>>=16;
   184     ip[3] = temp1 - temp2 ;
   185 
   186     temp1=xC5S3*irot_input_x;
   187     temp1=DOROUND(temp1);
   188     temp1>>=16;
   189     temp2=xC3S5*irot_input_y;
   190     temp2=DOROUND(temp2);
   191     temp2>>=16;
   192     ip[5] = temp1 + temp2;
   193 
   194     /* Increment data pointer for next row. */
   195     src += 8 ;
   196     ip += 8; /* advance pointer to next row */
   197 
   198   }
   199 
   200 
   201   /* Performed DCT on rows, now transform the columns */
   202   ip = InterData;
   203   for (loop = 0; loop < 8; loop++){
   204     /* Pre calculate some common sums and differences.  */
   205     is07 = ip[0 * 8] + ip[7 * 8];
   206     is12 = ip[1 * 8] + ip[2 * 8];
   207     is34 = ip[3 * 8] + ip[4 * 8];
   208     is56 = ip[5 * 8] + ip[6 * 8];
   209 
   210     id07 = ip[0 * 8] - ip[7 * 8];
   211     id12 = ip[1 * 8] - ip[2 * 8];
   212     id34 = ip[3 * 8] - ip[4 * 8];
   213     id56 = ip[5 * 8] - ip[6 * 8];
   214 
   215     is0734 = is07 + is34;
   216     is1256 = is12 + is56;
   217 
   218     /* Pre-Calculate some common product terms. */
   219     icommon_product1 = xC4S4*(is12 - is56) ;
   220     icommon_product2 = xC4S4*(id12 + id56) ;
   221     icommon_product1 = DOROUND(icommon_product1);
   222     icommon_product2 = DOROUND(icommon_product2);
   223     icommon_product1>>=16;
   224     icommon_product2>>=16;
   225 
   226 
   227     temp1 = xC4S4*(is0734 + is1256) ;
   228     temp2 = xC4S4*(is0734 - is1256) ;
   229     temp1 = DOROUND(temp1);
   230     temp2 = DOROUND(temp2);
   231     temp1>>=16;
   232     temp2>>=16;
   233     op[0*8] = (int16_t) temp1;
   234     op[4*8] = (int16_t) temp2;
   235 
   236     /* Define inputs to rotation for outputs 2 and 6 */
   237     irot_input_x = id12 - id56;
   238     irot_input_y = is07 - is34;
   239 
   240     /* Apply rotation for outputs 2 and 6.  */
   241     temp1=xC6S2*irot_input_x;
   242     temp1=DOROUND(temp1);
   243     temp1>>=16;
   244     temp2=xC2S6*irot_input_y;
   245     temp2=DOROUND(temp2);
   246     temp2>>=16;
   247     op[2*8] = (int16_t) (temp1 + temp2);
   248 
   249     temp1=xC6S2*irot_input_y;
   250     temp1=DOROUND(temp1);
   251     temp1>>=16;
   252     temp2=xC2S6*irot_input_x ;
   253     temp2=DOROUND(temp2);
   254     temp2>>=16;
   255     op[6*8] = (int16_t) (temp1 -temp2) ;
   256 
   257     /* Define inputs to rotation for outputs 1 and 7 */
   258     irot_input_x = icommon_product1 + id07;
   259     irot_input_y = -( id34 + icommon_product2 );
   260 
   261     /* Apply rotation for outputs 1 and 7. */
   262     temp1=xC1S7*irot_input_x;
   263     temp1=DOROUND(temp1);
   264     temp1>>=16;
   265     temp2=xC7S1*irot_input_y;
   266     temp2=DOROUND(temp2);
   267     temp2>>=16;
   268     op[1*8] = (int16_t) (temp1 - temp2);
   269 
   270     temp1=xC7S1*irot_input_x;
   271     temp1=DOROUND(temp1);
   272     temp1>>=16;
   273     temp2=xC1S7*irot_input_y ;
   274     temp2=DOROUND(temp2);
   275     temp2>>=16;
   276     op[7*8] = (int16_t) (temp1 + temp2);
   277 
   278     /* Define inputs to rotation for outputs 3 and 5 */
   279     irot_input_x = id07 - icommon_product1;
   280     irot_input_y = id34 - icommon_product2;
   281 
   282     /* Apply rotation for outputs 3 and 5. */
   283     temp1=xC3S5*irot_input_x;
   284     temp1=DOROUND(temp1);
   285     temp1>>=16;
   286     temp2=xC5S3*irot_input_y ;
   287     temp2=DOROUND(temp2);
   288     temp2>>=16;
   289     op[3*8] = (int16_t) (temp1 - temp2) ;
   290 
   291     temp1=xC5S3*irot_input_x;
   292     temp1=DOROUND(temp1);
   293     temp1>>=16;
   294     temp2=xC3S5*irot_input_y;
   295     temp2=DOROUND(temp2);
   296     temp2>>=16;
   297     op[5*8] = (int16_t) (temp1 + temp2);
   298 
   299     /* Increment data pointer for next column.  */
   300     ip ++;
   301     op ++;
   302   }
   303 }
   304 
   305 OIL_DEFINE_IMPL_REF (fdct8x8theora_ref, fdct8x8theora);
   306 
   307 
   308 
   309 #ifdef	__SYMBIAN32__
   310  
   311 OilFunctionClass* __oil_function_class_fdct8x8theora() {
   312 		return &_oil_function_class_fdct8x8theora;
   313 }
   314 #endif
   315 
   316 
   317 
   318 #ifdef	__SYMBIAN32__
   319  
   320 OilFunctionImpl* __oil_function_impl_fdct8x8theora_ref() {
   321 		return &_oil_function_impl_fdct8x8theora_ref;
   322 }
   323 #endif
   324 
   325 
   326 
   327 #ifdef	__SYMBIAN32__
   328  
   329 EXPORT_C void** _oil_function_class_ptr_fdct8x8theora ()	{
   330 	oil_function_class_ptr_fdct8x8theora = __oil_function_class_fdct8x8theora();
   331 	return &oil_function_class_ptr_fdct8x8theora->func;
   332 	}
   333 #endif
   334