4 * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
6 * This file is part of Libav.
8 * Libav is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * Libav is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 based upon some outcommented c code from mpeg2dec (idct_mmx.c
30 written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
33 #include "bit_depth_template.c"
50 #define W1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
51 #define W2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
52 #define W3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
53 #define W4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
54 #define W5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
55 #define W6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
56 #define W7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
62 #define MUL(a, b) MUL16(a, b)
63 #define MAC(a, b, c) MAC16(a, b, c)
79 #define MUL(a, b) ((a) * (b))
80 #define MAC(a, b, c) ((a) += (b) * (c))
84 #error "Unsupported bitdepth"
88 static inline void FUNC(idctRowCondDC)(DCTELEM *row)
90 int a0, a1, a2, a3, b0, b1, b2, b3;
93 #define ROW0_MASK (0xffffLL << 48 * HAVE_BIGENDIAN)
94 if (((((uint64_t *)row)[0] & ~ROW0_MASK) | ((uint64_t *)row)[1]) == 0) {
95 uint64_t temp = (row[0] << DC_SHIFT) & 0xffff;
98 ((uint64_t *)row)[0] = temp;
99 ((uint64_t *)row)[1] = temp;
103 if (!(((uint32_t*)row)[1] |
104 ((uint32_t*)row)[2] |
105 ((uint32_t*)row)[3] |
107 uint32_t temp = (row[0] << DC_SHIFT) & 0xffff;
109 ((uint32_t*)row)[0]=((uint32_t*)row)[1] =
110 ((uint32_t*)row)[2]=((uint32_t*)row)[3] = temp;
115 a0 = (W4 * row[0]) + (1 << (ROW_SHIFT - 1));
120 /* no need to optimize : gcc does it */
126 b0 = MUL(W1, row[1]);
128 b1 = MUL(W3, row[1]);
129 MAC(b1, -W7, row[3]);
130 b2 = MUL(W5, row[1]);
131 MAC(b2, -W1, row[3]);
132 b3 = MUL(W7, row[1]);
133 MAC(b3, -W5, row[3]);
135 if (AV_RN64A(row + 4)) {
136 a0 += W4*row[4] + W6*row[6];
137 a1 += - W4*row[4] - W2*row[6];
138 a2 += - W4*row[4] + W2*row[6];
139 a3 += W4*row[4] - W6*row[6];
144 MAC(b1, -W1, row[5]);
145 MAC(b1, -W5, row[7]);
151 MAC(b3, -W1, row[7]);
154 row[0] = (a0 + b0) >> ROW_SHIFT;
155 row[7] = (a0 - b0) >> ROW_SHIFT;
156 row[1] = (a1 + b1) >> ROW_SHIFT;
157 row[6] = (a1 - b1) >> ROW_SHIFT;
158 row[2] = (a2 + b2) >> ROW_SHIFT;
159 row[5] = (a2 - b2) >> ROW_SHIFT;
160 row[3] = (a3 + b3) >> ROW_SHIFT;
161 row[4] = (a3 - b3) >> ROW_SHIFT;
164 static inline void FUNC(idctSparseColPut)(pixel *dest, int line_size,
167 int a0, a1, a2, a3, b0, b1, b2, b3;
170 /* XXX: I did that only to give same values as previous code */
171 a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
181 b0 = MUL(W1, col[8*1]);
182 b1 = MUL(W3, col[8*1]);
183 b2 = MUL(W5, col[8*1]);
184 b3 = MUL(W7, col[8*1]);
186 MAC(b0, + W3, col[8*3]);
187 MAC(b1, - W7, col[8*3]);
188 MAC(b2, - W1, col[8*3]);
189 MAC(b3, - W5, col[8*3]);
199 MAC(b0, + W5, col[8*5]);
200 MAC(b1, - W1, col[8*5]);
201 MAC(b2, + W7, col[8*5]);
202 MAC(b3, + W3, col[8*5]);
213 MAC(b0, + W7, col[8*7]);
214 MAC(b1, - W5, col[8*7]);
215 MAC(b2, + W3, col[8*7]);
216 MAC(b3, - W1, col[8*7]);
219 dest[0] = CLIP((a0 + b0) >> COL_SHIFT);
221 dest[0] = CLIP((a1 + b1) >> COL_SHIFT);
223 dest[0] = CLIP((a2 + b2) >> COL_SHIFT);
225 dest[0] = CLIP((a3 + b3) >> COL_SHIFT);
227 dest[0] = CLIP((a3 - b3) >> COL_SHIFT);
229 dest[0] = CLIP((a2 - b2) >> COL_SHIFT);
231 dest[0] = CLIP((a1 - b1) >> COL_SHIFT);
233 dest[0] = CLIP((a0 - b0) >> COL_SHIFT);
236 static inline void FUNC(idctSparseColAdd)(pixel *dest, int line_size,
239 int a0, a1, a2, a3, b0, b1, b2, b3;
242 /* XXX: I did that only to give same values as previous code */
243 a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
253 b0 = MUL(W1, col[8*1]);
254 b1 = MUL(W3, col[8*1]);
255 b2 = MUL(W5, col[8*1]);
256 b3 = MUL(W7, col[8*1]);
258 MAC(b0, + W3, col[8*3]);
259 MAC(b1, - W7, col[8*3]);
260 MAC(b2, - W1, col[8*3]);
261 MAC(b3, - W5, col[8*3]);
271 MAC(b0, + W5, col[8*5]);
272 MAC(b1, - W1, col[8*5]);
273 MAC(b2, + W7, col[8*5]);
274 MAC(b3, + W3, col[8*5]);
285 MAC(b0, + W7, col[8*7]);
286 MAC(b1, - W5, col[8*7]);
287 MAC(b2, + W3, col[8*7]);
288 MAC(b3, - W1, col[8*7]);
291 dest[0] = CLIP(dest[0] + ((a0 + b0) >> COL_SHIFT));
293 dest[0] = CLIP(dest[0] + ((a1 + b1) >> COL_SHIFT));
295 dest[0] = CLIP(dest[0] + ((a2 + b2) >> COL_SHIFT));
297 dest[0] = CLIP(dest[0] + ((a3 + b3) >> COL_SHIFT));
299 dest[0] = CLIP(dest[0] + ((a3 - b3) >> COL_SHIFT));
301 dest[0] = CLIP(dest[0] + ((a2 - b2) >> COL_SHIFT));
303 dest[0] = CLIP(dest[0] + ((a1 - b1) >> COL_SHIFT));
305 dest[0] = CLIP(dest[0] + ((a0 - b0) >> COL_SHIFT));
308 static inline void FUNC(idctSparseCol)(DCTELEM *col)
310 int a0, a1, a2, a3, b0, b1, b2, b3;
312 /* XXX: I did that only to give same values as previous code */
313 a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
323 b0 = MUL(W1, col[8*1]);
324 b1 = MUL(W3, col[8*1]);
325 b2 = MUL(W5, col[8*1]);
326 b3 = MUL(W7, col[8*1]);
328 MAC(b0, + W3, col[8*3]);
329 MAC(b1, - W7, col[8*3]);
330 MAC(b2, - W1, col[8*3]);
331 MAC(b3, - W5, col[8*3]);
341 MAC(b0, + W5, col[8*5]);
342 MAC(b1, - W1, col[8*5]);
343 MAC(b2, + W7, col[8*5]);
344 MAC(b3, + W3, col[8*5]);
355 MAC(b0, + W7, col[8*7]);
356 MAC(b1, - W5, col[8*7]);
357 MAC(b2, + W3, col[8*7]);
358 MAC(b3, - W1, col[8*7]);
361 col[0 ] = ((a0 + b0) >> COL_SHIFT);
362 col[8 ] = ((a1 + b1) >> COL_SHIFT);
363 col[16] = ((a2 + b2) >> COL_SHIFT);
364 col[24] = ((a3 + b3) >> COL_SHIFT);
365 col[32] = ((a3 - b3) >> COL_SHIFT);
366 col[40] = ((a2 - b2) >> COL_SHIFT);
367 col[48] = ((a1 - b1) >> COL_SHIFT);
368 col[56] = ((a0 - b0) >> COL_SHIFT);
371 void FUNC(ff_simple_idct_put)(uint8_t *dest_, int line_size, DCTELEM *block)
373 pixel *dest = (pixel *)dest_;
376 line_size /= sizeof(pixel);
379 FUNC(idctRowCondDC)(block + i*8);
382 FUNC(idctSparseColPut)(dest + i, line_size, block + i);
385 void FUNC(ff_simple_idct_add)(uint8_t *dest_, int line_size, DCTELEM *block)
387 pixel *dest = (pixel *)dest_;
390 line_size /= sizeof(pixel);
393 FUNC(idctRowCondDC)(block + i*8);
396 FUNC(idctSparseColAdd)(dest + i, line_size, block + i);
399 void FUNC(ff_simple_idct)(DCTELEM *block)
403 FUNC(idctRowCondDC)(block + i*8);
406 FUNC(idctSparseCol)(block + i);