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