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

📄 epzs.c

📁 JM 11.0 KTA 2.1 Source Code
💻 C
📖 第 1 页 / 共 5 页
字号:
************************************************************************
* \brief
*    EPZS Block Type Predictors 
************************************************************************
*/
static void EPZSBlockTypePredictors (int block_x, int block_y, int blocktype, int ref, int list,
                                     EPZSStructure * predictor, int *prednum)
{
  short ***all_mv = img->all_mv[block_y][block_x][list];
  
  
  if ((ref > 0) && (blocktype < 5 || img->structure != FRAME))
  {
    predictor->point[*prednum].x = (mv_scale[list][ref][ref-1] * all_mv[ref-1][blocktype][0] + 512) >> 10;
    predictor->point[*prednum].y = (mv_scale[list][ref][ref-1] * all_mv[ref-1][blocktype][1] + 512) >> 10;
    *prednum += ((predictor->point[*prednum].x != 0) || (predictor->point[*prednum].y != 0));    
    
    predictor->point[*prednum].x = (mv_scale[list][ref][0] * all_mv[0][blocktype][0] + 512) >> 10;
    predictor->point[*prednum].y = (mv_scale[list][ref][0] * all_mv[0][blocktype][1] + 512) >> 10;
    *prednum += ((predictor->point[*prednum].x != 0) || (predictor->point[*prednum].y != 0));        
  }
  
  predictor->point[*prednum].x = (all_mv[ref][blk_parent[blocktype]][0] + 2) >> 2;
  predictor->point[*prednum].y = (all_mv[ref][blk_parent[blocktype]][1] + 2) >> 2;
  *prednum += ((predictor->point[*prednum].x != 0) || (predictor->point[*prednum].y != 0));    
  
  if (blocktype != 1)
  {
    predictor->point[*prednum].x = (all_mv[ref][1][0] + 2) >> 2;
    predictor->point[*prednum].y = (all_mv[ref][1][1] + 2) >> 2;
    *prednum += ((predictor->point[*prednum].x != 0) || (predictor->point[*prednum].y != 0));        
  }  
  
  if (blocktype != 4)
  {
    predictor->point[*prednum].x = (all_mv[ref][4][0] + 2) >> 2;
    predictor->point[*prednum].y = (all_mv[ref][4][1] + 2) >> 2;
    *prednum += ((predictor->point[*prednum].x != 0) || (predictor->point[*prednum].y != 0));    
  }
}

/*!
************************************************************************
* \brief
*    EPZS Window Based Predictors 
************************************************************************
*/
static void EPZSWindowPredictors (int mv_x, int mv_y, EPZSStructure *predictor, int *prednum, int extended)
{
  int pos;
  EPZSStructure *windowPred = (extended) ? window_predictor_extended : window_predictor;
  
  for (pos = 0; pos < windowPred->searchPoints; pos++)
  {
    predictor->point[(*prednum)  ].x = mv_x + windowPred->point[pos].x;
    predictor->point[(*prednum)++].y = mv_y + windowPred->point[pos].y;
  }
}

/*!
************************************************************************
* \brief
*    SAD computation 
************************************************************************
*/
static int computeSad(pel_t** cur_pic,
                      int blocksize_y,
                      int blocksize_x, 
                      int blockshape_x,
                      int mcost,
                      int min_mcost,
                      int cand_x,
                      int cand_y)
{
  int y,x4;
  
  pel_t *cur_line, *ref_line;
  for (y=0; y<blocksize_y; y++)
  {
    ref_line  = get_ref_line (blocksize_x, ref_pic, cand_y + y, cand_x, img_height, img_width);
    cur_line = cur_pic [y];
    
    for (x4 = 0; x4 < blockshape_x; x4++)
    {
      mcost += byte_abs[ *cur_line++ - *ref_line++ ];
      mcost += byte_abs[ *cur_line++ - *ref_line++ ];
      mcost += byte_abs[ *cur_line++ - *ref_line++ ];
      mcost += byte_abs[ *cur_line++ - *ref_line++ ];
      //mcost += abs( *cur_line++ - *ref_line++ );
      //mcost += abs( *cur_line++ - *ref_line++ );
      //mcost += abs( *cur_line++ - *ref_line++ );
      //mcost += abs( *cur_line++ - *ref_line++ );
    }    
    if (mcost >= min_mcost) break;
  }
  return mcost;
}

/*!
************************************************************************
* \brief
*    BiPred SAD computation (no weights)
************************************************************************
*/
static int computeBiPredSad1(pel_t** cur_pic,
                             int blocksize_y,
                             int blocksize_x, 
                             int blockshape_x,
                             int mcost,
                             int min_mcost,
                             int cand_x1, int cand_y1, 
                             int cand_x2, int cand_y2)
{
  pel_t *cur_line, *ref1_line, *ref2_line;
  int bi_diff; 
  int y,x4;  
#ifdef  USE_HP_FILTER//BROUND
  int round; 
  img->bipred_rounding_control = (img->nal_reference_idc!=0);
  round = 1 - img->bipred_rounding_control;
#endif
  
  for (y = 0; y < blocksize_y; y++)
  {
    ref2_line = get_ref_line2 (blocksize_x, ref_pic2, cand_y2 + y, cand_x2, img_height, img_width);
    ref1_line = get_ref_line1 (blocksize_x, ref_pic1, cand_y1 + y, cand_x1, img_height, img_width);
    cur_line = cur_pic [y];
    
    for (x4 = 0; x4 < blockshape_x; x4++)
    {         
#ifdef  USE_HP_FILTER//BROUND
      if(input->UseHPFilter != 0)
      {
        bi_diff = (*cur_line++) - ((*ref1_line++ + *ref2_line++ + round)>>1);
      }
      else
      {
        bi_diff = (*cur_line++) - ((*ref1_line++ + *ref2_line++)>>1);
      }
#else
      bi_diff = (*cur_line++) - ((*ref1_line++ + *ref2_line++)>>1);
#endif
      mcost += byte_abs[bi_diff];
#ifdef  USE_HP_FILTER//BROUND
      if(input->UseHPFilter != 0)
      {
        bi_diff = (*cur_line++) - ((*ref1_line++ + *ref2_line++ + round)>>1);
      }
      else
      {
        bi_diff = (*cur_line++) - ((*ref1_line++ + *ref2_line++)>>1);
      }
#else
      bi_diff = (*cur_line++) - ((*ref1_line++ + *ref2_line++)>>1);
#endif
      mcost += byte_abs[bi_diff];
#ifdef  USE_HP_FILTER//BROUND
      if(input->UseHPFilter != 0)
      {
        bi_diff = (*cur_line++) - ((*ref1_line++ + *ref2_line++ + round)>>1);
      }
      else
      {
        bi_diff = (*cur_line++) - ((*ref1_line++ + *ref2_line++)>>1);
      }
#else
      bi_diff = (*cur_line++) - ((*ref1_line++ + *ref2_line++)>>1);
#endif
      mcost += byte_abs[bi_diff];
#ifdef  USE_HP_FILTER//BROUND
      if(input->UseHPFilter != 0)
      {
        bi_diff = (*cur_line++) - ((*ref1_line++ + *ref2_line++ + round)>>1);
      }
      else
      {
        bi_diff = (*cur_line++) - ((*ref1_line++ + *ref2_line++)>>1);
      }
#else
      bi_diff = (*cur_line++) - ((*ref1_line++ + *ref2_line++)>>1);
#endif
      mcost += byte_abs[bi_diff];
    }        
    
    if (mcost >= min_mcost) break;
  }
  return mcost;
}


/*!
************************************************************************
* \brief
*    BiPred SAD computation (with weights)
************************************************************************
*/
static int computeBiPredSad2(pel_t** cur_pic,
                             int blocksize_y,
                             int blocksize_x, 
                             int blockshape_x,
                             int mcost,
                             int min_mcost,
                             int cand_x1, int cand_y1, 
                             int cand_x2, int cand_y2)
{
  pel_t *cur_line, *ref1_line, *ref2_line;
  int bi_diff; 
  int denom = luma_log_weight_denom + 1;
  int lround = 2 * wp_luma_round;
  int y,x4;  
  int weightedpel, pixel1, pixel2;
#ifdef  USE_HP_FILTER//BROUND
  img->bipred_rounding_control = (img->nal_reference_idc!=0);
  if(input->UseHPFilter != 0)
    lround = lround * (1 - img->bipred_rounding_control);
#endif

  for (y=0; y<blocksize_y; y++)
  {
    ref2_line  = get_ref_line2 (blocksize_x, ref_pic2, cand_y2 + y, cand_x2, img_height, img_width);
    ref1_line  = get_ref_line1 (blocksize_x, ref_pic1, cand_y1 + y, cand_x1, img_height, img_width);
    cur_line = cur_pic [y];
    
    for (x4 = 0; x4 < blockshape_x; x4++)
    { 
      pixel1 = weight1 * (*ref1_line++);
      pixel2 = weight2 * (*ref2_line++);
#ifdef USE_HP_FILTER//BROUND
      if(input->UseHPFilter != 0)
      {
        weightedpel =  Clip3 (0, img->max_imgpel_value ,((pixel1 + pixel2 + (offsetBi<<luma_log_weight_denom) + lround) >> denom));
      }
      else
      {
        weightedpel =  Clip3 (0, img->max_imgpel_value ,((pixel1 + pixel2 + lround) >> denom) + offsetBi);
      }
#else
      weightedpel =  Clip3 (0, img->max_imgpel_value ,((pixel1 + pixel2 + lround) >> denom) + offsetBi);
#endif

      bi_diff = (*cur_line++)  - weightedpel;
      mcost += byte_abs[bi_diff];
      
      pixel1 = weight1 * (*ref1_line++);
      pixel2 = weight2 * (*ref2_line++);
#ifdef USE_HP_FILTER//BROUND
      if(input->UseHPFilter != 0)
      {
        weightedpel =  Clip3 (0, img->max_imgpel_value ,((pixel1 + pixel2 + (offsetBi<<luma_log_weight_denom) + lround) >> denom));
      }
      else
      {
        weightedpel =  Clip3 (0, img->max_imgpel_value ,((pixel1 + pixel2 + lround) >> denom) + offsetBi);
      }
#else
      weightedpel =  Clip3 (0, img->max_imgpel_value ,((pixel1 + pixel2 + lround) >> denom) + offsetBi);
#endif
 
      bi_diff = (*cur_line++)  - weightedpel;
      mcost += byte_abs[bi_diff];
      
      pixel1 = weight1 * (*ref1_line++);
      pixel2 = weight2 * (*ref2_line++);
#ifdef USE_HP_FILTER//BROUND
      if(input->UseHPFilter != 0)
      {
        weightedpel =  Clip3 (0, img->max_imgpel_value ,((pixel1 + pixel2 + (offsetBi<<luma_log_weight_denom) + lround) >> denom));
      }
      else
      {
        weightedpel =  Clip3 (0, img->max_imgpel_value ,((pixel1 + pixel2 + lround) >> denom) + offsetBi);                     
      }
#else
      weightedpel =  Clip3 (0, img->max_imgpel_value ,((pixel1 + pixel2 + lround) >> denom) + offsetBi);                     
#endif

      bi_diff = (*cur_line++)  - weightedpel;
      mcost += byte_abs[bi_diff];
      
      pixel1 = weight1 * (*ref1_line++);
      pixel2 = weight2 * (*ref2_line++);
#ifdef USE_HP_FILTER//BROUND
      if(input->UseHPFilter != 0)
      {
        weightedpel =  Clip3 (0, img->max_imgpel_value ,((pixel1 + pixel2 + (offsetBi<<luma_log_weight_denom) + lround) >> denom));
      }
      else
      {
        weightedpel =  Clip3 (0, img->max_imgpel_value ,((pixel1 + pixel2 + lround) >> denom) + offsetBi);
      }
#else
      weightedpel =  Clip3 (0, img->max_imgpel_value ,((pixel1 + pixel2 + lround) >> denom) + offsetBi);
#endif

      bi_diff = (*cur_line++)  - weightedpel;
      mcost += byte_abs[bi_diff];
      if (mcost >= min_mcost) break;
    }    
    
    if (mcost >= min_mcost) break;
  }
  return mcost;
}

/*!
***********************************************************************
* \brief
*    FAST Motion Estimation using EPZS
*    AMT/HYC
***********************************************************************
*/
int                                            //  ==> minimum motion cost after search
EPZSPelBlockMotionSearch (pel_t ** cur_pic,    // <--  original pixel values for the AxB block
                          short ref,          // <--  reference picture 
                          int list,           // <--  reference list
                          int list_offset,    // <--  offset for Mbaff
                          char ***refPic,    // <--  reference array
                          short ****tmp_mv,   // <--  mv array
                          int pic_pix_x,      // <--  absolute x-coordinate of regarded AxB block
                          int pic_pix_y,      // <--  absolute y-coordinate of regarded AxB block
                          int blocktype,      // <--  block type (1-16x16 ... 7-4x4)
                          short pred_mv_x,    // <--  motion vector predictor (x) in sub-pel units
                          short pred_mv_y,    // <--  motion vector predictor (y) in sub-pel units
                          short *mv_x,        // <--> in: search center (x) / out: motion vector (x) - in pel units
                          short *mv_y,        // <--> in: search center (y) / out: motion vector (y) - in pel units
                          int search_range,    // <--  1-d search range in pel units
                          int min_mcost,      // <--  minimum motion cost (cost for center or huge value)
                          int lambda_factor)      // <--  lagrangian parameter for determining motion cost
{
  StorablePicture *ref_picture = listX[list+list_offset][ref];
  short blocksize_y = input->blc_size[blocktype][1];  // vertical block size
  short blocksize_x = input->blc_size[blocktype][0];  // horizontal block size
  short blockshape_x = (blocksize_x >> 2);  // horizontal block size in 4-pel units
  short blockshape_y = (blocksize_y >> 2);  // vertical block size in 4-pel units
  
  short mb_x = pic_pix_x - img->opix_x; 
  short mb_y = pic_pix_y - img->opix_y;
  short pic_pix_x2 = pic_pix_x >> 2;
  short pic_pix_y2 

⌨️ 快捷键说明

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