Changeset 531 in 3DVCSoftware for branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder
- Timestamp:
- 11 Jul 2013, 16:03:14 (11 years ago)
- Location:
- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.cpp
r521 r531 752 752 #if H_3D_GEN 753 753 WRITE_FLAG( 1, "vps_extension2_flag" ); 754 for( Int layer = 0; layer <= pcVPS->getMaxLayers() - 1; layer++ )755 { 756 if ( layer!= 0)757 { 758 if ( !( pcVPS->getDepthId( layer) == 1 ) )754 for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ ) 755 { 756 if (i!= 0) 757 { 758 if ( !( pcVPS->getDepthId( i ) == 1 ) ) 759 759 { 760 760 #if H_3D_IV_MERGE 761 WRITE_FLAG( pcVPS->getIvMvPredFlag ( layer) ? 1 : 0 , "iv_mv_pred_flag[i]");761 WRITE_FLAG( pcVPS->getIvMvPredFlag ( i ) ? 1 : 0 , "iv_mv_pred_flag[i]"); 762 762 #endif 763 763 #if H_3D_ARP 764 WRITE_FLAG( pcVPS->getUseAdvRP ( layer) ? 1 : 0, "advanced_residual_pred_flag" );764 WRITE_FLAG( pcVPS->getUseAdvRP ( i ) ? 1 : 0, "advanced_residual_pred_flag" ); 765 765 #endif 766 766 #if H_3D_NBDV_REF 767 WRITE_FLAG( pcVPS->getDepthRefinementFlag ( layer) ? 1 : 0 , "depth_refinement_flag[i]");767 WRITE_FLAG( pcVPS->getDepthRefinementFlag ( i ) ? 1 : 0 , "depth_refinement_flag[i]"); 768 768 #endif 769 769 #if H_3D_VSP 770 WRITE_FLAG( pcVPS->getViewSynthesisPredFlag( layer) ? 1 : 0 , "view_synthesis_pred_flag[i]");770 WRITE_FLAG( pcVPS->getViewSynthesisPredFlag( i ) ? 1 : 0 , "view_synthesis_pred_flag[i]"); 771 771 #endif 772 772 } 773 773 } 774 if( pcVPS->getDepthId( i ) ) 775 { 776 WRITE_FLAG( pcVPS->getVpsDepthModesFlag( i ), "vps_depth_modes_flag[i]" ); 777 778 #if H_3D_DIM_DLT 779 if( pcVPS->getVpsDepthModesFlag( i ) ) 780 { 781 WRITE_FLAG( pcVPS->getUseDLTFlag( i ) ? 1 : 0, "use_dlt_flag[i]" ); 782 if( pcVPS->getUseDLTFlag( i ) ) 783 { 784 // code mapping 785 WRITE_UVLC(pcVPS->getNumDepthValues(i), "num_dlt_depth_values[i]"); 786 for(Int d=0; d<pcVPS->getNumDepthValues(i); d++) 787 { 788 WRITE_UVLC( pcVPS->idx2DepthValue(i, d), "dlt_depth_value[i][d]" ); 789 } 790 } 791 } 792 #endif 793 } 794 774 795 } 775 796 #else -
branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCfg.h
r504 r531 403 403 Bool m_bUseIC; 404 404 #endif 405 406 //====== Depth Intra Modes ====== 407 #if H_3D_DIM 408 Bool m_useDMM; 409 Bool m_useRBC; 410 Bool m_useSDC; 411 Bool m_useDLT; 412 #endif 413 405 414 #endif 406 415 … … 948 957 Void setDispCoeff ( Double d ) { m_dDispCoeff = d; } 949 958 #endif // H_3D_VSO 959 960 //==== DIM ========== 961 #if H_3D_DIM 962 Bool getUseDMM () { return m_useDMM; } 963 Void setUseDMM ( Bool b) { m_useDMM = b; } 964 Bool getUseRBC () { return m_useRBC; } 965 Void setUseRBC ( Bool b) { m_useRBC = b; } 966 Bool getUseSDC () { return m_useSDC; } 967 Void setUseSDC ( Bool b) { m_useSDC = b; } 968 Bool getUseDLT () { return m_useDLT; } 969 Void setUseDLT ( Bool b) { m_useDLT = b; } 970 #endif 950 971 #endif // H_3D 951 972 }; -
branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.cpp
r521 r531 597 597 m_LCUPredictionSAD += m_temporalSAD; 598 598 m_addSADDepth = uiDepth; 599 } 600 #endif 601 602 #if H_3D_DIM_ENC 603 if( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) 604 { 605 earlyDetectionSkipMode = false; 599 606 } 600 607 #endif … … 762 769 763 770 // do normal intra modes 771 #if H_3D_DIM_ENC 772 if ( !bEarlySkip || ( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) ) 773 #else 764 774 if ( !bEarlySkip ) 775 #endif 765 776 { 766 777 // speedup for inter frames … … 768 779 rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || 769 780 rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || 770 rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) // avoid very complex intra if it is unlikely 781 rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 782 #if H_3D_DIM_ENC 783 || ( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) 784 #endif 785 ) // avoid very complex intra if it is unlikely 771 786 { 772 787 xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); … … 1732 1747 m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() ); 1733 1748 1749 #if H_3D_DIM_SDC 1750 if( !rpcTempCU->getSDCFlag( 0 ) ) 1751 #endif 1734 1752 m_pcPredSearch ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC ); 1735 1753 -
branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncEntropy.cpp
r521 r531 257 257 return; 258 258 } 259 #if H_3D_DIM_SDC 260 if( pcCU->getSDCFlag(uiAbsPartIdx) ) 261 { 262 return; 263 } 264 #endif 259 265 260 266 if( bRD ) … … 469 475 { 470 476 encodeIntraDirModeLuma ( pcCU, uiAbsPartIdx,true ); 477 #if H_3D_DIM_SDC 478 if(!pcCU->getSDCFlag(uiAbsPartIdx)) 479 #endif 471 480 encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD ); 472 481 } … … 641 650 UInt uiChromaOffset = uiLumaOffset>>2; 642 651 652 #if H_3D_DIM_SDC 653 if( pcCU->getSDCFlag( uiAbsPartIdx ) ) 654 { 655 assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); 656 assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 ); 657 assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 ); 658 assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 ); 659 assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 ); 660 return; 661 } 662 #endif 663 643 664 if( pcCU->isIntra(uiAbsPartIdx) ) 644 665 { -
branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.cpp
r530 r531 706 706 #if H_3D 707 707 pcSlice->setIvPicLists( m_ivPicLists ); 708 #if H_3D 709 pcSlice->setPicLists( m_ivPicLists ); 710 #endif 708 711 #if H_3D_IV_MERGE 709 712 assert( !m_pcEncTop->getIsDepth() || ( pcSlice->getTexturePic() != 0 ) ); -
branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSbac.cpp
r521 r531 89 89 , m_cTransformSkipSCModel ( 1, 2, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 90 90 , m_CUTransquantBypassFlagSCModel( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels) 91 #if H_3D_DIM 92 , m_cDepthIntraModeSCModel ( 1, 1, NUM_DEPTH_INTRA_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) 93 , m_cDdcFlagSCModel ( 1, 1, NUM_DDC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 94 , m_cDdcDataSCModel ( 1, 1, NUM_DDC_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) 95 #if H_3D_DIM_DMM 96 , m_cDmm1DataSCModel ( 1, 1, NUM_DMM1_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) 97 , m_cDmm2DataSCModel ( 1, 1, NUM_DMM2_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) 98 , m_cDmm3DataSCModel ( 1, 1, NUM_DMM3_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) 99 #endif 100 #if H_3D_DIM_RBC 101 , m_cRbcDataSCModel ( 1, 1, NUM_RBC_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) 102 #endif 103 #if H_3D_DIM_SDC 104 , m_cSDCResidualFlagSCModel ( 1, 1, SDC_NUM_RESIDUAL_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 105 , m_cSDCResidualSCModel ( 1, 1, SDC_NUM_RESIDUAL_CTX , m_contextModels + m_numContextModels, m_numContextModels) 106 #endif 107 #endif 91 108 { 92 109 assert( m_numContextModels <= MAX_NUM_CTX_MOD ); … … 146 163 m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 147 164 m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 165 166 #if H_3D_DIM 167 m_cDepthIntraModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE ); 168 m_cDdcFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG ); 169 m_cDdcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_DATA ); 170 #if H_3D_DIM_DMM 171 m_cDmm1DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA ); 172 m_cDmm2DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA ); 173 m_cDmm3DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA ); 174 #endif 175 #if H_3D_DIM_RBC 176 m_cRbcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RBC_DATA ); 177 #endif 178 #if H_3D_DIM_SDC 179 m_cSDCResidualFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG ); 180 m_cSDCResidualSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL ); 181 #endif 182 #endif 148 183 // new structure 149 184 m_uiLastQp = iQp; … … 206 241 curCost += m_cTransformSkipSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 207 242 curCost += m_CUTransquantBypassFlagSCModel.calcCost( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 243 #if H_3D_DIM 244 if( m_pcSlice->getVpsDepthModesFlag() ) 245 { 246 curCost += m_cDepthIntraModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DEPTH_INTRA_MODE ); 247 curCost += m_cDdcFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DDC_FLAG ); 248 curCost += m_cDdcDataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DDC_DATA ); 249 #if H_3D_DIM_DMM 250 curCost += m_cDmm1DataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM1_DATA ); 251 curCost += m_cDmm2DataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM2_DATA ); 252 curCost += m_cDmm3DataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM3_DATA ); 253 #endif 254 #if H_3D_DIM_RBC 255 curCost += m_cRbcDataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_RBC_DATA ); 256 #endif 257 } 258 #endif 208 259 if (curCost < bestCost) 209 260 { … … 261 312 m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 262 313 m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 314 315 #if H_3D_DIM 316 m_cDepthIntraModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE ); 317 m_cDdcFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG ); 318 m_cDdcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_DATA ); 319 #if H_3D_DIM_DMM 320 m_cDmm1DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA ); 321 m_cDmm2DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA ); 322 m_cDmm3DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA ); 323 #endif 324 #if H_3D_DIM_RBC 325 m_cRbcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RBC_DATA ); 326 #endif 327 #if H_3D_DIM_SDC 328 m_cSDCResidualFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG ); 329 m_cSDCResidualSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL ); 330 #endif 331 #endif 263 332 m_pcBinIf->start(); 264 333 } … … 403 472 } 404 473 474 #if H_3D_DIM 475 Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel ) 476 { 477 if( uiSymbol ) 478 { 479 m_pcBinIf->encodeBin( 1, rcSCModel ); 480 UInt uiCount = 0; 481 Bool bNoExGo = (uiSymbol < 13); 482 483 while( --uiSymbol && ++uiCount < 13 ) 484 { 485 m_pcBinIf->encodeBin( 1, rcSCModel ); 486 } 487 if( bNoExGo ) 488 { 489 m_pcBinIf->encodeBin( 0, rcSCModel ); 490 } 491 else 492 { 493 xWriteEpExGolomb( uiSymbol, 0 ); 494 } 495 } 496 else 497 { 498 m_pcBinIf->encodeBin( 0, rcSCModel ); 499 } 500 501 return; 502 } 503 504 Void TEncSbac::xCodeDimDeltaDC( Pel valDeltaDC, UInt dimType ) 505 { 506 xWriteExGolombLevel( UInt( abs( valDeltaDC ) ), m_cDdcDataSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) ); 507 if( valDeltaDC != 0 ) 508 { 509 UInt uiSign = valDeltaDC > 0 ? 0 : 1; 510 m_pcBinIf->encodeBinEP( uiSign ); 511 } 512 } 513 514 #if H_3D_DIM_DMM 515 Void TEncSbac::xCodeDmm1WedgeIdx( UInt uiTabIdx, Int iNumBit ) 516 { 517 for ( Int i = 0; i < iNumBit; i++ ) 518 { 519 m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cDmm1DataSCModel.get(0, 0, 0) ); 520 } 521 } 522 523 Void TEncSbac::xCodeDmm2Offset( Int iOffset ) 524 { 525 if( DMM2_DELTAEND_MAX > 0 ) 526 { 527 m_pcBinIf->encodeBin( (iOffset != 0) , m_cDmm2DataSCModel.get(0, 0, 0) ); 528 if( iOffset != 0 ) 529 { 530 UInt uiAbsValMinus1 = abs(iOffset)-1; 531 m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cDmm2DataSCModel.get(0, 0, 0) ); 532 m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cDmm2DataSCModel.get(0, 0, 0) ); 533 534 UInt uiSign = (iOffset > 0) ? 0 : 1; 535 m_pcBinIf->encodeBinEP( uiSign ); 536 } 537 } 538 } 539 540 Void TEncSbac::xCodeDmm3WedgeIdx( UInt uiIntraIdx, Int iNumBit ) 541 { 542 for( Int i = 0; i < iNumBit; i++ ) 543 { 544 m_pcBinIf->encodeBin( ( uiIntraIdx >> i ) & 1, m_cDmm3DataSCModel.get(0, 0, 0) ); 545 } 546 } 547 #endif 548 #if H_3D_DIM_RBC 549 Void TEncSbac::xCodeRbcEdge( TComDataCU* pcCU, UInt uiAbsPartIdx ) 550 { 551 UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ) + (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 1 : 0); 552 UChar* pucSymbolList = pcCU->getEdgeCode ( uiAbsPartIdx ); 553 UChar ucEdgeNumber = pcCU->getEdgeNumber ( uiAbsPartIdx ); 554 Bool bLeft = pcCU->getEdgeLeftFirst( uiAbsPartIdx ); 555 UChar ucStart = pcCU->getEdgeStartPos ( uiAbsPartIdx ); 556 UInt uiSymbol; 557 558 // 1. Top(0) or Left(1) 559 uiSymbol = (bLeft == false) ? 0 : 1; 560 m_pcBinIf->encodeBinEP( uiSymbol ); 561 562 // 2. Start position (lowest bit first) 563 uiSymbol = ucStart; 564 for( UInt ui = 6; ui > uiDepth; ui-- ) // 64(0)->6, 32(1)->5, 16(2)->4, 8(3)->3, 4(4)->2 565 { 566 m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); 567 uiSymbol >>= 1; 568 } 569 570 // 3. Number of edges 571 uiSymbol = ucEdgeNumber > 0 ? ucEdgeNumber - 1 : 0; 572 for( UInt ui = 7; ui > uiDepth; ui-- ) // 64(0)->7, 32(1)->6, 16(2)->5, 8(3)->4, 4(4)->3 573 { 574 m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); 575 uiSymbol >>= 1; 576 } 577 578 if(uiSymbol != 0) 579 { 580 printf(" ucEdgeNumber %d at depth %d\n",ucEdgeNumber, uiDepth); 581 assert(false); 582 } 583 584 // 4. Edges 585 for( Int iPtr2 = 0; iPtr2 < ucEdgeNumber; iPtr2++ ) 586 { 587 UInt uiReorderSymbol = pucSymbolList[iPtr2]; 588 for( UInt ui = 0; ui < uiReorderSymbol; ui++ ) 589 { 590 m_pcBinIf->encodeBin( 1, m_cRbcDataSCModel.get( 0, 0, 0 ) ); 591 } 592 593 if( uiReorderSymbol != 6 ) 594 m_pcBinIf->encodeBin( 0, m_cRbcDataSCModel.get( 0, 0, 0 ) ); 595 } 596 } 597 #endif 598 #if H_3D_DIM_SDC 599 Void TEncSbac::xCodeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ) 600 { 601 assert( pcCU->getSlice()->getIsDepth() ); 602 assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); 603 assert( pcCU->getSDCFlag(uiAbsPartIdx) ); 604 assert( uiSegment < 2 ); 605 606 Pel segmentDCOffset = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx); 607 608 UInt uiResidual = segmentDCOffset == 0 ? 0 : 1; 609 UInt uiSign = segmentDCOffset < 0 ? 1 : 0; 610 UInt uiAbsIdx = abs(segmentDCOffset); 611 612 #if H_3D_DIM_DLT 613 UInt uiMaxResidualBits = pcCU->getSlice()->getVPS()->getBitsPerDepthValue( pcCU->getSlice()->getLayerIdInVps() ); 614 #else 615 UInt uiMaxResidualBits = g_bitDepthY; 616 #endif 617 assert( uiMaxResidualBits <= g_bitDepthY ); 618 619 // residual flag 620 m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) ); 621 622 if (uiResidual) 623 { 624 // encode sign bit of residual 625 m_pcBinIf->encodeBinEP( uiSign ); 626 627 #if H_3D_DIM_DLT 628 UInt uiNumDepthValues = pcCU->getSlice()->getVPS()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() ); 629 #else 630 UInt uiNumDepthValues = ((1 << g_bitDepthY)-1); 631 #endif 632 assert(uiAbsIdx <= uiNumDepthValues); 633 634 // encode residual magnitude 635 uiAbsIdx -= 1; 636 // prefix part 637 if ( uiAbsIdx == 0 ) 638 m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) ); 639 else 640 { 641 UInt l = uiAbsIdx; 642 UInt k = 0; 643 UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2); 644 while ( l > 0 && k < uiPrefixThreshold ) 645 { 646 m_pcBinIf->encodeBin( 1, m_cSDCResidualSCModel.get(0, 0, 0) ); 647 l--; 648 k++; 649 } 650 if ( uiAbsIdx < uiPrefixThreshold ) 651 m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) ); 652 // suffix part 653 else 654 { 655 uiAbsIdx -= uiPrefixThreshold; 656 UInt uiSuffixLength = numBitsForValue(uiNumDepthValues - uiPrefixThreshold); 657 UInt uiBitInfo = 0; 658 for ( Int i = 0; i < uiSuffixLength; i++) 659 { 660 uiBitInfo = ( uiAbsIdx & ( 1 << i ) ) >> i; 661 m_pcBinIf->encodeBinEP( uiBitInfo); 662 } 663 } 664 } 665 666 } 667 } 668 #endif 669 #endif 670 405 671 // SBAC RD 406 672 Void TEncSbac::load ( TEncSbac* pSrc) … … 415 681 this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); 416 682 } 417 683 #if H_3D_DIM 684 Void TEncSbac::loadIntraDepthMode( TEncSbac* pSrc) 685 { 686 m_pcBinIf->copyState( pSrc->m_pcBinIf ); 687 688 this->m_cDepthIntraModeSCModel .copyFrom( &pSrc->m_cDepthIntraModeSCModel ); 689 this->m_cDdcFlagSCModel .copyFrom( &pSrc->m_cDdcFlagSCModel ); 690 } 691 #endif 418 692 419 693 Void TEncSbac::store( TEncSbac* pDest) … … 546 820 Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) 547 821 { 822 #if H_3D_DIM_SDC 823 if ( pcCU->getSlice()->isIntra() ) 824 { 825 assert( pcCU->isIntra(uiAbsPartIdx) ); 826 return; 827 } 828 #endif 829 548 830 // get context function is here 549 831 Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); … … 742 1024 { 743 1025 dir[j] = pcCU->getLumaIntraDir( absPartIdx+partOffset*j ); 1026 #if H_3D_DIM 1027 if( pcCU->getSlice()->getVpsDepthModesFlag() ) 1028 { 1029 codeIntraDepth( pcCU, absPartIdx+partOffset*j ); 1030 } 1031 if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) 1032 #if H_3D_DIM_SDC 1033 if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) ) 1034 #endif 1035 { 1036 #endif 744 1037 predNum[j] = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds[j]); 745 1038 for(UInt i = 0; i < predNum[j]; i++) … … 754 1047 DTRACE_CU("prev_intra_luma_pred_flag", (predIdx[j] != -1)? 1 : 0); 755 1048 #endif 1049 #if H_3D_DIM 1050 } 1051 #endif 1052 756 1053 } 757 1054 for (j=0;j<partNum;j++) 758 1055 { 1056 #if H_3D_DIM 1057 if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) 1058 #if H_3D_DIM_SDC 1059 if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) ) 1060 #endif 1061 { 1062 #endif 759 1063 if(predIdx[j] != -1) 760 1064 { … … 791 1095 #endif 792 1096 } 1097 #if H_3D_DIM 1098 } 1099 #endif 793 1100 } 794 1101 return; … … 829 1136 return; 830 1137 } 1138 1139 #if H_3D_DIM 1140 Void TEncSbac::codeIntraDepth( TComDataCU* pcCU, UInt absPartIdx ) 1141 { 1142 codeIntraDepthMode( pcCU, absPartIdx ); 1143 1144 UInt dir = pcCU->getLumaIntraDir( absPartIdx ); 1145 UInt dimType = getDimType( dir ); 1146 1147 switch( dimType ) 1148 { 1149 #if H_3D_DIM_DMM 1150 case( DMM1_IDX ): 1151 { 1152 xCodeDmm1WedgeIdx( pcCU->getDmmWedgeTabIdx( dimType, absPartIdx ), g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] ); 1153 } break; 1154 case( DMM2_IDX ): 1155 { 1156 xCodeDmm2Offset( pcCU->getDmm2DeltaEnd( absPartIdx ) ); 1157 } break; 1158 case( DMM3_IDX ): 1159 { 1160 xCodeDmm3WedgeIdx( pcCU->getDmm3IntraTabIdx( absPartIdx ), g_dmm3IntraTabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] ); 1161 } break; 1162 case( DMM4_IDX ): break; 1163 #endif 1164 #if H_3D_DIM_RBC 1165 case( RBC_IDX ): 1166 { 1167 assert( pcCU->getWidth( absPartIdx ) < 64 ); 1168 xCodeRbcEdge( pcCU, absPartIdx ); 1169 } break; 1170 #endif 1171 default: break; 1172 } 1173 1174 #if H_3D_DIM_SDC 1175 if( pcCU->getSDCFlag( absPartIdx ) ) 1176 { 1177 assert(pcCU->getPartitionSize(absPartIdx)==SIZE_2Nx2N); 1178 UInt uiNumSegments = ( dir == DC_IDX || dir == PLANAR_IDX )? 1 : 2; 1179 for(UInt uiSeg=0; uiSeg<uiNumSegments; uiSeg++) 1180 { 1181 xCodeSDCResidualData(pcCU, absPartIdx, uiSeg); 1182 } 1183 } 1184 else 1185 { 1186 #endif 1187 if( dimType < DIM_NUM_TYPE ) 1188 { 1189 UInt dimDeltaDC = isDimDeltaDC( dir ); 1190 m_pcBinIf->encodeBin( dimDeltaDC, m_cDdcFlagSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) ); 1191 if( dimDeltaDC ) 1192 { 1193 for( UInt segment = 0; segment < 2; segment++ ) 1194 { 1195 xCodeDimDeltaDC( pcCU->getDimDeltaDC( dimType, segment, absPartIdx ), dimType ); 1196 } 1197 } 1198 } 1199 #if H_3D_DIM_SDC 1200 } 1201 #endif 1202 } 1203 1204 Void TEncSbac::codeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx ) 1205 { 1206 UInt codeWordTable[3][9] = {{0, 0, 0, 2, 0,6, 0, 0, 7},{0, 2, 3, 4, 5, 6, 14, 31, 30},{0, 2, 0, 0, 0, 0, 3, 0, 0}}; 1207 UInt codeWordLenTable[3][9] = {{0, 1, 0, 2, 0,3, 0, 0, 3},{2, 3, 3, 3, 3, 3, 4, 5, 5},{1, 2, 0, 0, 0, 0, 2, 0, 0}}; 1208 UInt dir = pcCU->getLumaIntraDir( absPartIdx ); 1209 UInt puIdx = (pcCU->getWidth(absPartIdx) == 64) ? 2 : ( (pcCU->getPartitionSize(absPartIdx) == SIZE_NxN && pcCU->getWidth(absPartIdx) == 8) ? 0 : 1 ); 1210 UInt codeIdx = 0; 1211 1212 if( dir < NUM_INTRA_MODE ) 1213 { 1214 codeIdx = 1; 1215 } 1216 if( isDimMode( dir ) ) 1217 { 1218 switch( getDimType( dir ) ) 1219 { 1220 case DMM1_IDX: codeIdx = 3; break; 1221 case DMM4_IDX: codeIdx = 4; break; 1222 case DMM3_IDX: codeIdx = 5; break; 1223 case DMM2_IDX: codeIdx = 7; break; 1224 case RBC_IDX: codeIdx = 8; break; 1225 default: break; 1226 } 1227 } 1228 1229 #if H_3D_DIM_SDC 1230 if( pcCU->getSDCFlag( absPartIdx ) ) 1231 { 1232 switch( dir ) 1233 { 1234 case PLANAR_IDX: codeIdx = 0; break; 1235 case DC_IDX: codeIdx = 6; break; 1236 default: codeIdx = 2; break; 1237 } 1238 } 1239 #endif 1240 //mode coding 1241 for( UInt i = 0; i < codeWordLenTable[puIdx][codeIdx]; i++ ) 1242 { 1243 UInt bit = codeWordTable[puIdx][codeIdx] & ( 1<<(codeWordLenTable[puIdx][codeIdx] - i - 1) ); 1244 UInt ctxDepthMode = puIdx*3 + ( (i >= 2) ? 2 : i ); 1245 m_pcBinIf->encodeBin( bit!=0 , m_cDepthIntraModeSCModel.get(0, 0, ctxDepthMode) ); 1246 } 1247 } 1248 #endif 1249 831 1250 832 1251 Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) -
branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSbac.h
r504 r531 84 84 Void load ( TEncSbac* pScr ); 85 85 Void loadIntraDirModeLuma ( TEncSbac* pScr ); 86 #if H_3D_DIM 87 Void loadIntraDepthMode ( TEncSbac* pScr ); 88 #endif 86 89 Void store ( TEncSbac* pDest ); 87 90 Void loadContexts ( TEncSbac* pScr ); … … 113 116 Void xWriteEpExGolomb ( UInt uiSymbol, UInt uiCount ); 114 117 Void xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam ); 118 #if H_3D_DIM 119 Void xWriteExGolombLevel ( UInt uiSymbol, ContextModel& rcSCModel ); 120 Void xCodeDimDeltaDC ( Pel valDeltaDC, UInt dimType ); 121 #if H_3D_DIM_DMM 122 Void xCodeDmm1WedgeIdx ( UInt uiTabIdx, Int iNumBit ); 123 Void xCodeDmm2Offset ( Int iOffset ); 124 Void xCodeDmm3WedgeIdx ( UInt uiIntraIdx, Int iNumBit ); 125 #endif 126 #if H_3D_DIM_RBC 127 Void xCodeRbcEdge ( TComDataCU* pcCU, UInt uiAbsPartIdx ); 128 #endif 129 #if H_3D_DIM_SDC 130 Void xCodeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ); 131 #endif 132 #endif 115 133 116 134 Void xCopyFrom ( TEncSbac* pSrc ); … … 154 172 155 173 Void codeIntraDirChroma ( TComDataCU* pcCU, UInt uiAbsPartIdx ); 174 175 #if H_3D_DIM 176 Void codeIntraDepth ( TComDataCU* pcCU, UInt absPartIdx ); 177 Void codeIntraDepthMode ( TComDataCU* pcCU, UInt absPartIdx ); 178 #endif 179 156 180 Void codeInterDir ( TComDataCU* pcCU, UInt uiAbsPartIdx ); 157 181 Void codeRefFrmIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ); … … 219 243 ContextModel3DBuffer m_cTransformSkipSCModel; 220 244 ContextModel3DBuffer m_CUTransquantBypassFlagSCModel; 245 246 #if H_3D_DIM 247 ContextModel3DBuffer m_cDepthIntraModeSCModel; 248 ContextModel3DBuffer m_cDdcFlagSCModel; 249 ContextModel3DBuffer m_cDdcDataSCModel; 250 #if H_3D_DIM_DMM 251 ContextModel3DBuffer m_cDmm1DataSCModel; 252 ContextModel3DBuffer m_cDmm2DataSCModel; 253 ContextModel3DBuffer m_cDmm3DataSCModel; 254 #endif 255 #if H_3D_DIM_RBC 256 ContextModel3DBuffer m_cRbcDataSCModel; 257 #endif 258 #if H_3D_DIM_SDC 259 ContextModel3DBuffer m_cSDCResidualFlagSCModel; 260 ContextModel3DBuffer m_cSDCResidualSCModel; 261 #endif 262 #endif 221 263 }; 222 264 -
branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSearch.cpp
r510 r531 1017 1017 UInt& ruiDist, 1018 1018 #endif 1019 Int default0Save1Load2 ) 1019 Int default0Save1Load2 1020 #if H_3D_DIM_ENC 1021 , Bool zeroResi 1022 #endif 1023 ) 1020 1024 { 1021 1025 UInt uiLumaPredMode = pcCU ->getLumaIntraDir ( uiAbsPartIdx ); … … 1051 1055 pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail ); 1052 1056 //===== get prediction signal ===== 1057 #if H_3D_DIM 1058 if( isDimMode( uiLumaPredMode ) ) 1059 { 1060 predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, true ); 1061 } 1062 else 1063 { 1064 #endif 1053 1065 predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 1066 #if H_3D_DIM 1067 } 1068 #endif 1069 1054 1070 // save prediction 1055 1071 if(default0Save1Load2 == 1) … … 1091 1107 for( UInt uiY = 0; uiY < uiHeight; uiY++ ) 1092 1108 { 1109 #if H_3D_DIM_ENC 1110 if( zeroResi ) 1111 { 1112 memset( pResi, 0, sizeof( Pel ) * uiWidth ); 1113 pResi += uiStride; 1114 } 1115 else 1116 { 1117 #endif 1093 1118 for( UInt uiX = 0; uiX < uiWidth; uiX++ ) 1094 1119 { … … 1098 1123 pResi += uiStride; 1099 1124 pPred += uiStride; 1125 #if H_3D_DIM_ENC 1126 } 1127 #endif 1100 1128 } 1101 1129 } … … 1228 1256 { 1229 1257 uiChromaPredMode = pcCU->getLumaIntraDir( 0 ); 1258 #if H_3D_DIM 1259 mapDepthModeToIntraDir( uiChromaPredMode ); 1260 #endif 1230 1261 } 1231 1262 … … 1393 1424 Bool bCheckFirst, 1394 1425 #endif 1395 Double& dRDCost ) 1426 Double& dRDCost 1427 #if H_3D_DIM_ENC 1428 , Bool zeroResi 1429 #endif 1430 ) 1396 1431 { 1397 1432 UInt uiFullDepth = pcCU->getDepth( 0 ) + uiTrDepth; … … 1435 1470 #endif 1436 1471 #endif 1472 #if H_3D_DIM 1473 if( isDimMode( pcCU->getLumaIntraDir( uiAbsPartIdx ) ) ) 1474 { 1475 bCheckSplit = false; 1476 } 1477 #endif 1478 1437 1479 Double dSingleCost = MAX_DOUBLE; 1438 1480 #if H_3D_VSO … … 1601 1643 //----- code luma block with given intra prediction mode and store Cbf----- 1602 1644 dSingleCost = 0.0; 1645 #if H_3D_DIM_ENC 1646 xIntraCodingLumaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, uiSingleDistY, 0, zeroResi ); 1647 #else 1603 1648 xIntraCodingLumaBlk( pcCU, uiTrDepth, uiAbsPartIdx, pcOrgYuv, pcPredYuv, pcResiYuv, uiSingleDistY ); 1649 #endif 1604 1650 if( bCheckSplit ) 1605 1651 { … … 1796 1842 } 1797 1843 1844 #if H_3D_DIM_SDC 1845 Void TEncSearch::xIntraCodingSDC( TComDataCU* pcCU, UInt uiAbsPartIdx, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, Dist& ruiDist, Double& dRDCost, Bool bResidual ) 1846 { 1847 UInt uiLumaPredMode = pcCU ->getLumaIntraDir( uiAbsPartIdx ); 1848 UInt uiWidth = pcCU ->getWidth ( 0 ); 1849 UInt uiHeight = pcCU ->getHeight ( 0 ); 1850 UInt uiStride = pcOrgYuv ->getStride (); 1851 Pel* piOrg = pcOrgYuv ->getLumaAddr( uiAbsPartIdx ); 1852 Pel* piPred = pcPredYuv->getLumaAddr( uiAbsPartIdx ); 1853 Pel* piReco = pcPredYuv->getLumaAddr( uiAbsPartIdx ); 1854 1855 UInt uiZOrder = pcCU->getZorderIdxInCU() + uiAbsPartIdx; 1856 Pel* piRecIPred = pcCU->getPic()->getPicYuvRec()->getLumaAddr( pcCU->getAddr(), uiZOrder ); 1857 UInt uiRecIPredStride = pcCU->getPic()->getPicYuvRec()->getStride (); 1858 1859 AOF( uiWidth == uiHeight ); 1860 AOF( uiAbsPartIdx == 0 ); 1861 AOF( pcCU->getSDCAvailable(uiAbsPartIdx) ); 1862 AOF( pcCU->getSDCFlag(uiAbsPartIdx) ); 1863 AOF( uiLumaPredMode == DC_IDX || uiLumaPredMode == PLANAR_IDX || ( getDimType( uiLumaPredMode ) == DMM1_IDX && !isDimDeltaDC( uiLumaPredMode ) ) ); 1864 AOF( uiLumaPredMode == DC_IDX || uiLumaPredMode == PLANAR_IDX || uiWidth < 64 ); 1865 1866 //===== init availability pattern ===== 1867 Bool bAboveAvail = false; 1868 Bool bLeftAvail = false; 1869 pcCU->getPattern()->initPattern ( pcCU, 0, uiAbsPartIdx ); 1870 pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, 0, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail ); 1871 1872 //===== get prediction signal ===== 1873 #if H_3D_DIM 1874 if( isDimMode( uiLumaPredMode ) ) 1875 { 1876 predIntraLumaDepth( pcCU, uiAbsPartIdx, uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, true ); 1877 } 1878 else 1879 { 1880 #endif 1881 predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail ); 1882 #if H_3D_DIM 1883 } 1884 #endif 1885 1886 // number of segments depends on prediction mode 1887 UInt uiNumSegments = 1; 1888 Bool* pbMask = NULL; 1889 UInt uiMaskStride = 0; 1890 1891 if( getDimType( uiLumaPredMode ) == DMM1_IDX ) 1892 { 1893 Int uiTabIdx = pcCU->getDmmWedgeTabIdx(DMM1_IDX, uiAbsPartIdx); 1894 1895 WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])]; 1896 TComWedgelet* pcWedgelet = &(pacWedgeList->at( uiTabIdx )); 1897 1898 uiNumSegments = 2; 1899 pbMask = pcWedgelet->getPattern(); 1900 uiMaskStride = pcWedgelet->getStride(); 1901 } 1902 1903 // get DC prediction for each segment 1904 Pel apDCPredValues[2]; 1905 analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride ); 1906 1907 // get original DC for each segment 1908 Pel apDCOrigValues[2]; 1909 analyzeSegmentsSDC(piOrg, uiStride, uiWidth, apDCOrigValues, uiNumSegments, pbMask, uiMaskStride ); 1910 1911 for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ ) 1912 { 1913 // remap reconstructed value to valid depth values 1914 Pel pDCRec = bResidual?apDCOrigValues[uiSegment]:apDCPredValues[uiSegment]; 1915 1916 // get residual (idx) 1917 #if H_3D_DIM_DLT 1918 Pel pResidualIdx = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pDCRec ) - pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] ); 1919 #else 1920 Pel pResidualIdx = pDCRec - apDCPredValues[uiSegment]; 1921 #endif 1922 1923 // save SDC DC offset 1924 pcCU->setSDCSegmentDCOffset(pResidualIdx, uiSegment, uiAbsPartIdx); 1925 } 1926 1927 // reconstruct residual based on mask + DC residuals 1928 Pel apDCResiValues[2]; 1929 for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ ) 1930 { 1931 #if H_3D_DIM_DLT 1932 Pel pPredIdx = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), apDCPredValues[uiSegment] ); 1933 Pel pResiIdx = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx); 1934 Pel pRecoValue = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pPredIdx + pResiIdx ); 1935 1936 apDCResiValues[uiSegment] = pRecoValue - apDCPredValues[uiSegment]; 1937 #else 1938 apDCResiValues[uiSegment] = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx); 1939 #endif 1940 } 1941 1942 //===== reconstruction ===== 1943 Bool* pMask = pbMask; 1944 Pel* pPred = piPred; 1945 Pel* pReco = piReco; 1946 Pel* pRecIPred = piRecIPred; 1947 1948 for( UInt uiY = 0; uiY < uiHeight; uiY++ ) 1949 { 1950 for( UInt uiX = 0; uiX < uiWidth; uiX++ ) 1951 { 1952 UChar ucSegment = pMask?(UChar)pMask[uiX]:0; 1953 assert( ucSegment < uiNumSegments ); 1954 1955 Pel pResiDC = apDCResiValues[ucSegment]; 1956 1957 pReco [ uiX ] = ClipY( pPred[ uiX ] + pResiDC ); 1958 pRecIPred[ uiX ] = pReco[ uiX ]; 1959 } 1960 pPred += uiStride; 1961 pReco += uiStride; 1962 pRecIPred += uiRecIPredStride; 1963 pMask += uiMaskStride; 1964 } 1965 1966 // clear UV 1967 UInt uiStrideC = pcPredYuv->getCStride(); 1968 Pel *pRecCb = pcPredYuv->getCbAddr(); 1969 Pel *pRecCr = pcPredYuv->getCrAddr(); 1970 1971 for (Int y=0; y<uiHeight/2; y++) 1972 { 1973 for (Int x=0; x<uiWidth/2; x++) 1974 { 1975 pRecCb[x] = 128; 1976 pRecCr[x] = 128; 1977 } 1978 1979 pRecCb += uiStrideC; 1980 pRecCr += uiStrideC; 1981 } 1982 1983 //===== determine distortion ===== 1984 #if H_3D_VSO 1985 if ( m_pcRdCost->getUseVSO() ) 1986 ruiDist = m_pcRdCost->getDistPartVSO ( pcCU, uiAbsPartIdx, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, false ); 1987 else 1988 #endif 1989 ruiDist = m_pcRdCost->getDistPart(g_bitDepthY, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight ); 1990 1991 //===== determine rate and r-d cost ===== 1992 m_pcEntropyCoder->resetBits(); 1993 1994 // encode reduced intra header 1995 m_pcEntropyCoder->encodePredMode( pcCU, 0, true ); 1996 1997 // encode pred direction + DC residual data 1998 m_pcEntropyCoder->encodePredInfo( pcCU, 0, true ); 1999 UInt uiBits = m_pcEntropyCoder->getNumberOfWrittenBits(); 2000 2001 #if H_3D_VSO 2002 if ( m_pcRdCost->getUseLambdaScaleVSO()) 2003 dRDCost = m_pcRdCost->calcRdCostVSO( uiBits, ruiDist ); 2004 else 2005 #endif 2006 dRDCost = m_pcRdCost->calcRdCost( uiBits, ruiDist ); 2007 } 2008 #endif 1798 2009 1799 2010 Void … … 2632 2843 } 2633 2844 2845 #if H_3D_DIM 2846 //===== determine set of depth intra modes to be tested ===== 2847 if( m_pcEncCfg->getIsDepth() && uiWidth >= DIM_MIN_SIZE && uiWidth <= DIM_MAX_SIZE && uiWidth == uiHeight ) 2848 { 2849 #if H_3D_DIM_DMM 2850 if( m_pcEncCfg->getUseDMM() ) 2851 { 2852 for( UInt dmmType = 0; dmmType < DMM_NUM_TYPE; dmmType++ ) 2853 { 2854 UInt uiTabIdx = 0; 2855 TComWedgelet* biSegmentation = NULL; 2856 Pel deltaDC1 = 0; Pel deltaDC2 = 0; 2857 switch( dmmType ) 2858 { 2859 case( DMM1_IDX ): 2860 { 2861 xSearchDmm1Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx ); 2862 pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dmmType, uiPartOffset, uiDepth + uiInitTrDepth ); 2863 biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]); 2864 } break; 2865 case( DMM2_IDX ): 2866 { 2867 if( uiWidth > 4 ) 2868 { 2869 Int dmm2DeltaEnd = 0; 2870 xSearchDmm2Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx, dmm2DeltaEnd ); 2871 pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dmmType, uiPartOffset, uiDepth + uiInitTrDepth ); 2872 pcCU->setDmm2DeltaEndSubParts( dmm2DeltaEnd, uiPartOffset, uiDepth + uiInitTrDepth ); 2873 biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]); 2874 } 2875 } break; 2876 case( DMM3_IDX ): 2877 { 2878 UInt uiIntraTabIdx = 0; 2879 xSearchDmm3Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx, uiIntraTabIdx ); 2880 pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dmmType, uiPartOffset, uiDepth + uiInitTrDepth ); 2881 pcCU->setDmm3IntraTabIdxSubParts( uiIntraTabIdx, uiPartOffset, uiDepth + uiInitTrDepth ); 2882 biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]); 2883 } break; 2884 case( DMM4_IDX ): 2885 { 2886 if( uiWidth > 4 ) 2887 { 2888 biSegmentation = new TComWedgelet( uiWidth, uiHeight ); 2889 xPredContourFromTex( pcCU, uiPartOffset, uiWidth, uiHeight, biSegmentation ); 2890 } 2891 } break; 2892 default: assert(0); 2893 } 2894 2895 if( biSegmentation ) 2896 { 2897 xSearchDmmDeltaDCs( pcCU, uiPartOffset, piOrg, piPred, uiStride, biSegmentation->getPattern(), biSegmentation->getStride(), uiWidth, uiHeight, deltaDC1, deltaDC2 ); 2898 pcCU->setDimDeltaDC( dmmType, 0, uiPartOffset, deltaDC1 ); 2899 pcCU->setDimDeltaDC( dmmType, 1, uiPartOffset, deltaDC2 ); 2900 2901 uiRdModeList[ numModesForFullRD++ ] = (2*dmmType +DIM_OFFSET); 2902 uiRdModeList[ numModesForFullRD++ ] = (2*dmmType+1+DIM_OFFSET); 2903 2904 if( DMM4_IDX == dmmType ) { biSegmentation->destroy(); delete biSegmentation; } 2905 } 2906 } 2907 } 2908 #endif 2909 #if H_3D_DIM_RBC 2910 if( m_pcEncCfg->getUseRBC() ) 2911 { 2912 if( xSearchRbcEdge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight ) ) 2913 { 2914 Pel deltaDC1 = 0; Pel deltaDC2 = 0; 2915 xSearchRbcDeltaDCs( pcCU, uiPartOffset, piOrg, piPred, uiStride, pcCU->getEdgePartition( uiPartOffset ), uiWidth, uiWidth, uiHeight, deltaDC1, deltaDC2 ); 2916 pcCU->setDimDeltaDC( RBC_IDX, 0, uiPartOffset, deltaDC1 ); 2917 pcCU->setDimDeltaDC( RBC_IDX, 1, uiPartOffset, deltaDC2 ); 2918 2919 uiRdModeList[ numModesForFullRD++ ] = (2*RBC_IDX +DIM_OFFSET); 2920 uiRdModeList[ numModesForFullRD++ ] = (2*RBC_IDX+1+DIM_OFFSET); 2921 } 2922 } 2923 #endif 2924 } 2925 #endif 2926 2634 2927 //===== check modes (using r-d costs) ===== 2635 2928 #if HHI_RQT_INTRA_SPEEDUP_MOD … … 2646 2939 UInt uiBestPUDistC = 0; 2647 2940 Double dBestPUCost = MAX_DOUBLE; 2941 #if H_3D_DIM_SDC 2942 Bool bBestUseSDC = false; 2943 Pel apBestDCOffsets[2] = {0,0}; 2944 #endif 2648 2945 for( UInt uiMode = 0; uiMode < numModesForFullRD; uiMode++ ) 2649 2946 { … … 2653 2950 pcCU->setLumaIntraDirSubParts ( uiOrgMode, uiPartOffset, uiDepth + uiInitTrDepth ); 2654 2951 2952 #if H_3D_DIM_SDC 2953 Bool bTestSDC = ( m_pcEncCfg->getUseSDC() && pcCU->getSDCAvailable(uiPartOffset) ); 2954 2955 for( UInt uiSDC=0; uiSDC<=(bTestSDC?1:0); uiSDC++ ) 2956 { 2957 pcCU->setSDCFlagSubParts( (uiSDC != 0), uiPartOffset, uiDepth + uiInitTrDepth ); 2958 #endif 2959 2960 #if H_3D_DIM_ENC || H_3D_DIM_SDC 2961 Bool bTestZeroResi = false; 2962 #if H_3D_DIM_ENC 2963 bTestZeroResi |= pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->isIRAP(); 2964 #endif 2965 #if H_3D_DIM_SDC 2966 bTestZeroResi |= pcCU->getSDCFlag(uiPartOffset); 2967 #endif 2968 #endif 2969 2970 #if H_3D_DIM_ENC || H_3D_DIM_SDC 2971 for( UInt testZeroResi = 0; testZeroResi <= (bTestZeroResi ? 1 : 0) ; testZeroResi++ ) 2972 { 2973 #endif 2655 2974 // set context models 2656 2975 if( m_bUseSBACRD ) … … 2673 2992 } 2674 2993 #endif 2994 #if H_3D_DIM_SDC 2995 if( pcCU->getSDCFlag(uiPartOffset) ) 2996 { 2997 pcCU->setTrIdxSubParts(0, uiPartOffset, uiDepth + uiInitTrDepth); 2998 pcCU->setCbfSubParts(1, 1, 1, uiPartOffset, uiDepth + uiInitTrDepth); 2999 3000 // start encoding with SDC 3001 xIntraCodingSDC(pcCU, uiPartOffset, pcOrgYuv, pcPredYuv, uiPUDistY, dPUCost, (testZeroResi!=0)); 3002 } 3003 else 3004 { 3005 #endif 2675 3006 #if HHI_RQT_INTRA_SPEEDUP 3007 #if H_3D_DIM_ENC 3008 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost, (testZeroResi != 0) ); 3009 #else 2676 3010 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost ); 3011 #endif 3012 #else 3013 #if H_3D_DIM_ENC 3014 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost, (testZeroResi != 0) ); 2677 3015 #else 2678 3016 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost ); 3017 #endif 3018 #endif 3019 #if H_3D_DIM_SDC 3020 } 2679 3021 #endif 2680 3022 … … 2690 3032 uiBestPUDistC = uiPUDistC; 2691 3033 dBestPUCost = dPUCost; 3034 3035 #if H_3D_DIM_SDC 3036 if( pcCU->getSDCFlag(uiPartOffset) ) 3037 { 3038 bBestUseSDC = true; 3039 3040 // copy reconstruction 3041 pcPredYuv->copyPartToPartYuv(pcRecoYuv, uiPartOffset, uiWidth, uiHeight); 3042 3043 // copy DC values 3044 apBestDCOffsets[0] = pcCU->getSDCSegmentDCOffset(0, uiPartOffset); 3045 apBestDCOffsets[1] = pcCU->getSDCSegmentDCOffset(1, uiPartOffset); 3046 } 3047 else 3048 { 3049 bBestUseSDC = false; 3050 #endif 3051 xSetIntraResultQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcRecoYuv ); 3052 3053 UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth(0) + uiInitTrDepth ) << 1 ); 3054 ::memcpy( m_puhQTTempTrIdx, pcCU->getTransformIdx() + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3055 ::memcpy( m_puhQTTempCbf[0], pcCU->getCbf( TEXT_LUMA ) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3056 ::memcpy( m_puhQTTempCbf[1], pcCU->getCbf( TEXT_CHROMA_U ) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3057 ::memcpy( m_puhQTTempCbf[2], pcCU->getCbf( TEXT_CHROMA_V ) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3058 ::memcpy( m_puhQTTempTransformSkipFlag[0], pcCU->getTransformSkip(TEXT_LUMA) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3059 ::memcpy( m_puhQTTempTransformSkipFlag[1], pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3060 ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3061 #if H_3D_DIM_SDC 3062 } 3063 #endif 3064 } 3065 #if HHI_RQT_INTRA_SPEEDUP_MOD 3066 else if( dPUCost < dSecondBestPUCost ) 3067 { 3068 uiSecondBestMode = uiOrgMode; 3069 dSecondBestPUCost = dPUCost; 3070 } 3071 #endif 3072 #if H_3D_DIM_ENC || H_3D_DIM_SDC 3073 } 3074 #endif 3075 #if H_3D_DIM_SDC 3076 } // SDC loop 3077 #endif 3078 } // Mode loop 3079 3080 #if HHI_RQT_INTRA_SPEEDUP 3081 #if HHI_RQT_INTRA_SPEEDUP_MOD 3082 for( UInt ui =0; ui < 2; ++ui ) 3083 #endif 3084 { 3085 #if HHI_RQT_INTRA_SPEEDUP_MOD 3086 UInt uiOrgMode = ui ? uiSecondBestMode : uiBestPUMode; 3087 if( uiOrgMode == MAX_UINT ) 3088 { 3089 break; 3090 } 3091 #else 3092 UInt uiOrgMode = uiBestPUMode; 3093 #endif 3094 3095 pcCU->setLumaIntraDirSubParts ( uiOrgMode, uiPartOffset, uiDepth + uiInitTrDepth ); 3096 #if H_3D_DIM_SDC 3097 pcCU->setSDCFlagSubParts(false, uiPartOffset, uiDepth + uiInitTrDepth); 3098 #endif 3099 3100 // set context models 3101 if( m_bUseSBACRD ) 3102 { 3103 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); 3104 } 3105 3106 // determine residual for partition 3107 #if H_3D_VSO 3108 Dist uiPUDistY = 0; 3109 #else 3110 UInt uiPUDistY = 0; 3111 #endif 3112 UInt uiPUDistC = 0; 3113 Double dPUCost = 0.0; 3114 3115 #if H_3D_VSO // M37 3116 // reset Model 3117 if( m_pcRdCost->getUseRenModel() ) 3118 { 3119 m_pcRdCost->setRenModelData( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight ); 3120 } 3121 #endif 3122 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, false, dPUCost ); 3123 3124 // check r-d cost 3125 if( dPUCost < dBestPUCost ) 3126 { 3127 uiBestPUMode = uiOrgMode; 3128 uiBestPUDistY = uiPUDistY; 3129 uiBestPUDistC = uiPUDistC; 3130 dBestPUCost = dPUCost; 3131 #if H_3D_DIM_SDC 3132 bBestUseSDC = false; 3133 #endif 2692 3134 2693 3135 xSetIntraResultQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcRecoYuv ); … … 2702 3144 ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 2703 3145 } 2704 #if HHI_RQT_INTRA_SPEEDUP_MOD2705 else if( dPUCost < dSecondBestPUCost )2706 {2707 uiSecondBestMode = uiOrgMode;2708 dSecondBestPUCost = dPUCost;2709 }2710 #endif2711 } // Mode loop2712 2713 #if HHI_RQT_INTRA_SPEEDUP2714 #if HHI_RQT_INTRA_SPEEDUP_MOD2715 for( UInt ui =0; ui < 2; ++ui )2716 #endif2717 {2718 #if HHI_RQT_INTRA_SPEEDUP_MOD2719 UInt uiOrgMode = ui ? uiSecondBestMode : uiBestPUMode;2720 if( uiOrgMode == MAX_UINT )2721 {2722 break;2723 }2724 #else2725 UInt uiOrgMode = uiBestPUMode;2726 #endif2727 2728 pcCU->setLumaIntraDirSubParts ( uiOrgMode, uiPartOffset, uiDepth + uiInitTrDepth );2729 2730 // set context models2731 if( m_bUseSBACRD )2732 {2733 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );2734 }2735 2736 // determine residual for partition2737 #if H_3D_VSO2738 Dist uiPUDistY = 0;2739 #else2740 UInt uiPUDistY = 0;2741 #endif2742 UInt uiPUDistC = 0;2743 Double dPUCost = 0.0;2744 2745 #if H_3D_VSO // M372746 // reset Model2747 if( m_pcRdCost->getUseRenModel() )2748 {2749 m_pcRdCost->setRenModelData( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight );2750 }2751 #endif2752 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, false, dPUCost );2753 2754 // check r-d cost2755 if( dPUCost < dBestPUCost )2756 {2757 uiBestPUMode = uiOrgMode;2758 uiBestPUDistY = uiPUDistY;2759 uiBestPUDistC = uiPUDistC;2760 dBestPUCost = dPUCost;2761 2762 xSetIntraResultQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcRecoYuv );2763 2764 UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth(0) + uiInitTrDepth ) << 1 );2765 ::memcpy( m_puhQTTempTrIdx, pcCU->getTransformIdx() + uiPartOffset, uiQPartNum * sizeof( UChar ) );2766 ::memcpy( m_puhQTTempCbf[0], pcCU->getCbf( TEXT_LUMA ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );2767 ::memcpy( m_puhQTTempCbf[1], pcCU->getCbf( TEXT_CHROMA_U ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );2768 ::memcpy( m_puhQTTempCbf[2], pcCU->getCbf( TEXT_CHROMA_V ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );2769 ::memcpy( m_puhQTTempTransformSkipFlag[0], pcCU->getTransformSkip(TEXT_LUMA) + uiPartOffset, uiQPartNum * sizeof( UChar ) );2770 ::memcpy( m_puhQTTempTransformSkipFlag[1], pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, uiQPartNum * sizeof( UChar ) );2771 ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, uiQPartNum * sizeof( UChar ) );2772 }2773 3146 } // Mode loop 2774 3147 #endif … … 2777 3150 uiOverallDistY += uiBestPUDistY; 2778 3151 uiOverallDistC += uiBestPUDistC; 3152 3153 #if H_3D_DIM_SDC 3154 if( bBestUseSDC ) 3155 { 3156 pcCU->setTrIdxSubParts(0, uiPartOffset, uiDepth + uiInitTrDepth); 3157 pcCU->setCbfSubParts(1, 1, 1, uiPartOffset, uiDepth + uiInitTrDepth); 3158 3159 //=== copy best DC segment values back to CU ==== 3160 pcCU->setSDCSegmentDCOffset(apBestDCOffsets[0], 0, uiPartOffset); 3161 pcCU->setSDCSegmentDCOffset(apBestDCOffsets[1], 1, uiPartOffset); 3162 } 3163 else 3164 { 3165 #endif 2779 3166 2780 3167 //--- update transform index and cbf --- … … 2787 3174 ::memcpy( pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, m_puhQTTempTransformSkipFlag[1], uiQPartNum * sizeof( UChar ) ); 2788 3175 ::memcpy( pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, m_puhQTTempTransformSkipFlag[2], uiQPartNum * sizeof( UChar ) ); 3176 #if H_3D_DIM_SDC 3177 } 3178 #endif 2789 3179 //--- set reconstruction for next intra prediction blocks --- 2790 3180 if( uiPU != uiNumPU - 1 ) … … 2854 3244 //=== update PU data ==== 2855 3245 pcCU->setLumaIntraDirSubParts ( uiBestPUMode, uiPartOffset, uiDepth + uiInitTrDepth ); 3246 #if H_3D_DIM_SDC 3247 pcCU->setSDCFlagSubParts ( bBestUseSDC, uiPartOffset, uiDepth + uiInitTrDepth ); 3248 #endif 2856 3249 pcCU->copyToPic ( uiDepth, uiPU, uiInitTrDepth ); 2857 3250 } // PU loop … … 6194 6587 // Reload only contexts required for coding intra mode information 6195 6588 m_pcRDGoOnSbacCoder->loadIntraDirModeLuma( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); 6589 #if H_3D_DIM 6590 m_pcRDGoOnSbacCoder->loadIntraDepthMode( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); 6591 #endif 6196 6592 } 6197 6593 … … 6522 6918 } 6523 6919 6920 // ------------------------------------------------------------------------------------------------------------------- 6921 // Depth intra search 6922 // ------------------------------------------------------------------------------------------------------------------- 6923 #if H_3D_DIM 6924 Void TEncSearch::xCalcBiSegDCs( Pel* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& valDC1, Pel& valDC2 ) 6925 { 6926 valDC1 = ( 1<<( g_bitDepthY - 1) ); 6927 valDC2 = ( 1<<( g_bitDepthY - 1) ); 6928 6929 UInt uiDC1 = 0; 6930 UInt uiDC2 = 0; 6931 UInt uiNumPixDC1 = 0, uiNumPixDC2 = 0; 6932 if( srcStride == patternStride ) 6933 { 6934 for( UInt k = 0; k < (patternStride * patternStride); k++ ) 6935 { 6936 if( true == biSegPattern[k] ) 6937 { 6938 uiDC2 += ptrSrc[k]; 6939 uiNumPixDC2++; 6940 } 6941 else 6942 { 6943 uiDC1 += ptrSrc[k]; 6944 uiNumPixDC1++; 6945 } 6946 } 6947 } 6948 else 6949 { 6950 Pel* piTemp = ptrSrc; 6951 for( UInt uiY = 0; uiY < patternStride; uiY++ ) 6952 { 6953 for( UInt uiX = 0; uiX < patternStride; uiX++ ) 6954 { 6955 if( true == biSegPattern[uiX] ) 6956 { 6957 uiDC2 += piTemp[uiX]; 6958 uiNumPixDC2++; 6959 } 6960 else 6961 { 6962 uiDC1 += piTemp[uiX]; 6963 uiNumPixDC1++; 6964 } 6965 } 6966 piTemp += srcStride; 6967 biSegPattern += patternStride; 6968 } 6969 } 6970 6971 if( uiNumPixDC1 > 0 ) { valDC1 = uiDC1 / uiNumPixDC1; } 6972 if( uiNumPixDC2 > 0 ) { valDC2 = uiDC2 / uiNumPixDC2; } 6973 } 6974 6975 #if H_3D_DIM_DMM 6976 Void TEncSearch::xSearchDmmDeltaDCs( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piOrig, Pel* piPredic, UInt uiStride, Bool* biSegPattern, Int patternStride, UInt uiWidth, UInt uiHeight, Pel& rDeltaDC1, Pel& rDeltaDC2 ) 6977 { 6978 assert( biSegPattern ); 6979 Pel origDC1 = 0; Pel origDC2 = 0; 6980 xCalcBiSegDCs ( piOrig, uiStride, biSegPattern, patternStride, origDC1, origDC2 ); 6981 xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, origDC1, origDC2 ); 6982 6983 Int* piMask = pcCU->getPattern()->getAdiOrgBuf( uiWidth, uiHeight, m_piYuvExt ); // no filtering for DMM 6984 Int maskStride = 2*uiWidth + 1; 6985 Int* ptrSrc = piMask+maskStride+1; 6986 Pel predDC1 = 0; Pel predDC2 = 0; 6987 xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 ); 6988 6989 rDeltaDC1 = origDC1 - predDC1; 6990 rDeltaDC2 = origDC2 - predDC2; 6991 6992 #if H_3D_VSO 6993 if( m_pcRdCost->getUseVSO() ) 6994 { 6995 Pel fullDeltaDC1 = rDeltaDC1; 6996 Pel fullDeltaDC2 = rDeltaDC2; 6997 6998 Dist uiBestDist = RDO_DIST_MAX; 6999 UInt uiBestQStepDC1 = 0; 7000 UInt uiBestQStepDC2 = 0; 7001 7002 UInt uiDeltaDC1Max = abs(fullDeltaDC1); 7003 UInt uiDeltaDC2Max = abs(fullDeltaDC2); 7004 7005 //VSO Level delta DC check range extension 7006 uiDeltaDC1Max += (uiDeltaDC1Max>>1); 7007 uiDeltaDC2Max += (uiDeltaDC2Max>>1); 7008 7009 // limit search range to [0, IBDI_MAX] 7010 if( fullDeltaDC1 < 0 && uiDeltaDC1Max > abs(predDC1) ) { uiDeltaDC1Max = abs(predDC1); } 7011 if( fullDeltaDC1 >= 0 && uiDeltaDC1Max > ((1 << g_bitDepthY)-1) - abs(predDC1) ) { uiDeltaDC1Max = ((1 << g_bitDepthY)-1) - abs(predDC1); } 7012 7013 if( fullDeltaDC2 < 0 && uiDeltaDC2Max > abs(predDC2) ) { uiDeltaDC2Max = abs(predDC2); } 7014 if( fullDeltaDC2 >= 0 && uiDeltaDC2Max > ((1 << g_bitDepthY)-1) - abs(predDC2) ) { uiDeltaDC2Max = ((1 << g_bitDepthY)-1) - abs(predDC2); } 7015 7016 // init dist with original segment DCs 7017 xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, origDC1, origDC2 ); 7018 7019 Dist uiOrgDist = RDO_DIST_MAX; 7020 if( m_pcRdCost->getUseEstimatedVSD() ) 7021 { 7022 uiOrgDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false ); 7023 } 7024 else 7025 { 7026 uiOrgDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false ); 7027 } 7028 7029 uiBestDist = uiOrgDist; 7030 uiBestQStepDC1 = abs(fullDeltaDC1); 7031 uiBestQStepDC2 = abs(fullDeltaDC2); 7032 7033 // coarse search with step size 4 7034 for( UInt uiQStepDC1 = 0; uiQStepDC1 < uiDeltaDC1Max; uiQStepDC1 += 4 ) 7035 { 7036 Pel testDC1 = ClipY( predDC1 + ((Int)(uiQStepDC1) * (( fullDeltaDC1 < 0 ) ? -1 : 1)) ); 7037 for( UInt uiQStepDC2 = 0; uiQStepDC2 < uiDeltaDC2Max; uiQStepDC2 += 4 ) 7038 { 7039 Pel testDC2 = ClipY( predDC2 + ((Int)(uiQStepDC2) * (( fullDeltaDC2 < 0 ) ? -1 : 1)) ); 7040 7041 xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, testDC1, testDC2 ); 7042 7043 Dist uiAct4Dist = RDO_DIST_MAX; 7044 if( m_pcRdCost->getUseEstimatedVSD() ) 7045 { 7046 uiAct4Dist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false ); 7047 } 7048 else 7049 { 7050 uiAct4Dist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false ); 7051 } 7052 7053 if( uiAct4Dist < uiBestDist || uiBestDist == RDO_DIST_MAX ) 7054 { 7055 uiBestDist = uiAct4Dist; 7056 uiBestQStepDC1 = uiQStepDC1; 7057 uiBestQStepDC2 = uiQStepDC2; 7058 } 7059 } 7060 } 7061 7062 // refinement +-3 7063 for( UInt uiQStepDC1 = (UInt)max(0, ((Int)uiBestQStepDC1-3)); uiQStepDC1 <= (uiBestQStepDC1+3); uiQStepDC1++ ) 7064 { 7065 Pel testDC1 = ClipY( predDC1 + ((Int)(uiQStepDC1) * (( fullDeltaDC1 < 0 ) ? -1 : 1)) ); 7066 for( UInt uiQStepDC2 = (UInt)max(0, ((Int)uiBestQStepDC2-3)); uiQStepDC2 <= (uiBestQStepDC2+3); uiQStepDC2++ ) 7067 { 7068 Pel testDC2 = ClipY( predDC2 + ((Int)(uiQStepDC2) * (( fullDeltaDC2 < 0 ) ? -1 : 1)) ); 7069 7070 xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, testDC1, testDC2 ); 7071 7072 Dist uiActDist = RDO_DIST_MAX; 7073 if( m_pcRdCost->getUseEstimatedVSD() ) 7074 { 7075 uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false ); 7076 } 7077 else 7078 { 7079 uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false ); 7080 } 7081 7082 if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX ) 7083 { 7084 uiBestDist = uiActDist; 7085 uiBestQStepDC1 = uiQStepDC1; 7086 uiBestQStepDC2 = uiQStepDC2; 7087 } 7088 } 7089 } 7090 rDeltaDC1 = (Int)(uiBestQStepDC1) * (Int)(( fullDeltaDC1 < 0 ) ? -1 : 1); 7091 rDeltaDC2 = (Int)(uiBestQStepDC2) * (Int)(( fullDeltaDC2 < 0 ) ? -1 : 1); 7092 } 7093 #endif 7094 7095 #if H_3D_DIM_DLT 7096 rDeltaDC1 = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), ClipY(predDC1 + rDeltaDC1) ) - pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ); 7097 rDeltaDC2 = pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), ClipY(predDC2 + rDeltaDC2) ) - pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ); 7098 #endif 7099 } 7100 7101 Void TEncSearch::xSearchDmm1Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx ) 7102 { 7103 ruiTabIdx = 0; 7104 7105 // local pred buffer 7106 TComYuv cPredYuv; 7107 cPredYuv.create( uiWidth, uiHeight ); 7108 cPredYuv.clear(); 7109 7110 UInt uiPredStride = cPredYuv.getStride(); 7111 Pel* piPred = cPredYuv.getLumaAddr(); 7112 7113 Pel refDC1 = 0; Pel refDC2 = 0; 7114 WedgeList* pacWedgeList = &g_dmmWedgeLists [(g_aucConvertToBit[uiWidth])]; 7115 WedgeNodeList* pacWedgeNodeList = &g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])]; 7116 7117 // coarse wedge search 7118 Dist uiBestDist = RDO_DIST_MAX; 7119 UInt uiBestNodeId = 0; 7120 for( UInt uiNodeId = 0; uiNodeId < pacWedgeNodeList->size(); uiNodeId++ ) 7121 { 7122 TComWedgelet* pcWedgelet = &(pacWedgeList->at(pacWedgeNodeList->at(uiNodeId).getPatternIdx())); 7123 xCalcBiSegDCs ( piRef, uiRefStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 ); 7124 xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 ); 7125 7126 Dist uiActDist = RDO_DIST_MAX; 7127 #if H_3D_VSO 7128 if( m_pcRdCost->getUseVSO() ) 7129 { 7130 if( m_pcRdCost->getUseEstimatedVSD() ) 7131 { 7132 uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false ); 7133 } 7134 else 7135 { 7136 uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false ); 7137 } 7138 } 7139 else 7140 #endif 7141 { 7142 uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD ); 7143 } 7144 7145 if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX ) 7146 { 7147 uiBestDist = uiActDist; 7148 uiBestNodeId = uiNodeId; 7149 } 7150 } 7151 7152 // refinement 7153 Dist uiBestDistRef = uiBestDist; 7154 UInt uiBestTabIdxRef = pacWedgeNodeList->at(uiBestNodeId).getPatternIdx(); 7155 for( UInt uiRefId = 0; uiRefId < DMM_NUM_WEDGE_REFINES; uiRefId++ ) 7156 { 7157 if( pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId ) != DMM_NO_WEDGEINDEX ) 7158 { 7159 TComWedgelet* pcWedgelet = &(pacWedgeList->at(pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId ))); 7160 xCalcBiSegDCs ( piRef, uiRefStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 ); 7161 xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 ); 7162 7163 Dist uiActDist = RDO_DIST_MAX; 7164 #if H_3D_VSO 7165 if( m_pcRdCost->getUseVSO() ) 7166 { 7167 if( m_pcRdCost->getUseEstimatedVSD() ) //PM: use VSO instead of VSD here? 7168 { 7169 uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false ); 7170 } 7171 else 7172 { 7173 uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false ); 7174 } 7175 } 7176 else 7177 #endif 7178 { 7179 uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD ); 7180 } 7181 7182 if( uiActDist < uiBestDistRef || uiBestDistRef == RDO_DIST_MAX ) 7183 { 7184 uiBestDistRef = uiActDist; 7185 uiBestTabIdxRef = pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId ); 7186 } 7187 } 7188 } 7189 7190 ruiTabIdx = uiBestTabIdxRef; 7191 7192 cPredYuv.destroy(); 7193 return; 7194 } 7195 7196 Void TEncSearch::xSearchDmm2Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, Int& riWedgeDeltaEnd ) 7197 { 7198 ruiTabIdx = 0; 7199 riWedgeDeltaEnd = 0; 7200 7201 // local pred buffer 7202 TComYuv cPredYuv; 7203 cPredYuv.create( uiWidth, uiHeight ); 7204 cPredYuv.clear(); 7205 7206 UInt uiPredStride = cPredYuv.getStride(); 7207 Pel* piPred = cPredYuv.getLumaAddr(); 7208 7209 7210 // regular wedge search 7211 Dist uiBestDist = RDO_DIST_MAX; 7212 UInt uiBestTabIdx = 0; 7213 Int iBestDeltaEnd = 0; 7214 7215 UInt uiIdx = 0; 7216 Pel refDC1 = 0; Pel refDC2 = 0; 7217 for( Int iTestDeltaEnd = -DMM2_DELTAEND_MAX; iTestDeltaEnd <= DMM2_DELTAEND_MAX; iTestDeltaEnd++ ) 7218 { 7219 uiIdx = xPredWedgeFromIntra( pcCU, uiAbsPtIdx, uiWidth, uiHeight, iTestDeltaEnd ); 7220 TComWedgelet* pcWedgelet = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiIdx]); 7221 xCalcBiSegDCs ( piRef, uiRefStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 ); 7222 xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 ); 7223 7224 Dist uiActDist = RDO_DIST_MAX; 7225 #if H_3D_VSO 7226 if( m_pcRdCost->getUseVSO() ) 7227 { 7228 if( m_pcRdCost->getUseEstimatedVSD() ) 7229 { 7230 uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false ); 7231 } 7232 else 7233 { 7234 uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false ); 7235 } 7236 } 7237 else 7238 #endif 7239 { 7240 uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD ); 7241 } 7242 7243 if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX ) 7244 { 7245 uiBestDist = uiActDist; 7246 uiBestTabIdx = uiIdx; 7247 iBestDeltaEnd = iTestDeltaEnd; 7248 } 7249 else if( uiIdx == uiBestTabIdx && abs(iTestDeltaEnd) < abs(iBestDeltaEnd) ) 7250 { 7251 iBestDeltaEnd = iTestDeltaEnd; 7252 } 7253 } 7254 7255 ruiTabIdx = uiBestTabIdx; 7256 riWedgeDeltaEnd = iBestDeltaEnd; 7257 7258 cPredYuv.destroy(); 7259 return; 7260 } 7261 7262 Void TEncSearch::xSearchDmm3Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx ) 7263 { 7264 ruiTabIdx = 0; 7265 ruiIntraTabIdx = 0; 7266 7267 // local pred buffer 7268 TComYuv cPredYuv; 7269 cPredYuv.create( uiWidth, uiHeight ); 7270 cPredYuv.clear(); 7271 Pel* piPred = cPredYuv.getLumaAddr(); 7272 UInt uiPredStride = cPredYuv.getStride(); 7273 7274 // wedge search 7275 UInt uiBestDist = MAX_UINT; 7276 WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])]; 7277 Pel refDC1 = 0; Pel refDC2 = 0; 7278 7279 TComPic* pcPicTex = pcCU->getSlice()->getPicLists()->getPic( pcCU->getSlice()->getViewIndex(), false, pcCU->getSlice()->getPOC() ); 7280 assert( pcPicTex != NULL ); 7281 TComDataCU* pcColTexCU = pcPicTex->getCU(pcCU->getAddr()); 7282 UInt uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPtIdx; 7283 Int uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255; 7284 7285 std::vector< std::vector<UInt> > pauiWdgLstSz = g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]]; 7286 if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 ) 7287 { 7288 std::vector<UInt>* pauiWdgLst = &pauiWdgLstSz[uiColTexIntraDir-2]; 7289 for( UInt uiIdxW = 0; uiIdxW < pauiWdgLst->size(); uiIdxW++ ) 7290 { 7291 UInt uiIdx = pauiWdgLst->at(uiIdxW); 7292 TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiIdx)); 7293 xCalcBiSegDCs ( piRef, uiRefStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 ); 7294 xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 ); 7295 7296 UInt uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD ); 7297 if( uiActDist < uiBestDist || uiBestDist == MAX_UINT ) 7298 { 7299 uiBestDist = uiActDist; 7300 ruiTabIdx = uiIdx; 7301 ruiIntraTabIdx = uiIdxW; 7302 } 7303 } 7304 } 7305 else 7306 { 7307 WedgeNodeList* pacWedgeNodeList = &g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])]; 7308 UInt uiBestNodeDist = MAX_UINT; 7309 UInt uiBestNodeId = 0; 7310 for( UInt uiNodeId = 0; uiNodeId < pacWedgeNodeList->size(); uiNodeId++ ) 7311 { 7312 TComWedgelet* pcWedgelet = &(pacWedgeList->at(pacWedgeNodeList->at(uiNodeId).getPatternIdx())); 7313 xCalcBiSegDCs ( piRef, uiRefStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 ); 7314 xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 ); 7315 7316 UInt uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD ); 7317 if( uiActDist < uiBestNodeDist || uiBestNodeDist == MAX_UINT ) 7318 { 7319 uiBestNodeDist = uiActDist; 7320 uiBestNodeId = uiNodeId; 7321 ruiIntraTabIdx = uiNodeId; 7322 } 7323 } 7324 ruiTabIdx = pacWedgeNodeList->at(uiBestNodeId).getPatternIdx(); 7325 } 7326 7327 cPredYuv.destroy(); 7328 } 7329 #endif 7330 #if H_3D_DIM_RBC 7331 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 ) 7332 { 7333 assert( biSegPattern ); 7334 Pel origDC1 = 0; Pel origDC2 = 0; 7335 xCalcBiSegDCs ( piOrig, uiStride, biSegPattern, patternStride, origDC1, origDC2 ); 7336 xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, origDC1, origDC2 ); 7337 7338 Int* piMask = pcCU->getPattern()->getAdiOrgBuf( uiWidth, uiHeight, m_piYuvExt ); // no filtering for DMM 7339 Int maskStride = 2*uiWidth + 1; 7340 Int* ptrSrc = piMask+maskStride+1; 7341 Pel predDC1 = 0; Pel predDC2 = 0; 7342 xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 ); 7343 7344 rDeltaDC1 = origDC1 - predDC1; 7345 rDeltaDC2 = origDC2 - predDC2; 7346 7347 #if H_3D_VSO 7348 if( m_pcRdCost->getUseVSO() ) 7349 { 7350 Pel fullDeltaDC1 = rDeltaDC1; 7351 Pel fullDeltaDC2 = rDeltaDC2; 7352 7353 xDeltaDCQuantScaleDown( pcCU, fullDeltaDC1 ); 7354 xDeltaDCQuantScaleDown( pcCU, fullDeltaDC2 ); 7355 7356 Dist uiBestDist = RDO_DIST_MAX; 7357 UInt uiBestQStepDC1 = 0; 7358 UInt uiBestQStepDC2 = 0; 7359 7360 UInt uiDeltaDC1Max = abs(fullDeltaDC1); 7361 UInt uiDeltaDC2Max = abs(fullDeltaDC2); 7362 7363 //VSO Level delta DC check range extension 7364 uiDeltaDC1Max += (uiDeltaDC1Max>>1); 7365 uiDeltaDC2Max += (uiDeltaDC2Max>>1); 7366 7367 for( UInt uiQStepDC1 = 1; uiQStepDC1 <= uiDeltaDC1Max; uiQStepDC1++ ) 7368 { 7369 Pel iLevelDeltaDC1 = (Pel)(uiQStepDC1) * (Pel)(( fullDeltaDC1 < 0 ) ? -1 : 1); 7370 xDeltaDCQuantScaleUp( pcCU, iLevelDeltaDC1 ); 7371 Pel testDC1 = ClipY( predDC1 + iLevelDeltaDC1 ); 7372 7373 for( UInt uiQStepDC2 = 1; uiQStepDC2 <= uiDeltaDC2Max; uiQStepDC2++ ) 7374 { 7375 Pel iLevelDeltaDC2 = (Pel)(uiQStepDC2) * (Pel)(( fullDeltaDC2 < 0 ) ? -1 : 1); 7376 xDeltaDCQuantScaleUp( pcCU, iLevelDeltaDC2 ); 7377 Pel testDC2 = ClipY( predDC2 + iLevelDeltaDC2 ); 7378 7379 xAssignBiSegDCs( piPredic, uiStride, biSegPattern, patternStride, testDC1, testDC2 ); 7380 7381 Dist uiActDist = RDO_DIST_MAX; 7382 if( m_pcRdCost->getUseEstimatedVSD() ) 7383 { 7384 uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false ); 7385 } 7386 else 7387 { 7388 uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false ); 7389 } 7390 7391 if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX ) 7392 { 7393 uiBestDist = uiActDist; 7394 uiBestQStepDC1 = uiQStepDC1; 7395 uiBestQStepDC2 = uiQStepDC2; 7396 } 7397 } 7398 } 7399 7400 fullDeltaDC1 = (Int)(uiBestQStepDC1) * (Int)(( fullDeltaDC1 < 0 ) ? -1 : 1); 7401 fullDeltaDC2 = (Int)(uiBestQStepDC2) * (Int)(( fullDeltaDC2 < 0 ) ? -1 : 1); 7402 xDeltaDCQuantScaleUp( pcCU, fullDeltaDC1 ); 7403 xDeltaDCQuantScaleUp( pcCU, fullDeltaDC2 ); 7404 rDeltaDC1 = fullDeltaDC1; 7405 rDeltaDC2 = fullDeltaDC2; 7406 } 7407 #endif 7408 7409 xDeltaDCQuantScaleDown( pcCU, rDeltaDC1 ); 7410 xDeltaDCQuantScaleDown( pcCU, rDeltaDC2 ); 7411 } 7412 7413 Bool TEncSearch::xSearchRbcEdge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, Int iWidth, Int iHeight ) 7414 { 7415 Bool* pbEdge = (Bool*) xMalloc( Bool, iWidth * iHeight * 4 ); 7416 7417 Short* psDiffX = new Short[ iWidth * iHeight ]; 7418 Short* psDiffY = new Short[ iWidth * iHeight ]; 7419 Bool* pbEdgeX = new Bool [ iWidth * iHeight ]; 7420 Bool* pbEdgeY = new Bool [ iWidth * iHeight ]; 7421 7422 // Find Horizontal Gradient & Edge Detection ((x+1, y) - (x,y)) 7423 for( Int y=0; y<iHeight; y++ ) 7424 { 7425 Short* psDiffXPtr = &psDiffX[ y * iHeight ]; 7426 Bool* pbEdgeXPtr = &pbEdgeX[ y * iHeight ]; 7427 for(Int x=0; x<iWidth-1; x++ ) 7428 { 7429 *psDiffXPtr = piRef[ x+1 + y*uiRefStride ] - piRef[ x + y*uiRefStride ]; 7430 if(*psDiffXPtr >= RBC_THRESHOLD || *psDiffXPtr <= (-1)*RBC_THRESHOLD) 7431 { 7432 *pbEdgeXPtr = true; 7433 } 7434 else 7435 { 7436 *pbEdgeXPtr = false; 7437 } 7438 7439 psDiffXPtr++; 7440 pbEdgeXPtr++; 7441 } 7442 } 7443 7444 // Find Vertical Gradient & Edge Detection((x,y+1) - (x,y)) 7445 for( Int y=0; y<iHeight-1; y++ ) 7446 { 7447 Short* psDiffYPtr = &psDiffY[ y * iHeight ]; 7448 Bool* pbEdgeYPtr = &pbEdgeY[ y * iHeight ]; 7449 for(Int x=0; x<iWidth; x++ ) 7450 { 7451 *psDiffYPtr = piRef[ x + (y+1)*uiRefStride ] - piRef[ x + y*uiRefStride ]; 7452 if(*psDiffYPtr >= RBC_THRESHOLD || *psDiffYPtr <= (-1)*RBC_THRESHOLD) 7453 { 7454 *pbEdgeYPtr = true; 7455 } 7456 else 7457 { 7458 *pbEdgeYPtr = false; 7459 } 7460 7461 psDiffYPtr++; 7462 pbEdgeYPtr++; 7463 } 7464 } 7465 7466 // Eliminate local maximum 7467 for( Int y=0; y<iHeight; y++ ) 7468 { 7469 Short* psDiffXPtr = &psDiffX[ y * iHeight ]; 7470 Bool* pbEdgeXPtr = &pbEdgeX[ y * iHeight ]; 7471 for( Int x=0; x<iWidth-1; x++ ) 7472 { 7473 UShort usAbs0=0, usAbs1=0, usAbs2=0; // 0 : left, 1 : current, 2 : right 7474 7475 if( x > 0 && *(pbEdgeXPtr-1) == true ) 7476 { 7477 if( *(psDiffXPtr-1) >= 0) 7478 { 7479 usAbs0 = *(psDiffXPtr-1); 7480 7481 } 7482 else 7483 { 7484 usAbs0 = (-1) * *(psDiffXPtr-1); 7485 } 7486 } 7487 if( *pbEdgeXPtr == true ) 7488 { 7489 if( *(psDiffXPtr) >= 0) 7490 { 7491 usAbs1 = *(psDiffXPtr); 7492 } 7493 else 7494 { 7495 usAbs1 = (-1) * *(psDiffXPtr); 7496 } 7497 } 7498 if( x < iWidth-2 && *(pbEdgeXPtr+1) == true ) 7499 { 7500 if( *(psDiffXPtr+1) >= 0) 7501 { 7502 usAbs2 = *(psDiffXPtr+1); 7503 //bSign2 = true; 7504 } 7505 else 7506 { 7507 usAbs2 = (-1) * *(psDiffXPtr+1); 7508 } 7509 } 7510 7511 if( x == 0 ) 7512 { 7513 if( usAbs1 < usAbs2 ) 7514 { 7515 *pbEdgeXPtr = false; 7516 } 7517 } 7518 else if( x == iWidth-2 ) 7519 { 7520 if( usAbs1 <= usAbs0 ) 7521 *pbEdgeXPtr = false; 7522 } 7523 else 7524 { 7525 if( usAbs2 > usAbs0 ) 7526 { 7527 if( usAbs1 < usAbs2 ) 7528 *pbEdgeXPtr = false; 7529 } 7530 else 7531 { 7532 if( usAbs1 <= usAbs0 ) 7533 *pbEdgeXPtr = false; 7534 } 7535 } 7536 7537 psDiffXPtr++; 7538 pbEdgeXPtr++; 7539 } 7540 } 7541 7542 for( Int y=0; y<iHeight-1; y++ ) 7543 { 7544 Short* psDiffYPtr = &psDiffY[ y * iWidth ]; 7545 Bool* pbEdgeYPtr = &pbEdgeY[ y * iWidth ]; 7546 for( Int x=0; x<iWidth; x++ ) 7547 { 7548 UShort usAbs0=0, usAbs1=0, usAbs2=0; // 0 : upper, 1 : current, 2 : bottom 7549 if( y > 0 && *(pbEdgeYPtr-iWidth) == true ) 7550 { 7551 if( *(psDiffYPtr-iWidth) >= 0) 7552 { 7553 usAbs0 = *(psDiffYPtr-iWidth); 7554 } 7555 else 7556 { 7557 usAbs0 = (-1) * *(psDiffYPtr-iWidth); 7558 } 7559 } 7560 if( *pbEdgeYPtr == true ) 7561 { 7562 if( *(psDiffYPtr) >= 0) 7563 { 7564 usAbs1 = *(psDiffYPtr); 7565 } 7566 else 7567 { 7568 usAbs1 = (-1) * *(psDiffYPtr); 7569 } 7570 } 7571 if( y < iHeight-2 && *(pbEdgeYPtr+iWidth) == true ) 7572 { 7573 if( *(psDiffYPtr+iWidth) >= 0) 7574 { 7575 usAbs2 = *(psDiffYPtr+iWidth); 7576 } 7577 else 7578 { 7579 usAbs2 = (-1) * *(psDiffYPtr+iWidth); 7580 } 7581 } 7582 7583 if( y == 0 ) 7584 { 7585 if( usAbs1 < usAbs2 ) 7586 *pbEdgeYPtr = false; 7587 } 7588 else if( y == iHeight-2 ) 7589 { 7590 if( usAbs1 <= usAbs0 ) 7591 *pbEdgeYPtr = false; 7592 } 7593 else 7594 { 7595 if( usAbs2 > usAbs0 ) 7596 { 7597 if( usAbs1 < usAbs2 ) 7598 *pbEdgeYPtr = false; 7599 } 7600 else 7601 { 7602 if( usAbs1 <= usAbs0 ) 7603 *pbEdgeYPtr = false; 7604 } 7605 } 7606 7607 psDiffYPtr++; 7608 pbEdgeYPtr++; 7609 } 7610 } 7611 7612 // Edge Merging 7613 for( Int i=0; i< 4 * iWidth * iHeight; i++ ) 7614 pbEdge[ i ] = false; 7615 /// Even Line (0,2,4,6,...) => Vertical Edge 7616 for( Int i=0; i<iHeight; i++) 7617 { 7618 for( Int j=0; j<iWidth-1; j++) 7619 { 7620 pbEdge[ (2 * j + 1) + (2 * i) * 2 * iWidth ] = pbEdgeX[ j + i * iHeight ]; 7621 } 7622 } 7623 /// Odd Line (1,3,5,7,...) => Horizontal Edge 7624 for( Int i=0; i<iHeight-1; i++) 7625 { 7626 for( Int j=0; j<iWidth; j++) 7627 { 7628 pbEdge[ (2 * j) + (2 * i + 1) * 2 * iWidth ] = pbEdgeY[ j + i * iHeight ]; 7629 } 7630 } 7631 7632 // Intersection Filling 7633 /// Vertical Edge between Horizontal Edges 7634 for( Int i = 1; i < 2 * iHeight - 3; i += 2) 7635 { 7636 for( Int j = 0; j < 2 * iWidth - 1; j += 2) 7637 { 7638 if( pbEdge[ j + i * 2 * iWidth ] ) 7639 { 7640 if( j != 0 && pbEdge[ (j - 2) + ((i + 2) * 2 * iWidth) ] ) 7641 { 7642 if( !pbEdge[ (j - 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j - 1) + ((i + 3) * 2 * iWidth) ] ) 7643 pbEdge[ (j - 1) + ((i + 1) * 2 * iWidth) ] = true; 7644 } 7645 if( j != 2 * iWidth - 2 && pbEdge[ (j + 2) + ((i + 2) * 2 * iWidth) ] ) 7646 { 7647 if( !pbEdge[ (j + 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j + 1) + ((i + 3) * 2 * iWidth) ] ) 7648 pbEdge[ (j + 1) + ((i + 1) * 2 * iWidth) ] = true; 7649 } 7650 } 7651 } 7652 } 7653 /// Horizontal Edge between Vertical Edges 7654 for( Int j = 1; j < 2 * iWidth - 3; j += 2) 7655 { 7656 for( Int i = 0; i < 2 * iHeight - 1; i += 2) 7657 { 7658 if( pbEdge[ j + i * 2 * iWidth ] ) 7659 { 7660 if( i != 0 && pbEdge[ (j + 2) + ((i - 2) * 2 * iWidth) ] ) 7661 { 7662 if( !pbEdge[ (j - 1) + ((i - 1) * 2 * iWidth) ] && !pbEdge[ (j + 3) + ((i - 1) * 2 * iWidth) ] ) 7663 pbEdge[ (j + 1) + ((i - 1) * 2 * iWidth) ] = true; 7664 } 7665 if( i != 2 * iHeight - 2 && pbEdge[ (j + 2) + ((i + 2) * 2 * iWidth) ] ) 7666 { 7667 if( !pbEdge[ (j - 1) + ((i + 1) * 2 * iWidth) ] && !pbEdge[ (j + 3) + ((i + 1) * 2 * iWidth) ] ) 7668 pbEdge[ (j + 1) + ((i + 1) * 2 * iWidth) ] = true; 7669 } 7670 } 7671 } 7672 } 7673 7674 // Static Pruning Unnecessary Edges 7675 /// Step1. Stack push the unconnected edges 7676 UShort* pusUnconnectedEdgeStack = new UShort[ 4 * iWidth * iHeight ]; // approximate size calculation 7677 Int iUnconnectedEdgeStackPtr = 0; 7678 //// Vertical Edges 7679 for( Int i = 0; i < 2 * iHeight - 1; i += 2 ) 7680 { 7681 for( Int j = 1; j < 2 * iWidth - 2; j += 2 ) 7682 { 7683 if( pbEdge[ j + i * 2 * iWidth ] ) 7684 { 7685 if( !xCheckTerminatedEdge( pbEdge, j, i, iWidth, iHeight ) ) 7686 { 7687 pusUnconnectedEdgeStack[iUnconnectedEdgeStackPtr] = (i << 8) | (j); 7688 iUnconnectedEdgeStackPtr++; 7689 } 7690 } 7691 } 7692 } 7693 7694 //// Horizontal Edges 7695 for( Int i = 1; i < 2 * iHeight - 2; i += 2 ) 7696 { 7697 for( Int j = 0; j < 2 * iWidth - 1; j += 2 ) 7698 { 7699 if( pbEdge[ j + i * 2 * iWidth ] ) 7700 { 7701 if( !xCheckTerminatedEdge( pbEdge, j, i, iWidth, iHeight ) ) 7702 { 7703 pusUnconnectedEdgeStack[iUnconnectedEdgeStackPtr] = (i << 8) | (j); 7704 iUnconnectedEdgeStackPtr++; 7705 } 7706 } 7707 } 7708 } 7709 7710 /// Step2. Remove the edges from the stack and push the new unconnected edges 7711 //// (This step may contain duplicated edges already in the stack) 7712 //// (But it doesn't cause any functional problems) 7713 while( iUnconnectedEdgeStackPtr != 0 ) 7714 { 7715 iUnconnectedEdgeStackPtr--; 7716 Int iX = pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] & 0xff; 7717 Int iY = pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] >> 8; 7718 7719 pbEdge[ iX + iY * 2 * iWidth ] = false; 7720 7721 if( iY % 2 == 1 && iX > 0 && pbEdge[ iX - 2 + iY * 2 * iWidth ] && 7722 !xCheckTerminatedEdge( pbEdge, iX - 2, iY, iWidth, iHeight ) ) // left 7723 { 7724 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 0) << 8) | (iX - 2); 7725 iUnconnectedEdgeStackPtr++; 7726 } 7727 if( iY % 2 == 1 && iX < 2 * iWidth - 2 && pbEdge[ iX + 2 + iY * 2 * iWidth ] && 7728 !xCheckTerminatedEdge( pbEdge, iX + 2, iY, iWidth, iHeight ) ) // right 7729 { 7730 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 0) << 8) | (iX + 2); 7731 iUnconnectedEdgeStackPtr++; 7732 } 7733 if( iY % 2 == 0 && iY > 0 && pbEdge[ iX + (iY - 2) * 2 * iWidth ] && 7734 !xCheckTerminatedEdge( pbEdge, iX, iY - 2, iWidth, iHeight ) ) // top 7735 { 7736 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 2) << 8) | (iX + 0); 7737 iUnconnectedEdgeStackPtr++; 7738 } 7739 if( iY % 2 == 0 && iY < 2 * iHeight - 2 && pbEdge[ iX + (iY + 2) * 2 * iWidth ] && 7740 !xCheckTerminatedEdge( pbEdge, iX, iY + 2, iWidth, iHeight ) ) // bottom 7741 { 7742 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 2) << 8) | (iX + 0); 7743 iUnconnectedEdgeStackPtr++; 7744 } 7745 if( iX > 0 && iY > 0 && pbEdge[ iX - 1 + (iY - 1) * 2 * iWidth ] && 7746 !xCheckTerminatedEdge( pbEdge, iX - 1, iY - 1, iWidth, iHeight ) ) // left-top 7747 { 7748 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 1) << 8) | (iX - 1); 7749 iUnconnectedEdgeStackPtr++; 7750 } 7751 if( iX < 2 * iWidth - 1 && iY > 0 && pbEdge[ iX + 1 + (iY - 1) * 2 * iWidth ] && 7752 !xCheckTerminatedEdge( pbEdge, iX + 1, iY - 1, iWidth, iHeight ) ) // right-top 7753 { 7754 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY - 1) << 8) | (iX + 1); 7755 iUnconnectedEdgeStackPtr++; 7756 } 7757 if( iX > 0 && iY < 2 * iHeight - 1 && pbEdge[ iX - 1 + (iY + 1) * 2 * iWidth ] && 7758 !xCheckTerminatedEdge( pbEdge, iX - 1, iY + 1, iWidth, iHeight ) ) // left-bottom 7759 { 7760 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 1) << 8) | (iX - 1); 7761 iUnconnectedEdgeStackPtr++; 7762 } 7763 if( iX < 2 * iWidth - 1 && iY < 2 * iHeight - 1 && pbEdge[ iX + 1 + (iY + 1) * 2 * iWidth ] && 7764 !xCheckTerminatedEdge( pbEdge, iX + 1, iY + 1, iWidth, iHeight ) ) // right-bottom 7765 { 7766 pusUnconnectedEdgeStack[ iUnconnectedEdgeStackPtr ] = ((iY + 1) << 8) | (iX + 1); 7767 iUnconnectedEdgeStackPtr++; 7768 } 7769 } 7770 7771 7772 // Region Generation ( edge -> region ) 7773 Bool* pbRegion = pcCU->getEdgePartition( uiAbsPtIdx ); 7774 Bool* pbVisit = new Bool[ iWidth * iHeight ]; 7775 7776 for( UInt ui = 0; ui < iWidth * iHeight; ui++ ) 7777 { 7778 pbRegion[ ui ] = true; // fill it as region 1 (we'll discover region 0 next) 7779 pbVisit [ ui ] = false; 7780 } 7781 7782 Int* piStack = new Int[ iWidth * iHeight ]; 7783 7784 Int iPtr = 0; 7785 7786 piStack[iPtr++] = (0 << 8) | (0); 7787 pbRegion[ 0 ] = false; 7788 7789 while(iPtr > 0) 7790 { 7791 Int iTmp = piStack[--iPtr]; 7792 Int iX1, iY1; 7793 iX1 = iTmp & 0xff; 7794 iY1 = (iTmp >> 8) & 0xff; 7795 7796 pbVisit[ iX1 + iY1 * iWidth ] = true; 7797 7798 assert( iX1 >= 0 && iX1 < iWidth ); 7799 assert( iY1 >= 0 && iY1 < iHeight ); 7800 7801 if( iX1 > 0 && !pbEdge[ 2 * iX1 - 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 - 1 + iY1 * iWidth ] ) 7802 { 7803 piStack[iPtr++] = (iY1 << 8) | (iX1 - 1); 7804 pbRegion[ iX1 - 1 + iY1 * iWidth ] = false; 7805 } 7806 if( iX1 < iWidth - 1 && !pbEdge[ 2 * iX1 + 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 + 1 + iY1 * iWidth ] ) 7807 { 7808 piStack[iPtr++] = (iY1 << 8) | (iX1 + 1); 7809 pbRegion[ iX1 + 1 + iY1 * iWidth ] = false; 7810 } 7811 if( iY1 > 0 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 - 1) * iWidth ] && !pbVisit[ iX1 + (iY1 - 1) * iWidth ] ) 7812 { 7813 piStack[iPtr++] = ((iY1 - 1) << 8) | iX1; 7814 pbRegion[ iX1 + (iY1 - 1) * iWidth ] = false; 7815 } 7816 if( iY1 < iHeight - 1 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 + 1) * iWidth ] && !pbVisit[ iX1 + (iY1 + 1) * iWidth ] ) 7817 { 7818 piStack[iPtr++] = ((iY1 + 1) << 8) | iX1; 7819 pbRegion[ iX1 + (iY1 + 1) * iWidth ] = false; 7820 } 7821 } 7822 7823 /////////// 7824 iPtr = 0; 7825 for( Int i = 0; i < iWidth * iHeight; i++ ) 7826 pbVisit[ i ] = false; 7827 piStack[ iPtr++ ] = (0 << 8) | (0); // initial seed 7828 while( iPtr > 0 && iPtr < iWidth * iHeight ) 7829 { 7830 Int iX; 7831 Int iY; 7832 iPtr--; 7833 iX = piStack[ iPtr ] & 0xff; 7834 iY = piStack[ iPtr ] >> 8; 7835 pbVisit[ iY * iWidth + iX ] = true; 7836 7837 if( iY > 0 && !pbVisit[ (iY - 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY - 1) * iWidth + iX ] ) 7838 { 7839 piStack[ iPtr++ ] = ((iY - 1) << 8) | iX; 7840 } 7841 if( iY < iHeight - 1 && !pbVisit[ (iY + 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY + 1) * iWidth + iX ] ) 7842 { 7843 piStack[ iPtr++ ] = ((iY + 1) << 8) | iX; 7844 } 7845 if( iX > 0 && !pbVisit[ iY * iWidth + (iX - 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX - 1) ] ) 7846 { 7847 piStack[ iPtr++ ] = (iY << 8) | (iX - 1); 7848 } 7849 if( iX < iWidth - 1 && !pbVisit[ iY * iWidth + (iX + 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX + 1) ] ) 7850 { 7851 piStack[ iPtr++ ] = (iY << 8) | (iX + 1); 7852 } 7853 } 7854 assert( iPtr == 0 || iPtr == iWidth * iHeight ); 7855 7856 Bool bBipartition; 7857 if( iPtr == iWidth * iHeight ) 7858 { 7859 bBipartition = false; // single partition 7860 } 7861 else 7862 { 7863 for( Int i = 0; i < iWidth * iHeight; i++ ) 7864 { 7865 if( !pbVisit[ i ] ) 7866 { 7867 piStack[ iPtr++ ] = (( i / iWidth ) << 8) | ( i % iWidth ); 7868 pbVisit[ i ] = true; 7869 break; 7870 } 7871 } 7872 while( iPtr > 0 ) 7873 { 7874 Int iX; 7875 Int iY; 7876 iPtr--; 7877 iX = piStack[ iPtr ] & 0xff; 7878 iY = piStack[ iPtr ] >> 8; 7879 pbVisit[ iY * iWidth + iX ] = true; 7880 7881 if( iY > 0 && !pbVisit[ (iY - 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY - 1) * iWidth + iX ] ) 7882 { 7883 piStack[ iPtr++ ] = ((iY - 1) << 8) | iX; 7884 } 7885 if( iY < iHeight - 1 && !pbVisit[ (iY + 1) * iWidth + iX ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ (iY + 1) * iWidth + iX ] ) 7886 { 7887 piStack[ iPtr++ ] = ((iY + 1) << 8) | iX; 7888 } 7889 if( iX > 0 && !pbVisit[ iY * iWidth + (iX - 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX - 1) ] ) 7890 { 7891 piStack[ iPtr++ ] = (iY << 8) | (iX - 1); 7892 } 7893 if( iX < iWidth - 1 && !pbVisit[ iY * iWidth + (iX + 1) ] && pbRegion[ iY * iWidth + iX ] == pbRegion[ iY * iWidth + (iX + 1) ] ) 7894 { 7895 piStack[ iPtr++ ] = (iY << 8) | (iX + 1); 7896 } 7897 } 7898 bBipartition = true; 7899 for( Int i = 0; i < iWidth * iHeight; i++ ) 7900 { 7901 if( !pbVisit[ i ] ) 7902 { 7903 bBipartition = false; 7904 break; 7905 } 7906 } 7907 } 7908 7909 xFree( pbEdge ); 7910 delete[] pbEdgeX; pbEdgeX = NULL; 7911 delete[] pbEdgeY; pbEdgeY = NULL; 7912 delete[] psDiffX; psDiffX = NULL; 7913 delete[] psDiffY; psDiffY = NULL; 7914 delete[] pusUnconnectedEdgeStack; pusUnconnectedEdgeStack = NULL; 7915 delete[] pbVisit; pbVisit = NULL; 7916 delete[] piStack; piStack = NULL; 7917 7918 if( bBipartition ) 7919 { 7920 return xConstructChainCode( pcCU, uiAbsPtIdx, (UInt)iWidth, (UInt)iHeight ); 7921 } 7922 else 7923 { 7924 return false; 7925 } 7926 } 7927 7928 Bool TEncSearch::xCheckTerminatedEdge( Bool* pbEdge, Int iX, Int iY, Int iWidth, Int iHeight ) 7929 { 7930 if( (iY % 2) == 0 ) // vertical edge 7931 { 7932 Bool bTopConnected = false; 7933 Bool bBottomConnected = false; 7934 7935 if( iY != 0 ) 7936 { 7937 if( pbEdge[ iX + (iY - 2) * 2 * iWidth ] ) 7938 bTopConnected = true; 7939 if( pbEdge[ (iX - 1) + (iY - 1) * 2 * iWidth ] ) 7940 bTopConnected = true; 7941 if( pbEdge[ (iX + 1) + (iY - 1) * 2 * iWidth ] ) 7942 bTopConnected = true; 7943 } 7944 else 7945 { 7946 bTopConnected = true; 7947 } 7948 7949 7950 if( iY != 2 * iHeight - 2 ) 7951 { 7952 if( pbEdge[ iX + (iY + 2) * 2 * iWidth ] ) 7953 bBottomConnected = true; 7954 if( pbEdge[ (iX - 1) + (iY + 1) * 2 * iWidth ] ) 7955 bBottomConnected = true; 7956 if( pbEdge[ (iX + 1) + (iY + 1) * 2 * iWidth ] ) 7957 bBottomConnected = true; 7958 } 7959 else 7960 { 7961 bBottomConnected = true; 7962 } 7963 7964 7965 if( bTopConnected && bBottomConnected ) 7966 { 7967 return true; 7968 } 7969 else 7970 { 7971 return false; 7972 } 7973 } 7974 else 7975 { 7976 Bool bLeftConnected = false; 7977 Bool bRightConnected = false; 7978 7979 if( iX != 0 ) 7980 { 7981 if( pbEdge[ (iX - 2) + iY * 2 * iWidth ] ) 7982 bLeftConnected = true; 7983 if( pbEdge[ (iX - 1) + (iY - 1) * 2 * iWidth ] ) 7984 bLeftConnected = true; 7985 if( pbEdge[ (iX - 1) + (iY + 1) * 2 * iWidth ] ) 7986 bLeftConnected = true; 7987 } 7988 else 7989 { 7990 bLeftConnected = true; 7991 } 7992 7993 if( iX != 2 * iWidth - 2 ) 7994 { 7995 if( pbEdge[ (iX + 2) + iY * 2 * iWidth ] ) 7996 bRightConnected = true; 7997 if( pbEdge[ (iX + 1) + (iY - 1) * 2 * iWidth ] ) 7998 bRightConnected = true; 7999 if( pbEdge[ (iX + 1) + (iY + 1) * 2 * iWidth ] ) 8000 bRightConnected = true; 8001 } 8002 else 8003 { 8004 bRightConnected = true; 8005 } 8006 8007 8008 if( bLeftConnected && bRightConnected ) 8009 { 8010 return true; 8011 } 8012 else 8013 { 8014 return false; 8015 } 8016 } 8017 } 8018 Bool TEncSearch::xConstructChainCode( TComDataCU* pcCU, UInt uiAbsPtIdx, UInt uiWidth, UInt uiHeight ) 8019 { 8020 //UInt uiWidth = pcCU->getWidth( uiPartIdx ) >> (bPU4x4 ? 1 : 0); 8021 //UInt uiHeight = pcCU->getHeight( uiPartIdx ) >> (bPU4x4 ? 1 : 0); 8022 Bool* pbEdge = (Bool*) xMalloc( Bool, uiWidth * uiHeight * 4 ); 8023 Bool* pbVisit = (Bool*) xMalloc( Bool, uiWidth * uiHeight * 4 ); 8024 UInt uiMaxEdge = uiWidth * (RBC_MAX_EDGE_NUM_PER_4x4 / 4); 8025 Bool* pbRegion = pcCU->getEdgePartition( uiAbsPtIdx ); 8026 UChar* piEdgeCode = pcCU->getEdgeCode( uiAbsPtIdx ); 8027 Bool bStartLeft = false; 8028 Bool bPossible = false; 8029 Bool bFinish = false; 8030 Int iStartPosition = -1; 8031 Int iPtr = 0; 8032 Int iDir = -1, iNextDir = -1; 8033 Int iArrow = -1, iNextArrow = -1; 8034 Int iX = -1, iY = -1; 8035 Int iDiffX = 0, iDiffY = 0; 8036 UChar iCode = 255; 8037 UInt uiWidth2 = uiWidth * 2; 8038 8039 for( Int i = 0; i < uiWidth * uiHeight * 4; i++ ) 8040 pbEdge[ i ] = false; 8041 8042 for( Int i = 0; i < uiHeight; i++ ) 8043 { 8044 for( Int j = 0; j < uiWidth - 1; j++ ) 8045 { 8046 if( pbRegion[ i * uiWidth + j ] != pbRegion[ i * uiWidth + j + 1 ] ) 8047 pbEdge[ i * uiWidth * 4 + j * 2 + 1 ] = true; 8048 } 8049 } 8050 8051 for( Int i = 0; i < uiHeight - 1; i++ ) 8052 { 8053 for( Int j = 0; j < uiWidth; j++ ) 8054 { 8055 if( pbRegion[ (i + 0) * uiWidth + j ] != pbRegion[ (i + 1) * uiWidth + j ] ) 8056 pbEdge[ (2 * i + 1) * 2 * uiWidth + j * 2 ] = true; 8057 } 8058 } 8059 8060 for( Int i = 1; i < uiWidth2 - 2; i+=2 ) 8061 { 8062 if(pbEdge[ i ]) 8063 { 8064 bPossible = true; 8065 bStartLeft = false; 8066 iStartPosition = iX = i; 8067 iY = 0; 8068 iDir = 3; 8069 iArrow = 3; 8070 break; 8071 } 8072 } 8073 8074 if( !bPossible ) 8075 { 8076 for( Int i = 1; i < uiWidth2 - 2; i+=2 ) 8077 { 8078 if(pbEdge[ i * uiWidth2 ]) 8079 { 8080 bPossible = true; 8081 bStartLeft = true; 8082 iX = 0; 8083 iStartPosition = iY = i; 8084 iDir = 1; 8085 iArrow = 1; 8086 break; 8087 } 8088 } 8089 } 8090 8091 if( bPossible ) 8092 { 8093 for( Int i = 0; i < 4 * uiWidth * uiHeight; i++ ) 8094 pbVisit[ i ] = false; 8095 8096 while( !bFinish ) 8097 { 8098 Bool bArrowSkip = false; 8099 pbVisit[ iX + iY * uiWidth2 ] = true; 8100 8101 switch( iDir ) 8102 { 8103 case 0: // left 8104 if( iX > 0 && !pbVisit[ (iX - 2) + iY * uiWidth2 ] && pbEdge[ (iX - 2) + iY * uiWidth2 ] ) // left 8105 { 8106 iDiffX = -2; 8107 iDiffY = 0; 8108 iNextDir = 0; 8109 iNextArrow = 0; 8110 } 8111 else if( iX > 0 && !pbVisit[ (iX - 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY - 1) * uiWidth2 ] ) // top 8112 { 8113 iDiffX = -1; 8114 iDiffY = -1; 8115 iNextDir = 2; 8116 iNextArrow = 4; 8117 } 8118 else if( iX > 0 && !pbVisit[ (iX - 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY + 1) * uiWidth2 ] ) // bottom 8119 { 8120 iDiffX = -1; 8121 iDiffY = +1; 8122 iNextDir = 3; 8123 iNextArrow = iArrow; 8124 if( !(iPtr == 0 && iX == uiWidth2 - 2 && iY == uiHeight * 2 - 3) ) 8125 bArrowSkip = true; 8126 else 8127 iNextArrow = 3; 8128 } 8129 else if( iX == 0 ) 8130 { 8131 iDiffX = 0; 8132 iDiffY = 0; 8133 iNextDir = iDir; 8134 iNextArrow = iArrow; 8135 bFinish = true; 8136 continue; 8137 } 8138 else 8139 { 8140 iPtr = 0; // edge loop or unwanted case 8141 bFinish = true; 8142 //continue; 8143 assert(false); 8144 } 8145 break; 8146 case 1: // right 8147 if( iX < uiWidth2 - 2 && !pbVisit[ (iX + 2) + iY * uiWidth2 ] && pbEdge[ (iX + 2) + iY * uiWidth2 ] ) // right 8148 { 8149 iDiffX = +2; 8150 iDiffY = 0; 8151 iNextDir = 1; 8152 iNextArrow = 1; 8153 } 8154 else if( iX < uiWidth2 - 2 && !pbVisit[ (iX + 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY - 1) * uiWidth2 ] ) // top 8155 { 8156 iDiffX = +1; 8157 iDiffY = -1; 8158 iNextDir = 2; 8159 iNextArrow = iArrow; 8160 if( !(iPtr == 0 && iX == 0 && iY == 1) ) 8161 bArrowSkip = true; 8162 else 8163 iNextArrow = 2; 8164 } 8165 else if( iX < uiWidth2 - 2 && !pbVisit[ (iX + 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY + 1) * uiWidth2 ] ) // bottom 8166 { 8167 iDiffX = +1; 8168 iDiffY = +1; 8169 iNextDir = 3; 8170 iNextArrow = 7; 8171 } 8172 else if( iX == uiWidth2 - 2 ) 8173 { 8174 iDiffX = 0; 8175 iDiffY = 0; 8176 iNextDir = iDir; 8177 iNextArrow = iArrow; 8178 bFinish = true; 8179 continue; 8180 } 8181 else 8182 { 8183 iPtr = 0; // edge loop or unwanted case 8184 bFinish = true; 8185 //continue; 8186 assert(false); 8187 } 8188 break; 8189 case 2: // top 8190 if( iY > 0 && !pbVisit[ (iX - 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY - 1) * uiWidth2 ] ) // left 8191 { 8192 iDiffX = -1; 8193 iDiffY = -1; 8194 iNextDir = 0; 8195 iNextArrow = iArrow; 8196 if( !(iPtr == 0 && iX == 1 && iY == uiHeight * 2 - 2) ) 8197 bArrowSkip = true; 8198 else 8199 iNextArrow = 0; 8200 } 8201 else if( iY > 0 && !pbVisit[ (iX + 1) + (iY - 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY - 1) * uiWidth2 ] ) // right 8202 { 8203 iDiffX = +1; 8204 iDiffY = -1; 8205 iNextDir = 1; 8206 iNextArrow = 5; 8207 } 8208 else if( iY > 0 && !pbVisit[ iX + (iY - 2) * uiWidth2 ] && pbEdge[ iX + (iY - 2) * uiWidth2 ] ) // top 8209 { 8210 iDiffX = 0; 8211 iDiffY = -2; 8212 iNextDir = 2; 8213 iNextArrow = 2; 8214 } 8215 else if( iY == 0 ) 8216 { 8217 iDiffX = 0; 8218 iDiffY = 0; 8219 iNextDir = iDir; 8220 iNextArrow = iArrow; 8221 bFinish = true; 8222 continue; 8223 } 8224 else 8225 { 8226 iPtr = 0; // edge loop or unwanted case 8227 bFinish = true; 8228 //continue; 8229 assert(false); 8230 } 8231 break; 8232 case 3: // bottom 8233 if( iY < uiWidth2 - 2 && !pbVisit[ (iX - 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX - 1) + (iY + 1) * uiWidth2 ] ) // left 8234 { 8235 iDiffX = -1; 8236 iDiffY = +1; 8237 iNextDir = 0; 8238 iNextArrow = 6; 8239 } 8240 else if( iY < uiWidth2 - 2 && !pbVisit[ (iX + 1) + (iY + 1) * uiWidth2 ] && pbEdge[ (iX + 1) + (iY + 1) * uiWidth2 ] ) // right 8241 { 8242 iDiffX = +1; 8243 iDiffY = +1; 8244 iNextDir = 1; 8245 iNextArrow = iArrow; 8246 if( !(iPtr == 0 && iX == uiWidth * 2 - 3 && iY == 0) ) 8247 bArrowSkip = true; 8248 else 8249 iNextArrow = 1; 8250 } 8251 else if( iY < uiWidth2 - 2 && !pbVisit[ iX + (iY + 2) * uiWidth2 ] && pbEdge[ iX + (iY + 2) * uiWidth2 ] ) // bottom 8252 { 8253 iDiffX = 0; 8254 iDiffY = +2; 8255 iNextDir = 3; 8256 iNextArrow = 3; 8257 } 8258 else if( iY == uiWidth2 - 2 ) 8259 { 8260 iDiffX = 0; 8261 iDiffY = 0; 8262 iNextDir = iDir; 8263 iNextArrow = iArrow; 8264 bFinish = true; 8265 continue; 8266 } 8267 else 8268 { 8269 iPtr = 0; // edge loop or unwanted case 8270 bFinish = true; 8271 //continue; 8272 assert(false); 8273 } 8274 break; 8275 } 8276 8277 const UChar tableCode[8][8] = { { 0, -1, 4, 3, 2, 6, 1, 5 }, // iArrow(current direction), iNextArrow(next direction) 8278 { -1, 0, 3, 4, 5, 1, 6, 2 }, 8279 { 3, 4, 0, -1, 1, 2, 5, 6 }, 8280 { 4, 3, -1, 0, 6, 5, 2, 1 }, 8281 { 1, 6, 2, 5, 0, 4, 3, -1 }, 8282 { 5, 2, 1, 6, 3, 0, -1, 4 }, 8283 { 2, 5, 6, 1, 4, -1, 0, 3 }, 8284 { 6, 1, 5, 2, -1, 3, 4, 0 } }; 8285 8286 iCode = tableCode[iArrow][iNextArrow]; 8287 8288 if(iPtr >= uiMaxEdge) 8289 { 8290 iPtr = 0; // over the maximum number of edge 8291 bPossible = false; 8292 break; 8293 } 8294 8295 if( !bArrowSkip ) 8296 { 8297 piEdgeCode[iPtr++] = iCode; // first edge coding 8298 //printf("xEdgeCoding: (%d,%d)->(%d,%d) code %d\n",iX,iY, iX+iDiffX, iY+iDiffY, iCode); 8299 } 8300 8301 iX += iDiffX; 8302 iY += iDiffY; 8303 iDir = iNextDir; 8304 iArrow = iNextArrow; 8305 } 8306 } 8307 8308 pcCU->setEdgeLeftFirst( uiAbsPtIdx, bStartLeft ); 8309 pcCU->setEdgeStartPos ( uiAbsPtIdx, bStartLeft ? (iStartPosition - 1) >> 1 : (iStartPosition + 1) >> 1); 8310 pcCU->setEdgeNumber ( uiAbsPtIdx, iPtr ); 8311 8312 xFree( pbEdge ); 8313 xFree( pbVisit ); 8314 8315 return (iPtr != 0); 8316 } 8317 #endif 8318 #endif 6524 8319 //! \} -
branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSearch.h
r510 r531 261 261 UInt& ruiDist, 262 262 #endif 263 Int default0Save1Load2 = 0); 263 Int default0Save1Load2 = 0 264 #if H_3D_DIM_ENC 265 , Bool zeroResi = false 266 #endif 267 ); 264 268 Void xIntraCodingChromaBlk ( TComDataCU* pcCU, 265 269 UInt uiTrDepth, … … 288 292 Bool bCheckFirst, 289 293 #endif 290 Double& dRDCost ); 294 Double& dRDCost 295 #if H_3D_DIM_ENC 296 , Bool zeroResi = false 297 #endif 298 ); 291 299 292 300 Void xSetIntraResultQT ( TComDataCU* pcCU, … … 324 332 UInt uiAbsPartIdx, 325 333 UInt stateU0V1Both2 ); 334 335 336 // ------------------------------------------------------------------------------------------------------------------- 337 // Depth intra search 338 // ------------------------------------------------------------------------------------------------------------------- 339 #if H_3D_DIM 340 Void xCalcBiSegDCs ( Pel* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& valDC1, Pel& valDC2 ); 341 #if H_3D_DIM_DMM 342 Void xSearchDmmDeltaDCs ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piOrig, Pel* piPredic, UInt uiStride, Bool* biSegPattern, Int patternStride, UInt uiWidth, UInt uiHeight, Pel& rDeltaDC1, Pel& rDeltaDC2 ); 343 Void xSearchDmm1Wedge ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx ); 344 Void xSearchDmm2Wedge ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, Int& riWedgeDeltaEnd ); 345 Void xSearchDmm3Wedge ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx ); 346 #endif 347 #if H_3D_DIM_RBC 348 Void xSearchRbcDeltaDCs ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piOrig, Pel* piPredic, UInt uiStride, Bool* biSegPattern, Int patternStride, UInt uiWidth, UInt uiHeight, Pel& rDeltaDC1, Pel& rDeltaDC2 ); 349 Bool xSearchRbcEdge ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, Int iWidth, Int iHeight ); 350 351 Bool xCheckTerminatedEdge ( Bool* pbEdge, Int iX, Int iY, Int iWidth, Int iHeight ); 352 Bool xConstructChainCode ( TComDataCU* pcCU, UInt uiAbsPtIdx, UInt uiWidth, UInt uiHeight ); 353 #endif 354 #if H_3D_DIM_SDC 355 Void xIntraCodingSDC ( TComDataCU* pcCU, UInt uiAbsPartIdx, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, Dist& ruiDist, Double& dRDCost, Bool bResidual ); 356 #endif 357 #endif 326 358 327 359 // -------------------------------------------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.