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

📄 loopfilter.c

📁 压缩JM12.3d的完整的全部C语言的代码文档,用于嵌入式系统的压缩编解码
💻 C
📖 第 1 页 / 共 3 页
字号:
        SrcPtrQ = &(Img[pixQ.pos_y][pixQ.pos_x]);
        SrcPtrP = &(Img[pixP.pos_y][pixP.pos_x]);

        // Average QP of the two blocks
        QP = (MbP->qp + MbQ->qp + 1) >> 1;

        indexA = iClip3(0, MAX_QP, QP + AlphaC0Offset);
        indexB = iClip3(0, MAX_QP, QP + BetaOffset);

        Alpha   = ALPHA_TABLE[indexA] * bitdepth_scale;
        Beta    = BETA_TABLE [indexB] * bitdepth_scale;
        ClipTab = CLIP_TAB[indexA];

        L3  = SrcPtrP[-incP*3];
        L2  = SrcPtrP[-incP*2];
        L1  = SrcPtrP[-incP];
        L0  = SrcPtrP[0] ;
        R0  = SrcPtrQ[0] ;      
        R1  = SrcPtrQ[ incQ];      
        R2  = SrcPtrQ[ incQ*2];
        R3  = SrcPtrQ[ incQ*3];

        AbsDelta  = iabs( Delta = (R0 - L0) );

        if( AbsDelta < Alpha )
        {
          C0  = ClipTab[ Strng ] * bitdepth_scale;
          if( ((iabs( R0 - R1) - Beta )  & (iabs(L0 - L1) - Beta )) < 0  )
          {            
            if(Strng == 4 )    // INTRA strong filtering
            {
              RL0 = L0 + R0;
              small_gap = (AbsDelta < ((Alpha >> 2) + 2));
              aq  = ( iabs( R0 - R2) < Beta ) & small_gap;               
              ap  = ( iabs( L0 - L2) < Beta ) & small_gap;

              if (ap)
              {
                SrcPtrP[-incP*2] = (imgpel) ((((L3 + L2) << 1) + L2 + L1 + RL0 + 4) >> 3);
                SrcPtrP[-incP]   = (imgpel) (( L2 + L1 + L0 + R0 + 2) >> 2);
                SrcPtrP[0]       = (imgpel) (( R1 + ((L1 + RL0) << 1) +  L2 + 4) >> 3);
              }
              else
              {
                SrcPtrP[ -incP * 2 ] = L2;
                SrcPtrP[ -incP     ] = L1;
                SrcPtrP[ 0         ] = (imgpel) (((L1 << 1) + L0 + R1 + 2) >> 2) ;
              }

              if (aq)
              {
                SrcPtrQ[ 0        ] = (imgpel) (( L1 + ((R1 + RL0) << 1) +  R2 + 4) >> 3);
                SrcPtrQ[ incQ     ] = (imgpel) (( R2 + R0 + R1 + L0 + 2) >> 2);
                SrcPtrQ[ incQ * 2 ] = (imgpel) ((((R3 + R2) << 1) + R2 + R1 + RL0 + 4) >> 3);
              }
              else
              {
                SrcPtrQ[ 0        ] = (imgpel) (((R1 << 1) + R0 + L1 + 2) >> 2);
                SrcPtrQ[ incQ     ] = R1;
                SrcPtrQ[ incQ * 2 ] = R2;
              }
            }
            else   // normal filtering
            {
              RL0 = (L0 + R0 + 1) >> 1;
              aq  = (iabs( R0 - R2) < Beta);
              ap  = (iabs( L0 - L2) < Beta);

              c0  = (C0 + ap + aq) ;
              dif = iClip3( -c0, c0, ((Delta << 2) + (L1 - R1) + 4) >> 3) ;

              if( ap )
                SrcPtrP[-incP] += iClip3( -C0,  C0, ( L2 + RL0 - (L1 << 1)) >> 1 ) ;

              SrcPtrP[0]  = (imgpel) iClip3(0, img->max_imgpel_value, L0 + dif) ;
              SrcPtrQ[0]  = (imgpel) iClip3(0, img->max_imgpel_value, R0 - dif) ;

              if( aq  )
                SrcPtrQ[ incQ] += iClip3( -C0,  C0, ( R2 + RL0 - (R1 << 1)) >> 1 ) ;
            }            
          }
        }
      }
    }
  }
}

/*!
 *****************************************************************************************
 * \brief
 *    Filters chroma block edge for Frame or Field coded pictures
 *****************************************************************************************
 */
void EdgeLoopChromaNormal(imgpel** Img, byte Strength[16], ImageParameters *img, int MbQAddr, int AlphaC0Offset, int BetaOffset,
              int dir, int edge, int width, int uv)
{
  int      pel, Strng ;
  int      incP, incQ;
  int      C0, c0, Delta, dif, AbsDelta;
  imgpel   L1, L0, R0, R1;
  int      Alpha = 0, Beta = 0;
  const byte* ClipTab = NULL;
  int      indexA, indexB;
  int      PelNum = pelnum_cr[dir][img->yuv_format];
  int      StrengthIdx;
  imgpel   *SrcPtrP, *SrcPtrQ;
  int      QP;
  int      xQ, yQ;
  Macroblock *MbQ = &(img->mb_data[MbQAddr]);
  Macroblock *MbP;
  PixelPos pixP, pixQ, pixMB1, pixMB2;
  int      bitdepth_scale = img->bitdepth_scale[IS_CHROMA];

  xQ = dir ? 0 : edge - 1;
  yQ = dir ? (edge < 16 ? edge - 1: 0) : 0;

  getNeighbour(MbQAddr, xQ, yQ, IS_CHROMA, &pixMB1);

  if (pixMB1.available || (MbQ->LFDisableIdc == 0))
  {
    pixP = pixMB1;
    MbP = &(img->mb_data[pixP.mb_addr]);
    if (dir)
      yQ ++;
    else
      xQ ++;

    getNeighbour(MbQAddr, xQ, yQ, IS_CHROMA, &pixMB2);
    pixQ = pixMB2;

    // Average QP of the two blocks
    QP = (MbP->qpc[uv] + MbQ->qpc[uv] + 1) >> 1;

    indexA = iClip3(0, MAX_QP, QP + AlphaC0Offset);
    indexB = iClip3(0, MAX_QP, QP + BetaOffset);

    Alpha   = ALPHA_TABLE[indexA] * bitdepth_scale;
    Beta    = BETA_TABLE [indexB] * bitdepth_scale;
    ClipTab = CLIP_TAB[indexA];

    for( pel = 0 ; pel < PelNum ; pel++ )
    {
      if (dir)
      {
        xQ         = pel;
        pixP.x     = pixMB1.x + pel;
        pixP.pos_x = pixMB1.pos_x + pel;
        pixQ.x     = pixMB2.x + pel;
        pixQ.pos_x = pixMB2.pos_x + pel;
      }
      else
      {
        yQ         = pel;
        pixP.y     = pixMB1.y + pel;
        pixP.pos_y = pixMB1.pos_y + pel;
        pixQ.y     = pixMB2.y + pel;
        pixQ.pos_y = pixMB2.pos_y + pel;
      }

      StrengthIdx = (PelNum == 8) ? (((pel >> 1) << 2) + (pel & 0x01)) : pel;

      if( (Strng = Strength[StrengthIdx]) != 0)
      {
        incQ = dir ? width : 1;
        incP = dir ? width : 1;
        SrcPtrQ = &(Img[pixQ.pos_y][pixQ.pos_x]);
        SrcPtrP = &(Img[pixP.pos_y][pixP.pos_x]);

        L1  = SrcPtrP[-incP];
        L0  = SrcPtrP[0] ;
        R0  = SrcPtrQ[0] ;      
        R1  = SrcPtrQ[ incQ];      

        AbsDelta  = iabs( Delta = (R0 - L0) );

        if( AbsDelta < Alpha )
        {
          C0  = ClipTab[ Strng ] * bitdepth_scale;
          if( ((iabs( R0 - R1) - Beta )  & (iabs(L0 - L1) - Beta )) < 0  )
          {
            if( Strng == 4 )    // INTRA strong filtering
            {
              SrcPtrQ[0] = (imgpel) ( ((R1 << 1) + R0 + L1 + 2) >> 2 );
              SrcPtrP[0] = (imgpel) ( ((L1 << 1) + L0 + R1 + 2) >> 2 );
            }
            else
            {
              c0  = (C0 + 1);
              dif = iClip3( -c0, c0, ( (Delta << 2) + (L1 - R1) + 4) >> 3 ) ;

              SrcPtrP[0] = (imgpel) iClip3(0, img->max_imgpel_value_uv, L0 + dif) ;
              SrcPtrQ[0] = (imgpel) iClip3(0, img->max_imgpel_value_uv, R0 - dif) ;
            }
          }
        }
      }
    }
  }
}

/*!
*****************************************************************************************
* \brief
*    Filters chroma block edge for MBAFF types
*****************************************************************************************
 */
void EdgeLoopChromaMBAff(imgpel** Img, byte Strength[16], ImageParameters *img, int MbQAddr, int AlphaC0Offset, int BetaOffset,
              int dir, int edge, int width, int uv)
{
  int      pel, Strng ;
  int      incP, incQ;
  int      C0, c0, Delta, dif, AbsDelta;
  imgpel   L1, L0, R0, R1;
  int      Alpha = 0, Beta = 0;
  const byte* ClipTab = NULL;
  int      indexA, indexB;
  int      PelNum = pelnum_cr[dir][img->yuv_format];
  int      StrengthIdx;
  imgpel   *SrcPtrP, *SrcPtrQ;
  int      QP;
  int      xQ, yQ;
  Macroblock *MbQ = &(img->mb_data[MbQAddr]);
  Macroblock *MbP;
  PixelPos pixP, pixQ;
  int      dir_m1 = 1 - dir;
  int      bitdepth_scale = img->bitdepth_scale[IS_CHROMA];

  for( pel = 0 ; pel < PelNum ; pel++ )
  {
    xQ = dir ? pel : edge;
    yQ = dir ? (edge < 16? edge : 1) : pel;
    getNeighbour(MbQAddr, xQ, yQ, IS_CHROMA, &pixQ);
    getNeighbour(MbQAddr, xQ - (dir_m1), yQ - dir, IS_CHROMA, &pixP);    
    MbP = &(img->mb_data[pixP.mb_addr]);    
    StrengthIdx = (PelNum == 8) ? ((MbQ->mb_field && !MbP->mb_field) ? pel << 1 :((pel >> 1) << 2) + (pel & 0x01)) : pel;

    if (pixP.available || (MbQ->LFDisableIdc == 0))
    {
      if( (Strng = Strength[StrengthIdx]) != 0)
      {
        fieldModeFilteringFlag = (byte) (MbQ->mb_field || MbP->mb_field);
        incQ = dir ? ((fieldModeFilteringFlag && !MbQ->mb_field) ? 2 * width : width) : 1;
        incP = dir ? ((fieldModeFilteringFlag && !MbP->mb_field) ? 2 * width : width) : 1;
        SrcPtrQ = &(Img[pixQ.pos_y][pixQ.pos_x]);
        SrcPtrP = &(Img[pixP.pos_y][pixP.pos_x]);

        // Average QP of the two blocks
        QP = (MbP->qpc[uv] + MbQ->qpc[uv] + 1) >> 1;

        indexA = iClip3(0, MAX_QP, QP + AlphaC0Offset);
        indexB = iClip3(0, MAX_QP, QP + BetaOffset);

        Alpha   = ALPHA_TABLE[indexA] * bitdepth_scale;
        Beta    = BETA_TABLE [indexB] * bitdepth_scale;
        ClipTab = CLIP_TAB[indexA];

        L1  = SrcPtrP[-incP];
        L0  = SrcPtrP[0] ;
        R0  = SrcPtrQ[0] ;      
        R1  = SrcPtrQ[ incQ];      

        AbsDelta  = iabs( Delta = (R0 - L0) );

        if( AbsDelta < Alpha )
        {
          C0  = ClipTab[ Strng ] * bitdepth_scale;
          if( ((iabs( R0 - R1) - Beta )  & (iabs(L0 - L1) - Beta )) < 0  )
          {
            if( Strng == 4 )    // INTRA strong filtering
            {
              SrcPtrQ[0] = (imgpel) ( ((R1 << 1) + R0 + L1 + 2) >> 2 );
              SrcPtrP[0] = (imgpel) ( ((L1 << 1) + L0 + R1 + 2) >> 2 );
            }
            else
            {
              c0  = (C0 + 1);
              dif = iClip3( -c0, c0, ( (Delta << 2) + (L1 - R1) + 4) >> 3 ) ;

              SrcPtrP[0] = (imgpel) iClip3(0, img->max_imgpel_value_uv, L0 + dif) ;
              SrcPtrQ[0] = (imgpel) iClip3(0, img->max_imgpel_value_uv, R0 - dif) ;
            }
          }
        }
      }
    }
  }
}

int compute_deblock_strength(char **list0_refIdxArr, 
                             char **list1_refIdxArr, 
                             int64 **list0_refPicIdArr, 
                             int64 **list1_refPicIdArr, 
                             short  ***list0_mv,
                             short  ***list1_mv,
                             int blk_y, int blk_x, 
                             int blk_y2, int blk_x2, 
                             int mvlimit)
{
  static int64 ref_p0, ref_q0, ref_p1, ref_q1;
  static byte StrValue;

  ref_p0 = list0_refIdxArr[blk_y] [blk_x] <0 ? INT64_MIN : list0_refPicIdArr[blk_y] [blk_x];
  ref_q0 = list0_refIdxArr[blk_y2][blk_x2]<0 ? INT64_MIN : list0_refPicIdArr[blk_y2][blk_x2];
  ref_p1 = list1_refIdxArr[blk_y] [blk_x] <0 ? INT64_MIN : list1_refPicIdArr[blk_y] [blk_x];
  ref_q1 = list1_refIdxArr[blk_y2][blk_x2]<0 ? INT64_MIN : list1_refPicIdArr[blk_y2][blk_x2];
  if ( ((ref_p0==ref_q0) && (ref_p1==ref_q1)) ||
    ((ref_p0==ref_q1) && (ref_p1==ref_q0)))
  {
    // L0 and L1 reference pictures of p0 are different; q0 as well
    if (ref_p0 != ref_p1)
    {
      // compare MV for the same reference picture
      if (ref_p0 == ref_q0)
      {
        StrValue =  (byte) (
          (iabs( list0_mv[blk_y][blk_x][0] - list0_mv[blk_y2][blk_x2][0]) >= 4) |
          (iabs( list0_mv[blk_y][blk_x][1] - list0_mv[blk_y2][blk_x2][1]) >= mvlimit) |
          (iabs( list1_mv[blk_y][blk_x][0] - list1_mv[blk_y2][blk_x2][0]) >= 4) |
          (iabs( list1_mv[blk_y][blk_x][1] - list1_mv[blk_y2][blk_x2][1]) >= mvlimit));                  
      }
      else
      {
        StrValue =  (byte) (
          (iabs( list0_mv[blk_y][blk_x][0] - list1_mv[blk_y2][blk_x2][0]) >= 4) |
          (iabs( list0_mv[blk_y][blk_x][1] - list1_mv[blk_y2][blk_x2][1]) >= mvlimit) |
          (iabs( list1_mv[blk_y][blk_x][0] - list0_mv[blk_y2][blk_x2][0]) >= 4) |
          (iabs( list1_mv[blk_y][blk_x][1] - list0_mv[blk_y2][blk_x2][1]) >= mvlimit));
      }
    }
    else
    { // L0 and L1 reference pictures of p0 are the same; q0 as well

      StrValue = (byte) (
        ((iabs( list0_mv[blk_y][blk_x][0] - list0_mv[blk_y2][blk_x2][0]) >= 4) |
        (iabs( list0_mv[blk_y][blk_x][1] - list0_mv[blk_y2][blk_x2][1]) >= mvlimit ) |
        (iabs( list1_mv[blk_y][blk_x][0] - list1_mv[blk_y2][blk_x2][0]) >= 4) |
        (iabs( list1_mv[blk_y][blk_x][1] - list1_mv[blk_y2][blk_x2][1]) >= mvlimit))
        &&
        ((iabs( list0_mv[blk_y][blk_x][0] - list1_mv[blk_y2][blk_x2][0]) >= 4) |
        (iabs( list0_mv[blk_y][blk_x][1] - list1_mv[blk_y2][blk_x2][1]) >= mvlimit) |
        (iabs( list1_mv[blk_y][blk_x][0] - list0_mv[blk_y2][blk_x2][0]) >= 4) |
        (iabs( list1_mv[blk_y][blk_x][1] - list0_mv[blk_y2][blk_x2][1]) >= mvlimit)));
    }
  }
  else
  {
    StrValue = 1;
  }
 return StrValue;
}

⌨️ 快捷键说明

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