47 #define MB_INTRA_VLC_BITS 9
53 static const int offset_table2[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
93 int topleft_mb_pos, top_mb_pos;
94 int stride_y, fieldtx = 0;
110 v_dist = (16 - fieldtx) >> (fieldtx == 0);
135 v_dist = fieldtx ? 15 : 8;
157 #define inc_blk_idx(idx) do { \
159 if (idx >= v->n_allocated_blks) \
178 for (j = 0; j < 2; j++) {
211 for (j = 0; j < 2; j++) {
228 for (j = 0; j < 2; j++) {
244 for (j = 0; j < 2; j++) {
255 for (j = 0; j < 2; j++) {
349 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
352 uint8_t (*luty)[256], (*lutuv)[256];
360 mx = s->
mv[dir][0][0];
361 my = s->
mv[dir][0][1];
365 for (i = 0; i < 4; i++) {
371 uvmx = (mx + ((mx & 3) == 3)) >> 1;
372 uvmy = (my + ((my & 3) == 3)) >> 1;
384 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
385 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
412 if (!srcY || !srcU) {
417 src_x = s->
mb_x * 16 + (mx >> 2);
418 src_y = s->
mb_y * 16 + (my >> 2);
419 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
420 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
423 src_x = av_clip( src_x, -16, s->
mb_width * 16);
424 src_y = av_clip( src_y, -16, s->
mb_height * 16);
425 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
426 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
434 srcY += src_y * s->
linesize + src_x;
453 || (
unsigned)(src_y - 1) > v_edge_pos - (my&3) - 16 - 3) {
464 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
467 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
477 for (j = 0; j < 17 + s->
mspel * 2; j++) {
478 for (i = 0; i < 17 + s->
mspel * 2; i++)
479 src[i] = ((src[i] - 128) >> 1) + 128;
484 for (j = 0; j < 9; j++) {
485 for (i = 0; i < 9; i++) {
486 src[i] = ((src[i] - 128) >> 1) + 128;
487 src2[i] = ((src2[i] - 128) >> 1) + 128;
499 for (j = 0; j < 17 + s->
mspel * 2; j++) {
501 for (i = 0; i < 17 + s->
mspel * 2; i++)
502 src[i] = luty[f][src[i]];
507 for (j = 0; j < 9; j++) {
509 for (i = 0; i < 9; i++) {
510 src[i] = lutuv[f][src[i]];
511 src2[i] = lutuv[f][src2[i]];
521 dxy = ((my & 3) << 2) | (mx & 3);
528 dxy = (my & 2) | ((mx & 2) >> 1);
537 uvmx = (uvmx & 3) << 1;
538 uvmy = (uvmy & 3) << 1;
551 if (c < d)
return (
FFMIN(b, d) +
FFMAX(a, c)) / 2;
554 if (c < d)
return (
FFMIN(a, d) +
FFMAX(b, c)) / 2;
565 int dxy, mx, my, src_x, src_y;
577 mx = s->
mv[dir][
n][0];
578 my = s->
mv[dir][
n][1];
607 int same_count = 0, opp_count = 0, k;
608 int chosen_mv[2][4][2], f;
610 for (k = 0; k < 4; k++) {
612 chosen_mv[f][f ? opp_count : same_count][0] = s->
mv[0][k][0];
613 chosen_mv[f][f ? opp_count : same_count][1] = s->
mv[0][k][1];
617 f = opp_count > same_count;
618 switch (f ? opp_count : same_count) {
620 tx =
median4(chosen_mv[f][0][0], chosen_mv[f][1][0],
621 chosen_mv[f][2][0], chosen_mv[f][3][0]);
622 ty =
median4(chosen_mv[f][0][1], chosen_mv[f][1][1],
623 chosen_mv[f][2][1], chosen_mv[f][3][1]);
626 tx =
mid_pred(chosen_mv[f][0][0], chosen_mv[f][1][0], chosen_mv[f][2][0]);
627 ty =
mid_pred(chosen_mv[f][0][1], chosen_mv[f][1][1], chosen_mv[f][2][1]);
630 tx = (chosen_mv[f][0][0] + chosen_mv[f][1][0]) / 2;
631 ty = (chosen_mv[f][0][1] + chosen_mv[f][1][1]) / 2;
638 for (k = 0; k < 4; k++)
650 qx = (s->
mb_x * 16) + (mx >> 2);
651 qy = (s->
mb_y * 8) + (my >> 3);
656 mx -= 4 * (qx -
width);
659 else if (qy > height + 1)
660 my -= 8 * (qy - height - 1);
664 off = ((n > 1) ? s->
linesize : 0) + (n & 1) * 8;
666 off = s->
linesize * 4 * (n & 2) + (n & 1) * 8;
668 src_x = s->
mb_x * 16 + (n & 1) * 8 + (mx >> 2);
670 src_y = s->
mb_y * 16 + (n & 2) * 4 + (my >> 2);
672 src_y = s->
mb_y * 16 + ((n > 1) ? 1 : 0) + (my >> 2);
675 src_x = av_clip(src_x, -16, s->
mb_width * 16);
676 src_y = av_clip(src_y, -16, s->
mb_height * 16);
689 srcY += src_y * s->
linesize + src_x;
693 if (fieldmv && !(src_y & 1))
695 if (fieldmv && (src_y & 1) && src_y < 4)
700 || (
unsigned)(src_y - (s->
mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->
mspel * 2) << fieldmv)) {
704 9 + s->
mspel * 2, (9 + s->
mspel * 2) << fieldmv,
705 src_x - s->
mspel, src_y - (s->
mspel << fieldmv),
714 for (j = 0; j < 9 + s->
mspel * 2; j++) {
715 for (i = 0; i < 9 + s->
mspel * 2; i++)
716 src[i] = ((src[i] - 128) >> 1) + 128;
726 for (j = 0; j < 9 + s->
mspel * 2; j++) {
728 for (i = 0; i < 9 + s->
mspel * 2; i++)
729 src[i] = luty[f][src[i]];
737 dxy = ((my & 3) << 2) | (mx & 3);
743 dxy = (my & 2) | ((mx & 2) >> 1);
754 static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
756 idx = ((a[3] != flag) << 3)
757 | ((a[2] != flag) << 2)
758 | ((a[1] != flag) << 1)
761 *tx =
median4(mvx[0], mvx[1], mvx[2], mvx[3]);
762 *ty =
median4(mvy[0], mvy[1], mvy[2], mvy[3]);
764 }
else if (count[idx] == 1) {
767 *tx =
mid_pred(mvx[1], mvx[2], mvx[3]);
768 *ty =
mid_pred(mvy[1], mvy[2], mvy[3]);
771 *tx =
mid_pred(mvx[0], mvx[2], mvx[3]);
772 *ty =
mid_pred(mvy[0], mvy[2], mvy[3]);
775 *tx =
mid_pred(mvx[0], mvx[1], mvx[3]);
776 *ty =
mid_pred(mvy[0], mvy[1], mvy[3]);
779 *tx =
mid_pred(mvx[0], mvx[1], mvx[2]);
780 *ty =
mid_pred(mvy[0], mvy[1], mvy[2]);
783 }
else if (count[idx] == 2) {
785 for (i = 0; i < 3; i++)
790 for (i = t1 + 1; i < 4; i++)
795 *tx = (mvx[
t1] + mvx[
t2]) / 2;
796 *ty = (mvy[
t1] + mvy[
t2]) / 2;
811 int uvmx, uvmy, uvsrc_x, uvsrc_y;
812 int k, tx = 0, ty = 0;
813 int mvx[4], mvy[4], intra[4], mv_f[4];
825 for (k = 0; k < 4; k++) {
826 mvx[k] = s->
mv[dir][k][0];
827 mvy[k] = s->
mv[dir][k][1];
845 if (mv_f[0] + mv_f[1] + mv_f[2] + mv_f[3] > 2)
847 valid_count =
get_chroma_mv(mvx, mvy, mv_f, dominant, &tx, &ty);
855 uvmx = (tx + ((tx & 3) == 3)) >> 1;
856 uvmy = (ty + ((ty & 3) == 3)) >> 1;
862 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
863 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
867 uvmy += 2 - 4 * chroma_ref_type;
869 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
870 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
873 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
874 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
908 if (chroma_ref_type) {
916 || (
unsigned)uvsrc_x > (s->
h_edge_pos >> 1) - 9
917 || (
unsigned)uvsrc_y > (v_edge_pos >> 1) - 9) {
919 s->
uvlinesize, 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
922 s->
uvlinesize, 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
934 for (j = 0; j < 9; j++) {
935 for (i = 0; i < 9; i++) {
936 src[i] = ((src[i] - 128) >> 1) + 128;
937 src2[i] = ((src2[i] - 128) >> 1) + 128;
950 for (j = 0; j < 9; j++) {
951 int f = v->
field_mode ? chroma_ref_type : ((j + uvsrc_y) & 1);
952 for (i = 0; i < 9; i++) {
953 src[i] = lutuv[f][src[i]];
954 src2[i] = lutuv[f][src2[i]];
963 uvmx = (uvmx & 3) << 1;
964 uvmy = (uvmy & 3) << 1;
981 int uvsrc_x, uvsrc_y;
982 int uvmx_field[4], uvmy_field[4];
985 static const int s_rndtblfield[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 };
986 int v_dist = fieldmv ? 1 : 4;
994 for (i = 0; i < 4; i++) {
995 int d = i < 2 ? dir: dir2;
997 uvmx_field[i] = (tx + ((tx & 3) == 3)) >> 1;
1000 uvmy_field[i] = (ty >> 4) * 8 + s_rndtblfield[ty & 0xF];
1002 uvmy_field[i] = (ty + ((ty & 3) == 3)) >> 1;
1005 for (i = 0; i < 4; i++) {
1006 off = (i & 1) * 4 + ((i & 2) ? v_dist * s->
uvlinesize : 0);
1007 uvsrc_x = s->
mb_x * 8 + (i & 1) * 4 + (uvmx_field[i] >> 2);
1008 uvsrc_y = s->
mb_y * 8 + ((i & 2) ? v_dist : 0) + (uvmy_field[i] >> 2);
1012 if (i < 2 ? dir : dir2) {
1027 uvmx_field[i] = (uvmx_field[i] & 3) << 1;
1028 uvmy_field[i] = (uvmy_field[i] & 3) << 1;
1030 if (fieldmv && !(uvsrc_y & 1))
1033 if (fieldmv && (uvsrc_y & 1) && uvsrc_y < 2)
1036 || s->
h_edge_pos < 10 || v_edge_pos < (5 << fieldmv)
1037 || (unsigned)uvsrc_x > (s->
h_edge_pos >> 1) - 5
1038 || (unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) {
1055 for (j = 0; j < 5; j++) {
1056 int f = (uvsrc_y + (j << fieldmv)) & 1;
1057 for (i = 0; i < 5; i++) {
1058 src[i] = lutuv[f][src[i]];
1059 src2[i] = lutuv[f][src2[i]];
1097 #define GET_MQUANT() \
1098 if (v->dquantfrm) { \
1100 if (v->dqprofile == DQPROFILE_ALL_MBS) { \
1101 if (v->dqbilevel) { \
1102 mquant = (get_bits1(gb)) ? v->altpq : v->pq; \
1104 mqdiff = get_bits(gb, 3); \
1106 mquant = v->pq + mqdiff; \
1108 mquant = get_bits(gb, 5); \
1111 if (v->dqprofile == DQPROFILE_SINGLE_EDGE) \
1112 edges = 1 << v->dqsbedge; \
1113 else if (v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
1114 edges = (3 << v->dqsbedge) % 15; \
1115 else if (v->dqprofile == DQPROFILE_FOUR_EDGES) \
1117 if ((edges&1) && !s->mb_x) \
1118 mquant = v->altpq; \
1119 if ((edges&2) && s->first_slice_line) \
1120 mquant = v->altpq; \
1121 if ((edges&4) && s->mb_x == (s->mb_width - 1)) \
1122 mquant = v->altpq; \
1123 if ((edges&8) && s->mb_y == (s->mb_height - 1)) \
1124 mquant = v->altpq; \
1125 if (!mquant || mquant > 31) { \
1126 av_log(v->s.avctx, AV_LOG_ERROR, \
1127 "Overriding invalid mquant %d\n", mquant); \
1139 #define GET_MVDATA(_dmv_x, _dmv_y) \
1140 index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table, \
1141 VC1_MV_DIFF_VLC_BITS, 2); \
1143 mb_has_coeffs = 1; \
1146 mb_has_coeffs = 0; \
1149 _dmv_x = _dmv_y = 0; \
1150 } else if (index == 35) { \
1151 _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
1152 _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
1153 } else if (index == 36) { \
1158 index1 = index % 6; \
1159 if (!s->quarter_sample && index1 == 5) val = 1; \
1161 if (size_table[index1] - val > 0) \
1162 val = get_bits(gb, size_table[index1] - val); \
1164 sign = 0 - (val&1); \
1165 _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
1167 index1 = index / 6; \
1168 if (!s->quarter_sample && index1 == 5) val = 1; \
1170 if (size_table[index1] - val > 0) \
1171 val = get_bits(gb, size_table[index1] - val); \
1173 sign = 0 - (val & 1); \
1174 _dmv_y = (sign ^ ((val >> 1) + offset_table[index1])) - sign; \
1178 int *dmv_y,
int *pred_flag)
1181 int extend_x = 0, extend_y = 0;
1185 const int* offs_tab;
1202 extend_x = extend_y = 1;
1211 *pred_flag = *dmv_y & 1;
1212 *dmv_y = (*dmv_y + *pred_flag) >> 1;
1214 *dmv_y = (*dmv_y + (*dmv_y & 1)) >> 1;
1224 index1 = (index + 1) % 9;
1226 val =
get_bits(gb, index1 + extend_x);
1227 sign = 0 -(val & 1);
1228 *dmv_x = (sign ^ ((val >> 1) + offs_tab[index1])) - sign;
1235 index1 = (index + 1) / 9;
1236 if (index1 > v->
numref) {
1238 sign = 0 - (val & 1);
1239 *dmv_y = (sign ^ ((val >> 1) + offs_tab[index1 >> v->
numref])) - sign;
1242 if (v->
numref && pred_flag)
1243 *pred_flag = index1 & 1;
1249 int scaledvalue, refdist;
1250 int scalesame1, scalesame2;
1251 int scalezone1_x, zone1offset_x;
1268 if (
FFABS(n) < scalezone1_x)
1269 scaledvalue = (n * scalesame1) >> 8;
1272 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_x;
1274 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_x;
1282 int scaledvalue, refdist;
1283 int scalesame1, scalesame2;
1284 int scalezone1_y, zone1offset_y;
1301 if (
FFABS(n) < scalezone1_y)
1302 scaledvalue = (n * scalesame1) >> 8;
1305 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_y;
1307 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_y;
1312 return av_clip(scaledvalue, -v->
range_y / 2 + 1, v->
range_y / 2);
1314 return av_clip(scaledvalue, -v->
range_y / 2, v->
range_y / 2 - 1);
1319 int scalezone1_x, zone1offset_x;
1320 int scaleopp1, scaleopp2, brfd;
1332 if (
FFABS(n) < scalezone1_x)
1333 scaledvalue = (n * scaleopp1) >> 8;
1336 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_x;
1338 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_x;
1346 int scalezone1_y, zone1offset_y;
1347 int scaleopp1, scaleopp2, brfd;
1359 if (
FFABS(n) < scalezone1_y)
1360 scaledvalue = (n * scaleopp1) >> 8;
1363 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_y;
1365 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_y;
1369 return av_clip(scaledvalue, -v->
range_y / 2 + 1, v->
range_y / 2);
1371 return av_clip(scaledvalue, -v->
range_y / 2, v->
range_y / 2 - 1);
1378 int brfd, scalesame;
1392 n = (n * scalesame >> 8) << hpel;
1399 int refdist, scaleopp;
1416 n = (n * scaleopp >> 8) << hpel;
1423 int mv1,
int r_x,
int r_y,
uint8_t* is_intra,
1424 int pred_flag,
int dir)
1431 int mixedmv_pic, num_samefield = 0, num_oppfield = 0;
1432 int opposite, a_f, b_f, c_f;
1433 int16_t field_predA[2];
1434 int16_t field_predB[2];
1435 int16_t field_predC[2];
1436 int a_valid, b_valid, c_valid;
1437 int hybridmv_thresh, y_bias = 0;
1485 off = (s->
mb_x > 0) ? -1 : 1;
1500 b_valid = a_valid && (s->
mb_width > 1);
1501 c_valid = s->
mb_x || (n == 1 || n == 3);
1503 a_valid = a_valid && !is_intra[xy -
wrap];
1504 b_valid = b_valid && !is_intra[xy - wrap +
off];
1505 c_valid = c_valid && !is_intra[xy - 1];
1510 num_oppfield += a_f;
1511 num_samefield += 1 - a_f;
1512 field_predA[0] = A[0];
1513 field_predA[1] = A[1];
1515 field_predA[0] = field_predA[1] = 0;
1520 num_oppfield += b_f;
1521 num_samefield += 1 - b_f;
1522 field_predB[0] = B[0];
1523 field_predB[1] = B[1];
1525 field_predB[0] = field_predB[1] = 0;
1530 num_oppfield += c_f;
1531 num_samefield += 1 - c_f;
1532 field_predC[0] = C[0];
1533 field_predC[1] = C[1];
1535 field_predC[0] = field_predC[1] = 0;
1545 if (num_samefield <= num_oppfield)
1546 opposite = 1 - pred_flag;
1548 opposite = pred_flag;
1553 if (a_valid && !a_f) {
1554 field_predA[0] =
scaleforopp(v, field_predA[0], 0, dir);
1555 field_predA[1] =
scaleforopp(v, field_predA[1], 1, dir);
1557 if (b_valid && !b_f) {
1558 field_predB[0] =
scaleforopp(v, field_predB[0], 0, dir);
1559 field_predB[1] =
scaleforopp(v, field_predB[1], 1, dir);
1561 if (c_valid && !c_f) {
1562 field_predC[0] =
scaleforopp(v, field_predC[0], 0, dir);
1563 field_predC[1] =
scaleforopp(v, field_predC[1], 1, dir);
1568 if (a_valid && a_f) {
1569 field_predA[0] =
scaleforsame(v, n, field_predA[0], 0, dir);
1570 field_predA[1] =
scaleforsame(v, n, field_predA[1], 1, dir);
1572 if (b_valid && b_f) {
1573 field_predB[0] =
scaleforsame(v, n, field_predB[0], 0, dir);
1574 field_predB[1] =
scaleforsame(v, n, field_predB[1], 1, dir);
1576 if (c_valid && c_f) {
1577 field_predC[0] =
scaleforsame(v, n, field_predC[0], 0, dir);
1578 field_predC[1] =
scaleforsame(v, n, field_predC[1], 1, dir);
1585 px = field_predA[0];
1586 py = field_predA[1];
1587 }
else if (c_valid) {
1588 px = field_predC[0];
1589 py = field_predC[1];
1590 }
else if (b_valid) {
1591 px = field_predB[0];
1592 py = field_predB[1];
1598 if (num_samefield + num_oppfield > 1) {
1599 px =
mid_pred(field_predA[0], field_predB[0], field_predC[0]);
1600 py =
mid_pred(field_predA[1], field_predB[1], field_predC[1]);
1606 qx = (s->
mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0);
1607 qy = (s->
mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0);
1611 if (qx + px < -60) px = -60 - qx;
1612 if (qy + py < -60) py = -60 - qy;
1614 if (qx + px < -28) px = -28 - qx;
1615 if (qy + py < -28) py = -28 - qy;
1617 if (qx + px > X) px = X - qx;
1618 if (qy + py > Y) py = Y - qy;
1623 hybridmv_thresh = 32;
1624 if (a_valid && c_valid) {
1625 if (is_intra[xy - wrap])
1628 sum =
FFABS(px - field_predA[0]) +
FFABS(py - field_predA[1]);
1629 if (sum > hybridmv_thresh) {
1631 px = field_predA[0];
1632 py = field_predA[1];
1634 px = field_predC[0];
1635 py = field_predC[1];
1638 if (is_intra[xy - 1])
1641 sum =
FFABS(px - field_predC[0]) +
FFABS(py - field_predC[1]);
1642 if (sum > hybridmv_thresh) {
1644 px = field_predA[0];
1645 py = field_predA[1];
1647 px = field_predC[0];
1648 py = field_predC[1];
1677 int mvn,
int r_x,
int r_y,
uint8_t* is_intra,
int dir)
1681 int A[2],
B[2],
C[2];
1683 int a_valid = 0, b_valid = 0, c_valid = 0;
1684 int field_a, field_b, field_c;
1685 int total_valid, num_samefield, num_oppfield;
1686 int pos_c, pos_b, n_adj;
1714 off = ((n == 0) || (n == 1)) ? 1 : -1;
1716 if (s->
mb_x || (n == 1) || (n == 3)) {
1736 B[0] = B[1] = C[0] = C[1] = 0;
1744 n_adj = (n & 2) | (n & 1);
1798 total_valid = a_valid + b_valid + c_valid;
1800 if (!s->
mb_x && !(n == 1 || n == 3)) {
1805 B[0] = B[1] = C[0] = C[1] = 0;
1812 if (total_valid >= 2) {
1815 }
else if (total_valid) {
1816 if (a_valid) { px = A[0]; py = A[1]; }
1817 else if (b_valid) { px = B[0]; py = B[1]; }
1818 else { px = C[0]; py = C[1]; }
1823 field_a = (A[1] & 4) ? 1 : 0;
1827 field_b = (B[1] & 4) ? 1 : 0;
1831 field_c = (C[1] & 4) ? 1 : 0;
1835 num_oppfield = field_a + field_b + field_c;
1836 num_samefield = total_valid - num_oppfield;
1837 if (total_valid == 3) {
1838 if ((num_samefield == 3) || (num_oppfield == 3)) {
1841 }
else if (num_samefield >= num_oppfield) {
1844 px = !field_a ? A[0] : B[0];
1845 py = !field_a ? A[1] : B[1];
1847 px = field_a ? A[0] : B[0];
1848 py = field_a ? A[1] : B[1];
1850 }
else if (total_valid == 2) {
1851 if (num_samefield >= num_oppfield) {
1852 if (!field_a && a_valid) {
1855 }
else if (!field_b && b_valid) {
1864 if (field_a && a_valid) {
1876 }
else if (total_valid == 1) {
1877 px = (a_valid) ? A[0] : ((b_valid) ? B[0] : C[0]);
1878 py = (a_valid) ? A[1] : ((b_valid) ? B[1] : C[1]);
1892 }
else if (mvn == 2) {
1895 s->
mv[dir][n + 1][0] = s->
mv[dir][
n][0];
1896 s->
mv[dir][n + 1][1] = s->
mv[dir][
n][1];
1907 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
1915 mx = s->
mv[1][0][0];
1916 my = s->
mv[1][0][1];
1917 uvmx = (mx + ((mx & 3) == 3)) >> 1;
1918 uvmy = (my + ((my & 3) == 3)) >> 1;
1925 uvmx = uvmx + ((uvmx < 0) ? -(uvmx & 1) : (uvmx & 1));
1926 uvmy = uvmy + ((uvmy < 0) ? -(uvmy & 1) : (uvmy & 1));
1932 src_x = s->
mb_x * 16 + (mx >> 2);
1933 src_y = s->
mb_y * 16 + (my >> 2);
1934 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
1935 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
1938 src_x = av_clip( src_x, -16, s->
mb_width * 16);
1939 src_y = av_clip( src_y, -16, s->
mb_height * 16);
1940 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
1941 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
1949 srcY += src_y * s->
linesize + src_x;
1966 || (
unsigned)(src_x - 1) > s->
h_edge_pos - (mx & 3) - 16 - 3
1967 || (
unsigned)(src_y - 1) > v_edge_pos - (my & 3) - 16 - 3) {
1977 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
1980 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
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)
2141 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));
2142 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));
2143 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));
2144 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));
2160 if (!s->
mb_x) C[0] = C[1] = 0;
2169 }
else if (s->
mb_x) {
2179 qx = (s->
mb_x << 5);
2180 qy = (s->
mb_y << 5);
2183 if (qx + px < -28) px = -28 - qx;
2184 if (qy + py < -28) py = -28 - qy;
2185 if (qx + px > X) px = X - qx;
2186 if (qy + py > Y) py = Y - qy;
2188 qx = (s->
mb_x << 6);
2189 qy = (s->
mb_y << 6);
2192 if (qx + px < -60) px = -60 - qx;
2193 if (qy + py < -60) py = -60 - qy;
2194 if (qx + px > X) px = X - qx;
2195 if (qy + py > Y) py = Y - qy;
2200 if (is_intra[xy - wrap])
2213 if (is_intra[xy - 2])
2229 s->
mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
2230 s->
mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
2248 }
else if (s->
mb_x) {
2258 qx = (s->
mb_x << 5);
2259 qy = (s->
mb_y << 5);
2262 if (qx + px < -28) px = -28 - qx;
2263 if (qy + py < -28) py = -28 - qy;
2264 if (qx + px > X) px = X - qx;
2265 if (qy + py > Y) py = Y - qy;
2267 qx = (s->
mb_x << 6);
2268 qy = (s->
mb_y << 6);
2271 if (qx + px < -60) px = -60 - qx;
2272 if (qy + py < -60) py = -60 - qy;
2273 if (qx + px > X) px = X - qx;
2274 if (qy + py > Y) py = Y - qy;
2279 if (is_intra[xy - wrap])
2292 if (is_intra[xy - 2])
2309 s->
mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
2310 s->
mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
2325 int total_opp, k, f;
2340 f = (total_opp > 2) ? 1 : 0;
2342 s->
mv[0][0][0] = s->
mv[0][0][1] = 0;
2343 s->
mv[1][0][0] = s->
mv[1][0][1] = 0;
2347 for (k = 0; k < 4; k++) {
2364 if (n == 3 || mv1) {
2369 if (n == 3 || mv1) {
2385 int16_t **dc_val_ptr,
int *dir_ptr)
2389 static const uint16_t dcpred[32] = {
2390 -1, 1024, 512, 341, 256, 205, 171, 146, 128,
2391 114, 102, 93, 85, 79, 73, 68, 64,
2392 60, 57, 54, 51, 49, 47, 45, 43,
2393 41, 39, 38, 37, 35, 34, 33
2407 b = dc_val[ - 1 -
wrap];
2408 a = dc_val[ -
wrap];
2410 if (pq < 9 || !overlap) {
2413 b = a = dcpred[
scale];
2414 if (s->
mb_x == 0 && (n != 1 && n != 3))
2415 b = c = dcpred[
scale];
2420 if (s->
mb_x == 0 && (n != 1 && n != 3))
2424 if (abs(a - b) <= abs(b - c)) {
2433 *dc_val_ptr = &dc_val[0];
2450 int a_avail,
int c_avail,
2451 int16_t **dc_val_ptr,
int *dir_ptr)
2466 b = dc_val[ - 1 -
wrap];
2467 a = dc_val[ -
wrap];
2471 if (dqscale_index < 0)
2473 if (c_avail && (n != 1 && n != 3)) {
2478 if (a_avail && (n != 2 && n != 3)) {
2483 if (a_avail && c_avail && (n != 3)) {
2494 if (a_avail && c_avail) {
2495 if (abs(a - b) <= abs(b - c)) {
2502 }
else if (a_avail) {
2505 }
else if (c_avail) {
2514 *dc_val_ptr = &dc_val[0];
2563 int *
value,
int codingset)
2629 int coded,
int codingset)
2633 int dc_pred_dir = 0;
2636 int16_t *ac_val, *ac_val2;
2650 if (dcdiff == 119 ) {
2653 else if (v->
pq == 2) dcdiff =
get_bits(gb, 9);
2657 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
2658 else if (v->
pq == 2)
2659 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
2684 int last = 0, skip,
value;
2711 block[zz_table[i++]] =
value;
2717 for (k = 1; k < 8; k++)
2720 for (k = 1; k < 8; k++)
2725 for (k = 1; k < 8; k++) {
2731 for (k = 1; k < 64; k++)
2735 block[k] += (block[k] < 0) ? -v->
pq : v->
pq;
2749 memset(ac_val2, 0, 16 * 2);
2753 memcpy(ac_val2, ac_val, 8 * 2);
2757 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
2763 for (k = 1; k < 8; k++) {
2769 for (k = 1; k < 8; k++) {
2792 int coded,
int codingset,
int mquant)
2796 int dc_pred_dir = 0;
2798 int16_t *dc_val = NULL;
2799 int16_t *ac_val, *ac_val2;
2818 if (dcdiff == 119 ) {
2820 if (mquant == 1) dcdiff =
get_bits(gb, 10);
2821 else if (mquant == 2) dcdiff =
get_bits(gb, 9);
2825 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
2826 else if (mquant == 2)
2827 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
2848 if (!a_avail && !c_avail)
2853 scale = mquant * 2 + ((mquant == v->
pq) ? v->
halfpq : 0);
2861 if ( dc_pred_dir && c_avail && mb_pos)
2863 if (!dc_pred_dir && a_avail && mb_pos >= s->
mb_stride)
2865 if ( dc_pred_dir && n == 1)
2867 if (!dc_pred_dir && n == 2)
2873 int last = 0, skip,
value;
2898 block[zz_table[i++]] =
value;
2904 if (q2 && q1 != q2) {
2905 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2906 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2911 for (k = 1; k < 8; k++)
2914 for (k = 1; k < 8; k++)
2919 for (k = 1; k < 8; k++)
2922 for (k = 1; k < 8; k++)
2928 for (k = 1; k < 8; k++) {
2934 for (k = 1; k < 64; k++)
2938 block[k] += (block[k] < 0) ? -mquant : mquant;
2941 if (use_pred) i = 63;
2945 memset(ac_val2, 0, 16 * 2);
2948 memcpy(ac_val2, ac_val, 8 * 2);
2949 if (q2 && q1 != q2) {
2950 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2951 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2954 for (k = 1; k < 8; k++)
2955 ac_val2[k] = (ac_val2[k] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2960 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
2961 if (q2 && q1 != q2) {
2962 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2963 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2966 for (k = 1; k < 8; k++)
2967 ac_val2[k + 8] = (ac_val2[k + 8] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2975 for (k = 1; k < 8; k++) {
2981 for (k = 1; k < 8; k++) {
3004 int coded,
int mquant,
int codingset)
3008 int dc_pred_dir = 0;
3010 int16_t *dc_val = NULL;
3011 int16_t *ac_val, *ac_val2;
3022 mquant = (mquant < 1) ? 0 : ((mquant > 31) ? 31 : mquant);
3039 if (dcdiff == 119 ) {
3041 if (mquant == 1) dcdiff =
get_bits(gb, 10);
3042 else if (mquant == 2) dcdiff =
get_bits(gb, 9);
3046 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
3047 else if (mquant == 2)
3048 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
3055 dcdiff +=
vc1_pred_dc(&v->
s, v->
overlap, mquant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
3070 if (!a_avail) dc_pred_dir = 1;
3071 if (!c_avail) dc_pred_dir = 0;
3072 if (!a_avail && !c_avail) use_pred = 0;
3076 scale = mquant * 2 + v->
halfpq;
3084 if (dc_pred_dir && c_avail && mb_pos)
3086 if (!dc_pred_dir && a_avail && mb_pos >= s->
mb_stride)
3088 if ( dc_pred_dir && n == 1)
3090 if (!dc_pred_dir && n == 2)
3092 if (n == 3) q2 = q1;
3095 int last = 0, skip,
value;
3120 if (q2 && q1 != q2) {
3121 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3122 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3127 for (k = 1; k < 8; k++)
3130 for (k = 1; k < 8; k++)
3135 for (k = 1; k < 8; k++)
3138 for (k = 1; k < 8; k++)
3144 for (k = 1; k < 8; k++) {
3150 for (k = 1; k < 64; k++)
3154 block[k] += (block[k] < 0) ? -mquant : mquant;
3157 if (use_pred) i = 63;
3161 memset(ac_val2, 0, 16 * 2);
3164 memcpy(ac_val2, ac_val, 8 * 2);
3165 if (q2 && q1 != q2) {
3166 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3167 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3170 for (k = 1; k < 8; k++)
3171 ac_val2[k] = (ac_val2[k] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
3176 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
3177 if (q2 && q1 != q2) {
3178 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3179 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3182 for (k = 1; k < 8; k++)
3183 ac_val2[k + 8] = (ac_val2[k + 8] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
3191 for (k = 1; k < 8; k++) {
3197 for (k = 1; k < 8; k++) {
3214 int mquant,
int ttmb,
int first_block,
3215 uint8_t *dst,
int linesize,
int skip_block,
3223 int ttblk = ttmb & 7;
3235 && ((v->
ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
3245 scale = 2 * mquant + ((v->
pq == mquant) ? v->
halfpq : 0);
3270 block[idx] = value *
scale;
3272 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3284 pat = ~subblkpat & 0xF;
3285 for (j = 0; j < 4; j++) {
3286 last = subblkpat & (1 << (3 - j));
3288 off = (j & 1) * 4 + (j & 2) * 16;
3300 block[idx +
off] += (block[idx +
off] < 0) ? -mquant : mquant;
3302 if (!(subblkpat & (1 << (3 - j))) && !skip_block) {
3311 pat = ~((subblkpat & 2) * 6 + (subblkpat & 1) * 3) & 0xF;
3312 for (j = 0; j < 2; j++) {
3313 last = subblkpat & (1 << (1 - j));
3325 block[idx] = value *
scale;
3327 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3329 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
3338 pat = ~(subblkpat * 5) & 0xF;
3339 for (j = 0; j < 2; j++) {
3340 last = subblkpat & (1 << (1 - j));
3352 block[idx] = value *
scale;
3354 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3356 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
3366 *ttmb_out |= ttblk << (n * 4);
3379 block_cbp = mb_cbp >> (block_num * 4), bottom_cbp,
3381 block_is_intra = mb_is_intra >> (block_num * 4), bottom_is_intra;
3385 if (block_num > 3) {
3386 dst = s->
dest[block_num - 3];
3388 dst = s->
dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 8) * linesize;
3394 if (block_num > 3) {
3395 bottom_cbp = v->
cbp[s->
mb_x] >> (block_num * 4);
3396 bottom_is_intra = v->
is_intra[s->
mb_x] >> (block_num * 4);
3400 bottom_cbp = (block_num < 2) ? (mb_cbp >> ((block_num + 2) * 4))
3401 : (v->
cbp[s->
mb_x] >> ((block_num - 2) * 4));
3402 bottom_is_intra = (block_num < 2) ? (mb_is_intra >> ((block_num + 2) * 4))
3408 if (bottom_is_intra & 1 || block_is_intra & 1 ||
3409 mv[0][0] !=
mv[mv_stride][0] ||
mv[0][1] !=
mv[mv_stride][1]) {
3412 idx = ((bottom_cbp >> 2) | block_cbp) & 3;
3424 dst -= 4 * linesize;
3427 idx = (block_cbp | (block_cbp >> 2)) & 3;
3443 block_cbp = mb_cbp >> (block_num * 4), right_cbp,
3445 block_is_intra = mb_is_intra >> (block_num * 4), right_is_intra;
3449 if (block_num > 3) {
3450 dst = s->
dest[block_num - 3] - 8 * linesize;
3452 dst = s->
dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 16) * linesize - 8;
3458 if (block_num > 3) {
3463 right_cbp = (block_num & 1) ? (v->
cbp[s->
mb_x - s->
mb_stride] >> ((block_num - 1) * 4))
3464 : (mb_cbp >> ((block_num + 1) * 4));
3466 : (mb_is_intra >> ((block_num + 1) * 4));
3469 if (block_is_intra & 1 || right_is_intra & 1 ||
mv[0][0] !=
mv[1][0] ||
mv[0][1] !=
mv[1][1]) {
3472 idx = ((right_cbp >> 1) | block_cbp) & 5;
3487 idx = (block_cbp | (block_cbp >> 1)) & 5;
3504 for (i = 0; i < 6; i++) {
3511 for (i = 0; i < 6; i++) {
3517 for (i = 0; i < 6; i++) {
3534 int ttmb = v->
ttfrm;
3536 int mb_has_coeffs = 1;
3540 int first_block = 1;
3542 int skipped, fourmv;
3543 int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
3568 if (s->
mb_intra && !mb_has_coeffs) {
3572 }
else if (mb_has_coeffs) {
3588 for (i = 0; i < 6; i++) {
3591 val = ((cbp >> (5 - i)) & 1);
3592 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3599 if (i == 1 || i == 3 || s->
mb_x)
3608 for (j = 0; j < 64; j++)
3609 s->
block[i][j] <<= 1;
3617 block_cbp |= 0xF << (i << 2);
3618 block_intra |= 1 << i;
3623 block_cbp |= pat << (i << 2);
3624 if (!v->
ttmbf && ttmb < 8)
3631 for (i = 0; i < 6; i++) {
3642 int intra_count = 0, coded_inter = 0;
3643 int is_intra[6], is_coded[6];
3646 for (i = 0; i < 6; i++) {
3647 val = ((cbp >> (5 - i)) & 1);
3662 is_coded[i] = mb_has_coeffs;
3665 is_intra[i] = (intra_count >= 3);
3672 coded_inter = !is_intra[i] & is_coded[i];
3676 if (!intra_count && !coded_inter)
3683 for (i = 0; i < 6; i++)
3696 if (!v->
ttmbf && coded_inter)
3698 for (i = 0; i < 6; i++) {
3700 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3707 if (i == 1 || i == 3 || s->
mb_x)
3716 for (j = 0; j < 64; j++)
3717 s->
block[i][j] <<= 1;
3726 block_cbp |= 0xF << (i << 2);
3727 block_intra |= 1 << i;
3728 }
else if (is_coded[i]) {
3730 first_block, s->
dest[dst_idx] + off,
3734 block_cbp |= pat << (i << 2);
3735 if (!v->
ttmbf && ttmb < 8)
3743 for (i = 0; i < 6; i++) {
3747 for (i = 0; i < 4; i++) {
3773 int ttmb = v->
ttfrm;
3775 int mb_has_coeffs = 1;
3778 int first_block = 1;
3780 int skipped, fourmv = 0, twomv = 0;
3781 int block_cbp = 0, pat, block_tt = 0;
3782 int idx_mbmode = 0, mvbp;
3783 int stride_y, fieldtx;
3827 for (i = 0; i < 4; i++) {
3833 for (i = 0; i < 6; i++)
3846 for (i = 0; i < 6; i++) {
3849 val = ((cbp >> (5 - i)) & 1);
3854 if (i == 1 || i == 3 || s->
mb_x)
3863 off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->
linesize : (i & 1) * 8 + 4 * (i & 2) * s->
linesize;
3885 for (i = 0; i < 6; i++)
3892 for (i = 0; i < 6; i++) {
3895 val = ((mvbp >> (3 - i)) & 1);
3901 }
else if (i == 4) {
3934 if (!v->
ttmbf && cbp)
3936 for (i = 0; i < 6; i++) {
3939 val = ((cbp >> (5 - i)) & 1);
3941 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3943 off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->
linesize));
3946 first_block, s->
dest[dst_idx] + off,
3949 block_cbp |= pat << (i << 2);
3950 if (!v->
ttmbf && ttmb < 8)
3958 for (i = 0; i < 6; i++) {
3984 int ttmb = v->
ttfrm;
3986 int mb_has_coeffs = 1;
3989 int first_block = 1;
3992 int block_cbp = 0, pat, block_tt = 0;
3998 if (idx_mbmode <= 1) {
4009 mb_has_coeffs = idx_mbmode & 1;
4013 for (i = 0; i < 6; i++) {
4017 val = ((cbp >> (5 - i)) & 1);
4021 if (i == 1 || i == 3 || s->
mb_x)
4029 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4037 if (idx_mbmode <= 5) {
4038 dmv_x = dmv_y = pred_flag = 0;
4039 if (idx_mbmode & 1) {
4044 mb_has_coeffs = !(idx_mbmode & 2);
4047 for (i = 0; i < 6; i++) {
4049 dmv_x = dmv_y = pred_flag = 0;
4050 val = ((v->
fourmvbp >> (3 - i)) & 1);
4059 mb_has_coeffs = idx_mbmode & 1;
4067 if (!v->
ttmbf && cbp) {
4071 for (i = 0; i < 6; i++) {
4074 val = ((cbp >> (5 - i)) & 1);
4075 off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->
linesize;
4078 first_block, s->
dest[dst_idx] + off,
4082 block_cbp |= pat << (i << 2);
4083 if (!v->
ttmbf && ttmb < 8) ttmb = -1;
4103 int ttmb = v->
ttfrm;
4104 int mb_has_coeffs = 0;
4107 int first_block = 1;
4109 int skipped, direct;
4110 int dmv_x[2], dmv_y[2];
4125 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
4126 for (i = 0; i < 6; i++) {
4135 dmv_x[1] = dmv_x[0];
4136 dmv_y[1] = dmv_y[0];
4149 dmv_x[0] = dmv_y[0] = 0;
4153 for (i = 0; i < 6; i++)
4160 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4170 dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
4172 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4174 if (!mb_has_coeffs && !s->
mb_intra) {
4177 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4180 if (s->
mb_intra && !mb_has_coeffs) {
4189 if (!mb_has_coeffs) {
4192 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4198 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4210 for (i = 0; i < 6; i++) {
4213 val = ((cbp >> (5 - i)) & 1);
4214 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4221 if (i == 1 || i == 3 || s->
mb_x)
4230 for (j = 0; j < 64; j++)
4231 s->
block[i][j] <<= 1;
4235 first_block, s->
dest[dst_idx] + off,
4238 if (!v->
ttmbf && ttmb < 8)
4255 int ttmb = v->
ttfrm;
4256 int mb_has_coeffs = 0;
4258 int first_block = 1;
4261 int dmv_x[2], dmv_y[2], pred_flag[2];
4269 if (idx_mbmode <= 1) {
4280 mb_has_coeffs = idx_mbmode & 1;
4284 for (i = 0; i < 6; i++) {
4287 val = ((cbp >> (5 - i)) & 1);
4292 if (i == 1 || i == 3 || s->
mb_x)
4301 for (j = 0; j < 64; j++)
4302 s->
block[i][j] <<= 1;
4303 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4315 if (idx_mbmode <= 5) {
4317 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
4318 pred_flag[0] = pred_flag[1] = 0;
4343 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
4344 dmv_x[1] = dmv_y[1] = pred_flag[0] = 0;
4348 mb_has_coeffs = !(idx_mbmode & 2);
4354 for (i = 0; i < 6; i++) {
4356 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
4357 dmv_x[1] = dmv_y[1] = pred_flag[1] = 0;
4358 val = ((v->
fourmvbp >> (3 - i)) & 1);
4369 mb_has_coeffs = idx_mbmode & 1;
4377 if (!v->
ttmbf && cbp) {
4381 for (i = 0; i < 6; i++) {
4384 val = ((cbp >> (5 - i)) & 1);
4385 off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->
linesize;
4388 first_block, s->
dest[dst_idx] + off,
4391 if (!v->
ttmbf && ttmb < 8)
4409 int ttmb = v->
ttfrm;
4411 int mb_has_coeffs = 1;
4414 int first_block = 1;
4416 int skipped, direct, twomv = 0;
4417 int block_cbp = 0, pat, block_tt = 0;
4418 int idx_mbmode = 0, mvbp;
4419 int stride_y, fieldtx;
4463 for (i = 1; i < 4; i += 2) {
4470 for (i = 1; i < 4; i++) {
4480 for (i = 0; i < 4; i++) {
4488 for (i = 0; i < 6; i++)
4501 for (i = 0; i < 6; i++) {
4504 val = ((cbp >> (5 - i)) & 1);
4509 if (i == 1 || i == 3 || s->
mb_x)
4519 off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->
linesize : (i & 1) * 8 + 4 * (i & 2) * s->
linesize;
4559 for (i = 0; i < 6; i++)
4566 for (i = 0; i < 4; i++) {
4578 for (i = 0; i < 4; i++) {
4581 val = ((mvbp >> (3 - i)) & 1);
4624 for (i = 0; i < 2; i++) {
4654 for (i = 0; i < 2; i++) {
4664 if (!v->
ttmbf && cbp)
4666 for (i = 0; i < 6; i++) {
4669 val = ((cbp >> (5 - i)) & 1);
4671 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4673 off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->
linesize));
4676 first_block, s->
dest[dst_idx] + off,
4679 block_cbp |= pat << (i << 2);
4680 if (!v->
ttmbf && ttmb < 8)
4688 for (i = 0; i < 6; i++) {
4710 for (i = 0; i < 2; i++) {
4722 for (i = 0; i < 2; i++) {
4792 dst[0] = s->
dest[0];
4793 dst[1] = dst[0] + 8;
4795 dst[3] = dst[2] + 8;
4796 dst[4] = s->
dest[1];
4797 dst[5] = s->
dest[2];
4809 for (k = 0; k < 6; k++) {
4810 val = ((cbp >> (5 - k)) & 1);
4817 cbp |= val << (5 - k);
4826 for (j = 0; j < 64; j++)
4827 s->
block[k][j] <<= 1;
4831 for (j = 0; j < 64; j++)
4963 for (k = 0; k < 6; k++) {
4964 val = ((cbp >> (5 - k)) & 1);
4971 cbp |= val << (5 - k);
5081 if (apply_loop_filter) {
5217 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
5233 int effect_type, effect_flag;
5234 int effect_pcount1, effect_pcount2;
5235 int effect_params1[15], effect_params2[10];
5243 static void vc1_sprite_parse_transform(
GetBitContext* gb,
int c[7])
5250 c[2] = get_fp_val(gb);
5254 c[0] = c[4] = get_fp_val(gb);
5255 c[2] = get_fp_val(gb);
5258 c[0] = get_fp_val(gb);
5259 c[2] = get_fp_val(gb);
5260 c[4] = get_fp_val(gb);
5263 c[0] = get_fp_val(gb);
5264 c[1] = get_fp_val(gb);
5265 c[2] = get_fp_val(gb);
5266 c[3] = get_fp_val(gb);
5267 c[4] = get_fp_val(gb);
5270 c[5] = get_fp_val(gb);
5272 c[6] = get_fp_val(gb);
5282 for (sprite = 0; sprite <= v->
two_sprites; sprite++) {
5283 vc1_sprite_parse_transform(gb, sd->coefs[sprite]);
5284 if (sd->coefs[sprite][1] || sd->coefs[sprite][3])
5287 for (i = 0; i < 7; i++)
5289 sd->coefs[sprite][i] / (1<<16),
5290 (abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1 << 16));
5296 switch (sd->effect_pcount1 =
get_bits(gb, 4)) {
5298 vc1_sprite_parse_transform(gb, sd->effect_params1);
5301 vc1_sprite_parse_transform(gb, sd->effect_params1);
5302 vc1_sprite_parse_transform(gb, sd->effect_params1 + 7);
5305 for (i = 0; i < sd->effect_pcount1; i++)
5306 sd->effect_params1[i] = get_fp_val(gb);
5308 if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) {
5311 for (i = 0; i < sd->effect_pcount1; i++)
5313 sd->effect_params1[i] / (1 << 16),
5314 (abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1 << 16));
5318 sd->effect_pcount2 =
get_bits(gb, 16);
5319 if (sd->effect_pcount2 > 10) {
5322 }
else if (sd->effect_pcount2) {
5325 while (++i < sd->effect_pcount2) {
5326 sd->effect_params2[i] = get_fp_val(gb);
5328 sd->effect_params2[i] / (1 << 16),
5329 (abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1 << 16));
5344 static void vc1_draw_sprites(
VC1Context *v, SpriteData* sd)
5346 int i, plane, row, sprite;
5347 int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } };
5349 int xoff[2], xadv[2], yoff[2], yadv[2],
alpha;
5353 for (i = 0; i < 2; i++) {
5354 xoff[i] = av_clip(sd->coefs[i][2], 0, v->
sprite_width-1 << 16);
5355 xadv[i] = sd->coefs[i][0];
5359 yoff[i] = av_clip(sd->coefs[i][5], 0, v->
sprite_height-1 << 16);
5362 alpha = av_clip(sd->coefs[1][6], 0, (1<<16) - 1);
5371 for (sprite = 0; sprite <= v->
two_sprites; sprite++) {
5374 int ycoord = yoff[sprite] + yadv[sprite] * row;
5375 int yline = ycoord >> 16;
5377 ysub[sprite] = ycoord & 0xFFFF;
5383 if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) {
5384 src_h[sprite][0] = iplane + (xoff[sprite] >> 16) + yline * iline;
5386 src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + next_line;
5388 if (sr_cache[sprite][0] != yline) {
5389 if (sr_cache[sprite][1] == yline) {
5391 FFSWAP(
int, sr_cache[sprite][0], sr_cache[sprite][1]);
5393 v->
vc1dsp.
sprite_h(v->
sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width);
5394 sr_cache[sprite][0] = yline;
5397 if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) {
5399 iplane + next_line, xoff[sprite],
5400 xadv[sprite], width);
5401 sr_cache[sprite][1] = yline + 1;
5403 src_h[sprite][0] = v->
sr_rows[sprite][0];
5404 src_h[sprite][1] = v->
sr_rows[sprite][1];
5412 memcpy(dst, src_h[0][0], width);
5415 if (ysub[0] && ysub[1]) {
5417 src_h[1][0], src_h[1][1], ysub[1], alpha, width);
5418 }
else if (ysub[0]) {
5420 src_h[1][0], alpha, width);
5421 }
else if (ysub[1]) {
5423 src_h[0][0], (1<<16)-1-alpha, width);
5431 for (i = 0; i < 2; i++) {
5448 vc1_parse_sprites(v, gb, &sd);
5464 vc1_draw_sprites(v, &sd);
5484 plane ? 128 : 0, f->
linesize[plane]);
5540 for (i = 0; i < 4; i++)
5567 for (i = 0; i < 64; i++) {
5568 #define transpose(x) ((x >> 3) | ((x & 7) << 3))
5637 }
else if (count < 0) {
5644 int size, buf2_size;
5646 int seq_initialized = 0, ep_initialized = 0;
5656 for (; next <
end; start = next) {
5658 size = next - start - 4;
5669 seq_initialized = 1;
5681 if (!seq_initialized || !ep_initialized) {
5740 for (i = 0; i < 4; i++)
5772 int buf_size = avpkt->
size, n_slices = 0, i,
ret;
5777 const uint8_t *buf_start =
buf, *buf_start_second_field = NULL;
5778 int mb_height, n_slices1=-1;
5783 } *slices = NULL, *tmp;
5823 for (start = buf, end = buf + buf_size; next <
end; start = next) {
5825 size = next - start - 4;
5826 if (size <= 0)
continue;
5838 buf_start_second_field =
start;
5839 tmp =
av_realloc(slices,
sizeof(*slices) * (n_slices+1));
5844 if (!slices[n_slices].buf)
5847 slices[n_slices].buf);
5852 slices[n_slices].mby_start = s->
mb_height >> 1;
5853 n_slices1 = n_slices - 1;
5864 tmp =
av_realloc(slices,
sizeof(*slices) * (n_slices+1));
5869 if (!slices[n_slices].buf)
5872 slices[n_slices].buf);
5875 slices[n_slices].mby_start =
get_bits(&slices[n_slices].gb, 9);
5881 }
else if (v->
interlace && ((buf[0] & 0xC0) == 0xC0)) {
5892 buf_start_second_field = divider;
5893 tmp =
av_realloc(slices,
sizeof(*slices) * (n_slices+1));
5898 if (!slices[n_slices].buf)
5900 buf_size3 =
vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf);
5903 slices[n_slices].mby_start = s->
mb_height >> 1;
5904 n_slices1 = n_slices - 1;
6037 if ((CONFIG_VC1_VDPAU_DECODER)
6039 if (v->
field_mode && buf_start_second_field) {
6046 if (v->
field_mode && buf_start_second_field) {
6049 if (avctx->
hwaccel->
start_frame(avctx, buf_start, buf_start_second_field - buf_start) < 0)
6051 if (avctx->
hwaccel->
decode_slice(avctx, buf_start, buf_start_second_field - buf_start) < 0)
6057 s->
gb = slices[n_slices1 + 1].gb;
6067 if (avctx->
hwaccel->
start_frame(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field) < 0)
6069 if (avctx->
hwaccel->
decode_slice(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field) < 0)
6087 v->
bits = buf_size * 8;
6100 for (i = 0; i <= n_slices; i++) {
6101 if (i > 0 && slices[i - 1].mby_start >= mb_height) {
6104 "picture boundary (%d >= %d)\n", i,
6105 slices[i - 1].mby_start, mb_height);
6137 s->
start_mb_y = (i == 0) ? 0 :
FFMAX(0, slices[i-1].mby_start % mb_height);
6139 s->
end_mb_y = (i == n_slices ) ? mb_height :
FFMIN(mb_height, slices[i].mby_start % mb_height);
6141 if (i >= n_slices) {
6145 s->
end_mb_y = (i <= n_slices1 + 1) ? mb_height :
FFMIN(mb_height, slices[i].mby_start % mb_height);
6157 s->
gb = slices[i].gb;
6189 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
6190 if (vc1_decode_sprites(v, &s->
gb))
6213 for (i = 0; i < n_slices; i++)
6220 for (i = 0; i < n_slices; i++)
6260 .pix_fmts = vc1_hwaccel_pixfmt_list_420,
6264 #if CONFIG_WMV3_DECODER
6276 .pix_fmts = vc1_hwaccel_pixfmt_list_420,
6281 #if CONFIG_WMV3_VDPAU_DECODER
6282 AVCodec ff_wmv3_vdpau_decoder = {
6283 .
name =
"wmv3_vdpau",
6297 #if CONFIG_VC1_VDPAU_DECODER
6298 AVCodec ff_vc1_vdpau_decoder = {
6299 .
name =
"vc1_vdpau",
6313 #if CONFIG_WMV3IMAGE_DECODER
6314 AVCodec ff_wmv3image_decoder = {
6315 .
name =
"wmv3image",
6324 .
flush = vc1_sprite_flush,
6329 #if CONFIG_VC1IMAGE_DECODER
6330 AVCodec ff_vc1image_decoder = {
6340 .
flush = vc1_sprite_flush,