44 for (i = 0; i < 8; i++) {
49 d1 = (a - d + 3 + rnd) >> 3;
50 d2 = (a - d + b - c + 4 - rnd) >> 3;
52 src[-2 * stride] = a - d1;
53 src[-stride] = av_clip_uint8(b - d2);
54 src[0] = av_clip_uint8(c + d2);
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);
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;
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;
147 int a0 = (2 * (src[-2 * stride] - src[1 * stride]) -
148 5 * (src[-1 * stride] - src[0 * stride]) + 4) >> 3;
149 int a0_sign = a0 >> 31;
151 a0 = (a0 ^ a0_sign) - a0_sign;
153 int a1 =
FFABS((2 * (src[-4 * stride] - src[-1 * stride]) -
154 5 * (src[-3 * stride] - src[-2 * stride]) + 4) >> 3);
155 int a2 =
FFABS((2 * (src[ 0 * stride] - src[ 3 * stride]) -
156 5 * (src[ 1 * stride] - src[ 2 * stride]) + 4) >> 3);
157 if (a1 < a0 || a2 < a0) {
158 int clip = src[-1 * stride] - src[0 * stride];
159 int clip_sign = clip >> 31;
161 clip = ((clip ^ clip_sign) - clip_sign) >> 1;
164 int d = 5 * (a3 -
a0);
165 int d_sign = (d >> 31);
167 d = ((d ^ d_sign) - d_sign) >> 3;
170 if (d_sign ^ clip_sign)
174 d = (d ^ d_sign) - d_sign;
175 src[-1 * stride] = av_clip_uint8(src[-1 * stride] - d);
176 src[ 0 * stride] = av_clip_uint8(src[ 0 * stride] + d);
200 for (i = 0; i <
len; i += 4) {
247 dc = (3 * dc + 1) >> 1;
248 dc = (3 * dc + 16) >> 5;
250 for (i = 0; i < 8; i++) {
251 dest[0] = av_clip_uint8(dest[0] + dc);
252 dest[1] = av_clip_uint8(dest[1] + dc);
253 dest[2] = av_clip_uint8(dest[2] + dc);
254 dest[3] = av_clip_uint8(dest[3] + dc);
255 dest[4] = av_clip_uint8(dest[4] + dc);
256 dest[5] = av_clip_uint8(dest[5] + dc);
257 dest[6] = av_clip_uint8(dest[6] + dc);
258 dest[7] = av_clip_uint8(dest[7] + dc);
271 for (i = 0; i < 8; i++) {
272 t1 = 12 * (src[ 0] + src[32]) + 4;
273 t2 = 12 * (src[ 0] - src[32]) + 4;
274 t3 = 16 * src[16] + 6 * src[48];
275 t4 = 6 * src[16] - 16 * src[48];
282 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
283 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
284 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
285 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
287 dst[0] = (t5 +
t1) >> 3;
288 dst[1] = (t6 +
t2) >> 3;
289 dst[2] = (t7 +
t3) >> 3;
290 dst[3] = (t8 +
t4) >> 3;
291 dst[4] = (t8 -
t4) >> 3;
292 dst[5] = (t7 -
t3) >> 3;
293 dst[6] = (t6 -
t2) >> 3;
294 dst[7] = (t5 -
t1) >> 3;
302 for (i = 0; i < 8; i++) {
303 t1 = 12 * (src[ 0] + src[32]) + 64;
304 t2 = 12 * (src[ 0] - src[32]) + 64;
305 t3 = 16 * src[16] + 6 * src[48];
306 t4 = 6 * src[16] - 16 * src[48];
313 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
314 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
315 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
316 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
318 dst[ 0] = (t5 +
t1) >> 7;
319 dst[ 8] = (t6 +
t2) >> 7;
320 dst[16] = (t7 +
t3) >> 7;
321 dst[24] = (t8 +
t4) >> 7;
322 dst[32] = (t8 - t4 + 1) >> 7;
323 dst[40] = (t7 - t3 + 1) >> 7;
324 dst[48] = (t6 - t2 + 1) >> 7;
325 dst[56] = (t5 - t1 + 1) >> 7;
338 dc = (3 * dc + 1) >> 1;
339 dc = (17 * dc + 64) >> 7;
341 for (i = 0; i < 4; i++) {
342 dest[0] = av_clip_uint8(dest[0] + dc);
343 dest[1] = av_clip_uint8(dest[1] + dc);
344 dest[2] = av_clip_uint8(dest[2] + dc);
345 dest[3] = av_clip_uint8(dest[3] + dc);
346 dest[4] = av_clip_uint8(dest[4] + dc);
347 dest[5] = av_clip_uint8(dest[5] + dc);
348 dest[6] = av_clip_uint8(dest[6] + dc);
349 dest[7] = av_clip_uint8(dest[7] + dc);
363 for (i = 0; i < 4; i++) {
364 t1 = 12 * (src[0] + src[4]) + 4;
365 t2 = 12 * (src[0] - src[4]) + 4;
366 t3 = 16 * src[2] + 6 * src[6];
367 t4 = 6 * src[2] - 16 * src[6];
374 t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
375 t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
376 t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
377 t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
379 dst[0] = (t5 +
t1) >> 3;
380 dst[1] = (t6 +
t2) >> 3;
381 dst[2] = (t7 +
t3) >> 3;
382 dst[3] = (t8 +
t4) >> 3;
383 dst[4] = (t8 -
t4) >> 3;
384 dst[5] = (t7 -
t3) >> 3;
385 dst[6] = (t6 -
t2) >> 3;
386 dst[7] = (t5 -
t1) >> 3;
393 for (i = 0; i < 8; i++) {
394 t1 = 17 * (src[ 0] + src[16]) + 64;
395 t2 = 17 * (src[ 0] - src[16]) + 64;
396 t3 = 22 * src[ 8] + 10 * src[24];
397 t4 = 22 * src[24] - 10 * src[ 8];
399 dest[0 * linesize] = av_clip_uint8(dest[0 * linesize] + ((t1 + t3) >> 7));
400 dest[1 * linesize] = av_clip_uint8(dest[1 * linesize] + ((t2 - t4) >> 7));
401 dest[2 * linesize] = av_clip_uint8(dest[2 * linesize] + ((t2 + t4) >> 7));
402 dest[3 * linesize] = av_clip_uint8(dest[3 * linesize] + ((t1 - t3) >> 7));
415 dc = (17 * dc + 4) >> 3;
416 dc = (12 * dc + 64) >> 7;
418 for (i = 0; i < 8; i++) {
419 dest[0] = av_clip_uint8(dest[0] + dc);
420 dest[1] = av_clip_uint8(dest[1] + dc);
421 dest[2] = av_clip_uint8(dest[2] + dc);
422 dest[3] = av_clip_uint8(dest[3] + dc);
436 for (i = 0; i < 8; i++) {
437 t1 = 17 * (src[0] + src[2]) + 4;
438 t2 = 17 * (src[0] - src[2]) + 4;
439 t3 = 22 * src[1] + 10 * src[3];
440 t4 = 22 * src[3] - 10 * src[1];
442 dst[0] = (t1 +
t3) >> 3;
443 dst[1] = (t2 -
t4) >> 3;
444 dst[2] = (t2 +
t4) >> 3;
445 dst[3] = (t1 -
t3) >> 3;
452 for (i = 0; i < 4; i++) {
453 t1 = 12 * (src[ 0] + src[32]) + 64;
454 t2 = 12 * (src[ 0] - src[32]) + 64;
455 t3 = 16 * src[16] + 6 * src[48];
456 t4 = 6 * src[16] - 16 * src[48];
463 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
464 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
465 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
466 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
468 dest[0 * linesize] = av_clip_uint8(dest[0 * linesize] + ((t5 + t1) >> 7));
469 dest[1 * linesize] = av_clip_uint8(dest[1 * linesize] + ((t6 + t2) >> 7));
470 dest[2 * linesize] = av_clip_uint8(dest[2 * linesize] + ((t7 + t3) >> 7));
471 dest[3 * linesize] = av_clip_uint8(dest[3 * linesize] + ((t8 + t4) >> 7));
472 dest[4 * linesize] = av_clip_uint8(dest[4 * linesize] + ((t8 - t4 + 1) >> 7));
473 dest[5 * linesize] = av_clip_uint8(dest[5 * linesize] + ((t7 - t3 + 1) >> 7));
474 dest[6 * linesize] = av_clip_uint8(dest[6 * linesize] + ((t6 - t2 + 1) >> 7));
475 dest[7 * linesize] = av_clip_uint8(dest[7 * linesize] + ((t5 - t1 + 1) >> 7));
488 dc = (17 * dc + 4) >> 3;
489 dc = (17 * dc + 64) >> 7;
491 for (i = 0; i < 4; i++) {
492 dest[0] = av_clip_uint8(dest[0] + dc);
493 dest[1] = av_clip_uint8(dest[1] + dc);
494 dest[2] = av_clip_uint8(dest[2] + dc);
495 dest[3] = av_clip_uint8(dest[3] + dc);
508 for (i = 0; i < 4; i++) {
509 t1 = 17 * (src[0] + src[2]) + 4;
510 t2 = 17 * (src[0] - src[2]) + 4;
511 t3 = 22 * src[1] + 10 * src[3];
512 t4 = 22 * src[3] - 10 * src[1];
514 dst[0] = (t1 +
t3) >> 3;
515 dst[1] = (t2 -
t4) >> 3;
516 dst[2] = (t2 +
t4) >> 3;
517 dst[3] = (t1 -
t3) >> 3;
524 for (i = 0; i < 4; i++) {
525 t1 = 17 * (src[0] + src[16]) + 64;
526 t2 = 17 * (src[0] - src[16]) + 64;
527 t3 = 22 * src[8] + 10 * src[24];
528 t4 = 22 * src[24] - 10 * src[8];
530 dest[0 * linesize] = av_clip_uint8(dest[0 * linesize] + ((t1 + t3) >> 7));
531 dest[1 * linesize] = av_clip_uint8(dest[1 * linesize] + ((t2 - t4) >> 7));
532 dest[2 * linesize] = av_clip_uint8(dest[2 * linesize] + ((t2 + t4) >> 7));
533 dest[3 * linesize] = av_clip_uint8(dest[3 * linesize] + ((t1 - t3) >> 7));
543 #define VC1_MSPEL_FILTER_16B(DIR, TYPE) \
544 static av_always_inline int vc1_mspel_ ## DIR ## _filter_16bits(const TYPE *src, \
552 return -4 * src[-stride] + 53 * src[0] + \
553 18 * src[stride] - 3 * src[stride * 2]; \
555 return -1 * src[-stride] + 9 * src[0] + \
556 9 * src[stride] - 1 * src[stride * 2]; \
558 return -3 * src[-stride] + 18 * src[0] + \
559 53 * src[stride] - 4 * src[stride * 2]; \
575 return (-4 * src[-stride] + 53 * src[0] +
576 18 * src[stride] - 3 * src[stride * 2] + 32 - r) >> 6;
578 return (-1 * src[-stride] + 9 * src[0] +
579 9 * src[stride] - 1 * src[stride * 2] + 8 - r) >> 4;
581 return (-3 * src[-stride] + 18 * src[0] +
582 53 * src[stride] - 4 * src[stride * 2] + 32 - r) >> 6;
588 #define VC1_MSPEL_MC(OP, OP4, OPNAME) \
589 static av_always_inline void OPNAME ## vc1_mspel_mc(uint8_t *dst, \
590 const uint8_t *src, \
602 static const int shift_value[] = { 0, 5, 1, 5 }; \
603 int shift = (shift_value[hmode] + shift_value[vmode]) >> 1; \
604 int16_t tmp[11 * 8], *tptr = tmp; \
606 r = (1 << (shift - 1)) + rnd - 1; \
609 for (j = 0; j < 8; j++) { \
610 for (i = 0; i < 11; i++) \
611 tptr[i] = (vc1_mspel_ver_filter_16bits(src + i, stride, vmode) + r) >> shift; \
618 for (j = 0; j < 8; j++) { \
619 for (i = 0; i < 8; i++) \
620 OP(dst[i], (vc1_mspel_hor_filter_16bits(tptr + i, 1, hmode) + r) >> 7); \
629 for (j = 0; j < 8; j++) { \
630 for (i = 0; i < 8; i++) \
631 OP(dst[i], vc1_mspel_filter(src + i, stride, vmode, r)); \
640 for (j = 0; j < 8; j++) { \
641 for (i = 0; i < 8; i++) \
642 OP(dst[i], vc1_mspel_filter(src + i, 1, hmode, rnd)); \
647 static av_always_inline void OPNAME ## vc1_mspel_mc_16(uint8_t *dst, \
648 const uint8_t *src, \
660 static const int shift_value[] = { 0, 5, 1, 5 }; \
661 int shift = (shift_value[hmode] + shift_value[vmode]) >> 1; \
662 int16_t tmp[19 * 16], *tptr = tmp; \
664 r = (1 << (shift - 1)) + rnd - 1; \
667 for (j = 0; j < 16; j++) { \
668 for (i = 0; i < 19; i++) \
669 tptr[i] = (vc1_mspel_ver_filter_16bits(src + i, stride, vmode) + r) >> shift; \
676 for (j = 0; j < 16; j++) { \
677 for (i = 0; i < 16; i++) \
678 OP(dst[i], (vc1_mspel_hor_filter_16bits(tptr + i, 1, hmode) + r) >> 7); \
687 for (j = 0; j < 16; j++) { \
688 for (i = 0; i < 16; i++) \
689 OP(dst[i], vc1_mspel_filter(src + i, stride, vmode, r)); \
698 for (j = 0; j < 16; j++) { \
699 for (i = 0; i < 16; i++) \
700 OP(dst[i], vc1_mspel_filter(src + i, 1, hmode, rnd)); \
705 static void OPNAME ## pixels8x8_c(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int rnd){\
708 OP4(*(uint32_t*)(block ), AV_RN32(pixels ));\
709 OP4(*(uint32_t*)(block+4), AV_RN32(pixels+4));\
714 static void OPNAME ## pixels16x16_c(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int rnd){\
716 for(i=0; i<16; i++){\
717 OP4(*(uint32_t*)(block ), AV_RN32(pixels ));\
718 OP4(*(uint32_t*)(block+ 4), AV_RN32(pixels+ 4));\
719 OP4(*(uint32_t*)(block+ 8), AV_RN32(pixels+ 8));\
720 OP4(*(uint32_t*)(block+12), AV_RN32(pixels+12));\
726 #define op_put(a, b) a = av_clip_uint8(b)
727 #define op_avg(a, b) a = (a + av_clip_uint8(b) + 1) >> 1
728 #define op4_avg(a, b) a = rnd_avg32(a, b)
729 #define op4_put(a, b) a = b
736 #define PUT_VC1_MSPEL(a, b) \
737 static void put_vc1_mspel_mc ## a ## b ## _c(uint8_t *dst, \
738 const uint8_t *src, \
739 ptrdiff_t stride, int rnd) \
741 put_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
743 static void avg_vc1_mspel_mc ## a ## b ## _c(uint8_t *dst, \
744 const uint8_t *src, \
745 ptrdiff_t stride, int rnd) \
747 avg_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
749 static void put_vc1_mspel_mc ## a ## b ## _16_c(uint8_t *dst, \
750 const uint8_t *src, \
751 ptrdiff_t stride, int rnd) \
753 put_vc1_mspel_mc_16(dst, src, stride, a, b, rnd); \
755 static void avg_vc1_mspel_mc ## a ## b ## _16_c(uint8_t *dst, \
756 const uint8_t *src, \
757 ptrdiff_t stride, int rnd) \
759 avg_vc1_mspel_mc_16(dst, src, stride, a, b, rnd); \
781 #define chroma_mc(a) \
782 ((A * src[a] + B * src[a + 1] + \
783 C * src[stride + a] + D * src[stride + a + 1] + 32 - 4) >> 6)
786 int stride,
int h,
int x,
int y)
788 const int A = (8 - x) * (8 - y);
789 const int B = (x) * (8 - y);
790 const int C = (8 - x) * (y);
791 const int D = (x) * (y);
794 av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
796 for (i = 0; i < h; i++) {
811 int stride,
int h,
int x,
int y)
813 const int A = (8 - x) * (8 - y);
814 const int B = (x) * (8 - y);
815 const int C = (8 - x) * (y);
816 const int D = (x) * (y);
819 av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
821 for (i = 0; i < h; i++) {
831 #define avg2(a, b) (((a) + (b) + 1) >> 1)
834 int stride,
int h,
int x,
int y)
836 const int A = (8 - x) * (8 - y);
837 const int B = (x) * (8 - y);
838 const int C = (8 - x) * (y);
839 const int D = (x) * (y);
842 av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
844 for (i = 0; i < h; i++) {
860 int stride,
int h,
int x,
int y)
862 const int A = (8 - x) * (8 - y);
863 const int B = ( x) * (8 - y);
864 const int C = (8 - x) * ( y);
865 const int D = ( x) * ( y);
868 av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
870 for (i = 0; i < h; i++) {
880 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
883 int advance,
int count)
886 int a = src[(offset >> 16)];
887 int b = src[(offset >> 16) + 1];
888 *dst++ = a + ((b -
a) * (offset & 0xFFFF) >> 16);
901 int alpha,
int scaled,
909 a1 = a1 + ((b1 -
a1) * offset1 >> 16);
915 a2 = a2 + ((b2 -
a2) * offset2 >> 16);
917 a1 = a1 + ((a2 -
a1) * alpha >> 16);
925 int offset,
int width)
927 sprite_v_template(dst, src1a, src1b, offset, 0, NULL, NULL, 0, 0, 1, width);
930 static void sprite_v_double_noscale_c(
uint8_t *dst,
const uint8_t *src1a,
932 int alpha,
int width)
934 sprite_v_template(dst, src1a, NULL, 0, 1, src2a, NULL, 0, alpha, 0, width);
937 static void sprite_v_double_onescale_c(
uint8_t *dst,
942 int alpha,
int width)
944 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, NULL, 0, alpha, 1,
948 static void sprite_v_double_twoscale_c(
uint8_t *dst,
958 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, src2b, offset2,
963 #define FN_ASSIGN(X, Y) \
964 dsp->put_vc1_mspel_pixels_tab[1][X+4*Y] = put_vc1_mspel_mc##X##Y##_c; \
965 dsp->put_vc1_mspel_pixels_tab[0][X+4*Y] = put_vc1_mspel_mc##X##Y##_16_c; \
966 dsp->avg_vc1_mspel_pixels_tab[1][X+4*Y] = avg_vc1_mspel_mc##X##Y##_c; \
967 dsp->avg_vc1_mspel_pixels_tab[0][X+4*Y] = avg_vc1_mspel_mc##X##Y##_16_c
1020 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER