Mercurial > libavcodec.hg
comparison h263.c @ 695:3525da287ee2 libavcodec
adaptive quantization for h263
author | michaelni |
---|---|
date | Tue, 24 Sep 2002 15:07:44 +0000 |
parents | 852b5a416161 |
children | c622224012f0 |
comparison
equal
deleted
inserted
replaced
694:20810b0193ef | 695:3525da287ee2 |
---|---|
330 } | 330 } |
331 | 331 |
332 return score0 > score1 ? 1 : 0; | 332 return score0 > score1 ? 1 : 0; |
333 } | 333 } |
334 | 334 |
335 void ff_clean_mpeg4_qscales(MpegEncContext *s){ | 335 void ff_clean_h263_qscales(MpegEncContext *s){ |
336 int i; | 336 int i; |
337 /* more braindead iso mpeg mess */ | |
338 | 337 |
339 for(i=1; i<s->mb_num; i++){ | 338 for(i=1; i<s->mb_num; i++){ |
340 if(s->qscale_table[i] - s->qscale_table[i-1] >2) | 339 if(s->qscale_table[i] - s->qscale_table[i-1] >2) |
341 s->qscale_table[i]= s->qscale_table[i-1]+2; | 340 s->qscale_table[i]= s->qscale_table[i-1]+2; |
342 } | 341 } |
343 for(i=s->mb_num-2; i>=0; i--){ | 342 for(i=s->mb_num-2; i>=0; i--){ |
344 if(s->qscale_table[i] - s->qscale_table[i+1] >2) | 343 if(s->qscale_table[i] - s->qscale_table[i+1] >2) |
345 s->qscale_table[i]= s->qscale_table[i+1]+2; | 344 s->qscale_table[i]= s->qscale_table[i+1]+2; |
346 } | 345 } |
346 } | |
347 | |
348 void ff_clean_mpeg4_qscales(MpegEncContext *s){ | |
349 int i; | |
350 | |
351 ff_clean_h263_qscales(s); | |
347 | 352 |
348 for(i=1; i<s->mb_num; i++){ | 353 for(i=1; i<s->mb_num; i++){ |
349 if(s->qscale_table[i] != s->qscale_table[i-1] && (s->mb_type[i]&MB_TYPE_INTER4V)){ | 354 if(s->qscale_table[i] != s->qscale_table[i-1] && (s->mb_type[i]&MB_TYPE_INTER4V)){ |
350 s->mb_type[i]&= ~MB_TYPE_INTER4V; | 355 s->mb_type[i]&= ~MB_TYPE_INTER4V; |
351 s->mb_type[i]|= MB_TYPE_INTER; | 356 s->mb_type[i]|= MB_TYPE_INTER; |
741 { | 746 { |
742 int cbpc, cbpy, i, cbp, pred_x, pred_y; | 747 int cbpc, cbpy, i, cbp, pred_x, pred_y; |
743 INT16 pred_dc; | 748 INT16 pred_dc; |
744 INT16 rec_intradc[6]; | 749 INT16 rec_intradc[6]; |
745 UINT16 *dc_ptr[6]; | 750 UINT16 *dc_ptr[6]; |
751 const int dquant_code[5]= {1,0,9,2,3}; | |
746 | 752 |
747 //printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); | 753 //printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); |
748 if (!s->mb_intra) { | 754 if (!s->mb_intra) { |
749 /* compute cbp */ | 755 /* compute cbp */ |
750 cbp = 0; | 756 cbp = 0; |
751 for (i = 0; i < 6; i++) { | 757 for (i = 0; i < 6; i++) { |
752 if (s->block_last_index[i] >= 0) | 758 if (s->block_last_index[i] >= 0) |
753 cbp |= 1 << (5 - i); | 759 cbp |= 1 << (5 - i); |
754 } | 760 } |
755 if ((cbp | motion_x | motion_y) == 0) { | 761 if ((cbp | motion_x | motion_y | s->dquant) == 0) { |
756 /* skip macroblock */ | 762 /* skip macroblock */ |
757 put_bits(&s->pb, 1, 1); | 763 put_bits(&s->pb, 1, 1); |
758 return; | 764 return; |
759 } | 765 } |
760 put_bits(&s->pb, 1, 0); /* mb coded */ | 766 put_bits(&s->pb, 1, 0); /* mb coded */ |
761 cbpc = cbp & 3; | 767 cbpc = cbp & 3; |
768 if(s->dquant) cbpc+= 8; | |
762 put_bits(&s->pb, | 769 put_bits(&s->pb, |
763 inter_MCBPC_bits[cbpc], | 770 inter_MCBPC_bits[cbpc], |
764 inter_MCBPC_code[cbpc]); | 771 inter_MCBPC_code[cbpc]); |
765 cbpy = cbp >> 2; | 772 cbpy = cbp >> 2; |
766 cbpy ^= 0xf; | 773 cbpy ^= 0xf; |
767 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | 774 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
775 if(s->dquant) | |
776 put_bits(&s->pb, 2, dquant_code[s->dquant+2]); | |
768 | 777 |
769 /* motion vectors: 16x16 mode only now */ | 778 /* motion vectors: 16x16 mode only now */ |
770 h263_pred_motion(s, 0, &pred_x, &pred_y); | 779 h263_pred_motion(s, 0, &pred_x, &pred_y); |
771 | 780 |
772 if (!s->umvplus) { | 781 if (!s->umvplus) { |
826 cbp |= 1 << (5 - i); | 835 cbp |= 1 << (5 - i); |
827 } | 836 } |
828 | 837 |
829 cbpc = cbp & 3; | 838 cbpc = cbp & 3; |
830 if (s->pict_type == I_TYPE) { | 839 if (s->pict_type == I_TYPE) { |
840 if(s->dquant) cbpc+=4; | |
831 put_bits(&s->pb, | 841 put_bits(&s->pb, |
832 intra_MCBPC_bits[cbpc], | 842 intra_MCBPC_bits[cbpc], |
833 intra_MCBPC_code[cbpc]); | 843 intra_MCBPC_code[cbpc]); |
834 } else { | 844 } else { |
845 if(s->dquant) cbpc+=8; | |
835 put_bits(&s->pb, 1, 0); /* mb coded */ | 846 put_bits(&s->pb, 1, 0); /* mb coded */ |
836 put_bits(&s->pb, | 847 put_bits(&s->pb, |
837 inter_MCBPC_bits[cbpc + 4], | 848 inter_MCBPC_bits[cbpc + 4], |
838 inter_MCBPC_code[cbpc + 4]); | 849 inter_MCBPC_code[cbpc + 4]); |
839 } | 850 } |
841 /* XXX: currently, we do not try to use ac prediction */ | 852 /* XXX: currently, we do not try to use ac prediction */ |
842 put_bits(&s->pb, 1, 0); /* no AC prediction */ | 853 put_bits(&s->pb, 1, 0); /* no AC prediction */ |
843 } | 854 } |
844 cbpy = cbp >> 2; | 855 cbpy = cbp >> 2; |
845 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | 856 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
857 if(s->dquant) | |
858 put_bits(&s->pb, 2, dquant_code[s->dquant+2]); | |
846 } | 859 } |
847 | 860 |
848 for(i=0; i<6; i++) { | 861 for(i=0; i<6; i++) { |
849 /* encode each block */ | 862 /* encode each block */ |
850 h263_encode_block(s, block[i], i); | 863 h263_encode_block(s, block[i], i); |