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

📄 me_fullfast.c

📁 压缩JM12.3d的完整的全部C语言的代码文档,用于嵌入式系统的压缩编解码
💻 C
📖 第 1 页 / 共 3 页
字号:
    ref_y = img->opix_y - offset_y;

    for (pos = 0; pos < max_pos; pos++)
    {
      if (ref_x == spiral_search_x[pos] &&
        ref_y == spiral_search_y[pos])
      {
        pos_00[list][ref] = pos;
        break;
        }
      }
    }

    //===== loop over search range (spiral search): get blockwise SAD =====
    for (pos = 0; pos < max_pos; pos++)
    {
      abs_y = offset_y + spiral_search_y[pos];
      abs_x = offset_x + spiral_search_x[pos];

      abs_y4 = (abs_y + IMG_PAD_SIZE) << 2;
      abs_x4 = (abs_x + IMG_PAD_SIZE) << 2;

      if (range_partly_outside)
      {
      if (abs_y >= 0 && abs_y <= max_height&&
        abs_x >= 0 && abs_x <= max_width  )
        {
        ref_access_method = FAST_ACCESS;
        }
        else
        {
        ref_access_method = UMV_ACCESS;
      }
    }

    if (apply_weights)
    {
      srcptr = orig_pels;
      bindex = 0;

      refptr = get_line[ref_access_method] (ref_pic_sub.luma, abs_y4, abs_x4);

      for (blky = 0; blky < 4; blky++)
      {
        LineSadBlk0 = LineSadBlk1 = LineSadBlk2 = LineSadBlk3 = 0;

        for (y = 0; y < 4; y++)
        {
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk0 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk0 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk0 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk0 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk1 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk1 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk1 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk1 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk2 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk2 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk2 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk2 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk3 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk3 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk3 += dist_method [weighted_pel - *srcptr++];
          weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *refptr++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
          LineSadBlk3 += dist_method [weighted_pel - *srcptr++];
          refptr += img_padded_size_x - MB_BLOCK_SIZE;
        }

        block_sad[bindex++][pos] = LineSadBlk0;
        block_sad[bindex++][pos] = LineSadBlk1;
        block_sad[bindex++][pos] = LineSadBlk2;
        block_sad[bindex++][pos] = LineSadBlk3;
      }
      if (ChromaMEEnable)
      {
        for (k = 0; k < 2; k ++)
        {
          bindex = 0;

          refptr = get_crline[ref_access_method] (ref_pic_sub.crcb[k], abs_y4, abs_x4);
          for (blky = 0; blky < 4; blky++)
          {
            LineSadBlk0 = LineSadBlk1 = LineSadBlk2 = LineSadBlk3 = 0;

            for (y = 0; y < img->mb_cr_size_y; y+=BLOCK_SIZE)
            {
              for (x = 0; x < img->mb_cr_size_x; x += BLOCK_SIZE)
              {
                weighted_pel = iClip1( img->max_imgpel_value_uv, ((weight_cr[k] * *refptr++  + wp_chroma_round) >> chroma_log_weight_denom) + offset_cr[k]);
                LineSadBlk0 += dist_method [weighted_pel - *srcptr++];
              }
              for (x = 0; x < img->mb_cr_size_x; x += BLOCK_SIZE)
              {
                weighted_pel = iClip1( img->max_imgpel_value_uv, ((weight_cr[k] * *refptr++  + wp_chroma_round) >> chroma_log_weight_denom) + offset_cr[k]);
                LineSadBlk1 += dist_method [weighted_pel - *srcptr++];
              }
              for (x = 0; x < img->mb_cr_size_x; x += BLOCK_SIZE)
              {
                weighted_pel = iClip1( img->max_imgpel_value_uv, ((weight_cr[k] * *refptr++  + wp_chroma_round) >> chroma_log_weight_denom) + offset_cr[k]);
                LineSadBlk2 += dist_method [weighted_pel - *srcptr++];
              }
              for (x = 0; x < img->mb_cr_size_x; x += BLOCK_SIZE)
              {
                weighted_pel = iClip1( img->max_imgpel_value_uv, ((weight_cr[k] * *refptr++  + wp_chroma_round) >> chroma_log_weight_denom) + offset_cr[k]);
                LineSadBlk3 += dist_method [weighted_pel - *srcptr++];
              }
              refptr += img_cr_padded_size_x - img->mb_cr_size_x;
            }

            block_sad[bindex++][pos] += LineSadBlk0;
            block_sad[bindex++][pos] += LineSadBlk1;
            block_sad[bindex++][pos] += LineSadBlk2;
            block_sad[bindex++][pos] += LineSadBlk3;
          }
        }
      }
    }
    else
    {
      srcptr = orig_pels;
      bindex = 0;

      refptr = get_line[ref_access_method] (ref_pic_sub.luma, abs_y4, abs_x4);

      for (blky = 0; blky < 4; blky++)
      {
        LineSadBlk0 = LineSadBlk1 = LineSadBlk2 = LineSadBlk3 = 0;

        for (y = 0; y < 4; y++)
        {
          LineSadBlk0 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk0 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk0 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk0 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk1 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk1 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk1 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk1 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk2 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk2 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk2 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk2 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk3 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk3 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk3 += dist_method [*refptr++ - *srcptr++];
          LineSadBlk3 += dist_method [*refptr++ - *srcptr++];
          refptr += img_padded_size_x - MB_BLOCK_SIZE;
        }

        block_sad[bindex++][pos] = LineSadBlk0;
        block_sad[bindex++][pos] = LineSadBlk1;
        block_sad[bindex++][pos] = LineSadBlk2;
        block_sad[bindex++][pos] = LineSadBlk3;
      }

      if (ChromaMEEnable)
      {
        for (k = 0; k < 2; k ++)
        {
          bindex = 0;

          refptr = get_crline[ref_access_method] (ref_pic_sub.crcb[k], abs_y4, abs_x4);
          for (blky = 0; blky < 4; blky++)
          {
            LineSadBlk0 = LineSadBlk1 = LineSadBlk2 = LineSadBlk3 = 0;

            for (y = 0; y < img->mb_cr_size_y; y+=BLOCK_SIZE)
            {
              for (x = 0; x < img->mb_cr_size_x; x += BLOCK_SIZE)
              {
                LineSadBlk0 += dist_method [*refptr++ - *srcptr++];
              }
              for (x = 0; x < img->mb_cr_size_x; x += BLOCK_SIZE)
              {
                LineSadBlk1 += dist_method [*refptr++ - *srcptr++];
              }
              for (x = 0; x < img->mb_cr_size_x; x += BLOCK_SIZE)
              {
                LineSadBlk2 += dist_method [*refptr++ - *srcptr++];
              }
              for (x = 0; x < img->mb_cr_size_x; x += BLOCK_SIZE)
              {
                LineSadBlk3 += dist_method [*refptr++ - *srcptr++];
              }
              refptr += img_cr_padded_size_x - img->mb_cr_size_x;
            }

            block_sad[bindex++][pos] += LineSadBlk0;
            block_sad[bindex++][pos] += LineSadBlk1;
            block_sad[bindex++][pos] += LineSadBlk2;
            block_sad[bindex++][pos] += LineSadBlk3;
          }
        }
      }
    }
  }

  //===== combine SAD's for larger block types =====
  SetupLargerBlocks (list, ref, max_pos);

  //===== set flag marking that search setup have been done =====
  search_setup_done[list][ref] = 1;
}
#endif

/*!
 ***********************************************************************
 * \brief
 *    Fast Full pixel block motion search
 ***********************************************************************
 */
int                                                   //  ==> minimum motion cost after search
FastFullPelBlockMotionSearch (imgpel*   orig_pic,     // <--  not used
                              short     ref,          // <--  reference frame (0... or -1 (backward))
                              int       list,
                              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,         //  --> motion vector (x) - in pel units
                              short*    mv_y,         //  --> 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
{
  int   pos, offset_x, offset_y, cand_x, cand_y, mcost;

  int   max_pos       = (2*search_range+1)*(2*search_range+1);              // number of search positions
  int   best_pos      = 0;                                                  // position with minimum motion cost
  int   block_index;                                                        // block index for indexing SAD array
  distpel*  block_sad;                                                          // pointer to SAD array

  block_index   = (pic_pix_y-img->opix_y)+((pic_pix_x-img->opix_x)>>2); // block index for indexing SAD array
  block_sad     = BlockSAD[list][ref][blocktype][block_index];         // pointer to SAD array

  //===== set up fast full integer search if needed / set search center =====
  if (!search_setup_done[list][ref])
  {
    SetupFastFullPelSearch (ref, list);
  }

  offset_x = search_center_x[list][ref] - img->opix_x;
  offset_y = search_center_y[list][ref] - img->opix_y;

  //===== cost for (0,0)-vector: it is done before, because MVCost can be negative =====
  if (!input->rdopt)
  {
    mcost = block_sad[pos_00[list][ref]] + MV_COST_SMP (lambda_factor, 0, 0, pred_mv_x, pred_mv_y);

    if (mcost < min_mcost)
    {
      min_mcost = mcost;
      best_pos  = pos_00[list][ref];
    }
  }

  //===== loop over all search positions =====
  for (pos=0; pos<max_pos; pos++, block_sad++)
  {
    //--- check residual cost ---
    if (*block_sad < min_mcost)
    {
      //--- get motion vector cost ---
      cand_x = (offset_x + spiral_search_x[pos])<<2;
      cand_y = (offset_y + spiral_search_y[pos])<<2;
      mcost  = *block_sad;
      mcost += MV_COST_SMP (lambda_factor, cand_x, cand_y, pred_mv_x, pred_mv_y);

      //--- check motion cost ---
      if (mcost < min_mcost)
      {
        min_mcost = mcost;
        best_pos  = pos;
      }
    }
  }

  //===== set best motion vector and return minimum motion cost =====
  *mv_x = offset_x + spiral_search_x[best_pos];
  *mv_y = offset_y + spiral_search_y[best_pos];
  return min_mcost;
}

⌨️ 快捷键说明

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