⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image.c

📁 davinci avs.......................................................
💻 C
📖 第 1 页 / 共 3 页
字号:
  tmpu = (float)(1.0 / pow(10, snr->snr_u / 10));
  tmpv = (float)(1.0 / pow(10, snr->snr_v / 10));
  snr->snr_yuv = (float)(10 * log10(6 / ( tmpy + tmpu + tmpv ) )); 
#endif // _PSNR_YUV_
  
  if (pgImage->number == 0) // first
  {
    snr->snr_y1=(float)(10*log10(65025*(float)(pgImage->width)*(pgImage->height)/(float)diff_y));       // keep luma snr for first frame
    snr->snr_u1=(float)(10*log10(65025*(float)(pgImage->width)*(pgImage->height)/(float)(4*diff_u)));   // keep chroma snr for first frame
    snr->snr_v1=(float)(10*log10(65025*(float)(pgImage->width)*(pgImage->height)/(float)(4*diff_v)));   // keep chroma snr for first frame
    snr->snr_ya=snr->snr_y1;
    snr->snr_ua=snr->snr_u1;
    snr->snr_va=snr->snr_v1;

    if (diff_y == 0)   
      snr->snr_ya=50; // need to assign a reasonable large number so avg snr of entire sequece isn't infinite
    if (diff_u == 0)
      snr->snr_ua=50;
    if (diff_v == 0)
      snr->snr_va=50;
#ifdef _PSNR_YUV_
    if ( diff_y == 0 && diff_u == 0 && diff_v == 0 )
    {
        snr->snr_yuva = 50;
    }
    else
    {
        tmpy = (float)(4.0 / pow(10, snr->snr_y1 / 10));
        tmpu = (float)(1.0 / pow(10, snr->snr_u1 / 10));
        tmpv = (float)(1.0 / pow(10, snr->snr_v1 / 10));
        snr->snr_yuva = (float)(10 * log10(6 / ( tmpy + tmpu + tmpv ) ));
    }
#endif // _PSNR_YUV_
  }
  else
  {
    snr->snr_ya=(float)(snr->snr_ya*(pgImage->number/*+Bframe_ctr*/)+snr->snr_y)/(pgImage->number/*+Bframe_ctr*/+1); // average snr chroma for all frames
    snr->snr_ua=(float)(snr->snr_ua*(pgImage->number/*+Bframe_ctr*/)+snr->snr_u)/(pgImage->number/*+Bframe_ctr*/+1); // average snr luma for all frames
    snr->snr_va=(float)(snr->snr_va*(pgImage->number/*+Bframe_ctr*/)+snr->snr_v)/(pgImage->number/*+Bframe_ctr*/+1); // average snr luma for all frames
#ifdef _PSNR_YUV_
    snr->snr_yuva = (float)(snr->snr_yuva*(pgImage->number)+snr->snr_yuv)/(pgImage->number + 1);
#endif // _PSNR_YUV_
  }
}

/*!
************************************************************************
* \brief
*    Interpolation of 1/4 subpixel
************************************************************************
*/
void get_block(int x_pos, int y_pos, int block[4][4], unsigned char **ref_pic)//mark1
{

    int dx, dy;
    int x, y;
    int i, j;
    int maxold_x,maxold_y;
    int result;
    int tmp_res[26][26];
    int tmp_res_2[26][26];
		int tmp_res_3[26][26];
    static const int COEF_HALF_h[8] = {-1,4,-12,41,41,-12,4,-1};
		static const int COEF_HALF_v[8] = {0,0,-1,5,5,-1,0,0};
		const int iWeight1_2_h = 64;
		const int iWeight1_2_v = 8;


    static const int COEF_QUART[4] = {0, 1, 1, 0};
		const int iWeight1_4 = 2;
		

    //    A  a  1  b  B
    //    c  d  e  f
    //    2  h  3  i
    //    j  k  l  m
    //    C           D

    dx = x_pos & 3;
    dy = y_pos & 3;
    x_pos = ( x_pos - dx ) / 4;
    y_pos = ( y_pos - dy ) / 4;
    maxold_x = pgImage->width  - 1;
    maxold_y = pgImage->height - 1;
    
    if (dx == 0 && dy == 0) 
    {  //fullpel position: A
        for (j = 0; j < BLOCK_SIZE; j++)
        {
            for (i = 0; i < BLOCK_SIZE; i++)
            {
                block[i][j] = ref_pic[max(0, min(maxold_y, y_pos + j))][max(0, min(maxold_x, x_pos + i))];
            }
        }
    }
    else 
    { 
        if ( (dx == 2) && (dy == 0))
        {//horizonal 1/2 position: 1
            for (j = 0; j < BLOCK_SIZE; j++)
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    for (result = 0, x = -3; x < 5; x++)
                    {
                        result += ref_pic[max(0, min(maxold_y, y_pos + j))]
                                         [max(0, min(maxold_x, x_pos + i + x))] 
                                  * COEF_HALF_h[x + 3];
                    }
                    //block[i][j] = max(0, min(255, (result + 1) / 2));
                    //block[i][j] = max(0, min(255, (result + iWeight1_2_h / 2) / iWeight1_2_h));
										block[i][j] = max(0, min(255, (result + iWeight1_2_h / 2)>>6));
                }
            }
        }
        else if ( ( (dx == 1) || (dx == 3) ) && (dy == 0) )
        {//horizonal 1/4 position: a and b  
            for (j = 0; j < BLOCK_SIZE; j++) 
            {
                for (i = -1; i < BLOCK_SIZE + 1; i++) 
                {
                    for (result = 0, x = -3; x < 5; x++)
                    {
                        result += ref_pic[max(0, min(maxold_y, y_pos + j))]
                                         [max(0, min(maxold_x, x_pos + i + x))] 
                                  * COEF_HALF_h[x + 3];
                    }
                    //tmp_res[j][2 * (i + 1)] = max(0, min(255, (result + 4) / 8));
                    tmp_res[j][2 * (i + 1)] = max(0, min(255, (result + iWeight1_2_h / 2 ) >> 6));
                    tmp_res[j][2 * (i + 1) + 1] = ref_pic[max(0, min(maxold_y, y_pos + j))]
                                                         [max(0, min(maxold_x, x_pos + i + 1))];
                }
            }

            for (j = 0; j < BLOCK_SIZE; j++) 
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    for (result = 0, x = -1; x < 3; x++)
                    {

                        if (dx == 1)//a
                        {
                            result += tmp_res[j][2 * i + x + 1] * COEF_QUART[x + 1];
                        }
                        else//b
                        {
                            result += tmp_res[j][2 * i + x + 2] * COEF_QUART[3-(x + 1)];
                        }
                    }
                    //block[i][j] = max(0, min(255, (result + 8) / 16));
                    block[i][j] = max(0, min(255, (result + iWeight1_4 / 2 ) >>1));
                }
            }
        }//else if ( ( (dx == 1) || (dx == 3) ) && (dy == 0) )
        else if ( (dy == 2) && (dx == 0) )
        {//vertical 1/2 position: 2  
            for (j = 0; j < BLOCK_SIZE; j++) 
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    for (result = 0, y = -3; y < 5; y++)
                    {
                        result += ref_pic[max(0, min(maxold_y, y_pos + j + y))]
                                         [max(0, min(maxold_x, x_pos + i))]
                                  * COEF_HALF_v[y + 3];
                    }
                    //block[i][j] = max(0, min(255, (result + 1) / 2));
                    block[i][j] = max(0, min(255, (result + iWeight1_2_v / 2) >>3));
                }
            }
        }//else if ( (dy == 2) && (dx == 0) )
        else if( ( (dy == 1) || (dy == 3)) && (dx == 0) )
        {//vertical 1/4 position: c and j
            for (j = -1; j < BLOCK_SIZE + 1; j++) 
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    for (result = 0, y = -3; y < 5; y++)
                    {
                        result += ref_pic[max(0, min(maxold_y, y_pos + j + y))]
                                         [max(0, min(maxold_x, x_pos + i))]
                                  * COEF_HALF_v[y + 3];
                    }
                    //tmp_res[2 * ( j + 1 )][i] = max(0, min(255, (result + 4) / 8));
                    tmp_res[2 * ( j + 1 )][i] = max(0, min(255, (result + iWeight1_2_v / 2) >>3));
                    tmp_res[2 * ( j + 1 ) + 1][i] = ref_pic[max(0, min(maxold_y, y_pos + j + 1))]
                                                           [max(0, min(maxold_x, x_pos + i))];
                }
            }
            for (j = 0; j < BLOCK_SIZE; j++) 
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    for (result = 0, y = -1; y < 3; y++)
                    {
                        if (dy == 1)//c
                        {
                            result += tmp_res[2 * j + y + 1][i] * COEF_QUART[y + 1];
                        }
                        else//j
                        {
                            result += tmp_res[2 * j + y + 2][i] * COEF_QUART[3-(y + 1)];
                        }
                    }
                    //block[i][j] = max(0, min(255, (result + 8) / 16));
                    block[i][j] = max(0, min(255, (result + iWeight1_4 / 2) >>1));
                }
            }
        }//else if( ( (dy == 1) || (dy == 3)) && (dx == 0) )
        else if ( (dx == 2) && (dy == 2) )
        {//horizonal and vertical 1/2 position: 3    
            for (j = -3; j < BLOCK_SIZE + 4; j++) 
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    for (result = 0, x = -3; x < 5; x++)
                    {
                        result += ref_pic[max(0, min(maxold_y, y_pos + j))]
                                         [max(0, min(maxold_x, x_pos + i + x))] 
                                  * COEF_HALF_h[x + 3];
                    }
                    tmp_res[j + 3][i] = max(0, min(255, (result + iWeight1_2_h / 2) >>6));//max(0, min(255, (result+4)/8));
                }
            }
            for (j = 0; j < BLOCK_SIZE; j++) 
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    for (result = 0, y = -3; y < 5; y++)
                    {
                        result += tmp_res[j + y + 3][i] * COEF_HALF_v[y + 3];
                    }
                    block[i][j] = max(0, min(255, (result + iWeight1_2_v / 2) >>3));
                }
            }
        }
        else if( ( (dx == 1) || (dx == 3) ) && (dy == 2) )
        {//horizonal and vertical 1/4 position: h and i
           
			///////////////////////////////////////////////

			for (j = -3; j < BLOCK_SIZE + 4; j++) 
            {
                for (i = -1; i < BLOCK_SIZE+1; i++) 
                {
                    for (result = 0, x = -3; x < 5; x++)
                    {
                        result += ref_pic[max(0, min(maxold_y, y_pos + j))]
							[max(0, min(maxold_x, x_pos + i + x))] 
							* COEF_HALF_h[x + 3];
                    }
                    tmp_res[j + 3][i+1] = max(0, min(255, (result + iWeight1_2_h / 2) >>6));//max(0, min(255, (result+4)/8));
                }
            }
            for (j = 0; j < BLOCK_SIZE; j++) 
            {
                for (i = -1; i < BLOCK_SIZE+1; i++) 
                {
                    for (result = 0, y = -3; y < 5; y++)
                    {
                        result += tmp_res[j + y + 3][i+1] * COEF_HALF_v[y + 3];
                    }
                    tmp_res_3[j][i+1] = max(0, min(255, (result + iWeight1_2_v / 2) >>3));
                }
            }





			///////////////////////////////////////////////
			for (j = 0; j < BLOCK_SIZE; j++) 
            {
                //for (i = -4; i < BLOCK_SIZE + 5; i++) 
				for (i = 0; i < BLOCK_SIZE + 2; i++) 
                {
                    for (result = 0, y = -3; y < 5; y++)
                    {
                        result += ref_pic[max(0, min(maxold_y, y_pos + j + y))]
                                         [max(0, min(maxold_x, x_pos + i))]
                                  * COEF_HALF_v[y + 3];
                    }
                    tmp_res[j][i] = max(0, min(255, (result + iWeight1_2_v / 2) >>3));//max(0, min(255, (result+4)/8));
                    
                }
            }
            for (j = 0; j < BLOCK_SIZE; j++) 
            {
                for (i = 0; i < BLOCK_SIZE + 2; i++) 
                {
                     tmp_res_2[j][2 * i] = tmp_res_3[j][i];
                     tmp_res_2[j][2 * i + 1] = tmp_res[j][i];
                }
            }
            for (j = 0; j < BLOCK_SIZE; j++) 
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    for (result = 0, x = -1; x < 3; x++)
                    {
                        if (dx == 1)//h
                        {
                            result += tmp_res_2[j][2 * i + x + 1] * COEF_QUART[x + 1];
                        }
                        else
                        {
                            result += tmp_res_2[j][2 * i + x + 2] * COEF_QUART[3-(x + 1)];
                        }
                    }
                    //block[i][j] = max(0, min(255, (result + 8) / 16));
                    block[i][j] = max(0, min(255, (result + iWeight1_4 / 2) >>1));
                }
            }
        }
        else if( ( (dy == 1) || (dy == 3) ) && (dx == 2) )
        {//vertical and horizonal 1/4 position: e and l
            for (j = -4; j < BLOCK_SIZE+5; j++) 
            {
                for (i = 0; i < BLOCK_SIZE; i++) 
                {
                    for (result = 0, x = -3; x < 5; x++)
                    {
                        result += ref_pic[max(0, min(maxold_y, y_pos + j))]
                                         [max(0, min(maxold_x, x_pos + i + x))] 
                                  * COEF_HALF_h[x + 3];
                    }
                    tmp_res[j + 4][i] = max(0, min(255, (result + iWeight1_2_h / 2) >>6));// max(0, min(255, (result+4)/8));
                    //tmp_res[j + 2][i] = max(0, min(255, (result + iWeight1_2 / 2) / iWeight1_2));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -