43 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
46 uint8_t (*luty)[256], (*lutuv)[256];
54 mx = s->
mv[dir][0][0];
55 my = s->
mv[dir][0][1];
59 for (i = 0; i < 4; i++) {
65 uvmx = (mx + ((mx & 3) == 3)) >> 1;
66 uvmy = (my + ((my & 3) == 3)) >> 1;
78 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
79 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
106 if (!srcY || !srcU) {
111 src_x = s->
mb_x * 16 + (mx >> 2);
112 src_y = s->
mb_y * 16 + (my >> 2);
113 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
114 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
117 src_x = av_clip( src_x, -16, s->
mb_width * 16);
118 src_y = av_clip( src_y, -16, s->
mb_height * 16);
119 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
120 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
128 srcY += src_y * s->
linesize + src_x;
147 || (
unsigned)(src_y - 1) > v_edge_pos - (my&3) - 16 - 3) {
176 for (j = 0; j < 17 + s->
mspel * 2; j++) {
177 for (i = 0; i < 17 + s->
mspel * 2; i++)
178 src[i] = ((src[i] - 128) >> 1) + 128;
183 for (j = 0; j < 9; j++) {
184 for (i = 0; i < 9; i++) {
185 src[i] = ((src[i] - 128) >> 1) + 128;
186 src2[i] = ((src2[i] - 128) >> 1) + 128;
198 for (j = 0; j < 17 + s->
mspel * 2; j++) {
200 for (i = 0; i < 17 + s->
mspel * 2; i++)
201 src[i] = luty[f][src[i]];
206 for (j = 0; j < 9; j++) {
208 for (i = 0; i < 9; i++) {
209 src[i] = lutuv[f][src[i]];
210 src2[i] = lutuv[f][src2[i]];
220 dxy = ((my & 3) << 2) | (mx & 3);
223 dxy = (my & 2) | ((mx & 2) >> 1);
232 uvmx = (uvmx & 3) << 1;
233 uvmy = (uvmy & 3) << 1;
246 if (c < d)
return (
FFMIN(b, d) +
FFMAX(a, c)) / 2;
249 if (c < d)
return (
FFMIN(a, d) +
FFMAX(b, c)) / 2;
260 int dxy, mx, my, src_x, src_y;
272 mx = s->
mv[dir][
n][0];
273 my = s->
mv[dir][
n][1];
302 int same_count = 0, opp_count = 0, k;
303 int chosen_mv[2][4][2], f;
305 for (k = 0; k < 4; k++) {
307 chosen_mv[f][f ? opp_count : same_count][0] = s->
mv[0][k][0];
308 chosen_mv[f][f ? opp_count : same_count][1] = s->
mv[0][k][1];
312 f = opp_count > same_count;
313 switch (f ? opp_count : same_count) {
315 tx =
median4(chosen_mv[f][0][0], chosen_mv[f][1][0],
316 chosen_mv[f][2][0], chosen_mv[f][3][0]);
317 ty =
median4(chosen_mv[f][0][1], chosen_mv[f][1][1],
318 chosen_mv[f][2][1], chosen_mv[f][3][1]);
321 tx =
mid_pred(chosen_mv[f][0][0], chosen_mv[f][1][0], chosen_mv[f][2][0]);
322 ty =
mid_pred(chosen_mv[f][0][1], chosen_mv[f][1][1], chosen_mv[f][2][1]);
325 tx = (chosen_mv[f][0][0] + chosen_mv[f][1][0]) / 2;
326 ty = (chosen_mv[f][0][1] + chosen_mv[f][1][1]) / 2;
333 for (k = 0; k < 4; k++)
345 qx = (s->
mb_x * 16) + (mx >> 2);
346 qy = (s->
mb_y * 8) + (my >> 3);
351 mx -= 4 * (qx -
width);
354 else if (qy > height + 1)
355 my -= 8 * (qy - height - 1);
359 off = ((n > 1) ? s->
linesize : 0) + (n & 1) * 8;
361 off = s->
linesize * 4 * (n & 2) + (n & 1) * 8;
363 src_x = s->
mb_x * 16 + (n & 1) * 8 + (mx >> 2);
365 src_y = s->
mb_y * 16 + (n & 2) * 4 + (my >> 2);
367 src_y = s->
mb_y * 16 + ((n > 1) ? 1 : 0) + (my >> 2);
370 src_x = av_clip(src_x, -16, s->
mb_width * 16);
371 src_y = av_clip(src_y, -16, s->
mb_height * 16);
384 srcY += src_y * s->
linesize + src_x;
388 if (fieldmv && !(src_y & 1))
390 if (fieldmv && (src_y & 1) && src_y < 4)
395 || (
unsigned)(src_y - (s->
mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->
mspel * 2) << fieldmv)) {
400 9 + s->
mspel * 2, (9 + s->
mspel * 2) << fieldmv,
401 src_x - s->
mspel, src_y - (s->
mspel << fieldmv),
410 for (j = 0; j < 9 + s->
mspel * 2; j++) {
411 for (i = 0; i < 9 + s->
mspel * 2; i++)
412 src[i] = ((src[i] - 128) >> 1) + 128;
422 for (j = 0; j < 9 + s->
mspel * 2; j++) {
424 for (i = 0; i < 9 + s->
mspel * 2; i++)
425 src[i] = luty[f][src[i]];
433 dxy = ((my & 3) << 2) | (mx & 3);
439 dxy = (my & 2) | ((mx & 2) >> 1);
450 static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
452 idx = ((a[3] != flag) << 3)
453 | ((a[2] != flag) << 2)
454 | ((a[1] != flag) << 1)
457 *tx =
median4(mvx[0], mvx[1], mvx[2], mvx[3]);
458 *ty =
median4(mvy[0], mvy[1], mvy[2], mvy[3]);
460 }
else if (count[idx] == 1) {
463 *tx =
mid_pred(mvx[1], mvx[2], mvx[3]);
464 *ty =
mid_pred(mvy[1], mvy[2], mvy[3]);
467 *tx =
mid_pred(mvx[0], mvx[2], mvx[3]);
468 *ty =
mid_pred(mvy[0], mvy[2], mvy[3]);
471 *tx =
mid_pred(mvx[0], mvx[1], mvx[3]);
472 *ty =
mid_pred(mvy[0], mvy[1], mvy[3]);
475 *tx =
mid_pred(mvx[0], mvx[1], mvx[2]);
476 *ty =
mid_pred(mvy[0], mvy[1], mvy[2]);
479 }
else if (count[idx] == 2) {
481 for (i = 0; i < 3; i++)
486 for (i = t1 + 1; i < 4; i++)
491 *tx = (mvx[
t1] + mvx[
t2]) / 2;
492 *ty = (mvy[
t1] + mvy[
t2]) / 2;
507 int uvmx, uvmy, uvsrc_x, uvsrc_y;
508 int k, tx = 0, ty = 0;
509 int mvx[4], mvy[4], intra[4], mv_f[4];
521 for (k = 0; k < 4; k++) {
522 mvx[k] = s->
mv[dir][k][0];
523 mvy[k] = s->
mv[dir][k][1];
541 if (mv_f[0] + mv_f[1] + mv_f[2] + mv_f[3] > 2)
543 valid_count =
get_chroma_mv(mvx, mvy, mv_f, dominant, &tx, &ty);
551 uvmx = (tx + ((tx & 3) == 3)) >> 1;
552 uvmy = (ty + ((ty & 3) == 3)) >> 1;
558 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
559 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
563 uvmy += 2 - 4 * chroma_ref_type;
565 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
566 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
569 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
570 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
604 if (chroma_ref_type) {
612 || (
unsigned)uvsrc_x > (s->
h_edge_pos >> 1) - 9
613 || (
unsigned)uvsrc_y > (v_edge_pos >> 1) - 9) {
616 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
620 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
632 for (j = 0; j < 9; j++) {
633 for (i = 0; i < 9; i++) {
634 src[i] = ((src[i] - 128) >> 1) + 128;
635 src2[i] = ((src2[i] - 128) >> 1) + 128;
648 for (j = 0; j < 9; j++) {
649 int f = v->
field_mode ? chroma_ref_type : ((j + uvsrc_y) & 1);
650 for (i = 0; i < 9; i++) {
651 src[i] = lutuv[f][src[i]];
652 src2[i] = lutuv[f][src2[i]];
661 uvmx = (uvmx & 3) << 1;
662 uvmy = (uvmy & 3) << 1;
679 int uvsrc_x, uvsrc_y;
680 int uvmx_field[4], uvmy_field[4];
683 static const int s_rndtblfield[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 };
684 int v_dist = fieldmv ? 1 : 4;
692 for (i = 0; i < 4; i++) {
693 int d = i < 2 ? dir: dir2;
695 uvmx_field[i] = (tx + ((tx & 3) == 3)) >> 1;
698 uvmy_field[i] = (ty >> 4) * 8 + s_rndtblfield[ty & 0xF];
700 uvmy_field[i] = (ty + ((ty & 3) == 3)) >> 1;
703 for (i = 0; i < 4; i++) {
704 off = (i & 1) * 4 + ((i & 2) ? v_dist * s->
uvlinesize : 0);
705 uvsrc_x = s->
mb_x * 8 + (i & 1) * 4 + (uvmx_field[i] >> 2);
706 uvsrc_y = s->
mb_y * 8 + ((i & 2) ? v_dist : 0) + (uvmy_field[i] >> 2);
710 if (i < 2 ? dir : dir2) {
725 uvmx_field[i] = (uvmx_field[i] & 3) << 1;
726 uvmy_field[i] = (uvmy_field[i] & 3) << 1;
728 if (fieldmv && !(uvsrc_y & 1))
731 if (fieldmv && (uvsrc_y & 1) && uvsrc_y < 2)
734 || s->
h_edge_pos < 10 || v_edge_pos < (5 << fieldmv)
735 || (unsigned)uvsrc_x > (s->
h_edge_pos >> 1) - 5
736 || (unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) {
739 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
743 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
755 for (j = 0; j < 5; j++) {
756 int f = (uvsrc_y + (j << fieldmv)) & 1;
757 for (i = 0; i < 5; i++) {
758 src[i] = lutuv[f][src[i]];
759 src2[i] = lutuv[f][src2[i]];
793 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
803 uvmx = (mx + ((mx & 3) == 3)) >> 1;
804 uvmy = (my + ((my & 3) == 3)) >> 1;
810 uvmx = uvmx + ((uvmx < 0) ? -(uvmx & 1) : (uvmx & 1));
811 uvmy = uvmy + ((uvmy < 0) ? -(uvmy & 1) : (uvmy & 1));
817 src_x = s->
mb_x * 16 + (mx >> 2);
818 src_y = s->
mb_y * 16 + (my >> 2);
819 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
820 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
823 src_x = av_clip( src_x, -16, s->
mb_width * 16);
824 src_y = av_clip( src_y, -16, s->
mb_height * 16);
825 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
826 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
834 srcY += src_y * s->
linesize + src_x;
851 || (
unsigned)(src_x - 1) > s->
h_edge_pos - (mx & 3) - 16 - 3
852 || (
unsigned)(src_y - 1) > v_edge_pos - (my & 3) - 16 - 3) {
881 for (j = 0; j < 17 + s->
mspel * 2; j++) {
882 for (i = 0; i < 17 + s->
mspel * 2; i++)
883 src[i] = ((src[i] - 128) >> 1) + 128;
888 for (j = 0; j < 9; j++) {
889 for (i = 0; i < 9; i++) {
890 src[i] = ((src[i] - 128) >> 1) + 128;
891 src2[i] = ((src2[i] - 128) >> 1) + 128;
905 for (j = 0; j < 17 + s->
mspel * 2; j++) {
907 for (i = 0; i < 17 + s->
mspel * 2; i++)
908 src[i] = luty[f][src[i]];
913 for (j = 0; j < 9; j++) {
915 for (i = 0; i < 9; i++) {
916 src[i] = lutuv[f][src[i]];
917 src2[i] = lutuv[f][src2[i]];
930 dxy = ((my & 3) << 2) | (mx & 3);
933 dxy = (my & 2) | ((mx & 2) >> 1);
943 uvmx = (uvmx & 3) << 1;
944 uvmy = (uvmy & 3) << 1;