47 #define MB_INTRA_VLC_BITS 9
53 static const int offset_table2[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
79 int topleft_mb_pos, top_mb_pos;
80 int stride_y, fieldtx = 0;
96 v_dist = (16 - fieldtx) >> (fieldtx == 0);
121 v_dist = fieldtx ? 15 : 8;
143 #define inc_blk_idx(idx) do { \
145 if (idx >= v->n_allocated_blks) \
164 for (j = 0; j < 2; j++) {
197 for (j = 0; j < 2; j++) {
214 for (j = 0; j < 2; j++) {
230 for (j = 0; j < 2; j++) {
241 for (j = 0; j < 2; j++) {
335 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
338 uint8_t (*luty)[256], (*lutuv)[256];
346 mx = s->
mv[dir][0][0];
347 my = s->
mv[dir][0][1];
351 for (i = 0; i < 4; i++) {
357 uvmx = (mx + ((mx & 3) == 3)) >> 1;
358 uvmy = (my + ((my & 3) == 3)) >> 1;
370 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
371 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
398 if (!srcY || !srcU) {
403 src_x = s->
mb_x * 16 + (mx >> 2);
404 src_y = s->
mb_y * 16 + (my >> 2);
405 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
406 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
409 src_x = av_clip( src_x, -16, s->
mb_width * 16);
410 src_y = av_clip( src_y, -16, s->
mb_height * 16);
411 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
412 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
420 srcY += src_y * s->
linesize + src_x;
439 || (
unsigned)(src_y - 1) > v_edge_pos - (my&3) - 16 - 3) {
467 for (j = 0; j < 17 + s->
mspel * 2; j++) {
468 for (i = 0; i < 17 + s->
mspel * 2; i++)
469 src[i] = ((src[i] - 128) >> 1) + 128;
474 for (j = 0; j < 9; j++) {
475 for (i = 0; i < 9; i++) {
476 src[i] = ((src[i] - 128) >> 1) + 128;
477 src2[i] = ((src2[i] - 128) >> 1) + 128;
489 for (j = 0; j < 17 + s->
mspel * 2; j++) {
491 for (i = 0; i < 17 + s->
mspel * 2; i++)
492 src[i] = luty[f][src[i]];
497 for (j = 0; j < 9; j++) {
499 for (i = 0; i < 9; i++) {
500 src[i] = lutuv[f][src[i]];
501 src2[i] = lutuv[f][src2[i]];
511 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)
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)
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;
1920 uvmx = uvmx + ((uvmx < 0) ? -(uvmx & 1) : (uvmx & 1));
1921 uvmy = uvmy + ((uvmy < 0) ? -(uvmy & 1) : (uvmy & 1));
1927 src_x = s->
mb_x * 16 + (mx >> 2);
1928 src_y = s->
mb_y * 16 + (my >> 2);
1929 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
1930 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
1933 src_x = av_clip( src_x, -16, s->
mb_width * 16);
1934 src_y = av_clip( src_y, -16, s->
mb_height * 16);
1935 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
1936 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
1944 srcY += src_y * s->
linesize + src_x;
1961 || (
unsigned)(src_x - 1) > s->
h_edge_pos - (mx & 3) - 16 - 3
1962 || (
unsigned)(src_y - 1) > v_edge_pos - (my & 3) - 16 - 3) {
1990 for (j = 0; j < 17 + s->
mspel * 2; j++) {
1991 for (i = 0; i < 17 + s->
mspel * 2; i++)
1992 src[i] = ((src[i] - 128) >> 1) + 128;
1997 for (j = 0; j < 9; j++) {
1998 for (i = 0; i < 9; i++) {
1999 src[i] = ((src[i] - 128) >> 1) + 128;
2000 src2[i] = ((src2[i] - 128) >> 1) + 128;
2014 for (j = 0; j < 17 + s->
mspel * 2; j++) {
2016 for (i = 0; i < 17 + s->
mspel * 2; i++)
2017 src[i] = luty[f][src[i]];
2022 for (j = 0; j < 9; j++) {
2024 for (i = 0; i < 9; i++) {
2025 src[i] = lutuv[f][src[i]];
2026 src2[i] = lutuv[f][src2[i]];
2039 dxy = ((my & 3) << 2) | (mx & 3);
2046 dxy = (my & 2) | ((mx & 2) >> 1);
2056 uvmx = (uvmx & 3) << 1;
2057 uvmy = (uvmy & 3) << 1;
2071 #if B_FRACTION_DEN==256
2075 return 2 * ((value * n + 255) >> 9);
2076 return (value * n + 128) >> 8;
2089 int direct,
int mode)
2106 int direct,
int mvtype)
2145 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));
2146 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));
2147 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));
2148 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));
2163 if (!s->
mb_x) C[0] = C[1] = 0;
2172 }
else if (s->
mb_x) {
2182 qx = (s->
mb_x << 5);
2183 qy = (s->
mb_y << 5);
2186 if (qx + px < -28) px = -28 - qx;
2187 if (qy + py < -28) py = -28 - qy;
2188 if (qx + px > X) px = X - qx;
2189 if (qy + py > Y) py = Y - qy;
2191 qx = (s->
mb_x << 6);
2192 qy = (s->
mb_y << 6);
2195 if (qx + px < -60) px = -60 - qx;
2196 if (qy + py < -60) py = -60 - qy;
2197 if (qx + px > X) px = X - qx;
2198 if (qy + py > Y) py = Y - qy;
2203 if (is_intra[xy - wrap])
2216 if (is_intra[xy - 2])
2232 s->
mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
2233 s->
mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
2251 }
else if (s->
mb_x) {
2261 qx = (s->
mb_x << 5);
2262 qy = (s->
mb_y << 5);
2265 if (qx + px < -28) px = -28 - qx;
2266 if (qy + py < -28) py = -28 - qy;
2267 if (qx + px > X) px = X - qx;
2268 if (qy + py > Y) py = Y - qy;
2270 qx = (s->
mb_x << 6);
2271 qy = (s->
mb_y << 6);
2274 if (qx + px < -60) px = -60 - qx;
2275 if (qy + py < -60) py = -60 - qy;
2276 if (qx + px > X) px = X - qx;
2277 if (qy + py > Y) py = Y - qy;
2282 if (is_intra[xy - wrap])
2295 if (is_intra[xy - 2])
2312 s->
mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
2313 s->
mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
2328 int total_opp, k, f;
2343 f = (total_opp > 2) ? 1 : 0;
2345 s->
mv[0][0][0] = s->
mv[0][0][1] = 0;
2346 s->
mv[1][0][0] = s->
mv[1][0][1] = 0;
2350 for (k = 0; k < 4; k++) {
2367 if (n == 3 || mv1) {
2372 if (n == 3 || mv1) {
2388 int16_t **dc_val_ptr,
int *dir_ptr)
2392 static const uint16_t dcpred[32] = {
2393 -1, 1024, 512, 341, 256, 205, 171, 146, 128,
2394 114, 102, 93, 85, 79, 73, 68, 64,
2395 60, 57, 54, 51, 49, 47, 45, 43,
2396 41, 39, 38, 37, 35, 34, 33
2410 b = dc_val[ - 1 -
wrap];
2411 a = dc_val[ -
wrap];
2413 if (pq < 9 || !overlap) {
2416 b = a = dcpred[
scale];
2417 if (s->
mb_x == 0 && (n != 1 && n != 3))
2418 b = c = dcpred[
scale];
2423 if (s->
mb_x == 0 && (n != 1 && n != 3))
2427 if (abs(a - b) <= abs(b - c)) {
2436 *dc_val_ptr = &dc_val[0];
2453 int a_avail,
int c_avail,
2454 int16_t **dc_val_ptr,
int *dir_ptr)
2469 b = dc_val[ - 1 -
wrap];
2470 a = dc_val[ -
wrap];
2474 if (dqscale_index < 0)
2476 if (c_avail && (n != 1 && n != 3)) {
2481 if (a_avail && (n != 2 && n != 3)) {
2486 if (a_avail && c_avail && (n != 3)) {
2497 if (a_avail && c_avail) {
2498 if (abs(a - b) <= abs(b - c)) {
2505 }
else if (a_avail) {
2508 }
else if (c_avail) {
2517 *dc_val_ptr = &dc_val[0];
2566 int *
value,
int codingset)
2632 int coded,
int codingset)
2636 int dc_pred_dir = 0;
2639 int16_t *ac_val, *ac_val2;
2653 if (dcdiff == 119 ) {
2656 else if (v->
pq == 2) dcdiff =
get_bits(gb, 9);
2660 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
2661 else if (v->
pq == 2)
2662 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
2687 int last = 0, skip,
value;
2714 block[zz_table[i++]] =
value;
2720 for (k = 1; k < 8; k++)
2723 for (k = 1; k < 8; k++)
2728 for (k = 1; k < 8; k++) {
2734 for (k = 1; k < 64; k++)
2738 block[k] += (block[k] < 0) ? -v->
pq : v->
pq;
2752 memset(ac_val2, 0, 16 * 2);
2756 memcpy(ac_val2, ac_val, 8 * 2);
2760 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
2766 for (k = 1; k < 8; k++) {
2772 for (k = 1; k < 8; k++) {
2795 int coded,
int codingset,
int mquant)
2799 int dc_pred_dir = 0;
2801 int16_t *dc_val = NULL;
2802 int16_t *ac_val, *ac_val2;
2821 if (dcdiff == 119 ) {
2823 if (mquant == 1) dcdiff =
get_bits(gb, 10);
2824 else if (mquant == 2) dcdiff =
get_bits(gb, 9);
2828 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
2829 else if (mquant == 2)
2830 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
2851 if (!a_avail && !c_avail)
2856 scale = mquant * 2 + ((mquant == v->
pq) ? v->
halfpq : 0);
2864 if ( dc_pred_dir && c_avail && mb_pos)
2866 if (!dc_pred_dir && a_avail && mb_pos >= s->
mb_stride)
2868 if ( dc_pred_dir && n == 1)
2870 if (!dc_pred_dir && n == 2)
2876 int last = 0, skip,
value;
2901 block[zz_table[i++]] =
value;
2907 if (q2 && q1 != q2) {
2908 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2909 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2914 for (k = 1; k < 8; k++)
2917 for (k = 1; k < 8; k++)
2922 for (k = 1; k < 8; k++)
2925 for (k = 1; k < 8; k++)
2931 for (k = 1; k < 8; k++) {
2937 for (k = 1; k < 64; k++)
2941 block[k] += (block[k] < 0) ? -mquant : mquant;
2944 if (use_pred) i = 63;
2948 memset(ac_val2, 0, 16 * 2);
2951 memcpy(ac_val2, ac_val, 8 * 2);
2952 if (q2 && q1 != q2) {
2953 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2954 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2957 for (k = 1; k < 8; k++)
2958 ac_val2[k] = (ac_val2[k] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2963 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
2964 if (q2 && q1 != q2) {
2965 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2966 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2969 for (k = 1; k < 8; k++)
2970 ac_val2[k + 8] = (ac_val2[k + 8] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2978 for (k = 1; k < 8; k++) {
2984 for (k = 1; k < 8; k++) {
3007 int coded,
int mquant,
int codingset)
3011 int dc_pred_dir = 0;
3013 int16_t *dc_val = NULL;
3014 int16_t *ac_val, *ac_val2;
3025 mquant = (mquant < 1) ? 0 : ((mquant > 31) ? 31 : mquant);
3042 if (dcdiff == 119 ) {
3044 if (mquant == 1) dcdiff =
get_bits(gb, 10);
3045 else if (mquant == 2) dcdiff =
get_bits(gb, 9);
3049 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
3050 else if (mquant == 2)
3051 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
3058 dcdiff +=
vc1_pred_dc(&v->
s, v->
overlap, mquant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
3073 if (!a_avail) dc_pred_dir = 1;
3074 if (!c_avail) dc_pred_dir = 0;
3075 if (!a_avail && !c_avail) use_pred = 0;
3079 scale = mquant * 2 + v->
halfpq;
3087 if (dc_pred_dir && c_avail && mb_pos)
3089 if (!dc_pred_dir && a_avail && mb_pos >= s->
mb_stride)
3091 if ( dc_pred_dir && n == 1)
3093 if (!dc_pred_dir && n == 2)
3095 if (n == 3) q2 = q1;
3098 int last = 0, skip,
value;
3123 if (q2 && q1 != q2) {
3124 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3125 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3130 for (k = 1; k < 8; k++)
3133 for (k = 1; k < 8; k++)
3138 for (k = 1; k < 8; k++)
3141 for (k = 1; k < 8; k++)
3147 for (k = 1; k < 8; k++) {
3153 for (k = 1; k < 64; k++)
3157 block[k] += (block[k] < 0) ? -mquant : mquant;
3160 if (use_pred) i = 63;
3164 memset(ac_val2, 0, 16 * 2);
3167 memcpy(ac_val2, ac_val, 8 * 2);
3168 if (q2 && q1 != q2) {
3169 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3170 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3173 for (k = 1; k < 8; k++)
3174 ac_val2[k] = (ac_val2[k] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
3179 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
3180 if (q2 && q1 != q2) {
3181 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3182 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3185 for (k = 1; k < 8; k++)
3186 ac_val2[k + 8] = (ac_val2[k + 8] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
3194 for (k = 1; k < 8; k++) {
3200 for (k = 1; k < 8; k++) {
3217 int mquant,
int ttmb,
int first_block,
3218 uint8_t *dst,
int linesize,
int skip_block,
3226 int ttblk = ttmb & 7;
3238 && ((v->
ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
3248 scale = 2 * mquant + ((v->
pq == mquant) ? v->
halfpq : 0);
3273 block[idx] = value *
scale;
3275 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3287 pat = ~subblkpat & 0xF;
3288 for (j = 0; j < 4; j++) {
3289 last = subblkpat & (1 << (3 - j));
3291 off = (j & 1) * 4 + (j & 2) * 16;
3303 block[idx +
off] += (block[idx +
off] < 0) ? -mquant : mquant;
3305 if (!(subblkpat & (1 << (3 - j))) && !skip_block) {
3314 pat = ~((subblkpat & 2) * 6 + (subblkpat & 1) * 3) & 0xF;
3315 for (j = 0; j < 2; j++) {
3316 last = subblkpat & (1 << (1 - j));
3328 block[idx] = value *
scale;
3330 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3332 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
3341 pat = ~(subblkpat * 5) & 0xF;
3342 for (j = 0; j < 2; j++) {
3343 last = subblkpat & (1 << (1 - j));
3355 block[idx] = value *
scale;
3357 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3359 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
3369 *ttmb_out |= ttblk << (n * 4);
3382 block_cbp = mb_cbp >> (block_num * 4), bottom_cbp,
3384 block_is_intra = mb_is_intra >> (block_num * 4), bottom_is_intra;
3388 if (block_num > 3) {
3389 dst = s->
dest[block_num - 3];
3391 dst = s->
dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 8) * linesize;
3397 if (block_num > 3) {
3398 bottom_cbp = v->
cbp[s->
mb_x] >> (block_num * 4);
3399 bottom_is_intra = v->
is_intra[s->
mb_x] >> (block_num * 4);
3403 bottom_cbp = (block_num < 2) ? (mb_cbp >> ((block_num + 2) * 4))
3404 : (v->
cbp[s->
mb_x] >> ((block_num - 2) * 4));
3405 bottom_is_intra = (block_num < 2) ? (mb_is_intra >> ((block_num + 2) * 4))
3411 if (bottom_is_intra & 1 || block_is_intra & 1 ||
3412 mv[0][0] !=
mv[mv_stride][0] ||
mv[0][1] !=
mv[mv_stride][1]) {
3415 idx = ((bottom_cbp >> 2) | block_cbp) & 3;
3427 dst -= 4 * linesize;
3430 idx = (block_cbp | (block_cbp >> 2)) & 3;
3446 block_cbp = mb_cbp >> (block_num * 4), right_cbp,
3448 block_is_intra = mb_is_intra >> (block_num * 4), right_is_intra;
3452 if (block_num > 3) {
3453 dst = s->
dest[block_num - 3] - 8 * linesize;
3455 dst = s->
dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 16) * linesize - 8;
3461 if (block_num > 3) {
3466 right_cbp = (block_num & 1) ? (v->
cbp[s->
mb_x - s->
mb_stride] >> ((block_num - 1) * 4))
3467 : (mb_cbp >> ((block_num + 1) * 4));
3469 : (mb_is_intra >> ((block_num + 1) * 4));
3472 if (block_is_intra & 1 || right_is_intra & 1 ||
mv[0][0] !=
mv[1][0] ||
mv[0][1] !=
mv[1][1]) {
3475 idx = ((right_cbp >> 1) | block_cbp) & 5;
3490 idx = (block_cbp | (block_cbp >> 1)) & 5;
3507 for (i = 0; i < 6; i++) {
3514 for (i = 0; i < 6; i++) {
3520 for (i = 0; i < 6; i++) {
3537 int ttmb = v->
ttfrm;
3539 int mb_has_coeffs = 1;
3543 int first_block = 1;
3545 int skipped, fourmv;
3546 int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
3571 if (s->
mb_intra && !mb_has_coeffs) {
3575 }
else if (mb_has_coeffs) {
3591 for (i = 0; i < 6; i++) {
3594 val = ((cbp >> (5 - i)) & 1);
3595 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3602 if (i == 1 || i == 3 || s->
mb_x)
3611 for (j = 0; j < 64; j++)
3612 s->
block[i][j] <<= 1;
3620 block_cbp |= 0xF << (i << 2);
3621 block_intra |= 1 << i;
3626 block_cbp |= pat << (i << 2);
3627 if (!v->
ttmbf && ttmb < 8)
3634 for (i = 0; i < 6; i++) {
3645 int intra_count = 0, coded_inter = 0;
3646 int is_intra[6], is_coded[6];
3649 for (i = 0; i < 6; i++) {
3650 val = ((cbp >> (5 - i)) & 1);
3665 is_coded[i] = mb_has_coeffs;
3668 is_intra[i] = (intra_count >= 3);
3675 coded_inter = !is_intra[i] & is_coded[i];
3679 if (!intra_count && !coded_inter)
3686 for (i = 0; i < 6; i++)
3699 if (!v->
ttmbf && coded_inter)
3701 for (i = 0; i < 6; i++) {
3703 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3710 if (i == 1 || i == 3 || s->
mb_x)
3719 for (j = 0; j < 64; j++)
3720 s->
block[i][j] <<= 1;
3729 block_cbp |= 0xF << (i << 2);
3730 block_intra |= 1 << i;
3731 }
else if (is_coded[i]) {
3733 first_block, s->
dest[dst_idx] + off,
3737 block_cbp |= pat << (i << 2);
3738 if (!v->
ttmbf && ttmb < 8)
3746 for (i = 0; i < 6; i++) {
3750 for (i = 0; i < 4; i++) {
3776 int ttmb = v->
ttfrm;
3778 int mb_has_coeffs = 1;
3781 int first_block = 1;
3783 int skipped, fourmv = 0, twomv = 0;
3784 int block_cbp = 0, pat, block_tt = 0;
3785 int idx_mbmode = 0, mvbp;
3786 int stride_y, fieldtx;
3830 for (i = 0; i < 4; i++) {
3836 for (i = 0; i < 6; i++)
3849 for (i = 0; i < 6; i++) {
3852 val = ((cbp >> (5 - i)) & 1);
3857 if (i == 1 || i == 3 || s->
mb_x)
3866 off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->
linesize : (i & 1) * 8 + 4 * (i & 2) * s->
linesize;
3888 for (i = 0; i < 6; i++)
3895 for (i = 0; i < 6; i++) {
3898 val = ((mvbp >> (3 - i)) & 1);
3904 }
else if (i == 4) {
3937 if (!v->
ttmbf && cbp)
3939 for (i = 0; i < 6; i++) {
3942 val = ((cbp >> (5 - i)) & 1);
3944 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3946 off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->
linesize));
3949 first_block, s->
dest[dst_idx] + off,
3952 block_cbp |= pat << (i << 2);
3953 if (!v->
ttmbf && ttmb < 8)
3961 for (i = 0; i < 6; i++) {
3987 int ttmb = v->
ttfrm;
3989 int mb_has_coeffs = 1;
3992 int first_block = 1;
3995 int block_cbp = 0, pat, block_tt = 0;
4001 if (idx_mbmode <= 1) {
4012 mb_has_coeffs = idx_mbmode & 1;
4016 for (i = 0; i < 6; i++) {
4020 val = ((cbp >> (5 - i)) & 1);
4024 if (i == 1 || i == 3 || s->
mb_x)
4032 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4040 if (idx_mbmode <= 5) {
4041 dmv_x = dmv_y = pred_flag = 0;
4042 if (idx_mbmode & 1) {
4047 mb_has_coeffs = !(idx_mbmode & 2);
4050 for (i = 0; i < 6; i++) {
4052 dmv_x = dmv_y = pred_flag = 0;
4053 val = ((v->
fourmvbp >> (3 - i)) & 1);
4062 mb_has_coeffs = idx_mbmode & 1;
4070 if (!v->
ttmbf && cbp) {
4074 for (i = 0; i < 6; i++) {
4077 val = ((cbp >> (5 - i)) & 1);
4078 off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->
linesize;
4081 first_block, s->
dest[dst_idx] + off,
4085 block_cbp |= pat << (i << 2);
4086 if (!v->
ttmbf && ttmb < 8) ttmb = -1;
4106 int ttmb = v->
ttfrm;
4107 int mb_has_coeffs = 0;
4110 int first_block = 1;
4112 int skipped, direct;
4113 int dmv_x[2], dmv_y[2];
4128 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
4129 for (i = 0; i < 6; i++) {
4138 dmv_x[1] = dmv_x[0];
4139 dmv_y[1] = dmv_y[0];
4152 dmv_x[0] = dmv_y[0] = 0;
4156 for (i = 0; i < 6; i++)
4163 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4173 dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
4175 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4177 if (!mb_has_coeffs && !s->
mb_intra) {
4180 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4183 if (s->
mb_intra && !mb_has_coeffs) {
4192 if (!mb_has_coeffs) {
4195 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4201 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4213 for (i = 0; i < 6; i++) {
4216 val = ((cbp >> (5 - i)) & 1);
4217 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4224 if (i == 1 || i == 3 || s->
mb_x)
4233 for (j = 0; j < 64; j++)
4234 s->
block[i][j] <<= 1;
4238 first_block, s->
dest[dst_idx] + off,
4241 if (!v->
ttmbf && ttmb < 8)
4258 int ttmb = v->
ttfrm;
4259 int mb_has_coeffs = 0;
4261 int first_block = 1;
4264 int dmv_x[2], dmv_y[2], pred_flag[2];
4272 if (idx_mbmode <= 1) {
4283 mb_has_coeffs = idx_mbmode & 1;
4287 for (i = 0; i < 6; i++) {
4290 val = ((cbp >> (5 - i)) & 1);
4295 if (i == 1 || i == 3 || s->
mb_x)
4304 for (j = 0; j < 64; j++)
4305 s->
block[i][j] <<= 1;
4306 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4318 if (idx_mbmode <= 5) {
4320 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
4321 pred_flag[0] = pred_flag[1] = 0;
4346 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
4347 dmv_x[1] = dmv_y[1] = pred_flag[0] = 0;
4355 mb_has_coeffs = !(idx_mbmode & 2);
4361 for (i = 0; i < 6; i++) {
4363 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
4364 dmv_x[1] = dmv_y[1] = pred_flag[1] = 0;
4365 val = ((v->
fourmvbp >> (3 - i)) & 1);
4376 mb_has_coeffs = idx_mbmode & 1;
4384 if (!v->
ttmbf && cbp) {
4388 for (i = 0; i < 6; i++) {
4391 val = ((cbp >> (5 - i)) & 1);
4392 off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->
linesize;
4395 first_block, s->
dest[dst_idx] + off,
4398 if (!v->
ttmbf && ttmb < 8)
4416 int ttmb = v->
ttfrm;
4418 int mb_has_coeffs = 1;
4421 int first_block = 1;
4423 int skipped, direct, twomv = 0;
4424 int block_cbp = 0, pat, block_tt = 0;
4425 int idx_mbmode = 0, mvbp;
4426 int stride_y, fieldtx;
4472 for (i = 1; i < 4; i += 2) {
4479 for (i = 1; i < 4; i++) {
4489 for (i = 0; i < 4; i++) {
4497 for (i = 0; i < 6; i++)
4510 for (i = 0; i < 6; i++) {
4513 val = ((cbp >> (5 - i)) & 1);
4518 if (i == 1 || i == 3 || s->
mb_x)
4528 off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->
linesize : (i & 1) * 8 + 4 * (i & 2) * s->
linesize;
4568 for (i = 0; i < 6; i++)
4575 for (i = 0; i < 4; i++) {
4587 for (i = 0; i < 4; i++) {
4590 val = ((mvbp >> (3 - i)) & 1);
4633 for (i = 0; i < 2; i++) {
4663 for (i = 0; i < 2; i++) {
4673 if (!v->
ttmbf && cbp)
4675 for (i = 0; i < 6; i++) {
4678 val = ((cbp >> (5 - i)) & 1);
4680 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4682 off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->
linesize));
4685 first_block, s->
dest[dst_idx] + off,
4688 block_cbp |= pat << (i << 2);
4689 if (!v->
ttmbf && ttmb < 8)
4697 for (i = 0; i < 6; i++) {
4719 for (i = 0; i < 2; i++) {
4731 for (i = 0; i < 2; i++) {
4801 dst[0] = s->
dest[0];
4802 dst[1] = dst[0] + 8;
4804 dst[3] = dst[2] + 8;
4805 dst[4] = s->
dest[1];
4806 dst[5] = s->
dest[2];
4818 for (k = 0; k < 6; k++) {
4819 val = ((cbp >> (5 - k)) & 1);
4826 cbp |= val << (5 - k);
4835 for (j = 0; j < 64; j++)
4836 s->
block[k][j] <<= 1;
4840 for (j = 0; j < 64; j++)
4972 for (k = 0; k < 6; k++) {
4973 val = ((cbp >> (5 - k)) & 1);
4980 cbp |= val << (5 - k);
5090 if (apply_loop_filter) {
5226 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
5242 int effect_type, effect_flag;
5243 int effect_pcount1, effect_pcount2;
5244 int effect_params1[15], effect_params2[10];
5252 static void vc1_sprite_parse_transform(
GetBitContext* gb,
int c[7])
5259 c[2] = get_fp_val(gb);
5263 c[0] = c[4] = get_fp_val(gb);
5264 c[2] = get_fp_val(gb);
5267 c[0] = get_fp_val(gb);
5268 c[2] = get_fp_val(gb);
5269 c[4] = get_fp_val(gb);
5272 c[0] = get_fp_val(gb);
5273 c[1] = get_fp_val(gb);
5274 c[2] = get_fp_val(gb);
5275 c[3] = get_fp_val(gb);
5276 c[4] = get_fp_val(gb);
5279 c[5] = get_fp_val(gb);
5281 c[6] = get_fp_val(gb);
5291 for (sprite = 0; sprite <= v->
two_sprites; sprite++) {
5292 vc1_sprite_parse_transform(gb, sd->coefs[sprite]);
5293 if (sd->coefs[sprite][1] || sd->coefs[sprite][3])
5296 for (i = 0; i < 7; i++)
5298 sd->coefs[sprite][i] / (1<<16),
5299 (abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1 << 16));
5305 switch (sd->effect_pcount1 =
get_bits(gb, 4)) {
5307 vc1_sprite_parse_transform(gb, sd->effect_params1);
5310 vc1_sprite_parse_transform(gb, sd->effect_params1);
5311 vc1_sprite_parse_transform(gb, sd->effect_params1 + 7);
5314 for (i = 0; i < sd->effect_pcount1; i++)
5315 sd->effect_params1[i] = get_fp_val(gb);
5317 if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) {
5320 for (i = 0; i < sd->effect_pcount1; i++)
5322 sd->effect_params1[i] / (1 << 16),
5323 (abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1 << 16));
5327 sd->effect_pcount2 =
get_bits(gb, 16);
5328 if (sd->effect_pcount2 > 10) {
5331 }
else if (sd->effect_pcount2) {
5334 while (++i < sd->effect_pcount2) {
5335 sd->effect_params2[i] = get_fp_val(gb);
5337 sd->effect_params2[i] / (1 << 16),
5338 (abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1 << 16));
5357 static void vc1_draw_sprites(
VC1Context *v, SpriteData* sd)
5359 int i, plane, row, sprite;
5360 int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } };
5362 int xoff[2], xadv[2], yoff[2], yadv[2],
alpha;
5367 xoff[i] = av_clip(sd->coefs[i][2], 0, v->
sprite_width-1 << 16);
5368 xadv[i] = sd->coefs[i][0];
5372 yoff[i] = av_clip(sd->coefs[i][5], 0, v->
sprite_height-1 << 16);
5375 alpha = av_clip(sd->coefs[1][6], 0, (1<<16) - 1);
5384 for (sprite = 0; sprite <= v->
two_sprites; sprite++) {
5387 int ycoord = yoff[sprite] + yadv[sprite] * row;
5388 int yline = ycoord >> 16;
5390 ysub[sprite] = ycoord & 0xFFFF;
5396 if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) {
5397 src_h[sprite][0] = iplane + (xoff[sprite] >> 16) + yline * iline;
5399 src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + next_line;
5401 if (sr_cache[sprite][0] != yline) {
5402 if (sr_cache[sprite][1] == yline) {
5404 FFSWAP(
int, sr_cache[sprite][0], sr_cache[sprite][1]);
5406 v->
vc1dsp.
sprite_h(v->
sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width);
5407 sr_cache[sprite][0] = yline;
5410 if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) {
5412 iplane + next_line, xoff[sprite],
5413 xadv[sprite], width);
5414 sr_cache[sprite][1] = yline + 1;
5416 src_h[sprite][0] = v->
sr_rows[sprite][0];
5417 src_h[sprite][1] = v->
sr_rows[sprite][1];
5425 memcpy(dst, src_h[0][0], width);
5428 if (ysub[0] && ysub[1]) {
5430 src_h[1][0], src_h[1][1], ysub[1], alpha, width);
5431 }
else if (ysub[0]) {
5433 src_h[1][0], alpha, width);
5434 }
else if (ysub[1]) {
5436 src_h[0][0], (1<<16)-1-alpha, width);
5461 memset(&sd, 0,
sizeof(sd));
5463 ret = vc1_parse_sprites(v, gb, &sd);
5481 vc1_draw_sprites(v, &sd);
5501 plane ? 128 : 0, f->
linesize[plane]);
5558 for (i = 0; i < 4; i++)
5585 for (i = 0; i < 64; i++) {
5586 #define transpose(x) ((x >> 3) | ((x & 7) << 3))
5653 }
else if (count < 0) {
5660 int size, buf2_size;
5662 int seq_initialized = 0, ep_initialized = 0;
5672 for (; next <
end; start = next) {
5674 size = next - start - 4;
5685 seq_initialized = 1;
5697 if (!seq_initialized || !ep_initialized) {
5756 for (i = 0; i < 4; i++)
5788 int buf_size = avpkt->
size, n_slices = 0, i,
ret;
5793 const uint8_t *buf_start =
buf, *buf_start_second_field = NULL;
5794 int mb_height, n_slices1=-1;
5799 } *slices = NULL, *tmp;
5839 for (start = buf, end = buf + buf_size; next <
end; start = next) {
5841 size = next - start - 4;
5842 if (size <= 0)
continue;
5854 buf_start_second_field =
start;
5855 tmp =
av_realloc(slices,
sizeof(*slices) * (n_slices+1));
5860 if (!slices[n_slices].buf)
5863 slices[n_slices].buf);
5868 slices[n_slices].mby_start = s->
mb_height + 1 >> 1;
5869 n_slices1 = n_slices - 1;
5880 tmp =
av_realloc(slices,
sizeof(*slices) * (n_slices+1));
5885 if (!slices[n_slices].buf)
5888 slices[n_slices].buf);
5891 slices[n_slices].mby_start =
get_bits(&slices[n_slices].gb, 9);
5897 }
else if (v->
interlace && ((buf[0] & 0xC0) == 0xC0)) {
5908 buf_start_second_field = divider;
5909 tmp =
av_realloc(slices,
sizeof(*slices) * (n_slices+1));
5914 if (!slices[n_slices].buf)
5916 buf_size3 =
vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf);
5919 slices[n_slices].mby_start = s->
mb_height + 1 >> 1;
5920 n_slices1 = n_slices - 1;
6045 if ((CONFIG_VC1_VDPAU_DECODER)
6047 if (v->
field_mode && buf_start_second_field) {
6054 if (v->
field_mode && buf_start_second_field) {
6057 if (avctx->
hwaccel->
start_frame(avctx, buf_start, buf_start_second_field - buf_start) < 0)
6059 if (avctx->
hwaccel->
decode_slice(avctx, buf_start, buf_start_second_field - buf_start) < 0)
6065 s->
gb = slices[n_slices1 + 1].gb;
6075 if (avctx->
hwaccel->
start_frame(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field) < 0)
6077 if (avctx->
hwaccel->
decode_slice(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field) < 0)
6095 v->
bits = buf_size * 8;
6108 for (i = 0; i <= n_slices; i++) {
6109 if (i > 0 && slices[i - 1].mby_start >= mb_height) {
6112 "picture boundary (%d >= %d)\n", i,
6113 slices[i - 1].mby_start, mb_height);
6146 s->
start_mb_y = (i == 0) ? 0 :
FFMAX(0, slices[i-1].mby_start % mb_height);
6148 s->
end_mb_y = (i == n_slices ) ? mb_height :
FFMIN(mb_height, slices[i].mby_start % mb_height);
6150 if (i >= n_slices) {
6154 s->
end_mb_y = (i <= n_slices1 + 1) ? mb_height :
FFMIN(mb_height, slices[i].mby_start % mb_height);
6166 s->
gb = slices[i].gb;
6198 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
6199 if (vc1_decode_sprites(v, &s->
gb))
6221 for (i = 0; i < n_slices; i++)
6228 for (i = 0; i < n_slices; i++)
6268 .pix_fmts = vc1_hwaccel_pixfmt_list_420,
6272 #if CONFIG_WMV3_DECODER
6284 .pix_fmts = vc1_hwaccel_pixfmt_list_420,
6289 #if CONFIG_WMV3_VDPAU_DECODER
6290 AVCodec ff_wmv3_vdpau_decoder = {
6291 .
name =
"wmv3_vdpau",
6305 #if CONFIG_VC1_VDPAU_DECODER
6306 AVCodec ff_vc1_vdpau_decoder = {
6307 .
name =
"vc1_vdpau",
6321 #if CONFIG_WMV3IMAGE_DECODER
6322 AVCodec ff_wmv3image_decoder = {
6323 .
name =
"wmv3image",
6332 .
flush = vc1_sprite_flush,
6337 #if CONFIG_VC1IMAGE_DECODER
6338 AVCodec ff_vc1image_decoder = {
6348 .
flush = vc1_sprite_flush,