comparison mpegvideo.c @ 1785:14d918d0ef42 libavcodec

analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
author michael
date Fri, 06 Feb 2004 03:56:05 +0000
parents 65f7bd09f37b
children b7340afa261a
comparison
equal deleted inserted replaced
1784:65f7bd09f37b 1785:14d918d0ef42
4939 4939
4940 static int dct_quantize_refine(MpegEncContext *s, //FIXME breaks denoise? 4940 static int dct_quantize_refine(MpegEncContext *s, //FIXME breaks denoise?
4941 DCTELEM *block, int16_t *weight, DCTELEM *orig, 4941 DCTELEM *block, int16_t *weight, DCTELEM *orig,
4942 int n, int qscale){ 4942 int n, int qscale){
4943 int16_t rem[64]; 4943 int16_t rem[64];
4944 DCTELEM d1[64];
4944 const int *qmat; 4945 const int *qmat;
4945 const uint8_t *scantable= s->intra_scantable.scantable; 4946 const uint8_t *scantable= s->intra_scantable.scantable;
4946 const uint8_t *perm_scantable= s->intra_scantable.permutated; 4947 const uint8_t *perm_scantable= s->intra_scantable.permutated;
4947 // unsigned int threshold1, threshold2; 4948 // unsigned int threshold1, threshold2;
4948 // int bias=0; 4949 // int bias=0;
5059 for(;;){ 5060 for(;;){
5060 int best_score=s->dsp.try_8x8basis(rem, weight, basis[0], 0); 5061 int best_score=s->dsp.try_8x8basis(rem, weight, basis[0], 0);
5061 int nochange_score= best_score; 5062 int nochange_score= best_score;
5062 int best_coeff=0; 5063 int best_coeff=0;
5063 int best_change=0; 5064 int best_change=0;
5064 int run2, best_unquant_change; 5065 int run2, best_unquant_change, analyze_gradient;
5065 #ifdef REFINE_STATS 5066 #ifdef REFINE_STATS
5066 {START_TIMER 5067 {START_TIMER
5067 #endif 5068 #endif
5069 analyze_gradient = last_non_zero > 2 || s->avctx->quantizer_noise_shaping >= 3;
5070
5071 if(analyze_gradient){
5072 #ifdef REFINE_STATS
5073 {START_TIMER
5074 #endif
5075 for(i=0; i<64; i++){
5076 int w= weight[i];
5077
5078 d1[i] = (rem[i]*w*w + (1<<(RECON_SHIFT+12-1)))>>(RECON_SHIFT+12);
5079 }
5080 #ifdef REFINE_STATS
5081 STOP_TIMER("rem*w*w")}
5082 {START_TIMER
5083 #endif
5084 s->dsp.fdct(d1);
5085 #ifdef REFINE_STATS
5086 STOP_TIMER("dct")}
5087 #endif
5088 }
5089
5068 if(start_i){ 5090 if(start_i){
5069 const int level= block[0]; 5091 const int level= block[0];
5070 int change, old_coeff; 5092 int change, old_coeff;
5071 5093
5072 assert(s->mb_intra); 5094 assert(s->mb_intra);
5139 score += last_length[UNI_AC_ENC_INDEX(run, new_level+64)] 5161 score += last_length[UNI_AC_ENC_INDEX(run, new_level+64)]
5140 - last_length[UNI_AC_ENC_INDEX(run, level+64)]; 5162 - last_length[UNI_AC_ENC_INDEX(run, level+64)];
5141 } 5163 }
5142 }else{ 5164 }else{
5143 assert(ABS(new_level)==1); 5165 assert(ABS(new_level)==1);
5166
5167 if(analyze_gradient){
5168 int g= d1[ scantable[i] ];
5169 if(g && (g^new_level) >= 0)
5170 continue;
5171 }
5172
5144 if(i < last_non_zero){ 5173 if(i < last_non_zero){
5145 int next_i= i + run2 + 1; 5174 int next_i= i + run2 + 1;
5146 int next_level= block[ perm_scantable[next_i] ] + 64; 5175 int next_level= block[ perm_scantable[next_i] ] + 64;
5147 5176
5148 if(next_level&(~127)) 5177 if(next_level&(~127))