📄 spatial_domain_coding.c
字号:
for (p=0;p<9;p++)
{
f_test=(float)(p-4)*(float)ROUNDING_STEP;
SSD=0;
for (n=0;n<8;n++)
{
for (m=0;m<8;m++)
{
currMB->quantizer_indices [by+n][bx+m]=quantizer_index(currMB->prederror [by+n][bx+m], f_test+(adaptive_f_spatial_domain_8x8[img->type==B_SLICE]+img->adjust_adaptive_f_spatial_domain_8x8));
SSD+=img->quad[currMB->prederror[by+n][bx+m]-de_quantizer(currMB->quantizer_indices [by+n][bx+m])];
}
}
#ifdef INTERNAL_BIT_DEPTH_INCREASE
if (img->BitDepthIncrease)
{
SSD = (SSD+((1<<(img->BitDepthIncrease*2-1))))>>(img->BitDepthIncrease*2);
}
#endif
rate=writeLumaCoeff8x8 (block8x8, P8x8, 1);
if (p!=8)
{
reset_coding_state_spatial_domain (cs_spatial_domain_coding_rd_opt);
}
else
{
reset_coding_state (cs_spatial_domain_coding_rd_opt);
}
costs=rd_cost(SSD,rate);
if (costs<costs_min)
{
costs_min=costs;
f_best=f_test;
}
}
*SSD_best=0;
*ctr=0;
for (n=0;n<8;n++)
{
for (m=0;m<8;m++)
{
currMB->quantizer_indices [by+n][bx+m]=quantizer_index(currMB->prederror [by+n][bx+m], f_best+(adaptive_f_spatial_domain_8x8[img->type==B_SLICE]+img->adjust_adaptive_f_spatial_domain_8x8));
currMB->quantized_prederror[by+n][bx+m]=de_quantizer (currMB->quantizer_indices[by+n][bx+m]);
*SSD_best+=img->quad[currMB->prederror[by+n][bx+m]-currMB->quantized_prederror[by+n][bx+m]];
if (currMB->quantizer_indices [by+n][bx+m]!=0)
*ctr=*ctr+1;
}
}
#ifdef INTERNAL_BIT_DEPTH_INCREASE
if (img->BitDepthIncrease)
{
*SSD_best = (*SSD_best+((1<<(img->BitDepthIncrease*2-1))))>>(img->BitDepthIncrease*2);
}
#endif
currMB->SD_or_FD_t8x8=store_SD_or_FD;
}
void encode_in_spatial_domain_8x8(int block8x8,int64 *cbp_blk, int *cbp, int *coeff_cost)
{
Macroblock* currMB = &img->mb_data[img->current_mb_nr];
int m,n,k,l;
int b8_y = (block8x8 >>1);
int b8_x = (block8x8 % 2);
int mb_y = b8_y << 3;
int mb_x = b8_x << 3;
int SSD_rd_all = 0;
int rate_rd_all= 0;
int SSD_all_zero =0;
double rd_lowest = 0.0;
int SD_or_FD_t8x8_best=0;
int ox,oy;
int tmp_x,tmp_y;
int tmp_ox,tmp_oy;
int cbp_mask;
int cbp_blk_mask;
int coded;
int SSD_all[2];
int ctr;
int rd;
int rd_opt=0;
int blocks_non_coded;
int blocks_non_coded_best=0;
set_bit( &(currMB->SD_or_FD_t8x8),block8x8,0);
tmp_x = mb_x;
tmp_y = mb_y;
cbp_mask = 1 << block8x8;
coded = ((*cbp) & cbp_mask)>0?1:0;
SSD_all[0]=0;
tmp_x = img->pix_x+mb_x;
tmp_y = img->pix_y+mb_y;
tmp_ox = img->opix_x+mb_x;
tmp_oy = img->opix_y+mb_y;
for (n=0;n<8;n++)
{
for (m=0;m<8;m++)
{
#ifdef INTERNAL_BIT_DEPTH_INCREASE
SSD_all[0]+=SQR_DEPTH(imgY_org[tmp_oy+n][tmp_ox+m], enc_picture->imgY[tmp_y+n][tmp_x+m], input->BitDepthLuma, img->BitDepthIncrease);
#else
SSD_all[0]+=img->quad[imgY_org[tmp_oy+n][tmp_ox+m]-enc_picture->imgY[tmp_y+n][tmp_x+m]];
#endif
}
}
tmp_x = mb_x;
tmp_y = mb_y;
ctr=0;
SSD_all[1]=0;
for (n=0;n<8;n++)
{
for (m=0;m<8;m++)
{
currMB->quantizer_indices [tmp_y+n][tmp_x+m]=quantizer_index(currMB->prederror [tmp_y+n][tmp_x+m], (adaptive_f_spatial_domain_8x8[img->type==B_SLICE]+img->adjust_adaptive_f_spatial_domain_8x8));
currMB->quantized_prederror[tmp_y+n][tmp_x+m]=de_quantizer (currMB->quantizer_indices[tmp_y+n][tmp_x+m]);
if (img->AdaptiveRounding)
{
if (currMB->quantizer_indices[tmp_y+n][tmp_x+m]!=0)
{
#ifdef INTERNAL_BIT_DEPTH_INCREASE
img->adjust_adaptive_f_spatial_domain_8x8 += (float) (ROUNDING_WEIGHT_SD * (abs(currMB->prederror[tmp_y+n][tmp_x+m])-abs(currMB->quantized_prederror[tmp_y+n][tmp_x+m]))/(SD_RD_quant_s_for_all_qps_rec_int[Clip3(0,51,currMB->qp+img->bitdepth_luma_qp_scale)]/256.0));
#else
img->adjust_adaptive_f_spatial_domain_8x8 += (float) (ROUNDING_WEIGHT_SD * (abs(currMB->prederror[tmp_y+n][tmp_x+m])-abs(currMB->quantized_prederror[tmp_y+n][tmp_x+m]))/(SD_RD_quant_s_for_all_qps_rec_int[currMB->qp]/256.0));
#endif
}
}
SSD_all[1]+=img->quad[currMB->prederror[tmp_y+n][tmp_x+m]-currMB->quantized_prederror[tmp_y+n][tmp_x+m]];
if (currMB->quantizer_indices [tmp_y+n][tmp_x+m]!=0)
ctr++;
}
}
#ifdef INTERNAL_BIT_DEPTH_INCREASE
if (img->BitDepthIncrease)
{
SSD_all[1] = (SSD_all[1]+((1<<(img->BitDepthIncrease*2-1))))>>(img->BitDepthIncrease*2);
}
#endif
if (img->AdaptiveRounding && input->SD_Quantizer==1)
{
eliminate_expensive_samples_8x8(tmp_x, tmp_y,&(SSD_all[1]),&ctr);
}
store_coding_state (cs_spatial_domain_coding);
for (rd=0;rd<2;rd++)
{
SSD_rd_all=0;
SSD_rd_all += SSD_all[rd];
blocks_non_coded=0;
if (rd==1 && ctr==0) blocks_non_coded++;
else if (rd==0 && coded==0) blocks_non_coded++;
set_bit(&(currMB->SD_or_FD_t8x8), block8x8, rd);
if (blocks_non_coded==1)
{
rate_rd_all=0;
}
else
{
rate_rd_all=writeLumaCoeff8x8 (block8x8, P8x8, 1);
}
if (rd==1)
reset_coding_state (cs_spatial_domain_coding);
else
reset_coding_state_spatial_domain(cs_spatial_domain_coding);
if (!rd || (rd_cost(SSD_rd_all,rate_rd_all) < rd_lowest) )
{
rd_lowest=rd_cost(SSD_rd_all,rate_rd_all);
rd_opt=rd;
SD_or_FD_t8x8_best=rd;
blocks_non_coded_best=blocks_non_coded;
}
}
SSD_all_zero =0;
for (k=0;k<8;k++)
{
for (l=0;l<8;l++)
{
SSD_all_zero+=img->quad[currMB->prederror[mb_y+l][mb_x+k]];
}
}
#ifdef INTERNAL_BIT_DEPTH_INCREASE
if (img->BitDepthIncrease)
{
SSD_all_zero = (SSD_all_zero+((1<<(img->BitDepthIncrease*2-1))))>>(img->BitDepthIncrease*2);
}
#endif
if ((float)SSD_all_zero<rd_lowest)
{
SD_or_FD_t8x8_best=1;
blocks_non_coded_best=1;
ctr=0;
rd_opt=1;
for (l=0;l<8;l++)
{
memset(&currMB->quantizer_indices [mb_y+l][mb_x],0,8*sizeof(int));
memset(&currMB->quantized_prederror[mb_y+l][mb_x],0,8*sizeof(int));
}
}
set_bit(&(currMB->SD_or_FD_t8x8), block8x8, SD_or_FD_t8x8_best);
if (blocks_non_coded_best==1)
{
*coeff_cost = 0;
set_bit(&(currMB->SD_or_FD_t8x8), block8x8, 0);
}
else if (blocks_non_coded_best==0 && (((*cbp)&(1<<block8x8))==0))
{
*coeff_cost=_LUMA_COEFF_COST_+1;
(*cbp)|=(1<<block8x8);
cbp_blk_mask = 51 << (4*block8x8-2*(block8x8 & 0x01));
*cbp_blk = (*cbp_blk)|cbp_blk_mask;
}
else
{
if (rd_opt!=0 && ctr==0 && coded!=0)
{
cbp_blk_mask = 51 << (4*block8x8-2*(block8x8 & 0x01));
cbp_blk_mask = ~cbp_blk_mask;
*cbp_blk = (*cbp_blk)&cbp_blk_mask;
*cbp |= 1 << block8x8;
set_bit(&(currMB->SD_or_FD_t8x8), block8x8, 0);
}
else if (rd_opt!=0 && ctr!=0 && coded==0)
{
cbp_blk_mask = 51 << (4*block8x8-2*(block8x8 & 0x01));
*cbp_blk = (*cbp_blk)|cbp_blk_mask;
}
}
if (blocks_non_coded_best==0 && rd_opt!=0)
{
for (k=0;k<4;k++)
{
memset(img->cofAC[block8x8][k][0],0,65 * sizeof(int));
memset(img->cofAC[block8x8][k][1],0,65 * sizeof(int));
}
ox=(img->mb_x<<4)+mb_x;
oy=(img->mb_y<<4)+mb_y;
for (l=0;l<8;l++)
{
for (k=0;k<8;k++)
{
#ifdef INTERNAL_BIT_DEPTH_INCREASE
enc_picture->imgY[oy + l][ox + k] = min(((1<<img->bitdepth_luma)-1),max(0,currMB->quantized_prederror[mb_y + l][mb_x + k] + currMB->prediction[mb_y + l][mb_x + k]));
#else
enc_picture->imgY[oy + l][ox + k] = min(255,max(0,currMB->quantized_prederror[mb_y + l][mb_x + k] + currMB->prediction[mb_y + l][mb_x + k]));
#endif
}
}
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -