📄 delegatefilter.cpp
字号:
int width_cr=(width>>1);
int luma_pixel = width * height;
int chroma_pixel = (luma_pixel)>>2;
int temp_difference;
int j,i;
//int padstridehalf=PAD;
unsigned char * ori_image=origi_image;
unsigned char * rec_image;
// Luma.
for (j=0;j<height;j++)
{ rec_image=recon_image+width*(height-1-j);
for (i=0;i<width;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_y += temp_difference * temp_difference;
}
}
//Chroma.
for (j=0;j<height_cr;j++)
{ rec_image=recon_image+luma_pixel+width_cr*(height_cr-1-j);
for (i=0;i<width_cr;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_u += temp_difference * temp_difference;
}
}
for (j=0;j<height_cr;j++)
{ rec_image=recon_image+luma_pixel+width_cr*height_cr+width_cr*(height_cr-1-j);
for (i=0;i<width_cr;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_v += temp_difference * temp_difference;
}
}
}
void CDelegatorFilter::snr_cal_pad(unsigned char* origi_image, unsigned char * recon_image, int width, int height, double *snry, double *snru, double *snrv)
{
double diff_y,diff_u,diff_v;
int height_cr=(height>>1);
int width_cr=(width>>1);
int luma_pixel = width * height;
int chroma_pixel = (luma_pixel)>>2;
int temp_difference;
int j,i;
int padstridehalf=8;
unsigned char * ori_image=origi_image;
unsigned char * rec_image;
unsigned char * pointer=recon_image;
// Luma.
rec_image=recon_image+padstridehalf*(width+2*padstridehalf)+padstridehalf;
diff_y=0;
for (j=0;j<height;j++,rec_image+=2*padstridehalf)
for (i=0;i<width;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_y += temp_difference * temp_difference;
}
//Chroma.
rec_image=recon_image + (2*padstridehalf+width)*(2*padstridehalf+height)*5/4+padstridehalf/2*(width_cr+padstridehalf)+padstridehalf/2;//v
diff_v=0;
for (j=0;j<height_cr;j++,rec_image+=padstridehalf)
for (i=0;i<width_cr;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_v += temp_difference * temp_difference;
}
rec_image=recon_image+(2*padstridehalf+width)*(2*padstridehalf+height)+padstridehalf/2*(width_cr+padstridehalf)+padstridehalf/2;//u
diff_u=0;
for (j=0;j<height_cr;j++,rec_image+=padstridehalf)
for (i=0;i<width_cr;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_u += temp_difference * temp_difference;
}
if (diff_y ==0) diff_y=1;
if (diff_u ==0) diff_u=1;
if (diff_v ==0) diff_v=1;
// Collecting SNR statistics
*snry=10*log10(65025*(double)luma_pixel/diff_y);
*snru=10*log10(65025*(double)chroma_pixel/diff_u);
*snrv=10*log10(65025*(double)chroma_pixel/diff_v);
}
void CDelegatorFilter::snr_cal(unsigned char* origi_image, unsigned char * recon_image, int width, int height)
{
int height_cr=(height>>1);
int width_cr=(width>>1);
int luma_pixel = width * height;
int chroma_pixel = (luma_pixel)>>2;
int temp_difference;
int j,i;
//int padstridehalf=PAD;
const int padstridehalf=0; //yyq no padding
unsigned char * ori_image=origi_image;
unsigned char * rec_image;
unsigned char * pointer=recon_image;
// Luma.
rec_image=pointer+padstridehalf*(width+2*padstridehalf)+padstridehalf;
for (j=0;j<height;j++,rec_image+=2*padstridehalf)
for (i=0;i<width;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_y += temp_difference * temp_difference;
}
//Chroma.
pointer+=(2*padstridehalf+width)*(2*padstridehalf+height);
rec_image=pointer+padstridehalf/2*(width_cr+padstridehalf)+padstridehalf/2;
for (j=0;j<height_cr;j++,rec_image+=padstridehalf)
for (i=0;i<width_cr;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_u += temp_difference * temp_difference;
}
pointer+=(padstridehalf+width_cr)*(padstridehalf+height_cr);
rec_image=pointer+padstridehalf/2*(width_cr+padstridehalf)+padstridehalf/2;
for (j=0;j<height_cr;j++,rec_image+=padstridehalf)
for (i=0;i<width_cr;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_v += temp_difference * temp_difference;
}
}
/*
void CDelegatorFilter::snr_cal(unsigned char* origi_image, unsigned char * recon_image, int width, int height, double *snry, double *snru, double *snrv)
{
double diff_y,diff_u,diff_v;
int height_cr=(height>>1);
int width_cr=(width>>1);
int luma_pixel = width * height;
int chroma_pixel = (luma_pixel)>>2;
int temp_difference;
int j,i;
//int padstridehalf=PAD;
unsigned char * ori_image=origi_image;
unsigned char * rec_image;
// Luma.
diff_y=0;
for (j=0;j<height;j++)
{ rec_image=recon_image+width*(height-1-j);
for (i=0;i<width;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_y += temp_difference * temp_difference;
}
}
//Chroma.
diff_u=0;
for (j=0;j<height_cr;j++)
{ rec_image=recon_image+luma_pixel+width_cr*(height_cr-1-j);
for (i=0;i<width_cr;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_u += temp_difference * temp_difference;
}
}
diff_v=0;
for (j=0;j<height_cr;j++)
{ rec_image=recon_image+luma_pixel+width_cr*height_cr+width_cr*(height_cr-1-j);
for (i=0;i<width_cr;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_v += temp_difference * temp_difference;
}
}
if (diff_y ==0) diff_y=1;
if (diff_u ==0) diff_u=1;
if (diff_v ==0) diff_v=1;
// Collecting SNR statistics
*snry=10*log10(65025*(double)luma_pixel/diff_y);
*snru=10*log10(65025*(double)chroma_pixel/diff_u);
*snrv=10*log10(65025*(double)chroma_pixel/diff_v);
}
void CDelegatorFilter::snr_cal3(unsigned char* origi_image, unsigned char * recon_image, int width, int height, double *snry, double *snru, double *snrv)
{
double diff_y,diff_u,diff_v;
int height_cr=(height>>1);
int width_cr=(width>>1);
int luma_pixel = width * height;
int chroma_pixel = (luma_pixel)>>2;
int temp_difference;
int j,i;
//int padstridehalf=PAD;
const int padstridehalf=0; //yyq no padding
unsigned char * ori_image=origi_image;
unsigned char * rec_image;
unsigned char * pointer=recon_image;
// Luma.
rec_image=pointer+padstridehalf*(width+2*padstridehalf)+padstridehalf;
diff_y=0;
for (j=0;j<height;j++,rec_image+=2*padstridehalf)
for (i=0;i<width;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_y += temp_difference * temp_difference;
}
//Chroma.
pointer+=(2*padstridehalf+width)*(2*padstridehalf+height);
rec_image=pointer+padstridehalf/2*(width_cr+padstridehalf)+padstridehalf/2;
diff_u=0;
for (j=0;j<height_cr;j++,rec_image+=padstridehalf)
for (i=0;i<width_cr;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_u += temp_difference * temp_difference;
}
pointer+=(padstridehalf+width_cr)*(padstridehalf+height_cr);
rec_image=pointer+padstridehalf/2*(width_cr+padstridehalf)+padstridehalf/2;
diff_v=0;
for (j=0;j<height_cr;j++,rec_image+=padstridehalf)
for (i=0;i<width_cr;i++,rec_image++)
{
temp_difference= (*ori_image)-(*rec_image);
ori_image++;
diff_v += temp_difference * temp_difference;
}
if (diff_y ==0) diff_y=1;
if (diff_u ==0) diff_u=1;
if (diff_v ==0) diff_v=1;
// Collecting SNR statistics
*snry=10*log10(65025*(double)luma_pixel/diff_y);
*snru=10*log10(65025*(double)chroma_pixel/diff_u);
*snrv=10*log10(65025*(double)chroma_pixel/diff_v);
}
*/
int CDelegatorFilter::AllocBuffer(void)
{
if(m_pDataYV12)
delete m_pDataYV12;
m_pDataYV12 = new BYTE[m_nWidth*m_nHeight*12/8];
if(!m_pDataYV12)
return 0;
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -