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

📄 fast_me.c

📁 JM 11.0 KTA 2.1 Source Code
💻 C
📖 第 1 页 / 共 5 页
字号:
                         get_line = FastLine4X;
                       }
                       else
                       {
                         get_line = UMVLine4X;    
                       }
                       
                       search_range_dynamic = 3;
                       pred_frac_mv_x = (pred_mv_x - *mv_x)%4;
                       pred_frac_mv_y = (pred_mv_y - *mv_y)%4; 
                       
                       pred_frac_up_mv_x = (pred_MV_uplayer[0] - *mv_x)%4;
                       pred_frac_up_mv_y = (pred_MV_uplayer[1] - *mv_y)%4;
                       
                       
                       memset(SearchState[0],0,(2*search_range_dynamic+1)*(2*search_range_dynamic+1));
                       
                       if(input->hadamard)
                       {
                         cand_mv_x = *mv_x;    
                         cand_mv_y = *mv_y;    
#ifdef EIGHTH_PEL
                         mv_cost = MV_COST (lambda_factor, mv_shift, cand_mv_x, cand_mv_y, pred_mv_x, pred_mv_y);   
#else
                         mv_cost = MV_COST (lambda_factor, 0, cand_mv_x, cand_mv_y, pred_mv_x, pred_mv_y);
#endif
                         mcost = AddUpSADQuarter(pic_pix_x,pic_pix_y,blocksize_x,blocksize_y,cand_mv_x + pic4_pix_x,cand_mv_y + pic4_pix_y,ref_picture,orig_pic,mv_cost,min_mcost,useABT, blocktype);
                         SearchState[search_range_dynamic][search_range_dynamic] = 1;
                         if (mcost < min_mcost)
                         {
                           min_mcost = mcost;
                           currmv_x = cand_mv_x;
                           currmv_y = cand_mv_y; 
                         }
                       }
                       else
                       {
                         SearchState[search_range_dynamic][search_range_dynamic] = 1;
                         currmv_x = *mv_x;
                         currmv_y = *mv_y; 
                       }
                       
                       if(pred_frac_mv_x!=0 || pred_frac_mv_y!=0)
                       {
                         cand_mv_x = *mv_x + pred_frac_mv_x;    
                         cand_mv_y = *mv_y + pred_frac_mv_y;
#ifdef EIGHTH_PEL
                         mv_cost = MV_COST (lambda_factor, mv_shift, cand_mv_x, cand_mv_y, pred_mv_x, pred_mv_y);    
#else
                         mv_cost = MV_COST (lambda_factor, 0, cand_mv_x, cand_mv_y, pred_mv_x, pred_mv_y);
#endif
                         mcost = AddUpSADQuarter(pic_pix_x,pic_pix_y,blocksize_x,blocksize_y,cand_mv_x + pic4_pix_x, cand_mv_y + pic4_pix_y,ref_picture,orig_pic,mv_cost,min_mcost,useABT, blocktype);
                         SearchState[cand_mv_y -*mv_y + search_range_dynamic][cand_mv_x - *mv_x + search_range_dynamic] = 1;
                         if (mcost < min_mcost)
                         {
                           min_mcost = mcost;
                           currmv_x = cand_mv_x;
                           currmv_y = cand_mv_y; 
                         }
                       }
                       
                       
                       iXMinNow = currmv_x;
                       iYMinNow = currmv_y;
                       for(i=0;i<search_range_dynamic;i++) 
                       {
                         abort_search=1;
                         for (m = 0; m < 4; m++)
                         {
                           cand_mv_x = iXMinNow + Diamond_x[m];    
                           cand_mv_y = iYMinNow + Diamond_y[m]; 
                           
                           if(abs(cand_mv_x - *mv_x) <=search_range_dynamic && abs(cand_mv_y - *mv_y)<= search_range_dynamic)
                           {
                             if(!SearchState[cand_mv_y -*mv_y+ search_range_dynamic][cand_mv_x -*mv_x+ search_range_dynamic])
                             {
#ifdef EIGHTH_PEL
                               mv_cost = MV_COST (lambda_factor, mv_shift, cand_mv_x, cand_mv_y, pred_mv_x, pred_mv_y);    
#else
                               mv_cost = MV_COST (lambda_factor, 0, cand_mv_x, cand_mv_y, pred_mv_x, pred_mv_y);
#endif
                               mcost = AddUpSADQuarter(pic_pix_x,pic_pix_y,blocksize_x,blocksize_y,cand_mv_x + pic4_pix_x, cand_mv_y + pic4_pix_y,ref_picture,orig_pic,mv_cost,min_mcost,useABT, blocktype);
                               SearchState[cand_mv_y - *mv_y + search_range_dynamic][cand_mv_x - *mv_x + search_range_dynamic] = 1;
                               if (mcost < min_mcost)
                               {
                                 min_mcost = mcost;
                                 currmv_x = cand_mv_x;
                                 currmv_y = cand_mv_y; 
                                 abort_search = 0; 
                                 
                               }
                             }
                           }
                         }
                         iXMinNow = currmv_x;
                         iYMinNow = currmv_y;
                         if(abort_search)
                           break;
                       }
#ifdef EIGHTH_PEL
                       // 1/8-pel
                       if( img->mv_res )
                       {
                         *mv_x <<= 1;
                         *mv_y <<= 1;
                         pic4_pix_x <<= 1;
                         pic4_pix_y <<= 1;
                         iXMinNow <<= 1;
                         iYMinNow <<= 1;
                         currmv_x <<= 1;
                         currmv_y <<= 1;
                         search_range_dynamic <<=1;
                         
                         if ((pic4_pix_x + *mv_x > 1) && (pic4_pix_x + *mv_x < 2*max_pos_x4 - 2) &&
                           (pic4_pix_y + *mv_y > 1) && (pic4_pix_y + *mv_y < 2*max_pos_y4 - 2))
                           get_line = FastLine4X8;
                         else
                           get_line = UMVLine4X8;
                         
                         for(i=0;i<search_range_dynamic;i++)
                         {
                           abort_search=1;
                           for (m = 0; m < 4; m++)
                           {
                             cand_mv_x = iXMinNow + Diamond_x[m];
                             cand_mv_y = iYMinNow + Diamond_y[m];
                             
                             if(abs(cand_mv_x - *mv_x) <=search_range_dynamic && abs(cand_mv_y - *mv_y)<= search_range_dynamic)
                             {
                               mv_cost = MV_COST (lambda_factor, mv_shift, cand_mv_x, cand_mv_y, pred_mv_x, pred_mv_y);
                               
                               mcost = AddUpSADQuarter8(pic_pix_x,pic_pix_y,blocksize_x,blocksize_y,cand_mv_x + pic4_pix_x, cand_mv_y + pic4_pix_y,ref_picture,orig_pic,mv_cost,min_mcost,useABT, blocktype);
                               if (mcost < min_mcost)
                               {
                                 min_mcost = mcost;
                                 currmv_x = cand_mv_x;
                                 currmv_y = cand_mv_y;
                                 abort_search = 0;
                               }
                             }
                           }
                           iXMinNow = currmv_x;
                           iYMinNow = currmv_y;
                           if(abort_search)
                             break;
                         }
                       }
#endif
                       *mv_x = currmv_x;
                       *mv_y = currmv_y;
                       
                       //===== return minimum motion cost =====
                       return min_mcost;
}

/*!
************************************************************************
* \brief
* Functions for SAD prediction of intra block cases.
* 1. void   decide_intrabk_SAD() judges the block coding type(intra/inter) 
*    of neibouring blocks
* 2. void skip_intrabk_SAD() set the SAD to zero if neigouring block coding 
*    type is intra
* \date
*    2003.4
************************************************************************
*/
void   decide_intrabk_SAD()
{
  if (img->type != I_SLICE)
  {
    if (img->pix_x == 0 && img->pix_y == 0)
    {
      flag_intra_SAD = 0;
    }
    else if (img->pix_x == 0)
    {
      flag_intra_SAD = flag_intra[(img->pix_x)>>4];
    }
    else if (img->pix_y == 0)
    {
      flag_intra_SAD = flag_intra[((img->pix_x)>>4)-1];
    }
    else 
    {
      flag_intra_SAD = ((flag_intra[(img->pix_x)>>4])||(flag_intra[((img->pix_x)>>4)-1])||(flag_intra[((img->pix_x)>>4)+1])) ;
    }
  }
  return;
}

void skip_intrabk_SAD(int best_mode, int ref_max)
{
  int i,j,k, ref;
  if (img->number > 0) 
    flag_intra[(img->pix_x)>>4] = (best_mode == 9 || best_mode == 10) ? 1:0;
  if (img->type != I_SLICE  && (best_mode == 9 || best_mode == 10))
  {
    for (i=0; i < 4; i++)
    {
      for (j=0; j < 4; j++)
      {
        for (k=0; k < 9;k++)
        {
          fastme_l0_cost[k][j][i] = 0;
          fastme_l1_cost[k][j][i] = 0;
          for (ref=0; ref<ref_max;ref++)
          {
            fastme_ref_cost[ref][k][j][i] = 0;
          }
        }
      }
    }
    
  }
  return;
}


void setup_FME(short ref, int list, int block_y, int block_x, int blocktype, short   ******all_mv)
{
  int N_Bframe=0;
  int n_Bframe=0;
  int temp_blocktype = 0;
  int indication_blocktype[8]={0,0,1,1,2,4,4,5};
  N_Bframe = input->successive_Bframe;
  n_Bframe =(N_Bframe) ? (frame_ctr[B_SLICE]%(N_Bframe+1)): 0;
  
  
  /**************************** MV prediction **********************/ 
  //MV uplayer prediction
  if (blocktype>1) 
  {
    temp_blocktype = indication_blocktype[blocktype];
    pred_MV_uplayer[0] = all_mv[block_y][block_x][list][ref][temp_blocktype][0];
    pred_MV_uplayer[1] = all_mv[block_y][block_x][list][ref][temp_blocktype][1];
    
  }
  
  
  //MV ref-frame prediction
  pred_MV_ref_flag = 0;
  if(list==0)
  {
    if (img->field_picture) 
    {
      if ( ref > 1)
      {
        pred_MV_ref[0] = all_mv[block_y][block_x][0][ref-2][blocktype][0];
        pred_MV_ref[0] = (int)(pred_MV_ref[0]*((ref>>1)+1)/(float)((ref>>1)));
        pred_MV_ref[1] = all_mv[block_y][block_x][0][ref-2][blocktype][1];
        pred_MV_ref[1] = (int)(pred_MV_ref[1]*((ref>>1)+1)/(float)((ref>>1)));
        pred_MV_ref_flag = 1;
      }
      if (img->type == B_SLICE &&  (ref==0 || ref==1) )
      {
        pred_MV_ref[0] =(int) (all_mv[block_y][block_x][1][0][blocktype][0]*(-n_Bframe)/(N_Bframe-n_Bframe+1.0f));
        pred_MV_ref[1] =(int) (all_mv[block_y][block_x][1][0][blocktype][1]*(-n_Bframe)/(N_Bframe-n_Bframe+1.0f));
        pred_MV_ref_flag = 1;
      }
    }
    else //frame case
    {
      if ( ref > 0)
      {
        pred_MV_ref[0] = all_mv[block_y][block_x][0][ref-1][blocktype][0];
        pred_MV_ref[0] = (int)(pred_MV_ref[0]*(ref+1)/(float)(ref));
        pred_MV_ref[1] = all_mv[block_y][block_x][0][ref-1][blocktype][1];
        pred_MV_ref[1] = (int)(pred_MV_ref[1]*(ref+1)/(float)(ref));
        pred_MV_ref_flag = 1;
      }
      if (img->type == B_SLICE && (ref==0)) //B frame forward prediction, first ref
      {
        pred_MV_ref[0] =(int) (all_mv[block_y][block_x][1][0][blocktype][0]*(-n_Bframe)/(N_Bframe-n_Bframe+1.0f));
        pred_MV_ref[1] =(int) (all_mv[block_y][block_x][1][0][blocktype][1]*(-n_Bframe)/(N_Bframe-n_Bframe+1.0f));
        pred_MV_ref_flag = 1;
      }
    }
  }
  /******************************SAD prediction**********************************/
  if (list==0 && ref>0)  //pred_SAD_ref
  {
    
    if (flag_intra_SAD) //add this for irregular motion
    {
      pred_SAD = 0;
    }
    else 
    {
      if (img->field_picture)
      {
        if (ref > 1)
        {
          pred_SAD = fastme_ref_cost[ref-2][blocktype][block_y][block_x];
        }
        else
        {
          pred_SAD = fastme_ref_cost[0][blocktype][block_y][block_x];
        }
      }
      else
      {
        pred_SAD = fastme_ref_cost[ref-1][blocktype][block_y][block_x];
      }
      
    }
  }
  else if (blocktype>1)  // pred_SAD_uplayer
  {
    if (flag_intra_SAD) 
    {
      pred_SAD = 0;
    }
    else
    {
      pred_SAD = (list==1) ? (fastme_l1_cost[temp_blocktype][(img->pix_y>>2)+block_y][(img->pix_x>>2)+block_x]) : (fastme_l0_cost[temp_blocktype][(img->pix_y>>2)+block_y][(img->pix_x>>2)+block_x]);
      pred_SAD /= 2; 
    }
  }
  else pred_SAD = 0 ;  // pred_SAD_space
  
}

/*!
************************************************************************
* \brief
*    FastBipredIntegerPelBlockMotionSearch: fast pixel block motion search for bipred mode
*    this algrithm is called UMHexagonS(see JVT-D016),which includes 
*    four steps with different kinds of search patterns
* \author
*   Main contributors: (see contributors.h for copyright, address and affiliation details)
*   - Zhibo Chen         <chenzhibo@tsinghua.org.cn>
*   - JianFeng Xu        <fenax@video.mdc.tsinghua.edu.cn>
*   - Xiaozhong Xu       <xxz@video.mdc.tsinghua.edu.cn>
* \date   :
*   2006.1
************************************************************************
*/

⌨️ 快捷键说明

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