comparison mpeg12.c @ 947:9be53be2d1a9 libavcodec

trellis quantization for mpeg1 rounding bugfix for mpeg1 (seems this was introduced during the ME changes)
author michaelni
date Wed, 01 Jan 2003 00:42:18 +0000
parents caa77cd960c0
children 2d7c9f5738de
comparison
equal deleted inserted replaced
946:4f522c9e6099 947:9be53be2d1a9
64 static inline int mpeg2_decode_block_intra(MpegEncContext *s, 64 static inline int mpeg2_decode_block_intra(MpegEncContext *s,
65 DCTELEM *block, 65 DCTELEM *block,
66 int n); 66 int n);
67 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); 67 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred);
68 68
69 #ifdef CONFIG_ENCODERS
69 static UINT16 mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; 70 static UINT16 mv_penalty[MAX_FCODE+1][MAX_MV*2+1];
70 static UINT8 fcode_tab[MAX_MV*2+1]; 71 static UINT8 fcode_tab[MAX_MV*2+1];
72
73 static uint32_t uni_mpeg1_ac_vlc_bits[64*64*2];
74 static uint8_t uni_mpeg1_ac_vlc_len [64*64*2];
75 #endif
71 76
72 static inline int get_bits_diff(MpegEncContext *s){ 77 static inline int get_bits_diff(MpegEncContext *s){
73 int bits,ret; 78 int bits,ret;
74 79
75 bits= get_bit_count(&s->pb); 80 bits= get_bit_count(&s->pb);
116 rl->rl_vlc[0][i].level= level; 121 rl->rl_vlc[0][i].level= level;
117 rl->rl_vlc[0][i].run= run; 122 rl->rl_vlc[0][i].run= run;
118 } 123 }
119 } 124 }
120 125
126 static void init_uni_ac_vlc(RLTable *rl, uint32_t *uni_ac_vlc_bits, uint8_t *uni_ac_vlc_len){
127 int i;
128
129 for(i=0; i<128; i++){
130 int level= i-64;
131 int run;
132 for(run=0; run<64; run++){
133 int len, bits, code;
134
135 int alevel= ABS(level);
136 int sign= (level>>31)&1;
137
138 if (alevel > rl->max_level[0][run])
139 code= 111; /*rl->n*/
140 else
141 code= rl->index_run[0][run] + alevel - 1;
142
143 if (code < 111 /* rl->n */) {
144 /* store the vlc & sign at once */
145 len= mpeg1_vlc[code][1]+1;
146 bits= (mpeg1_vlc[code][0]<<1) + sign;
147 } else {
148 len= mpeg1_vlc[111/*rl->n*/][1]+6;
149 bits= mpeg1_vlc[111/*rl->n*/][0]<<6;
150
151 bits|= run;
152 if (alevel < 128) {
153 bits<<=8; len+=8;
154 bits|= level & 0xff;
155 } else {
156 bits<<=16; len+=16;
157 bits|= level & 0xff;
158 if (level < 0) {
159 bits|= 0x8001 + level + 255;
160 } else {
161 bits|= level & 0xffff;
162 }
163 }
164 }
165
166 uni_ac_vlc_bits[UNI_AC_ENC_INDEX(run, i)]= bits;
167 uni_ac_vlc_len [UNI_AC_ENC_INDEX(run, i)]= len;
168 }
169 }
170 }
121 171
122 static void put_header(MpegEncContext *s, int header) 172 static void put_header(MpegEncContext *s, int header)
123 { 173 {
124 align_put_bits(&s->pb); 174 align_put_bits(&s->pb);
125 put_bits(&s->pb, 16, header>>16); 175 put_bits(&s->pb, 16, header>>16);
463 int mv; 513 int mv;
464 int i; 514 int i;
465 515
466 done=1; 516 done=1;
467 init_rl(&rl_mpeg1); 517 init_rl(&rl_mpeg1);
468 518
469 for(i=0; i<64; i++) 519 for(i=0; i<64; i++)
470 { 520 {
471 mpeg1_max_level[0][i]= rl_mpeg1.max_level[0][i]; 521 mpeg1_max_level[0][i]= rl_mpeg1.max_level[0][i];
472 mpeg1_index_run[0][i]= rl_mpeg1.index_run[0][i]; 522 mpeg1_index_run[0][i]= rl_mpeg1.index_run[0][i];
473 } 523 }
524
525 init_uni_ac_vlc(&rl_mpeg1, uni_mpeg1_ac_vlc_bits, uni_mpeg1_ac_vlc_len);
474 526
475 /* build unified dc encoding tables */ 527 /* build unified dc encoding tables */
476 for(i=-255; i<256; i++) 528 for(i=-255; i<256; i++)
477 { 529 {
478 int adiff, index; 530 int adiff, index;
530 s->fcode_tab= fcode_tab; 582 s->fcode_tab= fcode_tab;
531 s->min_qcoeff=-255; 583 s->min_qcoeff=-255;
532 s->max_qcoeff= 255; 584 s->max_qcoeff= 255;
533 s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x 585 s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x
534 s->inter_quant_bias= 0; 586 s->inter_quant_bias= 0;
587 s->intra_ac_vlc_length=
588 s->inter_ac_vlc_length= uni_mpeg1_ac_vlc_len;
535 } 589 }
536 590
537 static inline void encode_dc(MpegEncContext *s, int diff, int component) 591 static inline void encode_dc(MpegEncContext *s, int diff, int component)
538 { 592 {
539 if (component == 0) { 593 if (component == 0) {
600 alevel= level; 654 alevel= level;
601 MASK_ABS(sign, alevel) 655 MASK_ABS(sign, alevel)
602 sign&=1; 656 sign&=1;
603 657
604 // code = get_rl_index(rl, 0, run, alevel); 658 // code = get_rl_index(rl, 0, run, alevel);
605 if (alevel > mpeg1_max_level[0][run]) 659 if (alevel <= mpeg1_max_level[0][run]){
606 code= 111; /*rl->n*/
607 else
608 code= mpeg1_index_run[0][run] + alevel - 1; 660 code= mpeg1_index_run[0][run] + alevel - 1;
609
610 if (code < 111 /* rl->n */) {
611 /* store the vlc & sign at once */ 661 /* store the vlc & sign at once */
612 put_bits(&s->pb, mpeg1_vlc[code][1]+1, (mpeg1_vlc[code][0]<<1) + sign); 662 put_bits(&s->pb, mpeg1_vlc[code][1]+1, (mpeg1_vlc[code][0]<<1) + sign);
613 } else { 663 } else {
614 /* escape seems to be pretty rare <5% so i dont optimize it */ 664 /* escape seems to be pretty rare <5% so i dont optimize it */
615 put_bits(&s->pb, mpeg1_vlc[111/*rl->n*/][1], mpeg1_vlc[111/*rl->n*/][0]); 665 put_bits(&s->pb, mpeg1_vlc[111/*rl->n*/][1], mpeg1_vlc[111/*rl->n*/][0]);