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
28 #include "libavutil/avassert.h"
29 #include "libavutil/common.h"
30 #include "h264chroma.h"
35 /** 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
62 static void vc1_h_overlap_c(uint8_t* src, int stride)
68 for(i = 0; i < 8; i++) {
73 d1 = (a - d + 3 + rnd) >> 3;
74 d2 = (a - d + b - c + 4 - rnd) >> 3;
77 src[-1] = av_clip_uint8(b - d2);
78 src[0] = av_clip_uint8(c + d2);
85 static void vc1_v_s_overlap_c(int16_t *top, int16_t *bottom)
90 int rnd1 = 4, rnd2 = 3;
91 for(i = 0; i < 8; i++) {
99 top[48] = ((a << 3) - d1 + rnd1) >> 3;
100 top[56] = ((b << 3) - d2 + rnd2) >> 3;
101 bottom[0] = ((c << 3) + d2 + rnd1) >> 3;
102 bottom[8] = ((d << 3) + d1 + rnd2) >> 3;
111 static void vc1_h_s_overlap_c(int16_t *left, int16_t *right)
116 int rnd1 = 4, rnd2 = 3;
117 for(i = 0; i < 8; i++) {
125 left[6] = ((a << 3) - d1 + rnd1) >> 3;
126 left[7] = ((b << 3) - d2 + rnd2) >> 3;
127 right[0] = ((c << 3) + d2 + rnd1) >> 3;
128 right[1] = ((d << 3) + d1 + rnd2) >> 3;
138 * VC-1 in-loop deblocking filter for one line
139 * @param src source block type
140 * @param stride block stride
141 * @param pq block quantizer
142 * @return whether other 3 pairs should be filtered or not
145 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]) - 5*(src[-1*stride] - src[ 0*stride]) + 4) >> 3;
147 int a0_sign = a0 >> 31; /* Store sign */
148 a0 = (a0 ^ a0_sign) - a0_sign; /* a0 = FFABS(a0); */
150 int a1 = FFABS((2*(src[-4*stride] - src[-1*stride]) - 5*(src[-3*stride] - src[-2*stride]) + 4) >> 3);
151 int a2 = FFABS((2*(src[ 0*stride] - src[ 3*stride]) - 5*(src[ 1*stride] - src[ 2*stride]) + 4) >> 3);
152 if(a1 < a0 || a2 < a0){
153 int clip = src[-1*stride] - src[ 0*stride];
154 int clip_sign = clip >> 31;
155 clip = ((clip ^ clip_sign) - clip_sign)>>1;
157 int a3 = FFMIN(a1, a2);
158 int d = 5 * (a3 - a0);
159 int d_sign = (d >> 31);
160 d = ((d ^ d_sign) - d_sign) >> 3;
163 if( d_sign ^ clip_sign )
167 d = (d ^ d_sign) - d_sign; /* Restore sign */
168 src[-1*stride] = av_clip_uint8(src[-1*stride] - d);
169 src[ 0*stride] = av_clip_uint8(src[ 0*stride] + d);
179 * VC-1 in-loop deblocking filter
180 * @param src source block type
181 * @param step distance between horizontally adjacent elements
182 * @param stride distance between vertically adjacent elements
183 * @param len edge length to filter (4 or 8 pixels)
184 * @param pq block quantizer
187 static inline void vc1_loop_filter(uint8_t* src, int step, int stride, int len, int pq)
192 for(i = 0; i < len; i += 4){
193 filt3 = vc1_filter_line(src + 2*step, stride, pq);
195 vc1_filter_line(src + 0*step, stride, pq);
196 vc1_filter_line(src + 1*step, stride, pq);
197 vc1_filter_line(src + 3*step, stride, pq);
203 static void vc1_v_loop_filter4_c(uint8_t *src, int stride, int pq)
205 vc1_loop_filter(src, 1, stride, 4, pq);
208 static void vc1_h_loop_filter4_c(uint8_t *src, int stride, int pq)
210 vc1_loop_filter(src, stride, 1, 4, pq);
213 static void vc1_v_loop_filter8_c(uint8_t *src, int stride, int pq)
215 vc1_loop_filter(src, 1, stride, 8, pq);
218 static void vc1_h_loop_filter8_c(uint8_t *src, int stride, int pq)
220 vc1_loop_filter(src, stride, 1, 8, pq);
223 static void vc1_v_loop_filter16_c(uint8_t *src, int stride, int pq)
225 vc1_loop_filter(src, 1, stride, 16, pq);
228 static void vc1_h_loop_filter16_c(uint8_t *src, int stride, int pq)
230 vc1_loop_filter(src, stride, 1, 16, pq);
233 /** Do inverse transform on 8x8 block
235 static void vc1_inv_trans_8x8_dc_c(uint8_t *dest, int linesize, int16_t *block)
239 dc = (3 * dc + 1) >> 1;
240 dc = (3 * dc + 16) >> 5;
241 for(i = 0; i < 8; i++){
242 dest[0] = av_clip_uint8(dest[0] + dc);
243 dest[1] = av_clip_uint8(dest[1] + dc);
244 dest[2] = av_clip_uint8(dest[2] + dc);
245 dest[3] = av_clip_uint8(dest[3] + dc);
246 dest[4] = av_clip_uint8(dest[4] + dc);
247 dest[5] = av_clip_uint8(dest[5] + dc);
248 dest[6] = av_clip_uint8(dest[6] + dc);
249 dest[7] = av_clip_uint8(dest[7] + dc);
254 static void vc1_inv_trans_8x8_c(int16_t block[64])
257 register int t1,t2,t3,t4,t5,t6,t7,t8;
258 int16_t *src, *dst, temp[64];
262 for(i = 0; i < 8; i++){
263 t1 = 12 * (src[ 0] + src[32]) + 4;
264 t2 = 12 * (src[ 0] - src[32]) + 4;
265 t3 = 16 * src[16] + 6 * src[48];
266 t4 = 6 * src[16] - 16 * src[48];
273 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
274 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
275 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
276 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
278 dst[0] = (t5 + t1) >> 3;
279 dst[1] = (t6 + t2) >> 3;
280 dst[2] = (t7 + t3) >> 3;
281 dst[3] = (t8 + t4) >> 3;
282 dst[4] = (t8 - t4) >> 3;
283 dst[5] = (t7 - t3) >> 3;
284 dst[6] = (t6 - t2) >> 3;
285 dst[7] = (t5 - t1) >> 3;
293 for(i = 0; i < 8; i++){
294 t1 = 12 * (src[ 0] + src[32]) + 64;
295 t2 = 12 * (src[ 0] - src[32]) + 64;
296 t3 = 16 * src[16] + 6 * src[48];
297 t4 = 6 * src[16] - 16 * src[48];
304 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
305 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
306 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
307 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
309 dst[ 0] = (t5 + t1) >> 7;
310 dst[ 8] = (t6 + t2) >> 7;
311 dst[16] = (t7 + t3) >> 7;
312 dst[24] = (t8 + t4) >> 7;
313 dst[32] = (t8 - t4 + 1) >> 7;
314 dst[40] = (t7 - t3 + 1) >> 7;
315 dst[48] = (t6 - t2 + 1) >> 7;
316 dst[56] = (t5 - t1 + 1) >> 7;
323 /** Do inverse transform on 8x4 part of block
325 static void vc1_inv_trans_8x4_dc_c(uint8_t *dest, int linesize, int16_t *block)
329 dc = ( 3 * dc + 1) >> 1;
330 dc = (17 * dc + 64) >> 7;
331 for(i = 0; i < 4; i++){
332 dest[0] = av_clip_uint8(dest[0] + dc);
333 dest[1] = av_clip_uint8(dest[1] + dc);
334 dest[2] = av_clip_uint8(dest[2] + dc);
335 dest[3] = av_clip_uint8(dest[3] + dc);
336 dest[4] = av_clip_uint8(dest[4] + dc);
337 dest[5] = av_clip_uint8(dest[5] + dc);
338 dest[6] = av_clip_uint8(dest[6] + dc);
339 dest[7] = av_clip_uint8(dest[7] + dc);
344 static void vc1_inv_trans_8x4_c(uint8_t *dest, int linesize, int16_t *block)
347 register int t1,t2,t3,t4,t5,t6,t7,t8;
352 for(i = 0; i < 4; i++){
353 t1 = 12 * (src[0] + src[4]) + 4;
354 t2 = 12 * (src[0] - src[4]) + 4;
355 t3 = 16 * src[2] + 6 * src[6];
356 t4 = 6 * src[2] - 16 * src[6];
363 t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
364 t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
365 t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
366 t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
368 dst[0] = (t5 + t1) >> 3;
369 dst[1] = (t6 + t2) >> 3;
370 dst[2] = (t7 + t3) >> 3;
371 dst[3] = (t8 + t4) >> 3;
372 dst[4] = (t8 - t4) >> 3;
373 dst[5] = (t7 - t3) >> 3;
374 dst[6] = (t6 - t2) >> 3;
375 dst[7] = (t5 - t1) >> 3;
382 for(i = 0; i < 8; i++){
383 t1 = 17 * (src[ 0] + src[16]) + 64;
384 t2 = 17 * (src[ 0] - src[16]) + 64;
385 t3 = 22 * src[ 8] + 10 * src[24];
386 t4 = 22 * src[24] - 10 * src[ 8];
388 dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t1 + t3) >> 7));
389 dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t2 - t4) >> 7));
390 dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t2 + t4) >> 7));
391 dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t1 - t3) >> 7));
398 /** Do inverse transform on 4x8 parts of block
400 static void vc1_inv_trans_4x8_dc_c(uint8_t *dest, int linesize, int16_t *block)
404 dc = (17 * dc + 4) >> 3;
405 dc = (12 * dc + 64) >> 7;
406 for(i = 0; i < 8; i++){
407 dest[0] = av_clip_uint8(dest[0] + dc);
408 dest[1] = av_clip_uint8(dest[1] + dc);
409 dest[2] = av_clip_uint8(dest[2] + dc);
410 dest[3] = av_clip_uint8(dest[3] + dc);
415 static void vc1_inv_trans_4x8_c(uint8_t *dest, int linesize, int16_t *block)
418 register int t1,t2,t3,t4,t5,t6,t7,t8;
423 for(i = 0; i < 8; i++){
424 t1 = 17 * (src[0] + src[2]) + 4;
425 t2 = 17 * (src[0] - src[2]) + 4;
426 t3 = 22 * src[1] + 10 * src[3];
427 t4 = 22 * src[3] - 10 * src[1];
429 dst[0] = (t1 + t3) >> 3;
430 dst[1] = (t2 - t4) >> 3;
431 dst[2] = (t2 + t4) >> 3;
432 dst[3] = (t1 - t3) >> 3;
439 for(i = 0; i < 4; i++){
440 t1 = 12 * (src[ 0] + src[32]) + 64;
441 t2 = 12 * (src[ 0] - src[32]) + 64;
442 t3 = 16 * src[16] + 6 * src[48];
443 t4 = 6 * src[16] - 16 * src[48];
450 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
451 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
452 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
453 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
455 dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t5 + t1) >> 7));
456 dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t6 + t2) >> 7));
457 dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t7 + t3) >> 7));
458 dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t8 + t4) >> 7));
459 dest[4*linesize] = av_clip_uint8(dest[4*linesize] + ((t8 - t4 + 1) >> 7));
460 dest[5*linesize] = av_clip_uint8(dest[5*linesize] + ((t7 - t3 + 1) >> 7));
461 dest[6*linesize] = av_clip_uint8(dest[6*linesize] + ((t6 - t2 + 1) >> 7));
462 dest[7*linesize] = av_clip_uint8(dest[7*linesize] + ((t5 - t1 + 1) >> 7));
469 /** Do inverse transform on 4x4 part of block
471 static void vc1_inv_trans_4x4_dc_c(uint8_t *dest, int linesize, int16_t *block)
475 dc = (17 * dc + 4) >> 3;
476 dc = (17 * dc + 64) >> 7;
477 for(i = 0; i < 4; i++){
478 dest[0] = av_clip_uint8(dest[0] + dc);
479 dest[1] = av_clip_uint8(dest[1] + dc);
480 dest[2] = av_clip_uint8(dest[2] + dc);
481 dest[3] = av_clip_uint8(dest[3] + dc);
486 static void vc1_inv_trans_4x4_c(uint8_t *dest, int linesize, int16_t *block)
489 register int t1,t2,t3,t4;
494 for(i = 0; i < 4; i++){
495 t1 = 17 * (src[0] + src[2]) + 4;
496 t2 = 17 * (src[0] - src[2]) + 4;
497 t3 = 22 * src[1] + 10 * src[3];
498 t4 = 22 * src[3] - 10 * src[1];
500 dst[0] = (t1 + t3) >> 3;
501 dst[1] = (t2 - t4) >> 3;
502 dst[2] = (t2 + t4) >> 3;
503 dst[3] = (t1 - t3) >> 3;
510 for(i = 0; i < 4; i++){
511 t1 = 17 * (src[ 0] + src[16]) + 64;
512 t2 = 17 * (src[ 0] - src[16]) + 64;
513 t3 = 22 * src[ 8] + 10 * src[24];
514 t4 = 22 * src[24] - 10 * src[ 8];
516 dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t1 + t3) >> 7));
517 dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t2 - t4) >> 7));
518 dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t2 + t4) >> 7));
519 dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t1 - t3) >> 7));
526 /* motion compensation functions */
527 /** Filter in case of 2 filters */
528 #define VC1_MSPEL_FILTER_16B(DIR, TYPE) \
529 static av_always_inline int vc1_mspel_ ## DIR ## _filter_16bits(const TYPE *src, int stride, int mode) \
532 case 0: /* no shift - should not occur */ \
534 case 1: /* 1/4 shift */ \
535 return -4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2]; \
536 case 2: /* 1/2 shift */ \
537 return -src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2]; \
538 case 3: /* 3/4 shift */ \
539 return -3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2]; \
541 return 0; /* should not occur */ \
544 VC1_MSPEL_FILTER_16B(ver, uint8_t)
545 VC1_MSPEL_FILTER_16B(hor, int16_t)
548 /** Filter used to interpolate fractional pel values
550 static av_always_inline int vc1_mspel_filter(const uint8_t *src, int stride, int mode, int r)
556 return (-4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2] + 32 - r) >> 6;
558 return (-src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2] + 8 - r) >> 4;
560 return (-3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2] + 32 - r) >> 6;
562 return 0; //should not occur
565 /** Function used to do motion compensation with bicubic interpolation
567 #define VC1_MSPEL_MC(OP, OP4, OPNAME)\
568 static av_always_inline void OPNAME ## vc1_mspel_mc(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int hmode, int vmode, int rnd)\
572 if (vmode) { /* Horizontal filter to apply */\
575 if (hmode) { /* Vertical filter to apply, output to tmp */\
576 static const int shift_value[] = { 0, 5, 1, 5 };\
577 int shift = (shift_value[hmode]+shift_value[vmode])>>1;\
578 int16_t tmp[11*8], *tptr = tmp;\
580 r = (1<<(shift-1)) + rnd-1;\
583 for(j = 0; j < 8; j++) {\
584 for(i = 0; i < 11; i++)\
585 tptr[i] = (vc1_mspel_ver_filter_16bits(src + i, stride, vmode)+r)>>shift;\
592 for(j = 0; j < 8; j++) {\
593 for(i = 0; i < 8; i++)\
594 OP(dst[i], (vc1_mspel_hor_filter_16bits(tptr + i, 1, hmode)+r)>>7);\
601 else { /* No horizontal filter, output 8 lines to dst */\
604 for(j = 0; j < 8; j++) {\
605 for(i = 0; i < 8; i++)\
606 OP(dst[i], vc1_mspel_filter(src + i, stride, vmode, r));\
614 /* Horizontal mode with no vertical mode */\
615 for(j = 0; j < 8; j++) {\
616 for(i = 0; i < 8; i++)\
617 OP(dst[i], vc1_mspel_filter(src + i, 1, hmode, rnd));\
622 static void OPNAME ## pixels8x8_c(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int rnd){\
625 OP4(*(uint32_t*)(block ), AV_RN32(pixels ));\
626 OP4(*(uint32_t*)(block+4), AV_RN32(pixels+4));\
632 #define op_put(a, b) a = av_clip_uint8(b)
633 #define op_avg(a, b) a = (a + av_clip_uint8(b) + 1) >> 1
634 #define op4_avg(a, b) a = rnd_avg32(a, b)
635 #define op4_put(a, b) a = b
637 VC1_MSPEL_MC(op_put, op4_put, put_)
638 VC1_MSPEL_MC(op_avg, op4_avg, avg_)
640 /* pixel functions - really are entry points to vc1_mspel_mc */
642 #define PUT_VC1_MSPEL(a, b)\
643 static void put_vc1_mspel_mc ## a ## b ##_c(uint8_t *dst, \
644 const uint8_t *src, \
645 ptrdiff_t stride, int rnd) \
647 put_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
649 static void avg_vc1_mspel_mc ## a ## b ##_c(uint8_t *dst, \
650 const uint8_t *src, \
651 ptrdiff_t stride, int rnd) \
653 avg_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
675 static void put_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){
676 const int A=(8-x)*(8-y);
677 const int B=( x)*(8-y);
678 const int C=(8-x)*( y);
679 const int D=( x)*( y);
682 av_assert2(x<8 && y<8 && x>=0 && y>=0);
686 dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
687 dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
688 dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
689 dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
690 dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6;
691 dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6;
692 dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6;
693 dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6;
699 static void put_no_rnd_vc1_chroma_mc4_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y){
700 const int A=(8-x)*(8-y);
701 const int B=( x)*(8-y);
702 const int C=(8-x)*( y);
703 const int D=( x)*( y);
706 av_assert2(x<8 && y<8 && x>=0 && y>=0);
710 dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
711 dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
712 dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
713 dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
719 #define avg2(a,b) ((a+b+1)>>1)
720 static void avg_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){
721 const int A=(8-x)*(8-y);
722 const int B=( x)*(8-y);
723 const int C=(8-x)*( y);
724 const int D=( x)*( y);
727 av_assert2(x<8 && y<8 && x>=0 && y>=0);
731 dst[0] = avg2(dst[0], ((A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6));
732 dst[1] = avg2(dst[1], ((A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6));
733 dst[2] = avg2(dst[2], ((A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6));
734 dst[3] = avg2(dst[3], ((A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6));
735 dst[4] = avg2(dst[4], ((A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6));
736 dst[5] = avg2(dst[5], ((A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6));
737 dst[6] = avg2(dst[6], ((A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6));
738 dst[7] = avg2(dst[7], ((A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6));
744 static void avg_no_rnd_vc1_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){
745 const int A=(8-x)*(8-y);
746 const int B=( x)*(8-y);
747 const int C=(8-x)*( y);
748 const int D=( x)*( y);
751 av_assert2(x<8 && y<8 && x>=0 && y>=0);
755 dst[0] = avg2(dst[0], ((A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6));
756 dst[1] = avg2(dst[1], ((A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6));
757 dst[2] = avg2(dst[2], ((A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6));
758 dst[3] = avg2(dst[3], ((A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6));
764 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
766 static void sprite_h_c(uint8_t *dst, const uint8_t *src, int offset, int advance, int count)
769 int a = src[(offset >> 16) ];
770 int b = src[(offset >> 16) + 1];
771 *dst++ = a + ((b - a) * (offset&0xFFFF) >> 16);
776 static av_always_inline void sprite_v_template(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
777 int two_sprites, const uint8_t *src2a, const uint8_t *src2b, int offset2,
778 int alpha, int scaled, int width)
785 a1 = a1 + ((b1 - a1) * offset1 >> 16);
791 a2 = a2 + ((b2 - a2) * offset2 >> 16);
793 a1 = a1 + ((a2 - a1) * alpha >> 16);
799 static void sprite_v_single_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset, int width)
801 sprite_v_template(dst, src1a, src1b, offset, 0, NULL, NULL, 0, 0, 1, width);
804 static void sprite_v_double_noscale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src2a, int alpha, int width)
806 sprite_v_template(dst, src1a, NULL, 0, 1, src2a, NULL, 0, alpha, 0, width);
809 static void sprite_v_double_onescale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
810 const uint8_t *src2a, int alpha, int width)
812 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, NULL, 0, alpha, 1, width);
815 static void sprite_v_double_twoscale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
816 const uint8_t *src2a, const uint8_t *src2b, int offset2,
817 int alpha, int width)
819 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, src2b, offset2, alpha, 2, width);
824 av_cold void ff_vc1dsp_init(VC1DSPContext* dsp) {
825 dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c;
826 dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c;
827 dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_c;
828 dsp->vc1_inv_trans_4x4 = vc1_inv_trans_4x4_c;
829 dsp->vc1_inv_trans_8x8_dc = vc1_inv_trans_8x8_dc_c;
830 dsp->vc1_inv_trans_4x8_dc = vc1_inv_trans_4x8_dc_c;
831 dsp->vc1_inv_trans_8x4_dc = vc1_inv_trans_8x4_dc_c;
832 dsp->vc1_inv_trans_4x4_dc = vc1_inv_trans_4x4_dc_c;
833 dsp->vc1_h_overlap = vc1_h_overlap_c;
834 dsp->vc1_v_overlap = vc1_v_overlap_c;
835 dsp->vc1_h_s_overlap = vc1_h_s_overlap_c;
836 dsp->vc1_v_s_overlap = vc1_v_s_overlap_c;
837 dsp->vc1_v_loop_filter4 = vc1_v_loop_filter4_c;
838 dsp->vc1_h_loop_filter4 = vc1_h_loop_filter4_c;
839 dsp->vc1_v_loop_filter8 = vc1_v_loop_filter8_c;
840 dsp->vc1_h_loop_filter8 = vc1_h_loop_filter8_c;
841 dsp->vc1_v_loop_filter16 = vc1_v_loop_filter16_c;
842 dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_c;
844 dsp->put_vc1_mspel_pixels_tab[ 0] = put_pixels8x8_c;
845 dsp->put_vc1_mspel_pixels_tab[ 1] = put_vc1_mspel_mc10_c;
846 dsp->put_vc1_mspel_pixels_tab[ 2] = put_vc1_mspel_mc20_c;
847 dsp->put_vc1_mspel_pixels_tab[ 3] = put_vc1_mspel_mc30_c;
848 dsp->put_vc1_mspel_pixels_tab[ 4] = put_vc1_mspel_mc01_c;
849 dsp->put_vc1_mspel_pixels_tab[ 5] = put_vc1_mspel_mc11_c;
850 dsp->put_vc1_mspel_pixels_tab[ 6] = put_vc1_mspel_mc21_c;
851 dsp->put_vc1_mspel_pixels_tab[ 7] = put_vc1_mspel_mc31_c;
852 dsp->put_vc1_mspel_pixels_tab[ 8] = put_vc1_mspel_mc02_c;
853 dsp->put_vc1_mspel_pixels_tab[ 9] = put_vc1_mspel_mc12_c;
854 dsp->put_vc1_mspel_pixels_tab[10] = put_vc1_mspel_mc22_c;
855 dsp->put_vc1_mspel_pixels_tab[11] = put_vc1_mspel_mc32_c;
856 dsp->put_vc1_mspel_pixels_tab[12] = put_vc1_mspel_mc03_c;
857 dsp->put_vc1_mspel_pixels_tab[13] = put_vc1_mspel_mc13_c;
858 dsp->put_vc1_mspel_pixels_tab[14] = put_vc1_mspel_mc23_c;
859 dsp->put_vc1_mspel_pixels_tab[15] = put_vc1_mspel_mc33_c;
861 dsp->avg_vc1_mspel_pixels_tab[ 0] = avg_pixels8x8_c;
862 dsp->avg_vc1_mspel_pixels_tab[ 1] = avg_vc1_mspel_mc10_c;
863 dsp->avg_vc1_mspel_pixels_tab[ 2] = avg_vc1_mspel_mc20_c;
864 dsp->avg_vc1_mspel_pixels_tab[ 3] = avg_vc1_mspel_mc30_c;
865 dsp->avg_vc1_mspel_pixels_tab[ 4] = avg_vc1_mspel_mc01_c;
866 dsp->avg_vc1_mspel_pixels_tab[ 5] = avg_vc1_mspel_mc11_c;
867 dsp->avg_vc1_mspel_pixels_tab[ 6] = avg_vc1_mspel_mc21_c;
868 dsp->avg_vc1_mspel_pixels_tab[ 7] = avg_vc1_mspel_mc31_c;
869 dsp->avg_vc1_mspel_pixels_tab[ 8] = avg_vc1_mspel_mc02_c;
870 dsp->avg_vc1_mspel_pixels_tab[ 9] = avg_vc1_mspel_mc12_c;
871 dsp->avg_vc1_mspel_pixels_tab[10] = avg_vc1_mspel_mc22_c;
872 dsp->avg_vc1_mspel_pixels_tab[11] = avg_vc1_mspel_mc32_c;
873 dsp->avg_vc1_mspel_pixels_tab[12] = avg_vc1_mspel_mc03_c;
874 dsp->avg_vc1_mspel_pixels_tab[13] = avg_vc1_mspel_mc13_c;
875 dsp->avg_vc1_mspel_pixels_tab[14] = avg_vc1_mspel_mc23_c;
876 dsp->avg_vc1_mspel_pixels_tab[15] = avg_vc1_mspel_mc33_c;
878 dsp->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c;
879 dsp->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c;
880 dsp->put_no_rnd_vc1_chroma_pixels_tab[1] = put_no_rnd_vc1_chroma_mc4_c;
881 dsp->avg_no_rnd_vc1_chroma_pixels_tab[1] = avg_no_rnd_vc1_chroma_mc4_c;
883 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
884 dsp->sprite_h = sprite_h_c;
885 dsp->sprite_v_single = sprite_v_single_c;
886 dsp->sprite_v_double_noscale = sprite_v_double_noscale_c;
887 dsp->sprite_v_double_onescale = sprite_v_double_onescale_c;
888 dsp->sprite_v_double_twoscale = sprite_v_double_twoscale_c;
892 ff_vc1dsp_init_x86(dsp);
894 ff_vc1dsp_init_ppc(dsp);