Update contrib.
2 * LIBOIL - Library of Optimized Inner Loops
3 * Copyright (c) 2001,2002,2003,2004 David A. Schleef <ds@schleef.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
27 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
33 #include <liboil/liboil.h>
34 #include "liboil/dct/dct.h"
36 #include <liboil/liboiltest.h>
37 #include <liboil/liboilparameter.h>
38 #include <liboil/liboilrandom.h>
41 * SECTION:liboilfuncs-dct:
42 * @title: Direct Cosine Transform
43 * @short_description: DCT related functions
46 #define BLOCK8x8_F64(ptr, stride, row, column) \
47 (*((double *)((unsigned char *)ptr + stride*row) + column))
49 #define BLOCK8x8_PTR_F64(ptr, stride, row, column) \
50 ((double *)((unsigned char *)ptr + stride*row) + column)
52 #define BLOCK8x8_S16(ptr, stride, row, column) \
53 (*((int16_t *)((unsigned char *)ptr + stride*row) + column))
56 idct8x8_test (OilTest *test)
58 int16_t *data = oil_test_get_source_data (test, OIL_ARG_SRC1);
59 int stride = oil_test_get_value (test, OIL_ARG_SSTR1);
64 OIL_GET(data, i*2 + j*stride, int16_t) = (oil_rand_s16() & 0xfff) - 2048;
76 * Performs a 2-D Inverse Discrete Cosine Transform on @s_8x8 and places
77 * the result in @d_8x8.
79 OIL_DEFINE_CLASS (idct8x8_f64, "double *d_8x8, int dstr, double *s_8x8, int sstr");
81 * oil_idct8x8lim10_f64:
87 * Performs a 2-D Inverse Discrete Cosine Transform on @s_8x8 and places
88 * the result in @d_8x8.
90 OIL_DEFINE_CLASS (idct8x8lim10_f64, "double *d_8x8, int dstr, double *s_8x8, int sstr");
98 * Performs a limited 2-D Inverse Discrete Cosine Transform on @s_8x8
99 * and places the result in @d_8x8.
101 OIL_DEFINE_CLASS_FULL (idct8x8_s16, "int16_t *d_8x8, int dstr, int16_t *s_8x8, int sstr", idct8x8_test);
103 * oil_idct8x8lim10_s16:
109 * Performs a limited 2-D Inverse Discrete Cosine Transform on @s_8x8
110 * and places the result in @d_8x8. The source 8x8 block must be non-zero
111 * only in the 10 lowest-order components.
113 OIL_DEFINE_CLASS (idct8x8lim10_s16, "int16_t *d_8x8, int dstr, int16_t *s_8x8, int sstr");
116 idct8x8_f64_ref (double *dest, int dstr, const double *src, int sstr)
118 static double idct_coeff[8][8];
119 static int idct_coeff_init = 0;
123 if(!idct_coeff_init){
127 scale = (i==0) ? sqrt(0.125) : 0.5;
129 idct_coeff[j][i] = scale *
130 cos((M_PI/8)*i*(j+0.5));
142 tmp2 += idct_coeff[j][l] *
143 BLOCK8x8_F64(src,sstr,k,l);
145 tmp1 += idct_coeff[i][k] * tmp2;
147 BLOCK8x8_F64(dest,dstr,i,j) = tmp1;
151 OIL_DEFINE_IMPL_REF (idct8x8_f64_ref, idct8x8_f64);
154 idct8x8lim10_f64_ref (double *dest, int dstr, const double *src, int sstr)
156 static double idct_coeff[8][8];
157 static int idct_coeff_init = 0;
161 if(!idct_coeff_init){
165 scale = (i==0) ? sqrt(0.125) : 0.5;
167 idct_coeff[j][i] = scale *
168 cos((M_PI/8)*i*(j+0.5));
180 tmp2 += idct_coeff[j][l] *
181 BLOCK8x8_F64(src,sstr,k,l);
183 tmp1 += idct_coeff[i][k] * tmp2;
185 BLOCK8x8_F64(dest,dstr,i,j) = tmp1;
189 OIL_DEFINE_IMPL_REF (idct8x8lim10_f64_ref, idct8x8lim10_f64);
191 #if defined(oil_idct8_f64)
193 idct8x8_f64_c (double *dest, int dstr, const double *src, int sstr)
197 int tmpstr = 8*sizeof(double);
201 BLOCK8x8_PTR_F64(tmp,tmpstr,i,0), sizeof(double),
202 BLOCK8x8_PTR_F64(src,sstr,i,0), sizeof(double));
206 BLOCK8x8_PTR_F64(dest,dstr,0,i), dstr,
207 BLOCK8x8_PTR_F64(tmp,tmpstr,0,i), tmpstr);
211 OIL_DEFINE_IMPL_DEPENDS (idct8x8_f64_c, idct8x8_f64, idct8_f64);
214 #if defined(oil_conv8x8_f64_s16) && defined(oil_idct8x8_f64) && \
215 defined(oil_conv8x8_s16_f64)
217 idct8x8_s16_ref (int16_t *dest, int dstr, const int16_t *src, int sstr)
221 oil_conv8x8_f64_s16 (s,8*sizeof(double),src,sstr);
222 oil_idct8x8_f64 (d,8*sizeof(double),s,8*sizeof(double));
223 oil_conv8x8_s16_f64 (dest,dstr,d,8*sizeof(double));
226 OIL_DEFINE_IMPL_REF (idct8x8_s16_ref, idct8x8_s16);
228 OIL_DEFINE_IMPL_DEPENDS (idct8x8_s16_ref, idct8x8_s16,
229 conv8x8_f64_s16, idct8x8_f64, conv8x8_s16_f64);
233 #if defined(oil_conv8x8_f64_s16) && defined(oil_idct8x8lim10_f64) && \
234 defined(oil_conv8x8_s16_f64)
236 idct8x8lim10_s16_ref (int16_t *dest, int dstr, const int16_t *src, int sstr)
240 oil_conv8x8_f64_s16 (s,8*sizeof(double),src,sstr);
241 oil_idct8x8lim10_f64 (d,8*sizeof(double),s,8*sizeof(double));
242 oil_conv8x8_s16_f64 (dest,dstr,d,8*sizeof(double));
245 OIL_DEFINE_IMPL_REF (idct8x8lim10_s16_ref, idct8x8lim10_s16);
247 OIL_DEFINE_IMPL_DEPENDS (idct8x8_s16_ref, idct8x8_s16,
248 conv8x8_f64_s16, idct8x8_f64, conv8x8_s16_f64);
256 OilFunctionClass* __oil_function_class_idct8x8_f64() {
257 return &_oil_function_class_idct8x8_f64;
263 OilFunctionClass* __oil_function_class_idct8x8lim10_f64() {
264 return &_oil_function_class_idct8x8lim10_f64;
270 OilFunctionClass* __oil_function_class_idct8x8_s16() {
271 return &_oil_function_class_idct8x8_s16;
277 OilFunctionClass* __oil_function_class_idct8x8lim10_s16() {
278 return &_oil_function_class_idct8x8lim10_s16;
286 OilFunctionImpl* __oil_function_impl_idct8x8_f64_ref() {
287 return &_oil_function_impl_idct8x8_f64_ref;
293 OilFunctionImpl* __oil_function_impl_idct8x8lim10_f64_ref() {
294 return &_oil_function_impl_idct8x8lim10_f64_ref;
300 OilFunctionImpl* __oil_function_impl_idct8x8_s16_ref() {
301 return &_oil_function_impl_idct8x8_s16_ref;
307 OilFunctionImpl* __oil_function_impl_idct8x8lim10_s16_ref() {
308 return &_oil_function_impl_idct8x8lim10_s16_ref;
316 OilFunctionImpl* __oil_function_impl_idct8x8_f64_c() {
317 return &_oil_function_impl_idct8x8_f64_c;
326 EXPORT_C void** _oil_function_class_ptr_idct8x8_f64 () {
327 oil_function_class_ptr_idct8x8_f64 = __oil_function_class_idct8x8_f64();
328 return &oil_function_class_ptr_idct8x8_f64->func;
334 EXPORT_C void** _oil_function_class_ptr_idct8x8lim10_f64 () {
335 oil_function_class_ptr_idct8x8lim10_f64 = __oil_function_class_idct8x8lim10_f64();
336 return &oil_function_class_ptr_idct8x8lim10_f64->func;
342 EXPORT_C void** _oil_function_class_ptr_idct8x8_s16 () {
343 oil_function_class_ptr_idct8x8_s16 = __oil_function_class_idct8x8_s16();
344 return &oil_function_class_ptr_idct8x8_s16->func;
350 EXPORT_C void** _oil_function_class_ptr_idct8x8lim10_s16 () {
351 oil_function_class_ptr_idct8x8lim10_s16 = __oil_function_class_idct8x8lim10_s16();
352 return &oil_function_class_ptr_idct8x8lim10_s16->func;