41 0, 1, 2, 4, 8, 3, 5,10,12,15, 7,11,13,14, 6, 9,
45 15, 0, 7,11,13,14, 3, 5,10,12, 1, 2, 4, 8, 6, 9,
91 6, 2, 0, 0, 8, 6, 3, 0, 9, 8, 7, 5, 10, 9, 8, 6,
92 11,10, 9, 7, 13,11,10, 8, 13,13,11, 9, 13,13,13,10,
93 14,14,13,11, 14,14,14,13, 15,15,14,14, 15,15,15,14,
94 16,15,15,15, 16,16,16,15, 16,16,16,16, 16,16,16,16,
98 6, 2, 0, 0, 6, 5, 3, 0, 7, 6, 6, 4, 8, 6, 6, 4,
99 8, 7, 7, 5, 9, 8, 8, 6, 11, 9, 9, 6, 11,11,11, 7,
100 12,11,11, 9, 12,12,12,11, 12,12,12,11, 13,13,13,12,
101 13,13,13,13, 13,14,13,13, 14,14,14,13, 14,14,14,14,
105 6, 4, 0, 0, 6, 5, 4, 0, 6, 5, 5, 4, 7, 5, 5, 4,
106 7, 5, 5, 4, 7, 6, 6, 4, 7, 6, 6, 4, 8, 7, 7, 5,
107 8, 8, 7, 6, 9, 8, 8, 7, 9, 9, 8, 8, 9, 9, 9, 8,
108 10, 9, 9, 9, 10,10,10,10, 10,10,10,10, 10,10,10,10,
112 6, 6, 0, 0, 6, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 6,
113 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
114 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
115 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
122 5, 1, 0, 0, 7, 4, 1, 0, 7, 6, 5, 3, 7, 6, 5, 3,
123 7, 6, 5, 4, 15, 6, 5, 4, 11,14, 5, 4, 8,10,13, 4,
124 15,14, 9, 4, 11,10,13,12, 15,14, 9,12, 11,10,13, 8,
125 15, 1, 9,12, 11,14,13, 8, 7,10, 9,12, 4, 6, 5, 8,
129 11, 2, 0, 0, 7, 7, 3, 0, 7,10, 9, 5, 7, 6, 5, 4,
130 4, 6, 5, 6, 7, 6, 5, 8, 15, 6, 5, 4, 11,14,13, 4,
131 15,10, 9, 4, 11,14,13,12, 8,10, 9, 8, 15,14,13,12,
132 11,10, 9,12, 7,11, 6, 8, 9, 8,10, 1, 7, 6, 5, 4,
136 15,14, 0, 0, 11,15,13, 0, 8,12,14,12, 15,10,11,11,
137 11, 8, 9,10, 9,14,13, 9, 8,10, 9, 8, 15,14,13,13,
138 11,14,10,12, 15,10,13,12, 11,14, 9,12, 8,10,13, 8,
139 13, 7, 9,12, 9,12,11,10, 5, 8, 7, 6, 1, 4, 3, 2,
143 0, 1, 0, 0, 4, 5, 6, 0, 8, 9,10,11, 12,13,14,15,
144 16,17,18,19, 20,21,22,23, 24,25,26,27, 28,29,30,31,
145 32,33,34,35, 36,37,38,39, 40,41,42,43, 44,45,46,47,
146 48,49,50,51, 52,53,54,55, 56,57,58,59, 60,61,62,63,
151 {1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9},
152 {3,3,3,3,3,4,4,4,4,5,5,6,6,6,6},
153 {4,3,3,3,4,4,3,3,4,5,5,6,5,6},
154 {5,3,4,4,3,3,3,4,3,4,5,5,5},
155 {4,4,4,3,3,3,3,3,4,5,4,5},
156 {6,5,3,3,3,3,3,3,4,3,6},
157 {6,5,3,3,3,2,3,4,3,6},
169 {1,3,2,3,2,3,2,3,2,3,2,3,2,3,2,1},
170 {7,6,5,4,3,5,4,3,2,3,2,3,2,1,0},
171 {5,7,6,5,4,3,4,3,2,3,2,1,1,0},
172 {3,7,5,4,6,5,4,3,3,2,2,1,0},
173 {5,4,3,7,6,5,4,3,2,1,1,0},
174 {1,1,7,6,5,4,3,2,1,1,0},
175 {1,1,5,4,3,3,2,1,1,0},
199 { 1, 3, 3, 4, 4, 4, 5, 5 },
200 { 3, 2, 3, 3, 3, 3, 3 },
201 { 3, 3, 2, 2, 3, 3 },
209 { 1, 2, 3, 2, 3, 1, 1, 0 },
210 { 0, 1, 1, 4, 5, 6, 7 },
211 { 0, 1, 1, 2, 6, 7 },
225 {3,3,3,3,3,3,3,4,5,6,7,8,9,10,11},
235 {7,6,5,4,3,2,1,1,1,1,1,1,1,1,1},
270 #define LEVEL_TAB_BITS 8
273 #define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8
274 #define CHROMA422_DC_COEFF_TOKEN_VLC_BITS 13
275 #define COEFF_TOKEN_VLC_BITS 8
276 #define TOTAL_ZEROS_VLC_BITS 9
277 #define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3
278 #define CHROMA422_DC_TOTAL_ZEROS_VLC_BITS 5
279 #define RUN_VLC_BITS 3
280 #define RUN7_VLC_BITS 6
287 const int index8=
scan8[n];
292 if(i<64) i= (i+1)>>1;
294 tprintf(h->
avctx,
"pred_nnz L%X T%X n%d s%d P%X\n", left, top, n,
scan8[n], i&31);
303 for(suffix_length=0; suffix_length<7; suffix_length++){
308 int level_code = (prefix << suffix_length) +
309 (i >> (
av_log2(i) - suffix_length)) - (1 << suffix_length);
310 int mask = -(level_code&1);
311 level_code = (((2 + level_code) >> 1) ^
mask) - mask;
367 init_vlc(&chroma_dc_total_zeros_vlc[i],
377 init_vlc(&chroma422_dc_total_zeros_vlc[i],
427 print_bin(buf>>(32-log), log);
445 static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3};
447 int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before;
456 total_coeff= coeff_token>>2;
461 total_coeff= coeff_token>>2;
465 total_coeff= coeff_token>>2;
474 if(total_coeff > (
unsigned)max_coeff) {
479 trailing_ones= coeff_token&3;
480 tprintf(h->
avctx,
"trailing:%d, total:%d\n", trailing_ones, total_coeff);
481 assert(total_coeff<=16);
485 level[0] = 1-((i&4)>>1);
486 level[1] = 1-((i&2) );
487 level[2] = 1-((i&1)<<1);
489 if(trailing_ones<total_coeff) {
491 int suffix_length = total_coeff > 10 & trailing_ones < 3;
496 if(level_code >= 100){
497 prefix= level_code - 100;
507 }
else if(prefix==14){
511 level_code= prefix +
get_bits(gb, 4);
513 level_code= 30 +
get_bits(gb, prefix-3);
519 level_code += (1<<(prefix-3))-4096;
523 if(trailing_ones < 3) level_code += 2;
526 mask= -(level_code&1);
527 level[trailing_ones]= (((2+level_code)>>1) ^
mask) - mask;
529 level_code += ((level_code>>31)|1) & -(trailing_ones < 3);
531 suffix_length = 1 + (level_code + 3
U > 6
U);
532 level[trailing_ones]= level_code;
536 for(i=trailing_ones+1;i<total_coeff;i++) {
537 static const unsigned int suffix_limit[7] = {0,3,6,12,24,48,INT_MAX };
542 if(level_code >= 100){
543 prefix= level_code - 100;
548 level_code = (prefix<<suffix_length) +
get_bits(gb, suffix_length);
550 level_code = (15<<suffix_length) +
get_bits(gb, prefix-3);
552 level_code += (1<<(prefix-3))-4096;
554 mask= -(level_code&1);
555 level_code= (((2+level_code)>>1) ^
mask) - mask;
557 level[i]= level_code;
558 suffix_length+= suffix_limit[suffix_length] + level_code > 2
U*suffix_limit[suffix_length];
562 if(total_coeff == max_coeff)
565 if (max_coeff <= 8) {
567 zeros_left =
get_vlc2(gb, chroma_dc_total_zeros_vlc[total_coeff - 1].table,
570 zeros_left =
get_vlc2(gb, chroma422_dc_total_zeros_vlc[total_coeff - 1].table,
577 #define STORE_BLOCK(type) \
578 scantable += zeros_left + total_coeff - 1; \
579 if(n >= LUMA_DC_BLOCK_INDEX){ \
580 ((type*)block)[*scantable] = level[0]; \
581 for(i=1;i<total_coeff && zeros_left > 0;i++) { \
583 run_before= get_vlc2(gb, run_vlc[zeros_left - 1].table, RUN_VLC_BITS, 1); \
585 run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \
586 zeros_left -= run_before; \
587 scantable -= 1 + run_before; \
588 ((type*)block)[*scantable]= level[i]; \
590 for(;i<total_coeff;i++) { \
592 ((type*)block)[*scantable]= level[i]; \
595 ((type*)block)[*scantable] = ((int)(level[0] * qmul[*scantable] + 32))>>6; \
596 for(i=1;i<total_coeff && zeros_left > 0;i++) { \
598 run_before= get_vlc2(gb, run_vlc[zeros_left - 1].table, RUN_VLC_BITS, 1); \
600 run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \
601 zeros_left -= run_before; \
602 scantable -= 1 + run_before; \
603 ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
605 for(;i<total_coeff;i++) { \
607 ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
611 if (zeros_left < 0) {
613 "negative number of zero coeffs at %d %d\n", h->
mb_x, h->
mb_y);
638 assert((cbp&15) == 0 || (cbp&15) == 15);
641 for(i8x8=0; i8x8<4; i8x8++){
642 for(i4x4=0; i4x4<4; i4x4++){
643 const int index= i4x4 + 4*i8x8 + p*16;
656 int cqm = (
IS_INTRA( mb_type ) ? 0:3)+p;
659 for(i8x8=0; i8x8<4; i8x8++){
664 for(i4x4=0; i4x4<4; i4x4++){
665 const int index= i4x4 + 4*i8x8 + p*16;
671 nnz[0] += nnz[1] + nnz[8] + nnz[9];
672 new_cbp |= !!nnz[0] << i8x8;
674 for(i4x4=0; i4x4<4; i4x4++){
675 const int index= i4x4 + 4*i8x8 + p*16;
685 nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;
695 unsigned int mb_type,
cbp;
719 if( (h->
mb_y&1) == 0 )
732 goto decode_intra_mb;
740 goto decode_intra_mb;
799 for(i=0; i<16; i+=di){
804 mode = rem_mode + (rem_mode >= mode);
828 }
else if(partition_count==4){
829 int i, j, sub_partition_count[4], list, ref[2][4];
869 }
else if(ref_count == 2){
901 for(j=0; j<sub_partition_count[i]; j++){
903 const int index= 4*i + block_width*j;
926 uint32_t *p= (uint32_t *)&h->
mv_cache[list][
scan8[4*i] ][0];
941 if(
IS_DIR(mb_type, 0, list)){
945 }
else if (rc == 2) {
958 if(
IS_DIR(mb_type, 0, list)){
972 if(
IS_DIR(mb_type, i, list)){
976 }
else if (rc == 2) {
993 if(
IS_DIR(mb_type, i, list)){
1010 if(
IS_DIR(mb_type, i, list)){
1014 }
else if (rc == 2) {
1031 if(
IS_DIR(mb_type, i, list)){
1069 if(dct8x8_allowed && (cbp&15) && !
IS_INTRA(mb_type)){
1077 int i4x4, i8x8, chroma_idx;
1081 const uint8_t *scan, *scan8x8;
1096 if(((
unsigned)h->
qscale) > max_qp){
1098 else h->
qscale-= max_qp+1;
1099 if(((
unsigned)h->
qscale) > max_qp){
1121 for(chroma_idx=0; chroma_idx<2; chroma_idx++)
1130 for(chroma_idx=0; chroma_idx<2; chroma_idx++){
1133 for (i8x8 = 0; i8x8 < 2; i8x8++) {
1134 for (i4x4 = 0; i4x4 < 4; i4x4++) {
1135 const int index = 16 + 16*chroma_idx + 8*i8x8 + i4x4;
1148 for(chroma_idx=0; chroma_idx<2; chroma_idx++)
1155 for(chroma_idx=0; chroma_idx<2; chroma_idx++){
1157 for(i4x4=0; i4x4<4; i4x4++){
1158 const int index= 16 + 16*chroma_idx + i4x4;
1159 if(
decode_residual(h, gb, h->
mb + (16*index << pixel_shift), index, scan + 1, qmul, 15) < 0){