Changeset 1390 in 3DVCSoftware for branches/HTM-16.0-MV-draft-5/source/Lib/TLibCommon/TComPrediction.cpp
- Timestamp:
- 13 Nov 2015, 17:00:20 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HTM-16.0-MV-draft-5/source/Lib/TLibCommon/TComPrediction.cpp
r1386 r1390 82 82 } 83 83 } 84 #if NH_3D_VSP85 m_pDepthBlock = (Int*) malloc(MAX_NUM_PART_IDXS_IN_CTU_WIDTH*MAX_NUM_PART_IDXS_IN_CTU_WIDTH*sizeof(Int));86 if (m_pDepthBlock == NULL)87 {88 printf("ERROR: UKTGHU, No memory allocated.\n");89 }90 #endif91 84 92 85 } … … 94 87 TComPrediction::~TComPrediction() 95 88 { 96 #if NH_3D_VSP97 if (m_pDepthBlock != NULL)98 {99 free(m_pDepthBlock);100 }101 m_cYuvDepthOnVsp.destroy();102 #endif103 89 104 90 destroy(); … … 123 109 m_cYuvPredTemp.destroy(); 124 110 125 #if NH_3D_ARP126 m_acYuvPredBase[0].destroy();127 m_acYuvPredBase[1].destroy();128 #endif129 111 if( m_pLumaRecBuffer ) 130 112 { … … 182 164 183 165 m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC ); 184 #if NH_3D_ARP185 m_acYuvPredBase[0] .create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );186 m_acYuvPredBase[1] .create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );187 #endif188 #if NH_3D_VSP189 m_cYuvDepthOnVsp.create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );190 #endif191 166 192 167 } … … 201 176 } 202 177 } 203 #if NH_3D_IC204 m_uiaShift[0] = 0;205 for( Int i = 1; i < 64; i++ )206 {207 m_uiaShift[i] = ( (1 << 15) + i/2 ) / i;208 }209 #endif210 178 } 211 179 … … 508 476 } 509 477 510 #if NH_3D_DMM511 Void TComPrediction::predIntraLumaDmm( TComDataCU* pcCU, UInt uiAbsPartIdx, DmmID dmmType, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight )512 {513 assert( iWidth == iHeight );514 assert( iWidth >= DMM_MIN_SIZE && iWidth <= DMM_MAX_SIZE );515 #if NH_3D_SDC_INTRA516 assert( !pcCU->getSDCFlag( uiAbsPartIdx ) );517 #endif518 519 // get partition520 Bool* biSegPattern = new Bool[ (UInt)(iWidth*iHeight) ];521 UInt patternStride = (UInt)iWidth;522 switch( dmmType )523 {524 case( DMM1_IDX ): { (getWedgeListScaled( (UInt)iWidth )->at( pcCU->getDmm1WedgeTabIdx( uiAbsPartIdx ) )).getPatternScaledCopy( (UInt)iWidth, biSegPattern ); } break;525 case( DMM4_IDX ): { predContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, biSegPattern ); } break;526 default: assert(0);527 }528 529 // get predicted partition values530 Pel predDC1 = 0, predDC2 = 0;531 predBiSegDCs( pcCU, uiAbsPartIdx, iWidth, iHeight, biSegPattern, patternStride, predDC1, predDC2 );532 533 // set segment values with deltaDC offsets534 Pel segDC1 = 0, segDC2 = 0;535 Pel deltaDC1 = pcCU->getDmmDeltaDC( dmmType, 0, uiAbsPartIdx );536 Pel deltaDC2 = pcCU->getDmmDeltaDC( dmmType, 1, uiAbsPartIdx );537 #if NH_3D_DLT538 segDC1 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 );539 segDC2 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 );540 #else541 segDC1 = ClipBD( predDC1 + deltaDC1, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) );542 segDC2 = ClipBD( predDC2 + deltaDC2, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) );543 #endif544 545 // set prediction signal546 Pel* pDst = piPred;547 assignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 );548 549 delete[] biSegPattern;550 }551 #endif552 478 553 479 /** Check for identical motion in both motion vector direction of a bi-directional predicted CU … … 565 491 Int layerIdL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getLayerId(); 566 492 Int layerIdL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getLayerId(); 567 #if NH_3D_ARP568 if(!pcCU->getARPW(PartAddr) && RefPOCL0 == RefPOCL1 && layerIdL0 == layerIdL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))569 #else570 493 if(RefPOCL0 == RefPOCL1 && layerIdL0 == layerIdL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) 571 #endif572 494 #else 573 495 if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) … … 581 503 } 582 504 583 #if NH_3D_SPIVMP 584 Void TComPrediction::xGetSubPUAddrAndMerge(TComDataCU* pcCU, UInt uiPartAddr, Int iSPWidth, Int iSPHeight, Int iNumSPInOneLine, Int iNumSP, UInt* uiMergedSPW, UInt* uiMergedSPH, UInt* uiSPAddr ) 585 { 586 for (Int i = 0; i < iNumSP; i++) 587 { 588 uiMergedSPW[i] = iSPWidth; 589 uiMergedSPH[i] = iSPHeight; 590 pcCU->getSPAbsPartIdx(uiPartAddr, iSPWidth, iSPHeight, i, iNumSPInOneLine, uiSPAddr[i]); 591 } 592 #if NH_3D_ARP 593 if( pcCU->getARPW( uiPartAddr ) != 0 ) 594 { 595 return; 596 } 597 #endif 598 599 // horizontal sub-PU merge 600 for (Int i=0; i<iNumSP; i++) 601 { 602 if (i % iNumSPInOneLine == iNumSPInOneLine - 1 || uiMergedSPW[i]==0 || uiMergedSPH[i]==0) 603 { 604 continue; 605 } 606 for (Int j=i+1; j<i+iNumSPInOneLine-i%iNumSPInOneLine; j++) 607 { 608 if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j])) 609 { 610 uiMergedSPW[i] += iSPWidth; 611 uiMergedSPW[j] = uiMergedSPH[j] = 0; 612 } 613 else 614 { 615 break; 616 } 617 } 618 } 619 //vertical sub-PU merge 620 for (Int i=0; i<iNumSP-iNumSPInOneLine; i++) 621 { 622 if (uiMergedSPW[i]==0 || uiMergedSPH[i]==0) 623 { 624 continue; 625 } 626 for (Int j=i+iNumSPInOneLine; j<iNumSP; j+=iNumSPInOneLine) 627 { 628 if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j]) && uiMergedSPW[i]==uiMergedSPW[j]) 629 { 630 uiMergedSPH[i] += iSPHeight; 631 uiMergedSPH[j] = uiMergedSPW[j] = 0; 632 } 633 else 634 { 635 break; 636 } 637 } 638 } 639 } 640 641 Bool TComPrediction::xCheckTwoSPMotion ( TComDataCU* pcCU, UInt PartAddr0, UInt PartAddr1 ) 642 { 643 if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr1)) 644 { 645 return false; 646 } 647 if( pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr1)) 648 { 649 return false; 650 } 651 652 if (pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) >= 0) 653 { 654 if (pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr1)) 655 { 656 return false; 657 } 658 } 659 660 if (pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) >= 0) 661 { 662 if (pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr1)) 663 { 664 return false; 665 } 666 } 667 return true; 668 } 669 #endif 670 671 #if NH_3D_DBBP 672 PartSize TComPrediction::getPartitionSizeFromDepth(Pel* pDepthPels, UInt uiDepthStride, UInt uiSize, TComDataCU*& pcCU) 673 { 674 const TComSPS* sps = pcCU->getSlice()->getSPS(); 675 UInt uiMaxCUWidth = sps->getMaxCUWidth(); 676 UInt uiMaxCUHeight = sps->getMaxCUHeight(); 677 678 // find virtual partitioning for this CU based on depth block 679 // segmentation of texture block --> mask IDs 680 Pel* pDepthBlockStart = pDepthPels; 681 682 // first compute average of depth block for thresholding 683 Int iSumDepth = 0; 684 Int iSubSample = 4; 685 Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth(COMPONENT_Y); 686 Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight(COMPONENT_Y); 687 TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag( ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV; 688 if( pcCU->getSlice()->getDepthRefinementFlag( ) ) 689 { 690 cDv.setVer(0); 691 } 692 Int iBlkX = ( pcCU->getCtuRsAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCtus() ) * uiMaxCUWidth + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCtu() ] ]+ ((cDv.getHor()+2)>>2); 693 Int iBlkY = ( pcCU->getCtuRsAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCtus() ) * uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCtu() ] ]+ ((cDv.getVer()+2)>>2); 694 695 UInt t=0; 696 697 for (Int y=0; y<uiSize; y+=iSubSample) 698 { 699 for (Int x=0; x<uiSize; x+=iSubSample) 700 { 701 if (iBlkX+x>iPictureWidth) 702 { 703 Int depthPel = pDepthPels[t]; 704 iSumDepth += depthPel; 705 } 706 else 707 { 708 Int depthPel = pDepthPels[x]; 709 t=x; 710 iSumDepth += depthPel; 711 } 712 } 713 714 // next row 715 if (!(iBlkY+y+4>iPictureHeight)) 716 { 717 pDepthPels += uiDepthStride*iSubSample; 718 } 719 } 720 721 Int iSizeInBits = g_aucConvertToBit[uiSize] - g_aucConvertToBit[iSubSample]; // respect sub-sampling factor 722 Int iMean = iSumDepth >> iSizeInBits*2; // iMean /= (uiSize*uiSize); 723 724 // start again for segmentation 725 pDepthPels = pDepthBlockStart; 726 727 // start mapping process 728 Int matchedPartSum[2][2] = {{0,0},{0,0}}; // counter for each part size and boolean option 729 PartSize virtualPartSizes[2] = { SIZE_Nx2N, SIZE_2NxN}; 730 731 UInt uiHalfSize = uiSize>>1; 732 for (Int y=0; y<uiSize; y+=iSubSample) 733 { 734 for (Int x=0; x<uiSize; x+=iSubSample) 735 { 736 Int depthPel = 0; 737 if (iBlkX+x>iPictureWidth) 738 { 739 depthPel = pDepthPels[t]; 740 } 741 else 742 { 743 depthPel = pDepthPels[x]; 744 t=x; 745 } 746 747 // decide which segment this pixel belongs to 748 Int ucSegment = (Int)(depthPel>iMean); 749 750 // Matched Filter to find optimal (conventional) partitioning 751 752 // SIZE_Nx2N 753 if(x<uiHalfSize) // left 754 { 755 matchedPartSum[0][ucSegment]++; 756 } 757 else // right 758 { 759 matchedPartSum[0][1-ucSegment]++; 760 } 761 762 // SIZE_2NxN 763 if(y<uiHalfSize) // top 764 { 765 matchedPartSum[1][ucSegment]++; 766 } 767 else // bottom 768 { 769 matchedPartSum[1][1-ucSegment]++; 770 } 771 } 772 773 // next row 774 if (!(iBlkY+y+4>iPictureHeight)) 775 { 776 pDepthPels += uiDepthStride*iSubSample; 777 } 778 } 779 780 PartSize matchedPartSize = NUMBER_OF_PART_SIZES; 781 782 Int iMaxMatchSum = 0; 783 for(Int p=0; p<2; p++) // loop over partition 784 { 785 for( Int b=0; b<=1; b++ ) // loop over boolean options 786 { 787 if(matchedPartSum[p][b] > iMaxMatchSum) 788 { 789 iMaxMatchSum = matchedPartSum[p][b]; 790 matchedPartSize = virtualPartSizes[p]; 791 } 792 } 793 } 794 795 AOF( matchedPartSize != NUMBER_OF_PART_SIZES ); 796 797 return matchedPartSize; 798 } 799 800 Bool TComPrediction::getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask, TComDataCU*& pcCU) 801 { 802 const TComSPS* sps = pcCU->getSlice()->getSPS(); 803 UInt uiMaxCUWidth = sps->getMaxCUWidth(); 804 UInt uiMaxCUHeight = sps->getMaxCUHeight(); 805 806 // segmentation of texture block --> mask IDs 807 Pel* pDepthBlockStart = pDepthPels; 808 809 // first compute average of depth block for thresholding 810 Int iSumDepth = 0; 811 Int uiMinDepth = MAX_INT; 812 Int uiMaxDepth = 0; 813 uiMinDepth = pDepthPels[ 0 ]; 814 uiMaxDepth = pDepthPels[ 0 ]; 815 iSumDepth = pDepthPels[ 0 ]; 816 817 Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth(COMPONENT_Y); 818 Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight(COMPONENT_Y); 819 TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag( ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV; 820 if( pcCU->getSlice()->getDepthRefinementFlag( ) ) 821 { 822 cDv.setVer(0); 823 } 824 Int iBlkX = ( pcCU->getCtuRsAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCtus() ) * uiMaxCUWidth + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCtu() ] ]+ ((cDv.getHor()+2)>>2); 825 Int iBlkY = ( pcCU->getCtuRsAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCtus() ) * uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCtu() ] ]+ ((cDv.getVer()+2)>>2); 826 if (iBlkX>(Int)(iPictureWidth - uiWidth)) 827 { 828 iSumDepth += pDepthPels[ iPictureWidth - iBlkX - 1 ]; 829 uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ iPictureWidth - iBlkX - 1 ]); 830 uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ iPictureWidth - iBlkX - 1 ]); 831 } 832 else 833 { 834 iSumDepth += pDepthPels[ uiWidth - 1 ]; 835 uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiWidth - 1 ]); 836 uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiWidth - 1 ]); 837 } 838 if (iBlkY>(Int)(iPictureHeight - uiHeight)) 839 { 840 iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]; 841 uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]); 842 uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]); 843 } 844 else 845 { 846 iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) ]; 847 uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) ]); 848 uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) ]); 849 } 850 if (iBlkY>(Int)(iPictureHeight - uiHeight) && iBlkX>(Int)(iPictureWidth - uiWidth)) 851 { 852 iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]; 853 uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]); 854 uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]); 855 } 856 else if (iBlkY>(Int)(iPictureHeight - uiHeight)) 857 { 858 iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]; 859 uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]); 860 uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]); 861 } 862 else if (iBlkX>(Int)(iPictureWidth - uiWidth)) 863 { 864 iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]; 865 uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]); 866 uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]); 867 } 868 else 869 { 870 iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]; 871 uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]); 872 uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]); 873 } 874 875 // don't generate mask for blocks with small depth range (encoder decision) 876 if( uiMaxDepth - uiMinDepth < 10 ) 877 { 878 return false; 879 } 880 881 AOF(uiWidth==uiHeight); 882 Int iMean = iSumDepth >> 2; 883 884 // start again for segmentation 885 pDepthPels = pDepthBlockStart; 886 887 Bool bInvertMask = pDepthPels[0]>iMean; // top-left segment needs to be mapped to partIdx 0 888 889 // generate mask 890 UInt t=0; 891 UInt uiSumPix[2] = {0,0}; 892 for (Int y=0; y<uiHeight; y++) 893 { 894 for (Int x=0; x<uiHeight; x++) 895 { 896 Int depthPel = 0; 897 if (iBlkX+x>iPictureWidth) 898 { 899 depthPel = pDepthPels[t]; 900 } 901 else 902 { 903 depthPel = pDepthPels[x]; 904 t=x; 905 } 906 907 // decide which segment this pixel belongs to 908 Int ucSegment = (Int)(depthPel>iMean); 909 910 if( bInvertMask ) 911 { 912 ucSegment = 1-ucSegment; 913 } 914 915 // count pixels for each segment 916 uiSumPix[ucSegment]++; 917 918 // set mask value 919 pMask[x] = (Bool)ucSegment; 920 } 921 922 // next row 923 if (!(iBlkY+y+1>iPictureHeight)) 924 pDepthPels += uiDepthStride; 925 pMask += MAX_CU_SIZE; 926 } 927 928 // don't generate valid mask for tiny segments (encoder decision) 929 // each segment needs to cover at least 1/8th of block 930 UInt uiMinPixPerSegment = (uiWidth*uiHeight) >> 3; 931 if( !( uiSumPix[0] > uiMinPixPerSegment && uiSumPix[1] > uiMinPixPerSegment ) ) 932 { 933 return false; 934 } 935 936 // all good 937 return true; 938 } 939 940 Void TComPrediction::combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr, UInt partSize, Int bitDepthY ) 941 { 942 Pel* piSrc[2] = {pInYuv[0]->getAddr(COMPONENT_Y, uiPartAddr), pInYuv[1]->getAddr(COMPONENT_Y, uiPartAddr)}; 943 UInt uiSrcStride = pInYuv[0]->getStride(COMPONENT_Y); 944 Pel* piDst = pOutYuv->getAddr(COMPONENT_Y, uiPartAddr); 945 UInt uiDstStride = pOutYuv->getStride(COMPONENT_Y); 946 947 UInt uiMaskStride= MAX_CU_SIZE; 948 Pel* tmpTar = 0; 949 tmpTar = (Pel *)xMalloc(Pel, uiWidth*uiHeight); 950 951 // backup pointer 952 Bool* pMaskStart = pMask; 953 954 // combine luma first 955 for (Int y=0; y<uiHeight; y++) 956 { 957 for (Int x=0; x<uiWidth; x++) 958 { 959 UChar ucSegment = (UChar)pMask[x]; 960 AOF( ucSegment < 2 ); 961 962 // filtering 963 tmpTar[y*uiWidth+x] = piSrc[ucSegment][x]; 964 } 965 966 piSrc[0] += uiSrcStride; 967 piSrc[1] += uiSrcStride; 968 pMask += uiMaskStride; 969 } 970 971 if (partSize == SIZE_Nx2N) 972 { 973 for (Int y=0; y<uiHeight; y++) 974 { 975 for (Int x=0; x<uiWidth; x++) 976 { 977 Bool l = (x==0)?pMaskStart[y*uiMaskStride+x]:pMaskStart[y*uiMaskStride+x-1]; 978 Bool r = (x==uiWidth-1)?pMaskStart[y*uiMaskStride+x]:pMaskStart[y*uiMaskStride+x+1]; 979 980 Pel left, right; 981 left = (x==0) ? tmpTar[y*uiWidth+x] : tmpTar[y*uiWidth+x-1]; 982 right = (x==uiWidth-1) ? tmpTar[y*uiWidth+x] : tmpTar[y*uiWidth+x+1]; 983 984 piDst[x] = (l!=r) ? ClipBD( Pel(( left + (tmpTar[y*uiWidth+x] << 1) + right ) >> 2 ), bitDepthY) : tmpTar[y*uiWidth+x]; 985 } 986 piDst += uiDstStride; 987 } 988 } 989 else // SIZE_2NxN 990 { 991 for (Int y=0; y<uiHeight; y++) 992 { 993 for (Int x=0; x<uiWidth; x++) 994 { 995 Bool t = (y==0)?pMaskStart[y*uiMaskStride+x]:pMaskStart[(y-1)*uiMaskStride+x]; 996 Bool b = (y==uiHeight-1)?pMaskStart[y*uiMaskStride+x]:pMaskStart[(y+1)*uiMaskStride+x]; 997 998 Pel top, bottom; 999 top = (y==0) ? tmpTar[y*uiWidth+x] : tmpTar[(y-1)*uiWidth+x]; 1000 bottom = (y==uiHeight-1) ? tmpTar[y*uiWidth+x] : tmpTar[(y+1)*uiWidth+x]; 1001 1002 piDst[x] = (t!=b) ? ClipBD( Pel(( top + (tmpTar[y*uiWidth+x] << 1) + bottom ) >> 2 ), bitDepthY) : tmpTar[y*uiWidth+x]; 1003 } 1004 piDst += uiDstStride; 1005 } 1006 } 1007 1008 if ( tmpTar ) 1009 { 1010 xFree(tmpTar); 1011 tmpTar = NULL; 1012 } 1013 1014 // now combine chroma 1015 Pel* piSrcU[2] = { pInYuv[0]->getAddr(COMPONENT_Cb, uiPartAddr), pInYuv[1]->getAddr(COMPONENT_Cb, uiPartAddr) }; 1016 Pel* piSrcV[2] = { pInYuv[0]->getAddr(COMPONENT_Cr, uiPartAddr), pInYuv[1]->getAddr(COMPONENT_Cr, uiPartAddr) }; 1017 UInt uiSrcStrideC = pInYuv[0]->getStride(COMPONENT_Cb); 1018 Pel* piDstU = pOutYuv->getAddr(COMPONENT_Cb, uiPartAddr); 1019 Pel* piDstV = pOutYuv->getAddr(COMPONENT_Cr, uiPartAddr); 1020 UInt uiDstStrideC = pOutYuv->getStride(COMPONENT_Cb); 1021 UInt uiWidthC = uiWidth >> 1; 1022 UInt uiHeightC = uiHeight >> 1; 1023 Pel filSrcU = 0, filSrcV = 0; 1024 Pel* tmpTarU = 0, *tmpTarV = 0; 1025 tmpTarU = (Pel *)xMalloc(Pel, uiWidthC*uiHeightC); 1026 tmpTarV = (Pel *)xMalloc(Pel, uiWidthC*uiHeightC); 1027 pMask = pMaskStart; 1028 1029 for (Int y=0; y<uiHeightC; y++) 1030 { 1031 for (Int x=0; x<uiWidthC; x++) 1032 { 1033 UChar ucSegment = (UChar)pMask[x*2]; 1034 AOF( ucSegment < 2 ); 1035 1036 // filtering 1037 tmpTarU[y*uiWidthC+x] = piSrcU[ucSegment][x]; 1038 tmpTarV[y*uiWidthC+x] = piSrcV[ucSegment][x]; 1039 } 1040 1041 piSrcU[0] += uiSrcStrideC; 1042 piSrcU[1] += uiSrcStrideC; 1043 piSrcV[0] += uiSrcStrideC; 1044 piSrcV[1] += uiSrcStrideC; 1045 pMask += 2*uiMaskStride; 1046 } 1047 1048 if (partSize == SIZE_Nx2N) 1049 { 1050 for (Int y=0; y<uiHeightC; y++) 1051 { 1052 for (Int x=0; x<uiWidthC; x++) 1053 { 1054 Bool l = (x==0)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[y*2*uiMaskStride+(x-1)*2]; 1055 Bool r = (x==uiWidthC-1)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[y*2*uiMaskStride+(x+1)*2]; 1056 1057 Pel leftU, rightU; 1058 leftU = (x==0) ? tmpTarU[y*uiWidthC+x] : tmpTarU[y*uiWidthC+x-1]; 1059 rightU = (x==uiWidthC-1) ? tmpTarU[y*uiWidthC+x] : tmpTarU[y*uiWidthC+x+1]; 1060 Pel leftV, rightV; 1061 leftV = (x==0) ? tmpTarV[y*uiWidthC+x] : tmpTarV[y*uiWidthC+x-1]; 1062 rightV = (x==uiWidthC-1) ? tmpTarV[y*uiWidthC+x] : tmpTarV[y*uiWidthC+x+1]; 1063 1064 if (l!=r) 1065 { 1066 filSrcU = ClipBD( Pel(( leftU + (tmpTarU[y*uiWidthC+x] << 1) + rightU ) >> 2 ), bitDepthY); 1067 filSrcV = ClipBD( Pel(( leftV + (tmpTarV[y*uiWidthC+x] << 1) + rightV ) >> 2 ), bitDepthY); 1068 } 1069 else 1070 { 1071 filSrcU = tmpTarU[y*uiWidthC+x]; 1072 filSrcV = tmpTarV[y*uiWidthC+x]; 1073 } 1074 piDstU[x] = filSrcU; 1075 piDstV[x] = filSrcV; 1076 } 1077 piDstU += uiDstStrideC; 1078 piDstV += uiDstStrideC; 1079 } 1080 } 1081 else 1082 { 1083 for (Int y=0; y<uiHeightC; y++) 1084 { 1085 for (Int x=0; x<uiWidthC; x++) 1086 { 1087 Bool t = (y==0)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[(y-1)*2*uiMaskStride+x*2]; 1088 Bool b = (y==uiHeightC-1)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[(y+1)*2*uiMaskStride+x*2]; 1089 1090 Pel topU, bottomU; 1091 topU = (y==0) ? tmpTarU[y*uiWidthC+x] : tmpTarU[(y-1)*uiWidthC+x]; 1092 bottomU = (y==uiHeightC-1) ? tmpTarU[y*uiWidthC+x] : tmpTarU[(y+1)*uiWidthC+x]; 1093 Pel topV, bottomV; 1094 topV = (y==0) ? tmpTarV[y*uiWidthC+x] : tmpTarV[(y-1)*uiWidthC+x]; 1095 bottomV = (y==uiHeightC-1) ? tmpTarV[y*uiWidthC+x] : tmpTarV[(y+1)*uiWidthC+x]; 1096 1097 if (t!=b) 1098 { 1099 filSrcU = ClipBD( Pel(( topU + (tmpTarU[y*uiWidthC+x] << 1) + bottomU ) >> 2 ), bitDepthY); 1100 filSrcV = ClipBD( Pel(( topV + (tmpTarV[y*uiWidthC+x] << 1) + bottomV ) >> 2 ), bitDepthY); 1101 } 1102 else 1103 { 1104 filSrcU = tmpTarU[y*uiWidthC+x]; 1105 filSrcV = tmpTarV[y*uiWidthC+x]; 1106 } 1107 piDstU[x] = filSrcU; 1108 piDstV[x] = filSrcV; 1109 } 1110 piDstU += uiDstStrideC; 1111 piDstV += uiDstStrideC; 1112 } 1113 } 1114 1115 if( tmpTarU ) 1116 { 1117 xFree(tmpTarU); 1118 tmpTarU = NULL; 1119 } 1120 if ( tmpTarV ) 1121 { 1122 xFree(tmpTarV); 1123 tmpTarV = NULL; 1124 } 1125 } 1126 #endif 505 1127 506 1128 507 Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx ) … … 1138 517 { 1139 518 pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); 1140 #if NH_3D_VSP1141 if ( pcCU->getVSPFlag(uiPartAddr) == 0)1142 {1143 #endif1144 519 if ( eRefPicList != REF_PIC_LIST_X ) 1145 520 { … … 1156 531 else 1157 532 { 1158 #if NH_3D_SPIVMP1159 if ( pcCU->getSPIVMPFlag(uiPartAddr)!=0)1160 {1161 Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;1162 1163 pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);1164 1165 UInt uiW[256], uiH[256];1166 UInt uiSPAddr[256];1167 1168 xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr);1169 1170 //MC1171 for (Int i = 0; i < iNumSP; i++)1172 {1173 if (uiW[i]==0 || uiH[i]==0)1174 {1175 continue;1176 }1177 if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] ))1178 {1179 xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred );1180 }1181 else1182 {1183 xPredInterBi (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred);1184 }1185 }1186 }1187 else1188 {1189 #endif1190 533 if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) 1191 534 { … … 1196 539 xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); 1197 540 } 1198 #if NH_3D_SPIVMP 1199 } 1200 #endif 1201 } 1202 #if NH_3D_VSP 1203 } 1204 else 1205 { 1206 if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) 1207 { 1208 xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); 1209 } 1210 else 1211 { 1212 xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); 1213 } 1214 } 1215 #endif 541 } 1216 542 return; 1217 543 } … … 1221 547 pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); 1222 548 1223 #if NH_3D_VSP1224 if ( pcCU->getVSPFlag(uiPartAddr) == 0 )1225 {1226 #endif1227 549 if ( eRefPicList != REF_PIC_LIST_X ) 1228 550 { … … 1239 561 else 1240 562 { 1241 #if NH_3D_SPIVMP1242 if (pcCU->getSPIVMPFlag(uiPartAddr)!=0)1243 {1244 Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;1245 1246 pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);1247 1248 UInt uiW[256], uiH[256];1249 UInt uiSPAddr[256];1250 1251 xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr);1252 //MC1253 for (Int i = 0; i < iNumSP; i++)1254 {1255 if (uiW[i]==0 || uiH[i]==0)1256 {1257 continue;1258 }1259 if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] ))1260 {1261 xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred );1262 }1263 else1264 {1265 xPredInterBi (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred);1266 }1267 }1268 }1269 else1270 {1271 #endif1272 563 if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) 1273 564 { … … 1278 569 xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); 1279 570 } 1280 #if NH_3D_SPIVMP 1281 } 1282 #endif 1283 } 1284 #if NH_3D_VSP 1285 } 1286 else 1287 { 1288 if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) 1289 { 1290 xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); 1291 } 1292 else 1293 { 1294 xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); 1295 } 1296 } 1297 #endif 571 } 1298 572 } 1299 573 return; … … 1319 593 pcCU->checkMvVertRest(cMv, eRefPicList, iRefIdx ); 1320 594 #endif 1321 #if NH_3D_ARP1322 if( pcCU->getARPW( uiPartAddr ) > 0 )1323 {1324 if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC() )1325 {1326 xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , pcYuvPred , bi );1327 }1328 else1329 {1330 xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, bi );1331 }1332 }1333 else1334 {1335 #endif1336 595 1337 596 for (UInt comp=COMPONENT_Y; comp<pcYuvPred->getNumberValidComponents(); comp++) 1338 597 { 1339 598 const ComponentID compID=ComponentID(comp); 1340 #if NH_3D_IC1341 Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() ) && ( isLuma(compID) || (iWidth > 8) );1342 xPredInterBlk(compID, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID))1343 #if NH_3D_ARP1344 , false1345 #endif1346 , bICFlag );1347 #else1348 599 xPredInterBlk (compID, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)) ); 1349 #endif 1350 } 1351 #if NH_3D_ARP 1352 } 1353 #endif 1354 } 1355 1356 #if NH_3D_VSP 1357 Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) 1358 { 1359 Int vspSize = pcCU->getVSPFlag( uiPartAddr ) >> 1; 1360 1361 Int widthSubPU, heightSubPU; 1362 if (vspSize) 1363 { 1364 widthSubPU = 8; 1365 heightSubPU = 4; 1366 } 1367 else 1368 { 1369 widthSubPU = 4; 1370 heightSubPU = 8; 1371 } 1372 xPredInterUniSubPU( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi, widthSubPU, heightSubPU ); 1373 } 1374 1375 Void TComPrediction::xPredInterUniSubPU( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, Int widthSubPU, Int heightSubPU ) 1376 { 1377 UInt numPartsInLine = pcCU->getPic()->getNumPartInCtuWidth(); 1378 UInt horiNumPartsInSubPU = widthSubPU >> 2; 1379 UInt vertNumPartsInSubPU = (heightSubPU >> 2) * numPartsInLine; 1380 1381 UInt partAddrRasterLine = g_auiZscanToRaster[ uiPartAddr ]; 1382 1383 for( Int posY=0; posY<iHeight; posY+=heightSubPU, partAddrRasterLine+=vertNumPartsInSubPU ) 1384 { 1385 UInt partAddrRasterSubPU = partAddrRasterLine; 1386 for( Int posX=0; posX<iWidth; posX+=widthSubPU, partAddrRasterSubPU+=horiNumPartsInSubPU ) 1387 { 1388 UInt partAddrSubPU = g_auiRasterToZscan[ partAddrRasterSubPU ]; 1389 Int refIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( partAddrSubPU ); assert (refIdx >= 0); 1390 TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( partAddrSubPU ); 1391 pcCU->clipMv(cMv); 1392 1393 xPredInterBlk( COMPONENT_Y, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) ); 1394 xPredInterBlk( COMPONENT_Cb, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA) ); 1395 xPredInterBlk( COMPONENT_Cr, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA) ); 1396 } 1397 } 1398 } 1399 #endif 1400 1401 #if NH_3D_ARP 1402 //temporal ARP 1403 Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) 1404 { 1405 Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); 1406 TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); 1407 Bool bTobeScaled = false; 1408 TComPic* pcPicYuvBaseCol = NULL; 1409 TComPic* pcPicYuvBaseRef = NULL; 1410 1411 #if NH_3D_NBDV 1412 DisInfo cDistparity; 1413 cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV; 1414 cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan; 1415 #else 1416 assert(0); // ARP can be applied only when a DV is available 1417 #endif 1418 UChar dW = pcCU->getARPW ( uiPartAddr ); 1419 1420 Int arpRefIdx = pcCU->getSlice()->getFirstTRefIdx(eRefPicList); 1421 if (arpRefIdx < 0 || !pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, cDistparity.m_aVIdxCan)) 1422 { 1423 dW = 0; 1424 bTobeScaled = false; 1425 } 1426 else 1427 { 1428 if( arpRefIdx != iRefIdx ) 1429 { 1430 bTobeScaled = true; 1431 } 1432 pcPicYuvBaseCol = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(), cDistparity.m_aVIdxCan ); 1433 pcPicYuvBaseRef = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC(), cDistparity.m_aVIdxCan ); 1434 } 1435 1436 if(bTobeScaled) 1437 { 1438 Int iCurrPOC = pcCU->getSlice()->getPOC(); 1439 Int iColRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx ); 1440 Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, arpRefIdx ); 1441 Int iScale = pcCU->xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC); 1442 if ( iScale != 4096 ) 1443 { 1444 cMv = cMv.scaleMv( iScale ); 1445 } 1446 iRefIdx = arpRefIdx; 1447 } 1448 1449 pcCU->clipMv(cMv); 1450 TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(); 1451 1452 for (UInt comp=COMPONENT_Y; comp< rpcYuvPred->getNumberValidComponents(); comp++) 1453 { 1454 const ComponentID compID=ComponentID(comp); 1455 xPredInterBlk ( compID, pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 ), pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true ); 1456 } 1457 1458 if( dW > 0 ) 1459 { 1460 TComYuv * pYuvB0 = &m_acYuvPredBase[0]; 1461 TComYuv * pYuvB1 = &m_acYuvPredBase[1]; 1462 1463 TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV; 1464 pcCU->clipMv(cMVwithDisparity); 1465 if (iWidth <= 8) 1466 { 1467 pYuvB0->clear(); pYuvB1->clear(); 1468 } 1469 TComMv cNBDV = cDistparity.m_acNBDV; 1470 pcCU->clipMv( cNBDV ); 1471 1472 TComPicYuv* pcPicYuvBaseColRec = pcPicYuvBaseCol->getPicYuvRec(); 1473 TComPicYuv* pcPicYuvBaseRefRec = pcPicYuvBaseRef->getPicYuvRec(); 1474 1475 UInt uiCompNum = ( iWidth > 8 ) ? 3: 1; 1476 for (UInt comp=COMPONENT_Y; comp< uiCompNum; comp++) 1477 { 1478 const ComponentID compID=ComponentID(comp); 1479 xPredInterBlk ( compID, pcCU, pcPicYuvBaseColRec, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, true, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true ); 1480 xPredInterBlk ( compID, pcCU, pcPicYuvBaseRefRec, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, true, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true ); 1481 } 1482 1483 pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight ); 1484 1485 if( 2 == dW ) 1486 { 1487 pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW ); 1488 } 1489 rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi, pcCU->getSlice()->getSPS()->getBitDepths() ); 1490 } 1491 } 1492 1493 Bool TComPrediction::xCheckBiInterviewARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eBaseRefPicList, TComPic*& pcPicYuvCurrTRef, TComMv& cBaseTMV, Int& iCurrTRefPoc ) 1494 { 1495 Int iRefIdx = pcCU->getCUMvField( eBaseRefPicList )->getRefIdx( uiPartAddr ); 1496 TComMv cDMv = pcCU->getCUMvField( eBaseRefPicList )->getMv( uiPartAddr ); 1497 TComPic* pcPicYuvBaseCol = pcCU->getSlice()->getRefPic( eBaseRefPicList, iRefIdx ); 1498 Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2 + ((cDMv.getHor() + 2)>>2); 1499 Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2); 1500 1501 irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX); 1502 irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); 1503 1504 Int uiLCUAddr,uiAbsPartAddr; 1505 pcPicYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr); 1506 TComDataCU *pColCU = pcPicYuvBaseCol->getCtu( uiLCUAddr ); 1507 1508 TComPic* pcPicYuvBaseTRef = NULL; 1509 pcPicYuvCurrTRef = NULL; 1510 1511 //If there is available motion in base reference list, use it 1512 if(!pColCU->isIntra(uiAbsPartAddr)) 1513 { 1514 for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1); iList ++) 1515 { 1516 RefPicList eRefPicListCurr = RefPicList(iList); 1517 Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr); 1518 if( iRef != -1) 1519 { 1520 pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); 1521 Int iCurrPOC = pColCU->getSlice()->getPOC(); 1522 Int iCurrRefPOC = pcPicYuvBaseTRef->getPOC(); 1523 Int iCurrRef = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr); 1524 1525 if( iCurrRef >= 0 && iCurrPOC != iCurrRefPOC) 1526 { 1527 pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); 1528 Int iTargetPOC = pcPicYuvCurrTRef->getPOC(); 1529 pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic(iTargetPOC, pcPicYuvBaseCol->getViewIndex() ); 1530 if(pcPicYuvBaseTRef) 1531 { 1532 cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr); 1533 Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC); 1534 if ( iScale != 4096 ) 1535 { 1536 cBaseTMV = cBaseTMV.scaleMv( iScale ); 1537 } 1538 iCurrTRefPoc = iTargetPOC; 1539 return true; 1540 } 1541 } 1542 } 1543 } 1544 } 1545 1546 //If there is no available motion in base reference list, use ( 0, 0 ) 1547 if( pcCU->getSlice()->getFirstTRefIdx( eBaseRefPicList ) >= 0 ) 1548 { 1549 cBaseTMV.set( 0, 0 ); 1550 pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic( eBaseRefPicList, pcCU->getSlice()->getFirstTRefIdx( eBaseRefPicList ) ); 1551 iCurrTRefPoc = pcPicYuvCurrTRef->getPOC(); 1552 return true; 1553 } 1554 1555 return false; 1556 } 1557 1558 //inter-view ARP 1559 Void TComPrediction::xPredInterUniARPviewRef( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) 1560 { 1561 Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); 1562 TComMv cDMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); 1563 TComMv cTempDMv = cDMv; 1564 UChar dW = pcCU->getARPW ( uiPartAddr ); 1565 1566 TComPic* pcPicYuvBaseTRef = NULL; 1567 TComPic* pcPicYuvCurrTRef = NULL; 1568 TComPic* pcPicYuvBaseCol = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx ); 1569 TComPicYuv* pcYuvBaseCol = pcPicYuvBaseCol->getPicYuvRec(); 1570 Bool bTMVAvai = false; 1571 TComMv cBaseTMV; 1572 1573 pcCU->clipMv(cTempDMv); 1574 1575 Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2 + ((cDMv.getHor() + 2)>>2); 1576 Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2); 1577 1578 irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX); 1579 irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); 1580 1581 Int uiLCUAddr,uiAbsPartAddr; 1582 pcPicYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr); 1583 TComDataCU *pColCU = pcPicYuvBaseCol->getCtu( uiLCUAddr ); 1584 if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getIsDepth() ) 1585 { 1586 RefPicList eOtherRefList = ( eRefPicList == REF_PIC_LIST_0 ) ? REF_PIC_LIST_1 : REF_PIC_LIST_0; 1587 Int iOtherRefIdx = pcCU->getCUMvField( eOtherRefList )->getRefIdx( uiPartAddr ); 1588 //The other prediction direction is temporal ARP 1589 if( iOtherRefIdx >= 0 && pcCU->getSlice()->getViewIndex() == pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx )->getViewIndex() ) 1590 { 1591 bTMVAvai = true; 1592 pcPicYuvBaseTRef = pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx ); 1593 Int iCurrPOC = pcCU->getSlice()->getPOC(); 1594 Int iCurrRefPOC = pcPicYuvBaseTRef->getPOC(); 1595 Int iCurrRef = pcCU->getSlice()->getFirstTRefIdx( eOtherRefList ); 1596 1597 if( iCurrRef >= 0 ) 1598 { 1599 pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic( eOtherRefList,iCurrRef ); 1600 Int iTargetPOC = pcPicYuvCurrTRef->getPOC(); 1601 pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic( iTargetPOC, pcPicYuvBaseCol->getViewIndex() ); 1602 if( pcPicYuvBaseTRef ) 1603 { 1604 cBaseTMV = pcCU->getCUMvField( eOtherRefList )->getMv( uiPartAddr ); 1605 Int iScale = pcCU-> xGetDistScaleFactor( iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC ); 1606 if ( iScale != 4096 ) 1607 { 1608 cBaseTMV = cBaseTMV.scaleMv( iScale ); 1609 } 1610 } 1611 else 1612 { 1613 dW = 0; 1614 } 1615 } 1616 else 1617 { 1618 dW = 0; 1619 } 1620 } 1621 1622 //Both prediction directions are inter-view ARP 1623 if ( iOtherRefIdx >= 0 && !bTMVAvai ) 1624 { 1625 RefPicList eBaseList = REF_PIC_LIST_0; 1626 Int iCurrTRefPoc; 1627 bTMVAvai = ( eBaseList != eRefPicList ) && ( pcCU->getSlice()->getViewIndex() != pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx )->getViewIndex() ); 1628 1629 if ( bTMVAvai ) 1630 { 1631 if( xCheckBiInterviewARP( pcCU, uiPartAddr, iWidth, iHeight, eBaseList, pcPicYuvCurrTRef, cBaseTMV, iCurrTRefPoc ) ) 1632 { 1633 pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic( iCurrTRefPoc, pcPicYuvBaseCol->getViewIndex() ); 1634 if ( pcPicYuvBaseTRef == NULL ) 1635 { 1636 dW = 0; 1637 } 1638 } 1639 else 1640 { 1641 dW = 0; 1642 } 1643 } 1644 } 1645 } 1646 1647 if( !pColCU->isIntra( uiAbsPartAddr ) && !bTMVAvai ) 1648 { 1649 TComMvField puMVField; 1650 for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1) && !bTMVAvai; iList ++) 1651 { 1652 RefPicList eRefPicListCurr = RefPicList(iList); 1653 Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr); 1654 if( iRef != -1 && pcCU->getSlice()->getArpRefPicAvailable( eRefPicListCurr, pcPicYuvBaseCol->getViewIndex())) 1655 { 1656 pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); 1657 Int iCurrPOC = pColCU->getSlice()->getPOC(); 1658 Int iCurrRefPOC = pcPicYuvBaseTRef->getPOC(); 1659 Int iCurrRef = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr); 1660 if (iCurrRef >= 0 && iCurrRefPOC != iCurrPOC) 1661 { 1662 pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); 1663 Int iTargetPOC = pcPicYuvCurrTRef->getPOC(); 1664 { 1665 pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic(iTargetPOC, pcPicYuvBaseCol->getViewIndex() ); 1666 if(pcPicYuvBaseTRef) 1667 { 1668 cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr); 1669 Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC); 1670 if ( iScale != 4096 ) 1671 cBaseTMV = cBaseTMV.scaleMv( iScale ); 1672 bTMVAvai = true; 1673 break; 1674 } 1675 } 1676 } 1677 } 1678 } 1679 } 1680 if (bTMVAvai == false) 1681 { 1682 bTMVAvai = true; 1683 cBaseTMV.set(0, 0); 1684 pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicList, pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); 1685 pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic (eRefPicList, pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); 1686 } 1687 1688 for (UInt comp=COMPONENT_Y; comp< rpcYuvPred->getNumberValidComponents(); comp++) 1689 { 1690 const ComponentID compID=ComponentID(comp); 1691 xPredInterBlk ( compID, pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 && bTMVAvai ), pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), bTMVAvai ); 1692 } 1693 1694 if( dW > 0 ) 1695 { 1696 assert ( bTMVAvai ); 1697 TComYuv* pYuvCurrTRef = &m_acYuvPredBase[0]; 1698 TComYuv* pYuvBaseTRef = &m_acYuvPredBase[1]; 1699 TComPicYuv* pcYuvCurrTref = pcPicYuvCurrTRef->getPicYuvRec(); 1700 TComPicYuv* pcYuvBaseTref = pcPicYuvBaseTRef->getPicYuvRec(); 1701 TComMv cTempMv = cDMv + cBaseTMV; 1702 1703 pcCU->clipMv(cBaseTMV); 1704 pcCU->clipMv(cTempMv); 1705 1706 if (iWidth <= 8) 1707 { 1708 pYuvCurrTRef->clear(); pYuvBaseTRef->clear(); 1709 } 1710 1711 UInt uiCompNum = ( iWidth > 8 ) ? 3: 1; 1712 for (UInt comp=COMPONENT_Y; comp< uiCompNum; comp++) 1713 { 1714 const ComponentID compID=ComponentID(comp); 1715 xPredInterBlk ( compID, pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, true, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true ); 1716 xPredInterBlk ( compID, pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv, iWidth, iHeight, pYuvBaseTRef, true, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true ); 1717 } 1718 1719 pYuvCurrTRef->subtractARP( pYuvCurrTRef , pYuvBaseTRef , uiPartAddr , iWidth , iHeight ); 1720 if(dW == 2) 1721 { 1722 pYuvCurrTRef->multiplyARP( uiPartAddr , iWidth , iHeight , dW ); 1723 } 1724 rpcYuvPred->addARP( rpcYuvPred , pYuvCurrTRef , uiPartAddr , iWidth , iHeight , !bi, pcCU->getSlice()->getSPS()->getBitDepths() ); 1725 } 1726 } 1727 #endif 600 } 601 } 602 603 1728 604 1729 605 Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv* pcYuvPred ) … … 1777 653 } 1778 654 1779 #if NH_3D_VSP1780 Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )1781 {1782 TComYuv* pcMbYuv;1783 Int iRefIdx[2] = {-1, -1};1784 Bool bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0);1785 1786 for ( Int iRefList = 0; iRefList < 2; iRefList++ )1787 {1788 RefPicList eRefPicList = RefPicList(iRefList);1789 iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );1790 1791 if ( iRefIdx[iRefList] < 0 )1792 {1793 continue;1794 }1795 assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );1796 1797 pcMbYuv = &m_acYuvPred[iRefList];1798 xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi );1799 }1800 1801 xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred, pcCU->getSlice()->getSPS()->getBitDepths() );1802 }1803 #endif1804 655 1805 656 /** … … 1819 670 1820 671 1821 #if NH_3D1822 Void TComPrediction::xPredInterBlk(const ComponentID compID, TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *dstPic, Bool bi, const Int bitDepth1823 #if NH_3D_ARP1824 , Bool filterType1825 #endif1826 #if NH_3D_IC1827 , Bool bICFlag1828 #endif1829 )1830 #else1831 672 Void TComPrediction::xPredInterBlk(const ComponentID compID, TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *dstPic, Bool bi, const Int bitDepth ) 1832 #endif1833 673 { 1834 674 #if NH_MV … … 1849 689 Int yFrac = mv->getVer() & ((1<<shiftVer)-1); 1850 690 1851 #if NH_3D_INTEGER_MV_DEPTH1852 if( cu->getSlice()->getIsDepth() )1853 {1854 refOffset = mv->getHor() + mv->getVer() * refStride;1855 ref = refPic->getAddr(compID, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refOffset;1856 xFrac = 0;1857 yFrac = 0;1858 }1859 #endif1860 691 1861 692 UInt cxWidth = width >> refPic->getComponentScaleX(compID); … … 1866 697 if ( yFrac == 0 ) 1867 698 { 1868 #if NH_3D1869 m_if.filterHor(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, xFrac, !bi1870 #if NH_3D_IC1871 || bICFlag1872 #endif1873 , chFmt, bitDepth1874 #if NH_3D_ARP1875 , filterType1876 #endif1877 );1878 #else1879 699 m_if.filterHor(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, xFrac, !bi, chFmt, bitDepth ); 1880 #endif1881 700 } 1882 701 else if ( xFrac == 0 ) 1883 702 { 1884 #if NH_3D1885 m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi1886 #if NH_3D_IC1887 || bICFlag1888 #endif1889 , chFmt, bitDepth1890 #if NH_3D_ARP1891 , filterType1892 #endif1893 );1894 #else1895 703 m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi, chFmt, bitDepth ); 1896 704 1897 #endif1898 705 } 1899 706 else … … 1904 711 const Int vFilterSize = isLuma(compID) ? NTAPS_LUMA : NTAPS_CHROMA; 1905 712 1906 #if NH_3D_ARP1907 m_if.filterHor(compID, ref - ((vFilterSize>>1) -1)*refStride, refStride, tmp, tmpStride, cxWidth, cxHeight+vFilterSize-1, xFrac, false, chFmt, bitDepth, filterType );1908 #else1909 713 m_if.filterHor(compID, ref - ((vFilterSize>>1) -1)*refStride, refStride, tmp, tmpStride, cxWidth, cxHeight+vFilterSize-1, xFrac, false, chFmt, bitDepth ); 1910 #endif 1911 1912 #if NH_3D 1913 m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight, yFrac, false, !bi 1914 #if NH_3D_IC 1915 || bICFlag 1916 #endif 1917 , chFmt, bitDepth 1918 #if NH_3D_ARP 1919 , filterType 1920 #endif 1921 ); 1922 #else 714 1923 715 m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight, yFrac, false, !bi, chFmt, bitDepth ); 1924 #endif 1925 } 1926 1927 #if NH_3D_IC 1928 if( bICFlag ) 1929 { 1930 Int a, b, i, j; 1931 const Int iShift = IC_CONST_SHIFT; 1932 Pel *dst2 = dst; 1933 1934 xGetLLSICPrediction( compID, cu, mv, refPic, a, b, bitDepth ); 1935 1936 for ( i = 0; i < cxHeight; i++ ) 1937 { 1938 for ( j = 0; j < cxWidth; j++ ) 1939 { 1940 dst[j] = Clip3( 0, ( 1 << bitDepth ) - 1, ( ( a*dst[j] ) >> iShift ) + b ); 1941 } 1942 dst += dstStride; 1943 } 1944 1945 if(bi) 1946 { 1947 Int shift = IF_INTERNAL_PREC - bitDepth; 1948 for (i = 0; i < cxHeight; i++) 1949 { 1950 for (j = 0; j < cxWidth; j++) 1951 { 1952 Pel val = dst2[j] << shift; 1953 dst2[j] = val - (Pel)IF_INTERNAL_OFFS; 1954 } 1955 dst2 += dstStride; 1956 } 1957 } 1958 } 1959 #endif 716 } 717 1960 718 1961 719 } … … 2104 862 (uiDirMode==HOR_IDX || uiDirMode==VER_IDX); 2105 863 } 2106 #if NH_3D_IC 2107 /** Function for deriving the position of first non-zero binary bit of a value 2108 * \param x input value 2109 * 2110 * This function derives the position of first non-zero binary bit of a value 2111 */ 2112 Int GetMSB( UInt x ) 2113 { 2114 Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1; 2115 2116 while( x > 1 ) 2117 { 2118 bits >>= 1; 2119 y = x >> bits; 2120 2121 if( y ) 2122 { 2123 x = y; 2124 iMSB += bits; 2125 } 2126 } 2127 2128 iMSB+=y; 2129 2130 return iMSB; 2131 } 2132 2133 2134 /** Function for deriving LM illumination compensation. 2135 */ 2136 Void TComPrediction::xGetLLSICPrediction( const ComponentID compID, TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, const Int bitDepth ) 2137 { 2138 TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec(); 2139 Pel *pRec = NULL, *pRef = NULL; 2140 UInt uiWidth, uiHeight, uiTmpPartIdx; 2141 Int iRecStride = pRecPic->getStride(compID); 2142 Int iRefStride = pRefPic->getStride(compID); 2143 Int iRefOffset, iHor, iVer; 2144 iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 ); 2145 iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 ); 2146 if( !isLuma(compID) ) 2147 { 2148 iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 ); 2149 iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 ); 2150 } 2151 uiWidth = pcCU->getWidth( 0 ) >> pRefPic->getComponentScaleX(compID); 2152 uiHeight = pcCU->getHeight( 0 ) >> pRefPic->getComponentScaleY(compID); 2153 2154 Int i, j, iCountShift = 0; 2155 2156 // LLS parameters estimation 2157 2158 Int x = 0, y = 0, xx = 0, xy = 0; 2159 Int precShift = std::max(0, bitDepth - 12); 2160 2161 UInt partAddr = 0; 2162 if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCtu() ) ) 2163 { 2164 iRefOffset = iHor + iVer * iRefStride - iRefStride; 2165 pRef = pRefPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) + iRefOffset; 2166 pRec = pRecPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) - iRecStride; 2167 for( j = 0; j < uiWidth; j+=2 ) 2168 { 2169 x += pRef[j]; 2170 y += pRec[j]; 2171 if( isLuma(compID) ) 2172 { 2173 xx += (pRef[j] * pRef[j])>>precShift; 2174 xy += (pRef[j] * pRec[j])>>precShift; 2175 } 2176 } 2177 iCountShift += g_aucConvertToBit[ uiWidth ] + 1; 2178 } 2179 2180 if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCtu() ) ) 2181 { 2182 iRefOffset = iHor + iVer * iRefStride - 1; 2183 pRef = pRefPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) + iRefOffset; 2184 pRec = pRecPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) - 1; 2185 for( i = 0; i < uiHeight; i+=2 ) 2186 { 2187 x += pRef[0]; 2188 y += pRec[0]; 2189 if( isLuma(compID) ) 2190 { 2191 xx += (pRef[0] * pRef[0])>>precShift; 2192 xy += (pRef[0] * pRec[0])>>precShift; 2193 } 2194 pRef += iRefStride*2; 2195 pRec += iRecStride*2; 2196 } 2197 iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 ); 2198 } 2199 2200 if( iCountShift == 0 ) 2201 { 2202 a = ( 1 << IC_CONST_SHIFT ); 2203 b = 0; 2204 return; 2205 } 2206 2207 if( !isLuma(compID) ) 2208 { 2209 a = ( 1 << IC_CONST_SHIFT ); 2210 b = ( y - x + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; 2211 } 2212 else 2213 { 2214 xy += xx >> IC_REG_COST_SHIFT; 2215 xx += xx >> IC_REG_COST_SHIFT; 2216 Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift); 2217 Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift); 2218 const Int iShift = IC_CONST_SHIFT; 2219 const Int iShiftA2 = 6; 2220 const Int iAccuracyShift = 15; 2221 2222 Int iScaleShiftA2 = 0; 2223 Int iScaleShiftA1 = 0; 2224 Int a1s; 2225 Int a2s; 2226 2227 a1 = Clip3(0, 2*a2, a1); 2228 iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; 2229 iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF; 2230 2231 if( iScaleShiftA1 < 0 ) 2232 { 2233 iScaleShiftA1 = 0; 2234 } 2235 2236 if( iScaleShiftA2 < 0 ) 2237 { 2238 iScaleShiftA2 = 0; 2239 } 2240 2241 Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1; 2242 2243 2244 a2s = a2 >> iScaleShiftA2; 2245 2246 a1s = a1 >> iScaleShiftA1; 2247 2248 a = a1s * m_uiaShift[ a2s ]; 2249 a = a >> iScaleShiftA; 2250 b = ( y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; 2251 } 2252 } 2253 #endif 2254 2255 #if NH_3D_SDC_INTRA 2256 Void TComPrediction::predConstantSDC( Pel* ptrSrc, UInt srcStride, UInt uiSize, Pel& predDC ) 2257 { 2258 Pel* pLeftTop = ptrSrc; 2259 Pel* pRightTop = ptrSrc + (uiSize-1); 2260 Pel* pLeftBottom = (ptrSrc+ (srcStride*(uiSize-1)) ); 2261 Pel* pRightBottom = (ptrSrc+ (srcStride*(uiSize-1)) + (uiSize-1)); 2262 predDC = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2; 2263 } 2264 #endif // NH_3D_SDC_INTRA 2265 2266 #if NH_3D_DMM 2267 Void TComPrediction::predContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool* segPattern ) 2268 { 2269 // get copy of co-located texture luma block 2270 TComYuv cTempYuv; 2271 cTempYuv.create( uiWidth, uiHeight, CHROMA_400 ); 2272 cTempYuv.clear(); 2273 Pel* piRefBlkY = cTempYuv.getAddr( COMPONENT_Y ); 2274 TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec(); 2275 assert( pcPicYuvRef != NULL ); 2276 Int iRefStride = pcPicYuvRef->getStride( COMPONENT_Y ); 2277 Pel* piRefY = pcPicYuvRef->getAddr ( COMPONENT_Y, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx ); 2278 2279 for( Int y = 0; y < uiHeight; y++ ) 2280 { 2281 ::memcpy(piRefBlkY, piRefY, sizeof(Pel)*uiWidth); 2282 piRefBlkY += uiWidth; 2283 piRefY += iRefStride; 2284 } 2285 2286 2287 // find contour for texture luma block 2288 piRefBlkY = cTempYuv.getAddr( COMPONENT_Y ); 2289 UInt iDC = 0; 2290 iDC = piRefBlkY[ 0 ]; 2291 iDC += piRefBlkY[ uiWidth - 1 ]; 2292 iDC += piRefBlkY[ uiWidth * (uiHeight - 1) ]; 2293 iDC += piRefBlkY[ uiWidth * (uiHeight - 1) + uiWidth - 1 ]; 2294 iDC = iDC >> 2; 2295 2296 piRefBlkY = cTempYuv.getAddr( COMPONENT_Y ); 2297 for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 2298 { 2299 segPattern[k] = (piRefBlkY[k] > iDC) ? true : false; 2300 } 2301 2302 cTempYuv.destroy(); 2303 } 2304 2305 Void TComPrediction::predBiSegDCs( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 ) 2306 { 2307 assert( biSegPattern ); 2308 const Pel *piMask = getPredictorPtr( COMPONENT_Y, false ); 2309 assert( piMask ); 2310 Int srcStride = 2*uiWidth + 1; 2311 const Pel *ptrSrc = piMask+srcStride+1; 2312 2313 Int refDC1, refDC2; 2314 const Int iTR = ( patternStride - 1 ) - srcStride; 2315 const Int iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride; 2316 const Int iLB = ( patternStride - 1 ) * srcStride - 1; 2317 const Int iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1; 2318 2319 Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] ); 2320 Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)] ); 2321 2322 if( bL == bT ) 2323 { 2324 const Int iTRR = ( patternStride * 2 - 1 ) - srcStride; 2325 const Int iLBB = ( patternStride * 2 - 1 ) * srcStride - 1; 2326 refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : (abs(ptrSrc[iTRR] - ptrSrc[-(Int)srcStride]) > abs(ptrSrc[iLBB] - ptrSrc[ -1]) ? ptrSrc[iTRR] : ptrSrc[iLBB]); 2327 refDC2 = ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1; 2328 } 2329 else 2330 { 2331 refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR]; 2332 refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM]; 2333 } 2334 2335 predDC1 = biSegPattern[0] ? refDC1 : refDC2; 2336 predDC2 = biSegPattern[0] ? refDC2 : refDC1; 2337 } 2338 2339 Void TComPrediction::assignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 ) 2340 { 2341 assert( biSegPattern ); 2342 if( dstStride == patternStride ) 2343 { 2344 for( UInt k = 0; k < (patternStride * patternStride); k++ ) 2345 { 2346 if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; } 2347 else { ptrDst[k] = valDC1; } 2348 } 2349 } 2350 else 2351 { 2352 Pel* piTemp = ptrDst; 2353 for( UInt uiY = 0; uiY < patternStride; uiY++ ) 2354 { 2355 for( UInt uiX = 0; uiX < patternStride; uiX++ ) 2356 { 2357 if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; } 2358 else { piTemp[uiX] = valDC1; } 2359 } 2360 piTemp += dstStride; 2361 biSegPattern += patternStride; 2362 } 2363 } 2364 } 2365 #endif 864 865 2366 866 //! \}
Note: See TracChangeset for help on using the changeset viewer.