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

📄 loopfilter.c.new

📁 h.264标准和jm
💻 NEW
📖 第 1 页 / 共 2 页
字号:
            
            if( (imgUV != NULL) && !(edge & 1) )
            {
              EdgeLoop( SrcU +  (edge<<1) * ((horizontal)? img->width_cr:1 ), Strength, QPC, MbQ[0]->LFAlphaC0Offset, MbQ[0]->LFBetaOffset, horizontal, img->width_cr, 1 ) ; 
              EdgeLoop( SrcV +  (edge<<1) * ((horizontal)? img->width_cr:1 ), Strength, QPC, MbQ[0]->LFAlphaC0Offset, MbQ[0]->LFBetaOffset, horizontal, img->width_cr, 1 ) ; 
            } 
          }
        }//end strangest case		
      }//end edge condition
    }//end edge
  }//end loop horizontal
}

  /*!
 *********************************************************************************************
 * \brief
 *    returns a buffer of 4 Strength values for one stripe in a mb (for different Frame types)
 *********************************************************************************************
 */
byte BLK_NUM[2][4][4]  = {{{0,4,8,12},{1,5,9,13},{2,6,10,14},{3,7,11,15}},{{0,1,2,3},{4,5,6,7},{8,9,10,11},{12,13,14,15}}} ;
byte BLK_4_TO_8[16]    = {0,0,1,1,0,0,1,1,2,2,3,3,2,2,3,3} ;

void GetStrength(byte Strength[16],struct img_par *img,Macroblock* MbP[16],Macroblock* MbQ[16],int dir,int edge,int block_y,int block_x, int mvlimit)
{
  int    blkP, blkQ, idx ;
  int    blk_x, blk_x2, blk_y, blk_y2 ;
  int    ***list0_mv = dec_picture->mv[LIST_0];
  int    ***list1_mv = dec_picture->mv[LIST_1];
  int    **list0_refIdxArr = dec_picture->ref_idx[LIST_0];
  int    **list1_refIdxArr = dec_picture->ref_idx[LIST_1];
  int    **list0_refPicIdArr = dec_picture->ref_pic_id[LIST_0];
  int    **list1_refPicIdArr = dec_picture->ref_pic_id[LIST_1];

  int i;
  int mixedModeEdgeFlag[16];
  int inIntraPrediction = 0;  
  int FrameMbs          = 0;  

  for(i = 0;i<16;i++)
  {
	  mixedModeEdgeFlag[i] = img->MbaffFrameFlag ? (MbP[i]->mb_field != MbQ[i]->mb_field) : 0; //8.7.2.1
  }

  for( idx=0 ; idx<16 ; idx++ )
  {
    Strength[idx] = initStrength;
  }

  for( idx=0 ; idx<16 ; idx++ )
  {                                               
    blkQ = BLK_NUM[dir][ edge       ][idx<<2];
    blkP = BLK_NUM[dir][(edge-1) & 3][idx<<2]; 

    inIntraPrediction = (MbP[idx]->mb_type==I4MB || MbP[idx]->mb_type==I16MB || MbP[idx]->mb_type==IPCM) || (MbQ[idx]->mb_type==I4MB || MbQ[idx]->mb_type==I16MB || MbQ[idx]->mb_type==IPCM);
    FrameMbs          = (img->structure==FRAME) || (img->MbaffFrameFlag && (!MbP[idx]->mb_field) (!MbQ[idx]->mb_field));

    // check for bS=4
    if ((!edge) && inIntraPrediction && (FrameMbs || (!dir && ((img->structure!=FRAME) || img->MbaffFrameFlag))) )
    {
      Strength[idx] = 4;
    }
    else
    {
      // check for bS = 3
      if(((!mixedModeEdgeFlag[idx]) && inIntraPrediction)||(mixedModeEdgeFlag[idx] && dir && inIntraPrediction))
      {
        Strength[idx] = 3;
      }
      else
      {
        // check for bS = 2
        if( ((MbQ->cbp_blk &  (1 << blkQ )) != 0) || ((MbP[idx]->cbp_blk &  (1 << blkP)) != 0) )
        {
          Strength[idx] = 2;
        }
        else
        {
          // check for bS = 1
          if (mixedModeEdgeFlag[idx])
          {
            Strength[idx] = 1;
          }
          else
          {
            Strength[idx] = 0;
            if ()

          }


        }

      }
    }

    { // do things normally
        else
        {                                                     // if no coefs, but vector difference >= 1 set Strength=1 
          blk_y  = block_y + (blkQ >> 2) ;   blk_y2 = blk_y -  dir ;
          blk_x  = block_x + (blkQ  & 3) ;   blk_x2 = blk_x - !dir ;
          if( (img->type == B_SLICE) )
          { 
            int ref_p0,ref_p1,ref_q0,ref_q1;	    
            ref_p0 = list0_refIdxArr[blk_x][blk_y]<0 ? -1 : list0_refPicIdArr[blk_x][blk_y];
            ref_q0 = list0_refIdxArr[blk_x2][blk_y2]<0 ? -1 : list0_refPicIdArr[blk_x2][blk_y2];
            ref_p1 = list1_refIdxArr[blk_x][blk_y]<0 ? -1 : list1_refPicIdArr[blk_x][blk_y];
            ref_q1 = list1_refIdxArr[blk_x2][blk_y2]<0 ? -1 : list1_refPicIdArr[blk_x2][blk_y2];
            if ( ((ref_p0==ref_q0) && (ref_p1==ref_q1)) ||
              ((ref_p0==ref_q1) && (ref_p1==ref_q0))) 
            {
              Strength[idx]=0;
              // 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) 
                {
                  Strength[idx] =  (abs( list0_mv[blk_x][blk_y][0] - list0_mv[blk_x2][blk_y2][0]) >= 4) |
                    (abs( list0_mv[blk_x][blk_y][1] - list0_mv[blk_x2][blk_y2][1]) >= mvlimit) |
                    (abs( list1_mv[blk_x][blk_y][0] - list1_mv[blk_x2][blk_y2][0]) >= 4) |
                    (abs( list1_mv[blk_x][blk_y][1] - list1_mv[blk_x2][blk_y2][1]) >= mvlimit);
                }
                else 
                {
                  Strength[idx] =  (abs( list0_mv[blk_x][blk_y][0] - list1_mv[blk_x2][blk_y2][0]) >= 4) |
                    (abs( list0_mv[blk_x][blk_y][1] - list1_mv[blk_x2][blk_y2][1]) >= mvlimit) |
                    (abs( list1_mv[blk_x][blk_y][0] - list0_mv[blk_x2][blk_y2][0]) >= 4) |
                    (abs( list1_mv[blk_x][blk_y][1] - list0_mv[blk_x2][blk_y2][1]) >= mvlimit);
                }	
              } 
              else 
              { 	// L0 and L1 reference pictures of p0 are the same; q0 as well
                
                Strength[idx] =  ((abs( list0_mv[blk_x][blk_y][0] - list0_mv[blk_x2][blk_y2][0]) >= 4) |
                  (abs( list0_mv[blk_x][blk_y][1] - list0_mv[blk_x2][blk_y2][1]) >= mvlimit ) |
                  (abs( list1_mv[blk_x][blk_y][0] - list1_mv[blk_x2][blk_y2][0]) >= 4) |
                  (abs( list1_mv[blk_x][blk_y][1] - list1_mv[blk_x2][blk_y2][1]) >= mvlimit))
                  &&
                  ((abs( list0_mv[blk_x][blk_y][0] - list1_mv[blk_x2][blk_y2][0]) >= 4) |
                  (abs( list0_mv[blk_x][blk_y][1] - list1_mv[blk_x2][blk_y2][1]) >= mvlimit) |
                  (abs( list1_mv[blk_x][blk_y][0] - list0_mv[blk_x2][blk_y2][0]) >= 4) |
                  (abs( list1_mv[blk_x][blk_y][1] - list0_mv[blk_x2][blk_y2][1]) >= mvlimit));
              } 
            }
            else 
            {
              Strength[idx] = 1;				
            }		
          } 
          else	
          { 	// P slice
            int ref_p0,ref_q0;	    
            ref_p0 = list0_refIdxArr[blk_x][blk_y]<0 ? -1 : list0_refPicIdArr[blk_x][blk_y];
            ref_q0 = list0_refIdxArr[blk_x2][blk_y2]<0 ? -1 : list0_refPicIdArr[blk_x2][blk_y2];
            Strength[idx] =  (ref_p0 != ref_q0 ) |
              (abs( list0_mv[blk_x][blk_y][0] - list0_mv[blk_x2][blk_y2][0]) >= 4 ) |
              (abs( list0_mv[blk_x][blk_y][1] - list0_mv[blk_x2][blk_y2][1]) >= mvlimit );
          }
        } 
      }
    }
  }
}


/*!
 *****************************************************************************************
 * \brief
 *    Filters one edge of 16 (luma) or 8 (chroma) pel
 *****************************************************************************************
 */
void EdgeLoop(byte* SrcPtr, byte Strength[16],int QP[16],
              int AlphaC0Offset, int BetaOffset, int dir, int width, int yuv)
{  //8.7.1
  int      pel, ap = 0, aq = 0, PtrInc, Strng ;
  int      inc, inc2, inc3, inc4 ;
  int      C0, c0, Delta, dif, AbsDelta ;
  int      L2 = 0, L1, L0, R0, R1, R2 = 0, RL0 ;
  int      Alpha[16], Beta[16];
  byte*  ClipTab[16];
  int      small_gap;
  int      indexA, indexB;

  //PrtInc/inc used to handle 8-320 -> 327 
  PtrInc  = dir?      1 : width ;
  inc     = dir?  width : 1 ;   // vertical filtering increment to next pixel is 1 else width
  inc2    = inc<<1 ;    
  inc3    = inc + inc2 ;    
  inc4    = inc<<2 ;

  for( pel=0 ; pel<16 ; pel++ )
  {
	  //8.7.2.2 outputs here - indexA, indexB, Alpha, Beta.  
      indexA = Clip3(0, MAX_QP, QP[pel] + AlphaC0Offset);  
      indexB = Clip3(0, MAX_QP, QP[pel] + BetaOffset);  
      
	  Alpha[pel] = ALPHA_TABLE[indexA];
	  Beta[pel] = BETA_TABLE[indexB];
	  ClipTab[pel]=CLIP_TAB[indexA];
	  
      if( (Strng = Strength[pel]) )  //filterSamplesFlag (8-333 equaliviant)
	  {
		  L0  = SrcPtr [-inc ] ;
          R0  = SrcPtr [    0] ;
          AbsDelta  = abs( Delta = R0 - L0 )  ;
     
	      if( AbsDelta < Alpha[pel] )
		  {
			  C0  = ClipTab[pel][ Strng ] ;
		      L1  = SrcPtr[-inc2] ;
		      R1  = SrcPtr[ inc ] ;
		      if( ((abs( R0 - R1) - Beta[pel] )  & (abs(L0 - L1) - Beta[pel] )) < 0  ) 
			  {
				  if( !yuv)  
				  {
					  L2  = SrcPtr[-inc3] ;
			          R2  = SrcPtr[ inc2] ;
			          aq  = (abs( R0 - R2) - Beta[pel] ) < 0  ; 
			          ap  = (abs( L0 - L2) - Beta[pel] ) < 0  ; 
				  }
          
				  RL0             = L0 + R0 ;
          			
				  if(Strng == 4 )    // INTRA strong filtering 8.7.2.4
				  {
					  if( yuv)  // Chroma
					  {
						  SrcPtr[   0 ] = ((R1 << 1) + R0 + L1 + 2) >> 2; //8-351
			              SrcPtr[-inc ] = ((L1 << 1) + L0 + R1 + 2) >> 2; //8-358                                   
					  }
			          else  // Luma
					  { 
						  small_gap = (AbsDelta < ((Alpha[pel] >> 2) + 2));
                
				          aq &= small_gap;  //8-347
				          ap &= small_gap;  //8-354
              
			              SrcPtr[   0 ]   = aq ? ( L1 + ((R1 + RL0) << 1) +  SrcPtr[ inc2] + 4) >> 3 : ((R1 << 1) + R0 + L1 + 2) >> 2 ;  //8-348, 8-351
				          SrcPtr[-inc ]   = ap ? ( R1 + ((L1 + RL0) << 1) +  SrcPtr[-inc3] + 4) >> 3 : ((L1 << 1) + L0 + R1 + 2) >> 2 ;  //8-355, 8-358
              
				          SrcPtr[ inc ] =   aq  ? ( SrcPtr[ inc2] + R0 + R1 + L0 + 2) >> 2 : SrcPtr[ inc ];  //8-349, 8-352
				          SrcPtr[-inc2] =   ap  ? ( SrcPtr[-inc3] + L1 + L0 + R0 + 2) >> 2 : SrcPtr[-inc2];  //8-346, 8-359
              
				          SrcPtr[ inc2] = aq ? (((SrcPtr[ inc3] + SrcPtr[ inc2]) <<1) + SrcPtr[ inc2] + R1 + RL0 + 4) >> 3 : R2;  //8-350, 8-353
				          SrcPtr[-inc3] = ap ? (((SrcPtr[-inc4] + SrcPtr[-inc3]) <<1) + SrcPtr[-inc3] + L1 + RL0 + 4) >> 3 : L2;  //8-357, 8-360
					  }
				  }
			      else                        // normal filtering 8.7.2.3
				  {
			              c0               = yuv? (C0+1):(C0 + ap + aq) ;  //8-337, 8-338
			              dif              = Clip3( -c0, c0, ( (Delta << 2) + (L1 - R1) + 4) >> 3 ) ;  //8-334
			              SrcPtr[  -inc ]  = Clip3(0, 255, L0 + dif) ;
			              SrcPtr[     0 ]  = Clip3(0, 255, R0 - dif) ;
            
		             	  if( !yuv )
						  {
							  if( ap )
								  SrcPtr[-inc2] += Clip3( -C0,  C0, ( L2 + ((RL0 + 1) >> 1) - (L1<<1)) >> 1 ) ;
							  if( aq  )  
								  SrcPtr[  inc] += Clip3( -C0,  C0, ( R2 + ((RL0 + 1) >> 1) - (R1<<1)) >> 1 ) ;
						  } ;
				  } ;
			  } ; 
		  } ;
	  
          SrcPtr += PtrInc ;      // Increment to next set of pixel
          pel    += yuv ;
	  } 
      else
	  {
		  SrcPtr += PtrInc << (2 - yuv) ;
          pel    += 3 ;
	  }  ;
  
  }//end of FOR

}

⌨️ 快捷键说明

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