[677] | 1 | #include <cstdio> |
---|
| 2 | #include <cstdlib> |
---|
| 3 | #include <cstring> |
---|
| 4 | #include <cmath> |
---|
| 5 | #include <algorithm> |
---|
| 6 | |
---|
| 7 | #include "TEnc3DAsymLUT.h" |
---|
| 8 | |
---|
| 9 | #if Q0048_CGS_3D_ASYMLUT |
---|
| 10 | |
---|
| 11 | TEnc3DAsymLUT::TEnc3DAsymLUT() |
---|
| 12 | { |
---|
| 13 | m_pColorInfo = NULL; |
---|
| 14 | m_pColorInfoC = NULL; |
---|
| 15 | m_pEncCuboid = NULL; |
---|
| 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; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | Void TEnc3DAsymLUT::create( Int nMaxOctantDepth , Int nInputBitDepth , Int nInputBitDepthC , Int nOutputBitDepth , Int nOutputBitDepthC , Int nMaxYPartNumLog2 ) |
---|
| 27 | { |
---|
| 28 | if( m_pColorInfo != NULL ) |
---|
[684] | 29 | { |
---|
[677] | 30 | destroy(); |
---|
[684] | 31 | } |
---|
| 32 | |
---|
[825] | 33 | TCom3DAsymLUT::create( nMaxOctantDepth , nInputBitDepth , nInputBitDepthC, nOutputBitDepth , nOutputBitDepthC, nMaxYPartNumLog2 |
---|
| 34 | #if R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
| 35 | , 1 << ( nInputBitDepthC - 1 ) , 1 << ( nInputBitDepthC - 1 ) |
---|
| 36 | #endif |
---|
| 37 | ); |
---|
[677] | 38 | xAllocate3DArray( m_pColorInfo , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
| 39 | xAllocate3DArray( m_pColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
| 40 | xAllocate3DArray( m_pEncCuboid , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
| 41 | xAllocate3DArray( m_pBestEncCuboid , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | Void TEnc3DAsymLUT::destroy() |
---|
| 45 | { |
---|
| 46 | xFree3DArray( m_pColorInfo ); |
---|
| 47 | xFree3DArray( m_pColorInfoC ); |
---|
| 48 | xFree3DArray( m_pEncCuboid ); |
---|
| 49 | xFree3DArray( m_pBestEncCuboid ); |
---|
| 50 | TCom3DAsymLUT::destroy(); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | TEnc3DAsymLUT::~TEnc3DAsymLUT() |
---|
| 54 | { |
---|
| 55 | if( m_dTotalFrameBit != 0 ) |
---|
[684] | 56 | { |
---|
[677] | 57 | printf( "\nTotal CGS bit: %d, %.2lf%%" , m_nTotalCGSBit , m_nTotalCGSBit * 100 / m_dTotalFrameBit ); |
---|
[684] | 58 | } |
---|
| 59 | |
---|
[677] | 60 | destroy(); |
---|
| 61 | } |
---|
| 62 | |
---|
[825] | 63 | #if R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
[677] | 64 | 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] | 65 | Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit ) |
---|
| 66 | { |
---|
| 67 | Int nInitP0 = rP0; |
---|
| 68 | Int nInitP1 = rP1; |
---|
| 69 | Int nInitP3 = rP3; |
---|
| 70 | Int nInitP7 = rP7; |
---|
| 71 | |
---|
| 72 | const Int nOne = xGetNormCoeffOne(); |
---|
| 73 | 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); |
---|
| 74 | if( N > 16 && dNorm != 0 ) |
---|
| 75 | { |
---|
| 76 | 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; |
---|
| 77 | 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; |
---|
| 78 | 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; |
---|
| 79 | nInitP0 = ( Int )( dInitA * nOne + 0.5 ) >> nResQuantBit << nResQuantBit; |
---|
| 80 | nInitP1 = ( Int )( dInitB * nOne + 0.5 ) >> nResQuantBit << nResQuantBit; |
---|
| 81 | nInitP3 = ( Int )( dInitC * nOne + 0.5 ) >> nResQuantBit << nResQuantBit; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | Int nMin = - ( 1 << ( m_nLUTBitDepth - 1 ) ); |
---|
| 85 | Int nMax = - nMin - ( 1 << nResQuantBit ); |
---|
| 86 | Int nMask = ( 1 << nResQuantBit ) - 1; |
---|
| 87 | |
---|
| 88 | Double dMinError = MAX_DOUBLE; |
---|
| 89 | Int nTestRange = 2; |
---|
| 90 | Int nStepSize = 1 << nResQuantBit; |
---|
| 91 | for( Int i = - nTestRange ; i <= nTestRange ; i++ ) |
---|
| 92 | { |
---|
| 93 | for( Int j = - nTestRange ; j <= nTestRange ; j++ ) |
---|
| 94 | { |
---|
| 95 | for( Int k = - nTestRange ; k <= nTestRange ; k++ ) |
---|
| 96 | { |
---|
| 97 | Int nTestP0 = Clip3( nMin , nMax , nInitP0 + i * nStepSize ); |
---|
| 98 | Int nTestP1 = Clip3( nMin , nMax , nInitP1 + j * nStepSize ); |
---|
| 99 | Int nTestP3 = Clip3( nMin , nMax , nInitP3 + k * nStepSize ); |
---|
| 100 | Double a = 1.0 * nTestP0 / nOne; |
---|
| 101 | Double b = 1.0 * nTestP1 / nOne; |
---|
| 102 | Double c = 1.0 * nTestP3 / nOne; |
---|
| 103 | Double d = ( Ys - a * ys - b * us - c * vs ) / N; |
---|
| 104 | nInitP7 = ( ( Int )d ) >> nResQuantBit << nResQuantBit; |
---|
| 105 | for( Int m = 0 ; m < 2 ; m++ ) |
---|
| 106 | { |
---|
| 107 | Int nTestP7 = Clip3( nMin , nMax , nInitP7 + m * nStepSize ); |
---|
| 108 | Double dError = xxCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , a , b , c , nTestP7 ); |
---|
| 109 | if( dError < dMinError ) |
---|
| 110 | { |
---|
| 111 | dMinError = dError; |
---|
| 112 | rP0 = ( Pel )nTestP0; |
---|
| 113 | rP1 = ( Pel )nTestP1; |
---|
| 114 | rP3 = ( Pel )nTestP3; |
---|
| 115 | rP7 = ( Pel )nTestP7; |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | assert( !( rP0 & nMask ) && !( rP1 & nMask ) && !( rP3 & nMask ) && !( rP7 & nMask ) ); |
---|
| 122 | |
---|
| 123 | return( dMinError ); |
---|
| 124 | } |
---|
| 125 | #else |
---|
| 126 | 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 , |
---|
[677] | 127 | Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV , |
---|
| 128 | Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit ) |
---|
| 129 | { |
---|
| 130 | Int nInitP0 = rP0; |
---|
| 131 | Int nInitP1 = rP1; |
---|
| 132 | Int nInitP3 = rP3; |
---|
| 133 | Int nInitP7 = rP7; |
---|
| 134 | |
---|
| 135 | 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); |
---|
| 136 | if( N > 16 && dNorm != 0 ) |
---|
| 137 | { |
---|
| 138 | 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; |
---|
| 139 | 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; |
---|
| 140 | 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; |
---|
| 141 | Double dInitD = (-uu * yy * vs * Yv + uu * yy * Ys * vv + uu * vs * yv * Yy - uu * ys * Yy * vv + uu * ys * yv * Yv - uu * Ys * yv * yv + yy * vs * uv * Yu + yy * us * uv * Yv - yy * Ys * uv * uv - yy * us * Yu * vv + ys * yu * Yu * vv + vs * Yv * yu * yu + ys * Yy * uv * uv - us * yu * yv * Yv + us * yu * Yy * vv + 2 * Ys * yv * uv * yu - vs * uv * yu * Yy - vs * yv * yu * Yu - Ys * vv * yu * yu - us * uv * yv * Yy - ys * yv * uv * Yu - ys * yu * uv * Yv + us * Yu * yv * yv) / dNorm; |
---|
| 142 | nInitP0 = xxCoeff2Vertex( dInitA , dInitB , dInitC , dInitD , y0 , u0 , v0 ) >> nResQuantBit << nResQuantBit ; |
---|
| 143 | nInitP1 = xxCoeff2Vertex( dInitA , dInitB , dInitC , dInitD , y0 , u0 + nLengthUV , v0 ) >> nResQuantBit << nResQuantBit ; |
---|
| 144 | nInitP3 = xxCoeff2Vertex( dInitA , dInitB , dInitC , dInitD , y0 , u0 + nLengthUV , v0 + nLengthUV ) >> nResQuantBit << nResQuantBit ; |
---|
| 145 | nInitP7 = xxCoeff2Vertex( dInitA , dInitB , dInitC , dInitD , y0 + nLengthY , u0 + nLengthUV , v0 + nLengthUV ) >> nResQuantBit << nResQuantBit ; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | Int nMin = - ( 1 << ( m_nLUTBitDepth - 1 ) ); |
---|
| 149 | Int nMax = - nMin - ( 1 << nResQuantBit ); |
---|
| 150 | Int nMask = ( 1 << nResQuantBit ) - 1; |
---|
| 151 | |
---|
| 152 | Double dMinError = MAX_DOUBLE; |
---|
| 153 | Int testRange = 2; |
---|
| 154 | for( Int i = - testRange , nDeltaP01 = nInitP1 - nInitP0 - testRange * ( 1 << nResQuantBit ) ; i <= testRange ; i++ , nDeltaP01 += ( 1 << nResQuantBit ) ) |
---|
| 155 | { |
---|
| 156 | for( Int j = - testRange , nDeltaP13 = nInitP3 - nInitP1 - testRange * ( 1 << nResQuantBit ) ; j <= testRange ; j++ , nDeltaP13 += ( 1 << nResQuantBit ) ) |
---|
| 157 | { |
---|
| 158 | for( Int k = - testRange , nDeltaP37 = nInitP7 - nInitP3 - testRange * ( 1 << nResQuantBit ) ; k <= testRange ; k++ , nDeltaP37 += ( 1 << nResQuantBit ) ) |
---|
| 159 | { |
---|
| 160 | Double a = 1.0 * nDeltaP37 / nLengthY; |
---|
| 161 | Double b = 1.0 * nDeltaP01 / nLengthUV; |
---|
| 162 | Double c = 1.0 * nDeltaP13 / nLengthUV; |
---|
| 163 | Double d = ( Ys - a * ys - b * us - c * vs ) / N; |
---|
| 164 | Int nP0 = xxCoeff2Vertex( a , b , c , d , y0 , u0 , v0 ) >> nResQuantBit << nResQuantBit ; |
---|
| 165 | nP0 = Clip3( nMin , nMax , nP0 ); |
---|
| 166 | Int nP1 = Clip3( nMin , nMax , nP0 + nDeltaP01 ); |
---|
| 167 | Int nP3 = Clip3( nMin , nMax , nP1 + nDeltaP13 ); |
---|
| 168 | Int nP7 = Clip3( nMin , nMax , nP3 + nDeltaP37 ); |
---|
[684] | 169 | if ( nP0 & nMask ) |
---|
| 170 | { |
---|
[677] | 171 | nP0 -= ( nP0 & nMask ); |
---|
[684] | 172 | } |
---|
| 173 | if ( nP1 & nMask ) |
---|
| 174 | { |
---|
[677] | 175 | nP1 -= ( nP1 & nMask ); |
---|
[684] | 176 | } |
---|
| 177 | if ( nP3 & nMask ) |
---|
| 178 | { |
---|
[677] | 179 | nP3 -= ( nP3 & nMask ); |
---|
[684] | 180 | } |
---|
| 181 | if ( nP7 & nMask ) |
---|
| 182 | { |
---|
[677] | 183 | nP7 -= ( nP7 & nMask ); |
---|
[684] | 184 | } |
---|
[677] | 185 | assert( !( nP0 & nMask ) && !( nP1 & nMask ) && !( nP3 & nMask ) && !( nP7 & nMask ) ); |
---|
| 186 | Double dError = xxCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , y0 , u0 , v0 , nLengthY , nLengthUV , nP0 , nP1 , nP3 , nP7 ); |
---|
| 187 | if( dError < dMinError ) |
---|
| 188 | { |
---|
| 189 | dMinError = dError; |
---|
| 190 | rP0 = ( Pel )nP0; |
---|
| 191 | rP1 = ( Pel )nP1; |
---|
| 192 | rP3 = ( Pel )nP3; |
---|
| 193 | rP7 = ( Pel )nP7; |
---|
| 194 | assert( nMin <= rP0 && rP0 <= nMax && nMin <= rP1 && rP1 <= nMax && nMin <= rP3 && rP3 <= nMax && nMin <= rP7 && rP7 <= nMax ); |
---|
| 195 | } |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | return( dMinError ); |
---|
| 201 | } |
---|
[825] | 202 | #endif |
---|
[677] | 203 | |
---|
[825] | 204 | #if R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
[677] | 205 | Double TEnc3DAsymLUT::estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc ) |
---|
| 206 | { |
---|
| 207 | xxCollectData( pCurPic , refLayerIdc ); |
---|
| 208 | |
---|
| 209 | Double dErrorLuma = 0 , dErrorChroma = 0; |
---|
| 210 | Int nYSize = 1 << ( getCurOctantDepth() + getCurYPartNumLog2() ); |
---|
| 211 | Int nUVSize = 1 << getCurOctantDepth(); |
---|
[825] | 212 | for( Int yIdx = 0 ; yIdx < nYSize ; yIdx++ ) |
---|
| 213 | { |
---|
| 214 | for( Int uIdx = 0 ; uIdx < nUVSize ; uIdx++ ) |
---|
| 215 | { |
---|
| 216 | for( Int vIdx = 0 ; vIdx < nUVSize ; vIdx++ ) |
---|
| 217 | { |
---|
| 218 | SColorInfo & rCuboidColorInfo = m_pColorInfo[yIdx][uIdx][vIdx]; |
---|
| 219 | SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx]; |
---|
| 220 | SCuboid & rCuboid = xGetCuboid( yIdx , uIdx , vIdx ); |
---|
| 221 | if( rCuboidColorInfo.N > 0 ) |
---|
| 222 | { |
---|
| 223 | 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 , |
---|
| 224 | rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y ); |
---|
| 225 | } |
---|
| 226 | if( rCuboidColorInfoC.N > 0 ) |
---|
| 227 | { |
---|
| 228 | 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 , |
---|
| 229 | rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U ); |
---|
| 230 | 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 , |
---|
| 231 | rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V ); |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | return( dErrorLuma + dErrorChroma); |
---|
| 238 | } |
---|
| 239 | #else |
---|
| 240 | Double TEnc3DAsymLUT::estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc ) |
---|
| 241 | { |
---|
| 242 | xxCollectData( pCurPic , refLayerIdc ); |
---|
| 243 | |
---|
| 244 | Double dErrorLuma = 0 , dErrorChroma = 0; |
---|
| 245 | Int nYSize = 1 << ( getCurOctantDepth() + getCurYPartNumLog2() ); |
---|
| 246 | Int nUVSize = 1 << getCurOctantDepth(); |
---|
[677] | 247 | Int nLengthY = 1 << ( getInputBitDepthY() - getCurOctantDepth() - getCurYPartNumLog2() ); |
---|
| 248 | Int nLengthUV = 1 << ( getInputBitDepthC() - getCurOctantDepth() ); |
---|
| 249 | for( Int yIdx = 0 ; yIdx < nYSize ; yIdx++ ) |
---|
| 250 | { |
---|
| 251 | for( Int uIdx = 0 ; uIdx < nUVSize ; uIdx++ ) |
---|
| 252 | { |
---|
| 253 | for( Int vIdx = 0 ; vIdx < nUVSize ; vIdx++ ) |
---|
| 254 | { |
---|
| 255 | SColorInfo & rCuboidColorInfo = m_pColorInfo[yIdx][uIdx][vIdx]; |
---|
| 256 | SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx]; |
---|
| 257 | SCuboid & rCuboid = xGetCuboid( yIdx , uIdx , vIdx ); |
---|
| 258 | Int y0 = yIdx << xGetYShift2Idx(); |
---|
| 259 | Int u0 = uIdx << xGetUShift2Idx(); |
---|
| 260 | Int v0 = vIdx << xGetVShift2Idx(); |
---|
| 261 | if( rCuboidColorInfo.N > 0 ) |
---|
| 262 | { |
---|
| 263 | 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 , |
---|
| 264 | y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y ); |
---|
| 265 | } |
---|
| 266 | if( rCuboidColorInfoC.N > 0 ) |
---|
| 267 | { |
---|
| 268 | 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 , |
---|
| 269 | y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U ); |
---|
| 270 | 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 , |
---|
| 271 | y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V ); |
---|
| 272 | } |
---|
[684] | 273 | } |
---|
[677] | 274 | } |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | return( dErrorLuma + dErrorChroma); |
---|
| 278 | } |
---|
[825] | 279 | #endif |
---|
[677] | 280 | |
---|
[825] | 281 | #if R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
[677] | 282 | Double TEnc3DAsymLUT::derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB ) |
---|
| 283 | { |
---|
| 284 | m_nLUTBitDepth = pCfg->getCGSLUTBit(); |
---|
| 285 | Int nCurYPartNumLog2 = 0 , nCurOctantDepth = 0; |
---|
| 286 | xxDerivePartNumLog2( pSlice , pCfg , nCurOctantDepth , nCurYPartNumLog2 , bSignalPPS , bElRapSliceTypeB ); |
---|
[825] | 287 | |
---|
| 288 | Int nBestResQuanBit = 0; |
---|
| 289 | Int nBestAdaptCThresholdU = 1 << ( getInputBitDepthC() - 1 ); |
---|
| 290 | Int nBestAdaptCThresholdV = 1 << ( getInputBitDepthC() - 1 ); |
---|
| 291 | Int nBestOctantDepth = nCurOctantDepth; |
---|
| 292 | Int nBestYPartNumLog2 = nCurYPartNumLog2; |
---|
| 293 | Int nTargetLoop = 1 + ( pCfg->getCGSAdaptChroma() && ( nCurOctantDepth == 1 || ( nCurOctantDepth * 3 + nCurYPartNumLog2 ) >= 5 ) ); |
---|
| 294 | Double dMinError = MAX_DOUBLE; |
---|
| 295 | for( Int nLoop = 0 ; nLoop < nTargetLoop ; nLoop++ ) |
---|
| 296 | { |
---|
| 297 | Int nAdaptCThresholdU = 1 << ( getInputBitDepthC() - 1 ); |
---|
| 298 | Int nAdaptCThresholdV = 1 << ( getInputBitDepthC() - 1 ); |
---|
| 299 | if( nLoop > 0 ) |
---|
| 300 | { |
---|
| 301 | nAdaptCThresholdU = ( Int )( m_dSumU / m_nNChroma + 0.5 ); |
---|
| 302 | nAdaptCThresholdV = ( Int )( m_dSumV / m_nNChroma + 0.5 ); |
---|
| 303 | if( nCurOctantDepth > 1 ) |
---|
| 304 | { |
---|
| 305 | nCurOctantDepth = 1; |
---|
| 306 | nCurYPartNumLog2 = 2; |
---|
| 307 | } |
---|
| 308 | if( nAdaptCThresholdU == nBestAdaptCThresholdU && nAdaptCThresholdV == nBestAdaptCThresholdV |
---|
| 309 | && nCurOctantDepth == nBestOctantDepth && nCurYPartNumLog2 == nBestYPartNumLog2 ) |
---|
| 310 | break; |
---|
| 311 | } |
---|
| 312 | xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2 , nAdaptCThresholdU , nAdaptCThresholdV ); |
---|
| 313 | xxCollectData( pCurPic , refLayerIdc ); |
---|
| 314 | for( Int nResQuanBit = 0 ; nResQuanBit < 4 ; nResQuanBit++ ) |
---|
| 315 | { |
---|
| 316 | Double dError = xxDeriveVertexes( nResQuanBit , m_pEncCuboid ) / ( 1 + ( nResQuanBit > 0 ) * 0.001 * ( pSlice->getDepth() + 1 ) ); |
---|
| 317 | if( dError <= dMinError ) |
---|
| 318 | { |
---|
| 319 | nBestResQuanBit = nResQuanBit; |
---|
| 320 | nBestAdaptCThresholdU = nAdaptCThresholdU; |
---|
| 321 | nBestAdaptCThresholdV = nAdaptCThresholdV; |
---|
| 322 | nBestOctantDepth = nCurOctantDepth; |
---|
| 323 | nBestYPartNumLog2 = nCurYPartNumLog2; |
---|
| 324 | SCuboid *** tmp = m_pBestEncCuboid; |
---|
| 325 | m_pBestEncCuboid = m_pEncCuboid; |
---|
| 326 | m_pEncCuboid = tmp; |
---|
| 327 | dMinError = dError; |
---|
| 328 | } |
---|
| 329 | else |
---|
| 330 | { |
---|
| 331 | break; |
---|
| 332 | } |
---|
| 333 | } |
---|
| 334 | } |
---|
| 335 | setResQuantBit( nBestResQuanBit ); |
---|
| 336 | xUpdatePartitioning( nBestOctantDepth , nBestYPartNumLog2 , nBestAdaptCThresholdU , nBestAdaptCThresholdV ); |
---|
| 337 | xSaveCuboids( m_pBestEncCuboid ); |
---|
| 338 | return( dMinError ); |
---|
| 339 | } |
---|
| 340 | #else |
---|
| 341 | Double TEnc3DAsymLUT::derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB ) |
---|
| 342 | { |
---|
| 343 | m_nLUTBitDepth = pCfg->getCGSLUTBit(); |
---|
| 344 | Int nCurYPartNumLog2 = 0 , nCurOctantDepth = 0; |
---|
| 345 | xxDerivePartNumLog2( pSlice , pCfg , nCurOctantDepth , nCurYPartNumLog2 , bSignalPPS , bElRapSliceTypeB ); |
---|
[677] | 346 | xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2 ); |
---|
| 347 | xxCollectData( pCurPic , refLayerIdc ); |
---|
| 348 | Int nBestResQuanBit = 0; |
---|
| 349 | Double dError0 = xxDeriveVertexes( nBestResQuanBit , m_pBestEncCuboid ); |
---|
| 350 | Double dCurError = dError0; |
---|
| 351 | Double dFactor = 1 + 0.001 * ( pSlice->getDepth() + 1 ); |
---|
| 352 | for( Int nResQuanBit = 1 ; nResQuanBit < 4 ; nResQuanBit++ ) |
---|
| 353 | { |
---|
| 354 | Double dError = xxDeriveVertexes( nResQuanBit , m_pEncCuboid ); |
---|
| 355 | if( dError < dError0 * dFactor ) |
---|
| 356 | { |
---|
| 357 | nBestResQuanBit = nResQuanBit; |
---|
| 358 | SCuboid *** tmp = m_pBestEncCuboid; |
---|
| 359 | m_pBestEncCuboid = m_pEncCuboid; |
---|
| 360 | m_pEncCuboid = tmp; |
---|
| 361 | dCurError = dError; |
---|
| 362 | } |
---|
| 363 | else |
---|
[684] | 364 | { |
---|
[677] | 365 | break; |
---|
[684] | 366 | } |
---|
[677] | 367 | } |
---|
| 368 | setResQuantBit( nBestResQuanBit ); |
---|
| 369 | xSaveCuboids( m_pBestEncCuboid ); |
---|
| 370 | return( dCurError ); |
---|
| 371 | } |
---|
[825] | 372 | #endif |
---|
[677] | 373 | |
---|
| 374 | Double TEnc3DAsymLUT::xxDeriveVertexes( Int nResQuanBit , SCuboid *** pCurCuboid ) |
---|
| 375 | { |
---|
| 376 | Double dErrorLuma = 0 , dErrorChroma = 0; |
---|
| 377 | Int nYSize = 1 << ( getCurOctantDepth() + getCurYPartNumLog2() ); |
---|
| 378 | Int nUVSize = 1 << getCurOctantDepth(); |
---|
[825] | 379 | #if !R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
[677] | 380 | Int nLengthY = 1 << ( getInputBitDepthY() - getCurOctantDepth() - getCurYPartNumLog2() ); |
---|
| 381 | Int nLengthUV = 1 << ( getInputBitDepthC() - getCurOctantDepth() ); |
---|
[825] | 382 | #endif |
---|
[677] | 383 | for( Int yIdx = 0 ; yIdx < nYSize ; yIdx++ ) |
---|
| 384 | { |
---|
| 385 | for( Int uIdx = 0 ; uIdx < nUVSize ; uIdx++ ) |
---|
| 386 | { |
---|
| 387 | for( Int vIdx = 0 ; vIdx < nUVSize ; vIdx++ ) |
---|
| 388 | { |
---|
| 389 | SColorInfo & rCuboidColorInfo = m_pColorInfo[yIdx][uIdx][vIdx]; |
---|
| 390 | SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx]; |
---|
| 391 | SCuboid & rCuboid = pCurCuboid[yIdx][uIdx][vIdx]; |
---|
[825] | 392 | #if !R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
[677] | 393 | Int y0 = yIdx << xGetYShift2Idx(); |
---|
| 394 | Int u0 = uIdx << xGetUShift2Idx(); |
---|
| 395 | Int v0 = vIdx << xGetVShift2Idx(); |
---|
[825] | 396 | #endif |
---|
[677] | 397 | for( Int idxVertex = 0 ; idxVertex < 4 ; idxVertex++ ) |
---|
[684] | 398 | { |
---|
[677] | 399 | rCuboid.P[idxVertex] = xGetCuboidVertexPredAll( yIdx , uIdx , vIdx , idxVertex , pCurCuboid ); |
---|
[684] | 400 | } |
---|
[677] | 401 | |
---|
| 402 | if( rCuboidColorInfo.N > 0 ) |
---|
| 403 | { |
---|
| 404 | 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] | 405 | #if !R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
| 406 | y0 , u0 , v0 , nLengthY , nLengthUV , |
---|
| 407 | #endif |
---|
| 408 | rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y , nResQuanBit ); |
---|
[677] | 409 | } |
---|
| 410 | if( rCuboidColorInfoC.N > 0 ) |
---|
| 411 | { |
---|
| 412 | 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] | 413 | #if !R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
| 414 | y0 , u0 , v0 , nLengthY , nLengthUV , |
---|
| 415 | #endif |
---|
| 416 | rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U , nResQuanBit ); |
---|
[677] | 417 | 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] | 418 | #if !R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
| 419 | y0 , u0 , v0 , nLengthY , nLengthUV , |
---|
| 420 | #endif |
---|
| 421 | rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V , nResQuanBit ); |
---|
[677] | 422 | } |
---|
| 423 | |
---|
| 424 | if( nResQuanBit > 0 ) |
---|
| 425 | { |
---|
| 426 | // check quantization |
---|
| 427 | for( Int idxVertex = 0 ; idxVertex < 4 ; idxVertex++ ) |
---|
| 428 | { |
---|
| 429 | SYUVP sPred = xGetCuboidVertexPredAll( yIdx , uIdx , vIdx , idxVertex , pCurCuboid ); |
---|
| 430 | assert( ( ( rCuboid.P[idxVertex].Y - sPred.Y ) >> nResQuanBit << nResQuanBit ) == rCuboid.P[idxVertex].Y - sPred.Y ); |
---|
| 431 | assert( ( ( rCuboid.P[idxVertex].U - sPred.U ) >> nResQuanBit << nResQuanBit ) == rCuboid.P[idxVertex].U - sPred.U ); |
---|
| 432 | assert( ( ( rCuboid.P[idxVertex].V - sPred.V ) >> nResQuanBit << nResQuanBit ) == rCuboid.P[idxVertex].V - sPred.V ); |
---|
| 433 | } |
---|
| 434 | } |
---|
| 435 | } |
---|
| 436 | } |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | return( dErrorLuma + dErrorChroma ); |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | Void TEnc3DAsymLUT::xxCollectData( TComPic * pCurPic , UInt refLayerIdc ) |
---|
| 443 | { |
---|
| 444 | Pel * pSrcY = m_pDsOrigPic->getLumaAddr(); |
---|
| 445 | Pel * pSrcU = m_pDsOrigPic->getCbAddr(); |
---|
| 446 | Pel * pSrcV = m_pDsOrigPic->getCrAddr(); |
---|
| 447 | Int nStrideSrcY = m_pDsOrigPic->getStride(); |
---|
| 448 | Int nStrideSrcC = m_pDsOrigPic->getCStride(); |
---|
| 449 | TComPicYuv *pRecPic = pCurPic->getSlice(pCurPic->getCurrSliceIdx())->getBaseColPic(refLayerIdc)->getPicYuvRec(); |
---|
| 450 | Pel * pIRLY = pRecPic->getLumaAddr(); |
---|
| 451 | Pel * pIRLU = pRecPic->getCbAddr(); |
---|
| 452 | Pel * pIRLV = pRecPic->getCrAddr(); |
---|
| 453 | Int nStrideILRY = pRecPic->getStride(); |
---|
| 454 | Int nStrideILRC = pRecPic->getCStride(); |
---|
| 455 | xReset3DArray( m_pColorInfo , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
| 456 | xReset3DArray( m_pColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
| 457 | |
---|
| 458 | //alignment padding |
---|
[815] | 459 | pRecPic->setBorderExtension( false ); |
---|
| 460 | pRecPic->extendPicBorder(); |
---|
[677] | 461 | |
---|
[815] | 462 | TComSlice * pSlice = pCurPic->getSlice(pCurPic->getCurrSliceIdx()); |
---|
| 463 | UInt refLayerId = pSlice->getVPS()->getRefLayerId(pSlice->getLayerId(), refLayerIdc); |
---|
| 464 | const Window &scalEL = pSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId); |
---|
| 465 | TComPicYuv *pcRecPicBL = pSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(); |
---|
| 466 | // borders of down-sampled picture |
---|
| 467 | Int leftDS = (scalEL.getWindowLeftOffset()*g_posScalingFactor[refLayerIdc][0]+(1<<15))>>16; |
---|
| 468 | Int rightDS = pcRecPicBL->getWidth() - 1 + (((scalEL.getWindowRightOffset())*g_posScalingFactor[refLayerIdc][0]+(1<<15))>>16); |
---|
| 469 | Int topDS = (((scalEL.getWindowTopOffset())*g_posScalingFactor[refLayerIdc][1]+(1<<15))>>16); |
---|
| 470 | Int bottomDS = pcRecPicBL->getHeight() - 1 + (((scalEL.getWindowBottomOffset())*g_posScalingFactor[refLayerIdc][1]+(1<<15))>>16); |
---|
| 471 | // overlapped region |
---|
| 472 | Int left = max( 0 , leftDS ); |
---|
| 473 | Int right = min( pcRecPicBL->getWidth() - 1 , rightDS ); |
---|
| 474 | Int top = max( 0 , topDS ); |
---|
| 475 | Int bottom = min( pcRecPicBL->getHeight() - 1 , bottomDS ); |
---|
| 476 | // since we do data collection only for overlapped region, the border extension is good enough |
---|
[677] | 477 | |
---|
[825] | 478 | #if R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
| 479 | m_dSumU = m_dSumV = 0; |
---|
| 480 | m_nNChroma = 0; |
---|
| 481 | #endif |
---|
[815] | 482 | for( Int i = top ; i <= bottom ; i++ ) |
---|
[677] | 483 | { |
---|
[815] | 484 | Int iDS = i-topDS; |
---|
| 485 | Int jDS = left-leftDS; |
---|
| 486 | Int posSrcY = iDS * nStrideSrcY + jDS; |
---|
| 487 | Int posIRLY = i * nStrideILRY + left; |
---|
| 488 | Int posSrcUV = ( iDS >> 1 ) * nStrideSrcC + (jDS>>1); |
---|
| 489 | Int posIRLUV = ( i >> 1 ) * nStrideILRC + (left>>1); |
---|
| 490 | for( Int j = left ; j <= right ; j++ , posSrcY++ , posIRLY++ , posSrcUV += !( j & 0x01 ) , posIRLUV += !( j & 0x01 ) ) |
---|
[677] | 491 | { |
---|
| 492 | Int Y = pSrcY[posSrcY]; |
---|
| 493 | Int y = pIRLY[posIRLY]; |
---|
| 494 | Int U = pSrcU[posSrcUV]; |
---|
| 495 | Int u = pIRLU[posIRLUV]; |
---|
| 496 | Int V = pSrcV[posSrcUV]; |
---|
| 497 | Int v = pIRLV[posIRLUV]; |
---|
| 498 | |
---|
| 499 | // alignment |
---|
| 500 | //filtering u, v for luma; |
---|
| 501 | Int posIRLUVN = posIRLUV + ((i&1)? nStrideILRC : -nStrideILRC); |
---|
| 502 | if((j&1)) |
---|
| 503 | { |
---|
| 504 | u = (pIRLU[posIRLUVN] + pIRLU[posIRLUVN+1] +(u + pIRLU[posIRLUV+1])*3 +4)>>3; |
---|
| 505 | v = (pIRLV[posIRLUVN] + pIRLV[posIRLUVN+1] +(v + pIRLV[posIRLUV+1])*3 +4)>>3; |
---|
| 506 | } |
---|
| 507 | else |
---|
| 508 | { |
---|
| 509 | u = (pIRLU[posIRLUVN] +u*3 +2)>>2; |
---|
| 510 | v = (pIRLV[posIRLUVN] +v*3 +2)>>2; |
---|
| 511 | } |
---|
| 512 | |
---|
[825] | 513 | #if R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
| 514 | m_dSumU += u; |
---|
| 515 | m_dSumV += v; |
---|
| 516 | m_nNChroma++; |
---|
| 517 | #endif |
---|
[677] | 518 | SColorInfo sColorInfo; |
---|
[825] | 519 | #if R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
| 520 | SColorInfo & rCuboidColorInfo = m_pColorInfo[xGetYIdx(y)][xGetUIdx(u)][xGetVIdx(v)]; |
---|
| 521 | #else |
---|
[677] | 522 | SColorInfo & rCuboidColorInfo = m_pColorInfo[y>>xGetYShift2Idx()][u>>xGetUShift2Idx()][v>>xGetVShift2Idx()]; |
---|
[825] | 523 | #endif |
---|
[677] | 524 | memset(&sColorInfo, 0, sizeof(SColorInfo)); |
---|
| 525 | sColorInfo.Ys = Y; |
---|
| 526 | sColorInfo.ys = y; |
---|
| 527 | sColorInfo.us = u; |
---|
| 528 | sColorInfo.vs = v; |
---|
| 529 | sColorInfo.Yy = Y * y; |
---|
| 530 | sColorInfo.Yu = Y * u; |
---|
| 531 | sColorInfo.Yv = Y * v; |
---|
| 532 | sColorInfo.yy = y * y; |
---|
| 533 | sColorInfo.yu = y * u; |
---|
| 534 | sColorInfo.yv = y * v; |
---|
| 535 | sColorInfo.uu = u * u; |
---|
| 536 | sColorInfo.uv = u * v; |
---|
| 537 | sColorInfo.vv = v * v; |
---|
| 538 | sColorInfo.YY = Y * Y; |
---|
| 539 | sColorInfo.N = 1; |
---|
| 540 | |
---|
| 541 | rCuboidColorInfo += sColorInfo; |
---|
| 542 | |
---|
| 543 | if(!((i&1) || (j&1))) |
---|
| 544 | { |
---|
| 545 | // alignment |
---|
| 546 | y = (pIRLY[posIRLY] + pIRLY[posIRLY+nStrideILRY] + 1)>>1; |
---|
| 547 | |
---|
| 548 | u = pIRLU[posIRLUV]; |
---|
| 549 | v = pIRLV[posIRLUV]; |
---|
[825] | 550 | #if R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
| 551 | SColorInfo & rCuboidColorInfoC = m_pColorInfoC[xGetYIdx(y)][xGetUIdx(u)][xGetVIdx(v)]; |
---|
| 552 | #else |
---|
[677] | 553 | SColorInfo & rCuboidColorInfoC = m_pColorInfoC[y>>xGetYShift2Idx()][u>>xGetUShift2Idx()][v>>xGetVShift2Idx()]; |
---|
[825] | 554 | #endif |
---|
[677] | 555 | sColorInfo.Us = U; |
---|
| 556 | sColorInfo.Vs = V; |
---|
| 557 | sColorInfo.ys = y; |
---|
| 558 | sColorInfo.us = u; |
---|
| 559 | sColorInfo.vs = v; |
---|
| 560 | |
---|
| 561 | sColorInfo.Uy = U * y; |
---|
| 562 | sColorInfo.Uu = U * u; |
---|
| 563 | sColorInfo.Uv = U * v; |
---|
| 564 | sColorInfo.Vy = V * y; |
---|
| 565 | sColorInfo.Vu = V * u; |
---|
| 566 | sColorInfo.Vv = V * v; |
---|
| 567 | sColorInfo.yy = y * y; |
---|
| 568 | sColorInfo.yu = y * u; |
---|
| 569 | sColorInfo.yv = y * v; |
---|
| 570 | sColorInfo.uu = u * u; |
---|
| 571 | sColorInfo.uv = u * v; |
---|
| 572 | sColorInfo.vv = v * v; |
---|
| 573 | sColorInfo.UU = U * U; |
---|
| 574 | sColorInfo.VV = V * V; |
---|
| 575 | sColorInfo.N = 1; |
---|
| 576 | |
---|
| 577 | rCuboidColorInfoC += sColorInfo; |
---|
| 578 | } |
---|
| 579 | } |
---|
| 580 | } |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | Void TEnc3DAsymLUT::xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB ) |
---|
| 584 | { |
---|
| 585 | Int nPartNumLog2 = 4; |
---|
| 586 | if( pSlice->getBaseColPic( pSlice->getInterLayerPredLayerIdc( 0 ) )->getSlice( 0 )->isIntra() ) |
---|
[684] | 587 | { |
---|
[677] | 588 | nPartNumLog2 = xGetMaxPartNumLog2(); |
---|
[684] | 589 | } |
---|
[825] | 590 | if( m_nAccuFrameBit && pSlice->getPPS()->getCGSFlag() ) |
---|
[677] | 591 | { |
---|
[825] | 592 | Double dBitCost = 1.0 * m_nAccuFrameCGSBit / m_nAccuFrameBit; |
---|
| 593 | nPartNumLog2 = m_nPrevFrameCGSPartNumLog2; |
---|
[677] | 594 | Double dBitCostT = 0.03; |
---|
| 595 | if( dBitCost < dBitCostT / 6.0 ) |
---|
| 596 | { |
---|
| 597 | nPartNumLog2++; |
---|
| 598 | } |
---|
| 599 | else if( dBitCost >= dBitCostT ) |
---|
| 600 | { |
---|
| 601 | nPartNumLog2--; |
---|
| 602 | } |
---|
| 603 | } |
---|
[825] | 604 | nPartNumLog2 = Clip3( 0 , xGetMaxPartNumLog2() , nPartNumLog2 ); |
---|
[677] | 605 | xxMapPartNum2DepthYPart( nPartNumLog2 , rOctantDepth , rYPartNumLog2 ); |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | Void TEnc3DAsymLUT::xxMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 ) |
---|
| 609 | { |
---|
| 610 | for( Int y = getMaxYPartNumLog2() ; y >= 0 ; y-- ) |
---|
| 611 | { |
---|
| 612 | for( Int depth = ( nPartNumLog2 - y ) >> 1 ; depth >= 0 ; depth-- ) |
---|
| 613 | { |
---|
| 614 | if( y + 3 * depth == nPartNumLog2 ) |
---|
| 615 | { |
---|
| 616 | rOctantDepth = depth; |
---|
| 617 | rYPartNumLog2 = y; |
---|
| 618 | return; |
---|
| 619 | } |
---|
| 620 | } |
---|
| 621 | } |
---|
| 622 | rOctantDepth = min( getMaxOctantDepth() , nPartNumLog2 / 3 ); |
---|
| 623 | rYPartNumLog2 = min( getMaxYPartNumLog2() , nPartNumLog2 - 3 * rOctantDepth ); |
---|
| 624 | } |
---|
| 625 | |
---|
| 626 | Void TEnc3DAsymLUT::updatePicCGSBits( TComSlice * pcSlice , Int nPPSBit ) |
---|
| 627 | { |
---|
| 628 | for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
---|
| 629 | { |
---|
| 630 | UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i); |
---|
[825] | 631 | m_nAccuFrameBit += pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit(); |
---|
[677] | 632 | m_dTotalFrameBit += pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit(); |
---|
| 633 | } |
---|
[825] | 634 | m_nAccuFrameCGSBit += nPPSBit; |
---|
[677] | 635 | m_nTotalCGSBit += nPPSBit; |
---|
[825] | 636 | m_nPrevFrameCGSPartNumLog2 = getCurOctantDepth() * 3 + getCurYPartNumLog2(); |
---|
[677] | 637 | } |
---|
| 638 | |
---|
| 639 | #endif |
---|