50 #define MB_INTRA_VLC_BITS 9
56 static const int offset_table2[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
82 int topleft_mb_pos, top_mb_pos;
83 int stride_y, fieldtx = 0;
99 v_dist = (16 - fieldtx) >> (fieldtx == 0);
124 v_dist = fieldtx ? 15 : 8;
146 #define inc_blk_idx(idx) do { \
148 if (idx >= v->n_allocated_blks) \
167 for (j = 0; j < 2; j++) {
200 for (j = 0; j < 2; j++) {
217 for (j = 0; j < 2; j++) {
233 for (j = 0; j < 2; j++) {
244 for (j = 0; j < 2; j++) {
338 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
341 uint8_t (*luty)[256], (*lutuv)[256];
349 mx = s->
mv[dir][0][0];
350 my = s->
mv[dir][0][1];
354 for (i = 0; i < 4; i++) {
360 uvmx = (mx + ((mx & 3) == 3)) >> 1;
361 uvmy = (my + ((my & 3) == 3)) >> 1;
373 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
374 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
401 if (!srcY || !srcU) {
406 src_x = s->
mb_x * 16 + (mx >> 2);
407 src_y = s->
mb_y * 16 + (my >> 2);
408 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
409 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
412 src_x = av_clip( src_x, -16, s->
mb_width * 16);
413 src_y = av_clip( src_y, -16, s->
mb_height * 16);
414 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
415 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
423 srcY += src_y * s->
linesize + src_x;
442 || (
unsigned)(src_y - 1) > v_edge_pos - (my&3) - 16 - 3) {
471 for (j = 0; j < 17 + s->
mspel * 2; j++) {
472 for (i = 0; i < 17 + s->
mspel * 2; i++)
473 src[i] = ((src[i] - 128) >> 1) + 128;
478 for (j = 0; j < 9; j++) {
479 for (i = 0; i < 9; i++) {
480 src[i] = ((src[i] - 128) >> 1) + 128;
481 src2[i] = ((src2[i] - 128) >> 1) + 128;
493 for (j = 0; j < 17 + s->
mspel * 2; j++) {
495 for (i = 0; i < 17 + s->
mspel * 2; i++)
496 src[i] = luty[f][src[i]];
501 for (j = 0; j < 9; j++) {
503 for (i = 0; i < 9; i++) {
504 src[i] = lutuv[f][src[i]];
505 src2[i] = lutuv[f][src2[i]];
515 dxy = ((my & 3) << 2) | (mx & 3);
518 dxy = (my & 2) | ((mx & 2) >> 1);
527 uvmx = (uvmx & 3) << 1;
528 uvmy = (uvmy & 3) << 1;
541 if (c < d)
return (
FFMIN(b, d) +
FFMAX(a, c)) / 2;
544 if (c < d)
return (
FFMIN(a, d) +
FFMAX(b, c)) / 2;
555 int dxy, mx, my, src_x, src_y;
567 mx = s->
mv[dir][
n][0];
568 my = s->
mv[dir][
n][1];
597 int same_count = 0, opp_count = 0, k;
598 int chosen_mv[2][4][2], f;
600 for (k = 0; k < 4; k++) {
602 chosen_mv[f][f ? opp_count : same_count][0] = s->
mv[0][k][0];
603 chosen_mv[f][f ? opp_count : same_count][1] = s->
mv[0][k][1];
607 f = opp_count > same_count;
608 switch (f ? opp_count : same_count) {
610 tx =
median4(chosen_mv[f][0][0], chosen_mv[f][1][0],
611 chosen_mv[f][2][0], chosen_mv[f][3][0]);
612 ty =
median4(chosen_mv[f][0][1], chosen_mv[f][1][1],
613 chosen_mv[f][2][1], chosen_mv[f][3][1]);
616 tx =
mid_pred(chosen_mv[f][0][0], chosen_mv[f][1][0], chosen_mv[f][2][0]);
617 ty =
mid_pred(chosen_mv[f][0][1], chosen_mv[f][1][1], chosen_mv[f][2][1]);
620 tx = (chosen_mv[f][0][0] + chosen_mv[f][1][0]) / 2;
621 ty = (chosen_mv[f][0][1] + chosen_mv[f][1][1]) / 2;
628 for (k = 0; k < 4; k++)
640 qx = (s->
mb_x * 16) + (mx >> 2);
641 qy = (s->
mb_y * 8) + (my >> 3);
646 mx -= 4 * (qx -
width);
649 else if (qy > height + 1)
650 my -= 8 * (qy - height - 1);
654 off = ((n > 1) ? s->
linesize : 0) + (n & 1) * 8;
656 off = s->
linesize * 4 * (n & 2) + (n & 1) * 8;
658 src_x = s->
mb_x * 16 + (n & 1) * 8 + (mx >> 2);
660 src_y = s->
mb_y * 16 + (n & 2) * 4 + (my >> 2);
662 src_y = s->
mb_y * 16 + ((n > 1) ? 1 : 0) + (my >> 2);
665 src_x = av_clip(src_x, -16, s->
mb_width * 16);
666 src_y = av_clip(src_y, -16, s->
mb_height * 16);
679 srcY += src_y * s->
linesize + src_x;
683 if (fieldmv && !(src_y & 1))
685 if (fieldmv && (src_y & 1) && src_y < 4)
690 || (
unsigned)(src_y - (s->
mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->
mspel * 2) << fieldmv)) {
695 9 + s->
mspel * 2, (9 + s->
mspel * 2) << fieldmv,
696 src_x - s->
mspel, src_y - (s->
mspel << fieldmv),
705 for (j = 0; j < 9 + s->
mspel * 2; j++) {
706 for (i = 0; i < 9 + s->
mspel * 2; i++)
707 src[i] = ((src[i] - 128) >> 1) + 128;
717 for (j = 0; j < 9 + s->
mspel * 2; j++) {
719 for (i = 0; i < 9 + s->
mspel * 2; i++)
720 src[i] = luty[f][src[i]];
728 dxy = ((my & 3) << 2) | (mx & 3);
734 dxy = (my & 2) | ((mx & 2) >> 1);
745 static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
747 idx = ((a[3] != flag) << 3)
748 | ((a[2] != flag) << 2)
749 | ((a[1] != flag) << 1)
752 *tx =
median4(mvx[0], mvx[1], mvx[2], mvx[3]);
753 *ty =
median4(mvy[0], mvy[1], mvy[2], mvy[3]);
755 }
else if (count[idx] == 1) {
758 *tx =
mid_pred(mvx[1], mvx[2], mvx[3]);
759 *ty =
mid_pred(mvy[1], mvy[2], mvy[3]);
762 *tx =
mid_pred(mvx[0], mvx[2], mvx[3]);
763 *ty =
mid_pred(mvy[0], mvy[2], mvy[3]);
766 *tx =
mid_pred(mvx[0], mvx[1], mvx[3]);
767 *ty =
mid_pred(mvy[0], mvy[1], mvy[3]);
770 *tx =
mid_pred(mvx[0], mvx[1], mvx[2]);
771 *ty =
mid_pred(mvy[0], mvy[1], mvy[2]);
774 }
else if (count[idx] == 2) {
776 for (i = 0; i < 3; i++)
781 for (i = t1 + 1; i < 4; i++)
786 *tx = (mvx[
t1] + mvx[
t2]) / 2;
787 *ty = (mvy[
t1] + mvy[
t2]) / 2;
802 int uvmx, uvmy, uvsrc_x, uvsrc_y;
803 int k, tx = 0, ty = 0;
804 int mvx[4], mvy[4], intra[4], mv_f[4];
816 for (k = 0; k < 4; k++) {
817 mvx[k] = s->
mv[dir][k][0];
818 mvy[k] = s->
mv[dir][k][1];
836 if (mv_f[0] + mv_f[1] + mv_f[2] + mv_f[3] > 2)
838 valid_count =
get_chroma_mv(mvx, mvy, mv_f, dominant, &tx, &ty);
846 uvmx = (tx + ((tx & 3) == 3)) >> 1;
847 uvmy = (ty + ((ty & 3) == 3)) >> 1;
853 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
854 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
858 uvmy += 2 - 4 * chroma_ref_type;
860 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
861 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
864 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
865 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
899 if (chroma_ref_type) {
907 || (
unsigned)uvsrc_x > (s->
h_edge_pos >> 1) - 9
908 || (
unsigned)uvsrc_y > (v_edge_pos >> 1) - 9) {
911 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
915 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
927 for (j = 0; j < 9; j++) {
928 for (i = 0; i < 9; i++) {
929 src[i] = ((src[i] - 128) >> 1) + 128;
930 src2[i] = ((src2[i] - 128) >> 1) + 128;
943 for (j = 0; j < 9; j++) {
944 int f = v->
field_mode ? chroma_ref_type : ((j + uvsrc_y) & 1);
945 for (i = 0; i < 9; i++) {
946 src[i] = lutuv[f][src[i]];
947 src2[i] = lutuv[f][src2[i]];
956 uvmx = (uvmx & 3) << 1;
957 uvmy = (uvmy & 3) << 1;
974 int uvsrc_x, uvsrc_y;
975 int uvmx_field[4], uvmy_field[4];
978 static const int s_rndtblfield[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 };
979 int v_dist = fieldmv ? 1 : 4;
987 for (i = 0; i < 4; i++) {
988 int d = i < 2 ? dir: dir2;
990 uvmx_field[i] = (tx + ((tx & 3) == 3)) >> 1;
993 uvmy_field[i] = (ty >> 4) * 8 + s_rndtblfield[ty & 0xF];
995 uvmy_field[i] = (ty + ((ty & 3) == 3)) >> 1;
998 for (i = 0; i < 4; i++) {
999 off = (i & 1) * 4 + ((i & 2) ? v_dist * s->
uvlinesize : 0);
1000 uvsrc_x = s->
mb_x * 8 + (i & 1) * 4 + (uvmx_field[i] >> 2);
1001 uvsrc_y = s->
mb_y * 8 + ((i & 2) ? v_dist : 0) + (uvmy_field[i] >> 2);
1005 if (i < 2 ? dir : dir2) {
1020 uvmx_field[i] = (uvmx_field[i] & 3) << 1;
1021 uvmy_field[i] = (uvmy_field[i] & 3) << 1;
1023 if (fieldmv && !(uvsrc_y & 1))
1026 if (fieldmv && (uvsrc_y & 1) && uvsrc_y < 2)
1029 || s->
h_edge_pos < 10 || v_edge_pos < (5 << fieldmv)
1030 || (unsigned)uvsrc_x > (s->
h_edge_pos >> 1) - 5
1031 || (unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) {
1034 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
1038 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
1050 for (j = 0; j < 5; j++) {
1051 int f = (uvsrc_y + (j << fieldmv)) & 1;
1052 for (i = 0; i < 5; i++) {
1053 src[i] = lutuv[f][src[i]];
1054 src2[i] = lutuv[f][src2[i]];
1092 #define GET_MQUANT() \
1093 if (v->dquantfrm) { \
1095 if (v->dqprofile == DQPROFILE_ALL_MBS) { \
1096 if (v->dqbilevel) { \
1097 mquant = (get_bits1(gb)) ? v->altpq : v->pq; \
1099 mqdiff = get_bits(gb, 3); \
1101 mquant = v->pq + mqdiff; \
1103 mquant = get_bits(gb, 5); \
1106 if (v->dqprofile == DQPROFILE_SINGLE_EDGE) \
1107 edges = 1 << v->dqsbedge; \
1108 else if (v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
1109 edges = (3 << v->dqsbedge) % 15; \
1110 else if (v->dqprofile == DQPROFILE_FOUR_EDGES) \
1112 if ((edges&1) && !s->mb_x) \
1113 mquant = v->altpq; \
1114 if ((edges&2) && s->first_slice_line) \
1115 mquant = v->altpq; \
1116 if ((edges&4) && s->mb_x == (s->mb_width - 1)) \
1117 mquant = v->altpq; \
1118 if ((edges&8) && s->mb_y == (s->mb_height - 1)) \
1119 mquant = v->altpq; \
1120 if (!mquant || mquant > 31) { \
1121 av_log(v->s.avctx, AV_LOG_ERROR, \
1122 "Overriding invalid mquant %d\n", mquant); \
1134 #define GET_MVDATA(_dmv_x, _dmv_y) \
1135 index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table, \
1136 VC1_MV_DIFF_VLC_BITS, 2); \
1138 mb_has_coeffs = 1; \
1141 mb_has_coeffs = 0; \
1144 _dmv_x = _dmv_y = 0; \
1145 } else if (index == 35) { \
1146 _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
1147 _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
1148 } else if (index == 36) { \
1153 index1 = index % 6; \
1154 if (!s->quarter_sample && index1 == 5) val = 1; \
1156 if (size_table[index1] - val > 0) \
1157 val = get_bits(gb, size_table[index1] - val); \
1159 sign = 0 - (val&1); \
1160 _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
1162 index1 = index / 6; \
1163 if (!s->quarter_sample && index1 == 5) val = 1; \
1165 if (size_table[index1] - val > 0) \
1166 val = get_bits(gb, size_table[index1] - val); \
1168 sign = 0 - (val & 1); \
1169 _dmv_y = (sign ^ ((val >> 1) + offset_table[index1])) - sign; \
1173 int *dmv_y,
int *pred_flag)
1176 int extend_x = 0, extend_y = 0;
1180 const int* offs_tab;
1197 extend_x = extend_y = 1;
1206 *pred_flag = *dmv_y & 1;
1207 *dmv_y = (*dmv_y + *pred_flag) >> 1;
1209 *dmv_y = (*dmv_y + (*dmv_y & 1)) >> 1;
1219 index1 = (index + 1) % 9;
1221 val =
get_bits(gb, index1 + extend_x);
1222 sign = 0 -(val & 1);
1223 *dmv_x = (sign ^ ((val >> 1) + offs_tab[index1])) - sign;
1230 index1 = (index + 1) / 9;
1231 if (index1 > v->
numref) {
1233 sign = 0 - (val & 1);
1234 *dmv_y = (sign ^ ((val >> 1) + offs_tab[index1 >> v->
numref])) - sign;
1237 if (v->
numref && pred_flag)
1238 *pred_flag = index1 & 1;
1244 int scaledvalue, refdist;
1245 int scalesame1, scalesame2;
1246 int scalezone1_x, zone1offset_x;
1263 if (
FFABS(n) < scalezone1_x)
1264 scaledvalue = (n * scalesame1) >> 8;
1267 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_x;
1269 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_x;
1277 int scaledvalue, refdist;
1278 int scalesame1, scalesame2;
1279 int scalezone1_y, zone1offset_y;
1296 if (
FFABS(n) < scalezone1_y)
1297 scaledvalue = (n * scalesame1) >> 8;
1300 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_y;
1302 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_y;
1307 return av_clip(scaledvalue, -v->
range_y / 2 + 1, v->
range_y / 2);
1309 return av_clip(scaledvalue, -v->
range_y / 2, v->
range_y / 2 - 1);
1314 int scalezone1_x, zone1offset_x;
1315 int scaleopp1, scaleopp2, brfd;
1327 if (
FFABS(n) < scalezone1_x)
1328 scaledvalue = (n * scaleopp1) >> 8;
1331 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_x;
1333 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_x;
1341 int scalezone1_y, zone1offset_y;
1342 int scaleopp1, scaleopp2, brfd;
1354 if (
FFABS(n) < scalezone1_y)
1355 scaledvalue = (n * scaleopp1) >> 8;
1358 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_y;
1360 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_y;
1364 return av_clip(scaledvalue, -v->
range_y / 2 + 1, v->
range_y / 2);
1366 return av_clip(scaledvalue, -v->
range_y / 2, v->
range_y / 2 - 1);
1373 int brfd, scalesame;
1387 n = (n * scalesame >> 8) << hpel;
1394 int refdist, scaleopp;
1411 n = (n * scaleopp >> 8) << hpel;
1418 int mv1,
int r_x,
int r_y,
uint8_t* is_intra,
1419 int pred_flag,
int dir)
1422 int xy,
wrap, off = 0;
1426 int mixedmv_pic, num_samefield = 0, num_oppfield = 0;
1427 int opposite, a_f, b_f, c_f;
1428 int16_t field_predA[2];
1429 int16_t field_predB[2];
1430 int16_t field_predC[2];
1431 int a_valid, b_valid, c_valid;
1432 int hybridmv_thresh, y_bias = 0;
1480 off = (s->
mb_x > 0) ? -1 : 1;
1495 b_valid = a_valid && (s->
mb_width > 1);
1496 c_valid = s->
mb_x || (n == 1 || n == 3);
1498 a_valid = a_valid && !is_intra[xy -
wrap];
1499 b_valid = b_valid && !is_intra[xy - wrap + off];
1500 c_valid = c_valid && !is_intra[xy - 1];
1505 num_oppfield += a_f;
1506 num_samefield += 1 - a_f;
1507 field_predA[0] = A[0];
1508 field_predA[1] = A[1];
1510 field_predA[0] = field_predA[1] = 0;
1515 num_oppfield += b_f;
1516 num_samefield += 1 - b_f;
1517 field_predB[0] = B[0];
1518 field_predB[1] = B[1];
1520 field_predB[0] = field_predB[1] = 0;
1525 num_oppfield += c_f;
1526 num_samefield += 1 - c_f;
1527 field_predC[0] = C[0];
1528 field_predC[1] = C[1];
1530 field_predC[0] = field_predC[1] = 0;
1540 if (num_samefield <= num_oppfield)
1541 opposite = 1 - pred_flag;
1543 opposite = pred_flag;
1548 if (a_valid && !a_f) {
1549 field_predA[0] =
scaleforopp(v, field_predA[0], 0, dir);
1550 field_predA[1] =
scaleforopp(v, field_predA[1], 1, dir);
1552 if (b_valid && !b_f) {
1553 field_predB[0] =
scaleforopp(v, field_predB[0], 0, dir);
1554 field_predB[1] =
scaleforopp(v, field_predB[1], 1, dir);
1556 if (c_valid && !c_f) {
1557 field_predC[0] =
scaleforopp(v, field_predC[0], 0, dir);
1558 field_predC[1] =
scaleforopp(v, field_predC[1], 1, dir);
1563 if (a_valid && a_f) {
1564 field_predA[0] =
scaleforsame(v, n, field_predA[0], 0, dir);
1565 field_predA[1] =
scaleforsame(v, n, field_predA[1], 1, dir);
1567 if (b_valid && b_f) {
1568 field_predB[0] =
scaleforsame(v, n, field_predB[0], 0, dir);
1569 field_predB[1] =
scaleforsame(v, n, field_predB[1], 1, dir);
1571 if (c_valid && c_f) {
1572 field_predC[0] =
scaleforsame(v, n, field_predC[0], 0, dir);
1573 field_predC[1] =
scaleforsame(v, n, field_predC[1], 1, dir);
1580 px = field_predA[0];
1581 py = field_predA[1];
1582 }
else if (c_valid) {
1583 px = field_predC[0];
1584 py = field_predC[1];
1585 }
else if (b_valid) {
1586 px = field_predB[0];
1587 py = field_predB[1];
1593 if (num_samefield + num_oppfield > 1) {
1594 px =
mid_pred(field_predA[0], field_predB[0], field_predC[0]);
1595 py =
mid_pred(field_predA[1], field_predB[1], field_predC[1]);
1601 qx = (s->
mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0);
1602 qy = (s->
mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0);
1606 if (qx + px < -60) px = -60 - qx;
1607 if (qy + py < -60) py = -60 - qy;
1609 if (qx + px < -28) px = -28 - qx;
1610 if (qy + py < -28) py = -28 - qy;
1612 if (qx + px > X) px = X - qx;
1613 if (qy + py > Y) py = Y - qy;
1618 hybridmv_thresh = 32;
1619 if (a_valid && c_valid) {
1620 if (is_intra[xy - wrap])
1623 sum =
FFABS(px - field_predA[0]) +
FFABS(py - field_predA[1]);
1624 if (sum > hybridmv_thresh) {
1626 px = field_predA[0];
1627 py = field_predA[1];
1629 px = field_predC[0];
1630 py = field_predC[1];
1633 if (is_intra[xy - 1])
1636 sum =
FFABS(px - field_predC[0]) +
FFABS(py - field_predC[1]);
1637 if (sum > hybridmv_thresh) {
1639 px = field_predA[0];
1640 py = field_predA[1];
1642 px = field_predC[0];
1643 py = field_predC[1];
1672 int mvn,
int r_x,
int r_y,
uint8_t* is_intra,
int dir)
1675 int xy,
wrap, off = 0;
1676 int A[2],
B[2],
C[2];
1678 int a_valid = 0, b_valid = 0, c_valid = 0;
1679 int field_a, field_b, field_c;
1680 int total_valid, num_samefield, num_oppfield;
1681 int pos_c, pos_b, n_adj;
1709 off = ((n == 0) || (n == 1)) ? 1 : -1;
1711 if (s->
mb_x || (n == 1) || (n == 3)) {
1731 B[0] = B[1] = C[0] = C[1] = 0;
1739 n_adj = (n & 2) | (n & 1);
1793 total_valid = a_valid + b_valid + c_valid;
1795 if (!s->
mb_x && !(n == 1 || n == 3)) {
1800 B[0] = B[1] = C[0] = C[1] = 0;
1807 if (total_valid >= 2) {
1810 }
else if (total_valid) {
1811 if (a_valid) { px = A[0]; py = A[1]; }
1812 else if (b_valid) { px = B[0]; py = B[1]; }
1813 else { px = C[0]; py = C[1]; }
1818 field_a = (A[1] & 4) ? 1 : 0;
1822 field_b = (B[1] & 4) ? 1 : 0;
1826 field_c = (C[1] & 4) ? 1 : 0;
1830 num_oppfield = field_a + field_b + field_c;
1831 num_samefield = total_valid - num_oppfield;
1832 if (total_valid == 3) {
1833 if ((num_samefield == 3) || (num_oppfield == 3)) {
1836 }
else if (num_samefield >= num_oppfield) {
1839 px = !field_a ? A[0] : B[0];
1840 py = !field_a ? A[1] : B[1];
1842 px = field_a ? A[0] : B[0];
1843 py = field_a ? A[1] : B[1];
1845 }
else if (total_valid == 2) {
1846 if (num_samefield >= num_oppfield) {
1847 if (!field_a && a_valid) {
1850 }
else if (!field_b && b_valid) {
1859 if (field_a && a_valid) {
1871 }
else if (total_valid == 1) {
1872 px = (a_valid) ? A[0] : ((b_valid) ? B[0] : C[0]);
1873 py = (a_valid) ? A[1] : ((b_valid) ? B[1] : C[1]);
1887 }
else if (mvn == 2) {
1890 s->
mv[dir][n + 1][0] = s->
mv[dir][
n][0];
1891 s->
mv[dir][n + 1][1] = s->
mv[dir][
n][1];
1902 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
1910 mx = s->
mv[1][0][0];
1911 my = s->
mv[1][0][1];
1912 uvmx = (mx + ((mx & 3) == 3)) >> 1;
1913 uvmy = (my + ((my & 3) == 3)) >> 1;
1921 uvmx = uvmx + ((uvmx < 0) ? -(uvmx & 1) : (uvmx & 1));
1922 uvmy = uvmy + ((uvmy < 0) ? -(uvmy & 1) : (uvmy & 1));
1928 src_x = s->
mb_x * 16 + (mx >> 2);
1929 src_y = s->
mb_y * 16 + (my >> 2);
1930 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
1931 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
1934 src_x = av_clip( src_x, -16, s->
mb_width * 16);
1935 src_y = av_clip( src_y, -16, s->
mb_height * 16);
1936 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
1937 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
1945 srcY += src_y * s->
linesize + src_x;
1962 || (
unsigned)(src_x - 1) > s->
h_edge_pos - (mx & 3) - 16 - 3
1963 || (
unsigned)(src_y - 1) > v_edge_pos - (my & 3) - 16 - 3) {
1992 for (j = 0; j < 17 + s->
mspel * 2; j++) {
1993 for (i = 0; i < 17 + s->
mspel * 2; i++)
1994 src[i] = ((src[i] - 128) >> 1) + 128;
1999 for (j = 0; j < 9; j++) {
2000 for (i = 0; i < 9; i++) {
2001 src[i] = ((src[i] - 128) >> 1) + 128;
2002 src2[i] = ((src2[i] - 128) >> 1) + 128;
2016 for (j = 0; j < 17 + s->
mspel * 2; j++) {
2018 for (i = 0; i < 17 + s->
mspel * 2; i++)
2019 src[i] = luty[f][src[i]];
2024 for (j = 0; j < 9; j++) {
2026 for (i = 0; i < 9; i++) {
2027 src[i] = lutuv[f][src[i]];
2028 src2[i] = lutuv[f][src2[i]];
2041 dxy = ((my & 3) << 2) | (mx & 3);
2044 dxy = (my & 2) | ((mx & 2) >> 1);
2054 uvmx = (uvmx & 3) << 1;
2055 uvmy = (uvmy & 3) << 1;
2069 #if B_FRACTION_DEN==256
2073 return 2 * ((value * n + 255) >> 9);
2074 return (value * n + 128) >> 8;
2087 int direct,
int mode)
2104 int direct,
int mvtype)
2107 int xy,
wrap, off = 0;
2143 s->
mv[0][0][0] = av_clip(s->
mv[0][0][0], -60 - (s->
mb_x << 6), (s->
mb_width << 6) - 4 - (s->
mb_x << 6));
2144 s->
mv[0][0][1] = av_clip(s->
mv[0][0][1], -60 - (s->
mb_y << 6), (s->
mb_height << 6) - 4 - (s->
mb_y << 6));
2145 s->
mv[1][0][0] = av_clip(s->
mv[1][0][0], -60 - (s->
mb_x << 6), (s->
mb_width << 6) - 4 - (s->
mb_x << 6));
2146 s->
mv[1][0][1] = av_clip(s->
mv[1][0][1], -60 - (s->
mb_y << 6), (s->
mb_height << 6) - 4 - (s->
mb_y << 6));
2161 if (!s->
mb_x) C[0] = C[1] = 0;
2170 }
else if (s->
mb_x) {
2180 qx = (s->
mb_x << 5);
2181 qy = (s->
mb_y << 5);
2184 if (qx + px < -28) px = -28 - qx;
2185 if (qy + py < -28) py = -28 - qy;
2186 if (qx + px > X) px = X - qx;
2187 if (qy + py > Y) py = Y - qy;
2189 qx = (s->
mb_x << 6);
2190 qy = (s->
mb_y << 6);
2193 if (qx + px < -60) px = -60 - qx;
2194 if (qy + py < -60) py = -60 - qy;
2195 if (qx + px > X) px = X - qx;
2196 if (qy + py > Y) py = Y - qy;
2201 if (is_intra[xy - wrap])
2214 if (is_intra[xy - 2])
2230 s->
mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
2231 s->
mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
2249 }
else if (s->
mb_x) {
2259 qx = (s->
mb_x << 5);
2260 qy = (s->
mb_y << 5);
2263 if (qx + px < -28) px = -28 - qx;
2264 if (qy + py < -28) py = -28 - qy;
2265 if (qx + px > X) px = X - qx;
2266 if (qy + py > Y) py = Y - qy;
2268 qx = (s->
mb_x << 6);
2269 qy = (s->
mb_y << 6);
2272 if (qx + px < -60) px = -60 - qx;
2273 if (qy + py < -60) py = -60 - qy;
2274 if (qx + px > X) px = X - qx;
2275 if (qy + py > Y) py = Y - qy;
2280 if (is_intra[xy - wrap])
2293 if (is_intra[xy - 2])
2310 s->
mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
2311 s->
mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
2326 int total_opp, k, f;
2341 f = (total_opp > 2) ? 1 : 0;
2343 s->
mv[0][0][0] = s->
mv[0][0][1] = 0;
2344 s->
mv[1][0][0] = s->
mv[1][0][1] = 0;
2348 for (k = 0; k < 4; k++) {
2365 if (n == 3 || mv1) {
2370 if (n == 3 || mv1) {
2386 int16_t **dc_val_ptr,
int *dir_ptr)
2390 static const uint16_t dcpred[32] = {
2391 -1, 1024, 512, 341, 256, 205, 171, 146, 128,
2392 114, 102, 93, 85, 79, 73, 68, 64,
2393 60, 57, 54, 51, 49, 47, 45, 43,
2394 41, 39, 38, 37, 35, 34, 33
2408 b = dc_val[ - 1 -
wrap];
2409 a = dc_val[ -
wrap];
2411 if (pq < 9 || !overlap) {
2414 b = a = dcpred[scale];
2415 if (s->
mb_x == 0 && (n != 1 && n != 3))
2416 b = c = dcpred[scale];
2421 if (s->
mb_x == 0 && (n != 1 && n != 3))
2425 if (abs(a - b) <= abs(b - c)) {
2434 *dc_val_ptr = &dc_val[0];
2451 int a_avail,
int c_avail,
2452 int16_t **dc_val_ptr,
int *dir_ptr)
2467 b = dc_val[ - 1 -
wrap];
2468 a = dc_val[ -
wrap];
2472 if (dqscale_index < 0)
2474 if (c_avail && (n != 1 && n != 3)) {
2479 if (a_avail && (n != 2 && n != 3)) {
2484 if (a_avail && c_avail && (n != 3)) {
2495 if (a_avail && c_avail) {
2496 if (abs(a - b) <= abs(b - c)) {
2503 }
else if (a_avail) {
2506 }
else if (c_avail) {
2515 *dc_val_ptr = &dc_val[0];
2564 int *
value,
int codingset)
2630 int coded,
int codingset)
2634 int dc_pred_dir = 0;
2637 int16_t *ac_val, *ac_val2;
2651 if (dcdiff == 119 ) {
2654 else if (v->
pq == 2) dcdiff =
get_bits(gb, 9);
2658 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
2659 else if (v->
pq == 2)
2660 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
2685 int last = 0, skip,
value;
2712 block[zz_table[i++]] =
value;
2718 for (k = 1; k < 8; k++)
2721 for (k = 1; k < 8; k++)
2726 for (k = 1; k < 8; k++) {
2732 for (k = 1; k < 64; k++)
2736 block[k] += (block[k] < 0) ? -v->
pq : v->
pq;
2750 memset(ac_val2, 0, 16 * 2);
2754 memcpy(ac_val2, ac_val, 8 * 2);
2758 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
2764 for (k = 1; k < 8; k++) {
2770 for (k = 1; k < 8; k++) {
2771 block[k << v->
top_blk_sh] = ac_val[k + 8] * scale;
2793 int coded,
int codingset,
int mquant)
2797 int dc_pred_dir = 0;
2799 int16_t *dc_val = NULL;
2800 int16_t *ac_val, *ac_val2;
2819 if (dcdiff == 119 ) {
2821 if (mquant == 1) dcdiff =
get_bits(gb, 10);
2822 else if (mquant == 2) dcdiff =
get_bits(gb, 9);
2826 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
2827 else if (mquant == 2)
2828 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
2849 if (!a_avail && !c_avail)
2854 scale = mquant * 2 + ((mquant == v->
pq) ? v->
halfpq : 0);
2862 if ( dc_pred_dir && c_avail && mb_pos)
2864 if (!dc_pred_dir && a_avail && mb_pos >= s->
mb_stride)
2866 if ( dc_pred_dir && n == 1)
2868 if (!dc_pred_dir && n == 2)
2874 int last = 0, skip,
value;
2899 block[zz_table[i++]] =
value;
2905 if (q2 && q1 != q2) {
2906 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2907 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2912 for (k = 1; k < 8; k++)
2915 for (k = 1; k < 8; k++)
2920 for (k = 1; k < 8; k++)
2923 for (k = 1; k < 8; k++)
2929 for (k = 1; k < 8; k++) {
2935 for (k = 1; k < 64; k++)
2939 block[k] += (block[k] < 0) ? -mquant : mquant;
2942 if (use_pred) i = 63;
2946 memset(ac_val2, 0, 16 * 2);
2949 memcpy(ac_val2, ac_val, 8 * 2);
2950 if (q2 && q1 != q2) {
2951 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2952 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2955 for (k = 1; k < 8; k++)
2956 ac_val2[k] = (ac_val2[k] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2961 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
2962 if (q2 && q1 != q2) {
2963 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2964 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2967 for (k = 1; k < 8; k++)
2968 ac_val2[k + 8] = (ac_val2[k + 8] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2976 for (k = 1; k < 8; k++) {
2982 for (k = 1; k < 8; k++) {
2983 block[k << v->
top_blk_sh] = ac_val2[k + 8] * scale;
3005 int coded,
int mquant,
int codingset)
3009 int dc_pred_dir = 0;
3011 int16_t *dc_val = NULL;
3012 int16_t *ac_val, *ac_val2;
3023 mquant = (mquant < 1) ? 0 : ((mquant > 31) ? 31 : mquant);
3040 if (dcdiff == 119 ) {
3042 if (mquant == 1) dcdiff =
get_bits(gb, 10);
3043 else if (mquant == 2) dcdiff =
get_bits(gb, 9);
3047 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
3048 else if (mquant == 2)
3049 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
3056 dcdiff +=
vc1_pred_dc(&v->
s, v->
overlap, mquant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
3071 if (!a_avail) dc_pred_dir = 1;
3072 if (!c_avail) dc_pred_dir = 0;
3073 if (!a_avail && !c_avail) use_pred = 0;
3077 scale = mquant * 2 + v->
halfpq;
3085 if (dc_pred_dir && c_avail && mb_pos)
3087 if (!dc_pred_dir && a_avail && mb_pos >= s->
mb_stride)
3089 if ( dc_pred_dir && n == 1)
3091 if (!dc_pred_dir && n == 2)
3093 if (n == 3) q2 = q1;
3096 int last = 0, skip,
value;
3121 if (q2 && q1 != q2) {
3122 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3123 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3128 for (k = 1; k < 8; k++)
3131 for (k = 1; k < 8; k++)
3136 for (k = 1; k < 8; k++)
3139 for (k = 1; k < 8; k++)
3145 for (k = 1; k < 8; k++) {
3151 for (k = 1; k < 64; k++)
3155 block[k] += (block[k] < 0) ? -mquant : mquant;
3158 if (use_pred) i = 63;
3162 memset(ac_val2, 0, 16 * 2);
3165 memcpy(ac_val2, ac_val, 8 * 2);
3166 if (q2 && q1 != q2) {
3167 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3168 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3171 for (k = 1; k < 8; k++)
3172 ac_val2[k] = (ac_val2[k] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
3177 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
3178 if (q2 && q1 != q2) {
3179 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3180 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3183 for (k = 1; k < 8; k++)
3184 ac_val2[k + 8] = (ac_val2[k + 8] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
3192 for (k = 1; k < 8; k++) {
3198 for (k = 1; k < 8; k++) {
3199 block[k << v->
top_blk_sh] = ac_val2[k + 8] * scale;
3215 int mquant,
int ttmb,
int first_block,
3216 uint8_t *dst,
int linesize,
int skip_block,
3223 int scale, off, idx, last, skip,
value;
3224 int ttblk = ttmb & 7;
3236 && ((v->
ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
3246 scale = 2 * mquant + ((v->
pq == mquant) ? v->
halfpq : 0);
3271 block[idx] = value * scale;
3273 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3285 pat = ~subblkpat & 0xF;
3286 for (j = 0; j < 4; j++) {
3287 last = subblkpat & (1 << (3 - j));
3289 off = (j & 1) * 4 + (j & 2) * 16;
3299 block[idx + off] = value * scale;
3301 block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant;
3303 if (!(subblkpat & (1 << (3 - j))) && !skip_block) {
3312 pat = ~((subblkpat & 2) * 6 + (subblkpat & 1) * 3) & 0xF;
3313 for (j = 0; j < 2; j++) {
3314 last = subblkpat & (1 << (1 - j));
3323 idx = v->
zz_8x4[i++] + off;
3326 block[idx] = value * scale;
3328 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3330 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
3339 pat = ~(subblkpat * 5) & 0xF;
3340 for (j = 0; j < 2; j++) {
3341 last = subblkpat & (1 << (1 - j));
3350 idx = v->
zz_4x8[i++] + off;
3353 block[idx] = value * scale;
3355 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3357 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
3367 *ttmb_out |= ttblk << (n * 4);
3380 block_cbp = mb_cbp >> (block_num * 4), bottom_cbp,
3382 block_is_intra = mb_is_intra >> (block_num * 4), bottom_is_intra;
3386 if (block_num > 3) {
3387 dst = s->
dest[block_num - 3];
3389 dst = s->
dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 8) * linesize;
3395 if (block_num > 3) {
3396 bottom_cbp = v->
cbp[s->
mb_x] >> (block_num * 4);
3397 bottom_is_intra = v->
is_intra[s->
mb_x] >> (block_num * 4);
3401 bottom_cbp = (block_num < 2) ? (mb_cbp >> ((block_num + 2) * 4))
3402 : (v->
cbp[s->
mb_x] >> ((block_num - 2) * 4));
3403 bottom_is_intra = (block_num < 2) ? (mb_is_intra >> ((block_num + 2) * 4))
3409 if (bottom_is_intra & 1 || block_is_intra & 1 ||
3410 mv[0][0] !=
mv[mv_stride][0] ||
mv[0][1] !=
mv[mv_stride][1]) {
3413 idx = ((bottom_cbp >> 2) | block_cbp) & 3;
3425 dst -= 4 * linesize;
3428 idx = (block_cbp | (block_cbp >> 2)) & 3;
3444 block_cbp = mb_cbp >> (block_num * 4), right_cbp,
3446 block_is_intra = mb_is_intra >> (block_num * 4), right_is_intra;
3450 if (block_num > 3) {
3451 dst = s->
dest[block_num - 3] - 8 * linesize;
3453 dst = s->
dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 16) * linesize - 8;
3459 if (block_num > 3) {
3464 right_cbp = (block_num & 1) ? (v->
cbp[s->
mb_x - s->
mb_stride] >> ((block_num - 1) * 4))
3465 : (mb_cbp >> ((block_num + 1) * 4));
3467 : (mb_is_intra >> ((block_num + 1) * 4));
3470 if (block_is_intra & 1 || right_is_intra & 1 ||
mv[0][0] !=
mv[1][0] ||
mv[0][1] !=
mv[1][1]) {
3473 idx = ((right_cbp >> 1) | block_cbp) & 5;
3488 idx = (block_cbp | (block_cbp >> 1)) & 5;
3505 for (i = 0; i < 6; i++) {
3512 for (i = 0; i < 6; i++) {
3518 for (i = 0; i < 6; i++) {
3535 int ttmb = v->
ttfrm;
3537 int mb_has_coeffs = 1;
3541 int first_block = 1;
3543 int skipped, fourmv;
3544 int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
3569 if (s->
mb_intra && !mb_has_coeffs) {
3573 }
else if (mb_has_coeffs) {
3589 for (i = 0; i < 6; i++) {
3592 val = ((cbp >> (5 - i)) & 1);
3593 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3600 if (i == 1 || i == 3 || s->
mb_x)
3609 for (j = 0; j < 64; j++)
3610 s->
block[i][j] <<= 1;
3612 s->
dest[dst_idx] + off,
3621 block_cbp |= 0xF << (i << 2);
3622 block_intra |= 1 << i;
3627 block_cbp |= pat << (i << 2);
3628 if (!v->
ttmbf && ttmb < 8)
3635 for (i = 0; i < 6; i++) {
3646 int intra_count = 0, coded_inter = 0;
3647 int is_intra[6], is_coded[6];
3650 for (i = 0; i < 6; i++) {
3651 val = ((cbp >> (5 - i)) & 1);
3666 is_coded[i] = mb_has_coeffs;
3669 is_intra[i] = (intra_count >= 3);
3676 coded_inter = !is_intra[i] & is_coded[i];
3680 if (!intra_count && !coded_inter)
3687 for (i = 0; i < 6; i++)
3700 if (!v->
ttmbf && coded_inter)
3702 for (i = 0; i < 6; i++) {
3704 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3711 if (i == 1 || i == 3 || s->
mb_x)
3720 for (j = 0; j < 64; j++)
3721 s->
block[i][j] <<= 1;
3723 s->
dest[dst_idx] + off,
3732 block_cbp |= 0xF << (i << 2);
3733 block_intra |= 1 << i;
3734 }
else if (is_coded[i]) {
3736 first_block, s->
dest[dst_idx] + off,
3740 block_cbp |= pat << (i << 2);
3741 if (!v->
ttmbf && ttmb < 8)
3749 for (i = 0; i < 6; i++) {
3753 for (i = 0; i < 4; i++) {
3779 int ttmb = v->
ttfrm;
3781 int mb_has_coeffs = 1;
3784 int first_block = 1;
3786 int skipped, fourmv = 0, twomv = 0;
3787 int block_cbp = 0, pat, block_tt = 0;
3788 int idx_mbmode = 0, mvbp;
3789 int stride_y, fieldtx;
3833 for (i = 0; i < 4; i++) {
3839 for (i = 0; i < 6; i++)
3852 for (i = 0; i < 6; i++) {
3855 val = ((cbp >> (5 - i)) & 1);
3860 if (i == 1 || i == 3 || s->
mb_x)
3869 off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->
linesize : (i & 1) * 8 + 4 * (i & 2) * s->
linesize;
3875 s->
dest[dst_idx] + off,
3893 for (i = 0; i < 6; i++)
3900 for (i = 0; i < 6; i++) {
3903 val = ((mvbp >> (3 - i)) & 1);
3909 }
else if (i == 4) {
3942 if (!v->
ttmbf && cbp)
3944 for (i = 0; i < 6; i++) {
3947 val = ((cbp >> (5 - i)) & 1);
3949 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3951 off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->
linesize));
3954 first_block, s->
dest[dst_idx] + off,
3957 block_cbp |= pat << (i << 2);
3958 if (!v->
ttmbf && ttmb < 8)
3966 for (i = 0; i < 6; i++) {
3992 int ttmb = v->
ttfrm;
3994 int mb_has_coeffs = 1;
3997 int first_block = 1;
4000 int block_cbp = 0, pat, block_tt = 0;
4006 if (idx_mbmode <= 1) {
4017 mb_has_coeffs = idx_mbmode & 1;
4021 for (i = 0; i < 6; i++) {
4025 val = ((cbp >> (5 - i)) & 1);
4029 if (i == 1 || i == 3 || s->
mb_x)
4037 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4039 s->
dest[dst_idx] + off,
4048 if (idx_mbmode <= 5) {
4049 dmv_x = dmv_y = pred_flag = 0;
4050 if (idx_mbmode & 1) {
4055 mb_has_coeffs = !(idx_mbmode & 2);
4058 for (i = 0; i < 6; i++) {
4060 dmv_x = dmv_y = pred_flag = 0;
4061 val = ((v->
fourmvbp >> (3 - i)) & 1);
4070 mb_has_coeffs = idx_mbmode & 1;
4078 if (!v->
ttmbf && cbp) {
4082 for (i = 0; i < 6; i++) {
4085 val = ((cbp >> (5 - i)) & 1);
4086 off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->
linesize;
4089 first_block, s->
dest[dst_idx] + off,
4093 block_cbp |= pat << (i << 2);
4094 if (!v->
ttmbf && ttmb < 8) ttmb = -1;
4114 int ttmb = v->
ttfrm;
4115 int mb_has_coeffs = 0;
4118 int first_block = 1;
4120 int skipped, direct;
4121 int dmv_x[2], dmv_y[2];
4136 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
4137 for (i = 0; i < 6; i++) {
4146 dmv_x[1] = dmv_x[0];
4147 dmv_y[1] = dmv_y[0];
4160 dmv_x[0] = dmv_y[0] = 0;
4164 for (i = 0; i < 6; i++)
4171 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4181 dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
4183 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4185 if (!mb_has_coeffs && !s->
mb_intra) {
4188 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4191 if (s->
mb_intra && !mb_has_coeffs) {
4200 if (!mb_has_coeffs) {
4203 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4209 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4221 for (i = 0; i < 6; i++) {
4224 val = ((cbp >> (5 - i)) & 1);
4225 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4232 if (i == 1 || i == 3 || s->
mb_x)
4241 for (j = 0; j < 64; j++)
4242 s->
block[i][j] <<= 1;
4244 s->
dest[dst_idx] + off,
4249 first_block, s->
dest[dst_idx] + off,
4252 if (!v->
ttmbf && ttmb < 8)
4269 int ttmb = v->
ttfrm;
4270 int mb_has_coeffs = 0;
4272 int first_block = 1;
4275 int dmv_x[2], dmv_y[2], pred_flag[2];
4283 if (idx_mbmode <= 1) {
4294 mb_has_coeffs = idx_mbmode & 1;
4298 for (i = 0; i < 6; i++) {
4301 val = ((cbp >> (5 - i)) & 1);
4306 if (i == 1 || i == 3 || s->
mb_x)
4315 for (j = 0; j < 64; j++)
4316 s->
block[i][j] <<= 1;
4317 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4319 s->
dest[dst_idx] + off,
4332 if (idx_mbmode <= 5) {
4334 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
4335 pred_flag[0] = pred_flag[1] = 0;
4360 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
4361 dmv_x[1] = dmv_y[1] = pred_flag[0] = 0;
4369 mb_has_coeffs = !(idx_mbmode & 2);
4375 for (i = 0; i < 6; i++) {
4377 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
4378 dmv_x[1] = dmv_y[1] = pred_flag[1] = 0;
4379 val = ((v->
fourmvbp >> (3 - i)) & 1);
4390 mb_has_coeffs = idx_mbmode & 1;
4398 if (!v->
ttmbf && cbp) {
4402 for (i = 0; i < 6; i++) {
4405 val = ((cbp >> (5 - i)) & 1);
4406 off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->
linesize;
4409 first_block, s->
dest[dst_idx] + off,
4412 if (!v->
ttmbf && ttmb < 8)
4430 int ttmb = v->
ttfrm;
4432 int mb_has_coeffs = 1;
4435 int first_block = 1;
4437 int skipped, direct, twomv = 0;
4438 int block_cbp = 0, pat, block_tt = 0;
4439 int idx_mbmode = 0, mvbp;
4440 int stride_y, fieldtx;
4486 for (i = 1; i < 4; i += 2) {
4493 for (i = 1; i < 4; i++) {
4503 for (i = 0; i < 4; i++) {
4511 for (i = 0; i < 6; i++)
4524 for (i = 0; i < 6; i++) {
4527 val = ((cbp >> (5 - i)) & 1);
4532 if (i == 1 || i == 3 || s->
mb_x)
4542 off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->
linesize : (i & 1) * 8 + 4 * (i & 2) * s->
linesize;
4548 s->
dest[dst_idx] + off,
4584 for (i = 0; i < 6; i++)
4591 for (i = 0; i < 4; i++) {
4603 for (i = 0; i < 4; i++) {
4606 val = ((mvbp >> (3 - i)) & 1);
4649 for (i = 0; i < 2; i++) {
4679 for (i = 0; i < 2; i++) {
4689 if (!v->
ttmbf && cbp)
4691 for (i = 0; i < 6; i++) {
4694 val = ((cbp >> (5 - i)) & 1);
4696 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4698 off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->
linesize));
4701 first_block, s->
dest[dst_idx] + off,
4704 block_cbp |= pat << (i << 2);
4705 if (!v->
ttmbf && ttmb < 8)
4713 for (i = 0; i < 6; i++) {
4735 for (i = 0; i < 2; i++) {
4747 for (i = 0; i < 2; i++) {
4817 dst[0] = s->
dest[0];
4818 dst[1] = dst[0] + 8;
4820 dst[3] = dst[2] + 8;
4821 dst[4] = s->
dest[1];
4822 dst[5] = s->
dest[2];
4834 for (k = 0; k < 6; k++) {
4835 val = ((cbp >> (5 - k)) & 1);
4842 cbp |= val << (5 - k);
4851 for (j = 0; j < 64; j++)
4852 s->
block[k][j] <<= 1;
4858 for (j = 0; j < 64; j++)
4992 for (k = 0; k < 6; k++) {
4993 val = ((cbp >> (5 - k)) & 1);
5000 cbp |= val << (5 - k);
5110 if (apply_loop_filter) {
5246 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
5262 int effect_type, effect_flag;
5263 int effect_pcount1, effect_pcount2;
5264 int effect_params1[15], effect_params2[10];
5272 static void vc1_sprite_parse_transform(
GetBitContext* gb,
int c[7])
5279 c[2] = get_fp_val(gb);
5283 c[0] = c[4] = get_fp_val(gb);
5284 c[2] = get_fp_val(gb);
5287 c[0] = get_fp_val(gb);
5288 c[2] = get_fp_val(gb);
5289 c[4] = get_fp_val(gb);
5292 c[0] = get_fp_val(gb);
5293 c[1] = get_fp_val(gb);
5294 c[2] = get_fp_val(gb);
5295 c[3] = get_fp_val(gb);
5296 c[4] = get_fp_val(gb);
5299 c[5] = get_fp_val(gb);
5301 c[6] = get_fp_val(gb);
5311 for (sprite = 0; sprite <= v->
two_sprites; sprite++) {
5312 vc1_sprite_parse_transform(gb, sd->coefs[sprite]);
5313 if (sd->coefs[sprite][1] || sd->coefs[sprite][3])
5316 for (i = 0; i < 7; i++)
5318 sd->coefs[sprite][i] / (1<<16),
5319 (abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1 << 16));
5325 switch (sd->effect_pcount1 =
get_bits(gb, 4)) {
5327 vc1_sprite_parse_transform(gb, sd->effect_params1);
5330 vc1_sprite_parse_transform(gb, sd->effect_params1);
5331 vc1_sprite_parse_transform(gb, sd->effect_params1 + 7);
5334 for (i = 0; i < sd->effect_pcount1; i++)
5335 sd->effect_params1[i] = get_fp_val(gb);
5337 if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) {
5340 for (i = 0; i < sd->effect_pcount1; i++)
5342 sd->effect_params1[i] / (1 << 16),
5343 (abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1 << 16));
5347 sd->effect_pcount2 =
get_bits(gb, 16);
5348 if (sd->effect_pcount2 > 10) {
5351 }
else if (sd->effect_pcount2) {
5354 while (++i < sd->effect_pcount2) {
5355 sd->effect_params2[i] = get_fp_val(gb);
5357 sd->effect_params2[i] / (1 << 16),
5358 (abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1 << 16));
5377 static void vc1_draw_sprites(
VC1Context *v, SpriteData* sd)
5379 int i, plane, row, sprite;
5380 int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } };
5382 int xoff[2], xadv[2], yoff[2], yadv[2],
alpha;
5387 xoff[i] = av_clip(sd->coefs[i][2], 0, v->
sprite_width-1 << 16);
5388 xadv[i] = sd->coefs[i][0];
5392 yoff[i] = av_clip(sd->coefs[i][5], 0, v->
sprite_height-1 << 16);
5395 alpha = av_clip(sd->coefs[1][6], 0, (1<<16) - 1);
5404 for (sprite = 0; sprite <= v->
two_sprites; sprite++) {
5407 int ycoord = yoff[sprite] + yadv[sprite] * row;
5408 int yline = ycoord >> 16;
5410 ysub[sprite] = ycoord & 0xFFFF;
5416 if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) {
5417 src_h[sprite][0] = iplane + (xoff[sprite] >> 16) + yline * iline;
5419 src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + next_line;
5421 if (sr_cache[sprite][0] != yline) {
5422 if (sr_cache[sprite][1] == yline) {
5424 FFSWAP(
int, sr_cache[sprite][0], sr_cache[sprite][1]);
5426 v->
vc1dsp.
sprite_h(v->
sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width);
5427 sr_cache[sprite][0] = yline;
5430 if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) {
5432 iplane + next_line, xoff[sprite],
5433 xadv[sprite], width);
5434 sr_cache[sprite][1] = yline + 1;
5436 src_h[sprite][0] = v->
sr_rows[sprite][0];
5437 src_h[sprite][1] = v->
sr_rows[sprite][1];
5445 memcpy(dst, src_h[0][0], width);
5448 if (ysub[0] && ysub[1]) {
5450 src_h[1][0], src_h[1][1], ysub[1], alpha, width);
5451 }
else if (ysub[0]) {
5453 src_h[1][0], alpha, width);
5454 }
else if (ysub[1]) {
5456 src_h[0][0], (1<<16)-1-alpha, width);
5481 memset(&sd, 0,
sizeof(sd));
5483 ret = vc1_parse_sprites(v, gb, &sd);
5501 vc1_draw_sprites(v, &sd);
5521 plane ? 128 : 0, f->
linesize[plane]);
5578 for (i = 0; i < 4; i++)
5605 for (i = 0; i < 64; i++) {
5606 #define transpose(x) (((x) >> 3) | (((x) & 7) << 3))
5673 }
else if (count < 0) {
5680 int size, buf2_size;
5682 int seq_initialized = 0, ep_initialized = 0;
5692 for (; next <
end; start = next) {
5694 size = next - start - 4;
5705 seq_initialized = 1;
5717 if (!seq_initialized || !ep_initialized) {
5776 for (i = 0; i < 4; i++)
5808 int buf_size = avpkt->
size, n_slices = 0, i,
ret;
5813 const uint8_t *buf_start =
buf, *buf_start_second_field = NULL;
5814 int mb_height, n_slices1=-1;
5819 } *slices = NULL, *tmp;
5859 for (start = buf, end = buf + buf_size; next <
end; start = next) {
5861 size = next - start - 4;
5862 if (size <= 0)
continue;
5874 buf_start_second_field =
start;
5880 if (!slices[n_slices].buf)
5883 slices[n_slices].buf);
5888 slices[n_slices].mby_start = s->
mb_height + 1 >> 1;
5889 n_slices1 = n_slices - 1;
5905 if (!slices[n_slices].buf)
5908 slices[n_slices].buf);
5911 slices[n_slices].mby_start =
get_bits(&slices[n_slices].gb, 9);
5917 }
else if (v->
interlace && ((buf[0] & 0xC0) == 0xC0)) {
5928 buf_start_second_field = divider;
5934 if (!slices[n_slices].buf)
5936 buf_size3 =
vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf);
5939 slices[n_slices].mby_start = s->
mb_height + 1 >> 1;
5940 n_slices1 = n_slices - 1;
6066 if ((CONFIG_VC1_VDPAU_DECODER)
6068 if (v->
field_mode && buf_start_second_field) {
6075 if (v->
field_mode && buf_start_second_field) {
6078 if (avctx->
hwaccel->
start_frame(avctx, buf_start, buf_start_second_field - buf_start) < 0)
6080 if (avctx->
hwaccel->
decode_slice(avctx, buf_start, buf_start_second_field - buf_start) < 0)
6086 s->
gb = slices[n_slices1 + 1].gb;
6096 if (avctx->
hwaccel->
start_frame(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field) < 0)
6098 if (avctx->
hwaccel->
decode_slice(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field) < 0)
6116 v->
bits = buf_size * 8;
6129 for (i = 0; i <= n_slices; i++) {
6130 if (i > 0 && slices[i - 1].mby_start >= mb_height) {
6133 "picture boundary (%d >= %d)\n", i,
6134 slices[i - 1].mby_start, mb_height);
6167 s->
start_mb_y = (i == 0) ? 0 :
FFMAX(0, slices[i-1].mby_start % mb_height);
6169 s->
end_mb_y = (i == n_slices ) ? mb_height :
FFMIN(mb_height, slices[i].mby_start % mb_height);
6171 if (i >= n_slices) {
6175 s->
end_mb_y = (i <= n_slices1 + 1) ? mb_height :
FFMIN(mb_height, slices[i].mby_start % mb_height);
6187 s->
gb = slices[i].gb;
6219 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
6220 if (vc1_decode_sprites(v, &s->
gb))
6242 for (i = 0; i < n_slices; i++)
6249 for (i = 0; i < n_slices; i++)
6265 #if CONFIG_VC1_DXVA2_HWACCEL
6268 #if CONFIG_VC1_VAAPI_HWACCEL
6271 #if CONFIG_VC1_VDPAU_HWACCEL
6289 .pix_fmts = vc1_hwaccel_pixfmt_list_420,
6293 #if CONFIG_WMV3_DECODER
6305 .pix_fmts = vc1_hwaccel_pixfmt_list_420,
6310 #if CONFIG_WMV3_VDPAU_DECODER
6311 AVCodec ff_wmv3_vdpau_decoder = {
6312 .
name =
"wmv3_vdpau",
6326 #if CONFIG_VC1_VDPAU_DECODER
6327 AVCodec ff_vc1_vdpau_decoder = {
6328 .
name =
"vc1_vdpau",
6342 #if CONFIG_WMV3IMAGE_DECODER
6343 AVCodec ff_wmv3image_decoder = {
6344 .
name =
"wmv3image",
6353 .
flush = vc1_sprite_flush,
6361 #if CONFIG_VC1IMAGE_DECODER
6362 AVCodec ff_vc1image_decoder = {
6372 .
flush = vc1_sprite_flush,