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

📄 me_distortion.c

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

/*!
************************************************************************
* \brief
*    BiPred (w/ weights) SATD computation
************************************************************************
*/
int computeBiPredSATD2(imgpel* src_pic,
                       int blocksize_y,
                       int blocksize_x,
                       int min_mcost,
                       int cand_x1, int cand_y1,
                       int cand_x2, int cand_y2)
{
  int mcost = 0;
  int y, x, y4, *d;
  int weighted_pel, pixel1, pixel2;
  int denom = luma_log_weight_denom + 1;
  int lround = 2 * wp_luma_round;
  int src_size_x, src_size_mul;
  imgpel *src_tmp = src_pic;

  if ( !test8x8transform )
  { // 4x4 TRANSFORM
    src_size_x = (blocksize_x - BLOCK_SIZE);
    src_size_mul = blocksize_x * BLOCK_SIZE;
    for (y=0; y<(blocksize_y<<2); y += BLOCK_SIZE_SP)
    {
      for (x=0; x<blocksize_x; x += BLOCK_SIZE)
      {
        d    = diff;
        src_line   = src_tmp + x;
        ref2_line  = get_line[bipred2_access_method] (ref_pic2_sub.luma, cand_y2 + y, cand_x2 + (x<<2));
        ref1_line  = get_line[bipred1_access_method] (ref_pic1_sub.luma, cand_y1 + y, cand_x1 + (x<<2));
        for (y4 = 0; y4 < BLOCK_SIZE; y4++ )
        {
          // 0
          pixel1 = weight1 * (*ref1_line++);
          pixel2 = weight2 * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
          *d++ =  (*src_line++) - weighted_pel;
          // 1
          pixel1 = weight1 * (*ref1_line++);
          pixel2 = weight2 * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
          *d++ =  (*src_line++) - weighted_pel;
          // 2
          pixel1 = weight1 * (*ref1_line++);
          pixel2 = weight2 * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
          *d++ =  (*src_line++) - weighted_pel;
          // 3
          pixel1 = weight1 * (*ref1_line++);
          pixel2 = weight2 * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
          *d++ =  (*src_line++) - weighted_pel;

          ref1_line += img_padded_size_x_m4x4;
          ref2_line += img_padded_size_x_m4x4;
          src_line  += src_size_x;
        }
        if ((mcost += HadamardSAD4x4 (diff)) > min_mcost) return mcost;
      }
      src_tmp += src_size_mul;
    }
  }
  else
  { // 8x8 TRANSFORM
    src_size_x = (blocksize_x - BLOCK_SIZE8x8);
    src_size_mul = blocksize_x * BLOCK_SIZE8x8;
    for (y=0; y<blocksize_y; y += BLOCK_SIZE8x8 )
    {
      int y_pos2 = cand_y2 + (y<<2);
      int y_pos1 = cand_y1 + (y<<2);
      for (x=0; x<blocksize_x; x += BLOCK_SIZE8x8 )
      {
        d = diff;
        src_line   = src_tmp + x;
        ref2_line  = get_line[bipred2_access_method] (ref_pic2_sub.luma, y_pos2, cand_x2 + (x<<2));
        ref1_line  = get_line[bipred1_access_method] (ref_pic1_sub.luma, y_pos1, cand_x1 + (x<<2));
        for (y4 = 0; y4 < BLOCK_SIZE8x8; y4++ )
        {
          // 0
          pixel1 = weight1 * (*ref1_line++);
          pixel2 = weight2 * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
          *d++ =  (*src_line++) - weighted_pel;
          // 1
          pixel1 = weight1 * (*ref1_line++);
          pixel2 = weight2 * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
          *d++ =  (*src_line++) - weighted_pel;
          // 2
          pixel1 = weight1 * (*ref1_line++);
          pixel2 = weight2 * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
          *d++ =  (*src_line++) - weighted_pel;
          // 3
          pixel1 = weight1 * (*ref1_line++);
          pixel2 = weight2 * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
          *d++ =  (*src_line++) - weighted_pel;
          // 4
          pixel1 = weight1 * (*ref1_line++);
          pixel2 = weight2 * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
          *d++ =  (*src_line++) - weighted_pel;
          // 5
          pixel1 = weight1 * (*ref1_line++);
          pixel2 = weight2 * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
          *d++ =  (*src_line++) - weighted_pel;
          // 6
          pixel1 = weight1 * (*ref1_line++);
          pixel2 = weight2 * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
          *d++ =  (*src_line++) - weighted_pel;
          // 7
          pixel1 = weight1 * (*ref1_line++);
          pixel2 = weight2 * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
          *d++ =  (*src_line) - weighted_pel;

          ref1_line += img_padded_size_x_m8x8;
          ref2_line += img_padded_size_x_m8x8;
          src_line  += src_size_x;
        }
        if ((mcost += HadamardSAD8x8 (diff)) > min_mcost) return mcost;
      }
      src_tmp += src_size_mul;
    }
  }
  return mcost;
}

/*!
************************************************************************
* \brief
*    SSE computation
************************************************************************
*/

int computeSSE(imgpel* src_pic,
               int blocksize_y,
               int blocksize_x,
               int min_mcost,
               int cand_x,
               int cand_y)
{
  int mcost = 0;
  int y,x4;
  int *byte_sse = img->quad;
  int pad_size_x = img_padded_size_x - blocksize_x;

  src_line = src_pic;
  ref_line = get_line[ref_access_method] (ref_pic_sub.luma, cand_y, cand_x);
  for (y=0; y<blocksize_y; y++)
  {
    for (x4 = 0; x4 < blocksize_x; x4+=4)
    {
      mcost += byte_sse[ *src_line++ - *ref_line++ ];
      mcost += byte_sse[ *src_line++ - *ref_line++ ];
      mcost += byte_sse[ *src_line++ - *ref_line++ ];
      mcost += byte_sse[ *src_line++ - *ref_line++ ];
    }
    if (mcost >= min_mcost) return mcost;
    ref_line += pad_size_x;
  }

  if ( ChromaMEEnable ) {
    // calculate chroma conribution to motion compensation error
    int blocksize_x_cr = blocksize_x >> shift_cr_x;
    int blocksize_y_cr = blocksize_y >> shift_cr_y;
    int cr_pad_size_x = img_cr_padded_size_x - blocksize_x_cr;
    int k;

    for (k=0; k<2; k++)
    {
      src_line = src_pic + (256 << k);
      ref_line = get_crline[ref_access_method] ( ref_pic_sub.crcb[k], cand_y, cand_x);
      for (y=0; y<blocksize_y_cr; y++)
      {
        for (x4 = 0; x4 < blocksize_x_cr; x4+=2)
        {
          mcost += byte_sse[ *src_line++ - *ref_line++ ];
          mcost += byte_sse[ *src_line++ - *ref_line++ ];
        }
        if (mcost >= min_mcost) return mcost;
        ref_line += cr_pad_size_x;
      }
    }
  }

  return mcost;
}


/*!
************************************************************************
* \brief
*    SSE computation of weighted samples
************************************************************************
*/

int computeSSEWP(imgpel* src_pic,
               int blocksize_y,
               int blocksize_x,
               int min_mcost,
               int cand_x,
               int cand_y)
{
  int mcost = 0;
  int y,x4;
  int weighted_pel;
  int *byte_sse = img->quad;
  int pad_size_x = img_padded_size_x - blocksize_x;

  src_line = src_pic;
  ref_line = get_line[ref_access_method] (ref_pic_sub.luma, cand_y, cand_x);
  for (y=0; y<blocksize_y; y++)
  {
    for (x4 = 0; x4 < blocksize_x; x4+=4)
    {
      weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
      mcost += byte_sse[ *src_line++ - weighted_pel ];
      weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
      mcost += byte_sse[ *src_line++ - weighted_pel ];
      weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
      mcost += byte_sse[ *src_line++ - weighted_pel ];
      weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++  + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
      mcost += byte_sse[ *src_line++ - weighted_pel ];
    }
    if (mcost >= min_mcost) return mcost;
    ref_line += pad_size_x;
  }

  if ( ChromaMEEnable ) {
    // calculate chroma conribution to motion compensation error
    // These could be made global to reduce computations
    int blocksize_x_cr = blocksize_x >> shift_cr_x;
    int blocksize_y_cr = blocksize_y >> shift_cr_y;
    int cr_pad_size_x = img_cr_padded_size_x - blocksize_x_cr;
    int k;

    for (k=0; k<2; k++)
    {
      src_line = src_pic + (256 << k);
      ref_line = get_crline[ref_access_method] ( ref_pic_sub.crcb[k], cand_y, cand_x);
      for (y=0; y<blocksize_y_cr; y++)
      {

        for (x4 = 0; x4 < blocksize_x_cr; x4+=2)
        {
          weighted_pel = iClip1( img->max_imgpel_value_uv, ((weight_cr[k] * *ref_line++  + wp_chroma_round) >> chroma_log_weight_denom) + offset_cr[k]);
          mcost += byte_sse[ *src_line++ - weighted_pel ];
          weighted_pel = iClip1( img->max_imgpel_value_uv, ((weight_cr[k] * *ref_line++  + wp_chroma_round) >> chroma_log_weight_denom) + offset_cr[k]);
          mcost += byte_sse[ *src_line++ - weighted_pel ];
        }
        if (mcost >= min_mcost) return mcost;
        ref_line += cr_pad_size_x;
      }
    }
  }

  return mcost;
}

/*!
************************************************************************
* \brief
*    BiPred SSE computation (no weights)
************************************************************************
*/
int computeBiPredSSE1(imgpel* src_pic,
                      int blocksize_y,
                      int blocksize_x,
                      int min_mcost,
                      int cand_x1, int cand_y1,
                      int cand_x2, int cand_y2)
{
  int mcost = 0;
  int bi_diff;
  int y,x4;
  int *byte_sse = img->quad;
  int pad_size_x = img_padded_size_x - blocksize_x;

  src_line   = src_pic;
  ref2_line  = get_line[bipred2_access_method] (ref_pic2_sub.luma, cand_y2, cand_x2);
  ref1_line  = get_line[bipred1_access_method] (ref_pic1_sub.luma, cand_y1, cand_x1);

  for (y = 0; y < blocksize_y; y++)
  {
    for (x4 = 0; x4 < blocksize_x; x4+=4)
    {
      bi_diff = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
      mcost += byte_sse[bi_diff];
      bi_diff = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
      mcost += byte_sse[bi_diff];
      bi_diff = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
      mcost += byte_sse[bi_diff];
      bi_diff = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
      mcost += byte_sse[bi_diff];
    }

    if (mcost >= min_mcost) return mcost;
    ref2_line += pad_size_x;
    ref1_line += pad_size_x;
  }

  if ( ChromaMEEnable ) {
    // calculate chroma conribution to motion compensation error
    int blocksize_x_cr = blocksize_x >> shift_cr_x;
    int blocksize_y_cr = blocksize_y >> shift_cr_y;
    int cr_pad_size_x = img_cr_padded_size_x - blocksize_x_cr;
    int k;

    for (k=0; k<2; k++)
    {
      src_line = src_pic + (256 << k);
      ref2_line = get_crline[bipred2_access_method] ( ref_pic2_sub.crcb[k], cand_y2, cand_x2);
      ref1_line = get_crline[bipred1_access_method] ( ref_pic1_sub.crcb[k], cand_y1, cand_x1);

      for (y=0; y<blocksize_y_cr; y++)
      {
        for (x4 = 0; x4 < blocksize_x_cr; x4+=2)
        {
          bi_diff = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
          mcost += byte_sse[bi_diff];
          bi_diff = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
          mcost += byte_sse[bi_diff];
        }
        if (mcost >= min_mcost) return mcost;
        ref2_line += cr_pad_size_x;
        ref1_line += cr_pad_size_x;
      }
    }
  }

  return mcost;
}


/*!
************************************************************************
* \brief
*    BiPred SSE computation (with weights)
************************************************************************
*/
int computeBiPredSSE2(imgpel* src_pic,
                      int blocksize_y,
                      int blocksize_x,
                      int min_mcost,
                      int cand_x1, int cand_y1,
                      int cand_x2, int cand_y2)
{
  int mcost = 0;
  int bi_diff;
  int denom = luma_log_weight_denom + 1;
  int lround = 2 * wp_luma_round;
  int y,x4;
  int weighted_pel, pixel1, pixel2;
  int pad_size_x = img_padded_size_x - blocksize_x;

  src_line   = src_pic;
  ref2_line  = get_line[bipred2_access_method] (ref_pic2_sub.luma, cand_y2, cand_x2);
  ref1_line  = get_line[bipred1_access_method] (ref_pic1_sub.luma, cand_y1, cand_x1);
  for (y=0; y<blocksize_y; y++)
  {
    for (x4 = 0; x4 < blocksize_x; x4+=4)
    {
      pixel1 = weight1 * (*ref1_line++);
      pixel2 = weight2 * (*ref2_line++);
      weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
      bi_diff = (*src_line++) - weighted_pel;
      mcost += bi_diff * bi_diff;

      pixel1 = weight1 * (*ref1_line++);
      pixel2 = weight2 * (*ref2_line++);
      weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
      bi_diff = (*src_line++) - weighted_pel;
      mcost += bi_diff * bi_diff;

      pixel1 = weight1 * (*ref1_line++);
      pixel2 = weight2 * (*ref2_line++);
      weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
      bi_diff = (*src_line++) - weighted_pel;
      mcost += bi_diff * bi_diff;

      pixel1 = weight1 * (*ref1_line++);
      pixel2 = weight2 * (*ref2_line++);
      weighted_pel =  iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
      bi_diff = (*src_line++) - weighted_pel;
      mcost += bi_diff * bi_diff;
    }
    if (mcost >= min_mcost) return mcost;
    ref2_line += pad_size_x;
    ref1_line += pad_size_x;
  }

  if ( ChromaMEEnable ) {
    // calculate chroma conribution to motion compensation error
    int blocksize_x_cr = blocksize_x >> shift_cr_x;
    int blocksize_y_cr = blocksize_y >> shift_cr_y;
    int cr_pad_size_x = img_cr_padded_size_x - blocksize_x_cr;
    int k;

    for (k=0; k<2; k++)
    {
      src_line = src_pic + (256 << k);
      ref2_line = get_crline[bipred2_access_method] ( ref_pic2_sub.crcb[k], cand_y2, cand_x2);
      ref1_line = get_crline[bipred1_access_method] ( ref_pic1_sub.crcb[k], cand_y1, cand_x1);

      for (y=0; y<blocksize_y_cr; y++)
      {
        for (x4 = 0; x4 < blocksize_x_cr; x4+=2)
        {
          pixel1 = weight1_cr[k] * (*ref1_line++);
          pixel2 = weight2_cr[k] * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value_uv, ((pixel1 + pixel2 + lround) >> denom) + offsetBi_cr[k]);
          bi_diff = (*src_line++) - weighted_pel;
          mcost += bi_diff * bi_diff;

          pixel1 = weight1_cr[k] * (*ref1_line++);
          pixel2 = weight2_cr[k] * (*ref2_line++);
          weighted_pel =  iClip1( img->max_imgpel_value_uv, ((pixel1 + pixel2 + lround) >> denom) + offsetBi_cr[k]);
          bi_diff = (*src_line++) - weighted_pel;
          mcost += bi_diff * bi_diff;
        }
        if (mcost >= min_mcost) return mcost;
        ref2_line += cr_pad_size_x;
        ref1_line += cr_pad_size_x;
      }
    }
  }

  return mcost;
}


⌨️ 快捷键说明

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