Mercurial > libavcodec.hg
comparison ratecontrol.c @ 2493:258120c61eea libavcodec
Border processing adaptive quant patch by (Christophe Massiot |cmassiot freebox fr)
author | michael |
---|---|
date | Wed, 02 Feb 2005 18:49:04 +0000 |
parents | 87b7fbed8609 |
children | 36d70fbb31c5 |
comparison
equal
deleted
inserted
replaced
2492:57ba17bd3924 | 2493:258120c61eea |
---|---|
499 const float lumi_masking= s->avctx->lumi_masking / (128.0*128.0); | 499 const float lumi_masking= s->avctx->lumi_masking / (128.0*128.0); |
500 const float dark_masking= s->avctx->dark_masking / (128.0*128.0); | 500 const float dark_masking= s->avctx->dark_masking / (128.0*128.0); |
501 const float temp_cplx_masking= s->avctx->temporal_cplx_masking; | 501 const float temp_cplx_masking= s->avctx->temporal_cplx_masking; |
502 const float spatial_cplx_masking = s->avctx->spatial_cplx_masking; | 502 const float spatial_cplx_masking = s->avctx->spatial_cplx_masking; |
503 const float p_masking = s->avctx->p_masking; | 503 const float p_masking = s->avctx->p_masking; |
504 const float border_masking = s->avctx->border_masking; | |
504 float bits_sum= 0.0; | 505 float bits_sum= 0.0; |
505 float cplx_sum= 0.0; | 506 float cplx_sum= 0.0; |
506 float cplx_tab[s->mb_num]; | 507 float cplx_tab[s->mb_num]; |
507 float bits_tab[s->mb_num]; | 508 float bits_tab[s->mb_num]; |
508 const int qmin= s->avctx->lmin; | 509 const int qmin= s->avctx->lmin; |
509 const int qmax= s->avctx->lmax; | 510 const int qmax= s->avctx->lmax; |
510 Picture * const pic= &s->current_picture; | 511 Picture * const pic= &s->current_picture; |
512 const int mb_width = s->mb_width; | |
513 const int mb_height = s->mb_height; | |
511 | 514 |
512 for(i=0; i<s->mb_num; i++){ | 515 for(i=0; i<s->mb_num; i++){ |
513 const int mb_xy= s->mb_index2xy[i]; | 516 const int mb_xy= s->mb_index2xy[i]; |
514 float temp_cplx= sqrt(pic->mc_mb_var[mb_xy]); //FIXME merge in pow() | 517 float temp_cplx= sqrt(pic->mc_mb_var[mb_xy]); //FIXME merge in pow() |
515 float spat_cplx= sqrt(pic->mb_var[mb_xy]); | 518 float spat_cplx= sqrt(pic->mb_var[mb_xy]); |
516 const int lumi= pic->mb_mean[mb_xy]; | 519 const int lumi= pic->mb_mean[mb_xy]; |
517 float bits, cplx, factor; | 520 float bits, cplx, factor; |
521 int mb_x = mb_xy % s->mb_stride; | |
522 int mb_y = mb_xy / s->mb_stride; | |
523 int mb_distance; | |
524 float mb_factor = 0.0; | |
518 #if 0 | 525 #if 0 |
519 if(spat_cplx < q/3) spat_cplx= q/3; //FIXME finetune | 526 if(spat_cplx < q/3) spat_cplx= q/3; //FIXME finetune |
520 if(temp_cplx < q/3) temp_cplx= q/3; //FIXME finetune | 527 if(temp_cplx < q/3) temp_cplx= q/3; //FIXME finetune |
521 #endif | 528 #endif |
522 if(spat_cplx < 4) spat_cplx= 4; //FIXME finetune | 529 if(spat_cplx < 4) spat_cplx= 4; //FIXME finetune |
533 | 540 |
534 if(lumi>127) | 541 if(lumi>127) |
535 factor*= (1.0 - (lumi-128)*(lumi-128)*lumi_masking); | 542 factor*= (1.0 - (lumi-128)*(lumi-128)*lumi_masking); |
536 else | 543 else |
537 factor*= (1.0 - (lumi-128)*(lumi-128)*dark_masking); | 544 factor*= (1.0 - (lumi-128)*(lumi-128)*dark_masking); |
545 | |
546 if(mb_x < mb_width/5){ | |
547 mb_distance = mb_width/5 - mb_x; | |
548 mb_factor = (float)mb_distance / (float)(mb_width/5); | |
549 }else if(mb_x > 4*mb_width/5){ | |
550 mb_distance = mb_x - 4*mb_width/5; | |
551 mb_factor = (float)mb_distance / (float)(mb_width/5); | |
552 } | |
553 if(mb_y < mb_height/5){ | |
554 mb_distance = mb_height/5 - mb_y; | |
555 mb_factor = FFMAX(mb_factor, (float)mb_distance / (float)(mb_height/5)); | |
556 }else if(mb_y > 4*mb_height/5){ | |
557 mb_distance = mb_y - 4*mb_height/5; | |
558 mb_factor = FFMAX(mb_factor, (float)mb_distance / (float)(mb_height/5)); | |
559 } | |
560 | |
561 factor*= 1.0 - border_masking*mb_factor; | |
538 | 562 |
539 if(factor<0.00001) factor= 0.00001; | 563 if(factor<0.00001) factor= 0.00001; |
540 | 564 |
541 bits= cplx*factor; | 565 bits= cplx*factor; |
542 cplx_sum+= cplx; | 566 cplx_sum+= cplx; |