40 #define MB_INTRA_VLC_BITS 9
45 { 0, 1, 2, 4, 8, 16, 32, 64, 128 },
46 { 0, 1, 3, 7, 15, 31, 63, 127, 255 },
65 s->dest[0] +=
s->current_picture_ptr->f->linesize[0];
66 s->dest[1] +=
s->current_picture_ptr->f->linesize[1];
67 s->dest[2] +=
s->current_picture_ptr->f->linesize[2];
88 for (
i = 0;
i < block_count;
i++) {
89 if (
i > 3 ? v->
mb_type[0][
s->block_index[
i] -
s->block_wrap[
i] - 1] :
90 v->
mb_type[0][
s->block_index[
i] - 2 *
s->block_wrap[
i] - 2]) {
91 dest =
s->dest[0] + ((
i & 2) - 4) * 4 *
s->linesize + ((
i & 1) - 2) * 8;
94 i > 3 ?
s->dest[
i - 3] - 8 *
s->uvlinesize - 8 : dest,
95 i > 3 ?
s->uvlinesize :
s->linesize);
98 i > 3 ?
s->dest[
i - 3] - 8 *
s->uvlinesize - 8 : dest,
99 i > 3 ?
s->uvlinesize :
s->linesize);
104 for (
i = 0;
i < block_count;
i++) {
105 if (
i > 3 ? v->
mb_type[0][
s->block_index[
i] -
s->block_wrap[
i]] :
106 v->
mb_type[0][
s->block_index[
i] - 2 *
s->block_wrap[
i]]) {
107 dest =
s->dest[0] + ((
i & 2) - 4) * 4 *
s->linesize + (
i & 1) * 8;
110 i > 3 ?
s->dest[
i - 3] - 8 *
s->uvlinesize : dest,
111 i > 3 ?
s->uvlinesize :
s->linesize);
114 i > 3 ?
s->dest[
i - 3] - 8 *
s->uvlinesize : dest,
115 i > 3 ?
s->uvlinesize :
s->linesize);
124 for (
i = 0;
i < block_count;
i++) {
125 if (
i > 3 ? v->
mb_type[0][
s->block_index[
i] - 1] :
128 dest =
s->dest[0] + ((
i & 2) >> 1) *
s->linesize + ((
i & 1) - 2) * 8;
130 dest =
s->dest[0] + (
i & 2) * 4 *
s->linesize + ((
i & 1) - 2) * 8;
133 i > 3 ?
s->dest[
i - 3] - 8 : dest,
134 i > 3 ?
s->uvlinesize :
s->linesize << fieldtx);
137 i > 3 ?
s->dest[
i - 3] - 8 : dest,
138 i > 3 ?
s->uvlinesize :
s->linesize << fieldtx);
145 for (
i = 0;
i < block_count;
i++) {
148 dest =
s->dest[0] + ((
i & 2) >> 1) *
s->linesize + (
i & 1) * 8;
150 dest =
s->dest[0] + (
i & 2) * 4 *
s->linesize + (
i & 1) * 8;
153 i > 3 ?
s->dest[
i - 3] : dest,
154 i > 3 ?
s->uvlinesize :
s->linesize << fieldtx);
157 i > 3 ?
s->dest[
i - 3] : dest,
158 i > 3 ?
s->uvlinesize :
s->linesize << fieldtx);
165 #define inc_blk_idx(idx) do { \
167 if (idx >= v->n_allocated_blks) \
182 #define GET_MQUANT() \
183 if (v->dquantfrm) { \
185 if (v->dqprofile == DQPROFILE_ALL_MBS) { \
186 if (v->dqbilevel) { \
187 mquant = (get_bits1(gb)) ? -v->altpq : v->pq; \
189 mqdiff = get_bits(gb, 3); \
191 mquant = -v->pq - mqdiff; \
193 mquant = -get_bits(gb, 5); \
196 if (v->dqprofile == DQPROFILE_SINGLE_EDGE) \
197 edges = 1 << v->dqsbedge; \
198 else if (v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
199 edges = (3 << v->dqsbedge) % 15; \
200 else if (v->dqprofile == DQPROFILE_FOUR_EDGES) \
202 if ((edges&1) && !s->mb_x) \
203 mquant = -v->altpq; \
204 if ((edges&2) && !s->mb_y) \
205 mquant = -v->altpq; \
206 if ((edges&4) && s->mb_x == (s->mb_width - 1)) \
207 mquant = -v->altpq; \
209 s->mb_y == ((s->mb_height >> v->field_mode) - 1)) \
210 mquant = -v->altpq; \
211 if (!mquant || mquant > 31 || mquant < -31) { \
212 av_log(v->s.avctx, AV_LOG_ERROR, \
213 "Overriding invalid mquant %d\n", mquant); \
225 #define GET_MVDATA(_dmv_x, _dmv_y) \
226 index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table, \
227 VC1_MV_DIFF_VLC_BITS, 2); \
235 _dmv_x = _dmv_y = 0; \
236 } else if (index == 35) { \
237 _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
238 _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
239 } else if (index == 36) { \
244 index1 = index % 6; \
245 _dmv_x = offset_table[1][index1]; \
246 val = size_table[index1] - (!s->quarter_sample && index1 == 5); \
248 val = get_bits(gb, val); \
249 sign = 0 - (val & 1); \
250 _dmv_x = (sign ^ ((val >> 1) + _dmv_x)) - sign; \
253 index1 = index / 6; \
254 _dmv_y = offset_table[1][index1]; \
255 val = size_table[index1] - (!s->quarter_sample && index1 == 5); \
257 val = get_bits(gb, val); \
258 sign = 0 - (val & 1); \
259 _dmv_y = (sign ^ ((val >> 1) + _dmv_y)) - sign; \
264 int *dmv_y,
int *pred_flag)
267 int extend_x, extend_y;
287 *pred_flag = *dmv_y & 1;
288 *dmv_y = (*dmv_y + (*dmv_y & 1)) >> 1;
293 index1 = (
index + 1) % 9;
296 sign = 0 - (
val & 1);
297 *dmv_x = (sign ^ ((
val >> 1) +
offset_table[extend_x][index1])) - sign;
300 index1 = (
index + 1) / 9;
303 sign = 0 - (
val & 1);
307 if (v->
numref && pred_flag)
308 *pred_flag = index1 & 1;
341 int16_t **dc_val_ptr,
int *dir_ptr)
345 static const uint16_t dcpred[32] = {
346 -1, 1024, 512, 341, 256, 205, 171, 146, 128,
347 114, 102, 93, 85, 79, 73, 68, 64,
348 60, 57, 54, 51, 49, 47, 45, 43,
349 41, 39, 38, 37, 35, 34, 33
353 if (n < 4)
scale =
s->y_dc_scale;
354 else scale =
s->c_dc_scale;
356 wrap =
s->block_wrap[n];
357 dc_val =
s->dc_val[0] +
s->block_index[n];
363 b = dc_val[ - 1 -
wrap];
366 if (pq < 9 || !overlap) {
368 if (
s->first_slice_line && (n != 2 && n != 3))
370 if (
s->mb_x == 0 && (n != 1 && n != 3))
374 if (
s->first_slice_line && (n != 2 && n != 3))
376 if (
s->mb_x == 0 && (n != 1 && n != 3))
389 *dc_val_ptr = &dc_val[0];
406 int a_avail,
int c_avail,
407 int16_t **dc_val_ptr,
int *dir_ptr)
411 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
416 q1 =
FFABS(
s->current_picture.qscale_table[mb_pos]);
417 dqscale_index =
s->y_dc_scale_table[
q1] - 1;
418 if (dqscale_index < 0)
421 wrap =
s->block_wrap[n];
422 dc_val =
s->dc_val[0] +
s->block_index[n];
428 b = dc_val[ - 1 -
wrap];
431 if (c_avail && (n != 1 && n != 3)) {
432 q2 =
FFABS(
s->current_picture.qscale_table[mb_pos - 1]);
434 c = (
int)((
unsigned)
c *
s->y_dc_scale_table[q2] *
ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
436 if (a_avail && (n != 2 && n != 3)) {
437 q2 =
FFABS(
s->current_picture.qscale_table[mb_pos -
s->mb_stride]);
439 a = (
int)((
unsigned)
a *
s->y_dc_scale_table[q2] *
ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
441 if (a_avail && c_avail && (n != 3)) {
447 q2 =
FFABS(
s->current_picture.qscale_table[off]);
449 b = (
int)((
unsigned)
b *
s->y_dc_scale_table[q2] *
ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
452 if (c_avail && (!a_avail ||
abs(
a -
b) <=
abs(
b -
c))) {
455 }
else if (a_avail) {
464 *dc_val_ptr = &dc_val[0];
477 uint8_t **coded_block_ptr)
481 xy =
s->block_index[n];
487 a =
s->coded_block[xy - 1 ];
488 b =
s->coded_block[xy - 1 -
wrap];
489 c =
s->coded_block[xy -
wrap];
498 *coded_block_ptr = &
s->coded_block[xy];
513 int *
value,
int codingset)
580 int coded,
int codingset)
587 int16_t *ac_val, *ac_val2;
597 const int m = (v->
pq == 1 || v->
pq == 2) ? 3 - v->
pq : 0;
598 if (dcdiff == 119 ) {
602 dcdiff = (dcdiff << m) +
get_bits(gb, m) - ((1 << m) - 1);
619 ac_val =
s->ac_val[0][
s->block_index[n]];
624 ac_val -= 16 *
s->block_wrap[n];
632 int last = 0, skip,
value;
633 const uint8_t *zz_table;
663 for (k = 1; k < 8; k++)
664 block[k << sh] += ac_val[k];
667 for (k = 1; k < 8; k++) {
673 for (k = 1; k < 64; k++)
683 memset(ac_val2, 0, 16 * 2);
695 memcpy(ac_val2, ac_val, 8 * 2);
696 for (k = 1; k < 8; k++) {
703 if (
s->ac_pred)
i = 63;
704 s->block_last_index[n] =
i;
718 int coded,
int codingset,
int mquant)
724 int16_t *dc_val =
NULL;
725 int16_t *ac_val, *ac_val2;
728 int use_pred =
s->ac_pred;
731 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
742 if (dcdiff == 119 ) {
746 dcdiff = (dcdiff << m) +
get_bits(gb, m) - ((1 << m) - 1);
764 if (!a_avail && !c_avail)
769 ac_val =
s->ac_val[0][
s->block_index[n]];
774 ac_val -= 16 *
s->block_wrap[n];
776 q1 =
s->current_picture.qscale_table[mb_pos];
779 else if (dc_pred_dir) {
782 else if (c_avail && mb_pos)
783 q2 =
s->current_picture.qscale_table[mb_pos - 1];
787 else if (a_avail && mb_pos >=
s->mb_stride)
788 q2 =
s->current_picture.qscale_table[mb_pos -
s->mb_stride];
795 int last = 0, skip,
value;
796 const uint8_t *zz_table;
839 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
840 if (q2 &&
q1 != q2) {
841 for (k = 1; k < 8; k++)
844 for (k = 1; k < 8; k++)
845 block[k << sh] += ac_val[k];
849 for (k = 1; k < 8; k++) {
855 for (k = 1; k < 64; k++)
865 memset(ac_val2, 0, 16 * 2);
877 memcpy(ac_val2, ac_val, 8 * 2);
882 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
883 if (q2 &&
q1 != q2) {
884 for (k = 1; k < 8; k++)
885 ac_val2[k] = (
int)(ac_val2[k] * q2 * (unsigned)
ff_vc1_dqscale[
q1 - 1] + 0x20000) >> 18;
887 for (k = 1; k < 8; k++) {
894 if (use_pred)
i = 63;
895 s->block_last_index[n] =
i;
909 int coded,
int mquant,
int codingset)
915 int16_t *dc_val =
NULL;
916 int16_t *ac_val, *ac_val2;
918 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
920 int use_pred =
s->ac_pred;
925 s->bdsp.clear_block(
block);
931 s->y_dc_scale =
s->y_dc_scale_table[
quant];
932 s->c_dc_scale =
s->c_dc_scale_table[
quant];
942 if (dcdiff == 119 ) {
946 dcdiff = (dcdiff << m) +
get_bits(gb, m) - ((1 << m) - 1);
959 block[0] = dcdiff *
s->y_dc_scale;
961 block[0] = dcdiff *
s->c_dc_scale;
968 if (!a_avail) dc_pred_dir = 1;
969 if (!c_avail) dc_pred_dir = 0;
970 if (!a_avail && !c_avail) use_pred = 0;
971 ac_val =
s->ac_val[0][
s->block_index[n]];
979 ac_val -= 16 *
s->block_wrap[n];
981 q1 =
s->current_picture.qscale_table[mb_pos];
982 if (dc_pred_dir && c_avail && mb_pos)
983 q2 =
s->current_picture.qscale_table[mb_pos - 1];
984 if (!dc_pred_dir && a_avail && mb_pos >=
s->mb_stride)
985 q2 =
s->current_picture.qscale_table[mb_pos -
s->mb_stride];
986 if (dc_pred_dir && n == 1)
988 if (!dc_pred_dir && n == 2)
993 int last = 0, skip,
value;
1024 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
1025 if (q2 &&
q1 != q2) {
1027 for (k = 1; k < 8; k++)
1030 for (k = 1; k < 8; k++)
1035 for (k = 1; k < 8; k++)
1038 for (k = 1; k < 8; k++)
1044 for (k = 1; k < 8; k++) {
1050 for (k = 1; k < 64; k++)
1057 if (use_pred)
i = 63;
1061 memset(ac_val2, 0, 16 * 2);
1064 memcpy(ac_val2, ac_val, 8 * 2);
1069 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
1070 if (q2 &&
q1 != q2) {
1071 for (k = 1; k < 8; k++)
1072 ac_val2[k] = (
int)(ac_val2[k] * (unsigned)q2 *
ff_vc1_dqscale[
q1 - 1] + 0x20000) >> 18;
1077 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
1082 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
1083 if (q2 &&
q1 != q2) {
1084 for (k = 1; k < 8; k++)
1085 ac_val2[k + 8] = (
int)(ac_val2[k + 8] * (unsigned)q2 *
ff_vc1_dqscale[
q1 - 1] + 0x20000) >> 18;
1093 for (k = 1; k < 8; k++) {
1099 for (k = 1; k < 8; k++) {
1108 s->block_last_index[n] =
i;
1116 int mquant,
int ttmb,
int first_block,
1117 uint8_t *dst,
int linesize,
int skip_block,
1125 int ttblk = ttmb & 7;
1129 s->bdsp.clear_block(
block);
1138 && ((v->
ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
1184 s->idsp.add_pixels_clamped(
block, dst, linesize);
1189 pat = ~subblkpat & 0xF;
1190 for (j = 0; j < 4; j++) {
1191 last = subblkpat & (1 << (3 - j));
1193 off = (j & 1) * 4 + (j & 2) * 16;
1209 if (!(subblkpat & (1 << (3 - j))) && !skip_block) {
1218 pat = ~((subblkpat & 2) * 6 + (subblkpat & 1) * 3) & 0xF;
1219 for (j = 0; j < 2; j++) {
1220 last = subblkpat & (1 << (1 - j));
1238 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
1247 pat = ~(subblkpat * 5) & 0xF;
1248 for (j = 0; j < 2; j++) {
1249 last = subblkpat & (1 << (1 - j));
1267 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
1277 *ttmb_out |= ttblk << (n * 4);
1292 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
1295 int ttmb = v->
ttfrm;
1297 int mb_has_coeffs = 1;
1301 int first_block = 1;
1303 int skipped, fourmv;
1304 int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
1322 s->current_picture.motion_val[1][
s->block_index[0]][0] = 0;
1323 s->current_picture.motion_val[1][
s->block_index[0]][1] = 0;
1329 if (
s->mb_intra && !mb_has_coeffs) {
1333 }
else if (mb_has_coeffs) {
1342 s->current_picture.qscale_table[mb_pos] = mquant;
1344 if (!v->
ttmbf && !
s->mb_intra && mb_has_coeffs)
1349 for (
i = 0;
i < 6;
i++) {
1350 s->dc_val[0][
s->block_index[
i]] = 0;
1352 val = ((cbp >> (5 -
i)) & 1);
1353 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1354 v->
mb_type[0][
s->block_index[
i]] =
s->mb_intra;
1358 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1360 if (
i == 1 ||
i == 3 ||
s->mb_x)
1369 for (j = 0; j < 64; j++)
1371 block_cbp |= 0xF << (
i << 2);
1372 block_intra |= 1 <<
i;
1375 s->dest[dst_idx] + off, (
i & 4) ?
s->uvlinesize :
s->linesize,
1379 block_cbp |= pat << (
i << 2);
1380 if (!v->
ttmbf && ttmb < 8)
1387 for (
i = 0;
i < 6;
i++) {
1389 s->dc_val[0][
s->block_index[
i]] = 0;
1392 s->current_picture.qscale_table[mb_pos] = 0;
1398 int intra_count = 0, coded_inter = 0;
1399 int is_intra[6], is_coded[6];
1402 for (
i = 0;
i < 6;
i++) {
1403 val = ((cbp >> (5 -
i)) & 1);
1404 s->dc_val[0][
s->block_index[
i]] = 0;
1416 intra_count +=
s->mb_intra;
1417 is_intra[
i] =
s->mb_intra;
1418 is_coded[
i] = mb_has_coeffs;
1421 is_intra[
i] = (intra_count >= 3);
1426 v->
mb_type[0][
s->block_index[
i]] = is_intra[
i];
1428 coded_inter = !is_intra[
i] & is_coded[
i];
1432 if (!intra_count && !coded_inter)
1435 s->current_picture.qscale_table[mb_pos] = mquant;
1439 for (
i = 0;
i < 6;
i++)
1441 if (((!
s->first_slice_line || (
i == 2 ||
i == 3)) && v->
mb_type[0][
s->block_index[
i] -
s->block_wrap[
i]])
1442 || ((
s->mb_x || (
i == 1 ||
i == 3)) && v->
mb_type[0][
s->block_index[
i] - 1])) {
1452 if (!v->
ttmbf && coded_inter)
1454 for (
i = 0;
i < 6;
i++) {
1456 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1457 s->mb_intra = is_intra[
i];
1461 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1463 if (
i == 1 ||
i == 3 ||
s->mb_x)
1472 for (j = 0; j < 64; j++)
1474 block_cbp |= 0xF << (
i << 2);
1475 block_intra |= 1 <<
i;
1476 }
else if (is_coded[
i]) {
1478 first_block,
s->dest[dst_idx] + off,
1479 (
i & 4) ?
s->uvlinesize :
s->linesize,
1484 block_cbp |= pat << (
i << 2);
1485 if (!v->
ttmbf && ttmb < 8)
1492 s->current_picture.qscale_table[mb_pos] = 0;
1493 for (
i = 0;
i < 6;
i++) {
1495 s->dc_val[0][
s->block_index[
i]] = 0;
1497 for (
i = 0;
i < 4;
i++) {
1502 s->current_picture.qscale_table[mb_pos] = 0;
1510 v->
cbp[
s->mb_x] = block_cbp;
1511 v->
ttblk[
s->mb_x] = block_tt;
1524 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
1527 int ttmb = v->
ttfrm;
1529 int mb_has_coeffs = 1;
1532 int first_block = 1;
1534 int skipped, fourmv = 0, twomv = 0;
1535 int block_cbp = 0, pat, block_tt = 0;
1536 int idx_mbmode = 0, mvbp;
1581 for (
i = 0;
i < 4;
i++) {
1582 s->current_picture.motion_val[1][
s->block_index[
i]][0] = 0;
1583 s->current_picture.motion_val[1][
s->block_index[
i]][1] = 0;
1594 s->current_picture.qscale_table[mb_pos] = mquant;
1596 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
1597 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
1599 for (
i = 0;
i < 6;
i++) {
1602 s->dc_val[0][
s->block_index[
i]] = 0;
1604 val = ((cbp >> (5 -
i)) & 1);
1605 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1607 if (
i == 1 ||
i == 3 ||
s->mb_x)
1616 off = (fieldtx) ? ((
i & 1) * 8) + ((
i & 2) >> 1) *
s->linesize : (
i & 1) * 8 + 4 * (
i & 2) *
s->linesize;
1619 block_cbp |= 0
xf << (
i << 2);
1635 for (
i = 0;
i < 6;
i++)
1642 for (
i = 0;
i < 4;
i++) {
1644 if (mvbp & (8 >>
i))
1678 s->current_picture.qscale_table[mb_pos] = mquant;
1679 if (!v->
ttmbf && cbp)
1681 for (
i = 0;
i < 6;
i++) {
1682 s->dc_val[0][
s->block_index[
i]] = 0;
1684 val = ((cbp >> (5 -
i)) & 1);
1686 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1688 off = (
i & 4) ? 0 : ((
i & 1) * 8 + ((
i > 1) *
s->linesize));
1691 first_block,
s->dest[dst_idx] + off,
1692 (
i & 4) ?
s->uvlinesize : (
s->linesize << fieldtx),
1696 block_cbp |= pat << (
i << 2);
1697 if (!v->
ttmbf && ttmb < 8)
1705 for (
i = 0;
i < 6;
i++) {
1707 s->dc_val[0][
s->block_index[
i]] = 0;
1710 s->current_picture.qscale_table[mb_pos] = 0;
1723 v->
cbp[
s->mb_x] = block_cbp;
1724 v->
ttblk[
s->mb_x] = block_tt;
1734 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
1737 int ttmb = v->
ttfrm;
1739 int mb_has_coeffs = 1;
1742 int first_block = 1;
1745 int block_cbp = 0, pat, block_tt = 0;
1751 if (idx_mbmode <= 1) {
1754 s->current_picture.motion_val[1][
s->block_index[0] + v->
blocks_off][0] = 0;
1755 s->current_picture.motion_val[1][
s->block_index[0] + v->
blocks_off][1] = 0;
1758 s->current_picture.qscale_table[mb_pos] = mquant;
1760 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
1761 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
1763 mb_has_coeffs = idx_mbmode & 1;
1767 for (
i = 0;
i < 6;
i++) {
1770 s->dc_val[0][
s->block_index[
i]] = 0;
1772 val = ((cbp >> (5 -
i)) & 1);
1773 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1775 if (
i == 1 ||
i == 3 ||
s->mb_x)
1783 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1784 block_cbp |= 0xf << (
i << 2);
1789 for (
i = 0;
i < 6;
i++)
1791 if (idx_mbmode <= 5) {
1792 dmv_x = dmv_y = pred_flag = 0;
1793 if (idx_mbmode & 1) {
1798 mb_has_coeffs = !(idx_mbmode & 2);
1801 for (
i = 0;
i < 4;
i++) {
1802 dmv_x = dmv_y = pred_flag = 0;
1809 mb_has_coeffs = idx_mbmode & 1;
1816 s->current_picture.qscale_table[mb_pos] = mquant;
1817 if (!v->
ttmbf && cbp) {
1821 for (
i = 0;
i < 6;
i++) {
1822 s->dc_val[0][
s->block_index[
i]] = 0;
1824 val = ((cbp >> (5 -
i)) & 1);
1825 off = (
i & 4) ? 0 : (
i & 1) * 8 + (
i & 2) * 4 *
s->linesize;
1828 first_block,
s->dest[dst_idx] + off,
1829 (
i & 4) ?
s->uvlinesize :
s->linesize,
1834 block_cbp |= pat << (
i << 2);
1835 if (!v->
ttmbf && ttmb < 8)
1845 v->
cbp[
s->mb_x] = block_cbp;
1846 v->
ttblk[
s->mb_x] = block_tt;
1858 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
1861 int ttmb = v->
ttfrm;
1862 int mb_has_coeffs = 0;
1865 int first_block = 1;
1868 int dmv_x[2], dmv_y[2];
1883 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
1884 for (
i = 0;
i < 6;
i++) {
1886 s->dc_val[0][
s->block_index[
i]] = 0;
1888 s->current_picture.qscale_table[mb_pos] = 0;
1893 dmv_x[1] = dmv_x[0];
1894 dmv_y[1] = dmv_y[0];
1896 if (skipped || !
s->mb_intra) {
1907 dmv_x[0] = dmv_y[0] = 0;
1911 for (
i = 0;
i < 6;
i++)
1912 v->
mb_type[0][
s->block_index[
i]] =
s->mb_intra;
1925 s->current_picture.qscale_table[mb_pos] = mquant;
1928 dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
1932 if (!mb_has_coeffs && !
s->mb_intra) {
1938 if (
s->mb_intra && !mb_has_coeffs) {
1940 s->current_picture.qscale_table[mb_pos] = mquant;
1947 if (!mb_has_coeffs) {
1962 s->current_picture.qscale_table[mb_pos] = mquant;
1963 if (!v->
ttmbf && !
s->mb_intra && mb_has_coeffs)
1968 for (
i = 0;
i < 6;
i++) {
1969 s->dc_val[0][
s->block_index[
i]] = 0;
1971 val = ((cbp >> (5 -
i)) & 1);
1972 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1973 v->
mb_type[0][
s->block_index[
i]] =
s->mb_intra;
1977 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1979 if (
i == 1 ||
i == 3 ||
s->mb_x)
1988 for (j = 0; j < 64; j++)
1989 s->block[
i][j] *= 2;
1990 s->idsp.put_signed_pixels_clamped(
s->block[
i],
1991 s->dest[dst_idx] + off,
1992 i & 4 ?
s->uvlinesize
1996 first_block,
s->dest[dst_idx] + off,
1997 (
i & 4) ?
s->uvlinesize :
s->linesize,
2001 if (!v->
ttmbf && ttmb < 8)
2016 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
2019 int ttmb = v->
ttfrm;
2020 int mb_has_coeffs = 0;
2022 int first_block = 1;
2025 int dmv_x[2], dmv_y[2], pred_flag[2];
2027 int block_cbp = 0, pat, block_tt = 0;
2034 if (idx_mbmode <= 1) {
2037 s->current_picture.motion_val[1][
s->block_index[0]][0] = 0;
2038 s->current_picture.motion_val[1][
s->block_index[0]][1] = 0;
2041 s->current_picture.qscale_table[mb_pos] = mquant;
2043 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
2044 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
2046 mb_has_coeffs = idx_mbmode & 1;
2050 for (
i = 0;
i < 6;
i++) {
2053 s->dc_val[0][
s->block_index[
i]] = 0;
2055 val = ((cbp >> (5 -
i)) & 1);
2056 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
2058 if (
i == 1 ||
i == 3 ||
s->mb_x)
2067 for (j = 0; j < 64; j++)
2068 s->block[
i][j] <<= 1;
2069 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
2070 s->idsp.put_signed_pixels_clamped(
s->block[
i],
2071 s->dest[dst_idx] + off,
2072 (
i & 4) ?
s->uvlinesize
2078 for (
i = 0;
i < 6;
i++)
2084 if (idx_mbmode <= 5) {
2086 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
2087 pred_flag[0] = pred_flag[1] = 0;
2112 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
2113 dmv_x[1] = dmv_y[1] = pred_flag[0] = 0;
2114 if (!
s->next_picture_ptr->field_picture) {
2121 mb_has_coeffs = !(idx_mbmode & 2);
2127 for (
i = 0;
i < 4;
i++) {
2128 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
2129 dmv_x[1] = dmv_y[1] = pred_flag[1] = 0;
2139 mb_has_coeffs = idx_mbmode & 1;
2146 s->current_picture.qscale_table[mb_pos] = mquant;
2147 if (!v->
ttmbf && cbp) {
2151 for (
i = 0;
i < 6;
i++) {
2152 s->dc_val[0][
s->block_index[
i]] = 0;
2154 val = ((cbp >> (5 -
i)) & 1);
2155 off = (
i & 4) ? 0 : (
i & 1) * 8 + (
i & 2) * 4 *
s->linesize;
2158 first_block,
s->dest[dst_idx] + off,
2159 (
i & 4) ?
s->uvlinesize :
s->linesize,
2163 block_cbp |= pat << (
i << 2);
2164 if (!v->
ttmbf && ttmb < 8)
2170 v->
cbp[
s->mb_x] = block_cbp;
2171 v->
ttblk[
s->mb_x] = block_tt;
2183 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
2186 int ttmb = v->
ttfrm;
2188 int mb_has_coeffs = 1;
2191 int first_block = 1;
2193 int skipped,
direct, twomv = 0;
2194 int block_cbp = 0, pat, block_tt = 0;
2195 int idx_mbmode = 0, mvbp;
2196 int stride_y, fieldtx;
2224 for (
i = 0;
i < 4;
i++) {
2225 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0] = 0;
2226 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1] = 0;
2227 s->mv[1][
i][0] =
s->current_picture.motion_val[1][
s->block_index[
i]][0] = 0;
2228 s->mv[1][
i][1] =
s->current_picture.motion_val[1][
s->block_index[
i]][1] = 0;
2239 s->current_picture.qscale_table[mb_pos] = mquant;
2241 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
2242 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
2244 for (
i = 0;
i < 6;
i++) {
2247 s->dc_val[0][
s->block_index[
i]] = 0;
2249 val = ((cbp >> (5 -
i)) & 1);
2250 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
2252 if (
i == 1 ||
i == 3 ||
s->mb_x)
2261 stride_y =
s->linesize << fieldtx;
2262 off = (fieldtx) ? ((
i & 1) * 8) + ((
i & 2) >> 1) *
s->linesize : (
i & 1) * 8 + 4 * (
i & 2) *
s->linesize;
2264 stride_y =
s->uvlinesize;
2267 s->idsp.put_signed_pixels_clamped(
s->block[
i],
2268 s->dest[dst_idx] + off,
2280 if (
s->next_picture_ptr->field_picture)
2282 s->mv[0][0][0] =
s->current_picture.motion_val[0][
s->block_index[0]][0] =
scale_mv(
s->next_picture.motion_val[1][
s->block_index[0]][0], v->
bfraction, 0,
s->quarter_sample);
2283 s->mv[0][0][1] =
s->current_picture.motion_val[0][
s->block_index[0]][1] =
scale_mv(
s->next_picture.motion_val[1][
s->block_index[0]][1], v->
bfraction, 0,
s->quarter_sample);
2284 s->mv[1][0][0] =
s->current_picture.motion_val[1][
s->block_index[0]][0] =
scale_mv(
s->next_picture.motion_val[1][
s->block_index[0]][0], v->
bfraction, 1,
s->quarter_sample);
2285 s->mv[1][0][1] =
s->current_picture.motion_val[1][
s->block_index[0]][1] =
scale_mv(
s->next_picture.motion_val[1][
s->block_index[0]][1], v->
bfraction, 1,
s->quarter_sample);
2288 s->mv[0][2][0] =
s->current_picture.motion_val[0][
s->block_index[2]][0] =
scale_mv(
s->next_picture.motion_val[1][
s->block_index[2]][0], v->
bfraction, 0,
s->quarter_sample);
2289 s->mv[0][2][1] =
s->current_picture.motion_val[0][
s->block_index[2]][1] =
scale_mv(
s->next_picture.motion_val[1][
s->block_index[2]][1], v->
bfraction, 0,
s->quarter_sample);
2290 s->mv[1][2][0] =
s->current_picture.motion_val[1][
s->block_index[2]][0] =
scale_mv(
s->next_picture.motion_val[1][
s->block_index[2]][0], v->
bfraction, 1,
s->quarter_sample);
2291 s->mv[1][2][1] =
s->current_picture.motion_val[1][
s->block_index[2]][1] =
scale_mv(
s->next_picture.motion_val[1][
s->block_index[2]][1], v->
bfraction, 1,
s->quarter_sample);
2293 for (
i = 1;
i < 4;
i += 2) {
2294 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0] =
s->mv[0][
i-1][0];
2295 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1] =
s->mv[0][
i-1][1];
2296 s->mv[1][
i][0] =
s->current_picture.motion_val[1][
s->block_index[
i]][0] =
s->mv[1][
i-1][0];
2297 s->mv[1][
i][1] =
s->current_picture.motion_val[1][
s->block_index[
i]][1] =
s->mv[1][
i-1][1];
2300 for (
i = 1;
i < 4;
i++) {
2301 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0] =
s->mv[0][0][0];
2302 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1] =
s->mv[0][0][1];
2303 s->mv[1][
i][0] =
s->current_picture.motion_val[1][
s->block_index[
i]][0] =
s->mv[1][0][0];
2304 s->mv[1][
i][1] =
s->current_picture.motion_val[1][
s->block_index[
i]][1] =
s->mv[1][0][1];
2310 if (skipped || !
s->mb_intra) {
2340 for (
i = 0;
i < 6;
i++)
2347 for (
i = 0;
i < 4;
i++) {
2359 for (
i = 0;
i < 4;
i++) {
2362 val = ((mvbp >> (3 -
i)) & 1);
2405 for (
i = 0;
i < 2;
i++) {
2406 s->mv[dir][
i+2][0] =
s->mv[dir][
i][0] =
s->current_picture.motion_val[dir][
s->block_index[
i+2]][0] =
s->current_picture.motion_val[dir][
s->block_index[
i]][0];
2407 s->mv[dir][
i+2][1] =
s->mv[dir][
i][1] =
s->current_picture.motion_val[dir][
s->block_index[
i+2]][1] =
s->current_picture.motion_val[dir][
s->block_index[
i]][1];
2408 s->mv[dir2][
i+2][0] =
s->mv[dir2][
i][0] =
s->current_picture.motion_val[dir2][
s->block_index[
i]][0] =
s->current_picture.motion_val[dir2][
s->block_index[
i+2]][0];
2409 s->mv[dir2][
i+2][1] =
s->mv[dir2][
i][1] =
s->current_picture.motion_val[dir2][
s->block_index[
i]][1] =
s->current_picture.motion_val[dir2][
s->block_index[
i+2]][1];
2435 for (
i = 0;
i < 2;
i++) {
2436 s->mv[!dir][
i+2][0] =
s->mv[!dir][
i][0] =
s->current_picture.motion_val[!dir][
s->block_index[
i+2]][0] =
s->current_picture.motion_val[!dir][
s->block_index[
i]][0];
2437 s->mv[!dir][
i+2][1] =
s->mv[!dir][
i][1] =
s->current_picture.motion_val[!dir][
s->block_index[
i+2]][1] =
s->current_picture.motion_val[!dir][
s->block_index[
i]][1];
2444 s->current_picture.qscale_table[mb_pos] = mquant;
2445 if (!v->
ttmbf && cbp)
2447 for (
i = 0;
i < 6;
i++) {
2448 s->dc_val[0][
s->block_index[
i]] = 0;
2450 val = ((cbp >> (5 -
i)) & 1);
2452 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
2454 off = (
i & 4) ? 0 : ((
i & 1) * 8 + ((
i > 1) *
s->linesize));
2457 first_block,
s->dest[dst_idx] + off,
2458 (
i & 4) ?
s->uvlinesize : (
s->linesize << fieldtx),
2462 block_cbp |= pat << (
i << 2);
2463 if (!v->
ttmbf && ttmb < 8)
2471 for (
i = 0;
i < 6;
i++) {
2473 s->dc_val[0][
s->block_index[
i]] = 0;
2476 s->current_picture.qscale_table[mb_pos] = 0;
2493 for (
i = 0;
i < 2;
i++) {
2494 s->mv[dir][
i+2][0] =
s->mv[dir][
i][0] =
s->current_picture.motion_val[dir][
s->block_index[
i+2]][0] =
s->current_picture.motion_val[dir][
s->block_index[
i]][0];
2495 s->mv[dir][
i+2][1] =
s->mv[dir][
i][1] =
s->current_picture.motion_val[dir][
s->block_index[
i+2]][1] =
s->current_picture.motion_val[dir][
s->block_index[
i]][1];
2496 s->mv[dir2][
i+2][0] =
s->mv[dir2][
i][0] =
s->current_picture.motion_val[dir2][
s->block_index[
i]][0] =
s->current_picture.motion_val[dir2][
s->block_index[
i+2]][0];
2497 s->mv[dir2][
i+2][1] =
s->mv[dir2][
i][1] =
s->current_picture.motion_val[dir2][
s->block_index[
i]][1] =
s->current_picture.motion_val[dir2][
s->block_index[
i+2]][1];
2505 for (
i = 0;
i < 2;
i++) {
2506 s->mv[!dir][
i+2][0] =
s->mv[!dir][
i][0] =
s->current_picture.motion_val[!dir][
s->block_index[
i+2]][0] =
s->current_picture.motion_val[!dir][
s->block_index[
i]][0];
2507 s->mv[!dir][
i+2][1] =
s->mv[!dir][
i][1] =
s->current_picture.motion_val[!dir][
s->block_index[
i+2]][1] =
s->current_picture.motion_val[!dir][
s->block_index[
i]][1];
2520 v->
cbp[
s->mb_x] = block_cbp;
2521 v->
ttblk[
s->mb_x] = block_tt;
2562 s->y_dc_scale =
s->y_dc_scale_table[v->
pq];
2563 s->c_dc_scale =
s->c_dc_scale_table[v->
pq];
2566 s->mb_x =
s->mb_y = 0;
2568 s->first_slice_line = 1;
2569 for (
s->mb_y =
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2575 mb_pos =
s->mb_x +
s->mb_y *
s->mb_width;
2577 s->current_picture.qscale_table[mb_pos] = v->
pq;
2578 for (
int i = 0;
i < 4;
i++) {
2579 s->current_picture.motion_val[1][
s->block_index[
i]][0] = 0;
2580 s->current_picture.motion_val[1][
s->block_index[
i]][1] = 0;
2587 for (k = 0; k < 6; k++) {
2588 v->
mb_type[0][
s->block_index[k]] = 1;
2590 val = ((cbp >> (5 - k)) & 1);
2597 cbp |=
val << (5 - k);
2609 for (k = 0; k < 6; k++)
2610 for (j = 0; j < 64; j++)
2615 for (k = 0; k < 6; k++)
2616 for (j = 0; j < 64; j++)
2641 s->first_slice_line = 0;
2693 s->mb_x =
s->mb_y = 0;
2695 s->first_slice_line = 1;
2696 s->mb_y =
s->start_mb_y;
2697 if (
s->start_mb_y) {
2700 memset(&
s->coded_block[
s->block_index[0] -
s->b8_stride], 0,
2701 (1 +
s->b8_stride) *
sizeof(*
s->coded_block));
2703 for (;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2706 for (;
s->mb_x <
s->mb_width;
s->mb_x++) {
2710 mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
2712 for (
int i = 0;
i < 4;
i++) {
2713 s->current_picture.motion_val[1][
s->block_index[
i] + v->
blocks_off][0] = 0;
2714 s->current_picture.motion_val[1][
s->block_index[
i] + v->
blocks_off][1] = 0;
2736 s->current_picture.qscale_table[mb_pos] = mquant;
2738 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
2739 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
2741 for (k = 0; k < 6; k++) {
2742 v->
mb_type[0][
s->block_index[k]] = 1;
2744 val = ((cbp >> (5 - k)) & 1);
2751 cbp |=
val << (5 - k);
2753 v->
a_avail = !
s->first_slice_line || (k == 2 || k == 3);
2754 v->
c_avail = !!
s->mb_x || (k == 1 || k == 3);
2786 s->first_slice_line = 0;
2827 s->first_slice_line = 1;
2829 for (
s->mb_y =
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2832 for (;
s->mb_x <
s->mb_width;
s->mb_x++) {
2867 v->
cbp -
s->mb_stride,
2868 sizeof(v->
cbp_base[0]) * 2 *
s->mb_stride);
2878 if (
s->mb_y !=
s->start_mb_y)
2880 s->first_slice_line = 0;
2882 if (
s->end_mb_y >=
s->start_mb_y)
2917 s->first_slice_line = 1;
2918 for (
s->mb_y =
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2921 for (;
s->mb_x <
s->mb_width;
s->mb_x++) {
2952 v->
cbp -
s->mb_stride,
2953 sizeof(v->
cbp_base[0]) * 2 *
s->mb_stride);
2964 s->first_slice_line = 0;
2980 s->first_slice_line = 1;
2981 for (
s->mb_y =
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2985 memcpy(
s->dest[0],
s->last_picture.f->data[0] +
s->mb_y * 16 *
s->linesize,
s->linesize * 16);
2986 memcpy(
s->dest[1],
s->last_picture.f->data[1] +
s->mb_y * 8 *
s->uvlinesize,
s->uvlinesize * 8);
2987 memcpy(
s->dest[2],
s->last_picture.f->data[2] +
s->mb_y * 8 *
s->uvlinesize,
s->uvlinesize * 8);
2989 s->first_slice_line = 0;