genericopenlibs/liboil/src/dct/idct8x8theora_ref.c
changeset 18 47c74d1534e1
equal deleted inserted replaced
0:e4d67989cc36 18:47c74d1534e1
       
     1 /*
       
     2  * LIBOIL - Library of Optimized Inner Loops
       
     3  * Copyright (c) 2001,2002,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/liboil.h>
       
    34 #include <liboil/liboiltest.h>
       
    35 #include <liboil/liboilrandom.h>
       
    36 #include "liboil/dct/dct.h"
       
    37 #include <math.h>
       
    38 
       
    39 #ifdef __SYMBIAN32__
       
    40 #ifdef __WINSCW__
       
    41 #pragma warn_unusedarg off 
       
    42 #endif//__WINSCW__
       
    43 #endif//__SYMBIAN32__
       
    44 
       
    45 static void
       
    46 idct8theora_s16_test (OilTest *test)
       
    47 {
       
    48   int i;
       
    49   int stride = test->params[OIL_ARG_SSTR1].value;
       
    50   uint16_t *ptr = (uint16_t *)oil_test_get_source_data(test,OIL_ARG_SRC1);
       
    51 
       
    52   for(i=0;i<8;i++){
       
    53     OIL_GET(ptr, i*stride, int16_t) = oil_rand_s16() >> 3;
       
    54     //OIL_GET(ptr, i*stride, int16_t) = 0;
       
    55   }
       
    56   //OIL_GET(ptr, 0*stride, int16_t) = 100;
       
    57 
       
    58 }
       
    59 
       
    60 static void
       
    61 idct8x8theora_s16_test (OilTest *test)
       
    62 {
       
    63   int i;
       
    64   int j;
       
    65   int stride = test->params[OIL_ARG_SSTR1].value;
       
    66   uint16_t *ptr = (uint16_t *)oil_test_get_source_data(test,OIL_ARG_SRC1);
       
    67 
       
    68   for(i=0;i<8;i++){
       
    69     for(j=0;j<8;j++){
       
    70       OIL_GET(ptr, i*stride + j*2, int16_t) = oil_rand_s16() >> 3;
       
    71     }
       
    72   }
       
    73 
       
    74 }
       
    75 
       
    76 /**
       
    77  * oil_idct8theora_s16:
       
    78  * @d_8:
       
    79  * @dstr:
       
    80  * @s_8:
       
    81  * @sstr:
       
    82  *
       
    83  * Performs a Inverse Discrete Cosine Transform on @s_8 and places
       
    84  * the result in @d_8, as defined by the Theora specification.
       
    85  */
       
    86 OIL_DEFINE_CLASS_FULL (idct8theora_s16, "int16_t *d_8, int dstr, int16_t *s_8, int sstr", idct8theora_s16_test);
       
    87 /**
       
    88  * oil_idct8x8theora_s16:
       
    89  * @d_8x8:
       
    90  * @dstr:
       
    91  * @s_8x8:
       
    92  * @sstr:
       
    93  *
       
    94  * Performs a Inverse Discrete Cosine Transform on @s_8x8 and places
       
    95  * the result in @d_8x8, as defined by the Theora specification.
       
    96  */
       
    97 OIL_DEFINE_CLASS_FULL (idct8x8theora_s16, "int16_t *d_8x8, int dstr, int16_t *s_8x8, int sstr", idct8x8theora_s16_test);
       
    98 
       
    99 
       
   100 
       
   101 #define C1 64277
       
   102 #define C2 60547
       
   103 #define C3 54491
       
   104 #define C4 46341
       
   105 #define C5 36410
       
   106 #define C6 25080
       
   107 #define C7 12785
       
   108 
       
   109 #define S7 64277
       
   110 #define S6 60547
       
   111 #define S5 54491
       
   112 #define S4 46341
       
   113 #define S3 36410
       
   114 #define S2 25080
       
   115 #define S1 12785
       
   116 
       
   117 #define TRUNC(x) ((int16_t)x)
       
   118 #define MULT(a,b) (((a)*(b))>>16)
       
   119 
       
   120 static void
       
   121 idct8theora_s16_ref (int16_t *dest, int dstr, const int16_t *src, int sstr)
       
   122 {
       
   123   int32_t t[10];
       
   124   int32_t r;
       
   125 
       
   126 #define Y(i) OIL_GET(src,sstr*(i),int16_t)
       
   127 #define X(i) OIL_GET(dest,sstr*(i),int16_t)
       
   128 
       
   129   /* the ordering here corresponds closely to the theora spec */
       
   130   t[0] = MULT(C4, Y(0) + Y(4));
       
   131   t[0] = TRUNC(t[0]);
       
   132   t[1] = MULT(C4, Y(0) - Y(4));
       
   133   t[1] = TRUNC(t[1]);
       
   134   t[2] = MULT(C6, Y(2)) - MULT(S6, Y(6));
       
   135   t[3] = MULT(S6, Y(2)) + MULT(C6, Y(6));
       
   136   t[4] = MULT(C7, Y(1)) - MULT(S7, Y(7));
       
   137   t[5] = MULT(C3, Y(5)) - MULT(S3, Y(3));
       
   138   t[6] = MULT(S3, Y(5)) + MULT(C3, Y(3));
       
   139   t[7] = MULT(S7, Y(1)) + MULT(C7, Y(7));
       
   140   r = t[4] + t[5];
       
   141   t[5] = MULT(C4, t[4] - t[5]);
       
   142   t[5] = TRUNC(t[5]);
       
   143   t[4] = r;
       
   144   r = t[7] + t[6];
       
   145   t[6] = MULT(C4, t[7] - t[6]);
       
   146   t[6] = TRUNC(t[6]);
       
   147   t[7] = r;
       
   148   r = t[0] + t[3];
       
   149   t[3] = t[0] - t[3];
       
   150   t[0] = r;
       
   151   r = t[1] + t[2];
       
   152   t[2] = t[1] - t[2];
       
   153   t[1] = r;
       
   154   r = t[6] + t[5];
       
   155   t[5] = t[6] - t[5];
       
   156   t[6] = r;
       
   157   r = t[0] + t[7];
       
   158   r = TRUNC(r);
       
   159   X(0) = r;
       
   160   r = t[1] + t[6];
       
   161   r = TRUNC(r);
       
   162   X(1) = r;
       
   163   r = t[2] + t[5];
       
   164   r = TRUNC(r);
       
   165   X(2) = r;
       
   166   r = t[3] + t[4];
       
   167   r = TRUNC(r);
       
   168   X(3) = r;
       
   169   r = t[3] - t[4];
       
   170   r = TRUNC(r);
       
   171   X(4) = r;
       
   172   r = t[2] - t[5];
       
   173   r = TRUNC(r);
       
   174   X(5) = r;
       
   175   r = t[1] - t[6];
       
   176   r = TRUNC(r);
       
   177   X(6) = r;
       
   178   r = t[0] - t[7];
       
   179   r = TRUNC(r);
       
   180   X(7) = r;
       
   181 }
       
   182 OIL_DEFINE_IMPL_REF (idct8theora_s16_ref, idct8theora_s16);
       
   183 
       
   184 
       
   185 static void
       
   186 idct8x8theora_s16_ref (int16_t *dest, int dstr, const int16_t *src, int sstr)
       
   187 {
       
   188   int i;
       
   189   int16_t tmp[64];
       
   190 
       
   191   for(i=0;i<8;i++){
       
   192     idct8theora_s16_ref(
       
   193         OIL_OFFSET(tmp, 8*sizeof(int16_t) * i), sizeof(int16_t),
       
   194         OIL_OFFSET(src, sstr * i), sizeof(int16_t));
       
   195   }
       
   196   for(i=0;i<8;i++){
       
   197     idct8theora_s16_ref(
       
   198         OIL_OFFSET(dest, sizeof(int16_t) * i), dstr,
       
   199         OIL_OFFSET(tmp, sizeof(int16_t) * i), sizeof(int16_t) * 8);
       
   200   }
       
   201 }
       
   202 OIL_DEFINE_IMPL_REF (idct8x8theora_s16_ref, idct8x8theora_s16);
       
   203 
       
   204 
       
   205 
       
   206 
       
   207 #ifdef	__SYMBIAN32__
       
   208  
       
   209 OilFunctionClass* __oil_function_class_idct8theora_s16() {
       
   210 		return &_oil_function_class_idct8theora_s16;
       
   211 }
       
   212 #endif
       
   213 
       
   214 #ifdef	__SYMBIAN32__
       
   215  
       
   216 OilFunctionClass* __oil_function_class_idct8x8theora_s16() {
       
   217 		return &_oil_function_class_idct8x8theora_s16;
       
   218 }
       
   219 #endif
       
   220 
       
   221 
       
   222 
       
   223 #ifdef	__SYMBIAN32__
       
   224  
       
   225 OilFunctionImpl* __oil_function_impl_idct8theora_s16_ref() {
       
   226 		return &_oil_function_impl_idct8theora_s16_ref;
       
   227 }
       
   228 #endif
       
   229 
       
   230 #ifdef	__SYMBIAN32__
       
   231  
       
   232 OilFunctionImpl* __oil_function_impl_idct8x8theora_s16_ref() {
       
   233 		return &_oil_function_impl_idct8x8theora_s16_ref;
       
   234 }
       
   235 #endif
       
   236 
       
   237 
       
   238 
       
   239 #ifdef	__SYMBIAN32__
       
   240  
       
   241 EXPORT_C void** _oil_function_class_ptr_idct8theora_s16 ()	{
       
   242 	oil_function_class_ptr_idct8theora_s16 = __oil_function_class_idct8theora_s16();
       
   243 	return &oil_function_class_ptr_idct8theora_s16->func;
       
   244 	}
       
   245 #endif
       
   246 
       
   247 #ifdef	__SYMBIAN32__
       
   248  
       
   249 EXPORT_C void** _oil_function_class_ptr_idct8x8theora_s16 ()	{
       
   250 	oil_function_class_ptr_idct8x8theora_s16 = __oil_function_class_idct8x8theora_s16();
       
   251 	return &oil_function_class_ptr_idct8x8theora_s16->func;
       
   252 	}
       
   253 #endif
       
   254