os/ossrv/genericopenlibs/liboil/src/dct/idct8x8_c.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) 2001,2002,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
//Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
sl@0
    28
sl@0
    29
#ifdef HAVE_CONFIG_H
sl@0
    30
#include "config.h"
sl@0
    31
#endif
sl@0
    32
sl@0
    33
#include <liboil/liboil.h>
sl@0
    34
#include "liboil/dct/dct.h"
sl@0
    35
#include <math.h>
sl@0
    36
#include <liboil/liboiltest.h>
sl@0
    37
#include <liboil/liboilparameter.h>
sl@0
    38
#include <liboil/liboilrandom.h>
sl@0
    39
sl@0
    40
/**
sl@0
    41
 * SECTION:liboilfuncs-dct:
sl@0
    42
 * @title: Direct Cosine Transform
sl@0
    43
 * @short_description: DCT related functions
sl@0
    44
 */
sl@0
    45
sl@0
    46
#define BLOCK8x8_F64(ptr, stride, row, column) \
sl@0
    47
	(*((double *)((unsigned char *)ptr + stride*row) + column))
sl@0
    48
sl@0
    49
#define BLOCK8x8_PTR_F64(ptr, stride, row, column) \
sl@0
    50
	((double *)((unsigned char *)ptr + stride*row) + column)
sl@0
    51
sl@0
    52
#define BLOCK8x8_S16(ptr, stride, row, column) \
sl@0
    53
	(*((int16_t *)((unsigned char *)ptr + stride*row) + column))
sl@0
    54
sl@0
    55
static void
sl@0
    56
idct8x8_test (OilTest *test)
sl@0
    57
{
sl@0
    58
  int16_t *data = oil_test_get_source_data (test, OIL_ARG_SRC1);
sl@0
    59
  int stride = oil_test_get_value (test, OIL_ARG_SSTR1);
sl@0
    60
  int i, j;
sl@0
    61
sl@0
    62
  for(j=0;j<8;j++){
sl@0
    63
    for(i=0;i<8;i++){
sl@0
    64
      OIL_GET(data, i*2 + j*stride, int16_t) = (oil_rand_s16() & 0xfff) - 2048;
sl@0
    65
    }
sl@0
    66
  }
sl@0
    67
}
sl@0
    68
sl@0
    69
/**
sl@0
    70
 * oil_idct8x8_f64:
sl@0
    71
 * @d_8x8:
sl@0
    72
 * @dstr:
sl@0
    73
 * @s_8x8:
sl@0
    74
 * @sstr:
sl@0
    75
 *
sl@0
    76
 * Performs a 2-D Inverse Discrete Cosine Transform on @s_8x8 and places
sl@0
    77
 * the result in @d_8x8.
sl@0
    78
 */
sl@0
    79
OIL_DEFINE_CLASS (idct8x8_f64, "double *d_8x8, int dstr, double *s_8x8, int sstr");
sl@0
    80
/**
sl@0
    81
 * oil_idct8x8lim10_f64:
sl@0
    82
 * @d_8x8:
sl@0
    83
 * @dstr:
sl@0
    84
 * @s_8x8:
sl@0
    85
 * @sstr:
sl@0
    86
 *
sl@0
    87
 * Performs a 2-D Inverse Discrete Cosine Transform on @s_8x8 and places
sl@0
    88
 * the result in @d_8x8.
sl@0
    89
 */
sl@0
    90
OIL_DEFINE_CLASS (idct8x8lim10_f64, "double *d_8x8, int dstr, double *s_8x8, int sstr");
sl@0
    91
/**
sl@0
    92
 * oil_idct8x8_s16:
sl@0
    93
 * @d_8x8:
sl@0
    94
 * @dstr:
sl@0
    95
 * @s_8x8:
sl@0
    96
 * @sstr:
sl@0
    97
 *
sl@0
    98
 * Performs a limited 2-D Inverse Discrete Cosine Transform on @s_8x8
sl@0
    99
 * and places the result in @d_8x8.
sl@0
   100
 */
sl@0
   101
OIL_DEFINE_CLASS_FULL (idct8x8_s16, "int16_t *d_8x8, int dstr, int16_t *s_8x8, int sstr", idct8x8_test);
sl@0
   102
/**
sl@0
   103
 * oil_idct8x8lim10_s16:
sl@0
   104
 * @d_8x8:
sl@0
   105
 * @dstr:
sl@0
   106
 * @s_8x8:
sl@0
   107
 * @sstr:
sl@0
   108
 *
sl@0
   109
 * Performs a limited 2-D Inverse Discrete Cosine Transform on @s_8x8
sl@0
   110
 * and places the result in @d_8x8.  The source 8x8 block must be non-zero
sl@0
   111
 * only in the 10 lowest-order components.
sl@0
   112
 */
sl@0
   113
OIL_DEFINE_CLASS (idct8x8lim10_s16, "int16_t *d_8x8, int dstr, int16_t *s_8x8, int sstr");
sl@0
   114
sl@0
   115
static void
sl@0
   116
idct8x8_f64_ref (double *dest, int dstr, const double *src, int sstr)
sl@0
   117
{
sl@0
   118
	static double idct_coeff[8][8];
sl@0
   119
	static int idct_coeff_init = 0;
sl@0
   120
	int i,j,k,l;
sl@0
   121
	double tmp1,tmp2;
sl@0
   122
sl@0
   123
	if(!idct_coeff_init){
sl@0
   124
		double scale;
sl@0
   125
sl@0
   126
		for(i=0;i<8;i++){
sl@0
   127
			scale = (i==0) ? sqrt(0.125) : 0.5;
sl@0
   128
			for(j=0;j<8;j++){
sl@0
   129
				idct_coeff[j][i] = scale *
sl@0
   130
					cos((M_PI/8)*i*(j+0.5));
sl@0
   131
			}
sl@0
   132
		}
sl@0
   133
		idct_coeff_init = 1;
sl@0
   134
	}
sl@0
   135
sl@0
   136
	for(i=0;i<8;i++){
sl@0
   137
		for(j=0;j<8;j++){
sl@0
   138
			tmp1 = 0;
sl@0
   139
			for(k=0;k<8;k++){
sl@0
   140
				tmp2 = 0;
sl@0
   141
				for(l=0;l<8;l++){
sl@0
   142
					tmp2 += idct_coeff[j][l] *
sl@0
   143
						BLOCK8x8_F64(src,sstr,k,l);
sl@0
   144
				}
sl@0
   145
				tmp1 += idct_coeff[i][k] * tmp2;
sl@0
   146
			}
sl@0
   147
			BLOCK8x8_F64(dest,dstr,i,j) = tmp1;
sl@0
   148
		}
sl@0
   149
	}
sl@0
   150
}
sl@0
   151
OIL_DEFINE_IMPL_REF (idct8x8_f64_ref, idct8x8_f64);
sl@0
   152
sl@0
   153
static void
sl@0
   154
idct8x8lim10_f64_ref (double *dest, int dstr, const double *src, int sstr)
sl@0
   155
{
sl@0
   156
	static double idct_coeff[8][8];
sl@0
   157
	static int idct_coeff_init = 0;
sl@0
   158
	int i,j,k,l;
sl@0
   159
	double tmp1,tmp2;
sl@0
   160
sl@0
   161
	if(!idct_coeff_init){
sl@0
   162
		double scale;
sl@0
   163
sl@0
   164
		for(i=0;i<8;i++){
sl@0
   165
			scale = (i==0) ? sqrt(0.125) : 0.5;
sl@0
   166
			for(j=0;j<8;j++){
sl@0
   167
				idct_coeff[j][i] = scale *
sl@0
   168
					cos((M_PI/8)*i*(j+0.5));
sl@0
   169
			}
sl@0
   170
		}
sl@0
   171
		idct_coeff_init = 1;
sl@0
   172
	}
sl@0
   173
sl@0
   174
	for(i=0;i<8;i++){
sl@0
   175
		for(j=0;j<8;j++){
sl@0
   176
			tmp1 = 0;
sl@0
   177
			for(k=0;k<4;k++){
sl@0
   178
				tmp2 = 0;
sl@0
   179
				for(l=0;l<4;l++){
sl@0
   180
					tmp2 += idct_coeff[j][l] *
sl@0
   181
						BLOCK8x8_F64(src,sstr,k,l);
sl@0
   182
				}
sl@0
   183
				tmp1 += idct_coeff[i][k] * tmp2;
sl@0
   184
			}
sl@0
   185
			BLOCK8x8_F64(dest,dstr,i,j) = tmp1;
sl@0
   186
		}
sl@0
   187
	}
sl@0
   188
}
sl@0
   189
OIL_DEFINE_IMPL_REF (idct8x8lim10_f64_ref, idct8x8lim10_f64);
sl@0
   190
sl@0
   191
#if defined(oil_idct8_f64)
sl@0
   192
static void
sl@0
   193
idct8x8_f64_c (double *dest, int dstr, const double *src, int sstr)
sl@0
   194
{
sl@0
   195
	int i;
sl@0
   196
	double tmp[64];
sl@0
   197
	int tmpstr = 8*sizeof(double);
sl@0
   198
sl@0
   199
	for(i=0;i<8;i++){
sl@0
   200
		oil_idct8_f64(
sl@0
   201
			BLOCK8x8_PTR_F64(tmp,tmpstr,i,0), sizeof(double),
sl@0
   202
			BLOCK8x8_PTR_F64(src,sstr,i,0), sizeof(double));
sl@0
   203
	}
sl@0
   204
	for(i=0;i<8;i++){
sl@0
   205
		oil_idct8_f64(
sl@0
   206
			BLOCK8x8_PTR_F64(dest,dstr,0,i), dstr,
sl@0
   207
			BLOCK8x8_PTR_F64(tmp,tmpstr,0,i), tmpstr);
sl@0
   208
	}
sl@0
   209
}
sl@0
   210
sl@0
   211
OIL_DEFINE_IMPL_DEPENDS (idct8x8_f64_c, idct8x8_f64, idct8_f64);
sl@0
   212
#endif
sl@0
   213
sl@0
   214
#if defined(oil_conv8x8_f64_s16) && defined(oil_idct8x8_f64) && \
sl@0
   215
    defined(oil_conv8x8_s16_f64)
sl@0
   216
static void
sl@0
   217
idct8x8_s16_ref (int16_t *dest, int dstr, const int16_t *src, int sstr)
sl@0
   218
{
sl@0
   219
	double s[64], d[64];
sl@0
   220
sl@0
   221
	oil_conv8x8_f64_s16 (s,8*sizeof(double),src,sstr);
sl@0
   222
	oil_idct8x8_f64 (d,8*sizeof(double),s,8*sizeof(double));
sl@0
   223
	oil_conv8x8_s16_f64 (dest,dstr,d,8*sizeof(double));
sl@0
   224
}
sl@0
   225
sl@0
   226
OIL_DEFINE_IMPL_REF (idct8x8_s16_ref, idct8x8_s16);
sl@0
   227
#if 0
sl@0
   228
OIL_DEFINE_IMPL_DEPENDS (idct8x8_s16_ref, idct8x8_s16,
sl@0
   229
    conv8x8_f64_s16, idct8x8_f64, conv8x8_s16_f64);
sl@0
   230
#endif
sl@0
   231
#endif
sl@0
   232
sl@0
   233
#if defined(oil_conv8x8_f64_s16) && defined(oil_idct8x8lim10_f64) && \
sl@0
   234
    defined(oil_conv8x8_s16_f64)
sl@0
   235
static void
sl@0
   236
idct8x8lim10_s16_ref (int16_t *dest, int dstr, const int16_t *src, int sstr)
sl@0
   237
{
sl@0
   238
	double s[64], d[64];
sl@0
   239
sl@0
   240
	oil_conv8x8_f64_s16 (s,8*sizeof(double),src,sstr);
sl@0
   241
	oil_idct8x8lim10_f64 (d,8*sizeof(double),s,8*sizeof(double));
sl@0
   242
	oil_conv8x8_s16_f64 (dest,dstr,d,8*sizeof(double));
sl@0
   243
}
sl@0
   244
sl@0
   245
OIL_DEFINE_IMPL_REF (idct8x8lim10_s16_ref, idct8x8lim10_s16);
sl@0
   246
#if 0
sl@0
   247
OIL_DEFINE_IMPL_DEPENDS (idct8x8_s16_ref, idct8x8_s16,
sl@0
   248
    conv8x8_f64_s16, idct8x8_f64, conv8x8_s16_f64);
sl@0
   249
#endif
sl@0
   250
#endif
sl@0
   251
sl@0
   252
sl@0
   253
sl@0
   254
#ifdef	__SYMBIAN32__
sl@0
   255
 
sl@0
   256
OilFunctionClass* __oil_function_class_idct8x8_f64() {
sl@0
   257
		return &_oil_function_class_idct8x8_f64;
sl@0
   258
}
sl@0
   259
#endif
sl@0
   260
sl@0
   261
#ifdef	__SYMBIAN32__
sl@0
   262
 
sl@0
   263
OilFunctionClass* __oil_function_class_idct8x8lim10_f64() {
sl@0
   264
		return &_oil_function_class_idct8x8lim10_f64;
sl@0
   265
}
sl@0
   266
#endif
sl@0
   267
sl@0
   268
#ifdef	__SYMBIAN32__
sl@0
   269
 
sl@0
   270
OilFunctionClass* __oil_function_class_idct8x8_s16() {
sl@0
   271
		return &_oil_function_class_idct8x8_s16;
sl@0
   272
}
sl@0
   273
#endif
sl@0
   274
sl@0
   275
#ifdef	__SYMBIAN32__
sl@0
   276
 
sl@0
   277
OilFunctionClass* __oil_function_class_idct8x8lim10_s16() {
sl@0
   278
		return &_oil_function_class_idct8x8lim10_s16;
sl@0
   279
}
sl@0
   280
#endif
sl@0
   281
sl@0
   282
sl@0
   283
sl@0
   284
#ifdef	__SYMBIAN32__
sl@0
   285
 
sl@0
   286
OilFunctionImpl* __oil_function_impl_idct8x8_f64_ref() {
sl@0
   287
		return &_oil_function_impl_idct8x8_f64_ref;
sl@0
   288
}
sl@0
   289
#endif
sl@0
   290
sl@0
   291
#ifdef	__SYMBIAN32__
sl@0
   292
 
sl@0
   293
OilFunctionImpl* __oil_function_impl_idct8x8lim10_f64_ref() {
sl@0
   294
		return &_oil_function_impl_idct8x8lim10_f64_ref;
sl@0
   295
}
sl@0
   296
#endif
sl@0
   297
sl@0
   298
#ifdef	__SYMBIAN32__
sl@0
   299
 
sl@0
   300
OilFunctionImpl* __oil_function_impl_idct8x8_s16_ref() {
sl@0
   301
		return &_oil_function_impl_idct8x8_s16_ref;
sl@0
   302
}
sl@0
   303
#endif
sl@0
   304
sl@0
   305
#ifdef	__SYMBIAN32__
sl@0
   306
 
sl@0
   307
OilFunctionImpl* __oil_function_impl_idct8x8lim10_s16_ref() {
sl@0
   308
		return &_oil_function_impl_idct8x8lim10_s16_ref;
sl@0
   309
}
sl@0
   310
#endif
sl@0
   311
sl@0
   312
sl@0
   313
sl@0
   314
#ifdef	__SYMBIAN32__
sl@0
   315
 
sl@0
   316
OilFunctionImpl* __oil_function_impl_idct8x8_f64_c() {
sl@0
   317
		return &_oil_function_impl_idct8x8_f64_c;
sl@0
   318
}
sl@0
   319
#endif
sl@0
   320
sl@0
   321
sl@0
   322
sl@0
   323
sl@0
   324
#ifdef	__SYMBIAN32__
sl@0
   325
 
sl@0
   326
EXPORT_C void** _oil_function_class_ptr_idct8x8_f64 ()	{
sl@0
   327
	oil_function_class_ptr_idct8x8_f64 = __oil_function_class_idct8x8_f64();
sl@0
   328
	return &oil_function_class_ptr_idct8x8_f64->func;
sl@0
   329
	}
sl@0
   330
#endif
sl@0
   331
sl@0
   332
#ifdef	__SYMBIAN32__
sl@0
   333
 
sl@0
   334
EXPORT_C void** _oil_function_class_ptr_idct8x8lim10_f64 ()	{
sl@0
   335
	oil_function_class_ptr_idct8x8lim10_f64 = __oil_function_class_idct8x8lim10_f64();
sl@0
   336
	return &oil_function_class_ptr_idct8x8lim10_f64->func;
sl@0
   337
	}
sl@0
   338
#endif
sl@0
   339
sl@0
   340
#ifdef	__SYMBIAN32__
sl@0
   341
 
sl@0
   342
EXPORT_C void** _oil_function_class_ptr_idct8x8_s16 ()	{
sl@0
   343
	oil_function_class_ptr_idct8x8_s16 = __oil_function_class_idct8x8_s16();
sl@0
   344
	return &oil_function_class_ptr_idct8x8_s16->func;
sl@0
   345
	}
sl@0
   346
#endif
sl@0
   347
sl@0
   348
#ifdef	__SYMBIAN32__
sl@0
   349
 
sl@0
   350
EXPORT_C void** _oil_function_class_ptr_idct8x8lim10_s16 ()	{
sl@0
   351
	oil_function_class_ptr_idct8x8lim10_s16 = __oil_function_class_idct8x8lim10_s16();
sl@0
   352
	return &oil_function_class_ptr_idct8x8lim10_s16->func;
sl@0
   353
	}
sl@0
   354
#endif
sl@0
   355