| 529 | } |
| 530 | |
| 531 | static void adaptive_quantization(MpegEncContext *s, double q){ |
| 532 | int i; |
| 533 | const float lumi_masking= s->avctx->lumi_masking / (128.0*128.0); |
| 534 | const float dark_masking= s->avctx->dark_masking / (128.0*128.0); |
| 535 | const float temp_cplx_masking= s->avctx->temporal_cplx_masking; |
| 536 | const float spatial_cplx_masking = s->avctx->spatial_cplx_masking; |
| 537 | const float p_masking = s->avctx->p_masking; |
| 538 | const float border_masking = s->avctx->border_masking; |
| 539 | float bits_sum= 0.0; |
| 540 | float cplx_sum= 0.0; |
| 541 | float cplx_tab[s->mb_num]; |
| 542 | float bits_tab[s->mb_num]; |
| 543 | const int qmin= s->avctx->mb_lmin; |
| 544 | const int qmax= s->avctx->mb_lmax; |
| 545 | Picture * const pic= &s->current_picture; |
| 546 | const int mb_width = s->mb_width; |
| 547 | const int mb_height = s->mb_height; |
| 548 | |
| 549 | for(i=0; i<s->mb_num; i++){ |
| 550 | const int mb_xy= s->mb_index2xy[i]; |
| 551 | float temp_cplx= sqrt(pic->mc_mb_var[mb_xy]); //FIXME merge in pow() |
| 552 | float spat_cplx= sqrt(pic->mb_var[mb_xy]); |
| 553 | const int lumi= pic->mb_mean[mb_xy]; |
| 554 | float bits, cplx, factor; |
| 555 | int mb_x = mb_xy % s->mb_stride; |
| 556 | int mb_y = mb_xy / s->mb_stride; |
| 557 | int mb_distance; |
| 558 | float mb_factor = 0.0; |
| 559 | #if 0 |
| 560 | if(spat_cplx < q/3) spat_cplx= q/3; //FIXME finetune |
| 561 | if(temp_cplx < q/3) temp_cplx= q/3; //FIXME finetune |
| 562 | #endif |
| 563 | if(spat_cplx < 4) spat_cplx= 4; //FIXME finetune |
| 564 | if(temp_cplx < 4) temp_cplx= 4; //FIXME finetune |
| 565 | |
| 566 | if((s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_INTRA)){//FIXME hq mode |
| 567 | cplx= spat_cplx; |
| 568 | factor= 1.0 + p_masking; |
| 569 | }else{ |
| 570 | cplx= temp_cplx; |
| 571 | factor= pow(temp_cplx, - temp_cplx_masking); |
| 572 | } |
| 573 | factor*=pow(spat_cplx, - spatial_cplx_masking); |
| 574 | |
| 575 | if(lumi>127) |
| 576 | factor*= (1.0 - (lumi-128)*(lumi-128)*lumi_masking); |
| 577 | else |
| 578 | factor*= (1.0 - (lumi-128)*(lumi-128)*dark_masking); |
| 579 | |
| 580 | if(mb_x < mb_width/5){ |
| 581 | mb_distance = mb_width/5 - mb_x; |
| 582 | mb_factor = (float)mb_distance / (float)(mb_width/5); |
| 583 | }else if(mb_x > 4*mb_width/5){ |
| 584 | mb_distance = mb_x - 4*mb_width/5; |
| 585 | mb_factor = (float)mb_distance / (float)(mb_width/5); |
| 586 | } |
| 587 | if(mb_y < mb_height/5){ |
| 588 | mb_distance = mb_height/5 - mb_y; |
no outgoing calls
no test coverage detected