46 #define MB_INTRA_VLC_BITS 9
52 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++) {
350 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
359 mx = s->
mv[dir][0][0];
360 my = s->
mv[dir][0][1];
368 uvmx = (mx + ((mx & 3) == 3)) >> 1;
369 uvmy = (my + ((my & 3) == 3)) >> 1;
381 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
382 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
415 src_x = s->
mb_x * 16 + (mx >> 2);
416 src_y = s->
mb_y * 16 + (my >> 2);
417 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
418 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
421 src_x = av_clip( src_x, -16, s->
mb_width * 16);
422 src_y = av_clip( src_y, -16, s->
mb_height * 16);
423 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
424 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
432 srcY += src_y * s->
linesize + src_x;
451 || (
unsigned)(src_y - 1) > v_edge_pos - (my&3) - 16 - 3) {
461 uvsrc_x, uvsrc_y, s->
h_edge_pos >> 1, v_edge_pos >> 1);
463 uvsrc_x, uvsrc_y, s->
h_edge_pos >> 1, v_edge_pos >> 1);
472 for (j = 0; j < 17 + s->
mspel * 2; j++) {
473 for (i = 0; i < 17 + s->
mspel * 2; i++)
474 src[i] = ((src[i] - 128) >> 1) + 128;
479 for (j = 0; j < 9; j++) {
480 for (i = 0; i < 9; i++) {
481 src[i] = ((src[i] - 128) >> 1) + 128;
482 src2[i] = ((src2[i] - 128) >> 1) + 128;
494 for (j = 0; j < 17 + s->
mspel * 2; j++) {
495 for (i = 0; i < 17 + s->
mspel * 2; i++)
496 src[i] = v->
luty[src[i]];
501 for (j = 0; j < 9; j++) {
502 for (i = 0; i < 9; i++) {
503 src[i] = v->
lutuv[src[i]];
504 src2[i] = v->
lutuv[src2[i]];
516 dxy = ((my & 3) << 2) | (mx & 3);
523 dxy = (my & 2) | ((mx & 2) >> 1);
532 uvmx = (uvmx & 3) << 1;
533 uvmy = (uvmy & 3) << 1;
546 if (c < d)
return (
FFMIN(b, d) +
FFMAX(a, c)) / 2;
549 if (c < d)
return (
FFMIN(a, d) +
FFMAX(b, c)) / 2;
561 int dxy, mx, my, src_x, src_y;
571 mx = s->
mv[dir][n][0];
572 my = s->
mv[dir][n][1];
594 int same_count = 0, opp_count = 0, k;
595 int chosen_mv[2][4][2], f;
597 for (k = 0; k < 4; k++) {
599 chosen_mv[f][f ? opp_count : same_count][0] = s->
mv[0][k][0];
600 chosen_mv[f][f ? opp_count : same_count][1] = s->
mv[0][k][1];
604 f = opp_count > same_count;
605 switch (f ? opp_count : same_count) {
607 tx =
median4(chosen_mv[f][0][0], chosen_mv[f][1][0],
608 chosen_mv[f][2][0], chosen_mv[f][3][0]);
609 ty =
median4(chosen_mv[f][0][1], chosen_mv[f][1][1],
610 chosen_mv[f][2][1], chosen_mv[f][3][1]);
613 tx =
mid_pred(chosen_mv[f][0][0], chosen_mv[f][1][0], chosen_mv[f][2][0]);
614 ty =
mid_pred(chosen_mv[f][0][1], chosen_mv[f][1][1], chosen_mv[f][2][1]);
617 tx = (chosen_mv[f][0][0] + chosen_mv[f][1][0]) / 2;
618 ty = (chosen_mv[f][0][1] + chosen_mv[f][1][1]) / 2;
625 for (k = 0; k < 4; k++)
633 qx = (s->
mb_x * 16) + (mx >> 2);
634 qy = (s->
mb_y * 8) + (my >> 3);
639 mx -= 4 * (qx -
width);
642 else if (qy > height + 1)
643 my -= 8 * (qy - height - 1);
647 off = ((n > 1) ? s->
linesize : 0) + (n & 1) * 8;
649 off = s->
linesize * 4 * (n & 2) + (n & 1) * 8;
651 src_x = s->
mb_x * 16 + (n & 1) * 8 + (mx >> 2);
653 src_y = s->
mb_y * 16 + (n & 2) * 4 + (my >> 2);
655 src_y = s->
mb_y * 16 + ((n > 1) ? 1 : 0) + (my >> 2);
658 src_x = av_clip(src_x, -16, s->
mb_width * 16);
659 src_y = av_clip(src_y, -16, s->
mb_height * 16);
672 srcY += src_y * s->
linesize + src_x;
676 if (fieldmv && !(src_y & 1))
678 if (fieldmv && (src_y & 1) && src_y < 4)
683 || (
unsigned)(src_y - (s->
mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->
mspel * 2) << fieldmv)) {
687 9 + s->
mspel * 2, (9 + s->
mspel * 2) << fieldmv,
688 src_x - s->
mspel, src_y - (s->
mspel << fieldmv),
697 for (j = 0; j < 9 + s->
mspel * 2; j++) {
698 for (i = 0; i < 9 + s->
mspel * 2; i++)
699 src[i] = ((src[i] - 128) >> 1) + 128;
709 for (j = 0; j < 9 + s->
mspel * 2; j++) {
710 for (i = 0; i < 9 + s->
mspel * 2; i++)
711 src[i] = v->
luty[src[i]];
719 dxy = ((my & 3) << 2) | (mx & 3);
722 dxy = (my & 2) | ((mx & 2) >> 1);
733 static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
735 idx = ((a[3] != flag) << 3)
736 | ((a[2] != flag) << 2)
737 | ((a[1] != flag) << 1)
740 *tx =
median4(mvx[0], mvx[1], mvx[2], mvx[3]);
741 *ty =
median4(mvy[0], mvy[1], mvy[2], mvy[3]);
743 }
else if (count[idx] == 1) {
746 *tx =
mid_pred(mvx[1], mvx[2], mvx[3]);
747 *ty =
mid_pred(mvy[1], mvy[2], mvy[3]);
750 *tx =
mid_pred(mvx[0], mvx[2], mvx[3]);
751 *ty =
mid_pred(mvy[0], mvy[2], mvy[3]);
754 *tx =
mid_pred(mvx[0], mvx[1], mvx[3]);
755 *ty =
mid_pred(mvy[0], mvy[1], mvy[3]);
758 *tx =
mid_pred(mvx[0], mvx[1], mvx[2]);
759 *ty =
mid_pred(mvy[0], mvy[1], mvy[2]);
762 }
else if (count[idx] == 2) {
764 for (i = 0; i < 3; i++)
769 for (i = t1 + 1; i < 4; i++)
774 *tx = (mvx[
t1] + mvx[
t2]) / 2;
775 *ty = (mvy[
t1] + mvy[
t2]) / 2;
790 int uvmx, uvmy, uvsrc_x, uvsrc_y;
791 int k, tx = 0, ty = 0;
792 int mvx[4], mvy[4], intra[4], mv_f[4];
802 for (k = 0; k < 4; k++) {
803 mvx[k] = s->
mv[dir][k][0];
804 mvy[k] = s->
mv[dir][k][1];
822 if (mv_f[0] + mv_f[1] + mv_f[2] + mv_f[3] > 2)
824 valid_count =
get_chroma_mv(mvx, mvy, mv_f, dominant, &tx, &ty);
832 uvmx = (tx + ((tx & 3) == 3)) >> 1;
833 uvmy = (ty + ((ty & 3) == 3)) >> 1;
839 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
840 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
844 uvmy += 2 - 4 * chroma_ref_type;
846 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
847 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
850 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
851 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
882 if (chroma_ref_type) {
891 || (
unsigned)uvsrc_x > (s->
h_edge_pos >> 1) - 9
892 || (
unsigned)uvsrc_y > (v_edge_pos >> 1) - 9) {
894 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
897 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
909 for (j = 0; j < 9; j++) {
910 for (i = 0; i < 9; i++) {
911 src[i] = ((src[i] - 128) >> 1) + 128;
912 src2[i] = ((src2[i] - 128) >> 1) + 128;
925 for (j = 0; j < 9; j++) {
926 for (i = 0; i < 9; i++) {
927 src[i] = v->
lutuv[src[i]];
928 src2[i] = v->
lutuv[src2[i]];
937 uvmx = (uvmx & 3) << 1;
938 uvmy = (uvmy & 3) << 1;
955 int uvsrc_x, uvsrc_y;
956 int uvmx_field[4], uvmy_field[4];
959 static const int s_rndtblfield[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 };
960 int v_dist = fieldmv ? 1 : 4;
968 for (i = 0; i < 4; i++) {
970 uvmx_field[i] = (tx + ((tx & 3) == 3)) >> 1;
973 uvmy_field[i] = (ty >> 4) * 8 + s_rndtblfield[ty & 0xF];
975 uvmy_field[i] = (ty + ((ty & 3) == 3)) >> 1;
978 for (i = 0; i < 4; i++) {
979 off = (i & 1) * 4 + ((i & 2) ? v_dist * s->
uvlinesize : 0);
980 uvsrc_x = s->
mb_x * 8 + (i & 1) * 4 + (uvmx_field[i] >> 2);
981 uvsrc_y = s->
mb_y * 8 + ((i & 2) ? v_dist : 0) + (uvmy_field[i] >> 2);
987 uvmx_field[i] = (uvmx_field[i] & 3) << 1;
988 uvmy_field[i] = (uvmy_field[i] & 3) << 1;
990 if (fieldmv && !(uvsrc_y & 1))
993 if (fieldmv && (uvsrc_y & 1) && uvsrc_y < 2)
996 || s->
h_edge_pos < 10 || v_edge_pos < (5 << fieldmv)
997 || (
unsigned)uvsrc_x > (s->
h_edge_pos >> 1) - 5
998 || (
unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) {
1000 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
1003 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
1015 for (j = 0; j < 5; j++) {
1016 for (i = 0; i < 5; i++) {
1017 src[i] = v->
lutuv[src[i]];
1018 src2[i] = v->
lutuv[src2[i]];
1046 #define GET_MQUANT() \
1047 if (v->dquantfrm) { \
1049 if (v->dqprofile == DQPROFILE_ALL_MBS) { \
1050 if (v->dqbilevel) { \
1051 mquant = (get_bits1(gb)) ? v->altpq : v->pq; \
1053 mqdiff = get_bits(gb, 3); \
1055 mquant = v->pq + mqdiff; \
1057 mquant = get_bits(gb, 5); \
1060 if (v->dqprofile == DQPROFILE_SINGLE_EDGE) \
1061 edges = 1 << v->dqsbedge; \
1062 else if (v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
1063 edges = (3 << v->dqsbedge) % 15; \
1064 else if (v->dqprofile == DQPROFILE_FOUR_EDGES) \
1066 if ((edges&1) && !s->mb_x) \
1067 mquant = v->altpq; \
1068 if ((edges&2) && s->first_slice_line) \
1069 mquant = v->altpq; \
1070 if ((edges&4) && s->mb_x == (s->mb_width - 1)) \
1071 mquant = v->altpq; \
1072 if ((edges&8) && s->mb_y == (s->mb_height - 1)) \
1073 mquant = v->altpq; \
1074 if (!mquant || mquant > 31) { \
1075 av_log(v->s.avctx, AV_LOG_ERROR, \
1076 "Overriding invalid mquant %d\n", mquant); \
1088 #define GET_MVDATA(_dmv_x, _dmv_y) \
1089 index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table, \
1090 VC1_MV_DIFF_VLC_BITS, 2); \
1092 mb_has_coeffs = 1; \
1095 mb_has_coeffs = 0; \
1098 _dmv_x = _dmv_y = 0; \
1099 } else if (index == 35) { \
1100 _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
1101 _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
1102 } else if (index == 36) { \
1107 index1 = index % 6; \
1108 if (!s->quarter_sample && index1 == 5) val = 1; \
1110 if (size_table[index1] - val > 0) \
1111 val = get_bits(gb, size_table[index1] - val); \
1113 sign = 0 - (val&1); \
1114 _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
1116 index1 = index / 6; \
1117 if (!s->quarter_sample && index1 == 5) val = 1; \
1119 if (size_table[index1] - val > 0) \
1120 val = get_bits(gb, size_table[index1] - val); \
1122 sign = 0 - (val & 1); \
1123 _dmv_y = (sign ^ ((val >> 1) + offset_table[index1])) - sign; \
1127 int *dmv_y,
int *pred_flag)
1130 int extend_x = 0, extend_y = 0;
1134 const int* offs_tab;
1151 extend_x = extend_y = 1;
1160 *pred_flag = *dmv_y & 1;
1161 *dmv_y = (*dmv_y + *pred_flag) >> 1;
1163 *dmv_y = (*dmv_y + (*dmv_y & 1)) >> 1;
1173 index1 = (index + 1) % 9;
1175 val =
get_bits(gb, index1 + extend_x);
1176 sign = 0 -(val & 1);
1177 *dmv_x = (sign ^ ((val >> 1) + offs_tab[index1])) - sign;
1184 index1 = (index + 1) / 9;
1185 if (index1 > v->
numref) {
1187 sign = 0 - (val & 1);
1188 *dmv_y = (sign ^ ((val >> 1) + offs_tab[index1 >> v->
numref])) - sign;
1191 if (v->
numref && pred_flag)
1192 *pred_flag = index1 & 1;
1198 int scaledvalue, refdist;
1199 int scalesame1, scalesame2;
1200 int scalezone1_x, zone1offset_x;
1217 if (
FFABS(n) < scalezone1_x)
1218 scaledvalue = (n * scalesame1) >> 8;
1221 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_x;
1223 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_x;
1231 int scaledvalue, refdist;
1232 int scalesame1, scalesame2;
1233 int scalezone1_y, zone1offset_y;
1250 if (
FFABS(n) < scalezone1_y)
1251 scaledvalue = (n * scalesame1) >> 8;
1254 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_y;
1256 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_y;
1261 return av_clip(scaledvalue, -v->
range_y / 2 + 1, v->
range_y / 2);
1263 return av_clip(scaledvalue, -v->
range_y / 2, v->
range_y / 2 - 1);
1268 int scalezone1_x, zone1offset_x;
1269 int scaleopp1, scaleopp2, brfd;
1281 if (
FFABS(n) < scalezone1_x)
1282 scaledvalue = (n * scaleopp1) >> 8;
1285 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_x;
1287 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_x;
1295 int scalezone1_y, zone1offset_y;
1296 int scaleopp1, scaleopp2, brfd;
1308 if (
FFABS(n) < scalezone1_y)
1309 scaledvalue = (n * scaleopp1) >> 8;
1312 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_y;
1314 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_y;
1318 return av_clip(scaledvalue, -v->
range_y / 2 + 1, v->
range_y / 2);
1320 return av_clip(scaledvalue, -v->
range_y / 2, v->
range_y / 2 - 1);
1327 int brfd, scalesame;
1341 n = (n * scalesame >> 8) << hpel;
1348 int refdist, scaleopp;
1365 n = (n * scaleopp >> 8) << hpel;
1372 int mv1,
int r_x,
int r_y,
uint8_t* is_intra,
1373 int pred_flag,
int dir)
1380 int mixedmv_pic, num_samefield = 0, num_oppfield = 0;
1381 int opposite, a_f, b_f, c_f;
1382 int16_t field_predA[2];
1383 int16_t field_predB[2];
1384 int16_t field_predC[2];
1385 int a_valid, b_valid, c_valid;
1386 int hybridmv_thresh, y_bias = 0;
1434 off = (s->
mb_x > 0) ? -1 : 1;
1449 b_valid = a_valid && (s->
mb_width > 1);
1450 c_valid = s->
mb_x || (n == 1 || n == 3);
1452 a_valid = a_valid && !is_intra[xy -
wrap];
1453 b_valid = b_valid && !is_intra[xy - wrap +
off];
1454 c_valid = c_valid && !is_intra[xy - 1];
1459 num_oppfield += a_f;
1460 num_samefield += 1 - a_f;
1461 field_predA[0] = A[0];
1462 field_predA[1] = A[1];
1464 field_predA[0] = field_predA[1] = 0;
1469 num_oppfield += b_f;
1470 num_samefield += 1 - b_f;
1471 field_predB[0] = B[0];
1472 field_predB[1] = B[1];
1474 field_predB[0] = field_predB[1] = 0;
1479 num_oppfield += c_f;
1480 num_samefield += 1 - c_f;
1481 field_predC[0] = C[0];
1482 field_predC[1] = C[1];
1484 field_predC[0] = field_predC[1] = 0;
1494 if (num_samefield <= num_oppfield)
1495 opposite = 1 - pred_flag;
1497 opposite = pred_flag;
1502 if (a_valid && !a_f) {
1503 field_predA[0] =
scaleforopp(v, field_predA[0], 0, dir);
1504 field_predA[1] =
scaleforopp(v, field_predA[1], 1, dir);
1506 if (b_valid && !b_f) {
1507 field_predB[0] =
scaleforopp(v, field_predB[0], 0, dir);
1508 field_predB[1] =
scaleforopp(v, field_predB[1], 1, dir);
1510 if (c_valid && !c_f) {
1511 field_predC[0] =
scaleforopp(v, field_predC[0], 0, dir);
1512 field_predC[1] =
scaleforopp(v, field_predC[1], 1, dir);
1517 if (a_valid && a_f) {
1518 field_predA[0] =
scaleforsame(v, n, field_predA[0], 0, dir);
1519 field_predA[1] =
scaleforsame(v, n, field_predA[1], 1, dir);
1521 if (b_valid && b_f) {
1522 field_predB[0] =
scaleforsame(v, n, field_predB[0], 0, dir);
1523 field_predB[1] =
scaleforsame(v, n, field_predB[1], 1, dir);
1525 if (c_valid && c_f) {
1526 field_predC[0] =
scaleforsame(v, n, field_predC[0], 0, dir);
1527 field_predC[1] =
scaleforsame(v, n, field_predC[1], 1, dir);
1534 px = field_predA[0];
1535 py = field_predA[1];
1536 }
else if (c_valid) {
1537 px = field_predC[0];
1538 py = field_predC[1];
1539 }
else if (b_valid) {
1540 px = field_predB[0];
1541 py = field_predB[1];
1547 if (num_samefield + num_oppfield > 1) {
1548 px =
mid_pred(field_predA[0], field_predB[0], field_predC[0]);
1549 py =
mid_pred(field_predA[1], field_predB[1], field_predC[1]);
1555 qx = (s->
mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0);
1556 qy = (s->
mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0);
1560 if (qx + px < -60) px = -60 - qx;
1561 if (qy + py < -60) py = -60 - qy;
1563 if (qx + px < -28) px = -28 - qx;
1564 if (qy + py < -28) py = -28 - qy;
1566 if (qx + px > X) px = X - qx;
1567 if (qy + py > Y) py = Y - qy;
1572 hybridmv_thresh = 32;
1573 if (a_valid && c_valid) {
1574 if (is_intra[xy - wrap])
1577 sum =
FFABS(px - field_predA[0]) +
FFABS(py - field_predA[1]);
1578 if (sum > hybridmv_thresh) {
1580 px = field_predA[0];
1581 py = field_predA[1];
1583 px = field_predC[0];
1584 py = field_predC[1];
1587 if (is_intra[xy - 1])
1590 sum =
FFABS(px - field_predC[0]) +
FFABS(py - field_predC[1]);
1591 if (sum > hybridmv_thresh) {
1593 px = field_predA[0];
1594 py = field_predA[1];
1596 px = field_predC[0];
1597 py = field_predC[1];
1626 int mvn,
int r_x,
int r_y,
uint8_t* is_intra)
1630 int A[2],
B[2],
C[2];
1632 int a_valid = 0, b_valid = 0, c_valid = 0;
1633 int field_a, field_b, field_c;
1634 int total_valid, num_samefield, num_oppfield;
1635 int pos_c, pos_b, n_adj;
1663 off = ((n == 0) || (n == 1)) ? 1 : -1;
1665 if (s->
mb_x || (n == 1) || (n == 3)) {
1685 B[0] = B[1] = C[0] = C[1] = 0;
1693 n_adj = (n & 2) | (n & 1);
1747 total_valid = a_valid + b_valid + c_valid;
1749 if (!s->
mb_x && !(n == 1 || n == 3)) {
1754 B[0] = B[1] = C[0] = C[1] = 0;
1761 if (total_valid >= 2) {
1764 }
else if (total_valid) {
1765 if (a_valid) { px = A[0]; py = A[1]; }
1766 else if (b_valid) { px = B[0]; py = B[1]; }
1767 else if (c_valid) { px = C[0]; py = C[1]; }
1774 field_a = (A[1] & 4) ? 1 : 0;
1778 field_b = (B[1] & 4) ? 1 : 0;
1782 field_c = (C[1] & 4) ? 1 : 0;
1786 num_oppfield = field_a + field_b + field_c;
1787 num_samefield = total_valid - num_oppfield;
1788 if (total_valid == 3) {
1789 if ((num_samefield == 3) || (num_oppfield == 3)) {
1792 }
else if (num_samefield >= num_oppfield) {
1795 px = !field_a ? A[0] : B[0];
1796 py = !field_a ? A[1] : B[1];
1798 px = field_a ? A[0] : B[0];
1799 py = field_a ? A[1] : B[1];
1801 }
else if (total_valid == 2) {
1802 if (num_samefield >= num_oppfield) {
1803 if (!field_a && a_valid) {
1806 }
else if (!field_b && b_valid) {
1809 }
else if (c_valid) {
1814 if (field_a && a_valid) {
1817 }
else if (field_b && b_valid) {
1820 }
else if (c_valid) {
1825 }
else if (total_valid == 1) {
1826 px = (a_valid) ? A[0] : ((b_valid) ? B[0] : C[0]);
1827 py = (a_valid) ? A[1] : ((b_valid) ? B[1] : C[1]);
1842 }
else if (mvn == 2) {
1845 s->
mv[0][n + 1][0] = s->
mv[0][n][0];
1846 s->
mv[0][n + 1][1] = s->
mv[0][n][1];
1858 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
1865 mx = s->
mv[1][0][0];
1866 my = s->
mv[1][0][1];
1867 uvmx = (mx + ((mx & 3) == 3)) >> 1;
1868 uvmy = (my + ((my & 3) == 3)) >> 1;
1875 uvmx = uvmx + ((uvmx < 0) ? -(uvmx & 1) : (uvmx & 1));
1876 uvmy = uvmy + ((uvmy < 0) ? -(uvmy & 1) : (uvmy & 1));
1882 src_x = s->
mb_x * 16 + (mx >> 2);
1883 src_y = s->
mb_y * 16 + (my >> 2);
1884 uvsrc_x = s->
mb_x * 8 + (uvmx >> 2);
1885 uvsrc_y = s->
mb_y * 8 + (uvmy >> 2);
1888 src_x = av_clip( src_x, -16, s->
mb_width * 16);
1889 src_y = av_clip( src_y, -16, s->
mb_height * 16);
1890 uvsrc_x = av_clip(uvsrc_x, -8, s->
mb_width * 8);
1891 uvsrc_y = av_clip(uvsrc_y, -8, s->
mb_height * 8);
1899 srcY += src_y * s->
linesize + src_x;
1916 || (
unsigned)(src_x - 1) > s->
h_edge_pos - (mx & 3) - 16 - 3
1917 || (
unsigned)(src_y - 1) > v_edge_pos - (my & 3) - 16 - 3) {
1927 uvsrc_x, uvsrc_y, s->
h_edge_pos >> 1, v_edge_pos >> 1);
1929 uvsrc_x, uvsrc_y, s->
h_edge_pos >> 1, v_edge_pos >> 1);
1938 for (j = 0; j < 17 + s->
mspel * 2; j++) {
1939 for (i = 0; i < 17 + s->
mspel * 2; i++)
1940 src[i] = ((src[i] - 128) >> 1) + 128;
1945 for (j = 0; j < 9; j++) {
1946 for (i = 0; i < 9; i++) {
1947 src[i] = ((src[i] - 128) >> 1) + 128;
1948 src2[i] = ((src2[i] - 128) >> 1) + 128;
1961 dxy = ((my & 3) << 2) | (mx & 3);
1968 dxy = (my & 2) | ((mx & 2) >> 1);
1978 uvmx = (uvmx & 3) << 1;
1979 uvmy = (uvmy & 3) << 1;
1993 #if B_FRACTION_DEN==256
1997 return 2 * ((value * n + 255) >> 9);
1998 return (value * n + 128) >> 8;
2011 int direct,
int mode)
2040 int direct,
int mvtype)
2075 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));
2076 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));
2077 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));
2078 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));
2094 if (!s->
mb_x) C[0] = C[1] = 0;
2103 }
else if (s->
mb_x) {
2113 qx = (s->
mb_x << 5);
2114 qy = (s->
mb_y << 5);
2117 if (qx + px < -28) px = -28 - qx;
2118 if (qy + py < -28) py = -28 - qy;
2119 if (qx + px > X) px = X - qx;
2120 if (qy + py > Y) py = Y - qy;
2122 qx = (s->
mb_x << 6);
2123 qy = (s->
mb_y << 6);
2126 if (qx + px < -60) px = -60 - qx;
2127 if (qy + py < -60) py = -60 - qy;
2128 if (qx + px > X) px = X - qx;
2129 if (qy + py > Y) py = Y - qy;
2134 if (is_intra[xy - wrap])
2147 if (is_intra[xy - 2])
2163 s->
mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
2164 s->
mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
2182 }
else if (s->
mb_x) {
2192 qx = (s->
mb_x << 5);
2193 qy = (s->
mb_y << 5);
2196 if (qx + px < -28) px = -28 - qx;
2197 if (qy + py < -28) py = -28 - qy;
2198 if (qx + px > X) px = X - qx;
2199 if (qy + py > Y) py = Y - qy;
2201 qx = (s->
mb_x << 6);
2202 qy = (s->
mb_y << 6);
2205 if (qx + px < -60) px = -60 - qx;
2206 if (qy + py < -60) py = -60 - qy;
2207 if (qx + px > X) px = X - qx;
2208 if (qy + py > Y) py = Y - qy;
2213 if (is_intra[xy - wrap])
2226 if (is_intra[xy - 2])
2243 s->
mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
2244 s->
mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
2259 int total_opp, k, f;
2274 f = (total_opp > 2) ? 1 : 0;
2276 s->
mv[0][0][0] = s->
mv[0][0][1] = 0;
2277 s->
mv[1][0][0] = s->
mv[1][0][1] = 0;
2281 for (k = 0; k < 4; k++) {
2298 if (n == 3 || mv1) {
2303 if (n == 3 || mv1) {
2319 int16_t **dc_val_ptr,
int *dir_ptr)
2323 static const uint16_t dcpred[32] = {
2324 -1, 1024, 512, 341, 256, 205, 171, 146, 128,
2325 114, 102, 93, 85, 79, 73, 68, 64,
2326 60, 57, 54, 51, 49, 47, 45, 43,
2327 41, 39, 38, 37, 35, 34, 33
2341 b = dc_val[ - 1 -
wrap];
2342 a = dc_val[ -
wrap];
2344 if (pq < 9 || !overlap) {
2347 b = a = dcpred[
scale];
2348 if (s->
mb_x == 0 && (n != 1 && n != 3))
2349 b = c = dcpred[
scale];
2354 if (s->
mb_x == 0 && (n != 1 && n != 3))
2358 if (abs(a - b) <= abs(b - c)) {
2367 *dc_val_ptr = &dc_val[0];
2384 int a_avail,
int c_avail,
2385 int16_t **dc_val_ptr,
int *dir_ptr)
2400 b = dc_val[ - 1 -
wrap];
2401 a = dc_val[ -
wrap];
2405 if (dqscale_index < 0)
2407 if (c_avail && (n != 1 && n != 3)) {
2412 if (a_avail && (n != 2 && n != 3)) {
2417 if (a_avail && c_avail && (n != 3)) {
2428 if (a_avail && c_avail) {
2429 if (abs(a - b) <= abs(b - c)) {
2436 }
else if (a_avail) {
2439 }
else if (c_avail) {
2448 *dc_val_ptr = &dc_val[0];
2497 int *
value,
int codingset)
2563 int coded,
int codingset)
2567 int dc_pred_dir = 0;
2570 int16_t *ac_val, *ac_val2;
2584 if (dcdiff == 119 ) {
2587 else if (v->
pq == 2) dcdiff =
get_bits(gb, 9);
2591 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
2592 else if (v->
pq == 2)
2593 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
2618 int last = 0, skip,
value;
2645 block[zz_table[i++]] =
value;
2651 for (k = 1; k < 8; k++)
2654 for (k = 1; k < 8; k++)
2659 for (k = 1; k < 8; k++) {
2665 for (k = 1; k < 64; k++)
2669 block[k] += (block[k] < 0) ? -v->
pq : v->
pq;
2683 memset(ac_val2, 0, 16 * 2);
2687 memcpy(ac_val2, ac_val, 8 * 2);
2691 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
2697 for (k = 1; k < 8; k++) {
2703 for (k = 1; k < 8; k++) {
2726 int coded,
int codingset,
int mquant)
2730 int dc_pred_dir = 0;
2732 int16_t *dc_val =
NULL;
2733 int16_t *ac_val, *ac_val2;
2752 if (dcdiff == 119 ) {
2754 if (mquant == 1) dcdiff =
get_bits(gb, 10);
2755 else if (mquant == 2) dcdiff =
get_bits(gb, 9);
2759 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
2760 else if (mquant == 2)
2761 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
2782 if (!a_avail && !c_avail)
2787 scale = mquant * 2 + ((mquant == v->
pq) ? v->
halfpq : 0);
2795 if ( dc_pred_dir && c_avail && mb_pos)
2797 if (!dc_pred_dir && a_avail && mb_pos >= s->
mb_stride)
2799 if ( dc_pred_dir && n == 1)
2801 if (!dc_pred_dir && n == 2)
2807 int last = 0, skip,
value;
2832 block[zz_table[i++]] =
value;
2838 if (q2 && q1 != q2) {
2839 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2840 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2845 for (k = 1; k < 8; k++)
2848 for (k = 1; k < 8; k++)
2853 for (k = 1; k < 8; k++)
2856 for (k = 1; k < 8; k++)
2862 for (k = 1; k < 8; k++) {
2868 for (k = 1; k < 64; k++)
2872 block[k] += (block[k] < 0) ? -mquant : mquant;
2875 if (use_pred) i = 63;
2879 memset(ac_val2, 0, 16 * 2);
2882 memcpy(ac_val2, ac_val, 8 * 2);
2883 if (q2 && q1 != q2) {
2884 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2885 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2888 for (k = 1; k < 8; k++)
2889 ac_val2[k] = (ac_val2[k] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2894 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
2895 if (q2 && q1 != q2) {
2896 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
2897 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
2900 for (k = 1; k < 8; k++)
2901 ac_val2[k + 8] = (ac_val2[k + 8] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2909 for (k = 1; k < 8; k++) {
2915 for (k = 1; k < 8; k++) {
2938 int coded,
int mquant,
int codingset)
2942 int dc_pred_dir = 0;
2944 int16_t *dc_val =
NULL;
2945 int16_t *ac_val, *ac_val2;
2956 mquant = (mquant < 1) ? 0 : ((mquant > 31) ? 31 : mquant);
2973 if (dcdiff == 119 ) {
2975 if (mquant == 1) dcdiff =
get_bits(gb, 10);
2976 else if (mquant == 2) dcdiff =
get_bits(gb, 9);
2980 dcdiff = (dcdiff << 2) +
get_bits(gb, 2) - 3;
2981 else if (mquant == 2)
2982 dcdiff = (dcdiff << 1) +
get_bits1(gb) - 1;
2989 dcdiff +=
vc1_pred_dc(&v->
s, v->
overlap, mquant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
3004 if (!a_avail) dc_pred_dir = 1;
3005 if (!c_avail) dc_pred_dir = 0;
3006 if (!a_avail && !c_avail) use_pred = 0;
3010 scale = mquant * 2 + v->
halfpq;
3018 if (dc_pred_dir && c_avail && mb_pos)
3020 if (!dc_pred_dir && a_avail && mb_pos >= s->
mb_stride)
3022 if ( dc_pred_dir && n == 1)
3024 if (!dc_pred_dir && n == 2)
3026 if (n == 3) q2 = q1;
3029 int last = 0, skip,
value;
3054 if (q2 && q1 != q2) {
3055 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3056 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3061 for (k = 1; k < 8; k++)
3064 for (k = 1; k < 8; k++)
3069 for (k = 1; k < 8; k++)
3072 for (k = 1; k < 8; k++)
3078 for (k = 1; k < 8; k++) {
3084 for (k = 1; k < 64; k++)
3088 block[k] += (block[k] < 0) ? -mquant : mquant;
3091 if (use_pred) i = 63;
3095 memset(ac_val2, 0, 16 * 2);
3098 memcpy(ac_val2, ac_val, 8 * 2);
3099 if (q2 && q1 != q2) {
3100 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3101 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3104 for (k = 1; k < 8; k++)
3105 ac_val2[k] = (ac_val2[k] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
3110 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
3111 if (q2 && q1 != q2) {
3112 q1 = q1 * 2 + ((q1 == v->
pq) ? v->
halfpq : 0) - 1;
3113 q2 = q2 * 2 + ((q2 == v->
pq) ? v->
halfpq : 0) - 1;
3116 for (k = 1; k < 8; k++)
3117 ac_val2[k + 8] = (ac_val2[k + 8] * q2 *
ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
3125 for (k = 1; k < 8; k++) {
3131 for (k = 1; k < 8; k++) {
3148 int mquant,
int ttmb,
int first_block,
3157 int ttblk = ttmb & 7;
3169 && ((v->
ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
3179 scale = 2 * mquant + ((v->
pq == mquant) ? v->
halfpq : 0);
3204 block[idx] = value *
scale;
3206 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3218 pat = ~subblkpat & 0xF;
3219 for (j = 0; j < 4; j++) {
3220 last = subblkpat & (1 << (3 - j));
3222 off = (j & 1) * 4 + (j & 2) * 16;
3234 block[idx +
off] += (block[idx +
off] < 0) ? -mquant : mquant;
3236 if (!(subblkpat & (1 << (3 - j))) && !skip_block) {
3245 pat = ~((subblkpat & 2) * 6 + (subblkpat & 1) * 3) & 0xF;
3246 for (j = 0; j < 2; j++) {
3247 last = subblkpat & (1 << (1 - j));
3259 block[idx] = value *
scale;
3261 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3263 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
3272 pat = ~(subblkpat * 5) & 0xF;
3273 for (j = 0; j < 2; j++) {
3274 last = subblkpat & (1 << (1 - j));
3286 block[idx] = value *
scale;
3288 block[idx] += (block[idx] < 0) ? -mquant : mquant;
3290 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
3300 *ttmb_out |= ttblk << (n * 4);
3313 block_cbp = mb_cbp >> (block_num * 4), bottom_cbp,
3315 block_is_intra = mb_is_intra >> (block_num * 4), bottom_is_intra;
3319 if (block_num > 3) {
3320 dst = s->
dest[block_num - 3];
3322 dst = s->
dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 8) * linesize;
3328 if (block_num > 3) {
3329 bottom_cbp = v->
cbp[s->
mb_x] >> (block_num * 4);
3330 bottom_is_intra = v->
is_intra[s->
mb_x] >> (block_num * 4);
3334 bottom_cbp = (block_num < 2) ? (mb_cbp >> ((block_num + 2) * 4))
3335 : (v->
cbp[s->
mb_x] >> ((block_num - 2) * 4));
3336 bottom_is_intra = (block_num < 2) ? (mb_is_intra >> ((block_num + 2) * 4))
3342 if (bottom_is_intra & 1 || block_is_intra & 1 ||
3343 mv[0][0] !=
mv[mv_stride][0] ||
mv[0][1] !=
mv[mv_stride][1]) {
3346 idx = ((bottom_cbp >> 2) | block_cbp) & 3;
3358 dst -= 4 * linesize;
3361 idx = (block_cbp | (block_cbp >> 2)) & 3;
3377 block_cbp = mb_cbp >> (block_num * 4), right_cbp,
3379 block_is_intra = mb_is_intra >> (block_num * 4), right_is_intra;
3383 if (block_num > 3) {
3384 dst = s->
dest[block_num - 3] - 8 * linesize;
3386 dst = s->
dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 16) * linesize - 8;
3392 if (block_num > 3) {
3397 right_cbp = (block_num & 1) ? (v->
cbp[s->
mb_x - s->
mb_stride] >> ((block_num - 1) * 4))
3398 : (mb_cbp >> ((block_num + 1) * 4));
3400 : (mb_is_intra >> ((block_num + 1) * 4));
3403 if (block_is_intra & 1 || right_is_intra & 1 ||
mv[0][0] !=
mv[1][0] ||
mv[0][1] !=
mv[1][1]) {
3406 idx = ((right_cbp >> 1) | block_cbp) & 5;
3421 idx = (block_cbp | (block_cbp >> 1)) & 5;
3438 for (i = 0; i < 6; i++) {
3445 for (i = 0; i < 6; i++) {
3451 for (i = 0; i < 6; i++) {
3468 int ttmb = v->
ttfrm;
3470 int mb_has_coeffs = 1;
3474 int first_block = 1;
3476 int skipped, fourmv;
3477 int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
3502 if (s->
mb_intra && !mb_has_coeffs) {
3506 }
else if (mb_has_coeffs) {
3522 for (i = 0; i < 6; i++) {
3525 val = ((cbp >> (5 - i)) & 1);
3526 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3533 if (i == 1 || i == 3 || s->
mb_x)
3542 for (j = 0; j < 64; j++)
3543 s->
block[i][j] <<= 1;
3551 block_cbp |= 0xF << (i << 2);
3552 block_intra |= 1 << i;
3557 block_cbp |= pat << (i << 2);
3558 if (!v->
ttmbf && ttmb < 8)
3565 for (i = 0; i < 6; i++) {
3576 int intra_count = 0, coded_inter = 0;
3577 int is_intra[6], is_coded[6];
3580 for (i = 0; i < 6; i++) {
3581 val = ((cbp >> (5 - i)) & 1);
3596 is_coded[i] = mb_has_coeffs;
3599 is_intra[i] = (intra_count >= 3);
3606 coded_inter = !is_intra[i] & is_coded[i];
3610 if (!intra_count && !coded_inter)
3617 for (i = 0; i < 6; i++)
3630 if (!v->
ttmbf && coded_inter)
3632 for (i = 0; i < 6; i++) {
3634 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3641 if (i == 1 || i == 3 || s->
mb_x)
3650 for (j = 0; j < 64; j++)
3651 s->
block[i][j] <<= 1;
3660 block_cbp |= 0xF << (i << 2);
3661 block_intra |= 1 << i;
3662 }
else if (is_coded[i]) {
3664 first_block, s->
dest[dst_idx] + off,
3668 block_cbp |= pat << (i << 2);
3669 if (!v->
ttmbf && ttmb < 8)
3677 for (i = 0; i < 6; i++) {
3681 for (i = 0; i < 4; i++) {
3707 int ttmb = v->
ttfrm;
3709 int mb_has_coeffs = 1;
3712 int first_block = 1;
3714 int skipped, fourmv = 0, twomv = 0;
3715 int block_cbp = 0, pat, block_tt = 0;
3716 int idx_mbmode = 0, mvbp;
3717 int stride_y, fieldtx;
3765 for (i = 0; i < 6; i++)
3778 for (i = 0; i < 6; i++) {
3781 val = ((cbp >> (5 - i)) & 1);
3786 if (i == 1 || i == 3 || s->
mb_x)
3795 off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->
linesize : (i & 1) * 8 + 4 * (i & 2) * s->
linesize;
3817 for (i = 0; i < 6; i++)
3824 for (i = 0; i < 6; i++) {
3827 val = ((mvbp >> (3 - i)) & 1);
3833 }
else if (i == 4) {
3866 if (!v->
ttmbf && cbp)
3868 for (i = 0; i < 6; i++) {
3871 val = ((cbp >> (5 - i)) & 1);
3873 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3875 off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->
linesize));
3878 first_block, s->
dest[dst_idx] + off,
3881 block_cbp |= pat << (i << 2);
3882 if (!v->
ttmbf && ttmb < 8)
3890 for (i = 0; i < 6; i++) {
3916 int ttmb = v->
ttfrm;
3918 int mb_has_coeffs = 1;
3921 int first_block = 1;
3924 int block_cbp = 0, pat, block_tt = 0;
3930 if (idx_mbmode <= 1) {
3941 mb_has_coeffs = idx_mbmode & 1;
3945 for (i = 0; i < 6; i++) {
3949 val = ((cbp >> (5 - i)) & 1);
3953 if (i == 1 || i == 3 || s->
mb_x)
3961 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
3969 if (idx_mbmode <= 5) {
3970 dmv_x = dmv_y = pred_flag = 0;
3971 if (idx_mbmode & 1) {
3976 mb_has_coeffs = !(idx_mbmode & 2);
3979 for (i = 0; i < 6; i++) {
3981 dmv_x = dmv_y = pred_flag = 0;
3982 val = ((v->
fourmvbp >> (3 - i)) & 1);
3991 mb_has_coeffs = idx_mbmode & 1;
3999 if (!v->
ttmbf && cbp) {
4003 for (i = 0; i < 6; i++) {
4006 val = ((cbp >> (5 - i)) & 1);
4007 off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->
linesize;
4010 first_block, s->
dest[dst_idx] + off,
4014 block_cbp |= pat << (i << 2);
4015 if (!v->
ttmbf && ttmb < 8) ttmb = -1;
4035 int ttmb = v->
ttfrm;
4036 int mb_has_coeffs = 0;
4039 int first_block = 1;
4041 int skipped, direct;
4042 int dmv_x[2], dmv_y[2];
4057 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
4058 for (i = 0; i < 6; i++) {
4067 dmv_x[1] = dmv_x[0];
4068 dmv_y[1] = dmv_y[0];
4081 dmv_x[0] = dmv_y[0] = 0;
4085 for (i = 0; i < 6; i++)
4092 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4102 dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
4104 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4106 if (!mb_has_coeffs && !s->
mb_intra) {
4109 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4112 if (s->
mb_intra && !mb_has_coeffs) {
4121 if (!mb_has_coeffs) {
4124 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4130 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
4142 for (i = 0; i < 6; i++) {
4145 val = ((cbp >> (5 - i)) & 1);
4146 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->
linesize);
4153 if (i == 1 || i == 3 || s->
mb_x)
4162 for (j = 0; j < 64; j++)
4163 s->
block[i][j] <<= 1;
4167 first_block, s->
dest[dst_idx] + off,
4170 if (!v->
ttmbf && ttmb < 8)
4187 int ttmb = v->
ttfrm;
4188 int mb_has_coeffs = 0;
4190 int first_block = 1;
4193 int dmv_x[2], dmv_y[2], pred_flag[2];
4195 int idx_mbmode, interpmvp;
4201 if (idx_mbmode <= 1) {
4212 mb_has_coeffs = idx_mbmode & 1;
4216 for (i = 0; i < 6; i++) {
4219 val = ((cbp >> (5 - i)) & 1);
4224 if (i == 1 || i == 3 || s->
mb_x)
4233 for (j = 0; j < 64; j++)
4234 s->
block[i][j] <<= 1;
4235 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;
4319 first_block, s->
dest[dst_idx] + off,
4322 if (!v->
ttmbf && ttmb < 8)
4379 dst[0] = s->
dest[0];
4380 dst[1] = dst[0] + 8;
4382 dst[3] = dst[2] + 8;
4383 dst[4] = s->
dest[1];
4384 dst[5] = s->
dest[2];
4396 for (k = 0; k < 6; k++) {
4397 val = ((cbp >> (5 - k)) & 1);
4404 cbp |= val << (5 - k);
4413 for (j = 0; j < 64; j++)
4414 s->
block[k][j] <<= 1;
4418 for (j = 0; j < 64; j++)
4550 for (k = 0; k < 6; k++) {
4551 val = ((cbp >> (5 - k)) & 1);
4558 cbp |= val << (5 - k);
4800 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
4816 int effect_type, effect_flag;
4817 int effect_pcount1, effect_pcount2;
4818 int effect_params1[15], effect_params2[10];
4826 static void vc1_sprite_parse_transform(
GetBitContext* gb,
int c[7])
4833 c[2] = get_fp_val(gb);
4837 c[0] = c[4] = get_fp_val(gb);
4838 c[2] = get_fp_val(gb);
4841 c[0] = get_fp_val(gb);
4842 c[2] = get_fp_val(gb);
4843 c[4] = get_fp_val(gb);
4846 c[0] = get_fp_val(gb);
4847 c[1] = get_fp_val(gb);
4848 c[2] = get_fp_val(gb);
4849 c[3] = get_fp_val(gb);
4850 c[4] = get_fp_val(gb);
4853 c[5] = get_fp_val(gb);
4855 c[6] = get_fp_val(gb);
4865 for (sprite = 0; sprite <= v->
two_sprites; sprite++) {
4866 vc1_sprite_parse_transform(gb, sd->coefs[sprite]);
4867 if (sd->coefs[sprite][1] || sd->coefs[sprite][3])
4870 for (i = 0; i < 7; i++)
4872 sd->coefs[sprite][i] / (1<<16),
4873 (abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1 << 16));
4879 switch (sd->effect_pcount1 =
get_bits(gb, 4)) {
4881 vc1_sprite_parse_transform(gb, sd->effect_params1);
4884 vc1_sprite_parse_transform(gb, sd->effect_params1);
4885 vc1_sprite_parse_transform(gb, sd->effect_params1 + 7);
4888 for (i = 0; i < sd->effect_pcount1; i++)
4889 sd->effect_params1[i] = get_fp_val(gb);
4891 if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) {
4894 for (i = 0; i < sd->effect_pcount1; i++)
4896 sd->effect_params1[i] / (1 << 16),
4897 (abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1 << 16));
4901 sd->effect_pcount2 =
get_bits(gb, 16);
4902 if (sd->effect_pcount2 > 10) {
4905 }
else if (sd->effect_pcount2) {
4908 while (++i < sd->effect_pcount2) {
4909 sd->effect_params2[i] = get_fp_val(gb);
4911 sd->effect_params2[i] / (1 << 16),
4912 (abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1 << 16));
4927 static void vc1_draw_sprites(
VC1Context *v, SpriteData* sd)
4929 int i, plane, row, sprite;
4930 int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } };
4932 int xoff[2], xadv[2], yoff[2], yadv[2],
alpha;
4936 for (i = 0; i < 2; i++) {
4937 xoff[i] = av_clip(sd->coefs[i][2], 0, v->
sprite_width-1 << 16);
4938 xadv[i] = sd->coefs[i][0];
4942 yoff[i] = av_clip(sd->coefs[i][5], 0, v->
sprite_height-1 << 16);
4945 alpha = av_clip(sd->coefs[1][6], 0, (1<<16) - 1);
4954 for (sprite = 0; sprite <= v->
two_sprites; sprite++) {
4957 int ycoord = yoff[sprite] + yadv[sprite] * row;
4958 int yline = ycoord >> 16;
4960 ysub[sprite] = ycoord & 0xFFFF;
4966 if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) {
4967 src_h[sprite][0] = iplane + (xoff[sprite] >> 16) + yline * iline;
4969 src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + next_line;
4971 if (sr_cache[sprite][0] != yline) {
4972 if (sr_cache[sprite][1] == yline) {
4974 FFSWAP(
int, sr_cache[sprite][0], sr_cache[sprite][1]);
4976 v->
vc1dsp.
sprite_h(v->
sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width);
4977 sr_cache[sprite][0] = yline;
4980 if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) {
4982 iplane + next_line, xoff[sprite],
4983 xadv[sprite], width);
4984 sr_cache[sprite][1] = yline + 1;
4986 src_h[sprite][0] = v->
sr_rows[sprite][0];
4987 src_h[sprite][1] = v->
sr_rows[sprite][1];
4995 memcpy(dst, src_h[0][0], width);
4998 if (ysub[0] && ysub[1]) {
5000 src_h[1][0], src_h[1][1], ysub[1], alpha, width);
5001 }
else if (ysub[0]) {
5003 src_h[1][0], alpha, width);
5004 }
else if (ysub[1]) {
5006 src_h[0][0], (1<<16)-1-alpha, width);
5014 for (i = 0; i < 2; i++) {
5030 vc1_parse_sprites(v, gb, &sd);
5052 vc1_draw_sprites(v, &sd);
5072 plane ? 128 : 0, f->
linesize[plane]);
5131 for (i = 0; i < 4; i++)
5146 for (i = 0; i < 64; i++) {
5147 #define transpose(x) ((x >> 3) | ((x & 7) << 3))
5215 }
else if (count < 0) {
5222 int size, buf2_size;
5224 int seq_initialized = 0, ep_initialized = 0;
5234 for (; next <
end; start = next) {
5236 size = next - start - 4;
5247 seq_initialized = 1;
5259 if (!seq_initialized || !ep_initialized) {
5315 for (i = 0; i < 4; i++)
5348 int buf_size = avpkt->
size, n_slices = 0, i;
5353 const uint8_t *buf_start = buf, *buf_start_second_field =
NULL;
5354 int mb_height, n_slices1=-1;
5359 } *slices =
NULL, *tmp;
5396 for (start = buf, end = buf + buf_size; next <
end; start = next) {
5398 size = next - start - 4;
5399 if (size <= 0)
continue;
5411 buf_start_second_field = start;
5412 tmp =
av_realloc(slices,
sizeof(*slices) * (n_slices+1));
5417 if (!slices[n_slices].buf)
5420 slices[n_slices].buf);
5425 slices[n_slices].mby_start = s->
mb_height >> 1;
5426 n_slices1 = n_slices - 1;
5437 tmp =
av_realloc(slices,
sizeof(*slices) * (n_slices+1));
5442 if (!slices[n_slices].buf)
5445 slices[n_slices].buf);
5448 slices[n_slices].mby_start =
get_bits(&slices[n_slices].gb, 9);
5454 }
else if (v->
interlace && ((buf[0] & 0xC0) == 0xC0)) {
5465 buf_start_second_field = divider;
5466 tmp =
av_realloc(slices,
sizeof(*slices) * (n_slices+1));
5471 if (!slices[n_slices].buf)
5473 buf_size3 =
vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf);
5476 slices[n_slices].mby_start = s->
mb_height >> 1;
5477 n_slices1 = n_slices - 1;
5606 if ((CONFIG_VC1_VDPAU_DECODER)
5610 if (v->
field_mode && buf_start_second_field) {
5613 if (avctx->
hwaccel->
start_frame(avctx, buf_start, buf_start_second_field - buf_start) < 0)
5615 if (avctx->
hwaccel->
decode_slice(avctx, buf_start, buf_start_second_field - buf_start) < 0)
5621 s->
gb = slices[n_slices1 + 1].gb;
5631 if (avctx->
hwaccel->
start_frame(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field) < 0)
5633 if (avctx->
hwaccel->
decode_slice(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field) < 0)
5654 v->
bits = buf_size * 8;
5669 v->
mv_f[0] = tmp[0];
5670 v->
mv_f[1] = tmp[1];
5673 for (i = 0; i <= n_slices; i++) {
5674 if (i > 0 && slices[i - 1].mby_start >= mb_height) {
5677 "picture boundary (%d >= %d)\n", i,
5678 slices[i - 1].mby_start, mb_height);
5706 s->
start_mb_y = (i == 0) ? 0 :
FFMAX(0, slices[i-1].mby_start % mb_height);
5708 s->
end_mb_y = (i == n_slices ) ? mb_height :
FFMIN(mb_height, slices[i].mby_start % mb_height);
5710 if (i >= n_slices) {
5714 s->
end_mb_y = (i <= n_slices1 + 1) ? mb_height :
FFMIN(mb_height, slices[i].mby_start % mb_height);
5726 s->
gb = slices[i].gb;
5758 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
5759 if (vc1_decode_sprites(v, &s->
gb))
5778 for (i = 0; i < n_slices; i++)
5785 for (i = 0; i < n_slices; i++)
5829 #if CONFIG_WMV3_DECODER
5846 #if CONFIG_WMV3_VDPAU_DECODER
5847 AVCodec ff_wmv3_vdpau_decoder = {
5848 .
name =
"wmv3_vdpau",
5862 #if CONFIG_VC1_VDPAU_DECODER
5863 AVCodec ff_vc1_vdpau_decoder = {
5864 .
name =
"vc1_vdpau",
5878 #if CONFIG_WMV3IMAGE_DECODER
5879 AVCodec ff_wmv3image_decoder = {
5880 .
name =
"wmv3image",
5888 .
flush = vc1_sprite_flush,
5894 #if CONFIG_VC1IMAGE_DECODER
5895 AVCodec ff_vc1image_decoder = {
5904 .
flush = vc1_sprite_flush,