Changeset 56 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComYuv.cpp
- Timestamp:
- 11 May 2012, 21:20:17 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibCommon/TComYuv.cpp
r21 r56 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 1,ISO/IEC6 * Copyright (c) 2010-2012, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 15 15 * this list of conditions and the following disclaimer in the documentation 16 16 * and/or other materials provided with the distribution. 17 * * Neither the name of the I SO/IEC nor the names of its contributors may17 * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may 18 18 * be used to endorse or promote products derived from this software without 19 19 * specific prior written permission. … … 32 32 */ 33 33 34 35 36 34 /** \file TComYuv.cpp 37 35 \brief general YUV buffer class … … 46 44 #include "CommonDef.h" 47 45 #include "TComYuv.h" 46 #include "TComInterpolationFilter.h" 47 48 //! \ingroup TLibCommon 49 //! \{ 48 50 49 51 TComYuv::TComYuv() … … 56 58 TComYuv::~TComYuv() 57 59 { 58 }59 60 Void TComYuv::printout()61 {62 Int x, y;63 64 Pel* pSrc = getLumaAddr( );65 Int iStride = getStride();66 67 68 printf("\nY ...");69 for ( y = 0; y < iStride; y++ )70 {71 printf ("\n");72 for ( x = 0; x < iStride; x++ )73 {74 printf ("%d ", pSrc[x]);75 }76 pSrc += iStride;77 }78 60 } 79 61 … … 306 288 } 307 289 #endif 308 290 309 291 Void TComYuv::copyPartToPartYuv ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight ) 310 292 { … … 320 302 Pel* pSrc = getLumaAddr(uiPartIdx); 321 303 Pel* pDst = pcYuvDst->getLumaAddr() + uiBlkY * pcYuvDst->getStride() + uiBlkX; 322 304 323 305 if( pSrc == pDst ) 324 306 { … … 327 309 return ; 328 310 } 329 311 330 312 UInt iSrcStride = getStride(); 331 313 UInt iDstStride = pcYuvDst->getStride(); … … 402 384 for ( x = uiPartSize-1; x >= 0; x-- ) 403 385 { 404 pDst[x] = xClip( pSrc0[x] + pSrc1[x] );386 pDst[x] = Clip( pSrc0[x] + pSrc1[x] ); 405 387 } 406 388 pSrc0 += iSrc0Stride; … … 410 392 } 411 393 412 Void 394 395 Void 413 396 TComYuv::add( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract ) 414 397 { … … 417 400 } 418 401 419 Void 402 Void 420 403 TComYuv::addLuma( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract ) 421 404 { … … 434 417 } 435 418 436 Void 419 Void 437 420 TComYuv::addChroma( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract ) 438 421 { … … 455 438 } 456 439 457 Void 440 Void 458 441 TComYuv::clip( Int iWidth, Int iHeight ) 459 442 { … … 462 445 } 463 446 464 Void 447 Void 465 448 TComYuv::clipLuma( Int iWidth, Int iHeight ) 466 449 { … … 476 459 } 477 460 478 Void 461 Void 479 462 TComYuv::clipChroma( Int iWidth, Int iHeight ) 480 463 { … … 492 475 } 493 476 494 495 477 Void TComYuv::addClip( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) 496 478 { … … 514 496 for ( x = uiPartSize-1; x >= 0; x-- ) 515 497 { 516 pDst[x] = xClip( pSrc0[x] + pSrc1[x] );498 pDst[x] = Clip( pSrc0[x] + pSrc1[x] ); 517 499 } 518 500 pSrc0 += iSrc0Stride; … … 540 522 for ( x = uiPartSize-1; x >= 0; x-- ) 541 523 { 542 pDstU[x] = xClip( pSrcU0[x] + pSrcU1[x] );543 pDstV[x] = xClip( pSrcV0[x] + pSrcV1[x] );524 pDstU[x] = Clip( pSrcU0[x] + pSrcU1[x] ); 525 pDstV[x] = Clip( pSrcV0[x] + pSrcV1[x] ); 544 526 } 545 527 … … 612 594 } 613 595 614 #ifdef ROUNDING_CONTROL_BIPRED 615 616 Void TComYuv::addAvg( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight, Bool bRound ) 596 Void TComYuv::addAvg( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight ) 617 597 { 618 598 Int x, y; … … 633 613 UInt iSrc1Stride = pcYuvSrc1->getStride(); 634 614 UInt iDstStride = getStride(); 635 636 #if HIGH_ACCURACY_BI 637 Int shiftNum = 15 - (g_uiBitDepth + g_uiBitIncrement); 638 Int offset = (1<<(shiftNum - 1)); 639 640 for ( y = iHeight-1; y >= 0; y-- ) 641 { 642 for ( x = iWidth-1; x >= 0; ) 643 { 644 // note: luma min width is 4 645 pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum ); x--; 646 pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--; 647 pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--; 648 pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--; 615 Int shiftNum = IF_INTERNAL_PREC + 1 - ( g_uiBitDepth + g_uiBitIncrement ); 616 Int offset = ( 1 << ( shiftNum - 1 ) ) + 2 * IF_INTERNAL_OFFS; 617 618 for ( y = 0; y < iHeight; y++ ) 619 { 620 for ( x = 0; x < iWidth; x += 4 ) 621 { 622 pDstY[ x + 0 ] = Clip( ( pSrcY0[ x + 0 ] + pSrcY1[ x + 0 ] + offset ) >> shiftNum ); 623 pDstY[ x + 1 ] = Clip( ( pSrcY0[ x + 1 ] + pSrcY1[ x + 1 ] + offset ) >> shiftNum ); 624 pDstY[ x + 2 ] = Clip( ( pSrcY0[ x + 2 ] + pSrcY1[ x + 2 ] + offset ) >> shiftNum ); 625 pDstY[ x + 3 ] = Clip( ( pSrcY0[ x + 3 ] + pSrcY1[ x + 3 ] + offset ) >> shiftNum ); 649 626 } 650 627 pSrcY0 += iSrc0Stride; … … 678 655 pDstV += iDstStride; 679 656 } 680 681 #else682 683 for ( y = iHeight-1; y >= 0; y-- )684 {685 for ( x = iWidth-1; x >= 0; )686 {687 // note: luma min width is 4688 pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--;689 pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--;690 pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--;691 pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--;692 }693 pSrcY0 += iSrc0Stride;694 pSrcY1 += iSrc1Stride;695 pDstY += iDstStride;696 }697 698 iSrc0Stride = pcYuvSrc0->getCStride();699 iSrc1Stride = pcYuvSrc1->getCStride();700 iDstStride = getCStride();701 702 iWidth >>=1;703 iHeight >>=1;704 705 for ( y = iHeight-1; y >= 0; y-- )706 {707 for ( x = iWidth-1; x >= 0; )708 {709 // note: chroma min width is 2710 pDstU[x] = (pSrcU0[x] + pSrcU1[x] + bRound) >> 1;711 pDstV[x] = (pSrcV0[x] + pSrcV1[x] + bRound) >> 1; x--;712 pDstU[x] = (pSrcU0[x] + pSrcU1[x] + bRound) >> 1;713 pDstV[x] = (pSrcV0[x] + pSrcV1[x] + bRound) >> 1; x--;714 }715 716 pSrcU0 += iSrc0Stride;717 pSrcU1 += iSrc1Stride;718 pSrcV0 += iSrc0Stride;719 pSrcV1 += iSrc1Stride;720 pDstU += iDstStride;721 pDstV += iDstStride;722 }723 #endif724 }725 726 #endif727 728 Void TComYuv::addAvg( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight )729 {730 Int x, y;731 732 Pel* pSrcY0 = pcYuvSrc0->getLumaAddr( iPartUnitIdx );733 Pel* pSrcU0 = pcYuvSrc0->getCbAddr ( iPartUnitIdx );734 Pel* pSrcV0 = pcYuvSrc0->getCrAddr ( iPartUnitIdx );735 736 Pel* pSrcY1 = pcYuvSrc1->getLumaAddr( iPartUnitIdx );737 Pel* pSrcU1 = pcYuvSrc1->getCbAddr ( iPartUnitIdx );738 Pel* pSrcV1 = pcYuvSrc1->getCrAddr ( iPartUnitIdx );739 740 Pel* pDstY = getLumaAddr( iPartUnitIdx );741 Pel* pDstU = getCbAddr ( iPartUnitIdx );742 Pel* pDstV = getCrAddr ( iPartUnitIdx );743 744 UInt iSrc0Stride = pcYuvSrc0->getStride();745 UInt iSrc1Stride = pcYuvSrc1->getStride();746 UInt iDstStride = getStride();747 #if HIGH_ACCURACY_BI748 Int shiftNum = 15 - (g_uiBitDepth + g_uiBitIncrement);749 Int offset = (1<<(shiftNum - 1));750 751 for ( y = iHeight-1; y >= 0; y-- )752 {753 for ( x = iWidth-1; x >= 0; )754 {755 // note: luma min width is 4756 pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum ); x--;757 pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;758 pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;759 pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;760 }761 pSrcY0 += iSrc0Stride;762 pSrcY1 += iSrc1Stride;763 pDstY += iDstStride;764 }765 766 iSrc0Stride = pcYuvSrc0->getCStride();767 iSrc1Stride = pcYuvSrc1->getCStride();768 iDstStride = getCStride();769 770 iWidth >>=1;771 iHeight >>=1;772 773 for ( y = iHeight-1; y >= 0; y-- )774 {775 for ( x = iWidth-1; x >= 0; )776 {777 // note: chroma min width is 2778 pDstU[x] = Clip((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum);779 pDstV[x] = Clip((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--;780 pDstU[x] = Clip((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum);781 pDstV[x] = Clip((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--;782 }783 784 pSrcU0 += iSrc0Stride;785 pSrcU1 += iSrc1Stride;786 pSrcV0 += iSrc0Stride;787 pSrcV1 += iSrc1Stride;788 pDstU += iDstStride;789 pDstV += iDstStride;790 }791 792 #else793 for ( y = iHeight-1; y >= 0; y-- )794 {795 for ( x = iWidth-1; x >= 0; )796 {797 // note: luma min width is 4798 pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--;799 pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--;800 pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--;801 pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--;802 }803 pSrcY0 += iSrc0Stride;804 pSrcY1 += iSrc1Stride;805 pDstY += iDstStride;806 }807 808 iSrc0Stride = pcYuvSrc0->getCStride();809 iSrc1Stride = pcYuvSrc1->getCStride();810 iDstStride = getCStride();811 812 iWidth >>=1;813 iHeight >>=1;814 815 for ( y = iHeight-1; y >= 0; y-- )816 {817 for ( x = iWidth-1; x >= 0; )818 {819 // note: chroma min width is 2820 pDstU[x] = (pSrcU0[x] + pSrcU1[x] + 1) >> 1;821 pDstV[x] = (pSrcV0[x] + pSrcV1[x] + 1) >> 1; x--;822 pDstU[x] = (pSrcU0[x] + pSrcU1[x] + 1) >> 1;823 pDstV[x] = (pSrcV0[x] + pSrcV1[x] + 1) >> 1; x--;824 }825 826 pSrcU0 += iSrc0Stride;827 pSrcU1 += iSrc1Stride;828 pSrcV0 += iSrc0Stride;829 pSrcV1 += iSrc1Stride;830 pDstU += iDstStride;831 pDstV += iDstStride;832 }833 #endif834 657 } 835 658 … … 844 667 Pel* pSrcY1 = pcYuvSrc1->getLumaAddr( iPartUnitIdx ); 845 668 Pel* pDstY = getLumaAddr() + uiBlkY * getStride() + uiBlkX; 846 669 847 670 UInt iSrc0Stride = pcYuvSrc0->getStride(); 848 671 UInt iSrc1Stride = pcYuvSrc1->getStride(); … … 862 685 #endif 863 686 864 865 Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiWidht, UInt uiHeight ) 687 Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight ) 866 688 { 867 689 Int x, y; 868 690 869 Pel* pSrc = pcYuvSrc->getLumaAddr( );870 Pel* pSrcU = pcYuvSrc->getCbAddr( );871 Pel* pSrcV = pcYuvSrc->getCrAddr( );872 873 Pel* pDst = m_apiBufY;874 Pel* pDstU = m_apiBufU;875 Pel* pDstV = m_apiBufV;691 Pel* pSrc = pcYuvSrc->getLumaAddr(uiPartIdx); 692 Pel* pSrcU = pcYuvSrc->getCbAddr(uiPartIdx); 693 Pel* pSrcV = pcYuvSrc->getCrAddr(uiPartIdx); 694 695 Pel* pDst = getLumaAddr(uiPartIdx); 696 Pel* pDstU = getCbAddr(uiPartIdx); 697 Pel* pDstV = getCrAddr(uiPartIdx); 876 698 877 699 Int iSrcStride = pcYuvSrc->getStride(); … … 882 704 for ( x = uiWidht-1; x >= 0; x-- ) 883 705 { 884 pDst[x ] = xClip( (pDst[x ]<<1) - pSrc[x ] ); 706 #if DISABLING_CLIP_FOR_BIPREDME 707 pDst[x ] = (pDst[x ]<<1) - pSrc[x ] ; 708 #else 709 pDst[x ] = Clip( (pDst[x ]<<1) - pSrc[x ] ); 710 #endif 885 711 } 886 712 pSrc += iSrcStride; … … 898 724 for ( x = uiWidht-1; x >= 0; x-- ) 899 725 { 900 pDstU[x ] = xClip( (pDstU[x ]<<1) - pSrcU[x ] ); 901 pDstV[x ] = xClip( (pDstV[x ]<<1) - pSrcV[x ] ); 726 #if DISABLING_CLIP_FOR_BIPREDME 727 pDstU[x ] = (pDstU[x ]<<1) - pSrcU[x ] ; 728 pDstV[x ] = (pDstV[x ]<<1) - pSrcV[x ] ; 729 #else 730 pDstU[x ] = Clip( (pDstU[x ]<<1) - pSrcU[x ] ); 731 pDstV[x ] = Clip( (pDstV[x ]<<1) - pSrcV[x ] ); 732 #endif 902 733 } 903 734 pSrcU += iSrcStride; … … 907 738 } 908 739 } 909 910 Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight ) 911 { 912 Int x, y; 913 914 Pel* pSrc = pcYuvSrc->getLumaAddr(uiPartIdx); 915 Pel* pSrcU = pcYuvSrc->getCbAddr(uiPartIdx); 916 Pel* pSrcV = pcYuvSrc->getCrAddr(uiPartIdx); 917 918 Pel* pDst = getLumaAddr(uiPartIdx); 919 Pel* pDstU = getCbAddr(uiPartIdx); 920 Pel* pDstV = getCrAddr(uiPartIdx); 921 922 Int iSrcStride = pcYuvSrc->getStride(); 923 Int iDstStride = getStride(); 924 925 for ( y = uiHeight-1; y >= 0; y-- ) 926 { 927 for ( x = uiWidht-1; x >= 0; x-- ) 928 { 929 pDst[x ] = xClip( (pDst[x ]<<1) - pSrc[x ] ); 930 } 931 pSrc += iSrcStride; 932 pDst += iDstStride; 933 } 934 935 iSrcStride = pcYuvSrc->getCStride(); 936 iDstStride = getCStride(); 937 938 uiHeight >>= 1; 939 uiWidht >>= 1; 940 941 for ( y = uiHeight-1; y >= 0; y-- ) 942 { 943 for ( x = uiWidht-1; x >= 0; x-- ) 944 { 945 pDstU[x ] = xClip( (pDstU[x ]<<1) - pSrcU[x ] ); 946 pDstV[x ] = xClip( (pDstV[x ]<<1) - pSrcV[x ] ); 947 } 948 pSrcU += iSrcStride; 949 pSrcV += iSrcStride; 950 pDstU += iDstStride; 951 pDstV += iDstStride; 952 } 953 } 954 955 956 Pel* TComYuv::getLumaAddr( UInt uiPartUnitIdx ) 957 { 958 UInt iBlkX; 959 UInt iBlkY; 960 iBlkX = g_auiRasterToPelX[g_auiZscanToRaster[uiPartUnitIdx]]; 961 iBlkY = g_auiRasterToPelY[g_auiZscanToRaster[uiPartUnitIdx]]; 962 963 return m_apiBufY + iBlkY*getStride() + iBlkX; 964 } 965 966 Pel* TComYuv::getCbAddr( UInt uiPartUnitIdx ) 967 { 968 UInt iBlkX; 969 UInt iBlkY; 970 iBlkX = g_auiRasterToPelX[g_auiZscanToRaster[uiPartUnitIdx]] >> 1; 971 iBlkY = g_auiRasterToPelY[g_auiZscanToRaster[uiPartUnitIdx]] >> 1; 972 973 return m_apiBufU + iBlkY*getCStride() + iBlkX; 974 } 975 976 Pel* TComYuv::getCrAddr( UInt uiPartUnitIdx ) 977 { 978 UInt iBlkX; 979 UInt iBlkY; 980 iBlkX = g_auiRasterToPelX[g_auiZscanToRaster[uiPartUnitIdx]] >> 1; 981 iBlkY = g_auiRasterToPelY[g_auiZscanToRaster[uiPartUnitIdx]] >> 1; 982 983 return m_apiBufV + iBlkY*getCStride() + iBlkX; 984 } 985 986 Pel* TComYuv::getLumaAddr( UInt iTransUnitIdx, UInt iBlkSize ) 987 { 988 UInt uiNumTrInWidth = m_iWidth / iBlkSize; 989 UInt iBlkX = iTransUnitIdx % uiNumTrInWidth; 990 UInt iBlkY = iTransUnitIdx / uiNumTrInWidth; 991 992 return m_apiBufY + (iBlkX + iBlkY * getStride()) * iBlkSize; 993 } 994 995 Pel* TComYuv::getCbAddr( UInt iTransUnitIdx, UInt iBlkSize ) 996 { 997 UInt uiNumTrInWidth = m_iCWidth / iBlkSize; 998 UInt iBlkX = iTransUnitIdx % uiNumTrInWidth; 999 UInt iBlkY = iTransUnitIdx / uiNumTrInWidth; 1000 1001 return m_apiBufU + (iBlkX + iBlkY * getCStride()) * iBlkSize; 1002 } 1003 1004 Pel* TComYuv::getCrAddr( UInt iTransUnitIdx, UInt iBlkSize ) 1005 { 1006 UInt uiNumTrInWidth = m_iCWidth / iBlkSize; 1007 UInt iBlkX = iTransUnitIdx % uiNumTrInWidth; 1008 UInt iBlkY = iTransUnitIdx / uiNumTrInWidth; 1009 1010 return m_apiBufV + (iBlkX + iBlkY * getCStride()) * iBlkSize; 1011 } 740 //! \}
Note: See TracChangeset for help on using the changeset viewer.