void DeblockMb(ImageParameters *img, byte **imgY, byte ***imgUV, int mb_y, int mb_x) { int EdgeCondition; int dir,edge,QP; byte Strength[4], *SrcY, *SrcU, *SrcV ; Macroblock *MbP, *MbQ ; int sizey; int QPC; int filterLeftMbEdgeFlag = (mb_x != 0); int filterTopMbEdgeFlag = (mb_y != 0); int fieldModeMbFlag; SrcY = imgY [mb_y<<4] + (mb_x<<4) ; // pointers to source SrcU = imgUV[0][mb_y<<3] + (mb_x<<3) ; SrcV = imgUV[1][mb_y<<3] + (mb_x<<3) ; MbQ = &img->mb_data[mb_y*img->PicWidthInMbs + mb_x] ; // current Mb fieldModeMbFlag = img->field_pic_flag || (img->MbaffFrameFlag && MbQ->mb_field); // return, if filter is disabled if (MbQ->LFDisableIdc==1) return; if (MbQ->LFDisableIdc==2) { // don't filter at slice boundaries filterLeftMbEdgeFlag = MbQ->mbAvailA; filterTopMbEdgeFlag = MbQ->mbAvailB;; } for( dir=0 ; dir<2 ; dir++ ) // vertical edges, than horicontal edges { EdgeCondition = (dir && filterTopMbEdgeFlag) || (!dir && filterLeftMbEdgeFlag); // can not filter beyond picture boundaries for( edge=0 ; edge<4 ; edge++ ) // first 4 vertical strips of 16 pel { // then 4 horicontal if( edge || EdgeCondition ) { sizey = mb_y%2 ? 1:2*img->width/MB_BLOCK_SIZE-1; MbP = (edge)? MbQ : ((dir)? (MbQ -(img->width>>4)) : (MbQ-1) ) ; // MbP = Mb of the remote 4x4 block QP = ( MbP->qp + MbQ->qp + 1) >> 1 ; // Average QP of the two blocks GetStrength(Strength,img,MbP,MbQ,dir,edge,mb_y<<2,mb_x<<2); // Strength for 4 blks in 1 stripe if( *((int*)Strength) ) // only if one of the 4 Strength bytes is != 0 { EdgeLoop( SrcY + (edge<<2)* ((dir)? img->width:1 ), Strength, QP, MbQ->LFAlphaC0Offset, MbQ->LFBetaOffset, dir, img->width, 0) ; if( (imgUV != NULL) && !(edge & 1) ) { QPC = (QP_SCALE_CR[MbP->qp] + QP_SCALE_CR[MbQ->qp] + 1) >> 1; EdgeLoop( SrcU + (edge<<1) * ((dir)? img->width_cr:1 ), Strength, QPC, MbQ->LFAlphaC0Offset, MbQ->LFBetaOffset, dir, img->width_cr, 1 ) ; EdgeLoop( SrcV + (edge<<1) * ((dir)? img->width_cr:1 ), Strength, QPC, MbQ->LFAlphaC0Offset, MbQ->LFBetaOffset, dir, img->width_cr, 1 ) ; } } }
/* ************************************************************************* * Function: Deblocks one 4:2:2 macroblock * Input: * Output: * Return: * Attention: ************************************************************************* */ void DeblockMb422(ImageParameters *img, byte **imgY, byte ***imgUV, int mb_y, int mb_x) { int EdgeCondition; int dir,edge,QP; byte Strength[2], Strth1[2], Strth2[2],*SrcY, *SrcU = NULL, *SrcV = NULL; Macroblock *MbP, *MbQ ; const int mb_width = img->width/16; const int mb_nr = img->current_mb_nr; Macroblock *currMB = &mb_data[mb_nr]; int QPchroma; SrcY = imgY [mb_y<<4] + (mb_x<<4) ; // pointers to source if (imgUV != NULL) { SrcU = imgUV[0][mb_y<<3] + (mb_x<<3) ; SrcV = imgUV[1][mb_y<<3] + (mb_x<<3) ; } MbQ = &mb_data[mb_y*(img->width>>4) + mb_x] ; // current Mb // This could also be handled as a filter offset of -51 if (MbQ->lf_disable) return; for( dir=0 ; dir<2 ; dir++ ) // vertical edges, then horicontal edges { EdgeCondition = (dir && mb_y) || (!dir && mb_x) ; // can not filter beyond frame boundaries if(dir && mb_y) { EdgeCondition = (currMB->slice_nr == mb_data[img->current_mb_nr-mb_width].slice_nr)? EdgeCondition:0; // can not filter beyond slice boundaries jlzheng 7.8 } for( edge=0 ; edge<2 ; edge++ ) // first 4 vertical strips of 16 pel { // then 4 horicontal if( edge || EdgeCondition ) { MbP = (edge)? MbQ : ((dir)? (MbQ -(img->width>>4)) : (MbQ-1) ) ; // MbP = Mb of the remote 4x4 block MbP是否需要重新得到? QP = (MbP->qp + MbQ->qp+1) >> 1 ; // Average QP of the two blocks GetStrength( Strength, MbP, MbQ, dir, edge, mb_y<<2, mb_x<<2); //Strength for 4 pairs of blks in 1 stripe if( *((short*)Strength) ) // && (QP>= 8) ) // only if one of the 4 Strength bytes is != 0 { EdgeLoop( SrcY + (edge<<3)* ((dir)? img->width:1 ), Strength,QP,dir, img->width, 0 ); if ((imgUV !=NULL) && (edge==0) && (dir==1)) { QPchroma=(QP_SCALE_CR[MbP->qp]+QP_SCALE_CR[MbQ->qp]+1)/2; EdgeLoop( SrcU, Strength, QPchroma, dir, img->width_cr, 1 ) ; EdgeLoop( SrcV, Strength, QPchroma, dir, img->width_cr, 1 ) ; } if ((imgUV !=NULL) && (edge==0) && (dir==0)) { QPchroma=(QP_SCALE_CR[MbP->qp]+QP_SCALE_CR[MbQ->qp]+1)/2; Strth1[0]=Strth1[1]=Strength[0]; Strth2[0]=Strth2[1]=Strength[1]; EdgeLoop( SrcU, Strth1, QPchroma, dir, img->width_cr, 1 ) ; EdgeLoop( SrcV, Strth1, QPchroma, dir, img->width_cr, 1 ) ; EdgeLoop( SrcU + 8*img->width_cr, Strth2, QPchroma, dir, img->width_cr, 1 ) ; EdgeLoop( SrcV + 8*img->width_cr, Strth2, QPchroma, dir, img->width_cr, 1 ) ; } if ((imgUV !=NULL) && (edge==1) && (dir==1)) { QPchroma=(QP_SCALE_CR[MbP->qp]+QP_SCALE_CR[MbQ->qp]+1)/2; EdgeLoop( SrcU + 8*img->width_cr, Strength, QPchroma, dir, img->width_cr, 1 ) ; EdgeLoop( SrcV + 8*img->width_cr, Strength, QPchroma, dir, img->width_cr, 1 ) ; } } } }//end edge }//end loop dir