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;
314 int direct,
int mode)
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;
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))
368 b =
a = dcpred[scale];
369 if (
s->mb_x == 0 && (
n != 1 &&
n != 3))
370 b =
c = dcpred[scale];
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)
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];
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;
600 const int m = (v->
pq == 1 || v->
pq == 2) ? 3 - v->
pq : 0;
601 if (dcdiff == 119 ) {
605 dcdiff = (dcdiff << m) +
get_bits(gb, m) - ((1 << m) - 1);
617 scale =
s->y_dc_scale;
619 scale =
s->c_dc_scale;
620 block[0] = dcdiff * scale;
622 ac_val =
s->ac_val[0][
s->block_index[
n]];
627 ac_val -= 16 *
s->block_wrap[
n];
635 int last = 0, skip,
value;
666 for (k = 1; k < 8; k++)
667 block[k << sh] += ac_val[k];
670 for (k = 1; k < 8; k++) {
676 for (k = 1; k < 64; k++)
686 memset(ac_val2, 0, 16 * 2);
698 memcpy(ac_val2, ac_val, 8 * 2);
699 for (k = 1; k < 8; k++) {
700 block[k << sh] = ac_val[k] * scale;
706 if (
s->ac_pred)
i = 63;
707 s->block_last_index[
n] =
i;
721 int coded,
int codingset,
int mquant)
727 int16_t *dc_val =
NULL;
728 int16_t *ac_val, *ac_val2;
731 int use_pred =
s->ac_pred;
734 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
749 if (dcdiff == 119 ) {
753 dcdiff = (dcdiff << m) +
get_bits(gb, m) - ((1 << m) - 1);
765 scale =
s->y_dc_scale;
767 scale =
s->c_dc_scale;
768 block[0] = dcdiff * scale;
771 if (!a_avail && !c_avail)
774 scale =
quant * 2 + ((mquant < 0) ? 0 : v->
halfpq);
776 ac_val =
s->ac_val[0][
s->block_index[
n]];
781 ac_val -= 16 *
s->block_wrap[
n];
783 q1 =
s->current_picture.qscale_table[mb_pos];
786 else if (dc_pred_dir) {
789 else if (c_avail && mb_pos)
790 q2 =
s->current_picture.qscale_table[mb_pos - 1];
794 else if (a_avail && mb_pos >=
s->mb_stride)
795 q2 =
s->current_picture.qscale_table[mb_pos -
s->mb_stride];
802 int last = 0, skip,
value;
846 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
847 if (q2 &&
q1 != q2) {
848 for (k = 1; k < 8; k++)
851 for (k = 1; k < 8; k++)
852 block[k << sh] += ac_val[k];
856 for (k = 1; k < 8; k++) {
862 for (k = 1; k < 64; k++)
872 memset(ac_val2, 0, 16 * 2);
884 memcpy(ac_val2, ac_val, 8 * 2);
889 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
890 if (q2 &&
q1 != q2) {
891 for (k = 1; k < 8; k++)
892 ac_val2[k] = (
int)(ac_val2[k] * q2 * (unsigned)
ff_vc1_dqscale[
q1 - 1] + 0x20000) >> 18;
894 for (k = 1; k < 8; k++) {
895 block[k << sh] = ac_val2[k] * scale;
901 if (use_pred)
i = 63;
902 s->block_last_index[
n] =
i;
916 int coded,
int mquant,
int codingset)
922 int16_t *dc_val =
NULL;
923 int16_t *ac_val, *ac_val2;
925 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
927 int use_pred =
s->ac_pred;
932 s->bdsp.clear_block(
block);
938 s->y_dc_scale =
s->y_dc_scale_table[
quant];
939 s->c_dc_scale =
s->c_dc_scale_table[
quant];
953 if (dcdiff == 119 ) {
957 dcdiff = (dcdiff << m) +
get_bits(gb, m) - ((1 << m) - 1);
970 block[0] = dcdiff *
s->y_dc_scale;
972 block[0] = dcdiff *
s->c_dc_scale;
979 if (!a_avail) dc_pred_dir = 1;
980 if (!c_avail) dc_pred_dir = 0;
981 if (!a_avail && !c_avail) use_pred = 0;
982 ac_val =
s->ac_val[0][
s->block_index[
n]];
985 scale =
quant * 2 + ((mquant < 0) ? 0 : v->
halfpq);
990 ac_val -= 16 *
s->block_wrap[
n];
992 q1 =
s->current_picture.qscale_table[mb_pos];
993 if (dc_pred_dir && c_avail && mb_pos)
994 q2 =
s->current_picture.qscale_table[mb_pos - 1];
995 if (!dc_pred_dir && a_avail && mb_pos >=
s->mb_stride)
996 q2 =
s->current_picture.qscale_table[mb_pos -
s->mb_stride];
997 if (dc_pred_dir &&
n == 1)
999 if (!dc_pred_dir &&
n == 2)
1001 if (
n == 3) q2 =
q1;
1004 int last = 0, skip,
value;
1035 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
1036 if (q2 &&
q1 != q2) {
1038 for (k = 1; k < 8; k++)
1041 for (k = 1; k < 8; k++)
1046 for (k = 1; k < 8; k++)
1049 for (k = 1; k < 8; k++)
1055 for (k = 1; k < 8; k++) {
1061 for (k = 1; k < 64; k++)
1068 if (use_pred)
i = 63;
1072 memset(ac_val2, 0, 16 * 2);
1075 memcpy(ac_val2, ac_val, 8 * 2);
1080 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
1081 if (q2 &&
q1 != q2) {
1082 for (k = 1; k < 8; k++)
1083 ac_val2[k] = (
int)(ac_val2[k] * (unsigned)q2 *
ff_vc1_dqscale[
q1 - 1] + 0x20000) >> 18;
1088 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
1093 q2 =
FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->
halfpq) - 1;
1094 if (q2 &&
q1 != q2) {
1095 for (k = 1; k < 8; k++)
1096 ac_val2[k + 8] = (
int)(ac_val2[k + 8] * (unsigned)q2 *
ff_vc1_dqscale[
q1 - 1] + 0x20000) >> 18;
1104 for (k = 1; k < 8; k++) {
1110 for (k = 1; k < 8; k++) {
1119 s->block_last_index[
n] =
i;
1127 int mquant,
int ttmb,
int first_block,
1128 uint8_t *dst,
int linesize,
int skip_block,
1135 int scale, off, idx, last, skip,
value;
1136 int ttblk = ttmb & 7;
1140 s->bdsp.clear_block(
block);
1149 && ((v->
ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
1159 scale =
quant * 2 + ((mquant < 0) ? 0 : v->
halfpq);
1195 s->idsp.add_pixels_clamped(
block, dst, linesize);
1200 pat = ~subblkpat & 0xF;
1201 for (j = 0; j < 4; j++) {
1202 last = subblkpat & (1 << (3 - j));
1204 off = (j & 1) * 4 + (j & 2) * 16;
1220 if (!(subblkpat & (1 << (3 - j))) && !skip_block) {
1229 pat = ~((subblkpat & 2) * 6 + (subblkpat & 1) * 3) & 0xF;
1230 for (j = 0; j < 2; j++) {
1231 last = subblkpat & (1 << (1 - j));
1249 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
1258 pat = ~(subblkpat * 5) & 0xF;
1259 for (j = 0; j < 2; j++) {
1260 last = subblkpat & (1 << (1 - j));
1278 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
1288 *ttmb_out |= ttblk << (
n * 4);
1303 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
1306 int ttmb = v->
ttfrm;
1308 int mb_has_coeffs = 1;
1312 int first_block = 1;
1314 int skipped, fourmv;
1315 int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
1333 s->current_picture.motion_val[1][
s->block_index[0]][0] = 0;
1334 s->current_picture.motion_val[1][
s->block_index[0]][1] = 0;
1340 if (
s->mb_intra && !mb_has_coeffs) {
1344 }
else if (mb_has_coeffs) {
1353 s->current_picture.qscale_table[mb_pos] = mquant;
1355 if (!v->
ttmbf && !
s->mb_intra && mb_has_coeffs)
1360 for (
i = 0;
i < 6;
i++) {
1361 s->dc_val[0][
s->block_index[
i]] = 0;
1363 val = ((cbp >> (5 -
i)) & 1);
1364 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1365 v->
mb_type[0][
s->block_index[
i]] =
s->mb_intra;
1369 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1371 if (
i == 1 ||
i == 3 ||
s->mb_x)
1380 for (j = 0; j < 64; j++)
1382 block_cbp |= 0xF << (
i << 2);
1383 block_intra |= 1 <<
i;
1386 s->dest[dst_idx] + off, (
i & 4) ?
s->uvlinesize :
s->linesize,
1390 block_cbp |= pat << (
i << 2);
1391 if (!v->
ttmbf && ttmb < 8)
1398 for (
i = 0;
i < 6;
i++) {
1400 s->dc_val[0][
s->block_index[
i]] = 0;
1403 s->current_picture.qscale_table[mb_pos] = 0;
1409 int intra_count = 0, coded_inter = 0;
1410 int is_intra[6], is_coded[6];
1413 for (
i = 0;
i < 6;
i++) {
1414 val = ((cbp >> (5 -
i)) & 1);
1415 s->dc_val[0][
s->block_index[
i]] = 0;
1427 intra_count +=
s->mb_intra;
1428 is_intra[
i] =
s->mb_intra;
1429 is_coded[
i] = mb_has_coeffs;
1432 is_intra[
i] = (intra_count >= 3);
1437 v->
mb_type[0][
s->block_index[
i]] = is_intra[
i];
1439 coded_inter = !is_intra[
i] & is_coded[
i];
1443 if (!intra_count && !coded_inter)
1446 s->current_picture.qscale_table[mb_pos] = mquant;
1450 for (
i = 0;
i < 6;
i++)
1452 if (((!
s->first_slice_line || (
i == 2 ||
i == 3)) && v->
mb_type[0][
s->block_index[
i] -
s->block_wrap[
i]])
1453 || ((
s->mb_x || (
i == 1 ||
i == 3)) && v->
mb_type[0][
s->block_index[
i] - 1])) {
1463 if (!v->
ttmbf && coded_inter)
1465 for (
i = 0;
i < 6;
i++) {
1467 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1468 s->mb_intra = is_intra[
i];
1472 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1474 if (
i == 1 ||
i == 3 ||
s->mb_x)
1483 for (j = 0; j < 64; j++)
1485 block_cbp |= 0xF << (
i << 2);
1486 block_intra |= 1 <<
i;
1487 }
else if (is_coded[
i]) {
1489 first_block,
s->dest[dst_idx] + off,
1490 (
i & 4) ?
s->uvlinesize :
s->linesize,
1495 block_cbp |= pat << (
i << 2);
1496 if (!v->
ttmbf && ttmb < 8)
1503 s->current_picture.qscale_table[mb_pos] = 0;
1504 for (
i = 0;
i < 6;
i++) {
1506 s->dc_val[0][
s->block_index[
i]] = 0;
1508 for (
i = 0;
i < 4;
i++) {
1513 s->current_picture.qscale_table[mb_pos] = 0;
1521 v->
cbp[
s->mb_x] = block_cbp;
1522 v->
ttblk[
s->mb_x] = block_tt;
1535 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
1538 int ttmb = v->
ttfrm;
1540 int mb_has_coeffs = 1;
1543 int first_block = 1;
1545 int skipped, fourmv = 0, twomv = 0;
1546 int block_cbp = 0, pat, block_tt = 0;
1547 int idx_mbmode = 0, mvbp;
1592 for (
i = 0;
i < 4;
i++) {
1593 s->current_picture.motion_val[1][
s->block_index[
i]][0] = 0;
1594 s->current_picture.motion_val[1][
s->block_index[
i]][1] = 0;
1605 s->current_picture.qscale_table[mb_pos] = mquant;
1607 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
1608 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
1610 for (
i = 0;
i < 6;
i++) {
1613 s->dc_val[0][
s->block_index[
i]] = 0;
1615 val = ((cbp >> (5 -
i)) & 1);
1616 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1618 if (
i == 1 ||
i == 3 ||
s->mb_x)
1627 off = (fieldtx) ? ((
i & 1) * 8) + ((
i & 2) >> 1) *
s->linesize : (
i & 1) * 8 + 4 * (
i & 2) *
s->linesize;
1630 block_cbp |= 0
xf << (
i << 2);
1646 for (
i = 0;
i < 6;
i++)
1653 for (
i = 0;
i < 4;
i++) {
1655 if (mvbp & (8 >>
i))
1689 s->current_picture.qscale_table[mb_pos] = mquant;
1690 if (!v->
ttmbf && cbp)
1692 for (
i = 0;
i < 6;
i++) {
1693 s->dc_val[0][
s->block_index[
i]] = 0;
1695 val = ((cbp >> (5 -
i)) & 1);
1697 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1699 off = (
i & 4) ? 0 : ((
i & 1) * 8 + ((
i > 1) *
s->linesize));
1702 first_block,
s->dest[dst_idx] + off,
1703 (
i & 4) ?
s->uvlinesize : (
s->linesize << fieldtx),
1707 block_cbp |= pat << (
i << 2);
1708 if (!v->
ttmbf && ttmb < 8)
1716 for (
i = 0;
i < 6;
i++) {
1718 s->dc_val[0][
s->block_index[
i]] = 0;
1721 s->current_picture.qscale_table[mb_pos] = 0;
1734 v->
cbp[
s->mb_x] = block_cbp;
1735 v->
ttblk[
s->mb_x] = block_tt;
1745 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
1748 int ttmb = v->
ttfrm;
1750 int mb_has_coeffs = 1;
1753 int first_block = 1;
1756 int block_cbp = 0, pat, block_tt = 0;
1762 if (idx_mbmode <= 1) {
1765 s->current_picture.motion_val[1][
s->block_index[0] + v->
blocks_off][0] = 0;
1766 s->current_picture.motion_val[1][
s->block_index[0] + v->
blocks_off][1] = 0;
1769 s->current_picture.qscale_table[mb_pos] = mquant;
1771 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
1772 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
1774 mb_has_coeffs = idx_mbmode & 1;
1778 for (
i = 0;
i < 6;
i++) {
1781 s->dc_val[0][
s->block_index[
i]] = 0;
1783 val = ((cbp >> (5 -
i)) & 1);
1784 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1786 if (
i == 1 ||
i == 3 ||
s->mb_x)
1794 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1795 block_cbp |= 0xf << (
i << 2);
1800 for (
i = 0;
i < 6;
i++)
1802 if (idx_mbmode <= 5) {
1803 dmv_x = dmv_y = pred_flag = 0;
1804 if (idx_mbmode & 1) {
1809 mb_has_coeffs = !(idx_mbmode & 2);
1812 for (
i = 0;
i < 4;
i++) {
1813 dmv_x = dmv_y = pred_flag = 0;
1820 mb_has_coeffs = idx_mbmode & 1;
1827 s->current_picture.qscale_table[mb_pos] = mquant;
1828 if (!v->
ttmbf && cbp) {
1832 for (
i = 0;
i < 6;
i++) {
1833 s->dc_val[0][
s->block_index[
i]] = 0;
1835 val = ((cbp >> (5 -
i)) & 1);
1836 off = (
i & 4) ? 0 : (
i & 1) * 8 + (
i & 2) * 4 *
s->linesize;
1839 first_block,
s->dest[dst_idx] + off,
1840 (
i & 4) ?
s->uvlinesize :
s->linesize,
1845 block_cbp |= pat << (
i << 2);
1846 if (!v->
ttmbf && ttmb < 8)
1856 v->
cbp[
s->mb_x] = block_cbp;
1857 v->
ttblk[
s->mb_x] = block_tt;
1869 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
1872 int ttmb = v->
ttfrm;
1873 int mb_has_coeffs = 0;
1876 int first_block = 1;
1878 int skipped, direct;
1879 int dmv_x[2], dmv_y[2];
1894 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
1895 for (
i = 0;
i < 6;
i++) {
1897 s->dc_val[0][
s->block_index[
i]] = 0;
1899 s->current_picture.qscale_table[mb_pos] = 0;
1904 dmv_x[1] = dmv_x[0];
1905 dmv_y[1] = dmv_y[0];
1907 if (skipped || !
s->mb_intra) {
1918 dmv_x[0] = dmv_y[0] = 0;
1922 for (
i = 0;
i < 6;
i++)
1923 v->
mb_type[0][
s->block_index[
i]] =
s->mb_intra;
1929 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1936 s->current_picture.qscale_table[mb_pos] = mquant;
1939 dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
1941 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1943 if (!mb_has_coeffs && !
s->mb_intra) {
1946 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1949 if (
s->mb_intra && !mb_has_coeffs) {
1951 s->current_picture.qscale_table[mb_pos] = mquant;
1958 if (!mb_has_coeffs) {
1961 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1967 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1973 s->current_picture.qscale_table[mb_pos] = mquant;
1974 if (!v->
ttmbf && !
s->mb_intra && mb_has_coeffs)
1979 for (
i = 0;
i < 6;
i++) {
1980 s->dc_val[0][
s->block_index[
i]] = 0;
1982 val = ((cbp >> (5 -
i)) & 1);
1983 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
1984 v->
mb_type[0][
s->block_index[
i]] =
s->mb_intra;
1988 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
1990 if (
i == 1 ||
i == 3 ||
s->mb_x)
1999 for (j = 0; j < 64; j++)
2000 s->block[
i][j] *= 2;
2001 s->idsp.put_signed_pixels_clamped(
s->block[
i],
2002 s->dest[dst_idx] + off,
2003 i & 4 ?
s->uvlinesize
2007 first_block,
s->dest[dst_idx] + off,
2008 (
i & 4) ?
s->uvlinesize :
s->linesize,
2012 if (!v->
ttmbf && ttmb < 8)
2027 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
2030 int ttmb = v->
ttfrm;
2031 int mb_has_coeffs = 0;
2033 int first_block = 1;
2036 int dmv_x[2], dmv_y[2], pred_flag[2];
2038 int block_cbp = 0, pat, block_tt = 0;
2045 if (idx_mbmode <= 1) {
2048 s->current_picture.motion_val[1][
s->block_index[0]][0] = 0;
2049 s->current_picture.motion_val[1][
s->block_index[0]][1] = 0;
2052 s->current_picture.qscale_table[mb_pos] = mquant;
2054 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
2055 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
2057 mb_has_coeffs = idx_mbmode & 1;
2061 for (
i = 0;
i < 6;
i++) {
2064 s->dc_val[0][
s->block_index[
i]] = 0;
2066 val = ((cbp >> (5 -
i)) & 1);
2067 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
2069 if (
i == 1 ||
i == 3 ||
s->mb_x)
2078 for (j = 0; j < 64; j++)
2079 s->block[
i][j] <<= 1;
2080 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
2081 s->idsp.put_signed_pixels_clamped(
s->block[
i],
2082 s->dest[dst_idx] + off,
2083 (
i & 4) ?
s->uvlinesize
2089 for (
i = 0;
i < 6;
i++)
2095 if (idx_mbmode <= 5) {
2097 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
2098 pred_flag[0] = pred_flag[1] = 0;
2123 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
2124 dmv_x[1] = dmv_y[1] = pred_flag[0] = 0;
2125 if (!
s->next_picture_ptr->field_picture) {
2132 mb_has_coeffs = !(idx_mbmode & 2);
2138 for (
i = 0;
i < 4;
i++) {
2139 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
2140 dmv_x[1] = dmv_y[1] = pred_flag[1] = 0;
2150 mb_has_coeffs = idx_mbmode & 1;
2157 s->current_picture.qscale_table[mb_pos] = mquant;
2158 if (!v->
ttmbf && cbp) {
2162 for (
i = 0;
i < 6;
i++) {
2163 s->dc_val[0][
s->block_index[
i]] = 0;
2165 val = ((cbp >> (5 -
i)) & 1);
2166 off = (
i & 4) ? 0 : (
i & 1) * 8 + (
i & 2) * 4 *
s->linesize;
2169 first_block,
s->dest[dst_idx] + off,
2170 (
i & 4) ?
s->uvlinesize :
s->linesize,
2174 block_cbp |= pat << (
i << 2);
2175 if (!v->
ttmbf && ttmb < 8)
2181 v->
cbp[
s->mb_x] = block_cbp;
2182 v->
ttblk[
s->mb_x] = block_tt;
2194 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
2197 int ttmb = v->
ttfrm;
2199 int mb_has_coeffs = 1;
2202 int first_block = 1;
2204 int skipped, direct, twomv = 0;
2205 int block_cbp = 0, pat, block_tt = 0;
2206 int idx_mbmode = 0, mvbp;
2207 int stride_y, fieldtx;
2235 for (
i = 0;
i < 4;
i++) {
2236 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0] = 0;
2237 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1] = 0;
2238 s->mv[1][
i][0] =
s->current_picture.motion_val[1][
s->block_index[
i]][0] = 0;
2239 s->mv[1][
i][1] =
s->current_picture.motion_val[1][
s->block_index[
i]][1] = 0;
2250 s->current_picture.qscale_table[mb_pos] = mquant;
2252 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
2253 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
2255 for (
i = 0;
i < 6;
i++) {
2258 s->dc_val[0][
s->block_index[
i]] = 0;
2260 val = ((cbp >> (5 -
i)) & 1);
2261 if (
i == 2 ||
i == 3 || !
s->first_slice_line)
2263 if (
i == 1 ||
i == 3 ||
s->mb_x)
2272 stride_y =
s->linesize << fieldtx;
2273 off = (fieldtx) ? ((
i & 1) * 8) + ((
i & 2) >> 1) *
s->linesize : (
i & 1) * 8 + 4 * (
i & 2) *
s->linesize;
2275 stride_y =
s->uvlinesize;
2278 s->idsp.put_signed_pixels_clamped(
s->block[
i],
2279 s->dest[dst_idx] + off,
2291 if (
s->next_picture_ptr->field_picture)
2293 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);
2294 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);
2295 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);
2296 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);
2299 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);
2300 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);
2301 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);
2302 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);
2304 for (
i = 1;
i < 4;
i += 2) {
2305 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0] =
s->mv[0][
i-1][0];
2306 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1] =
s->mv[0][
i-1][1];
2307 s->mv[1][
i][0] =
s->current_picture.motion_val[1][
s->block_index[
i]][0] =
s->mv[1][
i-1][0];
2308 s->mv[1][
i][1] =
s->current_picture.motion_val[1][
s->block_index[
i]][1] =
s->mv[1][
i-1][1];
2311 for (
i = 1;
i < 4;
i++) {
2312 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0] =
s->mv[0][0][0];
2313 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1] =
s->mv[0][0][1];
2314 s->mv[1][
i][0] =
s->current_picture.motion_val[1][
s->block_index[
i]][0] =
s->mv[1][0][0];
2315 s->mv[1][
i][1] =
s->current_picture.motion_val[1][
s->block_index[
i]][1] =
s->mv[1][0][1];
2321 if (skipped || !
s->mb_intra) {
2351 for (
i = 0;
i < 6;
i++)
2358 for (
i = 0;
i < 4;
i++) {
2370 for (
i = 0;
i < 4;
i++) {
2373 val = ((mvbp >> (3 -
i)) & 1);
2416 for (
i = 0;
i < 2;
i++) {
2417 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];
2418 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];
2419 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];
2420 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];
2446 for (
i = 0;
i < 2;
i++) {
2447 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];
2448 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];
2455 s->current_picture.qscale_table[mb_pos] = mquant;
2456 if (!v->
ttmbf && cbp)
2458 for (
i = 0;
i < 6;
i++) {
2459 s->dc_val[0][
s->block_index[
i]] = 0;
2461 val = ((cbp >> (5 -
i)) & 1);
2463 off = (
i & 4) ? 0 : ((
i & 1) * 8 + (
i & 2) * 4 *
s->linesize);
2465 off = (
i & 4) ? 0 : ((
i & 1) * 8 + ((
i > 1) *
s->linesize));
2468 first_block,
s->dest[dst_idx] + off,
2469 (
i & 4) ?
s->uvlinesize : (
s->linesize << fieldtx),
2473 block_cbp |= pat << (
i << 2);
2474 if (!v->
ttmbf && ttmb < 8)
2482 for (
i = 0;
i < 6;
i++) {
2484 s->dc_val[0][
s->block_index[
i]] = 0;
2487 s->current_picture.qscale_table[mb_pos] = 0;
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];
2507 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];
2508 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];
2516 for (
i = 0;
i < 2;
i++) {
2517 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];
2518 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];
2531 v->
cbp[
s->mb_x] = block_cbp;
2532 v->
ttblk[
s->mb_x] = block_tt;
2573 s->y_dc_scale =
s->y_dc_scale_table[v->
pq];
2574 s->c_dc_scale =
s->c_dc_scale_table[v->
pq];
2577 s->mb_x =
s->mb_y = 0;
2579 s->first_slice_line = 1;
2580 for (
s->mb_y =
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2586 mb_pos =
s->mb_x +
s->mb_y *
s->mb_width;
2588 s->current_picture.qscale_table[mb_pos] = v->
pq;
2589 for (
int i = 0;
i < 4;
i++) {
2590 s->current_picture.motion_val[1][
s->block_index[
i]][0] = 0;
2591 s->current_picture.motion_val[1][
s->block_index[
i]][1] = 0;
2598 for (k = 0; k < 6; k++) {
2599 v->
mb_type[0][
s->block_index[k]] = 1;
2601 val = ((cbp >> (5 - k)) & 1);
2608 cbp |=
val << (5 - k);
2620 for (k = 0; k < 6; k++)
2621 for (j = 0; j < 64; j++)
2626 for (k = 0; k < 6; k++)
2627 for (j = 0; j < 64; j++)
2652 s->first_slice_line = 0;
2701 s->mb_x =
s->mb_y = 0;
2703 s->first_slice_line = 1;
2704 s->mb_y =
s->start_mb_y;
2705 if (
s->start_mb_y) {
2708 memset(&
s->coded_block[
s->block_index[0] -
s->b8_stride], 0,
2709 (1 +
s->b8_stride) *
sizeof(*
s->coded_block));
2711 for (;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2714 for (;
s->mb_x <
s->mb_width;
s->mb_x++) {
2718 mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
2720 for (
int i = 0;
i < 4;
i++) {
2721 s->current_picture.motion_val[1][
s->block_index[
i] + v->
blocks_off][0] = 0;
2722 s->current_picture.motion_val[1][
s->block_index[
i] + v->
blocks_off][1] = 0;
2739 s->current_picture.qscale_table[mb_pos] = mquant;
2741 s->y_dc_scale =
s->y_dc_scale_table[
FFABS(mquant)];
2742 s->c_dc_scale =
s->c_dc_scale_table[
FFABS(mquant)];
2744 for (k = 0; k < 6; k++) {
2745 v->
mb_type[0][
s->block_index[k]] = 1;
2747 val = ((cbp >> (5 - k)) & 1);
2754 cbp |=
val << (5 - k);
2756 v->
a_avail = !
s->first_slice_line || (k == 2 || k == 3);
2757 v->
c_avail = !!
s->mb_x || (k == 1 || k == 3);
2789 s->first_slice_line = 0;
2829 s->first_slice_line = 1;
2831 for (
s->mb_y =
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2834 for (;
s->mb_x <
s->mb_width;
s->mb_x++) {
2863 v->
cbp -
s->mb_stride,
2864 sizeof(v->
cbp_base[0]) * 2 *
s->mb_stride);
2874 if (
s->mb_y !=
s->start_mb_y)
2876 s->first_slice_line = 0;
2878 if (
s->end_mb_y >=
s->start_mb_y)
2913 s->first_slice_line = 1;
2914 for (
s->mb_y =
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2917 for (;
s->mb_x <
s->mb_width;
s->mb_x++) {
2942 v->
cbp -
s->mb_stride,
2943 sizeof(v->
cbp_base[0]) * 2 *
s->mb_stride);
2954 s->first_slice_line = 0;
2970 s->first_slice_line = 1;
2971 for (
s->mb_y =
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2975 memcpy(
s->dest[0],
s->last_picture.f->data[0] +
s->mb_y * 16 *
s->linesize,
s->linesize * 16);
2976 memcpy(
s->dest[1],
s->last_picture.f->data[1] +
s->mb_y * 8 *
s->uvlinesize,
s->uvlinesize * 8);
2977 memcpy(
s->dest[2],
s->last_picture.f->data[2] +
s->mb_y * 8 *
s->uvlinesize,
s->uvlinesize * 8);
2979 s->first_slice_line = 0;