39 for (j = 0; j < k; j++) {
40 for (i = 0; i < k; i++)
41 srcY[i] = ((srcY[i] - 128) >> 1) + 128;
47 int k,
int uvlinesize)
50 for (j = 0; j < k; j++) {
51 for (i = 0; i < k; i++) {
52 srcU[i] = ((srcU[i] - 128) >> 1) + 128;
53 srcV[i] = ((srcV[i] - 128) >> 1) + 128;
66 for (j = 0; j < k; j += 2) {
67 for (i = 0; i < k; i++)
68 srcY[i] = lut1[srcY[i]];
74 for (i = 0; i < k; i++)
75 srcY[i] = lut2[srcY[i]];
82 int k,
int uvlinesize)
86 for (j = 0; j < k; j += 2) {
87 for (i = 0; i < k; i++) {
88 srcU[i] = lut1[srcU[i]];
89 srcV[i] = lut1[srcV[i]];
97 for (i = 0; i < k; i++) {
98 srcU[i] = lut2[srcU[i]];
99 srcV[i] = lut2[srcV[i]];
114 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
117 uint8_t (*luty)[256], (*lutuv)[256];
125 mx = s->
mv[dir][0][0];
126 my = s->
mv[dir][0][1];
130 for (i = 0; i < 4; i++) {
136 uvmx = (mx + ((mx & 3) == 3)) >> 1;
137 uvmy = (my + ((my & 3) == 3)) >> 1;
149 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
150 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
177 if (!srcY || !srcU) {
182 src_x = s->
mb_x * 16 + (mx >> 2);
183 src_y = s->
mb_y * 16 + (my >> 2);
184 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
185 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
188 src_x = av_clip( src_x, -16, s->
mb_width * 16);
189 src_y = av_clip( src_y, -16, s->
mb_height * 16);
190 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
191 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
199 srcY += src_y * s->
linesize + src_x;
218 || (
unsigned)(src_y - 1) > v_edge_pos - (my&3) - 16 - 3) {
221 const int k = 17 + s->
mspel * 2;
262 dxy = ((my & 3) << 2) | (mx & 3);
265 dxy = (my & 2) | ((mx & 2) >> 1);
274 uvmx = (uvmx & 3) << 1;
275 uvmy = (uvmy & 3) << 1;
291 int dxy, mx, my, src_x, src_y;
303 mx = s->
mv[dir][
n][0];
304 my = s->
mv[dir][
n][1];
333 int same_count = 0, opp_count = 0, k;
334 int chosen_mv[2][4][2], f;
336 for (k = 0; k < 4; k++) {
338 chosen_mv[f][f ? opp_count : same_count][0] = s->
mv[0][k][0];
339 chosen_mv[f][f ? opp_count : same_count][1] = s->
mv[0][k][1];
343 f = opp_count > same_count;
344 switch (f ? opp_count : same_count) {
346 tx =
median4(chosen_mv[f][0][0], chosen_mv[f][1][0],
347 chosen_mv[f][2][0], chosen_mv[f][3][0]);
348 ty =
median4(chosen_mv[f][0][1], chosen_mv[f][1][1],
349 chosen_mv[f][2][1], chosen_mv[f][3][1]);
352 tx =
mid_pred(chosen_mv[f][0][0], chosen_mv[f][1][0], chosen_mv[f][2][0]);
353 ty =
mid_pred(chosen_mv[f][0][1], chosen_mv[f][1][1], chosen_mv[f][2][1]);
356 tx = (chosen_mv[f][0][0] + chosen_mv[f][1][0]) / 2;
357 ty = (chosen_mv[f][0][1] + chosen_mv[f][1][1]) / 2;
364 for (k = 0; k < 4; k++)
376 qx = (s->
mb_x * 16) + (mx >> 2);
377 qy = (s->
mb_y * 8) + (my >> 3);
382 mx -= 4 * (qx -
width);
385 else if (qy > height + 1)
386 my -= 8 * (qy - height - 1);
390 off = ((n > 1) ? s->
linesize : 0) + (n & 1) * 8;
392 off = s->
linesize * 4 * (n & 2) + (n & 1) * 8;
394 src_x = s->
mb_x * 16 + (n & 1) * 8 + (mx >> 2);
396 src_y = s->
mb_y * 16 + (n & 2) * 4 + (my >> 2);
398 src_y = s->
mb_y * 16 + ((n > 1) ? 1 : 0) + (my >> 2);
401 src_x = av_clip(src_x, -16, s->
mb_width * 16);
402 src_y = av_clip(src_y, -16, s->
mb_height * 16);
415 srcY += src_y * s->
linesize + src_x;
419 if (fieldmv && !(src_y & 1))
421 if (fieldmv && (src_y & 1) && src_y < 4)
426 || (
unsigned)(src_y - (s->
mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->
mspel * 2) << fieldmv)) {
427 const int k = 9 + s->
mspel * 2;
434 src_x - s->
mspel, src_y - (s->
mspel << fieldmv),
452 dxy = ((my & 3) << 2) | (mx & 3);
458 dxy = (my & 2) | ((mx & 2) >> 1);
469 static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
471 idx = ((a[3] != flag) << 3)
472 | ((a[2] != flag) << 2)
473 | ((a[1] != flag) << 1)
476 *tx =
median4(mvx[0], mvx[1], mvx[2], mvx[3]);
477 *ty =
median4(mvy[0], mvy[1], mvy[2], mvy[3]);
479 }
else if (count[idx] == 1) {
482 *tx =
mid_pred(mvx[1], mvx[2], mvx[3]);
483 *ty =
mid_pred(mvy[1], mvy[2], mvy[3]);
486 *tx =
mid_pred(mvx[0], mvx[2], mvx[3]);
487 *ty =
mid_pred(mvy[0], mvy[2], mvy[3]);
490 *tx =
mid_pred(mvx[0], mvx[1], mvx[3]);
491 *ty =
mid_pred(mvy[0], mvy[1], mvy[3]);
494 *tx =
mid_pred(mvx[0], mvx[1], mvx[2]);
495 *ty =
mid_pred(mvy[0], mvy[1], mvy[2]);
498 }
else if (count[idx] == 2) {
500 for (i = 0; i < 3; i++)
505 for (i = t1 + 1; i < 4; i++)
510 *tx = (mvx[
t1] + mvx[
t2]) / 2;
511 *ty = (mvy[
t1] + mvy[
t2]) / 2;
526 int uvmx, uvmy, uvsrc_x, uvsrc_y;
527 int k, tx = 0, ty = 0;
528 int mvx[4], mvy[4], intra[4], mv_f[4];
540 for (k = 0; k < 4; k++) {
541 mvx[k] = s->
mv[dir][k][0];
542 mvy[k] = s->
mv[dir][k][1];
560 if (mv_f[0] + mv_f[1] + mv_f[2] + mv_f[3] > 2)
562 valid_count =
get_chroma_mv(mvx, mvy, mv_f, dominant, &tx, &ty);
570 uvmx = (tx + ((tx & 3) == 3)) >> 1;
571 uvmy = (ty + ((ty & 3) == 3)) >> 1;
577 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
578 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
582 uvmy += 2 - 4 * chroma_ref_type;
584 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
585 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
588 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
589 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
623 if (chroma_ref_type) {
631 || (
unsigned)uvsrc_x > (s->
h_edge_pos >> 1) - 9
632 || (
unsigned)uvsrc_y > (v_edge_pos >> 1) - 9) {
635 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
639 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
651 lutuv[v->
field_mode ? chroma_ref_type : ((0 + uvsrc_y) & 1)],
652 lutuv[v->
field_mode ? chroma_ref_type : ((1 + uvsrc_y) & 1)],
658 uvmx = (uvmx & 3) << 1;
659 uvmy = (uvmy & 3) << 1;
676 int uvsrc_x, uvsrc_y;
677 int uvmx_field[4], uvmy_field[4];
680 static const int s_rndtblfield[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 };
681 int v_dist = fieldmv ? 1 : 4;
689 for (i = 0; i < 4; i++) {
690 int d = i < 2 ? dir: dir2;
692 uvmx_field[i] = (tx + ((tx & 3) == 3)) >> 1;
695 uvmy_field[i] = (ty >> 4) * 8 + s_rndtblfield[ty & 0xF];
697 uvmy_field[i] = (ty + ((ty & 3) == 3)) >> 1;
700 for (i = 0; i < 4; i++) {
701 off = (i & 1) * 4 + ((i & 2) ? v_dist * s->
uvlinesize : 0);
702 uvsrc_x = s->
mb_x * 8 + (i & 1) * 4 + (uvmx_field[i] >> 2);
703 uvsrc_y = s->
mb_y * 8 + ((i & 2) ? v_dist : 0) + (uvmy_field[i] >> 2);
707 if (i < 2 ? dir : dir2) {
722 uvmx_field[i] = (uvmx_field[i] & 3) << 1;
723 uvmy_field[i] = (uvmy_field[i] & 3) << 1;
725 if (fieldmv && !(uvsrc_y & 1))
728 if (fieldmv && (uvsrc_y & 1) && uvsrc_y < 2)
731 || s->
h_edge_pos < 10 || v_edge_pos < (5 << fieldmv)
732 || (unsigned)uvsrc_x > (s->
h_edge_pos >> 1) - 5
733 || (unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) {
736 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
740 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
748 lutuv[(uvsrc_y + (0 << fieldmv)) & 1],
749 lutuv[(uvsrc_y + (1 << fieldmv)) & 1],
780 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
790 uvmx = (mx + ((mx & 3) == 3)) >> 1;
791 uvmy = (my + ((my & 3) == 3)) >> 1;
797 uvmx = uvmx + ((uvmx < 0) ? -(uvmx & 1) : (uvmx & 1));
798 uvmy = uvmy + ((uvmy < 0) ? -(uvmy & 1) : (uvmy & 1));
804 src_x = s->
mb_x * 16 + (mx >> 2);
805 src_y = s->
mb_y * 16 + (my >> 2);
806 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
807 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
810 src_x = av_clip( src_x, -16, s->
mb_width * 16);
811 src_y = av_clip( src_y, -16, s->
mb_height * 16);
812 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
813 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
821 srcY += src_y * s->
linesize + src_x;
838 || (
unsigned)(src_x - 1) > s->
h_edge_pos - (mx & 3) - 16 - 3
839 || (
unsigned)(src_y - 1) > v_edge_pos - (my & 3) - 16 - 3) {
842 const int k = 17 + s->
mspel * 2;
888 dxy = ((my & 3) << 2) | (mx & 3);
891 dxy = (my & 2) | ((mx & 2) >> 1);
901 uvmx = (uvmx & 3) << 1;
902 uvmy = (uvmy & 3) << 1;