Changeset 773 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncSearch.cpp
- Timestamp:
- 16 Jan 2014, 09:56:13 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibEncoder/TEncSearch.cpp
r758 r773 1124 1124 { 1125 1125 #endif 1126 for( UInt uiX = 0; uiX < uiWidth; uiX++ ) 1127 { 1128 #if LGE_PRED_RES_CODING_DLT_DOMAIN_F0159 1129 #if DLT_DIFF_CODING_IN_PPS 1130 if( (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps()) ) 1131 #else 1132 if( (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getVPS()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps()) ) 1133 #endif 1126 for( UInt uiX = 0; uiX < uiWidth; uiX++ ) 1127 { 1128 #if H_3D_DIM 1129 if( (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps()) ) 1134 1130 { 1135 #if DLT_DIFF_CODING_IN_PPS1136 1131 pResi[ uiX ] = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pOrg[ uiX ] ) - pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pPred[ uiX ] ); 1137 #else1138 pResi[ uiX ] = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pOrg[ uiX ] ) - pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pPred[ uiX ] );1139 #endif1140 1132 } 1141 1133 else 1142 1134 { 1143 1135 pResi[ uiX ] = pOrg[ uiX ] - pPred[ uiX ]; 1144 1136 } 1145 1137 #else 1146 pResi[ uiX ] = pOrg[ uiX ] - pPred[ uiX ];1147 #endif 1148 }1149 pOrg += uiStride;1150 pResi += uiStride;1151 pPred += uiStride;1138 pResi[ uiX ] = pOrg[ uiX ] - pPred[ uiX ]; 1139 #endif 1140 } 1141 pOrg += uiStride; 1142 pResi += uiStride; 1143 pPred += uiStride; 1152 1144 #if H_3D_DIM_ENC 1153 1145 } … … 1209 1201 for( UInt uiX = 0; uiX < uiWidth; uiX++ ) 1210 1202 { 1211 #if LGE_PRED_RES_CODING_DLT_DOMAIN_F0159 1212 #if DLT_DIFF_CODING_IN_PPS 1203 #if H_3D_DIM 1213 1204 if( (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps()) ) 1214 #else 1215 if( (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getVPS()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps()) ) 1216 #endif 1217 { 1218 #if DLT_DIFF_CODING_IN_PPS 1219 pReco [ uiX ] = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), Clip3( 0, pcCU->getSlice()->getPPS()->getDLT()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() ) - 1, pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pPred[ uiX ] ) + pResi[ uiX ] ) ); 1220 #else 1221 pReco [ uiX ] = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), Clip3( 0, pcCU->getSlice()->getVPS()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() ) - 1, pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pPred[ uiX ] ) + pResi[ uiX ] ) ); 1222 #endif 1223 } 1224 else 1225 { 1226 pReco [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] ); 1227 } 1205 { 1206 pReco [ uiX ] = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), Clip3( 0, pcCU->getSlice()->getPPS()->getDLT()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() ) - 1, pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pPred[ uiX ] ) + pResi[ uiX ] ) ); 1207 } 1208 else 1209 { 1210 pReco [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] ); 1211 } 1228 1212 #else 1229 1213 pReco [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] ); … … 1951 1935 // get residual (idx) 1952 1936 #if H_3D_DIM_DLT 1953 #if DLT_DIFF_CODING_IN_PPS1954 1937 Pel pResidualIdx = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pDCRec ) - pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] ); 1955 #else1956 Pel pResidualIdx = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pDCRec ) - pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );1957 #endif1958 1938 #else 1959 1939 Pel pResidualIdx = pDCRec - apDCPredValues[uiSegment]; … … 1969 1949 { 1970 1950 #if H_3D_DIM_DLT 1971 #if DLT_DIFF_CODING_IN_PPS1972 1951 Pel pPredIdx = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] ); 1973 1952 Pel pResiIdx = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx); 1974 1953 Pel pRecoValue = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx ); 1975 #else1976 Pel pPredIdx = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] );1977 Pel pResiIdx = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx);1978 Pel pRecoValue = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx );1979 #endif1980 1954 1981 1955 apDCResiValues[uiSegment] = pRecoValue - apDCPredValues[uiSegment]; … … 2924 2898 biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]); 2925 2899 } break; 2926 #if !SEC_DMM3_RBC_F0147 2927 case( DMM3_IDX ): 2928 { 2929 2930 TComPic* pcPicTex = pcCU->getSlice()->getTexturePic(); 2931 TComDataCU* pcColTexCU = pcPicTex->getCU( pcCU->getAddr() ); 2932 UInt uiTexPartIdx = pcCU->getZorderIdxInCU() + uiPartOffset; 2933 Int uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255; 2934 2935 if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 ) 2936 { 2937 UInt uiIntraTabIdx = 0; 2938 xSearchDmm3Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx, uiIntraTabIdx, uiColTexIntraDir ); 2939 pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dmmType, uiPartOffset, uiDepth + uiInitTrDepth ); 2940 pcCU->setDmm3IntraTabIdxSubParts( uiIntraTabIdx, uiPartOffset, uiDepth + uiInitTrDepth ); 2941 biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]); 2942 } 2943 } break; 2944 #endif 2900 2945 2901 case( DMM4_IDX ): 2946 2902 { … … 2968 2924 } 2969 2925 #endif 2970 #if H_3D_DIM_RBC2971 if( m_pcEncCfg->getUseRBC()2972 #if H_3D_FAST_DEPTH_INTRA2973 && (uiRdModeList[0] != PLANAR_IDX || varCU >= varThreshold)2974 #endif2975 )2976 {2977 if( xSearchRbcEdge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight ) )2978 {2979 Pel deltaDC1 = 0; Pel deltaDC2 = 0;2980 #if QC_DIM_DELTADC_UNIFY_F01322981 xSearchDmmDeltaDCs( pcCU, uiPartOffset, piOrg, piPred, uiStride, pcCU->getEdgePartition( uiPartOffset ), uiWidth, uiWidth, uiHeight, deltaDC1, deltaDC2 );2982 #else2983 xSearchRbcDeltaDCs( pcCU, uiPartOffset, piOrg, piPred, uiStride, pcCU->getEdgePartition( uiPartOffset ), uiWidth, uiWidth, uiHeight, deltaDC1, deltaDC2 );2984 #endif2985 pcCU->setDimDeltaDC( RBC_IDX, 0, uiPartOffset, deltaDC1 );2986 pcCU->setDimDeltaDC( RBC_IDX, 1, uiPartOffset, deltaDC2 );2987 2988 uiRdModeList[ numModesForFullRD++ ] = (2*RBC_IDX +DIM_OFFSET);2989 uiRdModeList[ numModesForFullRD++ ] = (2*RBC_IDX+1+DIM_OFFSET);2990 }2991 }2992 #endif2993 2926 } 2994 2927 #endif … … 3029 2962 Bool bTestZeroResi = false; 3030 2963 #if H_3D_DIM_ENC 3031 #if LGE_BUGFIX_F01583032 2964 bTestZeroResi |= pcCU->getSlice()->getIsDepth() && !pcCU->getSlice()->isIRAP(); 3033 #else3034 bTestZeroResi |= pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->isIRAP();3035 #endif3036 2965 #endif 3037 2966 #if H_3D_DIM_SDC … … 3642 3571 , InheritedVSPDisInfo* inheritedVSPDisInfo 3643 3572 #endif 3644 #if MTK_SPIVMP_F01103573 #if H_3D_SPIVMP 3645 3574 , Bool* pbSPIVMPFlag, TComMvField* pcMvFieldSP, UChar* puhInterDirSP 3646 3575 #endif … … 3660 3589 if ( iPUIdx == 0 ) 3661 3590 { 3662 #if ETRIKHU_MERGE_REUSE_F00933591 #if H_3D 3663 3592 pcCU->initAvailableFlags(); 3664 3593 pcCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand); … … 3668 3597 , inheritedVSPDisInfo 3669 3598 #endif 3670 #if MTK_SPIVMP_F01103599 #if H_3D_SPIVMP 3671 3600 , pbSPIVMPFlag, pcMvFieldSP, puhInterDirSP 3672 3601 #endif … … 3674 3603 ); 3675 3604 #else 3676 pcCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours 3677 #if H_3D_VSP 3678 , vspFlag 3679 , inheritedVSPDisInfo 3680 #endif 3681 , numValidMergeCand 3682 ); 3605 pcCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); 3683 3606 #endif 3684 3607 } … … 3687 3610 else 3688 3611 { 3689 #if ETRIKHU_MERGE_REUSE_F00933612 #if H_3D 3690 3613 pcCU->initAvailableFlags(); 3691 3614 pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand); … … 3695 3618 , inheritedVSPDisInfo 3696 3619 #endif 3697 #if MTK_SPIVMP_F01103620 #if H_3D_SPIVMP 3698 3621 , pbSPIVMPFlag, pcMvFieldSP, puhInterDirSP 3699 3622 #endif … … 3701 3624 ); 3702 3625 #else 3703 pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, cMvFieldNeighbours, uhInterDirNeighbours 3704 #if H_3D_VSP 3705 , vspFlag 3706 , inheritedVSPDisInfo 3707 #endif 3708 , numValidMergeCand 3626 pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand 3709 3627 ); 3710 3628 #endif … … 3726 3644 PartSize ePartSize = pcCU->getPartitionSize( 0 ); 3727 3645 3728 #if MTK_SPIVMP_F01103646 #if H_3D_SPIVMP 3729 3647 pcCU->setSPIVMPFlagSubParts( pbSPIVMPFlag[uiMergeCand], uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx )); 3730 3648 if (pbSPIVMPFlag[uiMergeCand]) … … 3748 3666 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx ); 3749 3667 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx ); 3750 #if MTK_SPIVMP_F01103668 #if H_3D_SPIVMP 3751 3669 } 3752 3670 #endif … … 4427 4345 DisInfo OriginalDvInfo = pcCU->getDvInfo(uiAbsPartIdx); 4428 4346 #endif 4429 #if MTK_SPIVMP_F01104347 #if H_3D_SPIVMP 4430 4348 Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM]; 4431 4349 memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM); … … 4440 4358 , inheritedVSPDisInfo 4441 4359 #endif 4442 #if MTK_SPIVMP_F01104360 #if H_3D_SPIVMP 4443 4361 , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP 4444 4362 #endif … … 4454 4372 pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMRGIndex].m_acDvInfo, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4455 4373 #endif 4456 #if MTK_SPIVMP_F01104374 #if H_3D_SPIVMP 4457 4375 pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMRGIndex], uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4458 4376 if (bSPIVMPFlag[uiMRGIndex]!=0) … … 4488 4406 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4489 4407 } 4490 #if MTK_SPIVMP_F01104408 #if H_3D_SPIVMP 4491 4409 } 4492 4410 #endif … … 4502 4420 else 4503 4421 { 4504 #if MTK_SPIVMP_F01104422 #if H_3D_SPIVMP 4505 4423 pcCU->setSPIVMPFlagSubParts(0, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4506 4424 #endif … … 4517 4435 } 4518 4436 } 4519 #if MTK_SPIVMP_F0110 4520 #if MTK_F0110_FIX 4437 #if H_3D_SPIVMP 4521 4438 delete[] pcMvFieldSP; 4522 4439 delete[] puhInterDirSP; 4523 #else4524 delete pcMvFieldSP;4525 delete puhInterDirSP;4526 #endif4527 4440 #endif 4528 4441 } … … 5438 5351 dZeroCost = dCost + 1; 5439 5352 } 5440 #if MTK_SPIVMP_F01105353 #if H_3D_SPIVMP 5441 5354 if ( dZeroCost < dCost || pcCU->getQtRootCbf(0)==0) 5442 5355 #else … … 7372 7285 7373 7286 #if H_3D_DIM_DLT 7374 #if DLT_DIFF_CODING_IN_PPS7375 7287 rDeltaDC1 = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), ClipY(predDC1 + rDeltaDC1) ) - pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ); 7376 7288 rDeltaDC2 = pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), ClipY(predDC2 + rDeltaDC2) ) - pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ); 7377 #else7378 rDeltaDC1 = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), ClipY(predDC1 + rDeltaDC1) ) - pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 );7379 rDeltaDC2 = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), ClipY(predDC2 + rDeltaDC2) ) - pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 );7380 #endif7381 7289 #endif 7382 7290 } … … 7477 7385 } 7478 7386 7479 #if !SEC_DMM3_RBC_F0147 7480 Void TEncSearch::xSearchDmm3Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx, UInt colTexIntraDir ) 7481 { 7482 ruiTabIdx = 0; 7483 ruiIntraTabIdx = 0; 7484 7485 // local pred buffer 7486 TComYuv cPredYuv; 7487 cPredYuv.create( uiWidth, uiHeight ); 7488 cPredYuv.clear(); 7489 Pel* piPred = cPredYuv.getLumaAddr(); 7490 UInt uiPredStride = cPredYuv.getStride(); 7491 7492 // wedge search 7493 UInt uiBestDist = MAX_UINT; 7494 WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])]; 7495 Pel refDC1 = 0; Pel refDC2 = 0; 7496 7497 std::vector< std::vector<UInt> > pauiWdgLstSz = g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]]; 7498 std::vector<UInt>* pauiWdgLst = &pauiWdgLstSz[colTexIntraDir-2]; 7499 for( UInt uiIdxW = 0; uiIdxW < pauiWdgLst->size(); uiIdxW++ ) 7500 { 7501 UInt uiIdx = pauiWdgLst->at(uiIdxW); 7502 TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiIdx)); 7503 xCalcBiSegDCs ( piRef, uiRefStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 ); 7504 xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 ); 7505 7506 UInt uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD ); 7507 if( uiActDist < uiBestDist || uiBestDist == MAX_UINT ) 7508 { 7509 uiBestDist = uiActDist; 7510 ruiTabIdx = uiIdx; 7511 ruiIntraTabIdx = uiIdxW; 7512 } 7513 } 7514 cPredYuv.destroy(); 7515 } 7516 #endif 7517 #endif 7518 #if H_3D_DIM_RBC 7519 Void TEncSearch::xSearchRbcDeltaDCs( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piOrig, Pel* piPredic, UInt uiStride, Bool* biSegPattern, Int patternStride, UInt uiWidth, UInt uiHeight, Pel& rDeltaDC1, Pel& rDeltaDC2 ) 7520 { 7521 assert( biSegPattern ); 7522 Pel origDC1 = 0; Pel origDC2 = 0; 7523 xCalcBiSegDCs ( piOrig, uiStride, biSegPattern, patternStride, origDC1, origDC2 ); 7524 xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, origDC1, origDC2 ); 7525 7526 Int* piMask = pcCU->getPattern()->getAdiOrgBuf( uiWidth, uiHeight, m_piYuvExt ); // no filtering for DMM 7527 Int maskStride = 2*uiWidth + 1; 7528 Int* ptrSrc = piMask+maskStride+1; 7529 Pel predDC1 = 0; Pel predDC2 = 0; 7530 xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 ); 7531 7532 rDeltaDC1 = origDC1 - predDC1; 7533 rDeltaDC2 = origDC2 - predDC2; 7534 7535 #if H_3D_VSO 7536 if( m_pcRdCost->getUseVSO() ) 7537 { 7538 Pel fullDeltaDC1 = rDeltaDC1; 7539 Pel fullDeltaDC2 = rDeltaDC2; 7540 7541 xDeltaDCQuantScaleDown( pcCU, fullDeltaDC1 ); 7542 xDeltaDCQuantScaleDown( pcCU, fullDeltaDC2 ); 7543 7544 Dist uiBestDist = RDO_DIST_MAX; 7545 UInt uiBestQStepDC1 = 0; 7546 UInt uiBestQStepDC2 = 0; 7547 7548 UInt uiDeltaDC1Max = abs(fullDeltaDC1); 7549 UInt uiDeltaDC2Max = abs(fullDeltaDC2); 7550 7551 //VSO Level delta DC check range extension 7552 uiDeltaDC1Max += (uiDeltaDC1Max>>1); 7553 uiDeltaDC2Max += (uiDeltaDC2Max>>1); 7554 7555 for( UInt uiQStepDC1 = 1; uiQStepDC1 <= uiDeltaDC1Max; uiQStepDC1++ ) 7556 { 7557 Pel iLevelDeltaDC1 = (Pel)(uiQStepDC1) * (Pel)(( fullDeltaDC1 < 0 ) ? -1 : 1); 7558 xDeltaDCQuantScaleUp( pcCU, iLevelDeltaDC1 ); 7559 Pel testDC1 = ClipY( predDC1 + iLevelDeltaDC1 ); 7560 7561 for( UInt uiQStepDC2 = 1; uiQStepDC2 <= uiDeltaDC2Max; uiQStepDC2++ ) 7562 { 7563 Pel iLevelDeltaDC2 = (Pel)(uiQStepDC2) * (Pel)(( fullDeltaDC2 < 0 ) ? -1 : 1); 7564 xDeltaDCQuantScaleUp( pcCU, iLevelDeltaDC2 ); 7565 Pel testDC2 = ClipY( predDC2 + iLevelDeltaDC2 ); 7566 7567 xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, testDC1, testDC2 ); 7568 7569 Dist uiActDist = RDO_DIST_MAX; 7570 if( m_pcRdCost->getUseEstimatedVSD() ) 7571 { 7572 uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false ); 7573 } 7574 else 7575 { 7576 uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false ); 7577 } 7578 7579 if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX ) 7580 { 7581 uiBestDist = uiActDist; 7582 uiBestQStepDC1 = uiQStepDC1; 7583 uiBestQStepDC2 = uiQStepDC2; 7584 } 7585 } 7586 } 7587 7588 fullDeltaDC1 = (Int)(uiBestQStepDC1) * (Int)(( fullDeltaDC1 < 0 ) ? -1 : 1); 7589 fullDeltaDC2 = (Int)(uiBestQStepDC2) * (Int)(( fullDeltaDC2 < 0 ) ? -1 : 1); 7590 xDeltaDCQuantScaleUp( pcCU, fullDeltaDC1 ); 7591 xDeltaDCQuantScaleUp( pcCU, fullDeltaDC2 ); 7592 rDeltaDC1 = fullDeltaDC1; 7593 rDeltaDC2 = fullDeltaDC2; 7594 } 7595 #endif 7596 7597 xDeltaDCQuantScaleDown( pcCU, rDeltaDC1 ); 7598 xDeltaDCQuantScaleDown( pcCU, rDeltaDC2 ); 7599 } 7600 7601 Bool TEncSearch::xSearchRbcEdge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, Int iWidth, Int iHeight ) 7602 { 7603 Bool* pbEdge = (Bool*) xMalloc( Bool, iWidth * iHeight * 4 ); 7604 7605 Short* psDiffX = new Short[ iWidth * iHeight ]; 7606 Short* psDiffY = new Short[ iWidth * iHeight ]; 7607 Bool* pbEdgeX = new Bool [ iWidth * iHeight ]; 7608 Bool* pbEdgeY = new Bool [ iWidth * iHeight ]; 7609 7610 // Find Horizontal Gradient & Edge Detection ((x+1, y) - (x,y)) 7611 for( Int y=0; y<iHeight; y++ ) 7612 { 7613 Short* psDiffXPtr = &psDiffX[ y * iHeight ]; 7614 Bool* pbEdgeXPtr = &pbEdgeX[ y * iHeight ]; 7615 for(Int x=0; x<iWidth-1; x++ ) 7616 { 7617 *psDiffXPtr = piRef[ x+1 + y*uiRefStride ] - piRef[ x + y*uiRefStride ]; 7618 if(*psDiffXPtr >= RBC_THRESHOLD || *psDiffXPtr <= (-1)*RBC_THRESHOLD) 7619 { 7620 *pbEdgeXPtr = true; 7621 } 7622 else 7623 { 7624 *pbEdgeXPtr = false; 7625 } 7626 7627 psDiffXPtr++; 7628 pbEdgeXPtr++; 7629 } 7630 } 7631 7632 // Find Vertical Gradient & Edge Detection((x,y+1) - (x,y)) 7633 for( Int y=0; y<iHeight-1; y++ ) 7634 { 7635 Short* psDiffYPtr = &psDiffY[ y * iHeight ]; 7636 Bool* pbEdgeYPtr = &pbEdgeY[ y * iHeight ]; 7637 for(Int x=0; x<iWidth; x++ ) 7638 { 7639 *psDiffYPtr = piRef[ x + (y+1)*uiRefStride ] - piRef[ x + y*uiRefStride ]; 7640 if(*psDiffYPtr >= RBC_THRESHOLD || *psDiffYPtr <= (-1)*RBC_THRESHOLD) 7641 { 7642 *pbEdgeYPtr = true; 7643 } 7644 else 7645 { 7646 *pbEdgeYPtr = false; 7647 } 7648 7649 psDiffYPtr++; 7650 pbEdgeYPtr++; 7651 } 7652 } 7653 7654 // Eliminate local maximum 7655 for( Int y=0; y<iHeight; y++ ) 7656 { 7657 Short* psDiffXPtr = &psDiffX[ y * iHeight ]; 7658 Bool* pbEdgeXPtr = &pbEdgeX[ y * iHeight ]; 7659 for( Int x=0; x<iWidth-1; x++ ) 7660 { 7661 UShort usAbs0=0, usAbs1=0, usAbs2=0; // 0 : left, 1 : current, 2 : right 7662 7663 if( x > 0 && *(pbEdgeXPtr-1) == true ) 7664 { 7665 if( *(psDiffXPtr-1) >= 0) 7666 { 7667 usAbs0 = *(psDiffXPtr-1); 7668 7669 } 7670 else 7671 { 7672 usAbs0 = (-1) * *(psDiffXPtr-1); 7673 } 7674 } 7675 if( *pbEdgeXPtr == true ) 7676 { 7677 if( *(psDiffXPtr) >= 0) 7678 { 7679 usAbs1 = *(psDiffXPtr); 7680 } 7681 else 7682 { 7683 usAbs1 = (-1) * *(psDiffXPtr); 7684 } 7685 } 7686 if( x < iWidth-2 && *(pbEdgeXPtr+1) == true ) 7687 { 7688 if( *(psDiffXPtr+1) >= 0) 7689 { 7690 usAbs2 = *(psDiffXPtr+1); 7691 //bSign2 = true; 7692 } 7693 else 7694 { 7695 usAbs2 = (-1) * *(psDiffXPtr+1); 7696 } 7697 } 7698 7699 if( x == 0 ) 7700 { 7701 if( usAbs1 < usAbs2 ) 7702 { 7703 *pbEdgeXPtr = false; 7704 } 7705 } 7706 else if( x == iWidth-2 ) 7707 { 7708 if( usAbs1 <= usAbs0 ) 7709 *pbEdgeXPtr = false; 7710 } 7711 else 7712 { 7713 if( usAbs2 > usAbs0 ) 7714 { 7715 if( usAbs1 < usAbs2 ) 7716 *pbEdgeXPtr = false; 7717 } 7718 else 7719 { 7720 if( usAbs1 <= usAbs0 ) 7721 *pbEdgeXPtr = false; 7722 } 7723 } 7724 7725 psDiffXPtr++; 7726 pbEdgeXPtr++; 7727 } 7728 } 7729 7730 for( Int y=0; y<iHeight-1; y++ ) 7731 { 7732 Short* psDiffYPtr = &psDiffY[ y * iWidth ]; 7733 Bool* pbEdgeYPtr = &pbEdgeY[ y * iWidth ]; 7734 for( Int x=0; x<iWidth; x++ ) 7735 { 7736 UShort usAbs0=0, usAbs1=0, usAbs2=0; // 0 : upper, 1 : current, 2 : bottom 7737 if( y > 0 && *(pbEdgeYPtr-iWidth) == true ) 7738 { 7739 if( *(psDiffYPtr-iWidth) >= 0) 7740 { 7741 usAbs0 = *(psDiffYPtr-iWidth); 7742 } 7743 else 7744 { 7745 usAbs0 = (-1) * *(psDiffYPtr-iWidth); 7746 } 7747 } 7748 if( *pbEdgeYPtr == true ) 7749 { 7750 if( *(psDiffYPtr) >= 0) 7751 { 7752 usAbs1 = *(psDiffYPtr); 7753 } 7754 else 7755 { 7756 usAbs1 = (-1) * *(psDiffYPtr); 7757 } 7758 } 7759 if( y < iHeight-2 && *(pbEdgeYPtr+iWidth) == true ) 7760 { 7761 if( *(psDiffYPtr+iWidth) >= 0) 7762 { 7763 usAbs2 = *(psDiffYPtr+iWidth); 7764 } 7765 else 7766 { 7767 usAbs2 = (-1) * *(psDiffYPtr+iWidth); 7768 } 7769 } 7770 7771 if( y == 0 ) 7772 { 7773 if( usAbs1 < usAbs2 ) 7774 *pbEdgeYPtr = false; 7775 } 7776 else if( y == iHeight-2 ) 7777 { 7778 if( usAbs1 <= usAbs0 ) 7779 *pbEdgeYPtr = false; 7780 } 7781 else 7782 { 7783 if( usAbs2 > usAbs0 ) 7784 { 7785 if( usAbs1 < usAbs2 ) 7786 *pbEdgeYPtr = false; 7787 } 7788 else 7789 { 7790 if( usAbs1 <= usAbs0 ) 7791 *pbEdgeYPtr = false; 7792 } 7793 } 7794 7795 psDiffYPtr++; 7796 pbEdgeYPtr++; 7797 } 7798 } 7799 7800 // Edge Merging 7801 for( Int i=0; i< 4 * iWidth * iHeight; i++ ) 7802 pbEdge[ i ] = false; 7803 /// Even Line (0,2,4,6,...) => Vertical Edge 7804 for( Int i=0; i<iHeight; i++) 7805 { 7806 for( Int j=0; j<iWidth-1; j++) 7807 { 7808 pbEdge[ (2 * j + 1) + (2 * i) * 2 * iWidth ] = pbEdgeX[ j + i * iHeight ]; 7809 } 7810 } 7811 /// Odd Line (1,3,5,7,...) => Horizontal Edge 7812 for( Int i=0; i<iHeight-1; i++) 7813 { 7814 for( Int j=0; j<iWidth; j++) 7815 { 7816 pbEdge[ (2 * j) + (2 * i + 1) * 2 * iWidth ] = pbEdgeY[ j + i * iHeight ]; 7817 } 7818 } 7819 7820 // Intersection Filling 7821 /// Vertical Edge between Horizontal Edges 7822 for( Int i = 1; i < 2 * iHeight - 3; i += 2) 7823 { 7824 for( Int j = 0; j < 2 * iWidth - 1; j += 2) 7825 { 7826 if( pbEdge[ j + i * 2 * iWidth ] ) 7827 { 7828 if( j != 0 && pbEdge[ (j - 2) + ((i + 2) * 2 * iWidth) ] ) 7829 { 7830 if( !pbEdge[ (j - 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j - 1) + ((i + 3) * 2 * iWidth) ] ) 7831 pbEdge[ (j - 1) + ((i + 1) * 2 * iWidth) ] = true; 7832 } 7833 if( j != 2 * iWidth - 2 && pbEdge[ (j + 2) + ((i + 2) * 2 * iWidth) ] ) 7834 { 7835 if( !pbEdge[ (j + 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j + 1) + ((i + 3) * 2 * iWidth) ] ) 7836 pbEdge[ (j + 1) + ((i + 1) * 2 * iWidth) ] = true; 7837 } 7838 } 7839 } 7840 } 7841 /// Horizontal Edge between Vertical Edges 7842 for( Int j = 1; j < 2 * iWidth - 3; j += 2) 7843 { 7844 for( Int i = 0; i < 2 * iHeight - 1; i += 2) 7845 { 7846 if( pbEdge[ j + i * 2 * iWidth ] ) 7847 { 7848 if( i != 0 && pbEdge[ (j + 2) + ((i - 2) * 2 * iWidth) ] ) 7849 { 7850 if( !pbEdge[ (j - 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j + 3) + ((i - 1) * 2 * iWidth) ] ) 7851 pbEdge[ (j + 1) + ((i - 1) * 2 * iWidth) ] = true; 7852 } 7853 if( i != 2 * iHeight - 2 && pbEdge[ (j + 2) + ((i + 2) * 2 * iWidth) ] ) 7854 { 7855 if( !pbEdge[ (j - 1) + ((i + 1) * 2 * iWidth) ] && !pbEdge[ (j + 3) + ((i + 1) * 2 * iWidth) ] ) 7856 pbEdge[ (j + 1) + ((i + 1) * 2 * iWidth) ] = true; 7857 } 7858 } 7859 } 7860 } 7861 7862 // Static Pruning Unnecessary Edges 7863 /// Step1. Stack push the unconnected edges 7864 UShort* pusUnconnectedEdgeStack = new UShort[ 4 * iWidth * iHeight ]; // approximate size calculation 7865 Int iUnconnectedEdgeStackPtr = 0; 7866 //// Vertical Edges 7867 for( Int i = 0; i < 2 * iHeight - 1; i += 2 ) 7868 { 7869 for( Int j = 1; j < 2 * iWidth - 2; j += 2 ) 7870 { 7871 if( pbEdge[ j + i * 2 * iWidth ] ) 7872 { 7873 if( !xCheckTerminatedEdge( pbEdge, j, i, iWidth, iHeight ) ) 7874 { 7875 pusUnconnectedEdgeStack[iUnconnectedEdgeStackPtr] = (i << 8) | (j); 7876 iUnconnectedEdgeStackPtr++; 7877 } 7878 } 7879 } 7880 } 7881 7882 //// Horizontal Edges 7883 for( Int i = 1; i < 2 * iHeight - 2; i += 2 ) 7884 { 7885 for( Int j = 0; j < 2 * iWidth - 1; j += 2 ) 7886 { 7887 if( pbEdge[ j + i * 2 * iWidth ] ) 7888 { 7889 if( !xCheckTerminatedEdge( pbEdge, j, i, iWidth, iHeight ) ) 7890 { 7891 pusUnconnectedEdgeStack[iUnconnectedEdgeStackPtr] = (i << 8) | (j); 7892 iUnconnectedEdgeStackPtr++; 7893 } 7894 } 7895 } 7896 } 7897 7898 /// Step2. Remove the edges from the stack and push the new unconnected edges 7899 //// (This step may contain duplicated edges already in the stack) 7900 //// (But it doesn't cause any functional problems) 7901 while( iUnconnectedEdgeStackPtr != 0 ) 7902 { 7903 iUnconnectedEdgeStackPtr--; 7904 Int iX = pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] & 0xff; 7905 Int iY = pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] >> 8; 7906 7907 pbEdge[ iX + iY * 2 * iWidth ] = false; 7908 7909 if( iY % 2 == 1 && iX > 0 && pbEdge[ iX - 2 + iY * 2 * iWidth ] && 7910 !xCheckTerminatedEdge( pbEdge, iX - 2, iY, iWidth, iHeight ) ) // left 7911 { 7912 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 0) << 8) | (iX - 2); 7913 iUnconnectedEdgeStackPtr++; 7914 } 7915 if( iY % 2 == 1 && iX < 2 * iWidth - 2 && pbEdge[ iX + 2 + iY * 2 * iWidth ] && 7916 !xCheckTerminatedEdge( pbEdge, iX + 2, iY, iWidth, iHeight ) ) // right 7917 { 7918 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 0) << 8) | (iX + 2); 7919 iUnconnectedEdgeStackPtr++; 7920 } 7921 if( iY % 2 == 0 && iY > 0 && pbEdge[ iX + (iY - 2) * 2 * iWidth ] && 7922 !xCheckTerminatedEdge( pbEdge, iX, iY - 2, iWidth, iHeight ) ) // top 7923 { 7924 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 2) << 8) | (iX + 0); 7925 iUnconnectedEdgeStackPtr++; 7926 } 7927 if( iY % 2 == 0 && iY < 2 * iHeight - 2 && pbEdge[ iX + (iY + 2) * 2 * iWidth ] && 7928 !xCheckTerminatedEdge( pbEdge, iX, iY + 2, iWidth, iHeight ) ) // bottom 7929 { 7930 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 2) << 8) | (iX + 0); 7931 iUnconnectedEdgeStackPtr++; 7932 } 7933 if( iX > 0 && iY > 0 && pbEdge[ iX - 1 + (iY - 1) * 2 * iWidth ] && 7934 !xCheckTerminatedEdge( pbEdge, iX - 1, iY - 1, iWidth, iHeight ) ) // left-top 7935 { 7936 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 1) << 8) | (iX - 1); 7937 iUnconnectedEdgeStackPtr++; 7938 } 7939 if( iX < 2 * iWidth - 1 && iY > 0 && pbEdge[ iX + 1 + (iY - 1) * 2 * iWidth ] && 7940 !xCheckTerminatedEdge( pbEdge, iX + 1, iY - 1, iWidth, iHeight ) ) // right-top 7941 { 7942 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 1) << 8) | (iX + 1); 7943 iUnconnectedEdgeStackPtr++; 7944 } 7945 if( iX > 0 && iY < 2 * iHeight - 1 && pbEdge[ iX - 1 + (iY + 1) * 2 * iWidth ] && 7946 !xCheckTerminatedEdge( pbEdge, iX - 1, iY + 1, iWidth, iHeight ) ) // left-bottom 7947 { 7948 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 1) << 8) | (iX - 1); 7949 iUnconnectedEdgeStackPtr++; 7950 } 7951 if( iX < 2 * iWidth - 1 && iY < 2 * iHeight - 1 && pbEdge[ iX + 1 + (iY + 1) * 2 * iWidth ] && 7952 !xCheckTerminatedEdge( pbEdge, iX + 1, iY + 1, iWidth, iHeight ) ) // right-bottom 7953 { 7954 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 1) << 8) | (iX + 1); 7955 iUnconnectedEdgeStackPtr++; 7956 } 7957 } 7958 7959 7960 // Region Generation ( edge -> region ) 7961 Bool* pbRegion = pcCU->getEdgePartition( uiAbsPtIdx ); 7962 Bool* pbVisit = new Bool[ iWidth * iHeight ]; 7963 7964 for( UInt ui = 0; ui < iWidth * iHeight; ui++ ) 7965 { 7966 pbRegion[ ui ] = true; // fill it as region 1 (we'll discover region 0 next) 7967 pbVisit [ ui ] = false; 7968 } 7969 7970 Int* piStack = new Int[ iWidth * iHeight ]; 7971 7972 Int iPtr = 0; 7973 7974 piStack[iPtr++] = (0 << 8) | (0); 7975 pbRegion[ 0 ] = false; 7976 7977 while(iPtr > 0) 7978 { 7979 Int iTmp = piStack[--iPtr]; 7980 Int iX1, iY1; 7981 iX1 = iTmp & 0xff; 7982 iY1 = (iTmp >> 8) & 0xff; 7983 7984 pbVisit[ iX1 + iY1 * iWidth ] = true; 7985 7986 assert( iX1 >= 0 && iX1 < iWidth ); 7987 assert( iY1 >= 0 && iY1 < iHeight ); 7988 7989 if( iX1 > 0 && !pbEdge[ 2 * iX1 - 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 - 1 + iY1 * iWidth ] ) 7990 { 7991 piStack[iPtr++] = (iY1 << 8) | (iX1 - 1); 7992 pbRegion[ iX1 - 1 + iY1 * iWidth ] = false; 7993 } 7994 if( iX1 < iWidth - 1 && !pbEdge[ 2 * iX1 + 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 + 1 + iY1 * iWidth ] ) 7995 { 7996 piStack[iPtr++] = (iY1 << 8) | (iX1 + 1); 7997 pbRegion[ iX1 + 1 + iY1 * iWidth ] = false; 7998 } 7999 if( iY1 > 0 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 - 1) * iWidth ] && !pbVisit[ iX1 + (iY1 - 1) * iWidth ] ) 8000 { 8001 piStack[iPtr++] = ((iY1 - 1) << 8) | iX1; 8002 pbRegion[ iX1 + (iY1 - 1) * iWidth ] = false; 8003 } 8004 if( iY1 < iHeight - 1 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 + 1) * iWidth ] && !pbVisit[ iX1 + (iY1 + 1) * iWidth ] ) 8005 { 8006 piStack[iPtr++] = ((iY1 + 1) << 8) | iX1; 8007 pbRegion[ iX1 + (iY1 + 1) * iWidth ] = false; 8008 } 8009 } 8010 8011 /////////// 8012 iPtr = 0; 8013 for( Int i = 0; i < iWidth * iHeight; i++ ) 8014 pbVisit[ i ] = false; 8015 piStack[ iPtr++ ] = (0 << 8) | (0); // initial seed 8016 while( iPtr > 0 && iPtr < iWidth * iHeight ) 8017 { 8018 Int iX; 8019 Int iY; 8020 iPtr--; 8021 iX = piStack[ iPtr ] & 0xff; 8022 iY = piStack[ iPtr ] >> 8; 8023 pbVisit[ iY * iWidth + iX ] = true; 8024 8025 if( iY > 0 && !pbVisit[ (iY - 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY - 1) * iWidth + iX ] ) 8026 { 8027 piStack[ iPtr++ ] = ((iY - 1) << 8) | iX; 8028 } 8029 if( iY < iHeight - 1 && !pbVisit[ (iY + 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY + 1) * iWidth + iX ] ) 8030 { 8031 piStack[ iPtr++ ] = ((iY + 1) << 8) | iX; 8032 } 8033 if( iX > 0 && !pbVisit[ iY * iWidth + (iX - 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX - 1) ] ) 8034 { 8035 piStack[ iPtr++ ] = (iY << 8) | (iX - 1); 8036 } 8037 if( iX < iWidth - 1 && !pbVisit[ iY * iWidth + (iX + 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX + 1) ] ) 8038 { 8039 piStack[ iPtr++ ] = (iY << 8) | (iX + 1); 8040 } 8041 } 8042 assert( iPtr == 0 || iPtr == iWidth * iHeight ); 8043 8044 Bool bBipartition; 8045 if( iPtr == iWidth * iHeight ) 8046 { 8047 bBipartition = false; // single partition 8048 } 8049 else 8050 { 8051 for( Int i = 0; i < iWidth * iHeight; i++ ) 8052 { 8053 if( !pbVisit[ i ] ) 8054 { 8055 piStack[ iPtr++ ] = (( i / iWidth ) << 8) | ( i % iWidth ); 8056 pbVisit[ i ] = true; 8057 break; 8058 } 8059 } 8060 while( iPtr > 0 ) 8061 { 8062 Int iX; 8063 Int iY; 8064 iPtr--; 8065 iX = piStack[ iPtr ] & 0xff; 8066 iY = piStack[ iPtr ] >> 8; 8067 pbVisit[ iY * iWidth + iX ] = true; 8068 8069 if( iY > 0 && !pbVisit[ (iY - 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY - 1) * iWidth + iX ] ) 8070 { 8071 piStack[ iPtr++ ] = ((iY - 1) << 8) | iX; 8072 } 8073 if( iY < iHeight - 1 && !pbVisit[ (iY + 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY + 1) * iWidth + iX ] ) 8074 { 8075 piStack[ iPtr++ ] = ((iY + 1) << 8) | iX; 8076 } 8077 if( iX > 0 && !pbVisit[ iY * iWidth + (iX - 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX - 1) ] ) 8078 { 8079 piStack[ iPtr++ ] = (iY << 8) | (iX - 1); 8080 } 8081 if( iX < iWidth - 1 && !pbVisit[ iY * iWidth + (iX + 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX + 1) ] ) 8082 { 8083 piStack[ iPtr++ ] = (iY << 8) | (iX + 1); 8084 } 8085 } 8086 bBipartition = true; 8087 for( Int i = 0; i < iWidth * iHeight; i++ ) 8088 { 8089 if( !pbVisit[ i ] ) 8090 { 8091 bBipartition = false; 8092 break; 8093 } 8094 } 8095 } 8096 8097 xFree( pbEdge ); 8098 delete[] pbEdgeX; pbEdgeX = NULL; 8099 delete[] pbEdgeY; pbEdgeY = NULL; 8100 delete[] psDiffX; psDiffX = NULL; 8101 delete[] psDiffY; psDiffY = NULL; 8102 delete[] pusUnconnectedEdgeStack; pusUnconnectedEdgeStack = NULL; 8103 delete[] pbVisit; pbVisit = NULL; 8104 delete[] piStack; piStack = NULL; 8105 8106 if( bBipartition ) 8107 { 8108 return xConstructChainCode( pcCU, uiAbsPtIdx, (UInt)iWidth, (UInt)iHeight ); 8109 } 8110 else 8111 { 8112 return false; 8113 } 8114 } 8115 8116 Bool TEncSearch::xCheckTerminatedEdge( Bool* pbEdge, Int iX, Int iY, Int iWidth, Int iHeight ) 8117 { 8118 if( (iY % 2) == 0 ) // vertical edge 8119 { 8120 Bool bTopConnected = false; 8121 Bool bBottomConnected = false; 8122 8123 if( iY != 0 ) 8124 { 8125 if( pbEdge[ iX + (iY - 2) * 2 * iWidth ] ) 8126 bTopConnected = true; 8127 if( pbEdge[ (iX - 1) + (iY - 1) * 2 * iWidth ] ) 8128 bTopConnected = true; 8129 if( pbEdge[ (iX + 1) + (iY - 1) * 2 * iWidth ] ) 8130 bTopConnected = true; 8131 } 8132 else 8133 { 8134 bTopConnected = true; 8135 } 8136 8137 8138 if( iY != 2 * iHeight - 2 ) 8139 { 8140 if( pbEdge[ iX + (iY + 2) * 2 * iWidth ] ) 8141 bBottomConnected = true; 8142 if( pbEdge[ (iX - 1) + (iY + 1) * 2 * iWidth ] ) 8143 bBottomConnected = true; 8144 if( pbEdge[ (iX + 1) + (iY + 1) * 2 * iWidth ] ) 8145 bBottomConnected = true; 8146 } 8147 else 8148 { 8149 bBottomConnected = true; 8150 } 8151 8152 8153 if( bTopConnected && bBottomConnected ) 8154 { 8155 return true; 8156 } 8157 else 8158 { 8159 return false; 8160 } 8161 } 8162 else 8163 { 8164 Bool bLeftConnected = false; 8165 Bool bRightConnected = false; 8166 8167 if( iX != 0 ) 8168 { 8169 if( pbEdge[ (iX - 2) + iY * 2 * iWidth ] ) 8170 bLeftConnected = true; 8171 if( pbEdge[ (iX - 1) + (iY - 1) * 2 * iWidth ] ) 8172 bLeftConnected = true; 8173 if( pbEdge[ (iX - 1) + (iY + 1) * 2 * iWidth ] ) 8174 bLeftConnected = true; 8175 } 8176 else 8177 { 8178 bLeftConnected = true; 8179 } 8180 8181 if( iX != 2 * iWidth - 2 ) 8182 { 8183 if( pbEdge[ (iX + 2) + iY * 2 * iWidth ] ) 8184 bRightConnected = true; 8185 if( pbEdge[ (iX + 1) + (iY - 1) * 2 * iWidth ] ) 8186 bRightConnected = true; 8187 if( pbEdge[ (iX + 1) + (iY + 1) * 2 * iWidth ] ) 8188 bRightConnected = true; 8189 } 8190 else 8191 { 8192 bRightConnected = true; 8193 } 8194 8195 8196 if( bLeftConnected && bRightConnected ) 8197 { 8198 return true; 8199 } 8200 else 8201 { 8202 return false; 8203 } 8204 } 8205 } 8206 Bool TEncSearch::xConstructChainCode( TComDataCU* pcCU, UInt uiAbsPtIdx, UInt uiWidth, UInt uiHeight ) 8207 { 8208 //UInt uiWidth = pcCU->getWidth( uiPartIdx ) >> (bPU4x4 ? 1 : 0); 8209 //UInt uiHeight = pcCU->getHeight( uiPartIdx ) >> (bPU4x4 ? 1 : 0); 8210 Bool* pbEdge = (Bool*) xMalloc( Bool, uiWidth * uiHeight * 4 ); 8211 Bool* pbVisit = (Bool*) xMalloc( Bool, uiWidth * uiHeight * 4 ); 8212 UInt uiMaxEdge = uiWidth * (RBC_MAX_EDGE_NUM_PER_4x4 / 4); 8213 Bool* pbRegion = pcCU->getEdgePartition( uiAbsPtIdx ); 8214 UChar* piEdgeCode = pcCU->getEdgeCode( uiAbsPtIdx ); 8215 Bool bStartLeft = false; 8216 Bool bPossible = false; 8217 Bool bFinish = false; 8218 Int iStartPosition = -1; 8219 Int iPtr = 0; 8220 Int iDir = -1, iNextDir = -1; 8221 Int iArrow = -1, iNextArrow = -1; 8222 Int iX = -1, iY = -1; 8223 Int iDiffX = 0, iDiffY = 0; 8224 UChar iCode = 255; 8225 UInt uiWidth2 = uiWidth * 2; 8226 8227 for( Int i = 0; i < uiWidth * uiHeight * 4; i++ ) 8228 pbEdge[ i ] = false; 8229 8230 for( Int i = 0; i < uiHeight; i++ ) 8231 { 8232 for( Int j = 0; j < uiWidth - 1; j++ ) 8233 { 8234 if( pbRegion[ i * uiWidth + j ] != pbRegion[ i * uiWidth + j + 1 ] ) 8235 pbEdge[ i * uiWidth * 4 + j * 2 + 1 ] = true; 8236 } 8237 } 8238 8239 for( Int i = 0; i < uiHeight - 1; i++ ) 8240 { 8241 for( Int j = 0; j < uiWidth; j++ ) 8242 { 8243 if( pbRegion[ (i + 0) * uiWidth + j ] != pbRegion[ (i + 1) * uiWidth + j ] ) 8244 pbEdge[ (2 * i + 1) * 2 * uiWidth + j * 2 ] = true; 8245 } 8246 } 8247 8248 for( Int i = 1; i < uiWidth2 - 2; i+=2 ) 8249 { 8250 if(pbEdge[ i ]) 8251 { 8252 bPossible = true; 8253 bStartLeft = false; 8254 iStartPosition = iX = i; 8255 iY = 0; 8256 iDir = 3; 8257 iArrow = 3; 8258 break; 8259 } 8260 } 8261 8262 if( !bPossible ) 8263 { 8264 for( Int i = 1; i < uiWidth2 - 2; i+=2 ) 8265 { 8266 if(pbEdge[ i * uiWidth2 ]) 8267 { 8268 bPossible = true; 8269 bStartLeft = true; 8270 iX = 0; 8271 iStartPosition = iY = i; 8272 iDir = 1; 8273 iArrow = 1; 8274 break; 8275 } 8276 } 8277 } 8278 8279 if( bPossible ) 8280 { 8281 for( Int i = 0; i < 4 * uiWidth * uiHeight; i++ ) 8282 pbVisit[ i ] = false; 8283 8284 while( !bFinish ) 8285 { 8286 Bool bArrowSkip = false; 8287 pbVisit[ iX + iY * uiWidth2 ] = true; 8288 8289 switch( iDir ) 8290 { 8291 case 0: // left 8292 if( iX > 0 && !pbVisit[ (iX - 2) + iY * uiWidth2 ] && pbEdge[ (iX - 2) + iY * uiWidth2 ] ) // left 8293 { 8294 iDiffX = -2; 8295 iDiffY = 0; 8296 iNextDir = 0; 8297 iNextArrow = 0; 8298 } 8299 else if( iX > 0 && !pbVisit[ (iX - 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY - 1) * uiWidth2 ] ) // top 8300 { 8301 iDiffX = -1; 8302 iDiffY = -1; 8303 iNextDir = 2; 8304 iNextArrow = 4; 8305 } 8306 else if( iX > 0 && !pbVisit[ (iX - 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY + 1) * uiWidth2 ] ) // bottom 8307 { 8308 iDiffX = -1; 8309 iDiffY = +1; 8310 iNextDir = 3; 8311 iNextArrow = iArrow; 8312 if( !(iPtr == 0 && iX == uiWidth2 - 2 && iY == uiHeight * 2 - 3) ) 8313 bArrowSkip = true; 8314 else 8315 iNextArrow = 3; 8316 } 8317 else if( iX == 0 ) 8318 { 8319 iDiffX = 0; 8320 iDiffY = 0; 8321 iNextDir = iDir; 8322 iNextArrow = iArrow; 8323 bFinish = true; 8324 continue; 8325 } 8326 else 8327 { 8328 iPtr = 0; // edge loop or unwanted case 8329 bFinish = true; 8330 //continue; 8331 assert(false); 8332 } 8333 break; 8334 case 1: // right 8335 if( iX < uiWidth2 - 2 && !pbVisit[ (iX + 2) + iY * uiWidth2 ] && pbEdge[ (iX + 2) + iY * uiWidth2 ] ) // right 8336 { 8337 iDiffX = +2; 8338 iDiffY = 0; 8339 iNextDir = 1; 8340 iNextArrow = 1; 8341 } 8342 else if( iX < uiWidth2 - 2 && !pbVisit[ (iX + 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY - 1) * uiWidth2 ] ) // top 8343 { 8344 iDiffX = +1; 8345 iDiffY = -1; 8346 iNextDir = 2; 8347 iNextArrow = iArrow; 8348 if( !(iPtr == 0 && iX == 0 && iY == 1) ) 8349 bArrowSkip = true; 8350 else 8351 iNextArrow = 2; 8352 } 8353 else if( iX < uiWidth2 - 2 && !pbVisit[ (iX + 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY + 1) * uiWidth2 ] ) // bottom 8354 { 8355 iDiffX = +1; 8356 iDiffY = +1; 8357 iNextDir = 3; 8358 iNextArrow = 7; 8359 } 8360 else if( iX == uiWidth2 - 2 ) 8361 { 8362 iDiffX = 0; 8363 iDiffY = 0; 8364 iNextDir = iDir; 8365 iNextArrow = iArrow; 8366 bFinish = true; 8367 continue; 8368 } 8369 else 8370 { 8371 iPtr = 0; // edge loop or unwanted case 8372 bFinish = true; 8373 //continue; 8374 assert(false); 8375 } 8376 break; 8377 case 2: // top 8378 if( iY > 0 && !pbVisit[ (iX - 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY - 1) * uiWidth2 ] ) // left 8379 { 8380 iDiffX = -1; 8381 iDiffY = -1; 8382 iNextDir = 0; 8383 iNextArrow = iArrow; 8384 if( !(iPtr == 0 && iX == 1 && iY == uiHeight * 2 - 2) ) 8385 bArrowSkip = true; 8386 else 8387 iNextArrow = 0; 8388 } 8389 else if( iY > 0 && !pbVisit[ (iX + 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY - 1) * uiWidth2 ] ) // right 8390 { 8391 iDiffX = +1; 8392 iDiffY = -1; 8393 iNextDir = 1; 8394 iNextArrow = 5; 8395 } 8396 else if( iY > 0 && !pbVisit[ iX + (iY - 2) * uiWidth2 ] && pbEdge[ iX + (iY - 2) * uiWidth2 ] ) // top 8397 { 8398 iDiffX = 0; 8399 iDiffY = -2; 8400 iNextDir = 2; 8401 iNextArrow = 2; 8402 } 8403 else if( iY == 0 ) 8404 { 8405 iDiffX = 0; 8406 iDiffY = 0; 8407 iNextDir = iDir; 8408 iNextArrow = iArrow; 8409 bFinish = true; 8410 continue; 8411 } 8412 else 8413 { 8414 iPtr = 0; // edge loop or unwanted case 8415 bFinish = true; 8416 //continue; 8417 assert(false); 8418 } 8419 break; 8420 case 3: // bottom 8421 if( iY < uiWidth2 - 2 && !pbVisit[ (iX - 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY + 1) * uiWidth2 ] ) // left 8422 { 8423 iDiffX = -1; 8424 iDiffY = +1; 8425 iNextDir = 0; 8426 iNextArrow = 6; 8427 } 8428 else if( iY < uiWidth2 - 2 && !pbVisit[ (iX + 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY + 1) * uiWidth2 ] ) // right 8429 { 8430 iDiffX = +1; 8431 iDiffY = +1; 8432 iNextDir = 1; 8433 iNextArrow = iArrow; 8434 if( !(iPtr == 0 && iX == uiWidth * 2 - 3 && iY == 0) ) 8435 bArrowSkip = true; 8436 else 8437 iNextArrow = 1; 8438 } 8439 else if( iY < uiWidth2 - 2 && !pbVisit[ iX + (iY + 2) * uiWidth2 ] && pbEdge[ iX + (iY + 2) * uiWidth2 ] ) // bottom 8440 { 8441 iDiffX = 0; 8442 iDiffY = +2; 8443 iNextDir = 3; 8444 iNextArrow = 3; 8445 } 8446 else if( iY == uiWidth2 - 2 ) 8447 { 8448 iDiffX = 0; 8449 iDiffY = 0; 8450 iNextDir = iDir; 8451 iNextArrow = iArrow; 8452 bFinish = true; 8453 continue; 8454 } 8455 else 8456 { 8457 iPtr = 0; // edge loop or unwanted case 8458 bFinish = true; 8459 //continue; 8460 assert(false); 8461 } 8462 break; 8463 } 8464 8465 const UChar tableCode[8][8] = { { 0, -1, 4, 3, 2, 6, 1, 5 }, // iArrow(current direction), iNextArrow(next direction) 8466 { -1, 0, 3, 4, 5, 1, 6, 2 }, 8467 { 3, 4, 0, -1, 1, 2, 5, 6 }, 8468 { 4, 3, -1, 0, 6, 5, 2, 1 }, 8469 { 1, 6, 2, 5, 0, 4, 3, -1 }, 8470 { 5, 2, 1, 6, 3, 0, -1, 4 }, 8471 { 2, 5, 6, 1, 4, -1, 0, 3 }, 8472 { 6, 1, 5, 2, -1, 3, 4, 0 } }; 8473 8474 iCode = tableCode[iArrow][iNextArrow]; 8475 8476 if(iPtr >= uiMaxEdge) 8477 { 8478 iPtr = 0; // over the maximum number of edge 8479 bPossible = false; 8480 break; 8481 } 8482 8483 if( !bArrowSkip ) 8484 { 8485 piEdgeCode[iPtr++] = iCode; // first edge coding 8486 //printf("xEdgeCoding: (%d,%d)->(%d,%d) code %d\n",iX,iY, iX+iDiffX, iY+iDiffY, iCode); 8487 } 8488 8489 iX += iDiffX; 8490 iY += iDiffY; 8491 iDir = iNextDir; 8492 iArrow = iNextArrow; 8493 } 8494 } 8495 8496 pcCU->setEdgeLeftFirst( uiAbsPtIdx, bStartLeft ); 8497 pcCU->setEdgeStartPos ( uiAbsPtIdx, bStartLeft ? (iStartPosition - 1) >> 1 : (iStartPosition + 1) >> 1); 8498 pcCU->setEdgeNumber ( uiAbsPtIdx, iPtr ); 8499 8500 xFree( pbEdge ); 8501 xFree( pbVisit ); 8502 8503 return (iPtr != 0); 8504 } 8505 #endif 7387 7388 #endif 7389 8506 7390 #endif 8507 7391 //! \}
Note: See TracChangeset for help on using the changeset viewer.