Update contrib.
2 * LIBOIL - Library of Optimized Inner Loops
3 * Copyright (c) 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.
28 /********************************************************************
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. *
35 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2003 *
36 * by the Xiph.Org Foundation http://www.xiph.org/ *
38 ********************************************************************
41 last mod: $Id: fdct8x8theora.c,v 1.3 2005-12-16 17:30:40 ds Exp $
43 ********************************************************************/
44 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
50 #include <liboil/liboilfunction.h>
51 #include <liboil/liboilfuncs.h>
52 #include "liboil/dct/dct.h"
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;
63 #define SIGNBITDUPPED(X) ((signed )(((X) & 0x80000000)) >> 31)
64 #define DOROUND(X) ( (SIGNBITDUPPED(X) & (0xffff)) + (X) )
71 * Calculates the FDCT transformation of @s_8x8 according to the Theora
72 * specification and places the result in @d_8x8.
74 * Note that the source and destination arrays are reversed compared
75 * to normal Liboil order.
77 OIL_DEFINE_CLASS(fdct8x8theora, "int16_t *s_8x8, int16_t *d_8x8");
80 fdct8x8theora_ref(const int16_t *src, int16_t *dest)
84 int32_t is07, is12, is34, is56;
85 int32_t is0734, is1256;
86 int32_t id07, id12, id34, id56;
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)). */
92 int32_t temp1, temp2; /* intermediate variable for computation */
94 int32_t InterData[64];
95 int32_t *ip = InterData;
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];
104 id07 = src[0] - src[7];
105 id12 = src[1] - src[2];
106 id34 = src[3] - src[4];
107 id56 = src[5] - src[6];
109 is0734 = is07 + is34;
110 is1256 = is12 + is56;
112 /* Pre-Calculate some common product terms. */
113 icommon_product1 = xC4S4*(is12 - is56);
114 icommon_product1 = DOROUND(icommon_product1);
115 icommon_product1>>=16;
117 icommon_product2 = xC4S4*(id12 + id56);
118 icommon_product2 = DOROUND(icommon_product2);
119 icommon_product2>>=16;
122 ip[0] = (xC4S4*(is0734 + is1256));
123 ip[0] = DOROUND(ip[0]);
126 ip[4] = (xC4S4*(is0734 - is1256));
127 ip[4] = DOROUND(ip[4]);
130 /* Define inputs to rotation for outputs 2 and 6 */
131 irot_input_x = id12 - id56;
132 irot_input_y = is07 - is34;
134 /* Apply rotation for outputs 2 and 6. */
135 temp1=xC6S2*irot_input_x;
136 temp1=DOROUND(temp1);
138 temp2=xC2S6*irot_input_y;
139 temp2=DOROUND(temp2);
141 ip[2] = temp1 + temp2;
143 temp1=xC6S2*irot_input_y;
144 temp1=DOROUND(temp1);
146 temp2=xC2S6*irot_input_x ;
147 temp2=DOROUND(temp2);
149 ip[6] = temp1 -temp2 ;
151 /* Define inputs to rotation for outputs 1 and 7 */
152 irot_input_x = icommon_product1 + id07;
153 irot_input_y = -( id34 + icommon_product2 );
155 /* Apply rotation for outputs 1 and 7. */
157 temp1=xC1S7*irot_input_x;
158 temp1=DOROUND(temp1);
160 temp2=xC7S1*irot_input_y;
161 temp2=DOROUND(temp2);
163 ip[1] = temp1 - temp2;
165 temp1=xC7S1*irot_input_x;
166 temp1=DOROUND(temp1);
168 temp2=xC1S7*irot_input_y ;
169 temp2=DOROUND(temp2);
171 ip[7] = temp1 + temp2 ;
173 /* Define inputs to rotation for outputs 3 and 5 */
174 irot_input_x = id07 - icommon_product1;
175 irot_input_y = id34 - icommon_product2;
177 /* Apply rotation for outputs 3 and 5. */
178 temp1=xC3S5*irot_input_x;
179 temp1=DOROUND(temp1);
181 temp2=xC5S3*irot_input_y ;
182 temp2=DOROUND(temp2);
184 ip[3] = temp1 - temp2 ;
186 temp1=xC5S3*irot_input_x;
187 temp1=DOROUND(temp1);
189 temp2=xC3S5*irot_input_y;
190 temp2=DOROUND(temp2);
192 ip[5] = temp1 + temp2;
194 /* Increment data pointer for next row. */
196 ip += 8; /* advance pointer to next row */
201 /* Performed DCT on rows, now transform the columns */
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];
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];
215 is0734 = is07 + is34;
216 is1256 = is12 + is56;
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;
227 temp1 = xC4S4*(is0734 + is1256) ;
228 temp2 = xC4S4*(is0734 - is1256) ;
229 temp1 = DOROUND(temp1);
230 temp2 = DOROUND(temp2);
233 op[0*8] = (int16_t) temp1;
234 op[4*8] = (int16_t) temp2;
236 /* Define inputs to rotation for outputs 2 and 6 */
237 irot_input_x = id12 - id56;
238 irot_input_y = is07 - is34;
240 /* Apply rotation for outputs 2 and 6. */
241 temp1=xC6S2*irot_input_x;
242 temp1=DOROUND(temp1);
244 temp2=xC2S6*irot_input_y;
245 temp2=DOROUND(temp2);
247 op[2*8] = (int16_t) (temp1 + temp2);
249 temp1=xC6S2*irot_input_y;
250 temp1=DOROUND(temp1);
252 temp2=xC2S6*irot_input_x ;
253 temp2=DOROUND(temp2);
255 op[6*8] = (int16_t) (temp1 -temp2) ;
257 /* Define inputs to rotation for outputs 1 and 7 */
258 irot_input_x = icommon_product1 + id07;
259 irot_input_y = -( id34 + icommon_product2 );
261 /* Apply rotation for outputs 1 and 7. */
262 temp1=xC1S7*irot_input_x;
263 temp1=DOROUND(temp1);
265 temp2=xC7S1*irot_input_y;
266 temp2=DOROUND(temp2);
268 op[1*8] = (int16_t) (temp1 - temp2);
270 temp1=xC7S1*irot_input_x;
271 temp1=DOROUND(temp1);
273 temp2=xC1S7*irot_input_y ;
274 temp2=DOROUND(temp2);
276 op[7*8] = (int16_t) (temp1 + temp2);
278 /* Define inputs to rotation for outputs 3 and 5 */
279 irot_input_x = id07 - icommon_product1;
280 irot_input_y = id34 - icommon_product2;
282 /* Apply rotation for outputs 3 and 5. */
283 temp1=xC3S5*irot_input_x;
284 temp1=DOROUND(temp1);
286 temp2=xC5S3*irot_input_y ;
287 temp2=DOROUND(temp2);
289 op[3*8] = (int16_t) (temp1 - temp2) ;
291 temp1=xC5S3*irot_input_x;
292 temp1=DOROUND(temp1);
294 temp2=xC3S5*irot_input_y;
295 temp2=DOROUND(temp2);
297 op[5*8] = (int16_t) (temp1 + temp2);
299 /* Increment data pointer for next column. */
305 OIL_DEFINE_IMPL_REF (fdct8x8theora_ref, fdct8x8theora);
311 OilFunctionClass* __oil_function_class_fdct8x8theora() {
312 return &_oil_function_class_fdct8x8theora;
320 OilFunctionImpl* __oil_function_impl_fdct8x8theora_ref() {
321 return &_oil_function_impl_fdct8x8theora_ref;
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;