[677] | 1 | #include <cstdio> |
---|
| 2 | #include <cstdlib> |
---|
| 3 | #include <cstring> |
---|
| 4 | #include <cmath> |
---|
| 5 | #include <algorithm> |
---|
| 6 | |
---|
| 7 | #include "TEnc3DAsymLUT.h" |
---|
| 8 | |
---|
[1212] | 9 | #if CGS_3D_ASYMLUT |
---|
[677] | 10 | TEnc3DAsymLUT::TEnc3DAsymLUT() |
---|
| 11 | { |
---|
| 12 | m_pColorInfo = NULL; |
---|
| 13 | m_pColorInfoC = NULL; |
---|
| 14 | m_pEncCuboid = NULL; |
---|
[877] | 15 | |
---|
[677] | 16 | m_pBestEncCuboid = NULL; |
---|
[825] | 17 | m_nAccuFrameBit = 0; |
---|
| 18 | m_nAccuFrameCGSBit = 0; |
---|
| 19 | m_nPrevFrameCGSPartNumLog2 = 0; |
---|
[677] | 20 | m_dTotalFrameBit = 0; |
---|
| 21 | m_nTotalCGSBit = 0; |
---|
| 22 | m_nPPSBit = 0; |
---|
| 23 | m_pDsOrigPic = NULL; |
---|
[877] | 24 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 25 | m_pMaxColorInfo = NULL; |
---|
| 26 | m_pMaxColorInfoC = NULL; |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | // fixed m_dDistFactor |
---|
| 30 | Double dTmpFactor[3]; |
---|
| 31 | dTmpFactor[I_SLICE] = 1.0; |
---|
| 32 | dTmpFactor[P_SLICE] = 4./3.; |
---|
| 33 | dTmpFactor[B_SLICE] = 1.5; |
---|
| 34 | for( Int iSliceType = 0; iSliceType < 3; iSliceType++) |
---|
| 35 | { |
---|
| 36 | for(Int iLayer = 0; iLayer < MAX_TLAYER; iLayer++) |
---|
| 37 | { |
---|
| 38 | m_dDistFactor[iSliceType][iLayer] = dTmpFactor[iSliceType]*(Double)(1<<iLayer); |
---|
| 39 | } |
---|
| 40 | } |
---|
| 41 | // initialization with approximate number of bits to code the LUT |
---|
| 42 | m_nNumLUTBits[0][0] = 200; // 1x1x1 |
---|
| 43 | m_nNumLUTBits[1][0] = 400; // 2x1x1 |
---|
| 44 | m_nNumLUTBits[1][1] = 1500; // 2x2x2 |
---|
| 45 | m_nNumLUTBits[2][0] = 800; // 4x1x1 |
---|
| 46 | m_nNumLUTBits[2][1] = 3200; // 4x2x2 |
---|
| 47 | m_nNumLUTBits[2][2] = 8500; // 4x4x4 |
---|
| 48 | m_nNumLUTBits[3][0] = 1200; // 8x1x1 |
---|
| 49 | m_nNumLUTBits[3][1] = 4500; // 8x2x2 |
---|
| 50 | m_nNumLUTBits[3][2] = 10000; // 8x4x4 |
---|
| 51 | m_nNumLUTBits[3][3] = 12000; // 8x8x8 |
---|
| 52 | #endif |
---|
[677] | 53 | } |
---|
| 54 | |
---|
| 55 | Void TEnc3DAsymLUT::create( Int nMaxOctantDepth , Int nInputBitDepth , Int nInputBitDepthC , Int nOutputBitDepth , Int nOutputBitDepthC , Int nMaxYPartNumLog2 ) |
---|
| 56 | { |
---|
| 57 | if( m_pColorInfo != NULL ) |
---|
[684] | 58 | { |
---|
[677] | 59 | destroy(); |
---|
[684] | 60 | } |
---|
| 61 | |
---|
[1214] | 62 | TCom3DAsymLUT::create( nMaxOctantDepth , nInputBitDepth , nInputBitDepthC, nOutputBitDepth , nOutputBitDepthC, nMaxYPartNumLog2, 1 << ( nInputBitDepthC - 1 ) , 1 << ( nInputBitDepthC - 1 ) ); |
---|
| 63 | |
---|
[677] | 64 | xAllocate3DArray( m_pColorInfo , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
| 65 | xAllocate3DArray( m_pColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
| 66 | xAllocate3DArray( m_pEncCuboid , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
| 67 | xAllocate3DArray( m_pBestEncCuboid , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
[877] | 68 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 69 | xAllocate3DArray( m_pMaxColorInfo , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
| 70 | xAllocate3DArray( m_pMaxColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
| 71 | |
---|
| 72 | m_pEncCavlc = new TEncCavlc; |
---|
| 73 | m_pBitstreamRedirect = new TComOutputBitstream; |
---|
| 74 | m_pEncCavlc->setBitstream(m_pBitstreamRedirect); |
---|
| 75 | #endif |
---|
[677] | 76 | } |
---|
| 77 | |
---|
| 78 | Void TEnc3DAsymLUT::destroy() |
---|
| 79 | { |
---|
| 80 | xFree3DArray( m_pColorInfo ); |
---|
| 81 | xFree3DArray( m_pColorInfoC ); |
---|
| 82 | xFree3DArray( m_pEncCuboid ); |
---|
| 83 | xFree3DArray( m_pBestEncCuboid ); |
---|
[877] | 84 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 85 | xFree3DArray( m_pMaxColorInfo ); |
---|
| 86 | xFree3DArray( m_pMaxColorInfoC ); |
---|
| 87 | delete m_pBitstreamRedirect; |
---|
| 88 | delete m_pEncCavlc; |
---|
| 89 | #endif |
---|
[677] | 90 | TCom3DAsymLUT::destroy(); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | TEnc3DAsymLUT::~TEnc3DAsymLUT() |
---|
| 94 | { |
---|
| 95 | if( m_dTotalFrameBit != 0 ) |
---|
[684] | 96 | { |
---|
[677] | 97 | printf( "\nTotal CGS bit: %d, %.2lf%%" , m_nTotalCGSBit , m_nTotalCGSBit * 100 / m_dTotalFrameBit ); |
---|
[684] | 98 | } |
---|
| 99 | |
---|
[677] | 100 | destroy(); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | Double TEnc3DAsymLUT::xxDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY , |
---|
[825] | 104 | Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit ) |
---|
| 105 | { |
---|
| 106 | Int nInitP0 = rP0; |
---|
| 107 | Int nInitP1 = rP1; |
---|
| 108 | Int nInitP3 = rP3; |
---|
| 109 | Int nInitP7 = rP7; |
---|
| 110 | |
---|
| 111 | const Int nOne = xGetNormCoeffOne(); |
---|
| 112 | Double dNorm = (N * yy * vv * uu - N * yy * uv * uv - N * yv * yv * uu - N * vv * yu * yu + 2 * N * yv * uv * yu - yy * vs * vs * uu + 2 * yy * vs * uv * us - yy * vv * us * us - 2 * vs * uv * yu * ys + uv * uv * ys * ys + vs * vs * yu * yu - 2 * yv * vs * us * yu + 2 * yv * vs * ys * uu - 2 * yv * uv * us * ys + 2 * vv * yu * ys * us - vv * uu * ys * ys + yv * yv * us * us); |
---|
| 113 | if( N > 16 && dNorm != 0 ) |
---|
| 114 | { |
---|
| 115 | Double dInitA = (-N * uu * yv * Yv + N * uu * Yy * vv - N * Yy * uv * uv + N * yv * uv * Yu - N * yu * Yu * vv + N * yu * uv * Yv + yu * us * Ys * vv - vs * ys * uv * Yu - yu * vs * us * Yv - yv * uv * us * Ys - yv * vs * us * Yu - yu * uv * vs * Ys - ys * us * uv * Yv + ys * us * Yu * vv + 2 * Yy * vs * uv * us + uu * yv * vs * Ys - uu * ys * Ys * vv + uu * vs * ys * Yv + ys * Ys * uv * uv - Yy * vv * us * us + yu * Yu * vs * vs + yv * Yv * us * us - uu * Yy * vs * vs) / dNorm; |
---|
| 116 | Double dInitB = (N * yy * Yu * vv - N * yy * uv * Yv - N * Yu * yv * yv - N * yu * Yy * vv + N * uv * yv * Yy + N * yv * yu * Yv - yy * us * Ys * vv + yy * uv * vs * Ys - yy * Yu * vs * vs + yy * vs * us * Yv - uv * vs * ys * Yy - yv * yu * vs * Ys + yu * Yy * vs * vs + yu * ys * Ys * vv - uv * yv * ys * Ys + 2 * Yu * yv * vs * ys + us * ys * Yy * vv - vs * ys * yu * Yv + uv * ys * ys * Yv + us * Ys * yv * yv - Yu * ys * ys * vv - yv * ys * us * Yv - vs * us * yv * Yy) / dNorm; |
---|
| 117 | Double dInitC = -(-N * yy * Yv * uu + N * yy * uv * Yu - N * yv * yu * Yu - N * uv * yu * Yy + N * Yv * yu * yu + N * yv * Yy * uu - yy * uv * us * Ys + yy * Yv * us * us + yy * vs * Ys * uu - yy * vs * us * Yu + yv * ys * us * Yu - vs * Ys * yu * yu - yv * ys * Ys * uu + vs * us * yu * Yy + vs * ys * yu * Yu - uv * Yu * ys * ys + Yv * uu * ys * ys - yv * Yy * us * us - 2 * Yv * yu * ys * us - vs * ys * Yy * uu + uv * us * ys * Yy + uv * yu * ys * Ys + yv * yu * us * Ys) / dNorm; |
---|
| 118 | nInitP0 = ( Int )( dInitA * nOne + 0.5 ) >> nResQuantBit << nResQuantBit; |
---|
| 119 | nInitP1 = ( Int )( dInitB * nOne + 0.5 ) >> nResQuantBit << nResQuantBit; |
---|
| 120 | nInitP3 = ( Int )( dInitC * nOne + 0.5 ) >> nResQuantBit << nResQuantBit; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | Int nMin = - ( 1 << ( m_nLUTBitDepth - 1 ) ); |
---|
| 124 | Int nMax = - nMin - ( 1 << nResQuantBit ); |
---|
| 125 | Int nMask = ( 1 << nResQuantBit ) - 1; |
---|
| 126 | |
---|
| 127 | Double dMinError = MAX_DOUBLE; |
---|
| 128 | Int nTestRange = 2; |
---|
| 129 | Int nStepSize = 1 << nResQuantBit; |
---|
| 130 | for( Int i = - nTestRange ; i <= nTestRange ; i++ ) |
---|
| 131 | { |
---|
| 132 | for( Int j = - nTestRange ; j <= nTestRange ; j++ ) |
---|
| 133 | { |
---|
| 134 | for( Int k = - nTestRange ; k <= nTestRange ; k++ ) |
---|
| 135 | { |
---|
| 136 | Int nTestP0 = Clip3( nMin , nMax , nInitP0 + i * nStepSize ); |
---|
| 137 | Int nTestP1 = Clip3( nMin , nMax , nInitP1 + j * nStepSize ); |
---|
| 138 | Int nTestP3 = Clip3( nMin , nMax , nInitP3 + k * nStepSize ); |
---|
| 139 | Double a = 1.0 * nTestP0 / nOne; |
---|
| 140 | Double b = 1.0 * nTestP1 / nOne; |
---|
| 141 | Double c = 1.0 * nTestP3 / nOne; |
---|
| 142 | Double d = ( Ys - a * ys - b * us - c * vs ) / N; |
---|
| 143 | nInitP7 = ( ( Int )d ) >> nResQuantBit << nResQuantBit; |
---|
| 144 | for( Int m = 0 ; m < 2 ; m++ ) |
---|
| 145 | { |
---|
| 146 | Int nTestP7 = Clip3( nMin , nMax , nInitP7 + m * nStepSize ); |
---|
| 147 | Double dError = xxCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , a , b , c , nTestP7 ); |
---|
| 148 | if( dError < dMinError ) |
---|
| 149 | { |
---|
| 150 | dMinError = dError; |
---|
| 151 | rP0 = ( Pel )nTestP0; |
---|
| 152 | rP1 = ( Pel )nTestP1; |
---|
| 153 | rP3 = ( Pel )nTestP3; |
---|
| 154 | rP7 = ( Pel )nTestP7; |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | assert( !( rP0 & nMask ) && !( rP1 & nMask ) && !( rP3 & nMask ) && !( rP7 & nMask ) ); |
---|
| 161 | |
---|
| 162 | return( dMinError ); |
---|
| 163 | } |
---|
[677] | 164 | |
---|
| 165 | Double TEnc3DAsymLUT::estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc ) |
---|
| 166 | { |
---|
| 167 | xxCollectData( pCurPic , refLayerIdc ); |
---|
| 168 | |
---|
| 169 | Double dErrorLuma = 0 , dErrorChroma = 0; |
---|
| 170 | Int nYSize = 1 << ( getCurOctantDepth() + getCurYPartNumLog2() ); |
---|
| 171 | Int nUVSize = 1 << getCurOctantDepth(); |
---|
[825] | 172 | for( Int yIdx = 0 ; yIdx < nYSize ; yIdx++ ) |
---|
| 173 | { |
---|
| 174 | for( Int uIdx = 0 ; uIdx < nUVSize ; uIdx++ ) |
---|
| 175 | { |
---|
| 176 | for( Int vIdx = 0 ; vIdx < nUVSize ; vIdx++ ) |
---|
| 177 | { |
---|
| 178 | SColorInfo & rCuboidColorInfo = m_pColorInfo[yIdx][uIdx][vIdx]; |
---|
| 179 | SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx]; |
---|
| 180 | SCuboid & rCuboid = xGetCuboid( yIdx , uIdx , vIdx ); |
---|
| 181 | if( rCuboidColorInfo.N > 0 ) |
---|
| 182 | { |
---|
| 183 | dErrorLuma += xxCalEstDist( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY , |
---|
| 184 | rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y ); |
---|
| 185 | } |
---|
| 186 | if( rCuboidColorInfoC.N > 0 ) |
---|
| 187 | { |
---|
| 188 | dErrorChroma += xxCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU , |
---|
| 189 | rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U ); |
---|
| 190 | dErrorChroma += xxCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV , |
---|
| 191 | rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V ); |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | return( dErrorLuma + dErrorChroma); |
---|
| 198 | } |
---|
| 199 | |
---|
[877] | 200 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 201 | Double TEnc3DAsymLUT::derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB, Double dFrameLambda ) |
---|
| 202 | { |
---|
| 203 | m_nLUTBitDepth = pCfg->getCGSLUTBit(); |
---|
| 204 | |
---|
| 205 | Int nBestAdaptCThresholdU = 1 << ( getInputBitDepthC() - 1 ); |
---|
| 206 | Int nBestAdaptCThresholdV = 1 << ( getInputBitDepthC() - 1 ); |
---|
| 207 | Int nAdaptCThresholdU, nAdaptCThresholdV; |
---|
| 208 | |
---|
| 209 | Int nTmpLutBits[MAX_Y_SIZE][MAX_C_SIZE] ; |
---|
| 210 | memset(nTmpLutBits, 0, sizeof(nTmpLutBits)); |
---|
| 211 | |
---|
| 212 | SLUTSize sMaxLutSize; |
---|
| 213 | |
---|
| 214 | // collect stats for the most partitions |
---|
| 215 | Int nCurYPartNumLog2 = 0 , nCurOctantDepth = 0; |
---|
| 216 | Int nMaxPartNumLog2 = xGetMaxPartNumLog2(); |
---|
| 217 | |
---|
| 218 | xxMapPartNum2DepthYPart( nMaxPartNumLog2 , nCurOctantDepth , nCurYPartNumLog2 ); |
---|
| 219 | xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV ); |
---|
| 220 | xxCollectData( pCurPic , refLayerIdc ); |
---|
| 221 | xxCopyColorInfo(m_pMaxColorInfo, m_pColorInfo, m_pMaxColorInfoC, m_pColorInfoC); |
---|
| 222 | |
---|
| 223 | sMaxLutSize.iCPartNumLog2 = nCurOctantDepth; |
---|
| 224 | sMaxLutSize.iYPartNumLog2 = nCurOctantDepth + nCurYPartNumLog2; |
---|
| 225 | |
---|
| 226 | m_pBitstreamRedirect->clear(); |
---|
| 227 | |
---|
| 228 | // find the best partition based on RD cost |
---|
| 229 | Int i; |
---|
| 230 | Double dMinCost, dCurCost; |
---|
| 231 | |
---|
| 232 | Int iBestLUTSizeIdx = 0; |
---|
| 233 | Int nBestResQuanBit = 0; |
---|
| 234 | Double dCurError, dMinError; |
---|
| 235 | Int iNumBitsCurSize; |
---|
| 236 | Int iNumBitsCurSizeSave = m_pEncCavlc->getNumberOfWrittenBits(); |
---|
| 237 | Double dDistFactor = getDistFactor(pSlice->getSliceType(), pSlice->getDepth()); |
---|
| 238 | |
---|
| 239 | // check all LUT sizes |
---|
| 240 | xxGetAllLutSizes(pSlice); |
---|
| 241 | if (m_nTotalLutSizes == 0) // return if no valid size is found, LUT will not be updated |
---|
| 242 | { |
---|
| 243 | nCurOctantDepth = sMaxLutSize.iCPartNumLog2; |
---|
| 244 | nCurYPartNumLog2 = sMaxLutSize.iYPartNumLog2-nCurOctantDepth; |
---|
| 245 | xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV ); |
---|
| 246 | return MAX_DOUBLE; |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | dMinCost = MAX_DOUBLE; dMinError = MAX_DOUBLE; |
---|
| 250 | for (i = 0; i < m_nTotalLutSizes; i++) |
---|
| 251 | { |
---|
| 252 | // add up the stats |
---|
| 253 | nCurOctantDepth = m_sLutSizes[i].iCPartNumLog2; |
---|
| 254 | nCurYPartNumLog2 = m_sLutSizes[i].iYPartNumLog2-nCurOctantDepth; |
---|
| 255 | xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV ); |
---|
| 256 | xxConsolidateData( &m_sLutSizes[i], &sMaxLutSize ); |
---|
| 257 | |
---|
| 258 | dCurError = xxDeriveVertexes(nBestResQuanBit, m_pEncCuboid); |
---|
| 259 | |
---|
| 260 | setResQuantBit( nBestResQuanBit ); |
---|
| 261 | xSaveCuboids( m_pEncCuboid ); |
---|
| 262 | m_pEncCavlc->xCode3DAsymLUT( this ); |
---|
| 263 | iNumBitsCurSize = m_pEncCavlc->getNumberOfWrittenBits(); |
---|
| 264 | dCurCost = dCurError/dDistFactor + dFrameLambda*(Double)(iNumBitsCurSize-iNumBitsCurSizeSave); |
---|
| 265 | nTmpLutBits[m_sLutSizes[i].iYPartNumLog2][m_sLutSizes[i].iCPartNumLog2] = iNumBitsCurSize-iNumBitsCurSizeSave; // store LUT size |
---|
| 266 | iNumBitsCurSizeSave = iNumBitsCurSize; |
---|
| 267 | if(dCurCost < dMinCost ) |
---|
| 268 | { |
---|
| 269 | SCuboid *** tmp = m_pBestEncCuboid; |
---|
| 270 | m_pBestEncCuboid = m_pEncCuboid; |
---|
| 271 | m_pEncCuboid = tmp; |
---|
| 272 | dMinCost = dCurCost; |
---|
| 273 | dMinError = dCurError; |
---|
| 274 | iBestLUTSizeIdx = i; |
---|
| 275 | } |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | nCurOctantDepth = m_sLutSizes[iBestLUTSizeIdx].iCPartNumLog2; |
---|
| 279 | nCurYPartNumLog2 = m_sLutSizes[iBestLUTSizeIdx].iYPartNumLog2-nCurOctantDepth; |
---|
| 280 | |
---|
| 281 | xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV ); |
---|
| 282 | |
---|
| 283 | Bool bUseNewColorInfo = false; |
---|
| 284 | if( pCfg->getCGSAdaptChroma() && nCurOctantDepth <= 1 ) // if the best size found so far has depth = 0 or 1, then check AdaptC U/V thresholds |
---|
| 285 | { |
---|
| 286 | nAdaptCThresholdU = ( Int )( m_dSumU / m_nNChroma + 0.5 ); |
---|
| 287 | nAdaptCThresholdV = ( Int )( m_dSumV / m_nNChroma + 0.5 ); |
---|
| 288 | if( !(nAdaptCThresholdU == nBestAdaptCThresholdU && nAdaptCThresholdV == nBestAdaptCThresholdV ) ) |
---|
| 289 | { |
---|
| 290 | nCurOctantDepth = 1; |
---|
| 291 | if( nCurOctantDepth + nCurYPartNumLog2 > getMaxYPartNumLog2()+getMaxOctantDepth() ) |
---|
| 292 | nCurYPartNumLog2 = getMaxYPartNumLog2()+getMaxOctantDepth()-nCurOctantDepth; |
---|
| 293 | xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2 , nAdaptCThresholdU , nAdaptCThresholdV ); |
---|
| 294 | xxCollectData( pCurPic , refLayerIdc ); |
---|
| 295 | |
---|
| 296 | dCurError = xxDeriveVertexes( nBestResQuanBit , m_pEncCuboid ) ; |
---|
| 297 | setResQuantBit( nBestResQuanBit ); |
---|
| 298 | xSaveCuboids( m_pEncCuboid ); |
---|
| 299 | m_pEncCavlc->xCode3DAsymLUT( this ); |
---|
| 300 | iNumBitsCurSize = m_pEncCavlc->getNumberOfWrittenBits(); |
---|
| 301 | dCurCost = dCurError/dDistFactor + dFrameLambda*(Double)(iNumBitsCurSize-iNumBitsCurSizeSave); |
---|
| 302 | iNumBitsCurSizeSave = iNumBitsCurSize; |
---|
| 303 | if(dCurCost < dMinCost ) |
---|
| 304 | { |
---|
| 305 | SCuboid *** tmp = m_pBestEncCuboid; |
---|
| 306 | m_pBestEncCuboid = m_pEncCuboid; |
---|
| 307 | m_pEncCuboid = tmp; |
---|
| 308 | dMinCost = dCurCost; |
---|
| 309 | dMinError = dCurError; |
---|
| 310 | nBestAdaptCThresholdU = nAdaptCThresholdU; |
---|
| 311 | nBestAdaptCThresholdV = nAdaptCThresholdV; |
---|
| 312 | bUseNewColorInfo = true; |
---|
| 313 | } |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV ); |
---|
| 318 | |
---|
| 319 | // check res_quant_bits only for the best table size and best U/V threshold |
---|
| 320 | if( !bUseNewColorInfo ) |
---|
| 321 | xxConsolidateData( &m_sLutSizes[iBestLUTSizeIdx], &sMaxLutSize ); |
---|
| 322 | |
---|
| 323 | // xxCollectData( pCurPic , refLayerIdc ); |
---|
| 324 | for( Int nResQuanBit = 1 ; nResQuanBit < 4 ; nResQuanBit++ ) |
---|
| 325 | { |
---|
| 326 | dCurError = xxDeriveVertexes( nResQuanBit , m_pEncCuboid ); |
---|
| 327 | |
---|
| 328 | setResQuantBit( nResQuanBit ); |
---|
| 329 | xSaveCuboids( m_pEncCuboid ); |
---|
| 330 | m_pEncCavlc->xCode3DAsymLUT( this ); |
---|
| 331 | iNumBitsCurSize = m_pEncCavlc->getNumberOfWrittenBits(); |
---|
| 332 | dCurCost = dCurError/dDistFactor + dFrameLambda*(Double)(iNumBitsCurSize-iNumBitsCurSizeSave); |
---|
| 333 | |
---|
| 334 | iNumBitsCurSizeSave = iNumBitsCurSize; |
---|
| 335 | if(dCurCost < dMinCost) |
---|
| 336 | { |
---|
| 337 | nBestResQuanBit = nResQuanBit; |
---|
| 338 | SCuboid *** tmp = m_pBestEncCuboid; |
---|
| 339 | m_pBestEncCuboid = m_pEncCuboid; |
---|
| 340 | m_pEncCuboid = tmp; |
---|
| 341 | dMinCost = dCurCost; |
---|
| 342 | dMinError = dCurError; |
---|
| 343 | } |
---|
| 344 | else |
---|
| 345 | { |
---|
| 346 | break; |
---|
| 347 | } |
---|
| 348 | } |
---|
| 349 | |
---|
| 350 | setResQuantBit( nBestResQuanBit ); |
---|
| 351 | xSaveCuboids( m_pBestEncCuboid ); |
---|
| 352 | |
---|
| 353 | // update LUT size stats |
---|
| 354 | for(Int iLutSizeY = 0; iLutSizeY < MAX_Y_SIZE; iLutSizeY++) |
---|
| 355 | { |
---|
| 356 | for(Int iLutSizeC = 0; iLutSizeC < MAX_C_SIZE; iLutSizeC++) |
---|
| 357 | { |
---|
| 358 | if(nTmpLutBits[iLutSizeY][iLutSizeC] != 0) |
---|
| 359 | m_nNumLUTBits[iLutSizeY][iLutSizeC] = (m_nNumLUTBits[iLutSizeY][iLutSizeC] + nTmpLutBits[iLutSizeY][iLutSizeC]*3+2)>>2; // update with new stats |
---|
| 360 | } |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | // return cost rather than error |
---|
| 364 | return( dMinCost ); |
---|
| 365 | } |
---|
| 366 | #endif |
---|
| 367 | |
---|
[677] | 368 | Double TEnc3DAsymLUT::derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB ) |
---|
| 369 | { |
---|
| 370 | m_nLUTBitDepth = pCfg->getCGSLUTBit(); |
---|
| 371 | Int nCurYPartNumLog2 = 0 , nCurOctantDepth = 0; |
---|
| 372 | xxDerivePartNumLog2( pSlice , pCfg , nCurOctantDepth , nCurYPartNumLog2 , bSignalPPS , bElRapSliceTypeB ); |
---|
[825] | 373 | |
---|
| 374 | Int nBestResQuanBit = 0; |
---|
| 375 | Int nBestAdaptCThresholdU = 1 << ( getInputBitDepthC() - 1 ); |
---|
| 376 | Int nBestAdaptCThresholdV = 1 << ( getInputBitDepthC() - 1 ); |
---|
| 377 | Int nBestOctantDepth = nCurOctantDepth; |
---|
| 378 | Int nBestYPartNumLog2 = nCurYPartNumLog2; |
---|
| 379 | Int nTargetLoop = 1 + ( pCfg->getCGSAdaptChroma() && ( nCurOctantDepth == 1 || ( nCurOctantDepth * 3 + nCurYPartNumLog2 ) >= 5 ) ); |
---|
| 380 | Double dMinError = MAX_DOUBLE; |
---|
| 381 | for( Int nLoop = 0 ; nLoop < nTargetLoop ; nLoop++ ) |
---|
| 382 | { |
---|
| 383 | Int nAdaptCThresholdU = 1 << ( getInputBitDepthC() - 1 ); |
---|
| 384 | Int nAdaptCThresholdV = 1 << ( getInputBitDepthC() - 1 ); |
---|
| 385 | if( nLoop > 0 ) |
---|
| 386 | { |
---|
| 387 | nAdaptCThresholdU = ( Int )( m_dSumU / m_nNChroma + 0.5 ); |
---|
| 388 | nAdaptCThresholdV = ( Int )( m_dSumV / m_nNChroma + 0.5 ); |
---|
| 389 | if( nCurOctantDepth > 1 ) |
---|
| 390 | { |
---|
| 391 | nCurOctantDepth = 1; |
---|
| 392 | nCurYPartNumLog2 = 2; |
---|
| 393 | } |
---|
| 394 | if( nAdaptCThresholdU == nBestAdaptCThresholdU && nAdaptCThresholdV == nBestAdaptCThresholdV |
---|
| 395 | && nCurOctantDepth == nBestOctantDepth && nCurYPartNumLog2 == nBestYPartNumLog2 ) |
---|
| 396 | break; |
---|
| 397 | } |
---|
[877] | 398 | |
---|
[825] | 399 | xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2 , nAdaptCThresholdU , nAdaptCThresholdV ); |
---|
| 400 | xxCollectData( pCurPic , refLayerIdc ); |
---|
| 401 | for( Int nResQuanBit = 0 ; nResQuanBit < 4 ; nResQuanBit++ ) |
---|
| 402 | { |
---|
| 403 | Double dError = xxDeriveVertexes( nResQuanBit , m_pEncCuboid ) / ( 1 + ( nResQuanBit > 0 ) * 0.001 * ( pSlice->getDepth() + 1 ) ); |
---|
| 404 | if( dError <= dMinError ) |
---|
| 405 | { |
---|
| 406 | nBestResQuanBit = nResQuanBit; |
---|
| 407 | nBestAdaptCThresholdU = nAdaptCThresholdU; |
---|
| 408 | nBestAdaptCThresholdV = nAdaptCThresholdV; |
---|
| 409 | nBestOctantDepth = nCurOctantDepth; |
---|
| 410 | nBestYPartNumLog2 = nCurYPartNumLog2; |
---|
| 411 | SCuboid *** tmp = m_pBestEncCuboid; |
---|
| 412 | m_pBestEncCuboid = m_pEncCuboid; |
---|
| 413 | m_pEncCuboid = tmp; |
---|
| 414 | dMinError = dError; |
---|
| 415 | } |
---|
| 416 | else |
---|
| 417 | { |
---|
| 418 | break; |
---|
| 419 | } |
---|
| 420 | } |
---|
| 421 | } |
---|
[877] | 422 | |
---|
[825] | 423 | setResQuantBit( nBestResQuanBit ); |
---|
| 424 | xUpdatePartitioning( nBestOctantDepth , nBestYPartNumLog2 , nBestAdaptCThresholdU , nBestAdaptCThresholdV ); |
---|
[877] | 425 | |
---|
[825] | 426 | xSaveCuboids( m_pBestEncCuboid ); |
---|
| 427 | return( dMinError ); |
---|
| 428 | } |
---|
[677] | 429 | |
---|
| 430 | Double TEnc3DAsymLUT::xxDeriveVertexes( Int nResQuanBit , SCuboid *** pCurCuboid ) |
---|
| 431 | { |
---|
| 432 | Double dErrorLuma = 0 , dErrorChroma = 0; |
---|
| 433 | Int nYSize = 1 << ( getCurOctantDepth() + getCurYPartNumLog2() ); |
---|
| 434 | Int nUVSize = 1 << getCurOctantDepth(); |
---|
[1214] | 435 | |
---|
[677] | 436 | for( Int yIdx = 0 ; yIdx < nYSize ; yIdx++ ) |
---|
| 437 | { |
---|
| 438 | for( Int uIdx = 0 ; uIdx < nUVSize ; uIdx++ ) |
---|
| 439 | { |
---|
| 440 | for( Int vIdx = 0 ; vIdx < nUVSize ; vIdx++ ) |
---|
| 441 | { |
---|
| 442 | SColorInfo & rCuboidColorInfo = m_pColorInfo[yIdx][uIdx][vIdx]; |
---|
| 443 | SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx]; |
---|
| 444 | SCuboid & rCuboid = pCurCuboid[yIdx][uIdx][vIdx]; |
---|
[1214] | 445 | |
---|
[677] | 446 | for( Int idxVertex = 0 ; idxVertex < 4 ; idxVertex++ ) |
---|
[684] | 447 | { |
---|
[677] | 448 | rCuboid.P[idxVertex] = xGetCuboidVertexPredAll( yIdx , uIdx , vIdx , idxVertex , pCurCuboid ); |
---|
[684] | 449 | } |
---|
[677] | 450 | |
---|
| 451 | if( rCuboidColorInfo.N > 0 ) |
---|
| 452 | { |
---|
| 453 | dErrorLuma += xxDeriveVertexPerColor( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY , |
---|
[825] | 454 | rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y , nResQuanBit ); |
---|
[677] | 455 | } |
---|
[1214] | 456 | |
---|
[677] | 457 | if( rCuboidColorInfoC.N > 0 ) |
---|
| 458 | { |
---|
| 459 | dErrorChroma += xxDeriveVertexPerColor( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU , |
---|
[825] | 460 | rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U , nResQuanBit ); |
---|
[1214] | 461 | |
---|
[677] | 462 | dErrorChroma += xxDeriveVertexPerColor( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV , |
---|
[825] | 463 | rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V , nResQuanBit ); |
---|
[677] | 464 | } |
---|
| 465 | |
---|
| 466 | if( nResQuanBit > 0 ) |
---|
| 467 | { |
---|
| 468 | // check quantization |
---|
| 469 | for( Int idxVertex = 0 ; idxVertex < 4 ; idxVertex++ ) |
---|
| 470 | { |
---|
| 471 | SYUVP sPred = xGetCuboidVertexPredAll( yIdx , uIdx , vIdx , idxVertex , pCurCuboid ); |
---|
| 472 | assert( ( ( rCuboid.P[idxVertex].Y - sPred.Y ) >> nResQuanBit << nResQuanBit ) == rCuboid.P[idxVertex].Y - sPred.Y ); |
---|
| 473 | assert( ( ( rCuboid.P[idxVertex].U - sPred.U ) >> nResQuanBit << nResQuanBit ) == rCuboid.P[idxVertex].U - sPred.U ); |
---|
| 474 | assert( ( ( rCuboid.P[idxVertex].V - sPred.V ) >> nResQuanBit << nResQuanBit ) == rCuboid.P[idxVertex].V - sPred.V ); |
---|
| 475 | } |
---|
| 476 | } |
---|
| 477 | } |
---|
| 478 | } |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | return( dErrorLuma + dErrorChroma ); |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | Void TEnc3DAsymLUT::xxCollectData( TComPic * pCurPic , UInt refLayerIdc ) |
---|
| 485 | { |
---|
[1029] | 486 | Pel * pSrcY = m_pDsOrigPic->getAddr(COMPONENT_Y); |
---|
| 487 | Pel * pSrcU = m_pDsOrigPic->getAddr(COMPONENT_Cb); |
---|
| 488 | Pel * pSrcV = m_pDsOrigPic->getAddr(COMPONENT_Cr); |
---|
| 489 | Int nStrideSrcY = m_pDsOrigPic->getStride(COMPONENT_Y); |
---|
| 490 | Int nStrideSrcC = m_pDsOrigPic->getStride(COMPONENT_Cb); |
---|
[677] | 491 | TComPicYuv *pRecPic = pCurPic->getSlice(pCurPic->getCurrSliceIdx())->getBaseColPic(refLayerIdc)->getPicYuvRec(); |
---|
[1029] | 492 | Pel * pIRLY = pRecPic->getAddr(COMPONENT_Y); |
---|
| 493 | Pel * pIRLU = pRecPic->getAddr(COMPONENT_Cb); |
---|
| 494 | Pel * pIRLV = pRecPic->getAddr(COMPONENT_Cr); |
---|
| 495 | Int nStrideILRY = pRecPic->getStride(COMPONENT_Y); |
---|
| 496 | Int nStrideILRC = pRecPic->getStride(COMPONENT_Cb); |
---|
[877] | 497 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 498 | xReset3DArray( m_pColorInfo , getMaxYSize() , getMaxCSize() , getMaxCSize() ); |
---|
| 499 | xReset3DArray( m_pColorInfoC , getMaxYSize() , getMaxCSize() , getMaxCSize() ); |
---|
| 500 | #else |
---|
[677] | 501 | xReset3DArray( m_pColorInfo , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
| 502 | xReset3DArray( m_pColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
[877] | 503 | #endif |
---|
[677] | 504 | |
---|
| 505 | //alignment padding |
---|
[815] | 506 | pRecPic->setBorderExtension( false ); |
---|
| 507 | pRecPic->extendPicBorder(); |
---|
[677] | 508 | |
---|
[815] | 509 | TComSlice * pSlice = pCurPic->getSlice(pCurPic->getCurrSliceIdx()); |
---|
| 510 | UInt refLayerId = pSlice->getVPS()->getRefLayerId(pSlice->getLayerId(), refLayerIdc); |
---|
[1235] | 511 | Window scalEL = pSlice->getPPS()->getScaledRefLayerWindowForLayer(refLayerId); |
---|
[815] | 512 | TComPicYuv *pcRecPicBL = pSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(); |
---|
| 513 | // borders of down-sampled picture |
---|
| 514 | Int leftDS = (scalEL.getWindowLeftOffset()*g_posScalingFactor[refLayerIdc][0]+(1<<15))>>16; |
---|
[1029] | 515 | Int rightDS = pcRecPicBL->getWidth(COMPONENT_Y) - 1 + (((scalEL.getWindowRightOffset())*g_posScalingFactor[refLayerIdc][0]+(1<<15))>>16); |
---|
[815] | 516 | Int topDS = (((scalEL.getWindowTopOffset())*g_posScalingFactor[refLayerIdc][1]+(1<<15))>>16); |
---|
[1029] | 517 | Int bottomDS = pcRecPicBL->getHeight(COMPONENT_Y) - 1 + (((scalEL.getWindowBottomOffset())*g_posScalingFactor[refLayerIdc][1]+(1<<15))>>16); |
---|
[815] | 518 | // overlapped region |
---|
| 519 | Int left = max( 0 , leftDS ); |
---|
[1029] | 520 | Int right = min( pcRecPicBL->getWidth(COMPONENT_Y) - 1 , rightDS ); |
---|
[815] | 521 | Int top = max( 0 , topDS ); |
---|
[1029] | 522 | Int bottom = min( pcRecPicBL->getHeight(COMPONENT_Y) - 1 , bottomDS ); |
---|
[815] | 523 | // since we do data collection only for overlapped region, the border extension is good enough |
---|
[677] | 524 | |
---|
[825] | 525 | m_dSumU = m_dSumV = 0; |
---|
| 526 | m_nNChroma = 0; |
---|
[1214] | 527 | |
---|
[815] | 528 | for( Int i = top ; i <= bottom ; i++ ) |
---|
[677] | 529 | { |
---|
[815] | 530 | Int iDS = i-topDS; |
---|
| 531 | Int jDS = left-leftDS; |
---|
| 532 | Int posSrcY = iDS * nStrideSrcY + jDS; |
---|
| 533 | Int posIRLY = i * nStrideILRY + left; |
---|
| 534 | Int posSrcUV = ( iDS >> 1 ) * nStrideSrcC + (jDS>>1); |
---|
| 535 | Int posIRLUV = ( i >> 1 ) * nStrideILRC + (left>>1); |
---|
| 536 | for( Int j = left ; j <= right ; j++ , posSrcY++ , posIRLY++ , posSrcUV += !( j & 0x01 ) , posIRLUV += !( j & 0x01 ) ) |
---|
[677] | 537 | { |
---|
| 538 | Int Y = pSrcY[posSrcY]; |
---|
| 539 | Int y = pIRLY[posIRLY]; |
---|
| 540 | Int U = pSrcU[posSrcUV]; |
---|
| 541 | Int u = pIRLU[posIRLUV]; |
---|
| 542 | Int V = pSrcV[posSrcUV]; |
---|
| 543 | Int v = pIRLV[posIRLUV]; |
---|
| 544 | |
---|
| 545 | // alignment |
---|
| 546 | //filtering u, v for luma; |
---|
| 547 | Int posIRLUVN = posIRLUV + ((i&1)? nStrideILRC : -nStrideILRC); |
---|
| 548 | if((j&1)) |
---|
| 549 | { |
---|
| 550 | u = (pIRLU[posIRLUVN] + pIRLU[posIRLUVN+1] +(u + pIRLU[posIRLUV+1])*3 +4)>>3; |
---|
| 551 | v = (pIRLV[posIRLUVN] + pIRLV[posIRLUVN+1] +(v + pIRLV[posIRLUV+1])*3 +4)>>3; |
---|
| 552 | } |
---|
| 553 | else |
---|
| 554 | { |
---|
| 555 | u = (pIRLU[posIRLUVN] +u*3 +2)>>2; |
---|
| 556 | v = (pIRLV[posIRLUVN] +v*3 +2)>>2; |
---|
| 557 | } |
---|
| 558 | |
---|
[825] | 559 | m_dSumU += u; |
---|
| 560 | m_dSumV += v; |
---|
| 561 | m_nNChroma++; |
---|
[1214] | 562 | |
---|
[677] | 563 | SColorInfo sColorInfo; |
---|
[825] | 564 | SColorInfo & rCuboidColorInfo = m_pColorInfo[xGetYIdx(y)][xGetUIdx(u)][xGetVIdx(v)]; |
---|
[1214] | 565 | |
---|
[677] | 566 | memset(&sColorInfo, 0, sizeof(SColorInfo)); |
---|
[1214] | 567 | |
---|
[677] | 568 | sColorInfo.Ys = Y; |
---|
| 569 | sColorInfo.ys = y; |
---|
| 570 | sColorInfo.us = u; |
---|
| 571 | sColorInfo.vs = v; |
---|
| 572 | sColorInfo.Yy = Y * y; |
---|
| 573 | sColorInfo.Yu = Y * u; |
---|
| 574 | sColorInfo.Yv = Y * v; |
---|
| 575 | sColorInfo.yy = y * y; |
---|
| 576 | sColorInfo.yu = y * u; |
---|
| 577 | sColorInfo.yv = y * v; |
---|
| 578 | sColorInfo.uu = u * u; |
---|
| 579 | sColorInfo.uv = u * v; |
---|
| 580 | sColorInfo.vv = v * v; |
---|
| 581 | sColorInfo.YY = Y * Y; |
---|
| 582 | sColorInfo.N = 1; |
---|
| 583 | |
---|
| 584 | rCuboidColorInfo += sColorInfo; |
---|
| 585 | |
---|
| 586 | if(!((i&1) || (j&1))) |
---|
| 587 | { |
---|
| 588 | // alignment |
---|
| 589 | y = (pIRLY[posIRLY] + pIRLY[posIRLY+nStrideILRY] + 1)>>1; |
---|
| 590 | |
---|
| 591 | u = pIRLU[posIRLUV]; |
---|
| 592 | v = pIRLV[posIRLUV]; |
---|
[1214] | 593 | |
---|
[825] | 594 | SColorInfo & rCuboidColorInfoC = m_pColorInfoC[xGetYIdx(y)][xGetUIdx(u)][xGetVIdx(v)]; |
---|
[1214] | 595 | |
---|
[677] | 596 | sColorInfo.Us = U; |
---|
| 597 | sColorInfo.Vs = V; |
---|
| 598 | sColorInfo.ys = y; |
---|
| 599 | sColorInfo.us = u; |
---|
| 600 | sColorInfo.vs = v; |
---|
| 601 | |
---|
| 602 | sColorInfo.Uy = U * y; |
---|
| 603 | sColorInfo.Uu = U * u; |
---|
| 604 | sColorInfo.Uv = U * v; |
---|
| 605 | sColorInfo.Vy = V * y; |
---|
| 606 | sColorInfo.Vu = V * u; |
---|
| 607 | sColorInfo.Vv = V * v; |
---|
| 608 | sColorInfo.yy = y * y; |
---|
| 609 | sColorInfo.yu = y * u; |
---|
| 610 | sColorInfo.yv = y * v; |
---|
| 611 | sColorInfo.uu = u * u; |
---|
| 612 | sColorInfo.uv = u * v; |
---|
| 613 | sColorInfo.vv = v * v; |
---|
| 614 | sColorInfo.UU = U * U; |
---|
| 615 | sColorInfo.VV = V * V; |
---|
| 616 | sColorInfo.N = 1; |
---|
| 617 | |
---|
| 618 | rCuboidColorInfoC += sColorInfo; |
---|
| 619 | } |
---|
| 620 | } |
---|
| 621 | } |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | Void TEnc3DAsymLUT::xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB ) |
---|
| 625 | { |
---|
| 626 | Int nPartNumLog2 = 4; |
---|
| 627 | if( pSlice->getBaseColPic( pSlice->getInterLayerPredLayerIdc( 0 ) )->getSlice( 0 )->isIntra() ) |
---|
[684] | 628 | { |
---|
[677] | 629 | nPartNumLog2 = xGetMaxPartNumLog2(); |
---|
[684] | 630 | } |
---|
[1214] | 631 | |
---|
[825] | 632 | if( m_nAccuFrameBit && pSlice->getPPS()->getCGSFlag() ) |
---|
[677] | 633 | { |
---|
[825] | 634 | Double dBitCost = 1.0 * m_nAccuFrameCGSBit / m_nAccuFrameBit; |
---|
| 635 | nPartNumLog2 = m_nPrevFrameCGSPartNumLog2; |
---|
[1214] | 636 | |
---|
[677] | 637 | Double dBitCostT = 0.03; |
---|
| 638 | if( dBitCost < dBitCostT / 6.0 ) |
---|
| 639 | { |
---|
| 640 | nPartNumLog2++; |
---|
| 641 | } |
---|
| 642 | else if( dBitCost >= dBitCostT ) |
---|
| 643 | { |
---|
| 644 | nPartNumLog2--; |
---|
| 645 | } |
---|
| 646 | } |
---|
[1214] | 647 | |
---|
[825] | 648 | nPartNumLog2 = Clip3( 0 , xGetMaxPartNumLog2() , nPartNumLog2 ); |
---|
[677] | 649 | xxMapPartNum2DepthYPart( nPartNumLog2 , rOctantDepth , rYPartNumLog2 ); |
---|
| 650 | } |
---|
| 651 | |
---|
| 652 | Void TEnc3DAsymLUT::xxMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 ) |
---|
| 653 | { |
---|
| 654 | for( Int y = getMaxYPartNumLog2() ; y >= 0 ; y-- ) |
---|
| 655 | { |
---|
| 656 | for( Int depth = ( nPartNumLog2 - y ) >> 1 ; depth >= 0 ; depth-- ) |
---|
| 657 | { |
---|
| 658 | if( y + 3 * depth == nPartNumLog2 ) |
---|
| 659 | { |
---|
| 660 | rOctantDepth = depth; |
---|
| 661 | rYPartNumLog2 = y; |
---|
| 662 | return; |
---|
| 663 | } |
---|
| 664 | } |
---|
| 665 | } |
---|
| 666 | rOctantDepth = min( getMaxOctantDepth() , nPartNumLog2 / 3 ); |
---|
| 667 | rYPartNumLog2 = min( getMaxYPartNumLog2() , nPartNumLog2 - 3 * rOctantDepth ); |
---|
| 668 | } |
---|
| 669 | |
---|
| 670 | Void TEnc3DAsymLUT::updatePicCGSBits( TComSlice * pcSlice , Int nPPSBit ) |
---|
| 671 | { |
---|
| 672 | for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
---|
| 673 | { |
---|
| 674 | UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i); |
---|
[825] | 675 | m_nAccuFrameBit += pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit(); |
---|
[677] | 676 | m_dTotalFrameBit += pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit(); |
---|
| 677 | } |
---|
[1214] | 678 | |
---|
[825] | 679 | m_nAccuFrameCGSBit += nPPSBit; |
---|
[677] | 680 | m_nTotalCGSBit += nPPSBit; |
---|
[825] | 681 | m_nPrevFrameCGSPartNumLog2 = getCurOctantDepth() * 3 + getCurYPartNumLog2(); |
---|
[1214] | 682 | |
---|
[877] | 683 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 684 | Int nCurELFrameBit = pcSlice->getPic()->getFrameBit(); |
---|
| 685 | const Int nSliceType = pcSlice->getSliceType(); |
---|
| 686 | const Int nSliceTempLevel = pcSlice->getDepth(); |
---|
| 687 | m_nPrevELFrameBit[nSliceType][nSliceTempLevel] = m_nPrevELFrameBit[nSliceType][nSliceTempLevel] == 0 ? nCurELFrameBit:((m_nPrevELFrameBit[nSliceType][nSliceTempLevel]+nCurELFrameBit)>>1); |
---|
| 688 | #endif |
---|
[677] | 689 | } |
---|
| 690 | |
---|
[877] | 691 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 692 | |
---|
| 693 | Void TEnc3DAsymLUT::xxGetAllLutSizes(TComSlice *pSlice) |
---|
| 694 | { |
---|
| 695 | Int iMaxYPartNumLog2, iMaxCPartNumLog2; |
---|
| 696 | Int iCurYPartNumLog2, iCurCPartNumLog2; |
---|
| 697 | Int iMaxAddYPartNumLog2; |
---|
| 698 | Int iNumELFrameBits = m_nPrevELFrameBit[pSlice->getSliceType()][pSlice->getDepth()]; |
---|
| 699 | |
---|
| 700 | xxMapPartNum2DepthYPart( xGetMaxPartNumLog2() , iMaxCPartNumLog2 , iMaxYPartNumLog2 ); |
---|
| 701 | iMaxAddYPartNumLog2 = iMaxYPartNumLog2; |
---|
| 702 | iMaxYPartNumLog2 += iMaxCPartNumLog2; |
---|
| 703 | |
---|
| 704 | //m_sLutSizes[0].iYPartNumLog2 = iMaxYPartNumLog2; |
---|
| 705 | //m_sLutSizes[0].iCPartNumLog2 = iMaxCPartNumLog2; |
---|
| 706 | m_nTotalLutSizes = 0; |
---|
| 707 | |
---|
| 708 | |
---|
| 709 | for(iCurYPartNumLog2 = iMaxYPartNumLog2; iCurYPartNumLog2 >= 0; iCurYPartNumLog2--) |
---|
| 710 | { |
---|
| 711 | for(iCurCPartNumLog2 = iMaxCPartNumLog2; iCurCPartNumLog2 >= 0; iCurCPartNumLog2--) |
---|
| 712 | { |
---|
| 713 | // try more sizes |
---|
| 714 | if(iCurCPartNumLog2 <= iCurYPartNumLog2 && |
---|
| 715 | (m_nNumLUTBits[iCurYPartNumLog2][iCurCPartNumLog2] < (iNumELFrameBits>>1)) && |
---|
| 716 | m_nTotalLutSizes < MAX_NUM_LUT_SIZES) |
---|
| 717 | { |
---|
| 718 | m_sLutSizes[m_nTotalLutSizes].iYPartNumLog2 = iCurYPartNumLog2; |
---|
| 719 | m_sLutSizes[m_nTotalLutSizes].iCPartNumLog2 = iCurCPartNumLog2; |
---|
| 720 | m_nTotalLutSizes ++; |
---|
| 721 | } |
---|
| 722 | } |
---|
| 723 | } |
---|
| 724 | |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | Void TEnc3DAsymLUT::xxCopyColorInfo( SColorInfo *** dst, SColorInfo *** src , SColorInfo *** dstC, SColorInfo *** srcC ) |
---|
| 728 | { |
---|
| 729 | Int yIdx, uIdx, vIdx; |
---|
| 730 | |
---|
| 731 | // copy from pColorInfo to pMaxColorInfo |
---|
| 732 | for(yIdx = 0; yIdx < xGetYSize(); yIdx++) |
---|
| 733 | { |
---|
| 734 | for(uIdx = 0; uIdx < xGetUSize(); uIdx++) |
---|
| 735 | { |
---|
| 736 | for(vIdx = 0; vIdx < xGetVSize(); vIdx++) |
---|
| 737 | { |
---|
| 738 | dst [yIdx][uIdx][vIdx] = src [yIdx][uIdx][vIdx]; |
---|
| 739 | dstC[yIdx][uIdx][vIdx] = srcC[yIdx][uIdx][vIdx]; |
---|
| 740 | } |
---|
| 741 | } |
---|
| 742 | } |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | Void TEnc3DAsymLUT::xxAddColorInfo( Int yIdx, Int uIdx, Int vIdx, Int iYDiffLog2, Int iCDiffLog2 ) |
---|
| 746 | { |
---|
| 747 | SColorInfo & rCuboidColorInfo = m_pColorInfo [yIdx][uIdx][vIdx]; |
---|
| 748 | SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx]; |
---|
| 749 | |
---|
| 750 | for( Int i = 0; i < (1<<iYDiffLog2); i++) |
---|
| 751 | { |
---|
| 752 | for (Int j = 0; j < (1<<iCDiffLog2); j++) |
---|
| 753 | { |
---|
| 754 | for(Int k = 0; k < (1<<iCDiffLog2); k++) |
---|
| 755 | { |
---|
| 756 | rCuboidColorInfo += m_pMaxColorInfo [(yIdx<<iYDiffLog2)+i][(uIdx<<iCDiffLog2)+j][(vIdx<<iCDiffLog2)+k]; |
---|
| 757 | rCuboidColorInfoC += m_pMaxColorInfoC[(yIdx<<iYDiffLog2)+i][(uIdx<<iCDiffLog2)+j][(vIdx<<iCDiffLog2)+k]; |
---|
| 758 | } |
---|
| 759 | } |
---|
| 760 | } |
---|
| 761 | } |
---|
| 762 | |
---|
| 763 | Void TEnc3DAsymLUT::xxConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize ) |
---|
| 764 | { |
---|
| 765 | Int yIdx, uIdx, vIdx; |
---|
| 766 | Int iYDiffLog2, iCDiffLog2; |
---|
| 767 | Int nYSize = 1<< pMaxLUTSize->iYPartNumLog2; |
---|
| 768 | Int nCSize = 1<< pMaxLUTSize->iCPartNumLog2; |
---|
| 769 | |
---|
| 770 | iYDiffLog2 = pMaxLUTSize->iYPartNumLog2-pCurLUTSize->iYPartNumLog2; |
---|
| 771 | iCDiffLog2 = pMaxLUTSize->iCPartNumLog2-pCurLUTSize->iCPartNumLog2; |
---|
| 772 | |
---|
| 773 | //assert(pMaxLUTSize->iCPartNumLog2 >= pCurLUTSize->iCPartNumLog2 && pMaxLUTSize->iYPartNumLog2 >= pCurLUTSize->iYPartNumLog2); |
---|
| 774 | if (iYDiffLog2 == 0 && iCDiffLog2 == 0) // shouldn't have to do anything |
---|
| 775 | { |
---|
| 776 | xxCopyColorInfo(m_pColorInfo, m_pMaxColorInfo, m_pColorInfoC, m_pMaxColorInfoC); |
---|
| 777 | return; |
---|
| 778 | } |
---|
| 779 | |
---|
| 780 | xReset3DArray( m_pColorInfo , 1<<pMaxLUTSize->iYPartNumLog2, 1<<pMaxLUTSize->iCPartNumLog2, 1<<pMaxLUTSize->iCPartNumLog2 ); |
---|
| 781 | xReset3DArray( m_pColorInfoC , 1<<pMaxLUTSize->iYPartNumLog2, 1<<pMaxLUTSize->iCPartNumLog2, 1<<pMaxLUTSize->iCPartNumLog2 ); |
---|
| 782 | |
---|
| 783 | for(yIdx = 0; yIdx < nYSize; yIdx++) |
---|
| 784 | { |
---|
| 785 | for(uIdx = 0; uIdx < nCSize; uIdx++) |
---|
| 786 | { |
---|
| 787 | for(vIdx = 0; vIdx < nCSize; vIdx++) |
---|
| 788 | { |
---|
| 789 | const SColorInfo & rCuboidSrc = m_pMaxColorInfo [yIdx][uIdx][vIdx]; |
---|
| 790 | const SColorInfo & rCuboidSrcC = m_pMaxColorInfoC[yIdx][uIdx][vIdx]; |
---|
| 791 | |
---|
| 792 | Int yIdx2, uIdx2, vIdx2; |
---|
| 793 | yIdx2 = yIdx>>iYDiffLog2; |
---|
| 794 | uIdx2 = uIdx>>iCDiffLog2; |
---|
| 795 | vIdx2 = vIdx>>iCDiffLog2; |
---|
| 796 | |
---|
| 797 | m_pColorInfo [yIdx2][uIdx2][vIdx2] += rCuboidSrc; |
---|
| 798 | m_pColorInfoC[yIdx2][uIdx2][vIdx2] += rCuboidSrcC; |
---|
| 799 | } |
---|
| 800 | } |
---|
| 801 | } |
---|
| 802 | } |
---|
| 803 | |
---|
| 804 | Void TEnc3DAsymLUT::update3DAsymLUTParam( TEnc3DAsymLUT * pSrc ) |
---|
| 805 | { |
---|
| 806 | assert( pSrc->getMaxOctantDepth() == getMaxOctantDepth() && pSrc->getMaxYPartNumLog2() == getMaxYPartNumLog2() ); |
---|
[1214] | 807 | xUpdatePartitioning( pSrc->getCurOctantDepth(), pSrc->getCurYPartNumLog2(), pSrc->getAdaptChromaThresholdU(), pSrc->getAdaptChromaThresholdV() ); |
---|
[877] | 808 | setResQuantBit( pSrc->getResQuantBit() ); |
---|
| 809 | } |
---|
| 810 | #endif |
---|
| 811 | #endif |
---|