42 0, 1, 2, 4, 8, 3, 5,10,12,15, 7,11,13,14, 6, 9,
46 15, 0, 7,11,13,14, 3, 5,10,12, 1, 2, 4, 8, 6, 9,
92 6, 2, 0, 0, 8, 6, 3, 0, 9, 8, 7, 5, 10, 9, 8, 6,
93 11,10, 9, 7, 13,11,10, 8, 13,13,11, 9, 13,13,13,10,
94 14,14,13,11, 14,14,14,13, 15,15,14,14, 15,15,15,14,
95 16,15,15,15, 16,16,16,15, 16,16,16,16, 16,16,16,16,
99 6, 2, 0, 0, 6, 5, 3, 0, 7, 6, 6, 4, 8, 6, 6, 4,
100 8, 7, 7, 5, 9, 8, 8, 6, 11, 9, 9, 6, 11,11,11, 7,
101 12,11,11, 9, 12,12,12,11, 12,12,12,11, 13,13,13,12,
102 13,13,13,13, 13,14,13,13, 14,14,14,13, 14,14,14,14,
106 6, 4, 0, 0, 6, 5, 4, 0, 6, 5, 5, 4, 7, 5, 5, 4,
107 7, 5, 5, 4, 7, 6, 6, 4, 7, 6, 6, 4, 8, 7, 7, 5,
108 8, 8, 7, 6, 9, 8, 8, 7, 9, 9, 8, 8, 9, 9, 9, 8,
109 10, 9, 9, 9, 10,10,10,10, 10,10,10,10, 10,10,10,10,
113 6, 6, 0, 0, 6, 6, 6, 0, 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,
116 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
123 5, 1, 0, 0, 7, 4, 1, 0, 7, 6, 5, 3, 7, 6, 5, 3,
124 7, 6, 5, 4, 15, 6, 5, 4, 11,14, 5, 4, 8,10,13, 4,
125 15,14, 9, 4, 11,10,13,12, 15,14, 9,12, 11,10,13, 8,
126 15, 1, 9,12, 11,14,13, 8, 7,10, 9,12, 4, 6, 5, 8,
130 11, 2, 0, 0, 7, 7, 3, 0, 7,10, 9, 5, 7, 6, 5, 4,
131 4, 6, 5, 6, 7, 6, 5, 8, 15, 6, 5, 4, 11,14,13, 4,
132 15,10, 9, 4, 11,14,13,12, 8,10, 9, 8, 15,14,13,12,
133 11,10, 9,12, 7,11, 6, 8, 9, 8,10, 1, 7, 6, 5, 4,
137 15,14, 0, 0, 11,15,13, 0, 8,12,14,12, 15,10,11,11,
138 11, 8, 9,10, 9,14,13, 9, 8,10, 9, 8, 15,14,13,13,
139 11,14,10,12, 15,10,13,12, 11,14, 9,12, 8,10,13, 8,
140 13, 7, 9,12, 9,12,11,10, 5, 8, 7, 6, 1, 4, 3, 2,
144 0, 1, 0, 0, 4, 5, 6, 0, 8, 9,10,11, 12,13,14,15,
145 16,17,18,19, 20,21,22,23, 24,25,26,27, 28,29,30,31,
146 32,33,34,35, 36,37,38,39, 40,41,42,43, 44,45,46,47,
147 48,49,50,51, 52,53,54,55, 56,57,58,59, 60,61,62,63,
152 {1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9},
153 {3,3,3,3,3,4,4,4,4,5,5,6,6,6,6},
154 {4,3,3,3,4,4,3,3,4,5,5,6,5,6},
155 {5,3,4,4,3,3,3,4,3,4,5,5,5},
156 {4,4,4,3,3,3,3,3,4,5,4,5},
157 {6,5,3,3,3,3,3,3,4,3,6},
158 {6,5,3,3,3,2,3,4,3,6},
170 {1,3,2,3,2,3,2,3,2,3,2,3,2,3,2,1},
171 {7,6,5,4,3,5,4,3,2,3,2,3,2,1,0},
172 {5,7,6,5,4,3,4,3,2,3,2,1,1,0},
173 {3,7,5,4,6,5,4,3,3,2,2,1,0},
174 {5,4,3,7,6,5,4,3,2,1,1,0},
175 {1,1,7,6,5,4,3,2,1,1,0},
176 {1,1,5,4,3,3,2,1,1,0},
200 { 1, 3, 3, 4, 4, 4, 5, 5 },
201 { 3, 2, 3, 3, 3, 3, 3 },
202 { 3, 3, 2, 2, 3, 3 },
210 { 1, 2, 3, 2, 3, 1, 1, 0 },
211 { 0, 1, 1, 4, 5, 6, 7 },
212 { 0, 1, 1, 2, 6, 7 },
226 {3,3,3,3,3,3,3,4,5,6,7,8,9,10,11},
236 {7,6,5,4,3,2,1,1,1,1,1,1,1,1,1},
271 #define LEVEL_TAB_BITS 8
274 #define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8
275 #define CHROMA422_DC_COEFF_TOKEN_VLC_BITS 13
276 #define COEFF_TOKEN_VLC_BITS 8
277 #define TOTAL_ZEROS_VLC_BITS 9
278 #define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3
279 #define CHROMA422_DC_TOTAL_ZEROS_VLC_BITS 5
280 #define RUN_VLC_BITS 3
281 #define RUN7_VLC_BITS 6
288 const int index8=
scan8[n];
293 if(i<64) i= (i+1)>>1;
304 for(suffix_length=0; suffix_length<7; suffix_length++){
309 int level_code = (prefix << suffix_length) +
310 (i >> (av_log2(i) - suffix_length)) - (1 << suffix_length);
311 int mask = -(level_code&1);
312 level_code = (((2 + level_code) >> 1) ^
mask) - mask;
368 init_vlc(&chroma_dc_total_zeros_vlc[i],
378 init_vlc(&chroma422_dc_total_zeros_vlc[i],
426 log= 32 - av_log2(buf);
428 print_bin(buf>>(32-log), log);
447 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};
449 int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before;
458 total_coeff= coeff_token>>2;
463 total_coeff= coeff_token>>2;
467 total_coeff= coeff_token>>2;
476 if(total_coeff > (
unsigned)max_coeff) {
481 trailing_ones= coeff_token&3;
482 tprintf(h->
s.
avctx,
"trailing:%d, total:%d\n", trailing_ones, total_coeff);
483 assert(total_coeff<=16);
487 level[0] = 1-((i&4)>>1);
488 level[1] = 1-((i&2) );
489 level[2] = 1-((i&1)<<1);
491 if(trailing_ones<total_coeff) {
493 int suffix_length = total_coeff > 10 & trailing_ones < 3;
498 if(level_code >= 100){
499 prefix= level_code - 100;
509 }
else if(prefix==14){
513 level_code= prefix +
get_bits(gb, 4);
515 level_code= 30 +
get_bits(gb, prefix-3);
521 level_code += (1<<(prefix-3))-4096;
525 if(trailing_ones < 3) level_code += 2;
528 mask= -(level_code&1);
529 level[trailing_ones]= (((2+level_code)>>1) ^
mask) - mask;
531 level_code += ((level_code>>31)|1) & -(trailing_ones < 3);
533 suffix_length = 1 + (level_code + 3
U > 6
U);
534 level[trailing_ones]= level_code;
538 for(i=trailing_ones+1;i<total_coeff;i++) {
539 static const unsigned int suffix_limit[7] = {0,3,6,12,24,48,INT_MAX };
544 if(level_code >= 100){
545 prefix= level_code - 100;
550 level_code = (prefix<<suffix_length) +
get_bits(gb, suffix_length);
552 level_code = (15<<suffix_length) +
get_bits(gb, prefix-3);
554 level_code += (1<<(prefix-3))-4096;
556 mask= -(level_code&1);
557 level_code= (((2+level_code)>>1) ^
mask) - mask;
559 level[i]= level_code;
560 suffix_length+= suffix_limit[suffix_length] + level_code > 2
U*suffix_limit[suffix_length];
564 if(total_coeff == max_coeff)
567 if (max_coeff <= 8) {
569 zeros_left =
get_vlc2(gb, (chroma_dc_total_zeros_vlc-1)[total_coeff].table,
572 zeros_left =
get_vlc2(gb, (chroma422_dc_total_zeros_vlc-1)[total_coeff].table,
579 #define STORE_BLOCK(type) \
580 scantable += zeros_left + total_coeff - 1; \
581 if(n >= LUMA_DC_BLOCK_INDEX){ \
582 ((type*)block)[*scantable] = level[0]; \
583 for(i=1;i<total_coeff && zeros_left > 0;i++) { \
585 run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1); \
587 run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \
588 zeros_left -= run_before; \
589 scantable -= 1 + run_before; \
590 ((type*)block)[*scantable]= level[i]; \
592 for(;i<total_coeff;i++) { \
594 ((type*)block)[*scantable]= level[i]; \
597 ((type*)block)[*scantable] = ((int)(level[0] * qmul[*scantable] + 32))>>6; \
598 for(i=1;i<total_coeff && zeros_left > 0;i++) { \
600 run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1); \
602 run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \
603 zeros_left -= run_before; \
604 scantable -= 1 + run_before; \
605 ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
607 for(;i<total_coeff;i++) { \
609 ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
640 assert((cbp&15) == 0 || (cbp&15) == 15);
643 for(i8x8=0; i8x8<4; i8x8++){
644 for(i4x4=0; i4x4<4; i4x4++){
645 const int index= i4x4 + 4*i8x8 + p*16;
658 int cqm = (
IS_INTRA( mb_type ) ? 0:3)+p;
661 for(i8x8=0; i8x8<4; i8x8++){
666 for(i4x4=0; i4x4<4; i4x4++){
667 const int index= i4x4 + 4*i8x8 + p*16;
673 nnz[0] += nnz[1] + nnz[8] + nnz[9];
674 new_cbp |= !!nnz[0] << i8x8;
676 for(i4x4=0; i4x4<4; i4x4++){
677 const int index= i4x4 + 4*i8x8 + p*16;
687 nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;
698 unsigned int mb_type,
cbp;
722 if( (s->
mb_y&1) == 0 )
735 goto decode_intra_mb;
743 goto decode_intra_mb;
767 static const uint16_t mb_sizes[4] = {256,384,512,768};
778 for(x=0; x < mb_size; x++){
812 for(i=0; i<16; i+=di){
817 mode = rem_mode + (rem_mode >= mode);
841 }
else if(partition_count==4){
842 int i, j, sub_partition_count[4], list, ref[2][4];
882 }
else if(ref_count == 2){
914 for(j=0; j<sub_partition_count[i]; j++){
916 const int index= 4*i + block_width*j;
939 uint32_t *p= (uint32_t *)&h->
mv_cache[list][
scan8[4*i] ][0];
954 if(
IS_DIR(mb_type, 0, list)){
970 if(
IS_DIR(mb_type, 0, list)){
984 if(
IS_DIR(mb_type, i, list)){
1004 if(
IS_DIR(mb_type, i, list)){
1021 if(
IS_DIR(mb_type, i, list)){
1041 if(
IS_DIR(mb_type, i, list)){
1079 if(dct8x8_allowed && (cbp&15) && !
IS_INTRA(mb_type)){
1087 int i4x4, i8x8, chroma_idx;
1091 const uint8_t *scan, *scan8x8;
1106 if(((
unsigned)s->
qscale) > max_qp){
1108 else s->
qscale-= max_qp+1;
1109 if(((
unsigned)s->
qscale) > max_qp){
1131 for(chroma_idx=0; chroma_idx<2; chroma_idx++)
1140 for(chroma_idx=0; chroma_idx<2; chroma_idx++){
1143 for (i8x8 = 0; i8x8 < 2; i8x8++) {
1144 for (i4x4 = 0; i4x4 < 4; i4x4++) {
1145 const int index = 16 + 16*chroma_idx + 8*i8x8 + i4x4;
1158 for(chroma_idx=0; chroma_idx<2; chroma_idx++)
1165 for(chroma_idx=0; chroma_idx<2; chroma_idx++){
1167 for(i4x4=0; i4x4<4; i4x4++){
1168 const int index= 16 + 16*chroma_idx + i4x4;
1169 if(
decode_residual(h, gb, h->
mb + (16*index << pixel_shift), index, scan + 1, qmul, 15) < 0){