2 * Simple IDCT (Alpha optimized)
4 * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
6 * based upon some outcommented C code from mpeg2dec (idct_mmx.c
7 * written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
9 * Alpha optimizations by Måns Rullgård <mans@mansr.com>
10 * and Falk Hueffner <falk@debian.org>
12 * This file is part of FFmpeg.
14 * FFmpeg is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * FFmpeg is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with FFmpeg; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "libavcodec/dsputil.h"
32 extern void (*put_pixels_clamped_axp_p
)(const DCTELEM
*block
, uint8_t *pixels
,
34 extern void (*add_pixels_clamped_axp_p
)(const DCTELEM
*block
, uint8_t *pixels
,
37 // cos(i * M_PI / 16) * sqrt(2) * (1 << 14)
38 // W4 is actually exactly 16384, but using 16383 works around
39 // accumulating rounding errors for some encoders
40 #define W1 ((int_fast32_t) 22725)
41 #define W2 ((int_fast32_t) 21407)
42 #define W3 ((int_fast32_t) 19266)
43 #define W4 ((int_fast32_t) 16383)
44 #define W5 ((int_fast32_t) 12873)
45 #define W6 ((int_fast32_t) 8867)
46 #define W7 ((int_fast32_t) 4520)
50 /* 0: all entries 0, 1: only first entry nonzero, 2: otherwise */
51 static inline int idct_row(DCTELEM
*row
)
53 int_fast32_t a0
, a1
, a2
, a3
, b0
, b1
, b2
, b3
, t
;
61 a0
= W4
* sextw(l
) + (1 << (ROW_SHIFT
- 1));
63 if (((l
& ~0xffffUL
) | r
) == 0) {
78 t
= extwl(l
, 4); /* row[2] */
87 t
= extwl(r
, 0); /* row[4] */
96 t
= extwl(r
, 4); /* row[6] */
105 t
= extwl(l
, 2); /* row[1] */
119 t
= extwl(l
, 6); /* row[3] */
129 t
= extwl(r
, 2); /* row[5] */
138 t
= extwl(r
, 6); /* row[7] */
147 row
[0] = (a0
+ b0
) >> ROW_SHIFT
;
148 row
[1] = (a1
+ b1
) >> ROW_SHIFT
;
149 row
[2] = (a2
+ b2
) >> ROW_SHIFT
;
150 row
[3] = (a3
+ b3
) >> ROW_SHIFT
;
151 row
[4] = (a3
- b3
) >> ROW_SHIFT
;
152 row
[5] = (a2
- b2
) >> ROW_SHIFT
;
153 row
[6] = (a1
- b1
) >> ROW_SHIFT
;
154 row
[7] = (a0
- b0
) >> ROW_SHIFT
;
159 static inline void idct_col(DCTELEM
*col
)
161 int_fast32_t a0
, a1
, a2
, a3
, b0
, b1
, b2
, b3
;
163 col
[0] += (1 << (COL_SHIFT
- 1)) / W4
;
165 a0
= W4
* col
[8 * 0];
166 a1
= W4
* col
[8 * 0];
167 a2
= W4
* col
[8 * 0];
168 a3
= W4
* col
[8 * 0];
171 a0
+= W2
* col
[8 * 2];
172 a1
+= W6
* col
[8 * 2];
173 a2
-= W6
* col
[8 * 2];
174 a3
-= W2
* col
[8 * 2];
178 a0
+= W4
* col
[8 * 4];
179 a1
-= W4
* col
[8 * 4];
180 a2
-= W4
* col
[8 * 4];
181 a3
+= W4
* col
[8 * 4];
185 a0
+= W6
* col
[8 * 6];
186 a1
-= W2
* col
[8 * 6];
187 a2
+= W2
* col
[8 * 6];
188 a3
-= W6
* col
[8 * 6];
192 b0
= W1
* col
[8 * 1];
193 b1
= W3
* col
[8 * 1];
194 b2
= W5
* col
[8 * 1];
195 b3
= W7
* col
[8 * 1];
204 b0
+= W3
* col
[8 * 3];
205 b1
-= W7
* col
[8 * 3];
206 b2
-= W1
* col
[8 * 3];
207 b3
-= W5
* col
[8 * 3];
211 b0
+= W5
* col
[8 * 5];
212 b1
-= W1
* col
[8 * 5];
213 b2
+= W7
* col
[8 * 5];
214 b3
+= W3
* col
[8 * 5];
218 b0
+= W7
* col
[8 * 7];
219 b1
-= W5
* col
[8 * 7];
220 b2
+= W3
* col
[8 * 7];
221 b3
-= W1
* col
[8 * 7];
224 col
[8 * 0] = (a0
+ b0
) >> COL_SHIFT
;
225 col
[8 * 7] = (a0
- b0
) >> COL_SHIFT
;
226 col
[8 * 1] = (a1
+ b1
) >> COL_SHIFT
;
227 col
[8 * 6] = (a1
- b1
) >> COL_SHIFT
;
228 col
[8 * 2] = (a2
+ b2
) >> COL_SHIFT
;
229 col
[8 * 5] = (a2
- b2
) >> COL_SHIFT
;
230 col
[8 * 3] = (a3
+ b3
) >> COL_SHIFT
;
231 col
[8 * 4] = (a3
- b3
) >> COL_SHIFT
;
234 /* If all rows but the first one are zero after row transformation,
235 all rows will be identical after column transformation. */
236 static inline void idct_col2(DCTELEM
*col
)
241 for (i
= 0; i
< 8; ++i
) {
242 int_fast32_t a0
= col
[i
] + (1 << (COL_SHIFT
- 1)) / W4
;
245 col
[i
] = a0
>> COL_SHIFT
;
248 l
= ldq(col
+ 0 * 4); r
= ldq(col
+ 1 * 4);
249 stq(l
, col
+ 2 * 4); stq(r
, col
+ 3 * 4);
250 stq(l
, col
+ 4 * 4); stq(r
, col
+ 5 * 4);
251 stq(l
, col
+ 6 * 4); stq(r
, col
+ 7 * 4);
252 stq(l
, col
+ 8 * 4); stq(r
, col
+ 9 * 4);
253 stq(l
, col
+ 10 * 4); stq(r
, col
+ 11 * 4);
254 stq(l
, col
+ 12 * 4); stq(r
, col
+ 13 * 4);
255 stq(l
, col
+ 14 * 4); stq(r
, col
+ 15 * 4);
258 void simple_idct_axp(DCTELEM
*block
)
262 int rowsZero
= 1; /* all rows except row 0 zero */
263 int rowsConstant
= 1; /* all rows consist of a constant value */
265 for (i
= 0; i
< 8; i
++) {
266 int sparseness
= idct_row(block
+ 8 * i
);
268 if (i
> 0 && sparseness
> 0)
276 } else if (rowsConstant
) {
278 for (i
= 0; i
< 8; i
+= 2) {
279 uint64_t v
= (uint16_t) block
[0];
280 uint64_t w
= (uint16_t) block
[8];
286 stq(v
, block
+ 0 * 4);
287 stq(v
, block
+ 1 * 4);
288 stq(w
, block
+ 2 * 4);
289 stq(w
, block
+ 3 * 4);
293 for (i
= 0; i
< 8; i
++)
298 void simple_idct_put_axp(uint8_t *dest
, int line_size
, DCTELEM
*block
)
300 simple_idct_axp(block
);
301 put_pixels_clamped_axp_p(block
, dest
, line_size
);
304 void simple_idct_add_axp(uint8_t *dest
, int line_size
, DCTELEM
*block
)
306 simple_idct_axp(block
);
307 add_pixels_clamped_axp_p(block
, dest
, line_size
);