2 * VC-1 and WMV3 decoder - DSP functions
3 * Copyright (c) 2006 Konstantin Shishkov
5 * This file is part of Libav.
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.
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.
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
24 * VC-1 and WMV3 decoder
29 #include "libavutil/common.h"
32 /** Apply overlap transform to horizontal edge
34 static void vc1_v_overlap_c(uint8_t* src, int stride)
40 for(i = 0; i < 8; i++) {
45 d1 = (a - d + 3 + rnd) >> 3;
46 d2 = (a - d + b - c + 4 - rnd) >> 3;
48 src[-2*stride] = a - d1;
49 src[-stride] = av_clip_uint8(b - d2);
50 src[0] = av_clip_uint8(c + d2);
57 /** Apply overlap transform to vertical edge
59 static void vc1_h_overlap_c(uint8_t* src, int stride)
65 for(i = 0; i < 8; i++) {
70 d1 = (a - d + 3 + rnd) >> 3;
71 d2 = (a - d + b - c + 4 - rnd) >> 3;
74 src[-1] = av_clip_uint8(b - d2);
75 src[0] = av_clip_uint8(c + d2);
82 static void vc1_v_s_overlap_c(DCTELEM *top, DCTELEM *bottom)
87 int rnd1 = 4, rnd2 = 3;
88 for(i = 0; i < 8; i++) {
96 top[48] = ((a << 3) - d1 + rnd1) >> 3;
97 top[56] = ((b << 3) - d2 + rnd2) >> 3;
98 bottom[0] = ((c << 3) + d2 + rnd1) >> 3;
99 bottom[8] = ((d << 3) + d1 + rnd2) >> 3;
108 static void vc1_h_s_overlap_c(DCTELEM *left, DCTELEM *right)
113 int rnd1 = 4, rnd2 = 3;
114 for(i = 0; i < 8; i++) {
122 left[6] = ((a << 3) - d1 + rnd1) >> 3;
123 left[7] = ((b << 3) - d2 + rnd2) >> 3;
124 right[0] = ((c << 3) + d2 + rnd1) >> 3;
125 right[1] = ((d << 3) + d1 + rnd2) >> 3;
135 * VC-1 in-loop deblocking filter for one line
136 * @param src source block type
137 * @param stride block stride
138 * @param pq block quantizer
139 * @return whether other 3 pairs should be filtered or not
142 static av_always_inline int vc1_filter_line(uint8_t* src, int stride, int pq){
143 int a0 = (2*(src[-2*stride] - src[ 1*stride]) - 5*(src[-1*stride] - src[ 0*stride]) + 4) >> 3;
144 int a0_sign = a0 >> 31; /* Store sign */
145 a0 = (a0 ^ a0_sign) - a0_sign; /* a0 = FFABS(a0); */
147 int a1 = FFABS((2*(src[-4*stride] - src[-1*stride]) - 5*(src[-3*stride] - src[-2*stride]) + 4) >> 3);
148 int a2 = FFABS((2*(src[ 0*stride] - src[ 3*stride]) - 5*(src[ 1*stride] - src[ 2*stride]) + 4) >> 3);
149 if(a1 < a0 || a2 < a0){
150 int clip = src[-1*stride] - src[ 0*stride];
151 int clip_sign = clip >> 31;
152 clip = ((clip ^ clip_sign) - clip_sign)>>1;
154 int a3 = FFMIN(a1, a2);
155 int d = 5 * (a3 - a0);
156 int d_sign = (d >> 31);
157 d = ((d ^ d_sign) - d_sign) >> 3;
160 if( d_sign ^ clip_sign )
164 d = (d ^ d_sign) - d_sign; /* Restore sign */
165 src[-1*stride] = av_clip_uint8(src[-1*stride] - d);
166 src[ 0*stride] = av_clip_uint8(src[ 0*stride] + d);
176 * VC-1 in-loop deblocking filter
177 * @param src source block type
178 * @param step distance between horizontally adjacent elements
179 * @param stride distance between vertically adjacent elements
180 * @param len edge length to filter (4 or 8 pixels)
181 * @param pq block quantizer
184 static inline void vc1_loop_filter(uint8_t* src, int step, int stride, int len, int pq)
189 for(i = 0; i < len; i += 4){
190 filt3 = vc1_filter_line(src + 2*step, stride, pq);
192 vc1_filter_line(src + 0*step, stride, pq);
193 vc1_filter_line(src + 1*step, stride, pq);
194 vc1_filter_line(src + 3*step, stride, pq);
200 static void vc1_v_loop_filter4_c(uint8_t *src, int stride, int pq)
202 vc1_loop_filter(src, 1, stride, 4, pq);
205 static void vc1_h_loop_filter4_c(uint8_t *src, int stride, int pq)
207 vc1_loop_filter(src, stride, 1, 4, pq);
210 static void vc1_v_loop_filter8_c(uint8_t *src, int stride, int pq)
212 vc1_loop_filter(src, 1, stride, 8, pq);
215 static void vc1_h_loop_filter8_c(uint8_t *src, int stride, int pq)
217 vc1_loop_filter(src, stride, 1, 8, pq);
220 static void vc1_v_loop_filter16_c(uint8_t *src, int stride, int pq)
222 vc1_loop_filter(src, 1, stride, 16, pq);
225 static void vc1_h_loop_filter16_c(uint8_t *src, int stride, int pq)
227 vc1_loop_filter(src, stride, 1, 16, pq);
230 /** Do inverse transform on 8x8 block
232 static void vc1_inv_trans_8x8_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
236 dc = (3 * dc + 1) >> 1;
237 dc = (3 * dc + 16) >> 5;
238 for(i = 0; i < 8; i++){
239 dest[0] = av_clip_uint8(dest[0] + dc);
240 dest[1] = av_clip_uint8(dest[1] + dc);
241 dest[2] = av_clip_uint8(dest[2] + dc);
242 dest[3] = av_clip_uint8(dest[3] + dc);
243 dest[4] = av_clip_uint8(dest[4] + dc);
244 dest[5] = av_clip_uint8(dest[5] + dc);
245 dest[6] = av_clip_uint8(dest[6] + dc);
246 dest[7] = av_clip_uint8(dest[7] + dc);
251 static void vc1_inv_trans_8x8_c(DCTELEM block[64])
254 register int t1,t2,t3,t4,t5,t6,t7,t8;
255 DCTELEM *src, *dst, temp[64];
259 for(i = 0; i < 8; i++){
260 t1 = 12 * (src[ 0] + src[32]) + 4;
261 t2 = 12 * (src[ 0] - src[32]) + 4;
262 t3 = 16 * src[16] + 6 * src[48];
263 t4 = 6 * src[16] - 16 * src[48];
270 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
271 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
272 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
273 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
275 dst[0] = (t5 + t1) >> 3;
276 dst[1] = (t6 + t2) >> 3;
277 dst[2] = (t7 + t3) >> 3;
278 dst[3] = (t8 + t4) >> 3;
279 dst[4] = (t8 - t4) >> 3;
280 dst[5] = (t7 - t3) >> 3;
281 dst[6] = (t6 - t2) >> 3;
282 dst[7] = (t5 - t1) >> 3;
290 for(i = 0; i < 8; i++){
291 t1 = 12 * (src[ 0] + src[32]) + 64;
292 t2 = 12 * (src[ 0] - src[32]) + 64;
293 t3 = 16 * src[16] + 6 * src[48];
294 t4 = 6 * src[16] - 16 * src[48];
301 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
302 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
303 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
304 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
306 dst[ 0] = (t5 + t1) >> 7;
307 dst[ 8] = (t6 + t2) >> 7;
308 dst[16] = (t7 + t3) >> 7;
309 dst[24] = (t8 + t4) >> 7;
310 dst[32] = (t8 - t4 + 1) >> 7;
311 dst[40] = (t7 - t3 + 1) >> 7;
312 dst[48] = (t6 - t2 + 1) >> 7;
313 dst[56] = (t5 - t1 + 1) >> 7;
320 /** Do inverse transform on 8x4 part of block
322 static void vc1_inv_trans_8x4_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
326 dc = ( 3 * dc + 1) >> 1;
327 dc = (17 * dc + 64) >> 7;
328 for(i = 0; i < 4; i++){
329 dest[0] = av_clip_uint8(dest[0] + dc);
330 dest[1] = av_clip_uint8(dest[1] + dc);
331 dest[2] = av_clip_uint8(dest[2] + dc);
332 dest[3] = av_clip_uint8(dest[3] + dc);
333 dest[4] = av_clip_uint8(dest[4] + dc);
334 dest[5] = av_clip_uint8(dest[5] + dc);
335 dest[6] = av_clip_uint8(dest[6] + dc);
336 dest[7] = av_clip_uint8(dest[7] + dc);
341 static void vc1_inv_trans_8x4_c(uint8_t *dest, int linesize, DCTELEM *block)
344 register int t1,t2,t3,t4,t5,t6,t7,t8;
349 for(i = 0; i < 4; i++){
350 t1 = 12 * (src[0] + src[4]) + 4;
351 t2 = 12 * (src[0] - src[4]) + 4;
352 t3 = 16 * src[2] + 6 * src[6];
353 t4 = 6 * src[2] - 16 * src[6];
360 t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
361 t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
362 t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
363 t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
365 dst[0] = (t5 + t1) >> 3;
366 dst[1] = (t6 + t2) >> 3;
367 dst[2] = (t7 + t3) >> 3;
368 dst[3] = (t8 + t4) >> 3;
369 dst[4] = (t8 - t4) >> 3;
370 dst[5] = (t7 - t3) >> 3;
371 dst[6] = (t6 - t2) >> 3;
372 dst[7] = (t5 - t1) >> 3;
379 for(i = 0; i < 8; i++){
380 t1 = 17 * (src[ 0] + src[16]) + 64;
381 t2 = 17 * (src[ 0] - src[16]) + 64;
382 t3 = 22 * src[ 8] + 10 * src[24];
383 t4 = 22 * src[24] - 10 * src[ 8];
385 dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t1 + t3) >> 7));
386 dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t2 - t4) >> 7));
387 dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t2 + t4) >> 7));
388 dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t1 - t3) >> 7));
395 /** Do inverse transform on 4x8 parts of block
397 static void vc1_inv_trans_4x8_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
401 dc = (17 * dc + 4) >> 3;
402 dc = (12 * dc + 64) >> 7;
403 for(i = 0; i < 8; i++){
404 dest[0] = av_clip_uint8(dest[0] + dc);
405 dest[1] = av_clip_uint8(dest[1] + dc);
406 dest[2] = av_clip_uint8(dest[2] + dc);
407 dest[3] = av_clip_uint8(dest[3] + dc);
412 static void vc1_inv_trans_4x8_c(uint8_t *dest, int linesize, DCTELEM *block)
415 register int t1,t2,t3,t4,t5,t6,t7,t8;
420 for(i = 0; i < 8; i++){
421 t1 = 17 * (src[0] + src[2]) + 4;
422 t2 = 17 * (src[0] - src[2]) + 4;
423 t3 = 22 * src[1] + 10 * src[3];
424 t4 = 22 * src[3] - 10 * src[1];
426 dst[0] = (t1 + t3) >> 3;
427 dst[1] = (t2 - t4) >> 3;
428 dst[2] = (t2 + t4) >> 3;
429 dst[3] = (t1 - t3) >> 3;
436 for(i = 0; i < 4; i++){
437 t1 = 12 * (src[ 0] + src[32]) + 64;
438 t2 = 12 * (src[ 0] - src[32]) + 64;
439 t3 = 16 * src[16] + 6 * src[48];
440 t4 = 6 * src[16] - 16 * src[48];
447 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
448 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
449 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
450 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
452 dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t5 + t1) >> 7));
453 dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t6 + t2) >> 7));
454 dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t7 + t3) >> 7));
455 dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t8 + t4) >> 7));
456 dest[4*linesize] = av_clip_uint8(dest[4*linesize] + ((t8 - t4 + 1) >> 7));
457 dest[5*linesize] = av_clip_uint8(dest[5*linesize] + ((t7 - t3 + 1) >> 7));
458 dest[6*linesize] = av_clip_uint8(dest[6*linesize] + ((t6 - t2 + 1) >> 7));
459 dest[7*linesize] = av_clip_uint8(dest[7*linesize] + ((t5 - t1 + 1) >> 7));
466 /** Do inverse transform on 4x4 part of block
468 static void vc1_inv_trans_4x4_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
472 dc = (17 * dc + 4) >> 3;
473 dc = (17 * dc + 64) >> 7;
474 for(i = 0; i < 4; i++){
475 dest[0] = av_clip_uint8(dest[0] + dc);
476 dest[1] = av_clip_uint8(dest[1] + dc);
477 dest[2] = av_clip_uint8(dest[2] + dc);
478 dest[3] = av_clip_uint8(dest[3] + dc);
483 static void vc1_inv_trans_4x4_c(uint8_t *dest, int linesize, DCTELEM *block)
486 register int t1,t2,t3,t4;
491 for(i = 0; i < 4; i++){
492 t1 = 17 * (src[0] + src[2]) + 4;
493 t2 = 17 * (src[0] - src[2]) + 4;
494 t3 = 22 * src[1] + 10 * src[3];
495 t4 = 22 * src[3] - 10 * src[1];
497 dst[0] = (t1 + t3) >> 3;
498 dst[1] = (t2 - t4) >> 3;
499 dst[2] = (t2 + t4) >> 3;
500 dst[3] = (t1 - t3) >> 3;
507 for(i = 0; i < 4; i++){
508 t1 = 17 * (src[ 0] + src[16]) + 64;
509 t2 = 17 * (src[ 0] - src[16]) + 64;
510 t3 = 22 * src[ 8] + 10 * src[24];
511 t4 = 22 * src[24] - 10 * src[ 8];
513 dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t1 + t3) >> 7));
514 dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t2 - t4) >> 7));
515 dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t2 + t4) >> 7));
516 dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t1 - t3) >> 7));
523 /* motion compensation functions */
524 /** Filter in case of 2 filters */
525 #define VC1_MSPEL_FILTER_16B(DIR, TYPE) \
526 static av_always_inline int vc1_mspel_ ## DIR ## _filter_16bits(const TYPE *src, int stride, int mode) \
529 case 0: /* no shift - should not occur */ \
531 case 1: /* 1/4 shift */ \
532 return -4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2]; \
533 case 2: /* 1/2 shift */ \
534 return -src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2]; \
535 case 3: /* 3/4 shift */ \
536 return -3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2]; \
538 return 0; /* should not occur */ \
541 VC1_MSPEL_FILTER_16B(ver, uint8_t)
542 VC1_MSPEL_FILTER_16B(hor, int16_t)
545 /** Filter used to interpolate fractional pel values
547 static av_always_inline int vc1_mspel_filter(const uint8_t *src, int stride, int mode, int r)
553 return (-4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2] + 32 - r) >> 6;
555 return (-src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2] + 8 - r) >> 4;
557 return (-3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2] + 32 - r) >> 6;
559 return 0; //should not occur
562 /** Function used to do motion compensation with bicubic interpolation
564 #define VC1_MSPEL_MC(OP, OPNAME)\
565 static av_always_inline void OPNAME ## vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, int hmode, int vmode, int rnd)\
569 if (vmode) { /* Horizontal filter to apply */\
572 if (hmode) { /* Vertical filter to apply, output to tmp */\
573 static const int shift_value[] = { 0, 5, 1, 5 };\
574 int shift = (shift_value[hmode]+shift_value[vmode])>>1;\
575 int16_t tmp[11*8], *tptr = tmp;\
577 r = (1<<(shift-1)) + rnd-1;\
580 for(j = 0; j < 8; j++) {\
581 for(i = 0; i < 11; i++)\
582 tptr[i] = (vc1_mspel_ver_filter_16bits(src + i, stride, vmode)+r)>>shift;\
589 for(j = 0; j < 8; j++) {\
590 for(i = 0; i < 8; i++)\
591 OP(dst[i], (vc1_mspel_hor_filter_16bits(tptr + i, 1, hmode)+r)>>7);\
598 else { /* No horizontal filter, output 8 lines to dst */\
601 for(j = 0; j < 8; j++) {\
602 for(i = 0; i < 8; i++)\
603 OP(dst[i], vc1_mspel_filter(src + i, stride, vmode, r));\
611 /* Horizontal mode with no vertical mode */\
612 for(j = 0; j < 8; j++) {\
613 for(i = 0; i < 8; i++)\
614 OP(dst[i], vc1_mspel_filter(src + i, 1, hmode, rnd));\
620 #define op_put(a, b) a = av_clip_uint8(b)
621 #define op_avg(a, b) a = (a + av_clip_uint8(b) + 1) >> 1
623 VC1_MSPEL_MC(op_put, put_)
624 VC1_MSPEL_MC(op_avg, avg_)
626 /* pixel functions - really are entry points to vc1_mspel_mc */
628 #define PUT_VC1_MSPEL(a, b)\
629 static void put_vc1_mspel_mc ## a ## b ##_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \
630 put_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
632 static void avg_vc1_mspel_mc ## a ## b ##_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \
633 avg_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
655 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){
656 const int A=(8-x)*(8-y);
657 const int B=( x)*(8-y);
658 const int C=(8-x)*( y);
659 const int D=( x)*( y);
662 assert(x<8 && y<8 && x>=0 && y>=0);
666 dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
667 dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
668 dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
669 dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
670 dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6;
671 dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6;
672 dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6;
673 dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6;
679 static void put_no_rnd_vc1_chroma_mc4_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y){
680 const int A=(8-x)*(8-y);
681 const int B=( x)*(8-y);
682 const int C=(8-x)*( y);
683 const int D=( x)*( y);
686 assert(x<8 && y<8 && x>=0 && y>=0);
690 dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
691 dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
692 dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
693 dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
699 #define avg2(a,b) ((a+b+1)>>1)
700 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){
701 const int A=(8-x)*(8-y);
702 const int B=( x)*(8-y);
703 const int C=(8-x)*( y);
704 const int D=( x)*( y);
707 assert(x<8 && y<8 && x>=0 && y>=0);
711 dst[0] = avg2(dst[0], ((A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6));
712 dst[1] = avg2(dst[1], ((A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6));
713 dst[2] = avg2(dst[2], ((A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6));
714 dst[3] = avg2(dst[3], ((A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6));
715 dst[4] = avg2(dst[4], ((A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6));
716 dst[5] = avg2(dst[5], ((A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6));
717 dst[6] = avg2(dst[6], ((A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6));
718 dst[7] = avg2(dst[7], ((A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6));
724 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
726 static void sprite_h_c(uint8_t *dst, const uint8_t *src, int offset, int advance, int count)
729 int a = src[(offset >> 16) ];
730 int b = src[(offset >> 16) + 1];
731 *dst++ = a + ((b - a) * (offset&0xFFFF) >> 16);
736 static av_always_inline void sprite_v_template(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
737 int two_sprites, const uint8_t *src2a, const uint8_t *src2b, int offset2,
738 int alpha, int scaled, int width)
745 a1 = a1 + ((b1 - a1) * offset1 >> 16);
751 a2 = a2 + ((b2 - a2) * offset2 >> 16);
753 a1 = a1 + ((a2 - a1) * alpha >> 16);
759 static void sprite_v_single_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset, int width)
761 sprite_v_template(dst, src1a, src1b, offset, 0, NULL, NULL, 0, 0, 1, width);
764 static void sprite_v_double_noscale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src2a, int alpha, int width)
766 sprite_v_template(dst, src1a, NULL, 0, 1, src2a, NULL, 0, alpha, 0, width);
769 static void sprite_v_double_onescale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
770 const uint8_t *src2a, int alpha, int width)
772 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, NULL, 0, alpha, 1, width);
775 static void sprite_v_double_twoscale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
776 const uint8_t *src2a, const uint8_t *src2b, int offset2,
777 int alpha, int width)
779 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, src2b, offset2, alpha, 2, width);
784 av_cold void ff_vc1dsp_init(VC1DSPContext* dsp) {
785 dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c;
786 dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c;
787 dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_c;
788 dsp->vc1_inv_trans_4x4 = vc1_inv_trans_4x4_c;
789 dsp->vc1_inv_trans_8x8_dc = vc1_inv_trans_8x8_dc_c;
790 dsp->vc1_inv_trans_4x8_dc = vc1_inv_trans_4x8_dc_c;
791 dsp->vc1_inv_trans_8x4_dc = vc1_inv_trans_8x4_dc_c;
792 dsp->vc1_inv_trans_4x4_dc = vc1_inv_trans_4x4_dc_c;
793 dsp->vc1_h_overlap = vc1_h_overlap_c;
794 dsp->vc1_v_overlap = vc1_v_overlap_c;
795 dsp->vc1_h_s_overlap = vc1_h_s_overlap_c;
796 dsp->vc1_v_s_overlap = vc1_v_s_overlap_c;
797 dsp->vc1_v_loop_filter4 = vc1_v_loop_filter4_c;
798 dsp->vc1_h_loop_filter4 = vc1_h_loop_filter4_c;
799 dsp->vc1_v_loop_filter8 = vc1_v_loop_filter8_c;
800 dsp->vc1_h_loop_filter8 = vc1_h_loop_filter8_c;
801 dsp->vc1_v_loop_filter16 = vc1_v_loop_filter16_c;
802 dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_c;
804 dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_pixels8x8_c;
805 dsp->put_vc1_mspel_pixels_tab[ 1] = put_vc1_mspel_mc10_c;
806 dsp->put_vc1_mspel_pixels_tab[ 2] = put_vc1_mspel_mc20_c;
807 dsp->put_vc1_mspel_pixels_tab[ 3] = put_vc1_mspel_mc30_c;
808 dsp->put_vc1_mspel_pixels_tab[ 4] = put_vc1_mspel_mc01_c;
809 dsp->put_vc1_mspel_pixels_tab[ 5] = put_vc1_mspel_mc11_c;
810 dsp->put_vc1_mspel_pixels_tab[ 6] = put_vc1_mspel_mc21_c;
811 dsp->put_vc1_mspel_pixels_tab[ 7] = put_vc1_mspel_mc31_c;
812 dsp->put_vc1_mspel_pixels_tab[ 8] = put_vc1_mspel_mc02_c;
813 dsp->put_vc1_mspel_pixels_tab[ 9] = put_vc1_mspel_mc12_c;
814 dsp->put_vc1_mspel_pixels_tab[10] = put_vc1_mspel_mc22_c;
815 dsp->put_vc1_mspel_pixels_tab[11] = put_vc1_mspel_mc32_c;
816 dsp->put_vc1_mspel_pixels_tab[12] = put_vc1_mspel_mc03_c;
817 dsp->put_vc1_mspel_pixels_tab[13] = put_vc1_mspel_mc13_c;
818 dsp->put_vc1_mspel_pixels_tab[14] = put_vc1_mspel_mc23_c;
819 dsp->put_vc1_mspel_pixels_tab[15] = put_vc1_mspel_mc33_c;
821 dsp->avg_vc1_mspel_pixels_tab[ 0] = ff_avg_pixels8x8_c;
822 dsp->avg_vc1_mspel_pixels_tab[ 1] = avg_vc1_mspel_mc10_c;
823 dsp->avg_vc1_mspel_pixels_tab[ 2] = avg_vc1_mspel_mc20_c;
824 dsp->avg_vc1_mspel_pixels_tab[ 3] = avg_vc1_mspel_mc30_c;
825 dsp->avg_vc1_mspel_pixels_tab[ 4] = avg_vc1_mspel_mc01_c;
826 dsp->avg_vc1_mspel_pixels_tab[ 5] = avg_vc1_mspel_mc11_c;
827 dsp->avg_vc1_mspel_pixels_tab[ 6] = avg_vc1_mspel_mc21_c;
828 dsp->avg_vc1_mspel_pixels_tab[ 7] = avg_vc1_mspel_mc31_c;
829 dsp->avg_vc1_mspel_pixels_tab[ 8] = avg_vc1_mspel_mc02_c;
830 dsp->avg_vc1_mspel_pixels_tab[ 9] = avg_vc1_mspel_mc12_c;
831 dsp->avg_vc1_mspel_pixels_tab[10] = avg_vc1_mspel_mc22_c;
832 dsp->avg_vc1_mspel_pixels_tab[11] = avg_vc1_mspel_mc32_c;
833 dsp->avg_vc1_mspel_pixels_tab[12] = avg_vc1_mspel_mc03_c;
834 dsp->avg_vc1_mspel_pixels_tab[13] = avg_vc1_mspel_mc13_c;
835 dsp->avg_vc1_mspel_pixels_tab[14] = avg_vc1_mspel_mc23_c;
836 dsp->avg_vc1_mspel_pixels_tab[15] = avg_vc1_mspel_mc33_c;
838 dsp->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c;
839 dsp->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c;
840 dsp->put_no_rnd_vc1_chroma_pixels_tab[1] = put_no_rnd_vc1_chroma_mc4_c;
842 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
843 dsp->sprite_h = sprite_h_c;
844 dsp->sprite_v_single = sprite_v_single_c;
845 dsp->sprite_v_double_noscale = sprite_v_double_noscale_c;
846 dsp->sprite_v_double_onescale = sprite_v_double_onescale_c;
847 dsp->sprite_v_double_twoscale = sprite_v_double_twoscale_c;
851 ff_vc1dsp_init_altivec(dsp);
853 ff_vc1dsp_init_x86(dsp);