39 #define MB_INTRA_VLC_BITS 9
44 { 0, 1, 2, 4, 8, 16, 32, 64, 128 },
45 { 0, 1, 3, 7, 15, 31, 63, 127, 255 },
64 s->dest[0] +=
s->current_picture_ptr->f->linesize[0];
65 s->dest[1] +=
s->current_picture_ptr->f->linesize[1];
66 s->dest[2] +=
s->current_picture_ptr->f->linesize[2];
87 for (
i = 0;
i < block_count;
i++) {
88 if (
i > 3 ? v->
mb_type[0][
s->block_index[
i] -
s->block_wrap[
i] - 1] :
89 v->
mb_type[0][
s->block_index[
i] - 2 *
s->block_wrap[
i] - 2]) {
90 dest =
s->dest[0] + ((
i & 2) - 4) * 4 *
s->linesize + ((
i & 1) - 2) * 8;
93 i > 3 ?
s->dest[
i - 3] - 8 *
s->uvlinesize - 8 : dest,
94 i > 3 ?
s->uvlinesize :
s->linesize);
97 i > 3 ?
s->dest[
i - 3] - 8 *
s->uvlinesize - 8 : dest,
98 i > 3 ?
s->uvlinesize :
s->linesize);
103 for (
i = 0;
i < block_count;
i++) {
104 if (
i > 3 ? v->
mb_type[0][
s->block_index[
i] -
s->block_wrap[
i]] :
105 v->
mb_type[0][
s->block_index[
i] - 2 *
s->block_wrap[
i]]) {
106 dest =
s->dest[0] + ((
i & 2) - 4) * 4 *
s->linesize + (
i & 1) * 8;
109 i > 3 ?
s->dest[
i - 3] - 8 *
s->uvlinesize : dest,
110 i > 3 ?
s->uvlinesize :
s->linesize);
113 i > 3 ?
s->dest[
i - 3] - 8 *
s->uvlinesize : dest,
114 i > 3 ?
s->uvlinesize :
s->linesize);
123 for (
i = 0;
i < block_count;
i++) {
124 if (
i > 3 ? v->
mb_type[0][
s->block_index[
i] - 1] :
127 dest =
s->dest[0] + ((
i & 2) >> 1) *
s->linesize + ((
i & 1) - 2) * 8;
129 dest =
s->dest[0] + (
i & 2) * 4 *
s->linesize + ((
i & 1) - 2) * 8;
132 i > 3 ?
s->dest[
i - 3] - 8 : dest,
133 i > 3 ?
s->uvlinesize :
s->linesize << fieldtx);
136 i > 3 ?
s->dest[
i - 3] - 8 : dest,
137 i > 3 ?
s->uvlinesize :
s->linesize << fieldtx);
144 for (
i = 0;
i < block_count;
i++) {
147 dest =
s->dest[0] + ((
i & 2) >> 1) *
s->linesize + (
i & 1) * 8;
149 dest =
s->dest[0] + (
i & 2) * 4 *
s->linesize + (
i & 1) * 8;
152 i > 3 ?
s->dest[
i - 3] : dest,
153 i > 3 ?
s->uvlinesize :
s->linesize << fieldtx);
156 i > 3 ?
s->dest[
i - 3] : dest,
157 i > 3 ?
s->uvlinesize :
s->linesize << fieldtx);
164 #define inc_blk_idx(idx) do { \
166 if (idx >= v->n_allocated_blks) \
181 #define GET_MQUANT() \
182 if (v->dquantfrm) { \
184 if (v->dqprofile == DQPROFILE_ALL_MBS) { \
185 if (v->dqbilevel) { \
186 mquant = (get_bits1(gb)) ? -v->altpq : v->pq; \
188 mqdiff = get_bits(gb, 3); \
190 mquant = -v->pq - mqdiff; \
192 mquant = -get_bits(gb, 5); \
195 if (v->dqprofile == DQPROFILE_SINGLE_EDGE) \
196 edges = 1 << v->dqsbedge; \
197 else if (v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
198 edges = (3 << v->dqsbedge) % 15; \
199 else if (v->dqprofile == DQPROFILE_FOUR_EDGES) \
201 if ((edges&1) && !s->mb_x) \
202 mquant = -v->altpq; \
203 if ((edges&2) && !s->mb_y) \
204 mquant = -v->altpq; \
205 if ((edges&4) && s->mb_x == (s->mb_width - 1)) \
206 mquant = -v->altpq; \
208 s->mb_y == ((s->mb_height >> v->field_mode) - 1)) \
209 mquant = -v->altpq; \
210 if (!mquant || mquant > 31 || mquant < -31) { \
211 av_log(v->s.avctx, AV_LOG_ERROR, \
212 "Overriding invalid mquant %d\n", mquant); \
224 #define GET_MVDATA(_dmv_x, _dmv_y) \
225 index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table, \
226 VC1_MV_DIFF_VLC_BITS, 2); \
234 _dmv_x = _dmv_y = 0; \
235 } else if (index == 35) { \
236 _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
237 _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
238 } else if (index == 36) { \
243 index1 = index % 6; \
244 _dmv_x = offset_table[1][index1]; \
245 val = size_table[index1] - (!s->quarter_sample && index1 == 5); \
247 val = get_bits(gb, val); \
248 sign = 0 - (val & 1); \
249 _dmv_x = (sign ^ ((val >> 1) + _dmv_x)) - sign; \
252 index1 = index / 6; \
253 _dmv_y = offset_table[1][index1]; \
254 val = size_table[index1] - (!s->quarter_sample && index1 == 5); \
256 val = get_bits(gb, val); \
257 sign = 0 - (val & 1); \
258 _dmv_y = (sign ^ ((val >> 1) + _dmv_y)) - sign; \
263 int *dmv_y,
int *pred_flag)
266 int extend_x, extend_y;
286 *pred_flag = *dmv_y & 1;
287 *dmv_y = (*dmv_y + (*dmv_y & 1)) >> 1;
292 index1 = (
index + 1) % 9;
295 sign = 0 - (
val & 1);
296 *dmv_x = (sign ^ ((
val >> 1) +
offset_table[extend_x][index1])) - sign;
299 index1 = (
index + 1) / 9;
302 sign = 0 - (
val & 1);
306 if (v->
numref && pred_flag)
307 *pred_flag = index1 & 1;
340 int16_t **dc_val_ptr,
int *dir_ptr)
344 static const uint16_t dcpred[32] = {
345 -1, 1024, 512, 341, 256, 205, 171, 146, 128,
346 114, 102, 93, 85, 79, 73, 68, 64,
347 60, 57, 54, 51, 49, 47, 45, 43,
348 41, 39, 38, 37, 35, 34, 33
352 if (n < 4)
scale =
s->y_dc_scale;
353 else scale =
s->c_dc_scale;
355 wrap =
s->block_wrap[n];
356 dc_val =
s->dc_val[0] +
s->block_index[n];
362 b = dc_val[ - 1 -
wrap];
365 if (pq < 9 || !overlap) {
367 if (
s->first_slice_line && (n != 2 && n != 3))
369 if (
s->mb_x == 0 && (n != 1 && n != 3))
373 if (
s->first_slice_line && (n != 2 && n != 3))
375 if (
s->mb_x == 0 && (n != 1 && n != 3))
388 *dc_val_ptr = &dc_val[0];
405 int a_avail,
int c_avail,
406 int16_t **dc_val_ptr,
int *dir_ptr)
410 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
415 q1 =
FFABS(
s->current_picture.qscale_table[mb_pos]);
416 dqscale_index =
s->y_dc_scale_table[
q1] - 1;
417 if (dqscale_index < 0)
420 wrap =
s->block_wrap[n];
421 dc_val =
s->dc_val[0] +
s->block_index[n];
427 b = dc_val[ - 1 -
wrap];
430 if (c_avail && (n != 1 && n != 3)) {
431 q2 =
FFABS(
s->current_picture.qscale_table[mb_pos - 1]);
433 c = (
int)((
unsigned)
c *
s->y_dc_scale_table[q2] *
ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
435 if (a_avail && (n != 2 && n != 3)) {
436 q2 =
FFABS(
s->current_picture.qscale_table[mb_pos -
s->mb_stride]);
438 a = (
int)((
unsigned)
a *
s->y_dc_scale_table[q2] *
ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
440 if (a_avail && c_avail && (n != 3)) {
446 q2 =
FFABS(
s->current_picture.qscale_table[off]);
448 b = (
int)((
unsigned)
b *
s->y_dc_scale_table[q2] *
ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
451 if (c_avail && (!a_avail ||
abs(
a -
b) <=
abs(
b -
c))) {
454 }
else if (a_avail) {
463 *dc_val_ptr = &dc_val[0];
476 uint8_t **coded_block_ptr)
480 xy =
s->block_index[n];
486 a =
s->coded_block[xy - 1 ];
487 b =
s->coded_block[xy - 1 -
wrap];
488 c =
s->coded_block[xy -
wrap];
497 *coded_block_ptr = &
s->coded_block[xy];
512 int *
value,
int codingset)
579 int coded,
int codingset)
586 int16_t *ac_val, *ac_val2;
596 const int m = (v->
pq == 1 || v->
pq == 2) ? 3 - v->
pq : 0;
597 if (dcdiff == 119 ) {
601 dcdiff = (dcdiff << m) +
get_bits(gb, m) - ((1 << m) - 1);
618 ac_val =
s->ac_val[0][
s->block_index[n]];
623 ac_val -= 16 *
s->block_wrap[n];
631 int last = 0, skip,
value;
632 const uint8_t *zz_table;
662 for (k = 1; k < 8; k++)
663 block[k << sh] += ac_val[k];
666 for (k = 1; k < 8; k++) {
672 for (k = 1; k < 64; k++)
682 memset(ac_val2, 0, 16 * 2);
694 memcpy(ac_val2, ac_val, 8 * 2);
695 for (k = 1; k < 8; k++) {
702 if (
s->ac_pred)
i = 63;
703 s->block_last_index[n] =
i;
717 int coded,
int codingset,
int mquant)
723 int16_t *dc_val =
NULL;
724 int16_t *ac_val, *ac_val2;
727 int use_pred =
s->ac_pred;
730 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
741 if (dcdiff == 119 ) {
745 dcdiff = (dcdiff << m) +
get_bits(gb, m) - ((1 << m) - 1);
763 if (!a_avail && !c_avail)
768 ac_val =
s->ac_val[0][
s->block_index[n]];
773 ac_val -= 16 *
s->block_wrap[n];
775 q1 =
s->current_picture.qscale_table[mb_pos];
778 else if (dc_pred_dir) {
781 else if (c_avail && mb_pos)
782 q2 =
s->current_picture.qscale_table[mb_pos - 1];
786 else if (a_avail && mb_pos >=
s->mb_stride)
787 q2 =
s->current_picture.qscale_table[mb_pos -
s->mb_stride];
794 int last = 0, skip,
value;
795 const uint8_t *zz_table;
838 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
839 if (q2 &&
q1 != q2) {
840 for (k = 1; k < 8; k++)
843 for (k = 1; k < 8; k++)
844 block[k << sh] += ac_val[k];
848 for (k = 1; k < 8; k++) {
854 for (k = 1; k < 64; k++)
864 memset(ac_val2, 0, 16 * 2);
876 memcpy(ac_val2, ac_val, 8 * 2);
881 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
882 if (q2 &&
q1 != q2) {
883 for (k = 1; k < 8; k++)
884 ac_val2[k] = (
int)(ac_val2[k] * q2 * (unsigned)
ff_vc1_dqscale[
q1 - 1] + 0x20000) >> 18;
886 for (k = 1; k < 8; k++) {
893 if (use_pred)
i = 63;
894 s->block_last_index[n] =
i;
908 int coded,
int mquant,
int codingset)
914 int16_t *dc_val =
NULL;
915 int16_t *ac_val, *ac_val2;
917 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
919 int use_pred =
s->ac_pred;
924 s->bdsp.clear_block(
block);
930 s->y_dc_scale =
s->y_dc_scale_table[
quant];
931 s->c_dc_scale =
s->c_dc_scale_table[
quant];
941 if (dcdiff == 119 ) {
945 dcdiff = (dcdiff << m) +
get_bits(gb, m) - ((1 << m) - 1);
958 block[0] = dcdiff *
s->y_dc_scale;
960 block[0] = dcdiff *
s->c_dc_scale;
967 if (!a_avail) dc_pred_dir = 1;
968 if (!c_avail) dc_pred_dir = 0;
969 if (!a_avail && !c_avail) use_pred = 0;
970 ac_val =
s->ac_val[0][
s->block_index[n]];
978 ac_val -= 16 *
s->block_wrap[n];
980 q1 =
s->current_picture.qscale_table[mb_pos];
981 if (dc_pred_dir && c_avail && mb_pos)
982 q2 =
s->current_picture.qscale_table[mb_pos - 1];
983 if (!dc_pred_dir && a_avail && mb_pos >=
s->mb_stride)
984 q2 =
s->current_picture.qscale_table[mb_pos -
s->mb_stride];
985 if (dc_pred_dir && n == 1)
987 if (!dc_pred_dir && n == 2)
992 int last = 0, skip,
value;
1023 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
1024 if (q2 &&
q1 != q2) {
1026 for (k = 1; k < 8; k++)
1029 for (k = 1; k < 8; k++)
1034 for (k = 1; k < 8; k++)
1037 for (k = 1; k < 8; k++)
1043 for (k = 1; k < 8; k++) {
1049 for (k = 1; k < 64; k++)
1056 if (use_pred)
i = 63;
1060 memset(ac_val2, 0, 16 * 2);
1063 memcpy(ac_val2, ac_val, 8 * 2);
1068 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
1069 if (q2 &&
q1 != q2) {
1070 for (k = 1; k < 8; k++)
1071 ac_val2[k] = (
int)(ac_val2[k] * (unsigned)q2 *
ff_vc1_dqscale[
q1 - 1] + 0x20000) >> 18;
1076 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
1081 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
1082 if (q2 &&
q1 != q2) {
1083 for (k = 1; k < 8; k++)
1084 ac_val2[k + 8] = (
int)(ac_val2[k + 8] * (unsigned)q2 *
ff_vc1_dqscale[
q1 - 1] + 0x20000) >> 18;
1092 for (k = 1; k < 8; k++) {
1098 for (k = 1; k < 8; k++) {
1107 s->block_last_index[n] =
i;
1115 int mquant,
int ttmb,
int first_block,
1116 uint8_t *dst,
int linesize,
int skip_block,
1124 int ttblk = ttmb & 7;
1128 s->bdsp.clear_block(
block);
1137 && ((v->
ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
1183 s->idsp.add_pixels_clamped(
block, dst, linesize);
1188 pat = ~subblkpat & 0xF;
1189 for (j = 0; j < 4; j++) {
1190 last = subblkpat & (1 << (3 - j));
1192 off = (j & 1) * 4 + (j & 2) * 16;
1208 if (!(subblkpat & (1 << (3 - j))) && !skip_block) {
1217 pat = ~((subblkpat & 2) * 6 + (subblkpat & 1) * 3) & 0xF;
1218 for (j = 0; j < 2; j++) {
1219 last = subblkpat & (1 << (1 - j));
1237 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
1246 pat = ~(subblkpat * 5) & 0xF;
1247 for (j = 0; j < 2; j++) {
1248 last = subblkpat & (1 << (1 - j));
1266 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
1276 *ttmb_out |= ttblk << (n * 4);
1291 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
1294 int ttmb = v->
ttfrm;
1296 int mb_has_coeffs = 1;
1300 int first_block = 1;
1302 int skipped, fourmv;
1303 int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
1321 s->current_picture.motion_val[1][
s->block_index[0]][0] = 0;
1322 s->current_picture.motion_val[1][
s->block_index[0]][1] = 0;
1328 if (
s->mb_intra && !mb_has_coeffs) {
1332 }
else if (mb_has_coeffs) {
1341 s->current_picture.qscale_table[mb_pos] = mquant;
1343 if (!v->
ttmbf && !
s->mb_intra && mb_has_coeffs)
1348 for (
i = 0;
i < 6;
i++) {
1349 s->dc_val[0][
s->block_index[
i]] = 0;
1351 val = ((cbp >> (5 -
i)) & 1);
1352 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1353 v->
mb_type[0][
s->block_index[
i]] =
s->mb_intra;
1357 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1359 if (
i == 1 ||
i == 3 ||
s->mb_x)
1368 for (j = 0; j < 64; j++)
1370 block_cbp |= 0xF << (
i << 2);
1371 block_intra |= 1 <<
i;
1374 s->dest[dst_idx] + off, (
i & 4) ?
s->uvlinesize :
s->linesize,
1378 block_cbp |= pat << (
i << 2);
1379 if (!v->
ttmbf && ttmb < 8)
1386 for (
i = 0;
i < 6;
i++) {
1388 s->dc_val[0][
s->block_index[
i]] = 0;
1391 s->current_picture.qscale_table[mb_pos] = 0;
1397 int intra_count = 0, coded_inter = 0;
1398 int is_intra[6], is_coded[6];
1401 for (
i = 0;
i < 6;
i++) {
1402 val = ((cbp >> (5 -
i)) & 1);
1403 s->dc_val[0][
s->block_index[
i]] = 0;
1415 intra_count +=
s->mb_intra;
1416 is_intra[
i] =
s->mb_intra;
1417 is_coded[
i] = mb_has_coeffs;
1420 is_intra[
i] = (intra_count >= 3);
1425 v->
mb_type[0][
s->block_index[
i]] = is_intra[
i];
1427 coded_inter = !is_intra[
i] & is_coded[
i];
1431 if (!intra_count && !coded_inter)
1434 s->current_picture.qscale_table[mb_pos] = mquant;
1438 for (
i = 0;
i < 6;
i++)
1440 if (((!
s->first_slice_line || (
i == 2 ||
i == 3)) && v->
mb_type[0][
s->block_index[
i] -
s->block_wrap[
i]])
1441 || ((
s->mb_x || (
i == 1 ||
i == 3)) && v->
mb_type[0][
s->block_index[
i] - 1])) {
1451 if (!v->
ttmbf && coded_inter)
1453 for (
i = 0;
i < 6;
i++) {
1455 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1456 s->mb_intra = is_intra[
i];
1460 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1462 if (
i == 1 ||
i == 3 ||
s->mb_x)
1471 for (j = 0; j < 64; j++)
1473 block_cbp |= 0xF << (
i << 2);
1474 block_intra |= 1 <<
i;
1475 }
else if (is_coded[
i]) {
1477 first_block,
s->dest[dst_idx] + off,
1478 (
i & 4) ?
s->uvlinesize :
s->linesize,
1483 block_cbp |= pat << (
i << 2);
1484 if (!v->
ttmbf && ttmb < 8)
1491 s->current_picture.qscale_table[mb_pos] = 0;
1492 for (
i = 0;
i < 6;
i++) {
1494 s->dc_val[0][
s->block_index[
i]] = 0;
1496 for (
i = 0;
i < 4;
i++) {
1501 s->current_picture.qscale_table[mb_pos] = 0;
1509 v->
cbp[
s->mb_x] = block_cbp;
1510 v->
ttblk[
s->mb_x] = block_tt;
1523 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
1526 int ttmb = v->
ttfrm;
1528 int mb_has_coeffs = 1;
1531 int first_block = 1;
1533 int skipped, fourmv = 0, twomv = 0;
1534 int block_cbp = 0, pat, block_tt = 0;
1535 int idx_mbmode = 0, mvbp;
1580 for (
i = 0;
i < 4;
i++) {
1581 s->current_picture.motion_val[1][
s->block_index[
i]][0] = 0;
1582 s->current_picture.motion_val[1][
s->block_index[
i]][1] = 0;
1593 s->current_picture.qscale_table[mb_pos] = mquant;
1595 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
1596 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
1598 for (
i = 0;
i < 6;
i++) {
1601 s->dc_val[0][
s->block_index[
i]] = 0;
1603 val = ((cbp >> (5 -
i)) & 1);
1604 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1606 if (
i == 1 ||
i == 3 ||
s->mb_x)
1615 off = (fieldtx) ? ((
i & 1) * 8) + ((
i & 2) >> 1) *
s->linesize : (
i & 1) * 8 + 4 * (
i & 2) *
s->linesize;
1618 block_cbp |= 0
xf << (
i << 2);
1634 for (
i = 0;
i < 6;
i++)
1641 for (
i = 0;
i < 4;
i++) {
1643 if (mvbp & (8 >>
i))
1677 s->current_picture.qscale_table[mb_pos] = mquant;
1678 if (!v->
ttmbf && cbp)
1680 for (
i = 0;
i < 6;
i++) {
1681 s->dc_val[0][
s->block_index[
i]] = 0;
1683 val = ((cbp >> (5 -
i)) & 1);
1685 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1687 off = (
i & 4) ? 0 : ((
i & 1) * 8 + ((
i > 1) *
s->linesize));
1690 first_block,
s->dest[dst_idx] + off,
1691 (
i & 4) ?
s->uvlinesize : (
s->linesize << fieldtx),
1695 block_cbp |= pat << (
i << 2);
1696 if (!v->
ttmbf && ttmb < 8)
1704 for (
i = 0;
i < 6;
i++) {
1706 s->dc_val[0][
s->block_index[
i]] = 0;
1709 s->current_picture.qscale_table[mb_pos] = 0;
1722 v->
cbp[
s->mb_x] = block_cbp;
1723 v->
ttblk[
s->mb_x] = block_tt;
1733 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
1736 int ttmb = v->
ttfrm;
1738 int mb_has_coeffs = 1;
1741 int first_block = 1;
1744 int block_cbp = 0, pat, block_tt = 0;
1750 if (idx_mbmode <= 1) {
1753 s->current_picture.motion_val[1][
s->block_index[0] + v->
blocks_off][0] = 0;
1754 s->current_picture.motion_val[1][
s->block_index[0] + v->
blocks_off][1] = 0;
1757 s->current_picture.qscale_table[mb_pos] = mquant;
1759 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
1760 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
1762 mb_has_coeffs = idx_mbmode & 1;
1766 for (
i = 0;
i < 6;
i++) {
1769 s->dc_val[0][
s->block_index[
i]] = 0;
1771 val = ((cbp >> (5 -
i)) & 1);
1772 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1774 if (
i == 1 ||
i == 3 ||
s->mb_x)
1782 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1783 block_cbp |= 0xf << (
i << 2);
1788 for (
i = 0;
i < 6;
i++)
1790 if (idx_mbmode <= 5) {
1791 dmv_x = dmv_y = pred_flag = 0;
1792 if (idx_mbmode & 1) {
1797 mb_has_coeffs = !(idx_mbmode & 2);
1800 for (
i = 0;
i < 4;
i++) {
1801 dmv_x = dmv_y = pred_flag = 0;
1808 mb_has_coeffs = idx_mbmode & 1;
1815 s->current_picture.qscale_table[mb_pos] = mquant;
1816 if (!v->
ttmbf && cbp) {
1820 for (
i = 0;
i < 6;
i++) {
1821 s->dc_val[0][
s->block_index[
i]] = 0;
1823 val = ((cbp >> (5 -
i)) & 1);
1824 off = (
i & 4) ? 0 : (
i & 1) * 8 + (
i & 2) * 4 *
s->linesize;
1827 first_block,
s->dest[dst_idx] + off,
1828 (
i & 4) ?
s->uvlinesize :
s->linesize,
1833 block_cbp |= pat << (
i << 2);
1834 if (!v->
ttmbf && ttmb < 8)
1844 v->
cbp[
s->mb_x] = block_cbp;
1845 v->
ttblk[
s->mb_x] = block_tt;
1857 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
1860 int ttmb = v->
ttfrm;
1861 int mb_has_coeffs = 0;
1864 int first_block = 1;
1867 int dmv_x[2], dmv_y[2];
1882 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
1883 for (
i = 0;
i < 6;
i++) {
1885 s->dc_val[0][
s->block_index[
i]] = 0;
1887 s->current_picture.qscale_table[mb_pos] = 0;
1892 dmv_x[1] = dmv_x[0];
1893 dmv_y[1] = dmv_y[0];
1895 if (skipped || !
s->mb_intra) {
1906 dmv_x[0] = dmv_y[0] = 0;
1910 for (
i = 0;
i < 6;
i++)
1911 v->
mb_type[0][
s->block_index[
i]] =
s->mb_intra;
1924 s->current_picture.qscale_table[mb_pos] = mquant;
1927 dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
1931 if (!mb_has_coeffs && !
s->mb_intra) {
1937 if (
s->mb_intra && !mb_has_coeffs) {
1939 s->current_picture.qscale_table[mb_pos] = mquant;
1946 if (!mb_has_coeffs) {
1961 s->current_picture.qscale_table[mb_pos] = mquant;
1962 if (!v->
ttmbf && !
s->mb_intra && mb_has_coeffs)
1967 for (
i = 0;
i < 6;
i++) {
1968 s->dc_val[0][
s->block_index[
i]] = 0;
1970 val = ((cbp >> (5 -
i)) & 1);
1971 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1972 v->
mb_type[0][
s->block_index[
i]] =
s->mb_intra;
1976 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1978 if (
i == 1 ||
i == 3 ||
s->mb_x)
1987 for (j = 0; j < 64; j++)
1988 s->block[
i][j] *= 2;
1989 s->idsp.put_signed_pixels_clamped(
s->block[
i],
1990 s->dest[dst_idx] + off,
1991 i & 4 ?
s->uvlinesize
1995 first_block,
s->dest[dst_idx] + off,
1996 (
i & 4) ?
s->uvlinesize :
s->linesize,
2000 if (!v->
ttmbf && ttmb < 8)
2015 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
2018 int ttmb = v->
ttfrm;
2019 int mb_has_coeffs = 0;
2021 int first_block = 1;
2024 int dmv_x[2], dmv_y[2], pred_flag[2];
2026 int block_cbp = 0, pat, block_tt = 0;
2033 if (idx_mbmode <= 1) {
2036 s->current_picture.motion_val[1][
s->block_index[0]][0] = 0;
2037 s->current_picture.motion_val[1][
s->block_index[0]][1] = 0;
2040 s->current_picture.qscale_table[mb_pos] = mquant;
2042 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
2043 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
2045 mb_has_coeffs = idx_mbmode & 1;
2049 for (
i = 0;
i < 6;
i++) {
2052 s->dc_val[0][
s->block_index[
i]] = 0;
2054 val = ((cbp >> (5 -
i)) & 1);
2055 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
2057 if (
i == 1 ||
i == 3 ||
s->mb_x)
2066 for (j = 0; j < 64; j++)
2067 s->block[
i][j] <<= 1;
2068 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
2069 s->idsp.put_signed_pixels_clamped(
s->block[
i],
2070 s->dest[dst_idx] + off,
2071 (
i & 4) ?
s->uvlinesize
2077 for (
i = 0;
i < 6;
i++)
2083 if (idx_mbmode <= 5) {
2085 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
2086 pred_flag[0] = pred_flag[1] = 0;
2111 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
2112 dmv_x[1] = dmv_y[1] = pred_flag[0] = 0;
2113 if (!
s->next_picture_ptr->field_picture) {
2120 mb_has_coeffs = !(idx_mbmode & 2);
2126 for (
i = 0;
i < 4;
i++) {
2127 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
2128 dmv_x[1] = dmv_y[1] = pred_flag[1] = 0;
2138 mb_has_coeffs = idx_mbmode & 1;
2145 s->current_picture.qscale_table[mb_pos] = mquant;
2146 if (!v->
ttmbf && cbp) {
2150 for (
i = 0;
i < 6;
i++) {
2151 s->dc_val[0][
s->block_index[
i]] = 0;
2153 val = ((cbp >> (5 -
i)) & 1);
2154 off = (
i & 4) ? 0 : (
i & 1) * 8 + (
i & 2) * 4 *
s->linesize;
2157 first_block,
s->dest[dst_idx] + off,
2158 (
i & 4) ?
s->uvlinesize :
s->linesize,
2162 block_cbp |= pat << (
i << 2);
2163 if (!v->
ttmbf && ttmb < 8)
2169 v->
cbp[
s->mb_x] = block_cbp;
2170 v->
ttblk[
s->mb_x] = block_tt;
2182 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
2185 int ttmb = v->
ttfrm;
2187 int mb_has_coeffs = 1;
2190 int first_block = 1;
2192 int skipped,
direct, twomv = 0;
2193 int block_cbp = 0, pat, block_tt = 0;
2194 int idx_mbmode = 0, mvbp;
2195 int stride_y, fieldtx;
2223 for (
i = 0;
i < 4;
i++) {
2224 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0] = 0;
2225 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1] = 0;
2226 s->mv[1][
i][0] =
s->current_picture.motion_val[1][
s->block_index[
i]][0] = 0;
2227 s->mv[1][
i][1] =
s->current_picture.motion_val[1][
s->block_index[
i]][1] = 0;
2238 s->current_picture.qscale_table[mb_pos] = mquant;
2240 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
2241 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
2243 for (
i = 0;
i < 6;
i++) {
2246 s->dc_val[0][
s->block_index[
i]] = 0;
2248 val = ((cbp >> (5 -
i)) & 1);
2249 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
2251 if (
i == 1 ||
i == 3 ||
s->mb_x)
2260 stride_y =
s->linesize << fieldtx;
2261 off = (fieldtx) ? ((
i & 1) * 8) + ((
i & 2) >> 1) *
s->linesize : (
i & 1) * 8 + 4 * (
i & 2) *
s->linesize;
2263 stride_y =
s->uvlinesize;
2266 s->idsp.put_signed_pixels_clamped(
s->block[
i],
2267 s->dest[dst_idx] + off,
2279 if (
s->next_picture_ptr->field_picture)
2281 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);
2282 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);
2283 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);
2284 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);
2287 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);
2288 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);
2289 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);
2290 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);
2292 for (
i = 1;
i < 4;
i += 2) {
2293 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0] =
s->mv[0][
i-1][0];
2294 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1] =
s->mv[0][
i-1][1];
2295 s->mv[1][
i][0] =
s->current_picture.motion_val[1][
s->block_index[
i]][0] =
s->mv[1][
i-1][0];
2296 s->mv[1][
i][1] =
s->current_picture.motion_val[1][
s->block_index[
i]][1] =
s->mv[1][
i-1][1];
2299 for (
i = 1;
i < 4;
i++) {
2300 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0] =
s->mv[0][0][0];
2301 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1] =
s->mv[0][0][1];
2302 s->mv[1][
i][0] =
s->current_picture.motion_val[1][
s->block_index[
i]][0] =
s->mv[1][0][0];
2303 s->mv[1][
i][1] =
s->current_picture.motion_val[1][
s->block_index[
i]][1] =
s->mv[1][0][1];
2309 if (skipped || !
s->mb_intra) {
2339 for (
i = 0;
i < 6;
i++)
2346 for (
i = 0;
i < 4;
i++) {
2358 for (
i = 0;
i < 4;
i++) {
2361 val = ((mvbp >> (3 -
i)) & 1);
2404 for (
i = 0;
i < 2;
i++) {
2405 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];
2406 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];
2407 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];
2408 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];
2434 for (
i = 0;
i < 2;
i++) {
2435 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];
2436 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];
2443 s->current_picture.qscale_table[mb_pos] = mquant;
2444 if (!v->
ttmbf && cbp)
2446 for (
i = 0;
i < 6;
i++) {
2447 s->dc_val[0][
s->block_index[
i]] = 0;
2449 val = ((cbp >> (5 -
i)) & 1);
2451 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
2453 off = (
i & 4) ? 0 : ((
i & 1) * 8 + ((
i > 1) *
s->linesize));
2456 first_block,
s->dest[dst_idx] + off,
2457 (
i & 4) ?
s->uvlinesize : (
s->linesize << fieldtx),
2461 block_cbp |= pat << (
i << 2);
2462 if (!v->
ttmbf && ttmb < 8)
2470 for (
i = 0;
i < 6;
i++) {
2472 s->dc_val[0][
s->block_index[
i]] = 0;
2475 s->current_picture.qscale_table[mb_pos] = 0;
2492 for (
i = 0;
i < 2;
i++) {
2493 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];
2494 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];
2495 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];
2496 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];
2504 for (
i = 0;
i < 2;
i++) {
2505 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];
2506 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];
2519 v->
cbp[
s->mb_x] = block_cbp;
2520 v->
ttblk[
s->mb_x] = block_tt;
2561 s->y_dc_scale =
s->y_dc_scale_table[v->
pq];
2562 s->c_dc_scale =
s->c_dc_scale_table[v->
pq];
2565 s->mb_x =
s->mb_y = 0;
2567 s->first_slice_line = 1;
2568 for (
s->mb_y =
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2574 mb_pos =
s->mb_x +
s->mb_y *
s->mb_width;
2576 s->current_picture.qscale_table[mb_pos] = v->
pq;
2577 for (
int i = 0;
i < 4;
i++) {
2578 s->current_picture.motion_val[1][
s->block_index[
i]][0] = 0;
2579 s->current_picture.motion_val[1][
s->block_index[
i]][1] = 0;
2586 for (k = 0; k < 6; k++) {
2587 v->
mb_type[0][
s->block_index[k]] = 1;
2589 val = ((cbp >> (5 - k)) & 1);
2596 cbp |=
val << (5 - k);
2608 for (k = 0; k < 6; k++)
2609 for (j = 0; j < 64; j++)
2614 for (k = 0; k < 6; k++)
2615 for (j = 0; j < 64; j++)
2640 s->first_slice_line = 0;
2692 s->mb_x =
s->mb_y = 0;
2694 s->first_slice_line = 1;
2695 s->mb_y =
s->start_mb_y;
2696 if (
s->start_mb_y) {
2699 memset(&
s->coded_block[
s->block_index[0] -
s->b8_stride], 0,
2700 (1 +
s->b8_stride) *
sizeof(*
s->coded_block));
2702 for (;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2705 for (;
s->mb_x <
s->mb_width;
s->mb_x++) {
2709 mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
2711 for (
int i = 0;
i < 4;
i++) {
2712 s->current_picture.motion_val[1][
s->block_index[
i] + v->
blocks_off][0] = 0;
2713 s->current_picture.motion_val[1][
s->block_index[
i] + v->
blocks_off][1] = 0;
2735 s->current_picture.qscale_table[mb_pos] = mquant;
2737 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
2738 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
2740 for (k = 0; k < 6; k++) {
2741 v->
mb_type[0][
s->block_index[k]] = 1;
2743 val = ((cbp >> (5 - k)) & 1);
2750 cbp |=
val << (5 - k);
2752 v->
a_avail = !
s->first_slice_line || (k == 2 || k == 3);
2753 v->
c_avail = !!
s->mb_x || (k == 1 || k == 3);
2785 s->first_slice_line = 0;
2826 s->first_slice_line = 1;
2828 for (
s->mb_y =
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2831 for (;
s->mb_x <
s->mb_width;
s->mb_x++) {
2866 v->
cbp -
s->mb_stride,
2867 sizeof(v->
cbp_base[0]) * 2 *
s->mb_stride);
2877 if (
s->mb_y !=
s->start_mb_y)
2879 s->first_slice_line = 0;
2881 if (
s->end_mb_y >=
s->start_mb_y)
2916 s->first_slice_line = 1;
2917 for (
s->mb_y =
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2920 for (;
s->mb_x <
s->mb_width;
s->mb_x++) {
2951 v->
cbp -
s->mb_stride,
2952 sizeof(v->
cbp_base[0]) * 2 *
s->mb_stride);
2963 s->first_slice_line = 0;
2979 s->first_slice_line = 1;
2980 for (
s->mb_y =
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2984 memcpy(
s->dest[0],
s->last_picture.f->data[0] +
s->mb_y * 16 *
s->linesize,
s->linesize * 16);
2985 memcpy(
s->dest[1],
s->last_picture.f->data[1] +
s->mb_y * 8 *
s->uvlinesize,
s->uvlinesize * 8);
2986 memcpy(
s->dest[2],
s->last_picture.f->data[2] +
s->mb_y * 8 *
s->uvlinesize,
s->uvlinesize * 8);
2988 s->first_slice_line = 0;