41 for (i = 0; i < 8; i++) {
46 d1 = (a - d + 3 + rnd) >> 3;
47 d2 = (a - d + b - c + 4 - rnd) >> 3;
49 src[-2 * stride] = a - d1;
50 src[-stride] = av_clip_uint8(b - d2);
51 src[0] = av_clip_uint8(c + d2);
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);
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;
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;
144 int a0 = (2 * (src[-2 * stride] - src[1 * stride]) -
145 5 * (src[-1 * stride] - src[0 * stride]) + 4) >> 3;
146 int a0_sign = a0 >> 31;
148 a0 = (a0 ^ a0_sign) - a0_sign;
150 int a1 =
FFABS((2 * (src[-4 * stride] - src[-1 * stride]) -
151 5 * (src[-3 * stride] - src[-2 * stride]) + 4) >> 3);
152 int a2 =
FFABS((2 * (src[ 0 * stride] - src[ 3 * stride]) -
153 5 * (src[ 1 * stride] - src[ 2 * stride]) + 4) >> 3);
154 if (a1 < a0 || a2 < a0) {
155 int clip = src[-1 * stride] - src[0 * stride];
156 int clip_sign = clip >> 31;
158 clip = ((clip ^ clip_sign) - clip_sign) >> 1;
161 int d = 5 * (a3 -
a0);
162 int d_sign = (d >> 31);
164 d = ((d ^ d_sign) - d_sign) >> 3;
167 if (d_sign ^ clip_sign)
171 d = (d ^ d_sign) - d_sign;
172 src[-1 * stride] = av_clip_uint8(src[-1 * stride] - d);
173 src[ 0 * stride] = av_clip_uint8(src[ 0 * stride] + d);
197 for (i = 0; i <
len; i += 4) {
244 dc = (3 * dc + 1) >> 1;
245 dc = (3 * dc + 16) >> 5;
247 for (i = 0; i < 8; i++) {
248 dest[0] = av_clip_uint8(dest[0] + dc);
249 dest[1] = av_clip_uint8(dest[1] + dc);
250 dest[2] = av_clip_uint8(dest[2] + dc);
251 dest[3] = av_clip_uint8(dest[3] + dc);
252 dest[4] = av_clip_uint8(dest[4] + dc);
253 dest[5] = av_clip_uint8(dest[5] + dc);
254 dest[6] = av_clip_uint8(dest[6] + dc);
255 dest[7] = av_clip_uint8(dest[7] + dc);
268 for (i = 0; i < 8; i++) {
269 t1 = 12 * (src[ 0] + src[32]) + 4;
270 t2 = 12 * (src[ 0] - src[32]) + 4;
271 t3 = 16 * src[16] + 6 * src[48];
272 t4 = 6 * src[16] - 16 * src[48];
279 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
280 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
281 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
282 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
284 dst[0] = (t5 +
t1) >> 3;
285 dst[1] = (t6 +
t2) >> 3;
286 dst[2] = (t7 +
t3) >> 3;
287 dst[3] = (t8 +
t4) >> 3;
288 dst[4] = (t8 -
t4) >> 3;
289 dst[5] = (t7 -
t3) >> 3;
290 dst[6] = (t6 -
t2) >> 3;
291 dst[7] = (t5 -
t1) >> 3;
299 for (i = 0; i < 8; i++) {
300 t1 = 12 * (src[ 0] + src[32]) + 64;
301 t2 = 12 * (src[ 0] - src[32]) + 64;
302 t3 = 16 * src[16] + 6 * src[48];
303 t4 = 6 * src[16] - 16 * src[48];
310 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
311 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
312 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
313 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
315 dst[ 0] = (t5 +
t1) >> 7;
316 dst[ 8] = (t6 +
t2) >> 7;
317 dst[16] = (t7 +
t3) >> 7;
318 dst[24] = (t8 +
t4) >> 7;
319 dst[32] = (t8 - t4 + 1) >> 7;
320 dst[40] = (t7 - t3 + 1) >> 7;
321 dst[48] = (t6 - t2 + 1) >> 7;
322 dst[56] = (t5 - t1 + 1) >> 7;
335 dc = (3 * dc + 1) >> 1;
336 dc = (17 * dc + 64) >> 7;
338 for (i = 0; i < 4; i++) {
339 dest[0] = av_clip_uint8(dest[0] + dc);
340 dest[1] = av_clip_uint8(dest[1] + dc);
341 dest[2] = av_clip_uint8(dest[2] + dc);
342 dest[3] = av_clip_uint8(dest[3] + dc);
343 dest[4] = av_clip_uint8(dest[4] + dc);
344 dest[5] = av_clip_uint8(dest[5] + dc);
345 dest[6] = av_clip_uint8(dest[6] + dc);
346 dest[7] = av_clip_uint8(dest[7] + dc);
360 for (i = 0; i < 4; i++) {
361 t1 = 12 * (src[0] + src[4]) + 4;
362 t2 = 12 * (src[0] - src[4]) + 4;
363 t3 = 16 * src[2] + 6 * src[6];
364 t4 = 6 * src[2] - 16 * src[6];
371 t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
372 t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
373 t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
374 t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
376 dst[0] = (t5 +
t1) >> 3;
377 dst[1] = (t6 +
t2) >> 3;
378 dst[2] = (t7 +
t3) >> 3;
379 dst[3] = (t8 +
t4) >> 3;
380 dst[4] = (t8 -
t4) >> 3;
381 dst[5] = (t7 -
t3) >> 3;
382 dst[6] = (t6 -
t2) >> 3;
383 dst[7] = (t5 -
t1) >> 3;
390 for (i = 0; i < 8; i++) {
391 t1 = 17 * (src[ 0] + src[16]) + 64;
392 t2 = 17 * (src[ 0] - src[16]) + 64;
393 t3 = 22 * src[ 8] + 10 * src[24];
394 t4 = 22 * src[24] - 10 * src[ 8];
396 dest[0 * linesize] = av_clip_uint8(dest[0 * linesize] + ((t1 + t3) >> 7));
397 dest[1 * linesize] = av_clip_uint8(dest[1 * linesize] + ((t2 - t4) >> 7));
398 dest[2 * linesize] = av_clip_uint8(dest[2 * linesize] + ((t2 + t4) >> 7));
399 dest[3 * linesize] = av_clip_uint8(dest[3 * linesize] + ((t1 - t3) >> 7));
412 dc = (17 * dc + 4) >> 3;
413 dc = (12 * dc + 64) >> 7;
415 for (i = 0; i < 8; i++) {
416 dest[0] = av_clip_uint8(dest[0] + dc);
417 dest[1] = av_clip_uint8(dest[1] + dc);
418 dest[2] = av_clip_uint8(dest[2] + dc);
419 dest[3] = av_clip_uint8(dest[3] + dc);
433 for (i = 0; i < 8; i++) {
434 t1 = 17 * (src[0] + src[2]) + 4;
435 t2 = 17 * (src[0] - src[2]) + 4;
436 t3 = 22 * src[1] + 10 * src[3];
437 t4 = 22 * src[3] - 10 * src[1];
439 dst[0] = (t1 +
t3) >> 3;
440 dst[1] = (t2 -
t4) >> 3;
441 dst[2] = (t2 +
t4) >> 3;
442 dst[3] = (t1 -
t3) >> 3;
449 for (i = 0; i < 4; i++) {
450 t1 = 12 * (src[ 0] + src[32]) + 64;
451 t2 = 12 * (src[ 0] - src[32]) + 64;
452 t3 = 16 * src[16] + 6 * src[48];
453 t4 = 6 * src[16] - 16 * src[48];
460 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
461 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
462 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
463 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
465 dest[0 * linesize] = av_clip_uint8(dest[0 * linesize] + ((t5 + t1) >> 7));
466 dest[1 * linesize] = av_clip_uint8(dest[1 * linesize] + ((t6 + t2) >> 7));
467 dest[2 * linesize] = av_clip_uint8(dest[2 * linesize] + ((t7 + t3) >> 7));
468 dest[3 * linesize] = av_clip_uint8(dest[3 * linesize] + ((t8 + t4) >> 7));
469 dest[4 * linesize] = av_clip_uint8(dest[4 * linesize] + ((t8 - t4 + 1) >> 7));
470 dest[5 * linesize] = av_clip_uint8(dest[5 * linesize] + ((t7 - t3 + 1) >> 7));
471 dest[6 * linesize] = av_clip_uint8(dest[6 * linesize] + ((t6 - t2 + 1) >> 7));
472 dest[7 * linesize] = av_clip_uint8(dest[7 * linesize] + ((t5 - t1 + 1) >> 7));
485 dc = (17 * dc + 4) >> 3;
486 dc = (17 * dc + 64) >> 7;
488 for (i = 0; i < 4; i++) {
489 dest[0] = av_clip_uint8(dest[0] + dc);
490 dest[1] = av_clip_uint8(dest[1] + dc);
491 dest[2] = av_clip_uint8(dest[2] + dc);
492 dest[3] = av_clip_uint8(dest[3] + dc);
505 for (i = 0; i < 4; i++) {
506 t1 = 17 * (src[0] + src[2]) + 4;
507 t2 = 17 * (src[0] - src[2]) + 4;
508 t3 = 22 * src[1] + 10 * src[3];
509 t4 = 22 * src[3] - 10 * src[1];
511 dst[0] = (t1 +
t3) >> 3;
512 dst[1] = (t2 -
t4) >> 3;
513 dst[2] = (t2 +
t4) >> 3;
514 dst[3] = (t1 -
t3) >> 3;
521 for (i = 0; i < 4; i++) {
522 t1 = 17 * (src[0] + src[16]) + 64;
523 t2 = 17 * (src[0] - src[16]) + 64;
524 t3 = 22 * src[8] + 10 * src[24];
525 t4 = 22 * src[24] - 10 * src[8];
527 dest[0 * linesize] = av_clip_uint8(dest[0 * linesize] + ((t1 + t3) >> 7));
528 dest[1 * linesize] = av_clip_uint8(dest[1 * linesize] + ((t2 - t4) >> 7));
529 dest[2 * linesize] = av_clip_uint8(dest[2 * linesize] + ((t2 + t4) >> 7));
530 dest[3 * linesize] = av_clip_uint8(dest[3 * linesize] + ((t1 - t3) >> 7));
540 #define VC1_MSPEL_FILTER_16B(DIR, TYPE) \
541 static av_always_inline int vc1_mspel_ ## DIR ## _filter_16bits(const TYPE *src, \
549 return -4 * src[-stride] + 53 * src[0] + \
550 18 * src[stride] - 3 * src[stride * 2]; \
552 return -1 * src[-stride] + 9 * src[0] + \
553 9 * src[stride] - 1 * src[stride * 2]; \
555 return -3 * src[-stride] + 18 * src[0] + \
556 53 * src[stride] - 4 * src[stride * 2]; \
572 return (-4 * src[-stride] + 53 * src[0] +
573 18 * src[stride] - 3 * src[stride * 2] + 32 - r) >> 6;
575 return (-1 * src[-stride] + 9 * src[0] +
576 9 * src[stride] - 1 * src[stride * 2] + 8 - r) >> 4;
578 return (-3 * src[-stride] + 18 * src[0] +
579 53 * src[stride] - 4 * src[stride * 2] + 32 - r) >> 6;
585 #define VC1_MSPEL_MC(OP, OP4, OPNAME) \
586 static av_always_inline void OPNAME ## vc1_mspel_mc(uint8_t *dst, \
587 const uint8_t *src, \
599 static const int shift_value[] = { 0, 5, 1, 5 }; \
600 int shift = (shift_value[hmode] + shift_value[vmode]) >> 1; \
601 int16_t tmp[11 * 8], *tptr = tmp; \
603 r = (1 << (shift - 1)) + rnd - 1; \
606 for (j = 0; j < 8; j++) { \
607 for (i = 0; i < 11; i++) \
608 tptr[i] = (vc1_mspel_ver_filter_16bits(src + i, stride, vmode) + r) >> shift; \
615 for (j = 0; j < 8; j++) { \
616 for (i = 0; i < 8; i++) \
617 OP(dst[i], (vc1_mspel_hor_filter_16bits(tptr + i, 1, hmode) + r) >> 7); \
626 for (j = 0; j < 8; j++) { \
627 for (i = 0; i < 8; i++) \
628 OP(dst[i], vc1_mspel_filter(src + i, stride, vmode, r)); \
637 for (j = 0; j < 8; j++) { \
638 for (i = 0; i < 8; i++) \
639 OP(dst[i], vc1_mspel_filter(src + i, 1, hmode, rnd)); \
644 static void OPNAME ## pixels8x8_c(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int rnd){\
647 OP4(*(uint32_t*)(block ), AV_RN32(pixels ));\
648 OP4(*(uint32_t*)(block+4), AV_RN32(pixels+4));\
654 #define op_put(a, b) a = av_clip_uint8(b)
655 #define op_avg(a, b) a = (a + av_clip_uint8(b) + 1) >> 1
656 #define op4_avg(a, b) a = rnd_avg32(a, b)
657 #define op4_put(a, b) a = b
664 #define PUT_VC1_MSPEL(a, b) \
665 static void put_vc1_mspel_mc ## a ## b ## _c(uint8_t *dst, \
666 const uint8_t *src, \
667 ptrdiff_t stride, int rnd) \
669 put_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
671 static void avg_vc1_mspel_mc ## a ## b ## _c(uint8_t *dst, \
672 const uint8_t *src, \
673 ptrdiff_t stride, int rnd) \
675 avg_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
697 #define chroma_mc(a) \
698 ((A * src[a] + B * src[a + 1] + \
699 C * src[stride + a] + D * src[stride + a + 1] + 32 - 4) >> 6)
702 int stride,
int h,
int x,
int y)
704 const int A = (8 - x) * (8 - y);
705 const int B = (x) * (8 - y);
706 const int C = (8 - x) * (y);
707 const int D = (x) * (y);
710 av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
712 for (i = 0; i < h; i++) {
727 int stride,
int h,
int x,
int y)
729 const int A = (8 - x) * (8 - y);
730 const int B = (x) * (8 - y);
731 const int C = (8 - x) * (y);
732 const int D = (x) * (y);
735 av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
737 for (i = 0; i < h; i++) {
747 #define avg2(a, b) (((a) + (b) + 1) >> 1)
750 int stride,
int h,
int x,
int y)
752 const int A = (8 - x) * (8 - y);
753 const int B = (x) * (8 - y);
754 const int C = (8 - x) * (y);
755 const int D = (x) * (y);
758 av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
760 for (i = 0; i < h; i++) {
776 int stride,
int h,
int x,
int y)
778 const int A = (8 - x) * (8 - y);
779 const int B = ( x) * (8 - y);
780 const int C = (8 - x) * ( y);
781 const int D = ( x) * ( y);
784 av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
786 for (i = 0; i < h; i++) {
796 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
799 int advance,
int count)
802 int a = src[(offset >> 16)];
803 int b = src[(offset >> 16) + 1];
804 *dst++ = a + ((b -
a) * (offset & 0xFFFF) >> 16);
817 int alpha,
int scaled,
825 a1 = a1 + ((b1 -
a1) * offset1 >> 16);
831 a2 = a2 + ((b2 -
a2) * offset2 >> 16);
833 a1 = a1 + ((a2 -
a1) * alpha >> 16);
841 int offset,
int width)
843 sprite_v_template(dst, src1a, src1b, offset, 0, NULL, NULL, 0, 0, 1, width);
846 static void sprite_v_double_noscale_c(
uint8_t *dst,
const uint8_t *src1a,
848 int alpha,
int width)
850 sprite_v_template(dst, src1a, NULL, 0, 1, src2a, NULL, 0, alpha, 0, width);
853 static void sprite_v_double_onescale_c(
uint8_t *dst,
858 int alpha,
int width)
860 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, NULL, 0, alpha, 1,
864 static void sprite_v_double_twoscale_c(
uint8_t *dst,
874 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, src2b, offset2,
942 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER