Remove a number of unnecessary dsputil.h #includes
[libav.git] / libavcodec / vc1dsp.c
1 /*
2 * VC-1 and WMV3 decoder - DSP functions
3 * Copyright (c) 2006 Konstantin Shishkov
4 *
5 * This file is part of Libav.
6 *
7 * Libav is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * Libav is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * VC-1 and WMV3 decoder
25 *
26 */
27
28 #include "libavutil/common.h"
29 #include "dsputil.h"
30 #include "h264chroma.h"
31 #include "vc1dsp.h"
32
33 /* Apply overlap transform to horizontal edge */
34 static void vc1_v_overlap_c(uint8_t *src, int stride)
35 {
36 int i;
37 int a, b, c, d;
38 int d1, d2;
39 int rnd = 1;
40 for (i = 0; i < 8; i++) {
41 a = src[-2 * stride];
42 b = src[-stride];
43 c = src[0];
44 d = src[stride];
45 d1 = (a - d + 3 + rnd) >> 3;
46 d2 = (a - d + b - c + 4 - rnd) >> 3;
47
48 src[-2 * stride] = a - d1;
49 src[-stride] = av_clip_uint8(b - d2);
50 src[0] = av_clip_uint8(c + d2);
51 src[stride] = d + d1;
52 src++;
53 rnd = !rnd;
54 }
55 }
56
57 /* Apply overlap transform to vertical edge */
58 static void vc1_h_overlap_c(uint8_t *src, int stride)
59 {
60 int i;
61 int a, b, c, d;
62 int d1, d2;
63 int rnd = 1;
64 for (i = 0; i < 8; i++) {
65 a = src[-2];
66 b = src[-1];
67 c = src[0];
68 d = src[1];
69 d1 = (a - d + 3 + rnd) >> 3;
70 d2 = (a - d + b - c + 4 - rnd) >> 3;
71
72 src[-2] = a - d1;
73 src[-1] = av_clip_uint8(b - d2);
74 src[0] = av_clip_uint8(c + d2);
75 src[1] = d + d1;
76 src += stride;
77 rnd = !rnd;
78 }
79 }
80
81 static void vc1_v_s_overlap_c(int16_t *top, int16_t *bottom)
82 {
83 int i;
84 int a, b, c, d;
85 int d1, d2;
86 int rnd1 = 4, rnd2 = 3;
87 for (i = 0; i < 8; i++) {
88 a = top[48];
89 b = top[56];
90 c = bottom[0];
91 d = bottom[8];
92 d1 = a - d;
93 d2 = a - d + b - c;
94
95 top[48] = ((a << 3) - d1 + rnd1) >> 3;
96 top[56] = ((b << 3) - d2 + rnd2) >> 3;
97 bottom[0] = ((c << 3) + d2 + rnd1) >> 3;
98 bottom[8] = ((d << 3) + d1 + rnd2) >> 3;
99
100 bottom++;
101 top++;
102 rnd2 = 7 - rnd2;
103 rnd1 = 7 - rnd1;
104 }
105 }
106
107 static void vc1_h_s_overlap_c(int16_t *left, int16_t *right)
108 {
109 int i;
110 int a, b, c, d;
111 int d1, d2;
112 int rnd1 = 4, rnd2 = 3;
113 for (i = 0; i < 8; i++) {
114 a = left[6];
115 b = left[7];
116 c = right[0];
117 d = right[1];
118 d1 = a - d;
119 d2 = a - d + b - c;
120
121 left[6] = ((a << 3) - d1 + rnd1) >> 3;
122 left[7] = ((b << 3) - d2 + rnd2) >> 3;
123 right[0] = ((c << 3) + d2 + rnd1) >> 3;
124 right[1] = ((d << 3) + d1 + rnd2) >> 3;
125
126 right += 8;
127 left += 8;
128 rnd2 = 7 - rnd2;
129 rnd1 = 7 - rnd1;
130 }
131 }
132
133 /**
134 * VC-1 in-loop deblocking filter for one line
135 * @param src source block type
136 * @param stride block stride
137 * @param pq block quantizer
138 * @return whether other 3 pairs should be filtered or not
139 * @see 8.6
140 */
141 static av_always_inline int vc1_filter_line(uint8_t *src, int stride, int pq)
142 {
143 int a0 = (2 * (src[-2 * stride] - src[1 * stride]) -
144 5 * (src[-1 * stride] - src[0 * stride]) + 4) >> 3;
145 int a0_sign = a0 >> 31; /* Store sign */
146
147 a0 = (a0 ^ a0_sign) - a0_sign; /* a0 = FFABS(a0); */
148 if (a0 < pq) {
149 int a1 = FFABS((2 * (src[-4 * stride] - src[-1 * stride]) -
150 5 * (src[-3 * stride] - src[-2 * stride]) + 4) >> 3);
151 int a2 = FFABS((2 * (src[ 0 * stride] - src[ 3 * stride]) -
152 5 * (src[ 1 * stride] - src[ 2 * stride]) + 4) >> 3);
153 if (a1 < a0 || a2 < a0) {
154 int clip = src[-1 * stride] - src[0 * stride];
155 int clip_sign = clip >> 31;
156
157 clip = ((clip ^ clip_sign) - clip_sign) >> 1;
158 if (clip) {
159 int a3 = FFMIN(a1, a2);
160 int d = 5 * (a3 - a0);
161 int d_sign = (d >> 31);
162
163 d = ((d ^ d_sign) - d_sign) >> 3;
164 d_sign ^= a0_sign;
165
166 if (d_sign ^ clip_sign)
167 d = 0;
168 else {
169 d = FFMIN(d, clip);
170 d = (d ^ d_sign) - d_sign; /* Restore sign */
171 src[-1 * stride] = av_clip_uint8(src[-1 * stride] - d);
172 src[ 0 * stride] = av_clip_uint8(src[ 0 * stride] + d);
173 }
174 return 1;
175 }
176 }
177 }
178 return 0;
179 }
180
181 /**
182 * VC-1 in-loop deblocking filter
183 * @param src source block type
184 * @param step distance between horizontally adjacent elements
185 * @param stride distance between vertically adjacent elements
186 * @param len edge length to filter (4 or 8 pixels)
187 * @param pq block quantizer
188 * @see 8.6
189 */
190 static inline void vc1_loop_filter(uint8_t *src, int step, int stride,
191 int len, int pq)
192 {
193 int i;
194 int filt3;
195
196 for (i = 0; i < len; i += 4) {
197 filt3 = vc1_filter_line(src + 2 * step, stride, pq);
198 if (filt3) {
199 vc1_filter_line(src + 0 * step, stride, pq);
200 vc1_filter_line(src + 1 * step, stride, pq);
201 vc1_filter_line(src + 3 * step, stride, pq);
202 }
203 src += step * 4;
204 }
205 }
206
207 static void vc1_v_loop_filter4_c(uint8_t *src, int stride, int pq)
208 {
209 vc1_loop_filter(src, 1, stride, 4, pq);
210 }
211
212 static void vc1_h_loop_filter4_c(uint8_t *src, int stride, int pq)
213 {
214 vc1_loop_filter(src, stride, 1, 4, pq);
215 }
216
217 static void vc1_v_loop_filter8_c(uint8_t *src, int stride, int pq)
218 {
219 vc1_loop_filter(src, 1, stride, 8, pq);
220 }
221
222 static void vc1_h_loop_filter8_c(uint8_t *src, int stride, int pq)
223 {
224 vc1_loop_filter(src, stride, 1, 8, pq);
225 }
226
227 static void vc1_v_loop_filter16_c(uint8_t *src, int stride, int pq)
228 {
229 vc1_loop_filter(src, 1, stride, 16, pq);
230 }
231
232 static void vc1_h_loop_filter16_c(uint8_t *src, int stride, int pq)
233 {
234 vc1_loop_filter(src, stride, 1, 16, pq);
235 }
236
237 /* Do inverse transform on 8x8 block */
238 static void vc1_inv_trans_8x8_dc_c(uint8_t *dest, int linesize, int16_t *block)
239 {
240 int i;
241 int dc = block[0];
242
243 dc = (3 * dc + 1) >> 1;
244 dc = (3 * dc + 16) >> 5;
245
246 for (i = 0; i < 8; i++) {
247 dest[0] = av_clip_uint8(dest[0] + dc);
248 dest[1] = av_clip_uint8(dest[1] + dc);
249 dest[2] = av_clip_uint8(dest[2] + dc);
250 dest[3] = av_clip_uint8(dest[3] + dc);
251 dest[4] = av_clip_uint8(dest[4] + dc);
252 dest[5] = av_clip_uint8(dest[5] + dc);
253 dest[6] = av_clip_uint8(dest[6] + dc);
254 dest[7] = av_clip_uint8(dest[7] + dc);
255 dest += linesize;
256 }
257 }
258
259 static void vc1_inv_trans_8x8_c(int16_t block[64])
260 {
261 int i;
262 register int t1, t2, t3, t4, t5, t6, t7, t8;
263 int16_t *src, *dst, temp[64];
264
265 src = block;
266 dst = temp;
267 for (i = 0; i < 8; i++) {
268 t1 = 12 * (src[ 0] + src[32]) + 4;
269 t2 = 12 * (src[ 0] - src[32]) + 4;
270 t3 = 16 * src[16] + 6 * src[48];
271 t4 = 6 * src[16] - 16 * src[48];
272
273 t5 = t1 + t3;
274 t6 = t2 + t4;
275 t7 = t2 - t4;
276 t8 = t1 - t3;
277
278 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
279 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
280 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
281 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
282
283 dst[0] = (t5 + t1) >> 3;
284 dst[1] = (t6 + t2) >> 3;
285 dst[2] = (t7 + t3) >> 3;
286 dst[3] = (t8 + t4) >> 3;
287 dst[4] = (t8 - t4) >> 3;
288 dst[5] = (t7 - t3) >> 3;
289 dst[6] = (t6 - t2) >> 3;
290 dst[7] = (t5 - t1) >> 3;
291
292 src += 1;
293 dst += 8;
294 }
295
296 src = temp;
297 dst = block;
298 for (i = 0; i < 8; i++) {
299 t1 = 12 * (src[ 0] + src[32]) + 64;
300 t2 = 12 * (src[ 0] - src[32]) + 64;
301 t3 = 16 * src[16] + 6 * src[48];
302 t4 = 6 * src[16] - 16 * src[48];
303
304 t5 = t1 + t3;
305 t6 = t2 + t4;
306 t7 = t2 - t4;
307 t8 = t1 - t3;
308
309 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
310 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
311 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
312 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
313
314 dst[ 0] = (t5 + t1) >> 7;
315 dst[ 8] = (t6 + t2) >> 7;
316 dst[16] = (t7 + t3) >> 7;
317 dst[24] = (t8 + t4) >> 7;
318 dst[32] = (t8 - t4 + 1) >> 7;
319 dst[40] = (t7 - t3 + 1) >> 7;
320 dst[48] = (t6 - t2 + 1) >> 7;
321 dst[56] = (t5 - t1 + 1) >> 7;
322
323 src++;
324 dst++;
325 }
326 }
327
328 /* Do inverse transform on 8x4 part of block */
329 static void vc1_inv_trans_8x4_dc_c(uint8_t *dest, int linesize, int16_t *block)
330 {
331 int i;
332 int dc = block[0];
333
334 dc = (3 * dc + 1) >> 1;
335 dc = (17 * dc + 64) >> 7;
336
337 for (i = 0; i < 4; i++) {
338 dest[0] = av_clip_uint8(dest[0] + dc);
339 dest[1] = av_clip_uint8(dest[1] + dc);
340 dest[2] = av_clip_uint8(dest[2] + dc);
341 dest[3] = av_clip_uint8(dest[3] + dc);
342 dest[4] = av_clip_uint8(dest[4] + dc);
343 dest[5] = av_clip_uint8(dest[5] + dc);
344 dest[6] = av_clip_uint8(dest[6] + dc);
345 dest[7] = av_clip_uint8(dest[7] + dc);
346 dest += linesize;
347 }
348 }
349
350 static void vc1_inv_trans_8x4_c(uint8_t *dest, int linesize, int16_t *block)
351 {
352 int i;
353 register int t1, t2, t3, t4, t5, t6, t7, t8;
354 int16_t *src, *dst;
355
356 src = block;
357 dst = block;
358
359 for (i = 0; i < 4; i++) {
360 t1 = 12 * (src[0] + src[4]) + 4;
361 t2 = 12 * (src[0] - src[4]) + 4;
362 t3 = 16 * src[2] + 6 * src[6];
363 t4 = 6 * src[2] - 16 * src[6];
364
365 t5 = t1 + t3;
366 t6 = t2 + t4;
367 t7 = t2 - t4;
368 t8 = t1 - t3;
369
370 t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
371 t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
372 t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
373 t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
374
375 dst[0] = (t5 + t1) >> 3;
376 dst[1] = (t6 + t2) >> 3;
377 dst[2] = (t7 + t3) >> 3;
378 dst[3] = (t8 + t4) >> 3;
379 dst[4] = (t8 - t4) >> 3;
380 dst[5] = (t7 - t3) >> 3;
381 dst[6] = (t6 - t2) >> 3;
382 dst[7] = (t5 - t1) >> 3;
383
384 src += 8;
385 dst += 8;
386 }
387
388 src = block;
389 for (i = 0; i < 8; i++) {
390 t1 = 17 * (src[ 0] + src[16]) + 64;
391 t2 = 17 * (src[ 0] - src[16]) + 64;
392 t3 = 22 * src[ 8] + 10 * src[24];
393 t4 = 22 * src[24] - 10 * src[ 8];
394
395 dest[0 * linesize] = av_clip_uint8(dest[0 * linesize] + ((t1 + t3) >> 7));
396 dest[1 * linesize] = av_clip_uint8(dest[1 * linesize] + ((t2 - t4) >> 7));
397 dest[2 * linesize] = av_clip_uint8(dest[2 * linesize] + ((t2 + t4) >> 7));
398 dest[3 * linesize] = av_clip_uint8(dest[3 * linesize] + ((t1 - t3) >> 7));
399
400 src++;
401 dest++;
402 }
403 }
404
405 /* Do inverse transform on 4x8 parts of block */
406 static void vc1_inv_trans_4x8_dc_c(uint8_t *dest, int linesize, int16_t *block)
407 {
408 int i;
409 int dc = block[0];
410
411 dc = (17 * dc + 4) >> 3;
412 dc = (12 * dc + 64) >> 7;
413
414 for (i = 0; i < 8; i++) {
415 dest[0] = av_clip_uint8(dest[0] + dc);
416 dest[1] = av_clip_uint8(dest[1] + dc);
417 dest[2] = av_clip_uint8(dest[2] + dc);
418 dest[3] = av_clip_uint8(dest[3] + dc);
419 dest += linesize;
420 }
421 }
422
423 static void vc1_inv_trans_4x8_c(uint8_t *dest, int linesize, int16_t *block)
424 {
425 int i;
426 register int t1, t2, t3, t4, t5, t6, t7, t8;
427 int16_t *src, *dst;
428
429 src = block;
430 dst = block;
431
432 for (i = 0; i < 8; i++) {
433 t1 = 17 * (src[0] + src[2]) + 4;
434 t2 = 17 * (src[0] - src[2]) + 4;
435 t3 = 22 * src[1] + 10 * src[3];
436 t4 = 22 * src[3] - 10 * src[1];
437
438 dst[0] = (t1 + t3) >> 3;
439 dst[1] = (t2 - t4) >> 3;
440 dst[2] = (t2 + t4) >> 3;
441 dst[3] = (t1 - t3) >> 3;
442
443 src += 8;
444 dst += 8;
445 }
446
447 src = block;
448 for (i = 0; i < 4; i++) {
449 t1 = 12 * (src[ 0] + src[32]) + 64;
450 t2 = 12 * (src[ 0] - src[32]) + 64;
451 t3 = 16 * src[16] + 6 * src[48];
452 t4 = 6 * src[16] - 16 * src[48];
453
454 t5 = t1 + t3;
455 t6 = t2 + t4;
456 t7 = t2 - t4;
457 t8 = t1 - t3;
458
459 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
460 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
461 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
462 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
463
464 dest[0 * linesize] = av_clip_uint8(dest[0 * linesize] + ((t5 + t1) >> 7));
465 dest[1 * linesize] = av_clip_uint8(dest[1 * linesize] + ((t6 + t2) >> 7));
466 dest[2 * linesize] = av_clip_uint8(dest[2 * linesize] + ((t7 + t3) >> 7));
467 dest[3 * linesize] = av_clip_uint8(dest[3 * linesize] + ((t8 + t4) >> 7));
468 dest[4 * linesize] = av_clip_uint8(dest[4 * linesize] + ((t8 - t4 + 1) >> 7));
469 dest[5 * linesize] = av_clip_uint8(dest[5 * linesize] + ((t7 - t3 + 1) >> 7));
470 dest[6 * linesize] = av_clip_uint8(dest[6 * linesize] + ((t6 - t2 + 1) >> 7));
471 dest[7 * linesize] = av_clip_uint8(dest[7 * linesize] + ((t5 - t1 + 1) >> 7));
472
473 src++;
474 dest++;
475 }
476 }
477
478 /* Do inverse transform on 4x4 part of block */
479 static void vc1_inv_trans_4x4_dc_c(uint8_t *dest, int linesize, int16_t *block)
480 {
481 int i;
482 int dc = block[0];
483
484 dc = (17 * dc + 4) >> 3;
485 dc = (17 * dc + 64) >> 7;
486
487 for (i = 0; i < 4; i++) {
488 dest[0] = av_clip_uint8(dest[0] + dc);
489 dest[1] = av_clip_uint8(dest[1] + dc);
490 dest[2] = av_clip_uint8(dest[2] + dc);
491 dest[3] = av_clip_uint8(dest[3] + dc);
492 dest += linesize;
493 }
494 }
495
496 static void vc1_inv_trans_4x4_c(uint8_t *dest, int linesize, int16_t *block)
497 {
498 int i;
499 register int t1, t2, t3, t4;
500 int16_t *src, *dst;
501
502 src = block;
503 dst = block;
504 for (i = 0; i < 4; i++) {
505 t1 = 17 * (src[0] + src[2]) + 4;
506 t2 = 17 * (src[0] - src[2]) + 4;
507 t3 = 22 * src[1] + 10 * src[3];
508 t4 = 22 * src[3] - 10 * src[1];
509
510 dst[0] = (t1 + t3) >> 3;
511 dst[1] = (t2 - t4) >> 3;
512 dst[2] = (t2 + t4) >> 3;
513 dst[3] = (t1 - t3) >> 3;
514
515 src += 8;
516 dst += 8;
517 }
518
519 src = block;
520 for (i = 0; i < 4; i++) {
521 t1 = 17 * (src[0] + src[16]) + 64;
522 t2 = 17 * (src[0] - src[16]) + 64;
523 t3 = 22 * src[8] + 10 * src[24];
524 t4 = 22 * src[24] - 10 * src[8];
525
526 dest[0 * linesize] = av_clip_uint8(dest[0 * linesize] + ((t1 + t3) >> 7));
527 dest[1 * linesize] = av_clip_uint8(dest[1 * linesize] + ((t2 - t4) >> 7));
528 dest[2 * linesize] = av_clip_uint8(dest[2 * linesize] + ((t2 + t4) >> 7));
529 dest[3 * linesize] = av_clip_uint8(dest[3 * linesize] + ((t1 - t3) >> 7));
530
531 src++;
532 dest++;
533 }
534 }
535
536 /* motion compensation functions */
537
538 /* Filter in case of 2 filters */
539 #define VC1_MSPEL_FILTER_16B(DIR, TYPE) \
540 static av_always_inline int vc1_mspel_ ## DIR ## _filter_16bits(const TYPE *src, \
541 int stride, \
542 int mode) \
543 { \
544 switch(mode) { \
545 case 0: /* no shift - should not occur */ \
546 return 0; \
547 case 1: /* 1/4 shift */ \
548 return -4 * src[-stride] + 53 * src[0] + \
549 18 * src[stride] - 3 * src[stride * 2]; \
550 case 2: /* 1/2 shift */ \
551 return -1 * src[-stride] + 9 * src[0] + \
552 9 * src[stride] - 1 * src[stride * 2]; \
553 case 3: /* 3/4 shift */ \
554 return -3 * src[-stride] + 18 * src[0] + \
555 53 * src[stride] - 4 * src[stride * 2]; \
556 } \
557 return 0; /* should not occur */ \
558 }
559
560 VC1_MSPEL_FILTER_16B(ver, uint8_t)
561 VC1_MSPEL_FILTER_16B(hor, int16_t)
562
563 /* Filter used to interpolate fractional pel values */
564 static av_always_inline int vc1_mspel_filter(const uint8_t *src, int stride,
565 int mode, int r)
566 {
567 switch (mode) {
568 case 0: // no shift
569 return src[0];
570 case 1: // 1/4 shift
571 return (-4 * src[-stride] + 53 * src[0] +
572 18 * src[stride] - 3 * src[stride * 2] + 32 - r) >> 6;
573 case 2: // 1/2 shift
574 return (-1 * src[-stride] + 9 * src[0] +
575 9 * src[stride] - 1 * src[stride * 2] + 8 - r) >> 4;
576 case 3: // 3/4 shift
577 return (-3 * src[-stride] + 18 * src[0] +
578 53 * src[stride] - 4 * src[stride * 2] + 32 - r) >> 6;
579 }
580 return 0; // should not occur
581 }
582
583 /* Function used to do motion compensation with bicubic interpolation */
584 #define VC1_MSPEL_MC(OP, OPNAME) \
585 static av_always_inline void OPNAME ## vc1_mspel_mc(uint8_t *dst, \
586 const uint8_t *src, \
587 int stride, \
588 int hmode, \
589 int vmode, \
590 int rnd) \
591 { \
592 int i, j; \
593 \
594 if (vmode) { /* Horizontal filter to apply */ \
595 int r; \
596 \
597 if (hmode) { /* Vertical filter to apply, output to tmp */ \
598 static const int shift_value[] = { 0, 5, 1, 5 }; \
599 int shift = (shift_value[hmode] + shift_value[vmode]) >> 1; \
600 int16_t tmp[11 * 8], *tptr = tmp; \
601 \
602 r = (1 << (shift - 1)) + rnd - 1; \
603 \
604 src -= 1; \
605 for (j = 0; j < 8; j++) { \
606 for (i = 0; i < 11; i++) \
607 tptr[i] = (vc1_mspel_ver_filter_16bits(src + i, stride, vmode) + r) >> shift; \
608 src += stride; \
609 tptr += 11; \
610 } \
611 \
612 r = 64 - rnd; \
613 tptr = tmp + 1; \
614 for (j = 0; j < 8; j++) { \
615 for (i = 0; i < 8; i++) \
616 OP(dst[i], (vc1_mspel_hor_filter_16bits(tptr + i, 1, hmode) + r) >> 7); \
617 dst += stride; \
618 tptr += 11; \
619 } \
620 \
621 return; \
622 } else { /* No horizontal filter, output 8 lines to dst */ \
623 r = 1 - rnd; \
624 \
625 for (j = 0; j < 8; j++) { \
626 for (i = 0; i < 8; i++) \
627 OP(dst[i], vc1_mspel_filter(src + i, stride, vmode, r)); \
628 src += stride; \
629 dst += stride; \
630 } \
631 return; \
632 } \
633 } \
634 \
635 /* Horizontal mode with no vertical mode */ \
636 for (j = 0; j < 8; j++) { \
637 for (i = 0; i < 8; i++) \
638 OP(dst[i], vc1_mspel_filter(src + i, 1, hmode, rnd)); \
639 dst += stride; \
640 src += stride; \
641 } \
642 }
643
644 #define op_put(a, b) a = av_clip_uint8(b)
645 #define op_avg(a, b) a = (a + av_clip_uint8(b) + 1) >> 1
646
647 VC1_MSPEL_MC(op_put, put_)
648 VC1_MSPEL_MC(op_avg, avg_)
649
650 /* pixel functions - really are entry points to vc1_mspel_mc */
651
652 #define PUT_VC1_MSPEL(a, b) \
653 static void put_vc1_mspel_mc ## a ## b ## _c(uint8_t *dst, \
654 const uint8_t *src, \
655 ptrdiff_t stride, int rnd) \
656 { \
657 put_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
658 } \
659 static void avg_vc1_mspel_mc ## a ## b ## _c(uint8_t *dst, \
660 const uint8_t *src, \
661 ptrdiff_t stride, int rnd) \
662 { \
663 avg_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
664 }
665
666 PUT_VC1_MSPEL(1, 0)
667 PUT_VC1_MSPEL(2, 0)
668 PUT_VC1_MSPEL(3, 0)
669
670 PUT_VC1_MSPEL(0, 1)
671 PUT_VC1_MSPEL(1, 1)
672 PUT_VC1_MSPEL(2, 1)
673 PUT_VC1_MSPEL(3, 1)
674
675 PUT_VC1_MSPEL(0, 2)
676 PUT_VC1_MSPEL(1, 2)
677 PUT_VC1_MSPEL(2, 2)
678 PUT_VC1_MSPEL(3, 2)
679
680 PUT_VC1_MSPEL(0, 3)
681 PUT_VC1_MSPEL(1, 3)
682 PUT_VC1_MSPEL(2, 3)
683 PUT_VC1_MSPEL(3, 3)
684
685 #define chroma_mc(a) \
686 ((A * src[a] + B * src[a + 1] + \
687 C * src[stride + a] + D * src[stride + a + 1] + 32 - 4) >> 6)
688 static void put_no_rnd_vc1_chroma_mc8_c(uint8_t *dst /* align 8 */,
689 uint8_t *src /* align 1 */,
690 int stride, int h, int x, int y)
691 {
692 const int A = (8 - x) * (8 - y);
693 const int B = (x) * (8 - y);
694 const int C = (8 - x) * (y);
695 const int D = (x) * (y);
696 int i;
697
698 assert(x < 8 && y < 8 && x >= 0 && y >= 0);
699
700 for (i = 0; i < h; i++) {
701 dst[0] = chroma_mc(0);
702 dst[1] = chroma_mc(1);
703 dst[2] = chroma_mc(2);
704 dst[3] = chroma_mc(3);
705 dst[4] = chroma_mc(4);
706 dst[5] = chroma_mc(5);
707 dst[6] = chroma_mc(6);
708 dst[7] = chroma_mc(7);
709 dst += stride;
710 src += stride;
711 }
712 }
713
714 static void put_no_rnd_vc1_chroma_mc4_c(uint8_t *dst, uint8_t *src,
715 int stride, int h, int x, int y)
716 {
717 const int A = (8 - x) * (8 - y);
718 const int B = (x) * (8 - y);
719 const int C = (8 - x) * (y);
720 const int D = (x) * (y);
721 int i;
722
723 assert(x < 8 && y < 8 && x >= 0 && y >= 0);
724
725 for (i = 0; i < h; i++) {
726 dst[0] = chroma_mc(0);
727 dst[1] = chroma_mc(1);
728 dst[2] = chroma_mc(2);
729 dst[3] = chroma_mc(3);
730 dst += stride;
731 src += stride;
732 }
733 }
734
735 #define avg2(a, b) (((a) + (b) + 1) >> 1)
736 static void avg_no_rnd_vc1_chroma_mc8_c(uint8_t *dst /* align 8 */,
737 uint8_t *src /* align 1 */,
738 int stride, int h, int x, int y)
739 {
740 const int A = (8 - x) * (8 - y);
741 const int B = (x) * (8 - y);
742 const int C = (8 - x) * (y);
743 const int D = (x) * (y);
744 int i;
745
746 assert(x < 8 && y < 8 && x >= 0 && y >= 0);
747
748 for (i = 0; i < h; i++) {
749 dst[0] = avg2(dst[0], chroma_mc(0));
750 dst[1] = avg2(dst[1], chroma_mc(1));
751 dst[2] = avg2(dst[2], chroma_mc(2));
752 dst[3] = avg2(dst[3], chroma_mc(3));
753 dst[4] = avg2(dst[4], chroma_mc(4));
754 dst[5] = avg2(dst[5], chroma_mc(5));
755 dst[6] = avg2(dst[6], chroma_mc(6));
756 dst[7] = avg2(dst[7], chroma_mc(7));
757 dst += stride;
758 src += stride;
759 }
760 }
761
762 static void avg_no_rnd_vc1_chroma_mc4_c(uint8_t *dst /* align 8 */,
763 uint8_t *src /* align 1 */,
764 int stride, int h, int x, int y)
765 {
766 const int A = (8 - x) * (8 - y);
767 const int B = ( x) * (8 - y);
768 const int C = (8 - x) * ( y);
769 const int D = ( x) * ( y);
770 int i;
771
772 assert(x < 8 && y < 8 && x >= 0 && y >= 0);
773
774 for (i = 0; i < h; i++) {
775 dst[0] = avg2(dst[0], chroma_mc(0));
776 dst[1] = avg2(dst[1], chroma_mc(1));
777 dst[2] = avg2(dst[2], chroma_mc(2));
778 dst[3] = avg2(dst[3], chroma_mc(3));
779 dst += stride;
780 src += stride;
781 }
782 }
783
784 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
785
786 static void sprite_h_c(uint8_t *dst, const uint8_t *src, int offset,
787 int advance, int count)
788 {
789 while (count--) {
790 int a = src[(offset >> 16)];
791 int b = src[(offset >> 16) + 1];
792 *dst++ = a + ((b - a) * (offset & 0xFFFF) >> 16);
793 offset += advance;
794 }
795 }
796
797 static av_always_inline void sprite_v_template(uint8_t *dst,
798 const uint8_t *src1a,
799 const uint8_t *src1b,
800 int offset1,
801 int two_sprites,
802 const uint8_t *src2a,
803 const uint8_t *src2b,
804 int offset2,
805 int alpha, int scaled,
806 int width)
807 {
808 int a1, b1, a2, b2;
809 while (width--) {
810 a1 = *src1a++;
811 if (scaled) {
812 b1 = *src1b++;
813 a1 = a1 + ((b1 - a1) * offset1 >> 16);
814 }
815 if (two_sprites) {
816 a2 = *src2a++;
817 if (scaled > 1) {
818 b2 = *src2b++;
819 a2 = a2 + ((b2 - a2) * offset2 >> 16);
820 }
821 a1 = a1 + ((a2 - a1) * alpha >> 16);
822 }
823 *dst++ = a1;
824 }
825 }
826
827 static void sprite_v_single_c(uint8_t *dst, const uint8_t *src1a,
828 const uint8_t *src1b,
829 int offset, int width)
830 {
831 sprite_v_template(dst, src1a, src1b, offset, 0, NULL, NULL, 0, 0, 1, width);
832 }
833
834 static void sprite_v_double_noscale_c(uint8_t *dst, const uint8_t *src1a,
835 const uint8_t *src2a,
836 int alpha, int width)
837 {
838 sprite_v_template(dst, src1a, NULL, 0, 1, src2a, NULL, 0, alpha, 0, width);
839 }
840
841 static void sprite_v_double_onescale_c(uint8_t *dst,
842 const uint8_t *src1a,
843 const uint8_t *src1b,
844 int offset1,
845 const uint8_t *src2a,
846 int alpha, int width)
847 {
848 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, NULL, 0, alpha, 1,
849 width);
850 }
851
852 static void sprite_v_double_twoscale_c(uint8_t *dst,
853 const uint8_t *src1a,
854 const uint8_t *src1b,
855 int offset1,
856 const uint8_t *src2a,
857 const uint8_t *src2b,
858 int offset2,
859 int alpha,
860 int width)
861 {
862 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, src2b, offset2,
863 alpha, 2, width);
864 }
865
866 #endif /* CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER */
867
868 av_cold void ff_vc1dsp_init(VC1DSPContext *dsp)
869 {
870 dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c;
871 dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c;
872 dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_c;
873 dsp->vc1_inv_trans_4x4 = vc1_inv_trans_4x4_c;
874 dsp->vc1_inv_trans_8x8_dc = vc1_inv_trans_8x8_dc_c;
875 dsp->vc1_inv_trans_4x8_dc = vc1_inv_trans_4x8_dc_c;
876 dsp->vc1_inv_trans_8x4_dc = vc1_inv_trans_8x4_dc_c;
877 dsp->vc1_inv_trans_4x4_dc = vc1_inv_trans_4x4_dc_c;
878
879 dsp->vc1_h_overlap = vc1_h_overlap_c;
880 dsp->vc1_v_overlap = vc1_v_overlap_c;
881 dsp->vc1_h_s_overlap = vc1_h_s_overlap_c;
882 dsp->vc1_v_s_overlap = vc1_v_s_overlap_c;
883
884 dsp->vc1_v_loop_filter4 = vc1_v_loop_filter4_c;
885 dsp->vc1_h_loop_filter4 = vc1_h_loop_filter4_c;
886 dsp->vc1_v_loop_filter8 = vc1_v_loop_filter8_c;
887 dsp->vc1_h_loop_filter8 = vc1_h_loop_filter8_c;
888 dsp->vc1_v_loop_filter16 = vc1_v_loop_filter16_c;
889 dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_c;
890
891 dsp->put_vc1_mspel_pixels_tab[0] = ff_put_pixels8x8_c;
892 dsp->put_vc1_mspel_pixels_tab[1] = put_vc1_mspel_mc10_c;
893 dsp->put_vc1_mspel_pixels_tab[2] = put_vc1_mspel_mc20_c;
894 dsp->put_vc1_mspel_pixels_tab[3] = put_vc1_mspel_mc30_c;
895 dsp->put_vc1_mspel_pixels_tab[4] = put_vc1_mspel_mc01_c;
896 dsp->put_vc1_mspel_pixels_tab[5] = put_vc1_mspel_mc11_c;
897 dsp->put_vc1_mspel_pixels_tab[6] = put_vc1_mspel_mc21_c;
898 dsp->put_vc1_mspel_pixels_tab[7] = put_vc1_mspel_mc31_c;
899 dsp->put_vc1_mspel_pixels_tab[8] = put_vc1_mspel_mc02_c;
900 dsp->put_vc1_mspel_pixels_tab[9] = put_vc1_mspel_mc12_c;
901 dsp->put_vc1_mspel_pixels_tab[10] = put_vc1_mspel_mc22_c;
902 dsp->put_vc1_mspel_pixels_tab[11] = put_vc1_mspel_mc32_c;
903 dsp->put_vc1_mspel_pixels_tab[12] = put_vc1_mspel_mc03_c;
904 dsp->put_vc1_mspel_pixels_tab[13] = put_vc1_mspel_mc13_c;
905 dsp->put_vc1_mspel_pixels_tab[14] = put_vc1_mspel_mc23_c;
906 dsp->put_vc1_mspel_pixels_tab[15] = put_vc1_mspel_mc33_c;
907
908 dsp->avg_vc1_mspel_pixels_tab[0] = ff_avg_pixels8x8_c;
909 dsp->avg_vc1_mspel_pixels_tab[1] = avg_vc1_mspel_mc10_c;
910 dsp->avg_vc1_mspel_pixels_tab[2] = avg_vc1_mspel_mc20_c;
911 dsp->avg_vc1_mspel_pixels_tab[3] = avg_vc1_mspel_mc30_c;
912 dsp->avg_vc1_mspel_pixels_tab[4] = avg_vc1_mspel_mc01_c;
913 dsp->avg_vc1_mspel_pixels_tab[5] = avg_vc1_mspel_mc11_c;
914 dsp->avg_vc1_mspel_pixels_tab[6] = avg_vc1_mspel_mc21_c;
915 dsp->avg_vc1_mspel_pixels_tab[7] = avg_vc1_mspel_mc31_c;
916 dsp->avg_vc1_mspel_pixels_tab[8] = avg_vc1_mspel_mc02_c;
917 dsp->avg_vc1_mspel_pixels_tab[9] = avg_vc1_mspel_mc12_c;
918 dsp->avg_vc1_mspel_pixels_tab[10] = avg_vc1_mspel_mc22_c;
919 dsp->avg_vc1_mspel_pixels_tab[11] = avg_vc1_mspel_mc32_c;
920 dsp->avg_vc1_mspel_pixels_tab[12] = avg_vc1_mspel_mc03_c;
921 dsp->avg_vc1_mspel_pixels_tab[13] = avg_vc1_mspel_mc13_c;
922 dsp->avg_vc1_mspel_pixels_tab[14] = avg_vc1_mspel_mc23_c;
923 dsp->avg_vc1_mspel_pixels_tab[15] = avg_vc1_mspel_mc33_c;
924
925 dsp->put_no_rnd_vc1_chroma_pixels_tab[0] = put_no_rnd_vc1_chroma_mc8_c;
926 dsp->avg_no_rnd_vc1_chroma_pixels_tab[0] = avg_no_rnd_vc1_chroma_mc8_c;
927 dsp->put_no_rnd_vc1_chroma_pixels_tab[1] = put_no_rnd_vc1_chroma_mc4_c;
928 dsp->avg_no_rnd_vc1_chroma_pixels_tab[1] = avg_no_rnd_vc1_chroma_mc4_c;
929
930 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
931 dsp->sprite_h = sprite_h_c;
932 dsp->sprite_v_single = sprite_v_single_c;
933 dsp->sprite_v_double_noscale = sprite_v_double_noscale_c;
934 dsp->sprite_v_double_onescale = sprite_v_double_onescale_c;
935 dsp->sprite_v_double_twoscale = sprite_v_double_twoscale_c;
936 #endif /* CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER */
937
938 if (ARCH_AARCH64)
939 ff_vc1dsp_init_aarch64(dsp);
940 if (ARCH_ARM)
941 ff_vc1dsp_init_arm(dsp);
942 if (ARCH_PPC)
943 ff_vc1dsp_init_ppc(dsp);
944 if (ARCH_X86)
945 ff_vc1dsp_init_x86(dsp);
946 }