2 * VC-1 and WMV3 decoder - DSP functions
3 * Copyright (c) 2006 Konstantin Shishkov
5 * This file is part of FFmpeg.
7 * FFmpeg 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.
12 * FFmpeg 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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 * VC-1 and WMV3 decoder
27 #include "libavutil/avassert.h"
28 #include "libavutil/common.h"
29 #include "libavutil/intreadwrite.h"
30 #include "h264chroma.h"
34 #include "startcode.h"
36 /* Apply overlap transform to horizontal edge */
37 static void vc1_v_overlap_c(uint8_t *src, int stride)
43 for (i = 0; i < 8; i++) {
48 d1 = (a - d + 3 + rnd) >> 3;
49 d2 = (a - d + b - c + 4 - rnd) >> 3;
51 src[-2 * stride] = a - d1;
52 src[-stride] = av_clip_uint8(b - d2);
53 src[0] = av_clip_uint8(c + d2);
60 /* Apply overlap transform to vertical edge */
61 static void vc1_h_overlap_c(uint8_t *src, int stride)
67 for (i = 0; i < 8; i++) {
72 d1 = (a - d + 3 + rnd) >> 3;
73 d2 = (a - d + b - c + 4 - rnd) >> 3;
76 src[-1] = av_clip_uint8(b - d2);
77 src[0] = av_clip_uint8(c + d2);
84 static void vc1_v_s_overlap_c(int16_t *top, int16_t *bottom)
89 int rnd1 = 4, rnd2 = 3;
90 for (i = 0; i < 8; i++) {
98 top[48] = ((a << 3) - d1 + rnd1) >> 3;
99 top[56] = ((b << 3) - d2 + rnd2) >> 3;
100 bottom[0] = ((c << 3) + d2 + rnd1) >> 3;
101 bottom[8] = ((d << 3) + d1 + rnd2) >> 3;
110 static void vc1_h_s_overlap_c(int16_t *left, int16_t *right)
115 int rnd1 = 4, rnd2 = 3;
116 for (i = 0; i < 8; i++) {
124 left[6] = ((a << 3) - d1 + rnd1) >> 3;
125 left[7] = ((b << 3) - d2 + rnd2) >> 3;
126 right[0] = ((c << 3) + d2 + rnd1) >> 3;
127 right[1] = ((d << 3) + d1 + rnd2) >> 3;
137 * VC-1 in-loop deblocking filter for one line
138 * @param src source block type
139 * @param stride block stride
140 * @param pq block quantizer
141 * @return whether other 3 pairs should be filtered or not
144 static av_always_inline int vc1_filter_line(uint8_t *src, int stride, int pq)
146 int a0 = (2 * (src[-2 * stride] - src[1 * stride]) -
147 5 * (src[-1 * stride] - src[0 * stride]) + 4) >> 3;
148 int a0_sign = a0 >> 31; /* Store sign */
150 a0 = (a0 ^ a0_sign) - a0_sign; /* a0 = FFABS(a0); */
152 int a1 = FFABS((2 * (src[-4 * stride] - src[-1 * stride]) -
153 5 * (src[-3 * stride] - src[-2 * stride]) + 4) >> 3);
154 int a2 = FFABS((2 * (src[ 0 * stride] - src[ 3 * stride]) -
155 5 * (src[ 1 * stride] - src[ 2 * stride]) + 4) >> 3);
156 if (a1 < a0 || a2 < a0) {
157 int clip = src[-1 * stride] - src[0 * stride];
158 int clip_sign = clip >> 31;
160 clip = ((clip ^ clip_sign) - clip_sign) >> 1;
162 int a3 = FFMIN(a1, a2);
163 int d = 5 * (a3 - a0);
164 int d_sign = (d >> 31);
166 d = ((d ^ d_sign) - d_sign) >> 3;
169 if (d_sign ^ clip_sign)
173 d = (d ^ d_sign) - d_sign; /* Restore sign */
174 src[-1 * stride] = av_clip_uint8(src[-1 * stride] - d);
175 src[ 0 * stride] = av_clip_uint8(src[ 0 * stride] + d);
185 * VC-1 in-loop deblocking filter
186 * @param src source block type
187 * @param step distance between horizontally adjacent elements
188 * @param stride distance between vertically adjacent elements
189 * @param len edge length to filter (4 or 8 pixels)
190 * @param pq block quantizer
193 static inline void vc1_loop_filter(uint8_t *src, int step, int stride,
199 for (i = 0; i < len; i += 4) {
200 filt3 = vc1_filter_line(src + 2 * step, stride, pq);
202 vc1_filter_line(src + 0 * step, stride, pq);
203 vc1_filter_line(src + 1 * step, stride, pq);
204 vc1_filter_line(src + 3 * step, stride, pq);
210 static void vc1_v_loop_filter4_c(uint8_t *src, int stride, int pq)
212 vc1_loop_filter(src, 1, stride, 4, pq);
215 static void vc1_h_loop_filter4_c(uint8_t *src, int stride, int pq)
217 vc1_loop_filter(src, stride, 1, 4, pq);
220 static void vc1_v_loop_filter8_c(uint8_t *src, int stride, int pq)
222 vc1_loop_filter(src, 1, stride, 8, pq);
225 static void vc1_h_loop_filter8_c(uint8_t *src, int stride, int pq)
227 vc1_loop_filter(src, stride, 1, 8, pq);
230 static void vc1_v_loop_filter16_c(uint8_t *src, int stride, int pq)
232 vc1_loop_filter(src, 1, stride, 16, pq);
235 static void vc1_h_loop_filter16_c(uint8_t *src, int stride, int pq)
237 vc1_loop_filter(src, stride, 1, 16, pq);
240 /* Do inverse transform on 8x8 block */
241 static void vc1_inv_trans_8x8_dc_c(uint8_t *dest, ptrdiff_t stride, int16_t *block)
246 dc = (3 * dc + 1) >> 1;
247 dc = (3 * dc + 16) >> 5;
249 for (i = 0; i < 8; i++) {
250 dest[0] = av_clip_uint8(dest[0] + dc);
251 dest[1] = av_clip_uint8(dest[1] + dc);
252 dest[2] = av_clip_uint8(dest[2] + dc);
253 dest[3] = av_clip_uint8(dest[3] + dc);
254 dest[4] = av_clip_uint8(dest[4] + dc);
255 dest[5] = av_clip_uint8(dest[5] + dc);
256 dest[6] = av_clip_uint8(dest[6] + dc);
257 dest[7] = av_clip_uint8(dest[7] + dc);
262 static void vc1_inv_trans_8x8_c(int16_t block[64])
265 register int t1, t2, t3, t4, t5, t6, t7, t8;
266 int16_t *src, *dst, temp[64];
270 for (i = 0; i < 8; i++) {
271 t1 = 12 * (src[ 0] + src[32]) + 4;
272 t2 = 12 * (src[ 0] - src[32]) + 4;
273 t3 = 16 * src[16] + 6 * src[48];
274 t4 = 6 * src[16] - 16 * src[48];
281 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
282 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
283 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
284 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
286 dst[0] = (t5 + t1) >> 3;
287 dst[1] = (t6 + t2) >> 3;
288 dst[2] = (t7 + t3) >> 3;
289 dst[3] = (t8 + t4) >> 3;
290 dst[4] = (t8 - t4) >> 3;
291 dst[5] = (t7 - t3) >> 3;
292 dst[6] = (t6 - t2) >> 3;
293 dst[7] = (t5 - t1) >> 3;
301 for (i = 0; i < 8; i++) {
302 t1 = 12 * (src[ 0] + src[32]) + 64;
303 t2 = 12 * (src[ 0] - src[32]) + 64;
304 t3 = 16 * src[16] + 6 * src[48];
305 t4 = 6 * src[16] - 16 * src[48];
312 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
313 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
314 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
315 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
317 dst[ 0] = (t5 + t1) >> 7;
318 dst[ 8] = (t6 + t2) >> 7;
319 dst[16] = (t7 + t3) >> 7;
320 dst[24] = (t8 + t4) >> 7;
321 dst[32] = (t8 - t4 + 1) >> 7;
322 dst[40] = (t7 - t3 + 1) >> 7;
323 dst[48] = (t6 - t2 + 1) >> 7;
324 dst[56] = (t5 - t1 + 1) >> 7;
331 /* Do inverse transform on 8x4 part of block */
332 static void vc1_inv_trans_8x4_dc_c(uint8_t *dest, ptrdiff_t stride, int16_t *block)
337 dc = (3 * dc + 1) >> 1;
338 dc = (17 * dc + 64) >> 7;
340 for (i = 0; i < 4; i++) {
341 dest[0] = av_clip_uint8(dest[0] + dc);
342 dest[1] = av_clip_uint8(dest[1] + dc);
343 dest[2] = av_clip_uint8(dest[2] + dc);
344 dest[3] = av_clip_uint8(dest[3] + dc);
345 dest[4] = av_clip_uint8(dest[4] + dc);
346 dest[5] = av_clip_uint8(dest[5] + dc);
347 dest[6] = av_clip_uint8(dest[6] + dc);
348 dest[7] = av_clip_uint8(dest[7] + dc);
353 static void vc1_inv_trans_8x4_c(uint8_t *dest, ptrdiff_t stride, int16_t *block)
356 register int t1, t2, t3, t4, t5, t6, t7, t8;
362 for (i = 0; i < 4; i++) {
363 t1 = 12 * (src[0] + src[4]) + 4;
364 t2 = 12 * (src[0] - src[4]) + 4;
365 t3 = 16 * src[2] + 6 * src[6];
366 t4 = 6 * src[2] - 16 * src[6];
373 t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
374 t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
375 t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
376 t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
378 dst[0] = (t5 + t1) >> 3;
379 dst[1] = (t6 + t2) >> 3;
380 dst[2] = (t7 + t3) >> 3;
381 dst[3] = (t8 + t4) >> 3;
382 dst[4] = (t8 - t4) >> 3;
383 dst[5] = (t7 - t3) >> 3;
384 dst[6] = (t6 - t2) >> 3;
385 dst[7] = (t5 - t1) >> 3;
392 for (i = 0; i < 8; i++) {
393 t1 = 17 * (src[ 0] + src[16]) + 64;
394 t2 = 17 * (src[ 0] - src[16]) + 64;
395 t3 = 22 * src[ 8] + 10 * src[24];
396 t4 = 22 * src[24] - 10 * src[ 8];
398 dest[0 * stride] = av_clip_uint8(dest[0 * stride] + ((t1 + t3) >> 7));
399 dest[1 * stride] = av_clip_uint8(dest[1 * stride] + ((t2 - t4) >> 7));
400 dest[2 * stride] = av_clip_uint8(dest[2 * stride] + ((t2 + t4) >> 7));
401 dest[3 * stride] = av_clip_uint8(dest[3 * stride] + ((t1 - t3) >> 7));
408 /* Do inverse transform on 4x8 parts of block */
409 static void vc1_inv_trans_4x8_dc_c(uint8_t *dest, ptrdiff_t stride, int16_t *block)
414 dc = (17 * dc + 4) >> 3;
415 dc = (12 * dc + 64) >> 7;
417 for (i = 0; i < 8; i++) {
418 dest[0] = av_clip_uint8(dest[0] + dc);
419 dest[1] = av_clip_uint8(dest[1] + dc);
420 dest[2] = av_clip_uint8(dest[2] + dc);
421 dest[3] = av_clip_uint8(dest[3] + dc);
426 static void vc1_inv_trans_4x8_c(uint8_t *dest, ptrdiff_t stride, int16_t *block)
429 register int t1, t2, t3, t4, t5, t6, t7, t8;
435 for (i = 0; i < 8; i++) {
436 t1 = 17 * (src[0] + src[2]) + 4;
437 t2 = 17 * (src[0] - src[2]) + 4;
438 t3 = 22 * src[1] + 10 * src[3];
439 t4 = 22 * src[3] - 10 * src[1];
441 dst[0] = (t1 + t3) >> 3;
442 dst[1] = (t2 - t4) >> 3;
443 dst[2] = (t2 + t4) >> 3;
444 dst[3] = (t1 - t3) >> 3;
451 for (i = 0; i < 4; i++) {
452 t1 = 12 * (src[ 0] + src[32]) + 64;
453 t2 = 12 * (src[ 0] - src[32]) + 64;
454 t3 = 16 * src[16] + 6 * src[48];
455 t4 = 6 * src[16] - 16 * src[48];
462 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
463 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
464 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
465 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
467 dest[0 * stride] = av_clip_uint8(dest[0 * stride] + ((t5 + t1) >> 7));
468 dest[1 * stride] = av_clip_uint8(dest[1 * stride] + ((t6 + t2) >> 7));
469 dest[2 * stride] = av_clip_uint8(dest[2 * stride] + ((t7 + t3) >> 7));
470 dest[3 * stride] = av_clip_uint8(dest[3 * stride] + ((t8 + t4) >> 7));
471 dest[4 * stride] = av_clip_uint8(dest[4 * stride] + ((t8 - t4 + 1) >> 7));
472 dest[5 * stride] = av_clip_uint8(dest[5 * stride] + ((t7 - t3 + 1) >> 7));
473 dest[6 * stride] = av_clip_uint8(dest[6 * stride] + ((t6 - t2 + 1) >> 7));
474 dest[7 * stride] = av_clip_uint8(dest[7 * stride] + ((t5 - t1 + 1) >> 7));
481 /* Do inverse transform on 4x4 part of block */
482 static void vc1_inv_trans_4x4_dc_c(uint8_t *dest, ptrdiff_t stride, int16_t *block)
487 dc = (17 * dc + 4) >> 3;
488 dc = (17 * dc + 64) >> 7;
490 for (i = 0; i < 4; i++) {
491 dest[0] = av_clip_uint8(dest[0] + dc);
492 dest[1] = av_clip_uint8(dest[1] + dc);
493 dest[2] = av_clip_uint8(dest[2] + dc);
494 dest[3] = av_clip_uint8(dest[3] + dc);
499 static void vc1_inv_trans_4x4_c(uint8_t *dest, ptrdiff_t stride, int16_t *block)
502 register int t1, t2, t3, t4;
507 for (i = 0; i < 4; i++) {
508 t1 = 17 * (src[0] + src[2]) + 4;
509 t2 = 17 * (src[0] - src[2]) + 4;
510 t3 = 22 * src[1] + 10 * src[3];
511 t4 = 22 * src[3] - 10 * src[1];
513 dst[0] = (t1 + t3) >> 3;
514 dst[1] = (t2 - t4) >> 3;
515 dst[2] = (t2 + t4) >> 3;
516 dst[3] = (t1 - t3) >> 3;
523 for (i = 0; i < 4; i++) {
524 t1 = 17 * (src[0] + src[16]) + 64;
525 t2 = 17 * (src[0] - src[16]) + 64;
526 t3 = 22 * src[8] + 10 * src[24];
527 t4 = 22 * src[24] - 10 * src[8];
529 dest[0 * stride] = av_clip_uint8(dest[0 * stride] + ((t1 + t3) >> 7));
530 dest[1 * stride] = av_clip_uint8(dest[1 * stride] + ((t2 - t4) >> 7));
531 dest[2 * stride] = av_clip_uint8(dest[2 * stride] + ((t2 + t4) >> 7));
532 dest[3 * stride] = av_clip_uint8(dest[3 * stride] + ((t1 - t3) >> 7));
539 /* motion compensation functions */
541 /* Filter in case of 2 filters */
542 #define VC1_MSPEL_FILTER_16B(DIR, TYPE) \
543 static av_always_inline int vc1_mspel_ ## DIR ## _filter_16bits(const TYPE *src, \
548 case 0: /* no shift - should not occur */ \
550 case 1: /* 1/4 shift */ \
551 return -4 * src[-stride] + 53 * src[0] + \
552 18 * src[stride] - 3 * src[stride * 2]; \
553 case 2: /* 1/2 shift */ \
554 return -1 * src[-stride] + 9 * src[0] + \
555 9 * src[stride] - 1 * src[stride * 2]; \
556 case 3: /* 3/4 shift */ \
557 return -3 * src[-stride] + 18 * src[0] + \
558 53 * src[stride] - 4 * src[stride * 2]; \
560 return 0; /* should not occur */ \
563 VC1_MSPEL_FILTER_16B(ver, uint8_t)
564 VC1_MSPEL_FILTER_16B(hor, int16_t)
566 /* Filter used to interpolate fractional pel values */
567 static av_always_inline int vc1_mspel_filter(const uint8_t *src, int stride,
574 return (-4 * src[-stride] + 53 * src[0] +
575 18 * src[stride] - 3 * src[stride * 2] + 32 - r) >> 6;
577 return (-1 * src[-stride] + 9 * src[0] +
578 9 * src[stride] - 1 * src[stride * 2] + 8 - r) >> 4;
580 return (-3 * src[-stride] + 18 * src[0] +
581 53 * src[stride] - 4 * src[stride * 2] + 32 - r) >> 6;
583 return 0; // should not occur
586 /* Function used to do motion compensation with bicubic interpolation */
587 #define VC1_MSPEL_MC(OP, OP4, OPNAME) \
588 static av_always_inline void OPNAME ## vc1_mspel_mc(uint8_t *dst, \
589 const uint8_t *src, \
597 if (vmode) { /* Horizontal filter to apply */ \
600 if (hmode) { /* Vertical filter to apply, output to tmp */ \
601 static const int shift_value[] = { 0, 5, 1, 5 }; \
602 int shift = (shift_value[hmode] + shift_value[vmode]) >> 1; \
603 int16_t tmp[11 * 8], *tptr = tmp; \
605 r = (1 << (shift - 1)) + rnd - 1; \
608 for (j = 0; j < 8; j++) { \
609 for (i = 0; i < 11; i++) \
610 tptr[i] = (vc1_mspel_ver_filter_16bits(src + i, stride, vmode) + r) >> shift; \
617 for (j = 0; j < 8; j++) { \
618 for (i = 0; i < 8; i++) \
619 OP(dst[i], (vc1_mspel_hor_filter_16bits(tptr + i, 1, hmode) + r) >> 7); \
625 } else { /* No horizontal filter, output 8 lines to dst */ \
628 for (j = 0; j < 8; j++) { \
629 for (i = 0; i < 8; i++) \
630 OP(dst[i], vc1_mspel_filter(src + i, stride, vmode, r)); \
638 /* Horizontal mode with no vertical mode */ \
639 for (j = 0; j < 8; j++) { \
640 for (i = 0; i < 8; i++) \
641 OP(dst[i], vc1_mspel_filter(src + i, 1, hmode, rnd)); \
646 static av_always_inline void OPNAME ## vc1_mspel_mc_16(uint8_t *dst, \
647 const uint8_t *src, \
655 if (vmode) { /* Horizontal filter to apply */ \
658 if (hmode) { /* Vertical filter to apply, output to tmp */ \
659 static const int shift_value[] = { 0, 5, 1, 5 }; \
660 int shift = (shift_value[hmode] + shift_value[vmode]) >> 1; \
661 int16_t tmp[19 * 16], *tptr = tmp; \
663 r = (1 << (shift - 1)) + rnd - 1; \
666 for (j = 0; j < 16; j++) { \
667 for (i = 0; i < 19; i++) \
668 tptr[i] = (vc1_mspel_ver_filter_16bits(src + i, stride, vmode) + r) >> shift; \
675 for (j = 0; j < 16; j++) { \
676 for (i = 0; i < 16; i++) \
677 OP(dst[i], (vc1_mspel_hor_filter_16bits(tptr + i, 1, hmode) + r) >> 7); \
683 } else { /* No horizontal filter, output 8 lines to dst */ \
686 for (j = 0; j < 16; j++) { \
687 for (i = 0; i < 16; i++) \
688 OP(dst[i], vc1_mspel_filter(src + i, stride, vmode, r)); \
696 /* Horizontal mode with no vertical mode */ \
697 for (j = 0; j < 16; j++) { \
698 for (i = 0; i < 16; i++) \
699 OP(dst[i], vc1_mspel_filter(src + i, 1, hmode, rnd)); \
704 static void OPNAME ## pixels8x8_c(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int rnd){\
707 OP4(*(uint32_t*)(block ), AV_RN32(pixels ));\
708 OP4(*(uint32_t*)(block+4), AV_RN32(pixels+4));\
713 static void OPNAME ## pixels16x16_c(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int rnd){\
715 for(i=0; i<16; i++){\
716 OP4(*(uint32_t*)(block ), AV_RN32(pixels ));\
717 OP4(*(uint32_t*)(block+ 4), AV_RN32(pixels+ 4));\
718 OP4(*(uint32_t*)(block+ 8), AV_RN32(pixels+ 8));\
719 OP4(*(uint32_t*)(block+12), AV_RN32(pixels+12));\
725 #define op_put(a, b) (a) = av_clip_uint8(b)
726 #define op_avg(a, b) (a) = ((a) + av_clip_uint8(b) + 1) >> 1
727 #define op4_avg(a, b) (a) = rnd_avg32(a, b)
728 #define op4_put(a, b) (a) = (b)
730 VC1_MSPEL_MC(op_put, op4_put, put_)
731 VC1_MSPEL_MC(op_avg, op4_avg, avg_)
733 /* pixel functions - really are entry points to vc1_mspel_mc */
735 #define PUT_VC1_MSPEL(a, b) \
736 static void put_vc1_mspel_mc ## a ## b ## _c(uint8_t *dst, \
737 const uint8_t *src, \
738 ptrdiff_t stride, int rnd) \
740 put_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
742 static void avg_vc1_mspel_mc ## a ## b ## _c(uint8_t *dst, \
743 const uint8_t *src, \
744 ptrdiff_t stride, int rnd) \
746 avg_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
748 static void put_vc1_mspel_mc ## a ## b ## _16_c(uint8_t *dst, \
749 const uint8_t *src, \
750 ptrdiff_t stride, int rnd) \
752 put_vc1_mspel_mc_16(dst, src, stride, a, b, rnd); \
754 static void avg_vc1_mspel_mc ## a ## b ## _16_c(uint8_t *dst, \
755 const uint8_t *src, \
756 ptrdiff_t stride, int rnd) \
758 avg_vc1_mspel_mc_16(dst, src, stride, a, b, rnd); \
780 #define chroma_mc(a) \
781 ((A * src[a] + B * src[a + 1] + \
782 C * src[stride + a] + D * src[stride + a + 1] + 32 - 4) >> 6)
783 static void put_no_rnd_vc1_chroma_mc8_c(uint8_t *dst /* align 8 */,
784 uint8_t *src /* align 1 */,
785 ptrdiff_t stride, int h, int x, int y)
787 const int A = (8 - x) * (8 - y);
788 const int B = (x) * (8 - y);
789 const int C = (8 - x) * (y);
790 const int D = (x) * (y);
793 av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
795 for (i = 0; i < h; i++) {
796 dst[0] = chroma_mc(0);
797 dst[1] = chroma_mc(1);
798 dst[2] = chroma_mc(2);
799 dst[3] = chroma_mc(3);
800 dst[4] = chroma_mc(4);
801 dst[5] = chroma_mc(5);
802 dst[6] = chroma_mc(6);
803 dst[7] = chroma_mc(7);
809 static void put_no_rnd_vc1_chroma_mc4_c(uint8_t *dst, uint8_t *src,
810 ptrdiff_t stride, int h, int x, int y)
812 const int A = (8 - x) * (8 - y);
813 const int B = (x) * (8 - y);
814 const int C = (8 - x) * (y);
815 const int D = (x) * (y);
818 av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
820 for (i = 0; i < h; i++) {
821 dst[0] = chroma_mc(0);
822 dst[1] = chroma_mc(1);
823 dst[2] = chroma_mc(2);
824 dst[3] = chroma_mc(3);
830 #define avg2(a, b) (((a) + (b) + 1) >> 1)
831 static void avg_no_rnd_vc1_chroma_mc8_c(uint8_t *dst /* align 8 */,
832 uint8_t *src /* align 1 */,
833 ptrdiff_t stride, int h, int x, int y)
835 const int A = (8 - x) * (8 - y);
836 const int B = (x) * (8 - y);
837 const int C = (8 - x) * (y);
838 const int D = (x) * (y);
841 av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
843 for (i = 0; i < h; i++) {
844 dst[0] = avg2(dst[0], chroma_mc(0));
845 dst[1] = avg2(dst[1], chroma_mc(1));
846 dst[2] = avg2(dst[2], chroma_mc(2));
847 dst[3] = avg2(dst[3], chroma_mc(3));
848 dst[4] = avg2(dst[4], chroma_mc(4));
849 dst[5] = avg2(dst[5], chroma_mc(5));
850 dst[6] = avg2(dst[6], chroma_mc(6));
851 dst[7] = avg2(dst[7], chroma_mc(7));
857 static void avg_no_rnd_vc1_chroma_mc4_c(uint8_t *dst /* align 8 */,
858 uint8_t *src /* align 1 */,
859 ptrdiff_t stride, int h, int x, int y)
861 const int A = (8 - x) * (8 - y);
862 const int B = ( x) * (8 - y);
863 const int C = (8 - x) * ( y);
864 const int D = ( x) * ( y);
867 av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
869 for (i = 0; i < h; i++) {
870 dst[0] = avg2(dst[0], chroma_mc(0));
871 dst[1] = avg2(dst[1], chroma_mc(1));
872 dst[2] = avg2(dst[2], chroma_mc(2));
873 dst[3] = avg2(dst[3], chroma_mc(3));
879 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
881 static void sprite_h_c(uint8_t *dst, const uint8_t *src, int offset,
882 int advance, int count)
885 int a = src[(offset >> 16)];
886 int b = src[(offset >> 16) + 1];
887 *dst++ = a + ((b - a) * (offset & 0xFFFF) >> 16);
892 static av_always_inline void sprite_v_template(uint8_t *dst,
893 const uint8_t *src1a,
894 const uint8_t *src1b,
897 const uint8_t *src2a,
898 const uint8_t *src2b,
900 int alpha, int scaled,
908 a1 = a1 + ((b1 - a1) * offset1 >> 16);
914 a2 = a2 + ((b2 - a2) * offset2 >> 16);
916 a1 = a1 + ((a2 - a1) * alpha >> 16);
922 static void sprite_v_single_c(uint8_t *dst, const uint8_t *src1a,
923 const uint8_t *src1b,
924 int offset, int width)
926 sprite_v_template(dst, src1a, src1b, offset, 0, NULL, NULL, 0, 0, 1, width);
929 static void sprite_v_double_noscale_c(uint8_t *dst, const uint8_t *src1a,
930 const uint8_t *src2a,
931 int alpha, int width)
933 sprite_v_template(dst, src1a, NULL, 0, 1, src2a, NULL, 0, alpha, 0, width);
936 static void sprite_v_double_onescale_c(uint8_t *dst,
937 const uint8_t *src1a,
938 const uint8_t *src1b,
940 const uint8_t *src2a,
941 int alpha, int width)
943 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, NULL, 0, alpha, 1,
947 static void sprite_v_double_twoscale_c(uint8_t *dst,
948 const uint8_t *src1a,
949 const uint8_t *src1b,
951 const uint8_t *src2a,
952 const uint8_t *src2b,
957 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, src2b, offset2,
961 #endif /* CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER */
962 #define FN_ASSIGN(X, Y) \
963 dsp->put_vc1_mspel_pixels_tab[1][X+4*Y] = put_vc1_mspel_mc##X##Y##_c; \
964 dsp->put_vc1_mspel_pixels_tab[0][X+4*Y] = put_vc1_mspel_mc##X##Y##_16_c; \
965 dsp->avg_vc1_mspel_pixels_tab[1][X+4*Y] = avg_vc1_mspel_mc##X##Y##_c; \
966 dsp->avg_vc1_mspel_pixels_tab[0][X+4*Y] = avg_vc1_mspel_mc##X##Y##_16_c
968 av_cold void ff_vc1dsp_init(VC1DSPContext *dsp)
970 dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c;
971 dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c;
972 dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_c;
973 dsp->vc1_inv_trans_4x4 = vc1_inv_trans_4x4_c;
974 dsp->vc1_inv_trans_8x8_dc = vc1_inv_trans_8x8_dc_c;
975 dsp->vc1_inv_trans_4x8_dc = vc1_inv_trans_4x8_dc_c;
976 dsp->vc1_inv_trans_8x4_dc = vc1_inv_trans_8x4_dc_c;
977 dsp->vc1_inv_trans_4x4_dc = vc1_inv_trans_4x4_dc_c;
979 dsp->vc1_h_overlap = vc1_h_overlap_c;
980 dsp->vc1_v_overlap = vc1_v_overlap_c;
981 dsp->vc1_h_s_overlap = vc1_h_s_overlap_c;
982 dsp->vc1_v_s_overlap = vc1_v_s_overlap_c;
984 dsp->vc1_v_loop_filter4 = vc1_v_loop_filter4_c;
985 dsp->vc1_h_loop_filter4 = vc1_h_loop_filter4_c;
986 dsp->vc1_v_loop_filter8 = vc1_v_loop_filter8_c;
987 dsp->vc1_h_loop_filter8 = vc1_h_loop_filter8_c;
988 dsp->vc1_v_loop_filter16 = vc1_v_loop_filter16_c;
989 dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_c;
991 dsp->put_vc1_mspel_pixels_tab[0][0] = put_pixels16x16_c;
992 dsp->avg_vc1_mspel_pixels_tab[0][0] = avg_pixels16x16_c;
993 dsp->put_vc1_mspel_pixels_tab[1][0] = put_pixels8x8_c;
994 dsp->avg_vc1_mspel_pixels_tab[1][0] = avg_pixels8x8_c;
1014 dsp->put_no_rnd_vc1_chroma_pixels_tab[0] = put_no_rnd_vc1_chroma_mc8_c;
1015 dsp->avg_no_rnd_vc1_chroma_pixels_tab[0] = avg_no_rnd_vc1_chroma_mc8_c;
1016 dsp->put_no_rnd_vc1_chroma_pixels_tab[1] = put_no_rnd_vc1_chroma_mc4_c;
1017 dsp->avg_no_rnd_vc1_chroma_pixels_tab[1] = avg_no_rnd_vc1_chroma_mc4_c;
1019 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
1020 dsp->sprite_h = sprite_h_c;
1021 dsp->sprite_v_single = sprite_v_single_c;
1022 dsp->sprite_v_double_noscale = sprite_v_double_noscale_c;
1023 dsp->sprite_v_double_onescale = sprite_v_double_onescale_c;
1024 dsp->sprite_v_double_twoscale = sprite_v_double_twoscale_c;
1025 #endif /* CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER */
1027 dsp->startcode_find_candidate = ff_startcode_find_candidate_c;
1030 ff_vc1dsp_init_aarch64(dsp);
1032 ff_vc1dsp_init_arm(dsp);
1034 ff_vc1dsp_init_ppc(dsp);
1036 ff_vc1dsp_init_x86(dsp);
1038 ff_vc1dsp_init_mips(dsp);