HEVC學習(十) —— 與變換有關的幾個主要函數及重要變量

本文主要是列出幾個與變換有關的函數,以及涉及到的比較重要的變量,但不會去深入討論函數的實現,日後有機會的話會更詳細地討論這幾個函數,這裏僅是列舉出來,起到備忘的作用,也能供大家參考。

 

如何定位到這幾個函數的,方法與前面的一篇博客HEVC學習(八) —— 以SAO爲例淺析跟蹤代碼方法類似,有興趣的朋友可以去看看,這裏就不重複這個過程了。

 

在xCompressCU函數中,有這麼幾個函數值得我們注意的,xCheckRDCostInter、xCheckRDCostMerge2Nx2N、xCheckRDCostIntra。它們分別是實現幀間預測模式、Merge模式、幀內預測式的主函數。前兩個函數的子函數xEstimateResidualQT(實際上通過調用函數encodeResAndCalcRdInterCU)、第三個函數的子函數xRecurIntraCodingQT(實際上通過調用xIntraCodingLumaBlk、xIntraCodingChromaBlk)均會調用函數transformNxN,該函數如下定義:

  1. Void TComTrQuant::transformNxN( TComDataCU* pcCU,  
  2.                                Pel*        pcResidual,   
  3.                                UInt        uiStride,   
  4.                                TCoeff*     rpcCoeff,   
  5. #if ADAPTIVE_QP_SELECTION  
  6.                                Int*&       rpcArlCoeff,   
  7. #endif  
  8.                                UInt        uiWidth,   
  9.                                UInt        uiHeight,   
  10.                                UInt&       uiAbsSum,   
  11.                                TextType    eTType,   
  12.                                UInt        uiAbsPartIdx,  
  13.                                Bool        useTransformSkip  
  14.                                )  
  15. {  
  16.   if (pcCU->getCUTransquantBypass(uiAbsPartIdx))  
  17.   {  
  18.     uiAbsSum=0;  
  19.     for (UInt k = 0; k<uiHeight; k++)  
  20.     {  
  21.       for (UInt j = 0; j<uiWidth; j++)  
  22.       {  
  23.         rpcCoeff[k*uiWidth+j]= pcResidual[k*uiStride+j];  
  24.         uiAbsSum += abs(pcResidual[k*uiStride+j]);  
  25.       }  
  26.     }  
  27.     return;  
  28.   }  
  29.   UInt uiMode;  //luma intra pred  
  30.   if(eTType == TEXT_LUMA && pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA )  
  31.   {  
  32.     uiMode = pcCU->getLumaIntraDir( uiAbsPartIdx );  
  33.   }  
  34.   else  
  35.   {  
  36.     uiMode = REG_DCT;  
  37.   }  
  38.     
  39.   uiAbsSum = 0;  
  40.   assert( (pcCU->getSlice()->getSPS()->getMaxTrSize() >= uiWidth) );  
  41.   if(useTransformSkip)  
  42.   {  
  43.     xTransformSkip( pcResidual, uiStride, m_plTempCoeff, uiWidth, uiHeight );  
  44.   }  
  45.   else  
  46.   {  
  47.     xT( uiMode, pcResidual, uiStride, m_plTempCoeff, uiWidth, uiHeight );  
  48.   }  
  49.   xQuant( pcCU, m_plTempCoeff, rpcCoeff,  
  50. #if ADAPTIVE_QP_SELECTION  
  51.        rpcArlCoeff,  
  52. #endif  
  53.        uiWidth, uiHeight, uiAbsSum, eTType, uiAbsPartIdx );  
  54. }  

這個函數主要調用了xTransformSkip、xT、xQuant三個函數,分別實現對殘差進行TS(Transform Skip)模式、普通變換模式以及量化的功能。對於第二個函數xT來說,它調用了xTrNxN,該函數的實現如下所示:

  1. /** MxN forward transform (2D) 
  2. *  \param block input data (residual) 
  3. *  \param coeff output data (transform coefficients) 
  4. *  \param iWidth input data (width of transform) 
  5. *  \param iHeight input data (height of transform) 
  6. */  
  7. void xTrMxN(short *block,short *coeff, int iWidth, int iHeight, UInt uiMode)  
  8. {  
  9. #if FULL_NBIT  
  10.   int shift_1st = g_aucConvertToBit[iWidth]  + 1 + g_uiBitDepth - 8; // log2(iWidth) - 1 + g_uiBitDepth - 8  
  11. #else  
  12.   int shift_1st = g_aucConvertToBit[iWidth]  + 1 + g_uiBitIncrement; // log2(iWidth) - 1 + g_uiBitIncrement  
  13. #endif  
  14.   int shift_2nd = g_aucConvertToBit[iHeight]  + 8;                   // log2(iHeight) + 6  
  15.   
  16.   short tmp[ 64 * 64 ];  
  17.   
  18. #if !REMOVE_NSQT  
  19.   if( iWidth == 16 && iHeight == 4)  
  20.   {  
  21.     partialButterfly16( block, tmp, shift_1st, iHeight );  
  22.     partialButterfly4( tmp, coeff, shift_2nd, iWidth );  
  23.   }  
  24.   else if( iWidth == 32 && iHeight == 8 )  
  25.   {  
  26.     partialButterfly32( block, tmp, shift_1st, iHeight );  
  27.     partialButterfly8( tmp, coeff, shift_2nd, iWidth );  
  28.   }  
  29.   else if( iWidth == 4 && iHeight == 16)  
  30.   {  
  31.     partialButterfly4( block, tmp, shift_1st, iHeight );  
  32.     partialButterfly16( tmp, coeff, shift_2nd, iWidth );  
  33.   }  
  34.   else if( iWidth == 8 && iHeight == 32 )  
  35.   {  
  36.     partialButterfly8( block, tmp, shift_1st, iHeight );  
  37.     partialButterfly32( tmp, coeff, shift_2nd, iWidth );  
  38.   }  
  39.   else  
  40. #endif  
  41.   if( iWidth == 4 && iHeight == 4)  
  42.   {  
  43. #if INTRA_TRANS_SIMP  
  44.     if (uiMode != REG_DCT)  
  45.     {  
  46.       fastForwardDst(block,tmp,shift_1st); // Forward DST BY FAST ALGORITHM, block input, tmp output  
  47.       fastForwardDst(tmp,coeff,shift_2nd); // Forward DST BY FAST ALGORITHM, tmp input, coeff output  
  48.     }  
  49.     else  
  50.     {  
  51.       partialButterfly4(block, tmp, shift_1st, iHeight);  
  52.       partialButterfly4(tmp, coeff, shift_2nd, iWidth);  
  53.     }  
  54.   
  55. #else  
  56.     if (uiMode != REG_DCT && (!uiMode || (uiMode>=2 && uiMode <= 25)))    // Check for DCT or DST  
  57.     {  
  58.       fastForwardDst(block,tmp,shift_1st); // Forward DST BY FAST ALGORITHM, block input, tmp output  
  59.     }  
  60.     else    
  61.     {  
  62.       partialButterfly4(block, tmp, shift_1st, iHeight);  
  63.     }  
  64.     if (uiMode != REG_DCT && (!uiMode || (uiMode>=11 && uiMode <= 34)))    // Check for DCT or DST  
  65.     {  
  66.       fastForwardDst(tmp,coeff,shift_2nd); // Forward DST BY FAST ALGORITHM, tmp input, coeff output  
  67.     }  
  68.     else    
  69.     {  
  70.       partialButterfly4(tmp, coeff, shift_2nd, iWidth);  
  71.     }  
  72. #endif  
  73.   }  
  74.   else if( iWidth == 8 && iHeight == 8)  
  75.   {  
  76.     partialButterfly8( block, tmp, shift_1st, iHeight );  
  77.     partialButterfly8( tmp, coeff, shift_2nd, iWidth );  
  78.   }  
  79.   else if( iWidth == 16 && iHeight == 16)  
  80.   {  
  81.     partialButterfly16( block, tmp, shift_1st, iHeight );  
  82.     partialButterfly16( tmp, coeff, shift_2nd, iWidth );  
  83.   }  
  84.   else if( iWidth == 32 && iHeight == 32)  
  85.   {  
  86.     partialButterfly32( block, tmp, shift_1st, iHeight );  
  87.     partialButterfly32( tmp, coeff, shift_2nd, iWidth );  
  88.   }  
  89. }  

到了這裏,相信大家光看名字也能看出這些代碼是做什麼事情的了,對幀內預測模式的4x4塊進行DST變換,其餘的根據塊大小分別做蝶形快速變換(4x4,8x8,16x16,32x32),不同尺寸的變換矩陣在代碼中如下表示:

  1. const short g_aiT4[4][4] =  
  2. {  
  3.   { 64, 64, 64, 64},  
  4.   { 83, 36,-36,-83},  
  5.   { 64,-64,-64, 64},  
  6.   { 36,-83, 83,-36}  
  7. };  
  8.   
  9. const short g_aiT8[8][8] =  
  10. {  
  11.   { 64, 64, 64, 64, 64, 64, 64, 64},  
  12.   { 89, 75, 50, 18,-18,-50,-75,-89},  
  13.   { 83, 36,-36,-83,-83,-36, 36, 83},  
  14.   { 75,-18,-89,-50, 50, 89, 18,-75},  
  15.   { 64,-64,-64, 64, 64,-64,-64, 64},  
  16.   { 50,-89, 18, 75,-75,-18, 89,-50},  
  17.   { 36,-83, 83,-36,-36, 83,-83, 36},  
  18.   { 18,-50, 75,-89, 89,-75, 50,-18}  
  19. };  
  20.   
  21. const short g_aiT16[16][16] =  
  22. {  
  23.   { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},  
  24.   { 90, 87, 80, 70, 57, 43, 25,  9, -9,-25,-43,-57,-70,-80,-87,-90},  
  25.   { 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89},  
  26.   { 87, 57,  9,-43,-80,-90,-70,-25, 25, 70, 90, 80, 43, -9,-57,-87},  
  27.   { 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83},  
  28.   { 80,  9,-70,-87,-25, 57, 90, 43,-43,-90,-57, 25, 87, 70, -9,-80},  
  29.   { 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75},  
  30.   { 70,-43,-87,  9, 90, 25,-80,-57, 57, 80,-25,-90, -9, 87, 43,-70},  
  31.   { 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64},  
  32.   { 57,-80,-25, 90, -9,-87, 43, 70,-70,-43, 87,  9,-90, 25, 80,-57},  
  33.   { 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50},  
  34.   { 43,-90, 57, 25,-87, 70,  9,-80, 80, -9,-70, 87,-25,-57, 90,-43},  
  35.   { 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36},  
  36.   { 25,-70, 90,-80, 43,  9,-57, 87,-87, 57, -9,-43, 80,-90, 70,-25},  
  37.   { 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18},  
  38.   {  9,-25, 43,-57, 70,-80, 87,-90, 90,-87, 80,-70, 57,-43, 25, -9}  
  39. };  
  40.   
  41. const short g_aiT32[32][32] =  
  42. {  
  43.   { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},  
  44.   { 90, 90, 88, 85, 82, 78, 73, 67, 61, 54, 46, 38, 31, 22, 13,  4, -4,-13,-22,-31,-38,-46,-54,-61,-67,-73,-78,-82,-85,-88,-90,-90},  
  45.   { 90, 87, 80, 70, 57, 43, 25,  9, -9,-25,-43,-57,-70,-80,-87,-90,-90,-87,-80,-70,-57,-43,-25, -9,  9, 25, 43, 57, 70, 80, 87, 90},  
  46.   { 90, 82, 67, 46, 22, -4,-31,-54,-73,-85,-90,-88,-78,-61,-38,-13, 13, 38, 61, 78, 88, 90, 85, 73, 54, 31,  4,-22,-46,-67,-82,-90},  
  47.   { 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89, 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89},  
  48.   { 88, 67, 31,-13,-54,-82,-90,-78,-46, -4, 38, 73, 90, 85, 61, 22,-22,-61,-85,-90,-73,-38,  4, 46, 78, 90, 82, 54, 13,-31,-67,-88},  
  49.   { 87, 57,  9,-43,-80,-90,-70,-25, 25, 70, 90, 80, 43, -9,-57,-87,-87,-57, -9, 43, 80, 90, 70, 25,-25,-70,-90,-80,-43,  9, 57, 87},  
  50.   { 85, 46,-13,-67,-90,-73,-22, 38, 82, 88, 54, -4,-61,-90,-78,-31, 31, 78, 90, 61,  4,-54,-88,-82,-38, 22, 73, 90, 67, 13,-46,-85},  
  51.   { 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83},  
  52.   { 82, 22,-54,-90,-61, 13, 78, 85, 31,-46,-90,-67,  4, 73, 88, 38,-38,-88,-73, -4, 67, 90, 46,-31,-85,-78,-13, 61, 90, 54,-22,-82},  
  53.   { 80,  9,-70,-87,-25, 57, 90, 43,-43,-90,-57, 25, 87, 70, -9,-80,-80, -9, 70, 87, 25,-57,-90,-43, 43, 90, 57,-25,-87,-70,  9, 80},  
  54.   { 78, -4,-82,-73, 13, 85, 67,-22,-88,-61, 31, 90, 54,-38,-90,-46, 46, 90, 38,-54,-90,-31, 61, 88, 22,-67,-85,-13, 73, 82,  4,-78},  
  55.   { 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75, 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75},  
  56.   { 73,-31,-90,-22, 78, 67,-38,-90,-13, 82, 61,-46,-88, -4, 85, 54,-54,-85,  4, 88, 46,-61,-82, 13, 90, 38,-67,-78, 22, 90, 31,-73},  
  57.   { 70,-43,-87,  9, 90, 25,-80,-57, 57, 80,-25,-90, -9, 87, 43,-70,-70, 43, 87, -9,-90,-25, 80, 57,-57,-80, 25, 90,  9,-87,-43, 70},  
  58.   { 67,-54,-78, 38, 85,-22,-90,  4, 90, 13,-88,-31, 82, 46,-73,-61, 61, 73,-46,-82, 31, 88,-13,-90, -4, 90, 22,-85,-38, 78, 54,-67},  
  59.   { 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64},  
  60.   { 61,-73,-46, 82, 31,-88,-13, 90, -4,-90, 22, 85,-38,-78, 54, 67,-67,-54, 78, 38,-85,-22, 90,  4,-90, 13, 88,-31,-82, 46, 73,-61},  
  61.   { 57,-80,-25, 90, -9,-87, 43, 70,-70,-43, 87,  9,-90, 25, 80,-57,-57, 80, 25,-90,  9, 87,-43,-70, 70, 43,-87, -9, 90,-25,-80, 57},  
  62.   { 54,-85, -4, 88,-46,-61, 82, 13,-90, 38, 67,-78,-22, 90,-31,-73, 73, 31,-90, 22, 78,-67,-38, 90,-13,-82, 61, 46,-88,  4, 85,-54},  
  63.   { 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50, 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50},  
  64.   { 46,-90, 38, 54,-90, 31, 61,-88, 22, 67,-85, 13, 73,-82,  4, 78,-78, -4, 82,-73,-13, 85,-67,-22, 88,-61,-31, 90,-54,-38, 90,-46},  
  65.   { 43,-90, 57, 25,-87, 70,  9,-80, 80, -9,-70, 87,-25,-57, 90,-43,-43, 90,-57,-25, 87,-70, -9, 80,-80,  9, 70,-87, 25, 57,-90, 43},  
  66.   { 38,-88, 73, -4,-67, 90,-46,-31, 85,-78, 13, 61,-90, 54, 22,-82, 82,-22,-54, 90,-61,-13, 78,-85, 31, 46,-90, 67,  4,-73, 88,-38},  
  67.   { 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36},  
  68.   { 31,-78, 90,-61,  4, 54,-88, 82,-38,-22, 73,-90, 67,-13,-46, 85,-85, 46, 13,-67, 90,-73, 22, 38,-82, 88,-54, -4, 61,-90, 78,-31},  
  69.   { 25,-70, 90,-80, 43,  9,-57, 87,-87, 57, -9,-43, 80,-90, 70,-25,-25, 70,-90, 80,-43, -9, 57,-87, 87,-57,  9, 43,-80, 90,-70, 25},  
  70.   { 22,-61, 85,-90, 73,-38, -4, 46,-78, 90,-82, 54,-13,-31, 67,-88, 88,-67, 31, 13,-54, 82,-90, 78,-46,  4, 38,-73, 90,-85, 61,-22},  
  71.   { 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18, 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18},  
  72.   { 13,-38, 61,-78, 88,-90, 85,-73, 54,-31,  4, 22,-46, 67,-82, 90,-90, 82,-67, 46,-22, -4, 31,-54, 73,-85, 90,-88, 78,-61, 38,-13},  
  73.   {  9,-25, 43,-57, 70,-80, 87,-90, 90,-87, 80,-70, 57,-43, 25, -9, -9, 25,-43, 57,-70, 80,-87, 90,-90, 87,-80, 70,-57, 43,-25,  9},  
  74.   {  4,-13, 22,-31, 38,-46, 54,-61, 67,-73, 78,-82, 85,-88, 90,-90, 90,-90, 88,-85, 82,-78, 73,-67, 61,-54, 46,-38, 31,-22, 13, -4}  
  75. };  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章