41 for(i = 0; i < 8; i++) {
46 d1 = (a - d + 3 + rnd) >> 3;
47 d2 = (a - d + b - c + 4 - rnd) >> 3;
50 src[-
stride] = av_clip_uint8(b - d2);
51 src[0] = av_clip_uint8(c + d2);
66 for(i = 0; i < 8; i++) {
71 d1 = (a - d + 3 + rnd) >> 3;
72 d2 = (a - d + b - c + 4 - rnd) >> 3;
75 src[-1] = av_clip_uint8(b - d2);
76 src[0] = av_clip_uint8(c + d2);
88 int rnd1 = 4, rnd2 = 3;
89 for(i = 0; i < 8; i++) {
97 top[48] = ((a << 3) - d1 + rnd1) >> 3;
98 top[56] = ((b << 3) - d2 + rnd2) >> 3;
99 bottom[0] = ((c << 3) + d2 + rnd1) >> 3;
100 bottom[8] = ((d << 3) + d1 + rnd2) >> 3;
114 int rnd1 = 4, rnd2 = 3;
115 for(i = 0; i < 8; i++) {
123 left[6] = ((a << 3) - d1 + rnd1) >> 3;
124 left[7] = ((b << 3) - d2 + rnd2) >> 3;
125 right[0] = ((c << 3) + d2 + rnd1) >> 3;
126 right[1] = ((d << 3) + d1 + rnd2) >> 3;
144 int a0 = (2*(src[-2*
stride] - src[ 1*
stride]) - 5*(src[-1*stride] - src[ 0*stride]) + 4) >> 3;
145 int a0_sign = a0 >> 31;
146 a0 = (a0 ^ a0_sign) - a0_sign;
148 int a1 =
FFABS((2*(src[-4*stride] - src[-1*stride]) - 5*(src[-3*stride] - src[-2*stride]) + 4) >> 3);
149 int a2 =
FFABS((2*(src[ 0*stride] - src[ 3*stride]) - 5*(src[ 1*stride] - src[ 2*stride]) + 4) >> 3);
150 if(a1 < a0 || a2 < a0){
152 int clip_sign = clip >> 31;
153 clip = ((clip ^ clip_sign) - clip_sign)>>1;
156 int d = 5 * (a3 -
a0);
157 int d_sign = (d >> 31);
158 d = ((d ^ d_sign) - d_sign) >> 3;
161 if( d_sign ^ clip_sign )
165 d = (d ^ d_sign) - d_sign;
166 src[-1*
stride] = av_clip_uint8(src[-1*stride] - d);
167 src[ 0*
stride] = av_clip_uint8(src[ 0*stride] + d);
190 for(i = 0; i <
len; i += 4){
237 dc = (3 * dc + 1) >> 1;
238 dc = (3 * dc + 16) >> 5;
239 for(i = 0; i < 8; i++){
240 dest[0] = av_clip_uint8(dest[0] + dc);
241 dest[1] = av_clip_uint8(dest[1] + dc);
242 dest[2] = av_clip_uint8(dest[2] + dc);
243 dest[3] = av_clip_uint8(dest[3] + dc);
244 dest[4] = av_clip_uint8(dest[4] + dc);
245 dest[5] = av_clip_uint8(dest[5] + dc);
246 dest[6] = av_clip_uint8(dest[6] + dc);
247 dest[7] = av_clip_uint8(dest[7] + dc);
260 for(i = 0; i < 8; i++){
261 t1 = 12 * (src[ 0] + src[32]) + 4;
262 t2 = 12 * (src[ 0] - src[32]) + 4;
263 t3 = 16 * src[16] + 6 * src[48];
264 t4 = 6 * src[16] - 16 * src[48];
271 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
272 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
273 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
274 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
276 dst[0] = (t5 +
t1) >> 3;
277 dst[1] = (t6 +
t2) >> 3;
278 dst[2] = (t7 +
t3) >> 3;
279 dst[3] = (t8 +
t4) >> 3;
280 dst[4] = (t8 -
t4) >> 3;
281 dst[5] = (t7 -
t3) >> 3;
282 dst[6] = (t6 -
t2) >> 3;
283 dst[7] = (t5 -
t1) >> 3;
291 for(i = 0; i < 8; i++){
292 t1 = 12 * (src[ 0] + src[32]) + 64;
293 t2 = 12 * (src[ 0] - src[32]) + 64;
294 t3 = 16 * src[16] + 6 * src[48];
295 t4 = 6 * src[16] - 16 * src[48];
302 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
303 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
304 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
305 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
307 dst[ 0] = (t5 +
t1) >> 7;
308 dst[ 8] = (t6 +
t2) >> 7;
309 dst[16] = (t7 +
t3) >> 7;
310 dst[24] = (t8 +
t4) >> 7;
311 dst[32] = (t8 - t4 + 1) >> 7;
312 dst[40] = (t7 - t3 + 1) >> 7;
313 dst[48] = (t6 - t2 + 1) >> 7;
314 dst[56] = (t5 - t1 + 1) >> 7;
327 dc = ( 3 * dc + 1) >> 1;
328 dc = (17 * dc + 64) >> 7;
329 for(i = 0; i < 4; i++){
330 dest[0] = av_clip_uint8(dest[0] + dc);
331 dest[1] = av_clip_uint8(dest[1] + dc);
332 dest[2] = av_clip_uint8(dest[2] + dc);
333 dest[3] = av_clip_uint8(dest[3] + dc);
334 dest[4] = av_clip_uint8(dest[4] + dc);
335 dest[5] = av_clip_uint8(dest[5] + dc);
336 dest[6] = av_clip_uint8(dest[6] + dc);
337 dest[7] = av_clip_uint8(dest[7] + dc);
350 for(i = 0; i < 4; i++){
351 t1 = 12 * (src[0] + src[4]) + 4;
352 t2 = 12 * (src[0] - src[4]) + 4;
353 t3 = 16 * src[2] + 6 * src[6];
354 t4 = 6 * src[2] - 16 * src[6];
361 t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
362 t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
363 t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
364 t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
366 dst[0] = (t5 +
t1) >> 3;
367 dst[1] = (t6 +
t2) >> 3;
368 dst[2] = (t7 +
t3) >> 3;
369 dst[3] = (t8 +
t4) >> 3;
370 dst[4] = (t8 -
t4) >> 3;
371 dst[5] = (t7 -
t3) >> 3;
372 dst[6] = (t6 -
t2) >> 3;
373 dst[7] = (t5 -
t1) >> 3;
380 for(i = 0; i < 8; i++){
381 t1 = 17 * (src[ 0] + src[16]) + 64;
382 t2 = 17 * (src[ 0] - src[16]) + 64;
383 t3 = 22 * src[ 8] + 10 * src[24];
384 t4 = 22 * src[24] - 10 * src[ 8];
386 dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t1 + t3) >> 7));
387 dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t2 - t4) >> 7));
388 dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t2 + t4) >> 7));
389 dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t1 - t3) >> 7));
402 dc = (17 * dc + 4) >> 3;
403 dc = (12 * dc + 64) >> 7;
404 for(i = 0; i < 8; i++){
405 dest[0] = av_clip_uint8(dest[0] + dc);
406 dest[1] = av_clip_uint8(dest[1] + dc);
407 dest[2] = av_clip_uint8(dest[2] + dc);
408 dest[3] = av_clip_uint8(dest[3] + dc);
421 for(i = 0; i < 8; i++){
422 t1 = 17 * (src[0] + src[2]) + 4;
423 t2 = 17 * (src[0] - src[2]) + 4;
424 t3 = 22 * src[1] + 10 * src[3];
425 t4 = 22 * src[3] - 10 * src[1];
427 dst[0] = (t1 +
t3) >> 3;
428 dst[1] = (t2 -
t4) >> 3;
429 dst[2] = (t2 +
t4) >> 3;
430 dst[3] = (t1 -
t3) >> 3;
437 for(i = 0; i < 4; i++){
438 t1 = 12 * (src[ 0] + src[32]) + 64;
439 t2 = 12 * (src[ 0] - src[32]) + 64;
440 t3 = 16 * src[16] + 6 * src[48];
441 t4 = 6 * src[16] - 16 * src[48];
448 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
449 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
450 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
451 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
453 dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t5 + t1) >> 7));
454 dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t6 + t2) >> 7));
455 dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t7 + t3) >> 7));
456 dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t8 + t4) >> 7));
457 dest[4*linesize] = av_clip_uint8(dest[4*linesize] + ((t8 - t4 + 1) >> 7));
458 dest[5*linesize] = av_clip_uint8(dest[5*linesize] + ((t7 - t3 + 1) >> 7));
459 dest[6*linesize] = av_clip_uint8(dest[6*linesize] + ((t6 - t2 + 1) >> 7));
460 dest[7*linesize] = av_clip_uint8(dest[7*linesize] + ((t5 - t1 + 1) >> 7));
473 dc = (17 * dc + 4) >> 3;
474 dc = (17 * dc + 64) >> 7;
475 for(i = 0; i < 4; i++){
476 dest[0] = av_clip_uint8(dest[0] + dc);
477 dest[1] = av_clip_uint8(dest[1] + dc);
478 dest[2] = av_clip_uint8(dest[2] + dc);
479 dest[3] = av_clip_uint8(dest[3] + dc);
492 for(i = 0; i < 4; i++){
493 t1 = 17 * (src[0] + src[2]) + 4;
494 t2 = 17 * (src[0] - src[2]) + 4;
495 t3 = 22 * src[1] + 10 * src[3];
496 t4 = 22 * src[3] - 10 * src[1];
498 dst[0] = (t1 +
t3) >> 3;
499 dst[1] = (t2 -
t4) >> 3;
500 dst[2] = (t2 +
t4) >> 3;
501 dst[3] = (t1 -
t3) >> 3;
508 for(i = 0; i < 4; i++){
509 t1 = 17 * (src[ 0] + src[16]) + 64;
510 t2 = 17 * (src[ 0] - src[16]) + 64;
511 t3 = 22 * src[ 8] + 10 * src[24];
512 t4 = 22 * src[24] - 10 * src[ 8];
514 dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t1 + t3) >> 7));
515 dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t2 - t4) >> 7));
516 dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t2 + t4) >> 7));
517 dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t1 - t3) >> 7));
526 #define VC1_MSPEL_FILTER_16B(DIR, TYPE) \
527 static av_always_inline int vc1_mspel_ ## DIR ## _filter_16bits(const TYPE *src, int stride, int mode) \
533 return -4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2]; \
535 return -src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2]; \
537 return -3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2]; \
554 return (-4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2] + 32 - r) >> 6;
556 return (-src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2] + 8 - r) >> 4;
558 return (-3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2] + 32 - r) >> 6;
565 #define VC1_MSPEL_MC(OP, OP4, OPNAME)\
566 static av_always_inline void OPNAME ## vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, int hmode, int vmode, int rnd)\
574 static const int shift_value[] = { 0, 5, 1, 5 };\
575 int shift = (shift_value[hmode]+shift_value[vmode])>>1;\
576 int16_t tmp[11*8], *tptr = tmp;\
578 r = (1<<(shift-1)) + rnd-1;\
581 for(j = 0; j < 8; j++) {\
582 for(i = 0; i < 11; i++)\
583 tptr[i] = (vc1_mspel_ver_filter_16bits(src + i, stride, vmode)+r)>>shift;\
590 for(j = 0; j < 8; j++) {\
591 for(i = 0; i < 8; i++)\
592 OP(dst[i], (vc1_mspel_hor_filter_16bits(tptr + i, 1, hmode)+r)>>7);\
602 for(j = 0; j < 8; j++) {\
603 for(i = 0; i < 8; i++)\
604 OP(dst[i], vc1_mspel_filter(src + i, stride, vmode, r));\
613 for(j = 0; j < 8; j++) {\
614 for(i = 0; i < 8; i++)\
615 OP(dst[i], vc1_mspel_filter(src + i, 1, hmode, rnd));\
620 static void OPNAME ## pixels8x8_c(uint8_t *block, const uint8_t *pixels, int line_size, int rnd){\
623 OP4(*(uint32_t*)(block ), AV_RN32(pixels ));\
624 OP4(*(uint32_t*)(block+4), AV_RN32(pixels+4));\
630 #define op_put(a, b) a = av_clip_uint8(b)
631 #define op_avg(a, b) a = (a + av_clip_uint8(b) + 1) >> 1
632 #define op4_avg(a, b) a = rnd_avg32(a, b)
633 #define op4_put(a, b) a = b
640 #define PUT_VC1_MSPEL(a, b)\
641 static void put_vc1_mspel_mc ## a ## b ##_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \
642 put_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
644 static void avg_vc1_mspel_mc ## a ## b ##_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \
645 avg_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
668 const int A=(8-x)*(8-y);
669 const int B=( x)*(8-y);
670 const int C=(8-x)*( y);
671 const int D=( x)*( y);
678 dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
679 dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
680 dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
681 dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
682 dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6;
683 dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6;
684 dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6;
685 dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6;
692 const int A=(8-x)*(8-y);
693 const int B=( x)*(8-y);
694 const int C=(8-x)*( y);
695 const int D=( x)*( y);
702 dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
703 dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
704 dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
705 dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
711 #define avg2(a,b) ((a+b+1)>>1)
713 const int A=(8-x)*(8-y);
714 const int B=( x)*(8-y);
715 const int C=(8-x)*( y);
716 const int D=( x)*( y);
723 dst[0] =
avg2(dst[0], ((A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6));
724 dst[1] =
avg2(dst[1], ((A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6));
725 dst[2] =
avg2(dst[2], ((A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6));
726 dst[3] =
avg2(dst[3], ((A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6));
727 dst[4] =
avg2(dst[4], ((A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6));
728 dst[5] =
avg2(dst[5], ((A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6));
729 dst[6] =
avg2(dst[6], ((A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6));
730 dst[7] =
avg2(dst[7], ((A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6));
736 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
741 int a = src[(offset >> 16) ];
742 int b = src[(offset >> 16) + 1];
743 *dst++ = a + ((b -
a) * (offset&0xFFFF) >> 16);
749 int two_sprites,
const uint8_t *src2a,
const uint8_t *src2b,
int offset2,
750 int alpha,
int scaled,
int width)
757 a1 = a1 + ((b1 -
a1) * offset1 >> 16);
763 a2 = a2 + ((b2 -
a2) * offset2 >> 16);
765 a1 = a1 + ((a2 -
a1) * alpha >> 16);
771 static void sprite_v_single_c(
uint8_t *dst,
const uint8_t *src1a,
const uint8_t *src1b,
int offset,
int width)
773 sprite_v_template(dst, src1a, src1b, offset, 0,
NULL,
NULL, 0, 0, 1, width);
776 static void sprite_v_double_noscale_c(
uint8_t *dst,
const uint8_t *src1a,
const uint8_t *src2a,
int alpha,
int width)
778 sprite_v_template(dst, src1a,
NULL, 0, 1, src2a,
NULL, 0, alpha, 0, width);
781 static void sprite_v_double_onescale_c(
uint8_t *dst,
const uint8_t *src1a,
const uint8_t *src1b,
int offset1,
782 const uint8_t *src2a,
int alpha,
int width)
784 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a,
NULL, 0, alpha, 1, width);
787 static void sprite_v_double_twoscale_c(
uint8_t *dst,
const uint8_t *src1a,
const uint8_t *src1b,
int offset1,
789 int alpha,
int width)
791 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, src2b, offset2, alpha, 2, width);
854 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER