46 #define MB_INTRA_VLC_BITS 9
52 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;
98 v_dist = (16 - fieldtx) >> (fieldtx == 0);
122 v_dist = fieldtx ? 15 : 8;
144 #define inc_blk_idx(idx) do { \
146 if (idx >= v->n_allocated_blks) \
165 for (j = 0; j < 2; j++) {
198 for (j = 0; j < 2; j++) {
215 for (j = 0; j < 2; j++) {
231 for (j = 0; j < 2; j++) {
242 for (j = 0; j < 2; j++) {
336 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
345 mx = s->
mv[dir][0][0];
346 my = s->
mv[dir][0][1];
354 uvmx = (mx + ((mx & 3) == 3)) >> 1;
355 uvmy = (my + ((my & 3) == 3)) >> 1;
367 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
368 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
401 src_x = s->
mb_x * 16 + (mx >> 2);
402 src_y = s->
mb_y * 16 + (my >> 2);
403 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
404 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
407 src_x = av_clip( src_x, -16, s->
mb_width * 16);
408 src_y = av_clip( src_y, -16, s->
mb_height * 16);
409 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
410 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
418 srcY += src_y * s->
linesize + src_x;
437 || (
unsigned)(src_y - 1) > v_edge_pos - (my&3) - 16 - 3) {
447 uvsrc_x, uvsrc_y, s->
h_edge_pos >> 1, v_edge_pos >> 1);
449 uvsrc_x, uvsrc_y, s->
h_edge_pos >> 1, v_edge_pos >> 1);
458 for (j = 0; j < 17 + s->
mspel * 2; j++) {
459 for (i = 0; i < 17 + s->
mspel * 2; i++)
460 src[i] = ((src[i] - 128) >> 1) + 128;
465 for (j = 0; j < 9; j++) {
466 for (i = 0; i < 9; i++) {
467 src[i] = ((src[i] - 128) >> 1) + 128;
468 src2[i] = ((src2[i] - 128) >> 1) + 128;
480 for (j = 0; j < 17 + s->
mspel * 2; j++) {
481 for (i = 0; i < 17 + s->
mspel * 2; i++)
482 src[i] = v->
luty[src[i]];
487 for (j = 0; j < 9; j++) {
488 for (i = 0; i < 9; i++) {
489 src[i] = v->
lutuv[src[i]];
490 src2[i] = v->
lutuv[src2[i]];
507 dxy = ((my & 3) << 2) | (mx & 3);
514 dxy = (my & 2) | ((mx & 2) >> 1);
523 uvmx = (uvmx & 3) << 1;
524 uvmy = (uvmy & 3) << 1;
537 if (c < d)
return (
FFMIN(b, d) +
FFMAX(a, c)) / 2;
540 if (c < d)
return (
FFMIN(a, d) +
FFMAX(b, c)) / 2;
552 int dxy, mx, my, src_x, src_y;
562 mx = s->
mv[dir][n][0];
563 my = s->
mv[dir][n][1];
585 int same_count = 0, opp_count = 0, k;
586 int chosen_mv[2][4][2], f;
588 for (k = 0; k < 4; k++) {
590 chosen_mv[f][f ? opp_count : same_count][0] = s->
mv[0][k][0];
591 chosen_mv[f][f ? opp_count : same_count][1] = s->
mv[0][k][1];
595 f = opp_count > same_count;
596 switch (f ? opp_count : same_count) {
598 tx =
median4(chosen_mv[f][0][0], chosen_mv[f][1][0],
599 chosen_mv[f][2][0], chosen_mv[f][3][0]);
600 ty =
median4(chosen_mv[f][0][1], chosen_mv[f][1][1],
601 chosen_mv[f][2][1], chosen_mv[f][3][1]);
604 tx =
mid_pred(chosen_mv[f][0][0], chosen_mv[f][1][0], chosen_mv[f][2][0]);
605 ty =
mid_pred(chosen_mv[f][0][1], chosen_mv[f][1][1], chosen_mv[f][2][1]);
608 tx = (chosen_mv[f][0][0] + chosen_mv[f][1][0]) / 2;
609 ty = (chosen_mv[f][0][1] + chosen_mv[f][1][1]) / 2;
616 for (k = 0; k < 4; k++)
624 qx = (s->
mb_x * 16) + (mx >> 2);
625 qy = (s->
mb_y * 8) + (my >> 3);
630 mx -= 4 * (qx -
width);
633 else if (qy > height + 1)
634 my -= 8 * (qy - height - 1);
638 off = ((n > 1) ? s->
linesize : 0) + (n & 1) * 8;
640 off = s->
linesize * 4 * (n & 2) + (n & 1) * 8;
644 src_x = s->
mb_x * 16 + (n & 1) * 8 + (mx >> 2);
646 src_y = s->
mb_y * 16 + (n & 2) * 4 + (my >> 2);
648 src_y = s->
mb_y * 16 + ((n > 1) ? 1 : 0) + (my >> 2);
651 src_x = av_clip(src_x, -16, s->
mb_width * 16);
652 src_y = av_clip(src_y, -16, s->
mb_height * 16);
665 srcY += src_y * s->
linesize + src_x;
669 if (fieldmv && !(src_y & 1))
671 if (fieldmv && (src_y & 1) && src_y < 4)
676 || (
unsigned)(src_y - (s->
mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->
mspel * 2) << fieldmv)) {
680 9 + s->
mspel * 2, (9 + s->
mspel * 2) << fieldmv,
681 src_x - s->
mspel, src_y - (s->
mspel << fieldmv),
690 for (j = 0; j < 9 + s->
mspel * 2; j++) {
691 for (i = 0; i < 9 + s->
mspel * 2; i++)
692 src[i] = ((src[i] - 128) >> 1) + 128;
702 for (j = 0; j < 9 + s->
mspel * 2; j++) {
703 for (i = 0; i < 9 + s->
mspel * 2; i++)
704 src[i] = v->
luty[src[i]];
712 dxy = ((my & 3) << 2) | (mx & 3);
715 dxy = (my & 2) | ((mx & 2) >> 1);
726 static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
728 idx = ((a[3] != flag) << 3)
729 | ((a[2] != flag) << 2)
730 | ((a[1] != flag) << 1)
733 *tx =
median4(mvx[0], mvx[1], mvx[2], mvx[3]);
734 *ty =
median4(mvy[0], mvy[1], mvy[2], mvy[3]);
736 }
else if (count[idx] == 1) {
739 *tx =
mid_pred(mvx[1], mvx[2], mvx[3]);
740 *ty =
mid_pred(mvy[1], mvy[2], mvy[3]);
743 *tx =
mid_pred(mvx[0], mvx[2], mvx[3]);
744 *ty =
mid_pred(mvy[0], mvy[2], mvy[3]);
747 *tx =
mid_pred(mvx[0], mvx[1], mvx[3]);
748 *ty =
mid_pred(mvy[0], mvy[1], mvy[3]);
751 *tx =
mid_pred(mvx[0], mvx[1], mvx[2]);
752 *ty =
mid_pred(mvy[0], mvy[1], mvy[2]);
755 }
else if (count[idx] == 2) {
757 for (i = 0; i < 3; i++)
762 for (i = t1 + 1; i < 4; i++)
767 *tx = (mvx[
t1] + mvx[
t2]) / 2;
768 *ty = (mvy[
t1] + mvy[
t2]) / 2;
783 int uvmx, uvmy, uvsrc_x, uvsrc_y;
784 int k, tx = 0, ty = 0;
785 int mvx[4], mvy[4], intra[4], mv_f[4];
795 for (k = 0; k < 4; k++) {
796 mvx[k] = s->
mv[dir][k][0];
797 mvy[k] = s->
mv[dir][k][1];
815 if (mv_f[0] + mv_f[1] + mv_f[2] + mv_f[3] > 2)
817 valid_count =
get_chroma_mv(mvx, mvy, mv_f, dominant, &tx, &ty);
825 uvmx = (tx + ((tx & 3) == 3)) >> 1;
826 uvmy = (ty + ((ty & 3) == 3)) >> 1;
832 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
833 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
837 uvmy += 2 - 4 * chroma_ref_type;
839 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
840 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
843 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
844 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
875 if (chroma_ref_type) {
884 || (
unsigned)uvsrc_x > (s->
h_edge_pos >> 1) - 9
885 || (
unsigned)uvsrc_y > (v_edge_pos >> 1) - 9) {
887 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
890 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
902 for (j = 0; j < 9; j++) {
903 for (i = 0; i < 9; i++) {
904 src[i] = ((src[i] - 128) >> 1) + 128;
905 src2[i] = ((src2[i] - 128) >> 1) + 128;
918 for (j = 0; j < 9; j++) {
919 for (i = 0; i < 9; i++) {
920 src[i] = v->
lutuv[src[i]];
921 src2[i] = v->
lutuv[src2[i]];
930 uvmx = (uvmx & 3) << 1;
931 uvmy = (uvmy & 3) << 1;
948 int uvsrc_x, uvsrc_y;
949 int uvmx_field[4], uvmy_field[4];
952 static const int s_rndtblfield[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 };
953 int v_dist = fieldmv ? 1 : 4;
961 for (i = 0; i < 4; i++) {
963 uvmx_field[i] = (tx + ((tx & 3) == 3)) >> 1;
966 uvmy_field[i] = (ty >> 4) * 8 + s_rndtblfield[ty & 0xF];
968 uvmy_field[i] = (ty + ((ty & 3) == 3)) >> 1;
971 for (i = 0; i < 4; i++) {
972 off = (i & 1) * 4 + ((i & 2) ? v_dist * s->
uvlinesize : 0);
973 uvsrc_x = s->
mb_x * 8 + (i & 1) * 4 + (uvmx_field[i] >> 2);
974 uvsrc_y = s->
mb_y * 8 + ((i & 2) ? v_dist : 0) + (uvmy_field[i] >> 2);
980 uvmx_field[i] = (uvmx_field[i] & 3) << 1;
981 uvmy_field[i] = (uvmy_field[i] & 3) << 1;
983 if (fieldmv && !(uvsrc_y & 1))
986 if (fieldmv && (uvsrc_y & 1) && uvsrc_y < 2)
989 || s->
h_edge_pos < 10 || v_edge_pos < (5 << fieldmv)
990 || (
unsigned)uvsrc_x > (s->
h_edge_pos >> 1) - 5
991 || (
unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) {
993 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
996 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
1008 for (j = 0; j < 5; j++) {
1009 for (i = 0; i < 5; i++) {
1010 src[i] = v->
lutuv[src[i]];
1011 src2[i] = v->
lutuv[src2[i]];
1039 #define GET_MQUANT() \
1040 if (v->dquantfrm) { \
1042 if (v->dqprofile == DQPROFILE_ALL_MBS) { \
1043 if (v->dqbilevel) { \
1044 mquant = (get_bits1(gb)) ? v->altpq : v->pq; \
1046 mqdiff = get_bits(gb, 3); \
1048 mquant = v->pq + mqdiff; \
1050 mquant = get_bits(gb, 5); \
1053 if (v->dqprofile == DQPROFILE_SINGLE_EDGE) \
1054 edges = 1 << v->dqsbedge; \
1055 else if (v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
1056 edges = (3 << v->dqsbedge) % 15; \
1057 else if (v->dqprofile == DQPROFILE_FOUR_EDGES) \
1059 if ((edges&1) && !s->mb_x) \
1060 mquant = v->altpq; \
1061 if ((edges&2) && s->first_slice_line) \
1062 mquant = v->altpq; \
1063 if ((edges&4) && s->mb_x == (s->mb_width - 1)) \
1064 mquant = v->altpq; \
1065 if ((edges&8) && s->mb_y == (s->mb_height - 1)) \
1066 mquant = v->altpq; \
1067 if (!mquant || mquant > 31) { \
1068 av_log(v->s.avctx, AV_LOG_ERROR, \
1069 "Overriding invalid mquant %d\n", mquant); \
1081 #define GET_MVDATA(_dmv_x, _dmv_y) \
1082 index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table, \
1083 VC1_MV_DIFF_VLC_BITS, 2); \
1085 mb_has_coeffs = 1; \
1088 mb_has_coeffs = 0; \
1091 _dmv_x = _dmv_y = 0; \
1092 } else if (index == 35) { \
1093 _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
1094 _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
1095 } else if (index == 36) { \
1100 index1 = index % 6; \
1101 if (!s->quarter_sample && index1 == 5) val = 1; \
1103 if (size_table[index1] - val > 0) \
1104 val = get_bits(gb, size_table[index1] - val); \
1106 sign = 0 - (val&1); \
1107 _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
1109 index1 = index / 6; \
1110 if (!s->quarter_sample && index1 == 5) val = 1; \
1112 if (size_table[index1] - val > 0) \
1113 val = get_bits(gb, size_table[index1] - val); \
1115 sign = 0 - (val & 1); \
1116 _dmv_y = (sign ^ ((val >> 1) + offset_table[index1])) - sign; \
1120 int *dmv_y,
int *pred_flag)
1123 int extend_x = 0, extend_y = 0;
1127 const int* offs_tab;
1144 extend_x = extend_y = 1;
1153 *pred_flag = *dmv_y & 1;
1154 *dmv_y = (*dmv_y + *pred_flag) >> 1;
1156 *dmv_y = (*dmv_y + (*dmv_y & 1)) >> 1;
1166 index1 = (index + 1) % 9;
1168 val =
get_bits(gb, index1 + extend_x);
1169 sign = 0 -(val & 1);
1170 *dmv_x = (sign ^ ((val >> 1) + offs_tab[index1])) - sign;
1177 index1 = (index + 1) / 9;
1178 if (index1 > v->
numref) {
1180 sign = 0 - (val & 1);
1181 *dmv_y = (sign ^ ((val >> 1) + offs_tab[index1 >> v->
numref])) - sign;
1184 if (v->
numref && pred_flag)
1185 *pred_flag = index1 & 1;
1191 int scaledvalue, refdist;
1192 int scalesame1, scalesame2;
1193 int scalezone1_x, zone1offset_x;
1210 if (
FFABS(n) < scalezone1_x)
1211 scaledvalue = (n * scalesame1) >> 8;
1214 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_x;
1216 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_x;
1224 int scaledvalue, refdist;
1225 int scalesame1, scalesame2;
1226 int scalezone1_y, zone1offset_y;
1243 if (
FFABS(n) < scalezone1_y)
1244 scaledvalue = (n * scalesame1) >> 8;
1247 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_y;
1249 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_y;
1254 return av_clip(scaledvalue, -v->
range_y / 2 + 1, v->
range_y / 2);
1256 return av_clip(scaledvalue, -v->
range_y / 2, v->
range_y / 2 - 1);
1261 int scalezone1_x, zone1offset_x;
1262 int scaleopp1, scaleopp2, brfd;
1274 if (
FFABS(n) < scalezone1_x)
1275 scaledvalue = (n * scaleopp1) >> 8;
1278 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_x;
1280 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_x;
1288 int scalezone1_y, zone1offset_y;
1289 int scaleopp1, scaleopp2, brfd;
1301 if (
FFABS(n) < scalezone1_y)
1302 scaledvalue = (n * scaleopp1) >> 8;
1305 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_y;
1307 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_y;
1311 return av_clip(scaledvalue, -v->
range_y / 2 + 1, v->
range_y / 2);
1313 return av_clip(scaledvalue, -v->
range_y / 2, v->
range_y / 2 - 1);
1320 int brfd, scalesame;
1334 n = (n * scalesame >> 8) << hpel;
1341 int refdist, scaleopp;
1358 n = (n * scaleopp >> 8) << hpel;
1365 int mv1,
int r_x,
int r_y,
uint8_t* is_intra,
1366 int pred_flag,
int dir)
1373 int mixedmv_pic, num_samefield = 0, num_oppfield = 0;
1374 int opposite, a_f, b_f, c_f;
1375 int16_t field_predA[2];
1376 int16_t field_predB[2];
1377 int16_t field_predC[2];
1378 int a_valid, b_valid, c_valid;
1379 int hybridmv_thresh, y_bias = 0;
1427 off = (s->
mb_x > 0) ? -1 : 1;
1442 b_valid = a_valid && (s->
mb_width > 1);
1443 c_valid = s->
mb_x || (n == 1 || n == 3);
1445 a_valid = a_valid && !is_intra[xy -
wrap];
1446 b_valid = b_valid && !is_intra[xy - wrap +
off];
1447 c_valid = c_valid && !is_intra[xy - 1];
1452 num_oppfield += a_f;
1453 num_samefield += 1 - a_f;
1454 field_predA[0] = A[0];
1455 field_predA[1] = A[1];
1457 field_predA[0] = field_predA[1] = 0;
1462 num_oppfield += b_f;
1463 num_samefield += 1 - b_f;
1464 field_predB[0] = B[0];
1465 field_predB[1] = B[1];
1467 field_predB[0] = field_predB[1] = 0;
1472 num_oppfield += c_f;
1473 num_samefield += 1 - c_f;
1474 field_predC[0] = C[0];
1475 field_predC[1] = C[1];
1477 field_predC[0] = field_predC[1] = 0;
1487 if (num_samefield <= num_oppfield)
1488 opposite = 1 - pred_flag;
1490 opposite = pred_flag;
1495 if (a_valid && !a_f) {
1496 field_predA[0] =
scaleforopp(v, field_predA[0], 0, dir);
1497 field_predA[1] =
scaleforopp(v, field_predA[1], 1, dir);
1499 if (b_valid && !b_f) {
1500 field_predB[0] =
scaleforopp(v, field_predB[0], 0, dir);
1501 field_predB[1] =
scaleforopp(v, field_predB[1], 1, dir);
1503 if (c_valid && !c_f) {
1504 field_predC[0] =
scaleforopp(v, field_predC[0], 0, dir);
1505 field_predC[1] =
scaleforopp(v, field_predC[1], 1, dir);
1510 if (a_valid && a_f) {
1511 field_predA[0] =
scaleforsame(v, n, field_predA[0], 0, dir);
1512 field_predA[1] =
scaleforsame(v, n, field_predA[1], 1, dir);
1514 if (b_valid && b_f) {
1515 field_predB[0] =
scaleforsame(v, n, field_predB[0], 0, dir);
1516 field_predB[1] =
scaleforsame(v, n, field_predB[1], 1, dir);
1518 if (c_valid && c_f) {
1519 field_predC[0] =
scaleforsame(v, n, field_predC[0], 0, dir);
1520 field_predC[1] =
scaleforsame(v, n, field_predC[1], 1, dir);
1527 px = field_predA[0];
1528 py = field_predA[1];
1529 }
else if (c_valid) {
1530 px = field_predC[0];
1531 py = field_predC[1];
1532 }
else if (b_valid) {
1533 px = field_predB[0];
1534 py = field_predB[1];
1540 if (num_samefield + num_oppfield > 1) {
1541 px =
mid_pred(field_predA[0], field_predB[0], field_predC[0]);
1542 py =
mid_pred(field_predA[1], field_predB[1], field_predC[1]);
1548 qx = (s->
mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0);
1549 qy = (s->
mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0);
1553 if (qx + px < -60) px = -60 - qx;
1554 if (qy + py < -60) py = -60 - qy;
1556 if (qx + px < -28) px = -28 - qx;
1557 if (qy + py < -28) py = -28 - qy;
1559 if (qx + px > X) px = X - qx;
1560 if (qy + py > Y) py = Y - qy;
1565 hybridmv_thresh = 32;
1566 if (a_valid && c_valid) {
1567 if (is_intra[xy - wrap])
1570 sum =
FFABS(px - field_predA[0]) +
FFABS(py - field_predA[1]);
1571 if (sum > hybridmv_thresh) {
1573 px = field_predA[0];
1574 py = field_predA[1];
1576 px = field_predC[0];
1577 py = field_predC[1];
1580 if (is_intra[xy - 1])
1583 sum =
FFABS(px - field_predC[0]) +
FFABS(py - field_predC[1]);
1584 if (sum > hybridmv_thresh) {
1586 px = field_predA[0];
1587 py = field_predA[1];
1589 px = field_predC[0];
1590 py = field_predC[1];
1619 int mvn,
int r_x,
int r_y,
uint8_t* is_intra)
1623 int A[2],
B[2],
C[2];
1625 int a_valid = 0, b_valid = 0, c_valid = 0;
1626 int field_a, field_b, field_c;
1627 int total_valid, num_samefield, num_oppfield;
1628 int pos_c, pos_b, n_adj;
1656 off = ((n == 0) || (n == 1)) ? 1 : -1;
1658 if (s->
mb_x || (n == 1) || (n == 3)) {
1678 B[0] = B[1] = C[0] = C[1] = 0;
1686 n_adj = (n & 2) | (n & 1);
1740 total_valid = a_valid + b_valid + c_valid;
1742 if (!s->
mb_x && !(n == 1 || n == 3)) {
1747 B[0] = B[1] = C[0] = C[1] = 0;
1754 if (total_valid >= 2) {
1757 }
else if (total_valid) {
1758 if (a_valid) { px = A[0]; py = A[1]; }
1759 if (b_valid) { px = B[0]; py = B[1]; }
1760 if (c_valid) { px = C[0]; py = C[1]; }
1766 field_a = (A[1] & 4) ? 1 : 0;
1770 field_b = (B[1] & 4) ? 1 : 0;
1774 field_c = (C[1] & 4) ? 1 : 0;
1778 num_oppfield = field_a + field_b + field_c;
1779 num_samefield = total_valid - num_oppfield;
1780 if (total_valid == 3) {
1781 if ((num_samefield == 3) || (num_oppfield == 3)) {
1784 }
else if (num_samefield >= num_oppfield) {
1787 px = !field_a ? A[0] : B[0];
1788 py = !field_a ? A[1] : B[1];
1790 px = field_a ? A[0] : B[0];
1791 py = field_a ? A[1] : B[1];
1793 }
else if (total_valid == 2) {
1794 if (num_samefield >= num_oppfield) {
1795 if (!field_a && a_valid) {
1798 }
else if (!field_b && b_valid) {
1801 }
else if (c_valid) {
1806 if (field_a && a_valid) {
1809 }
else if (field_b && b_valid) {
1812 }
else if (c_valid) {
1817 }
else if (total_valid == 1) {
1818 px = (a_valid) ? A[0] : ((b_valid) ? B[0] : C[0]);
1819 py = (a_valid) ? A[1] : ((b_valid) ? B[1] : C[1]);
1834 }
else if (mvn == 2) {
1837 s->
mv[0][n + 1][0] = s->
mv[0][n][0];
1838 s->
mv[0][n + 1][1] = s->
mv[0][n][1];
1849 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
1856 mx = s->
mv[1][0][0];
1857 my = s->
mv[1][0][1];
1858 uvmx = (mx + ((mx & 3) == 3)) >> 1;
1859 uvmy = (my + ((my & 3) == 3)) >> 1;
1866 uvmx = uvmx + ((uvmx < 0) ? -(uvmx & 1) : (uvmx & 1));
1867 uvmy = uvmy + ((uvmy < 0) ? -(uvmy & 1) : (uvmy & 1));
1873 src_x = s->
mb_x * 16 + (mx >> 2);
1874 src_y = s->
mb_y * 16 + (my >> 2);
1875 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
1876 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
1879 src_x = av_clip( src_x, -16, s->
mb_width * 16);
1880 src_y = av_clip( src_y, -16, s->
mb_height * 16);
1881 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
1882 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
1890 srcY += src_y * s->
linesize + src_x;
1907 || (
unsigned)(src_x - 1) > s->
h_edge_pos - (mx & 3) - 16 - 3
1908 || (
unsigned)(src_y - 1) > v_edge_pos - (my & 3) - 16 - 3) {
1918 uvsrc_x, uvsrc_y, s->
h_edge_pos >> 1, v_edge_pos >> 1);
1920 uvsrc_x, uvsrc_y, s->
h_edge_pos >> 1, v_edge_pos >> 1);
1929 for (j = 0; j < 17 + s->
mspel * 2; j++) {
1930 for (i = 0; i < 17 + s->
mspel * 2; i++)
1931 src[i] = ((src[i] - 128) >> 1) + 128;
1936 for (j = 0; j < 9; j++) {
1937 for (i = 0; i < 9; i++) {
1938 src[i] = ((src[i] - 128) >> 1) + 128;
1939 src2[i] = ((src2[i] - 128) >> 1) + 128;
1957 dxy = ((my & 3) << 2) | (mx & 3);
1964 dxy = (my & 2) | ((mx & 2) >> 1);
1974 uvmx = (uvmx & 3) << 1;
1975 uvmy = (uvmy & 3) << 1;
1989 #if B_FRACTION_DEN==256
1993 return 2 * ((value * n + 255) >> 9);
1994 return (value * n + 128) >> 8;
2007 int direct,
int mode)
2036 int direct,
int mvtype)
2071 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));
2072 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));
2073 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));
2074 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));
2090 if (!s->
mb_x) C[0] = C[1] = 0;
2099 }
else if (s->
mb_x) {
2109 qx = (s->
mb_x << 5);
2110 qy = (s->
mb_y << 5);
2113 if (qx + px < -28) px = -28 - qx;
2114 if (qy + py < -28) py = -28 - qy;
2115 if (qx + px > X) px = X - qx;
2116 if (qy + py > Y) py = Y - qy;
2118 qx = (s->
mb_x << 6);
2119 qy = (s->
mb_y << 6);
2122 if (qx + px < -60) px = -60 - qx;
2123 if (qy + py < -60) py = -60 - qy;
2124 if (qx + px > X) px = X - qx;
2125 if (qy + py > Y) py = Y - qy;
2130 if (is_intra[xy - wrap])
2143 if (is_intra[xy - 2])
2159 s->
mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
2160 s->
mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
2178 }
else if (s->
mb_x) {
2188 qx = (s->
mb_x << 5);
2189 qy = (s->
mb_y << 5);
2192 if (qx + px < -28) px = -28 - qx;
2193 if (qy + py < -28) py = -28 - qy;
2194 if (qx + px > X) px = X - qx;
2195 if (qy + py > Y) py = Y - qy;
2197 qx = (s->
mb_x << 6);
2198 qy = (s->
mb_y << 6);
2201 if (qx + px < -60) px = -60 - qx;
2202 if (qy + py < -60) py = -60 - qy;
2203 if (qx + px > X) px = X - qx;
2204 if (qy + py > Y) py = Y - qy;
2209 if (is_intra[xy - wrap])
2222 if (is_intra[xy - 2])
2239 s->
mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
2240 s->
mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
2255 int total_opp, k, f;
2270 f = (total_opp > 2) ? 1 : 0;
2272 s->
mv[0][0][0] = s->
mv[0][0][1] = 0;
2273 s->
mv[1][0][0] = s->
mv[1][0][1] = 0;
2277 for (k = 0; k < 4; k++) {
2294 if (n == 3 || mv1) {
2299 if (n == 3 || mv1) {
2315 int16_t **dc_val_ptr,
int *dir_ptr)
2319 static const uint16_t dcpred[32] = {
2320 -1, 1024, 512, 341, 256, 205, 171, 146, 128,
2321 114, 102, 93, 85, 79, 73, 68, 64,
2322 60, 57, 54, 51, 49, 47, 45, 43,
2323 41, 39, 38, 37, 35, 34, 33
2337 b = dc_val[ - 1 -
wrap];
2338 a = dc_val[ -
wrap];
2340 if (pq < 9 || !overlap) {
2343 b = a = dcpred[
scale];
2344 if (s->
mb_x == 0 && (n != 1 && n != 3))
2345 b = c = dcpred[
scale];
2350 if (s->
mb_x == 0 && (n != 1 && n != 3))
2354 if (abs(a - b) <= abs(b - c)) {
2363 *dc_val_ptr = &dc_val[0];
2380 int a_avail,
int c_avail,
2381 int16_t **dc_val_ptr,
int *dir_ptr)
2396 b = dc_val[ - 1 -
wrap];
2397 a = dc_val[ -
wrap];
2401 if (dqscale_index < 0)
2403 if (c_avail && (n != 1 && n != 3)) {
2408 if (a_avail && (n != 2 && n != 3)) {
2413 if (a_avail && c_avail && (n != 3)) {
2424 if (a_avail && c_avail) {
2425 if (abs(a - b) <= abs(b - c)) {
2432 }
else if (a_avail) {
2435 }
else if (c_avail) {
2444 *dc_val_ptr = &dc_val[0];
2493 int *
value,
int codingset)
2559 int coded,
int codingset)
2563 int dc_pred_dir = 0;
2566 int16_t *ac_val, *ac_val2;
2580 if (dcdiff == 119 ) {
2583 else if (v->
pq == 2) dcdiff =
get_bits(gb, 9);
2587 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
2588 else if (v->
pq == 2)
2589 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
2614 int last = 0, skip,
value;
2641 block[zz_table[i++]] =
value;
2647 for (k = 1; k < 8; k++)
2650 for (k = 1; k < 8; k++)
2655 for (k = 1; k < 8; k++) {
2661 for (k = 1; k < 64; k++)
2665 block[k] += (block[k] < 0) ? -v->
pq : v->
pq;
2679 memset(ac_val2, 0, 16 * 2);
2683 memcpy(ac_val2, ac_val, 8 * 2);
2687 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
2693 for (k = 1; k < 8; k++) {
2699 for (k = 1; k < 8; k++) {
2722 int coded,
int codingset,
int mquant)
2726 int dc_pred_dir = 0;
2729 int16_t *ac_val, *ac_val2;
2748 if (dcdiff == 119 ) {
2750 if (mquant == 1) dcdiff =
get_bits(gb, 10);
2751 else if (mquant == 2) dcdiff =
get_bits(gb, 9);
2755 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
2756 else if (mquant == 2)
2757 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
2778 if (!a_avail && !c_avail)
2783 scale = mquant * 2 + ((mquant == v->
pq) ? v->
halfpq : 0);
2791 if ( dc_pred_dir && c_avail && mb_pos)
2793 if (!dc_pred_dir && a_avail && mb_pos >= s->
mb_stride)
2795 if ( dc_pred_dir && n == 1)
2797 if (!dc_pred_dir && n == 2)
2803 int last = 0, skip,
value;
2828 block[zz_table[i++]] =
value;
2834 if (q2 && q1 != q2) {
2835 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2836 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2841 for (k = 1; k < 8; k++)
2844 for (k = 1; k < 8; k++)
2849 for (k = 1; k < 8; k++)
2852 for (k = 1; k < 8; k++)
2858 for (k = 1; k < 8; k++) {
2864 for (k = 1; k < 64; k++)
2868 block[k] += (block[k] < 0) ? -mquant : mquant;
2871 if (use_pred) i = 63;
2875 memset(ac_val2, 0, 16 * 2);
2878 memcpy(ac_val2, ac_val, 8 * 2);
2879 if (q2 && q1 != q2) {
2880 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2881 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2884 for (k = 1; k < 8; k++)
2885 ac_val2[k] = (ac_val2[k] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2890 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
2891 if (q2 && q1 != q2) {
2892 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2893 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2896 for (k = 1; k < 8; k++)
2897 ac_val2[k + 8] = (ac_val2[k + 8] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2905 for (k = 1; k < 8; k++) {
2911 for (k = 1; k < 8; k++) {
2934 int coded,
int mquant,
int codingset)
2938 int dc_pred_dir = 0;
2941 int16_t *ac_val, *ac_val2;
2952 mquant = (mquant < 1) ? 0 : ((mquant > 31) ? 31 : mquant);
2969 if (dcdiff == 119 ) {
2971 if (mquant == 1) dcdiff =
get_bits(gb, 10);
2972 else if (mquant == 2) dcdiff =
get_bits(gb, 9);
2976 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
2977 else if (mquant == 2)
2978 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
2985 dcdiff +=
vc1_pred_dc(&v->
s, v->
overlap, mquant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
3000 if (!a_avail) dc_pred_dir = 1;
3001 if (!c_avail) dc_pred_dir = 0;
3002 if (!a_avail && !c_avail) use_pred = 0;
3006 scale = mquant * 2 + v->
halfpq;
3014 if (dc_pred_dir && c_avail && mb_pos)
3016 if (!dc_pred_dir && a_avail && mb_pos >= s->
mb_stride)
3018 if ( dc_pred_dir && n == 1)
3020 if (!dc_pred_dir && n == 2)
3022 if (n == 3) q2 = q1;
3025 int last = 0, skip,
value;
3050 if (q2 && q1 != q2) {
3051 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3052 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3057 for (k = 1; k < 8; k++)
3060 for (k = 1; k < 8; k++)
3065 for (k = 1; k < 8; k++)
3068 for (k = 1; k < 8; k++)
3074 for (k = 1; k < 8; k++) {
3080 for (k = 1; k < 64; k++)
3084 block[k] += (block[k] < 0) ? -mquant : mquant;
3087 if (use_pred) i = 63;
3091 memset(ac_val2, 0, 16 * 2);
3094 memcpy(ac_val2, ac_val, 8 * 2);
3095 if (q2 && q1 != q2) {
3096 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3097 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3100 for (k = 1; k < 8; k++)
3101 ac_val2[k] = (ac_val2[k] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
3106 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
3107 if (q2 && q1 != q2) {
3108 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3109 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3112 for (k = 1; k < 8; k++)
3113 ac_val2[k + 8] = (ac_val2[k + 8] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
3121 for (k = 1; k < 8; k++) {
3127 for (k = 1; k < 8; k++) {
3144 int mquant,
int ttmb,
int first_block,
3153 int ttblk = ttmb & 7;
3165 && ((v->
ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
3175 scale = 2 * mquant + ((v->
pq == mquant) ? v->
halfpq : 0);
3200 block[idx] = value *
scale;
3202 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3214 pat = ~subblkpat & 0xF;
3215 for (j = 0; j < 4; j++) {
3216 last = subblkpat & (1 << (3 - j));
3218 off = (j & 1) * 4 + (j & 2) * 16;
3230 block[idx +
off] += (block[idx +
off] < 0) ? -mquant : mquant;
3232 if (!(subblkpat & (1 << (3 - j))) && !skip_block) {
3241 pat = ~((subblkpat & 2) * 6 + (subblkpat & 1) * 3) & 0xF;
3242 for (j = 0; j < 2; j++) {
3243 last = subblkpat & (1 << (1 - j));
3255 block[idx] = value *
scale;
3257 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3259 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
3268 pat = ~(subblkpat * 5) & 0xF;
3269 for (j = 0; j < 2; j++) {
3270 last = subblkpat & (1 << (1 - j));
3282 block[idx] = value *
scale;
3284 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3286 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
3296 *ttmb_out |= ttblk << (n * 4);
3309 block_cbp = mb_cbp >> (block_num * 4), bottom_cbp,
3311 block_is_intra = mb_is_intra >> (block_num * 4), bottom_is_intra;
3315 if (block_num > 3) {
3316 dst = s->
dest[block_num - 3];
3318 dst = s->
dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 8) * linesize;
3324 if (block_num > 3) {
3325 bottom_cbp = v->
cbp[s->
mb_x] >> (block_num * 4);
3326 bottom_is_intra = v->
is_intra[s->
mb_x] >> (block_num * 4);
3330 bottom_cbp = (block_num < 2) ? (mb_cbp >> ((block_num + 2) * 4))
3331 : (v->
cbp[s->
mb_x] >> ((block_num - 2) * 4));
3332 bottom_is_intra = (block_num < 2) ? (mb_is_intra >> ((block_num + 2) * 4))
3338 if (bottom_is_intra & 1 || block_is_intra & 1 ||
3339 mv[0][0] !=
mv[mv_stride][0] ||
mv[0][1] !=
mv[mv_stride][1]) {
3342 idx = ((bottom_cbp >> 2) | block_cbp) & 3;
3354 dst -= 4 * linesize;
3357 idx = (block_cbp | (block_cbp >> 2)) & 3;
3373 block_cbp = mb_cbp >> (block_num * 4), right_cbp,
3375 block_is_intra = mb_is_intra >> (block_num * 4), right_is_intra;
3379 if (block_num > 3) {
3380 dst = s->
dest[block_num - 3] - 8 * linesize;
3382 dst = s->
dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 16) * linesize - 8;
3388 if (block_num > 3) {
3393 right_cbp = (block_num & 1) ? (v->
cbp[s->
mb_x - s->
mb_stride] >> ((block_num - 1) * 4))
3394 : (mb_cbp >> ((block_num + 1) * 4));
3396 : (mb_is_intra >> ((block_num + 1) * 4));
3399 if (block_is_intra & 1 || right_is_intra & 1 ||
mv[0][0] !=
mv[1][0] ||
mv[0][1] !=
mv[1][1]) {
3402 idx = ((right_cbp >> 1) | block_cbp) & 5;
3417 idx = (block_cbp | (block_cbp >> 1)) & 5;
3434 for (i = 0; i < 6; i++) {
3441 for (i = 0; i < 6; i++) {
3447 for (i = 0; i < 6; i++) {
3464 int ttmb = v->
ttfrm;
3466 int mb_has_coeffs = 1;
3470 int first_block = 1;
3472 int skipped, fourmv;
3473 int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
3498 if (s->
mb_intra && !mb_has_coeffs) {
3502 }
else if (mb_has_coeffs) {
3518 for (i = 0; i < 6; i++) {
3521 val = ((cbp >> (5 - i)) & 1);
3522 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3529 if (i == 1 || i == 3 || s->
mb_x)
3538 for (j = 0; j < 64; j++)
3539 s->
block[i][j] <<= 1;
3547 block_cbp |= 0xF << (i << 2);
3548 block_intra |= 1 << i;
3553 block_cbp |= pat << (i << 2);
3554 if (!v->
ttmbf && ttmb < 8)
3561 for (i = 0; i < 6; i++) {
3572 int intra_count = 0, coded_inter = 0;
3573 int is_intra[6], is_coded[6];
3576 for (i = 0; i < 6; i++) {
3577 val = ((cbp >> (5 - i)) & 1);
3592 is_coded[i] = mb_has_coeffs;
3595 is_intra[i] = (intra_count >= 3);
3602 coded_inter = !is_intra[i] & is_coded[i];
3606 if (!intra_count && !coded_inter)
3613 for (i = 0; i < 6; i++)
3626 if (!v->
ttmbf && coded_inter)
3628 for (i = 0; i < 6; i++) {
3630 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3637 if (i == 1 || i == 3 || s->
mb_x)
3646 for (j = 0; j < 64; j++)
3647 s->
block[i][j] <<= 1;
3656 block_cbp |= 0xF << (i << 2);
3657 block_intra |= 1 << i;
3658 }
else if (is_coded[i]) {
3660 first_block, s->
dest[dst_idx] + off,
3664 block_cbp |= pat << (i << 2);
3665 if (!v->
ttmbf && ttmb < 8)
3673 for (i = 0; i < 6; i++) {
3677 for (i = 0; i < 4; i++) {
3703 int ttmb = v->
ttfrm;
3705 int mb_has_coeffs = 1;
3708 int first_block = 1;
3710 int skipped, fourmv = 0, twomv = 0;
3711 int block_cbp = 0, pat, block_tt = 0;
3712 int idx_mbmode = 0, mvbp;
3713 int stride_y, fieldtx;
3761 for (i = 0; i < 6; i++)
3774 for (i = 0; i < 6; i++) {
3777 val = ((cbp >> (5 - i)) & 1);
3782 if (i == 1 || i == 3 || s->
mb_x)
3791 off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->
linesize : (i & 1) * 8 + 4 * (i & 2) * s->
linesize;
3813 for (i = 0; i < 6; i++)
3820 for (i = 0; i < 6; i++) {
3823 val = ((mvbp >> (3 - i)) & 1);
3829 }
else if (i == 4) {
3862 if (!v->
ttmbf && cbp)
3864 for (i = 0; i < 6; i++) {
3867 val = ((cbp >> (5 - i)) & 1);
3869 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3871 off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->
linesize));
3874 first_block, s->
dest[dst_idx] + off,
3877 block_cbp |= pat << (i << 2);
3878 if (!v->
ttmbf && ttmb < 8)
3886 for (i = 0; i < 6; i++) {
3912 int ttmb = v->
ttfrm;
3914 int mb_has_coeffs = 1;
3917 int first_block = 1;
3920 int block_cbp = 0, pat, block_tt = 0;
3926 if (idx_mbmode <= 1) {
3937 mb_has_coeffs = idx_mbmode & 1;
3941 for (i = 0; i < 6; i++) {
3945 val = ((cbp >> (5 - i)) & 1);
3949 if (i == 1 || i == 3 || s->
mb_x)
3957 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3966 if (idx_mbmode <= 5) {
3967 dmv_x = dmv_y = pred_flag = 0;
3968 if (idx_mbmode & 1) {
3973 mb_has_coeffs = !(idx_mbmode & 2);
3976 for (i = 0; i < 6; i++) {
3978 dmv_x = dmv_y = pred_flag = 0;
3979 val = ((v->
fourmvbp >> (3 - i)) & 1);
3988 mb_has_coeffs = idx_mbmode & 1;
3996 if (!v->
ttmbf && cbp) {
4000 for (i = 0; i < 6; i++) {
4003 val = ((cbp >> (5 - i)) & 1);
4004 off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->
linesize;
4009 first_block, s->
dest[dst_idx] + off,
4013 block_cbp |= pat << (i << 2);
4014 if (!v->
ttmbf && ttmb < 8) ttmb = -1;
4034 int ttmb = v->
ttfrm;
4035 int mb_has_coeffs = 0;
4038 int first_block = 1;
4040 int skipped, direct;
4041 int dmv_x[2], dmv_y[2];
4056 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
4057 for (i = 0; i < 6; i++) {
4066 dmv_x[1] = dmv_x[0];
4067 dmv_y[1] = dmv_y[0];
4080 dmv_x[0] = dmv_y[0] = 0;
4084 for (i = 0; i < 6; i++)
4091 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4101 dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
4103 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4105 if (!mb_has_coeffs && !s->
mb_intra) {
4108 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4111 if (s->
mb_intra && !mb_has_coeffs) {
4120 if (!mb_has_coeffs) {
4123 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4129 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4141 for (i = 0; i < 6; i++) {
4144 val = ((cbp >> (5 - i)) & 1);
4145 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4152 if (i == 1 || i == 3 || s->
mb_x)
4161 for (j = 0; j < 64; j++)
4162 s->
block[i][j] <<= 1;
4166 first_block, s->
dest[dst_idx] + off,
4169 if (!v->
ttmbf && ttmb < 8)
4186 int ttmb = v->
ttfrm;
4187 int mb_has_coeffs = 0;
4189 int first_block = 1;
4192 int dmv_x[2], dmv_y[2], pred_flag[2];
4194 int idx_mbmode, interpmvp;
4200 if (idx_mbmode <= 1) {
4211 mb_has_coeffs = idx_mbmode & 1;
4215 for (i = 0; i < 6; i++) {
4218 val = ((cbp >> (5 - i)) & 1);
4223 if (i == 1 || i == 3 || s->
mb_x)
4232 for (j = 0; j < 64; j++)
4233 s->
block[i][j] <<= 1;
4234 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4247 if (idx_mbmode <= 5) {
4248 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
4249 pred_flag[0] = pred_flag[1] = 0;
4274 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
4275 dmv_x[1] = dmv_y[1] = pred_flag[0] = 0;
4279 mb_has_coeffs = !(idx_mbmode & 2);
4285 for (i = 0; i < 6; i++) {
4287 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
4288 dmv_x[1] = dmv_y[1] = pred_flag[1] = 0;
4289 val = ((v->
fourmvbp >> (3 - i)) & 1);
4300 mb_has_coeffs = idx_mbmode & 1;
4308 if (!v->
ttmbf && cbp) {
4312 for (i = 0; i < 6; i++) {
4315 val = ((cbp >> (5 - i)) & 1);
4316 off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->
linesize;
4321 first_block, s->
dest[dst_idx] + off,
4324 if (!v->
ttmbf && ttmb < 8)
4381 dst[0] = s->
dest[0];
4382 dst[1] = dst[0] + 8;
4384 dst[3] = dst[2] + 8;
4385 dst[4] = s->
dest[1];
4386 dst[5] = s->
dest[2];
4398 for (k = 0; k < 6; k++) {
4399 val = ((cbp >> (5 - k)) & 1);
4406 cbp |= val << (5 - k);
4415 for (j = 0; j < 64; j++)
4416 s->
block[k][j] <<= 1;
4420 for (j = 0; j < 64; j++)
4552 for (k = 0; k < 6; k++) {
4553 val = ((cbp >> (5 - k)) & 1);
4560 cbp |= val << (5 - k);
4801 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
4817 int effect_type, effect_flag;
4818 int effect_pcount1, effect_pcount2;
4819 int effect_params1[15], effect_params2[10];
4827 static void vc1_sprite_parse_transform(
GetBitContext* gb,
int c[7])
4834 c[2] = get_fp_val(gb);
4838 c[0] = c[4] = get_fp_val(gb);
4839 c[2] = get_fp_val(gb);
4842 c[0] = get_fp_val(gb);
4843 c[2] = get_fp_val(gb);
4844 c[4] = get_fp_val(gb);
4847 c[0] = get_fp_val(gb);
4848 c[1] = get_fp_val(gb);
4849 c[2] = get_fp_val(gb);
4850 c[3] = get_fp_val(gb);
4851 c[4] = get_fp_val(gb);
4854 c[5] = get_fp_val(gb);
4856 c[6] = get_fp_val(gb);
4866 for (sprite = 0; sprite <= v->
two_sprites; sprite++) {
4867 vc1_sprite_parse_transform(gb, sd->coefs[sprite]);
4868 if (sd->coefs[sprite][1] || sd->coefs[sprite][3])
4871 for (i = 0; i < 7; i++)
4873 sd->coefs[sprite][i] / (1<<16),
4874 (abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1 << 16));
4880 switch (sd->effect_pcount1 =
get_bits(gb, 4)) {
4882 vc1_sprite_parse_transform(gb, sd->effect_params1);
4885 vc1_sprite_parse_transform(gb, sd->effect_params1);
4886 vc1_sprite_parse_transform(gb, sd->effect_params1 + 7);
4889 for (i = 0; i < sd->effect_pcount1; i++)
4890 sd->effect_params1[i] = get_fp_val(gb);
4892 if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) {
4895 for (i = 0; i < sd->effect_pcount1; i++)
4897 sd->effect_params1[i] / (1 << 16),
4898 (abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1 << 16));
4902 sd->effect_pcount2 =
get_bits(gb, 16);
4903 if (sd->effect_pcount2 > 10) {
4906 }
else if (sd->effect_pcount2) {
4909 while (++i < sd->effect_pcount2) {
4910 sd->effect_params2[i] = get_fp_val(gb);
4912 sd->effect_params2[i] / (1 << 16),
4913 (abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1 << 16));
4928 static void vc1_draw_sprites(
VC1Context *v, SpriteData* sd)
4930 int i, plane, row, sprite;
4931 int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } };
4933 int xoff[2], xadv[2], yoff[2], yadv[2], alpha;
4937 for (i = 0; i < 2; i++) {
4938 xoff[i] = av_clip(sd->coefs[i][2], 0, v->
sprite_width-1 << 16);
4939 xadv[i] = sd->coefs[i][0];
4943 yoff[i] = av_clip(sd->coefs[i][5], 0, v->
sprite_height-1 << 16);
4946 alpha = av_clip(sd->coefs[1][6], 0, (1<<16) - 1);
4955 for (sprite = 0; sprite <= v->
two_sprites; sprite++) {
4958 int ycoord = yoff[sprite] + yadv[sprite] * row;
4959 int yline = ycoord >> 16;
4961 ysub[sprite] = ycoord & 0xFFFF;
4967 if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) {
4968 src_h[sprite][0] = iplane + (xoff[sprite] >> 16) + yline * iline;
4970 src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + next_line;
4972 if (sr_cache[sprite][0] != yline) {
4973 if (sr_cache[sprite][1] == yline) {
4975 FFSWAP(
int, sr_cache[sprite][0], sr_cache[sprite][1]);
4977 v->
vc1dsp.
sprite_h(v->
sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width);
4978 sr_cache[sprite][0] = yline;
4981 if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) {
4983 iplane + next_line, xoff[sprite],
4984 xadv[sprite], width);
4985 sr_cache[sprite][1] = yline + 1;
4987 src_h[sprite][0] = v->
sr_rows[sprite][0];
4988 src_h[sprite][1] = v->
sr_rows[sprite][1];
4996 memcpy(dst, src_h[0][0], width);
4999 if (ysub[0] && ysub[1]) {
5001 src_h[1][0], src_h[1][1], ysub[1], alpha, width);
5002 }
else if (ysub[0]) {
5004 src_h[1][0], alpha, width);
5005 }
else if (ysub[1]) {
5007 src_h[0][0], (1<<16)-1-alpha, width);
5015 for (i = 0; i < 2; i++) {
5031 vc1_parse_sprites(v, gb, &sd);
5053 vc1_draw_sprites(v, &sd);
5073 plane ? 128 : 0, f->
linesize[plane]);
5132 for (i = 0; i < 4; i++)
5147 for (i = 0; i < 64; i++) {
5148 #define transpose(x) ((x >> 3) | ((x & 7) << 3))
5218 }
else if (count < 0) {
5225 int size, buf2_size;
5227 int seq_initialized = 0, ep_initialized = 0;
5237 for (; next <
end; start = next) {
5239 size = next - start - 4;
5250 seq_initialized = 1;
5262 if (!seq_initialized || !ep_initialized) {
5313 for (i = 0; i < 4; i++)
5346 int buf_size = avpkt->
size, n_slices = 0, i;
5351 const uint8_t *buf_start = buf, *buf_start_second_field =
NULL;
5352 int mb_height, n_slices1=-1;
5357 } *slices =
NULL, *tmp;
5394 for (start = buf, end = buf + buf_size; next <
end; start = next) {
5396 size = next - start - 4;
5397 if (size <= 0)
continue;
5409 buf_start_second_field = start;
5410 tmp =
av_realloc(slices,
sizeof(*slices) * (n_slices+1));
5415 if (!slices[n_slices].buf)
5418 slices[n_slices].buf);
5423 slices[n_slices].mby_start = s->
mb_height >> 1;
5424 n_slices1 = n_slices - 1;
5435 tmp =
av_realloc(slices,
sizeof(*slices) * (n_slices+1));
5440 if (!slices[n_slices].buf)
5443 slices[n_slices].buf);
5446 slices[n_slices].mby_start =
get_bits(&slices[n_slices].gb, 9);
5452 }
else if (v->
interlace && ((buf[0] & 0xC0) == 0xC0)) {
5463 buf_start_second_field = divider;
5464 tmp =
av_realloc(slices,
sizeof(*slices) * (n_slices+1));
5469 if (!slices[n_slices].buf)
5471 buf_size3 =
vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf);
5474 slices[n_slices].mby_start = s->
mb_height >> 1;
5475 n_slices1 = n_slices - 1;
5604 if ((CONFIG_VC1_VDPAU_DECODER)
5608 if (v->
field_mode && buf_start_second_field) {
5611 if (avctx->
hwaccel->
start_frame(avctx, buf_start, buf_start_second_field - buf_start) < 0)
5613 if (avctx->
hwaccel->
decode_slice(avctx, buf_start, buf_start_second_field - buf_start) < 0)
5619 s->
gb = slices[n_slices1 + 1].gb;
5629 if (avctx->
hwaccel->
start_frame(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field) < 0)
5631 if (avctx->
hwaccel->
decode_slice(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field) < 0)
5650 v->
bits = buf_size * 8;
5665 v->
mv_f[0] = tmp[0];
5666 v->
mv_f[1] = tmp[1];
5669 for (i = 0; i <= n_slices; i++) {
5670 if (i > 0 && slices[i - 1].mby_start >= mb_height) {
5673 "picture boundary (%d >= %d)\n", i,
5674 slices[i - 1].mby_start, mb_height);
5700 s->
start_mb_y = (i == 0) ? 0 :
FFMAX(0, slices[i-1].mby_start % mb_height);
5702 s->
end_mb_y = (i == n_slices ) ? mb_height :
FFMIN(mb_height, slices[i].mby_start % mb_height);
5704 if (i >= n_slices) {
5708 s->
end_mb_y = (i <= n_slices1 + 1) ? mb_height :
FFMIN(mb_height, slices[i].mby_start % mb_height);
5716 s->
gb = slices[i].gb;
5748 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
5749 if (vc1_decode_sprites(v, &s->
gb))
5768 for (i = 0; i < n_slices; i++)
5775 for (i = 0; i < n_slices; i++)
5805 #if CONFIG_WMV3_DECODER
5822 #if CONFIG_WMV3_VDPAU_DECODER
5823 AVCodec ff_wmv3_vdpau_decoder = {
5824 .
name =
"wmv3_vdpau",
5838 #if CONFIG_VC1_VDPAU_DECODER
5839 AVCodec ff_vc1_vdpau_decoder = {
5840 .
name =
"vc1_vdpau",
5854 #if CONFIG_WMV3IMAGE_DECODER
5855 AVCodec ff_wmv3image_decoder = {
5856 .
name =
"wmv3image",
5864 .
flush = vc1_sprite_flush,
5870 #if CONFIG_VC1IMAGE_DECODER
5871 AVCodec ff_vc1image_decoder = {
5880 .
flush = vc1_sprite_flush,