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; |
---|
17 | memset( m_nPrevFrameBit , 0 , sizeof( m_nPrevFrameBit ) ); |
---|
18 | memset( m_nPrevFrameCGSBit , 0 , sizeof( m_nPrevFrameCGSBit ) ); |
---|
19 | memset( m_nPrevFrameCGSPartNumLog2 , 0 , sizeof( m_nPrevFrameCGSPartNumLog2 ) ); |
---|
20 | memset( m_nPrevFrameOverWritePPS , 0 , sizeof( m_nPrevFrameOverWritePPS ) ); |
---|
21 | m_dTotalFrameBit = 0; |
---|
22 | m_nTotalCGSBit = 0; |
---|
23 | m_nPPSBit = 0; |
---|
24 | m_pDsOrigPic = NULL; |
---|
25 | } |
---|
26 | |
---|
27 | Void TEnc3DAsymLUT::create( Int nMaxOctantDepth , Int nInputBitDepth , Int nInputBitDepthC , Int nOutputBitDepth , Int nOutputBitDepthC , Int nMaxYPartNumLog2 ) |
---|
28 | { |
---|
29 | if( m_pColorInfo != NULL ) |
---|
30 | { |
---|
31 | destroy(); |
---|
32 | } |
---|
33 | |
---|
34 | TCom3DAsymLUT::create( nMaxOctantDepth , nInputBitDepth , nInputBitDepthC, nOutputBitDepth , nOutputBitDepthC, nMaxYPartNumLog2 ); |
---|
35 | xAllocate3DArray( m_pColorInfo , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
36 | xAllocate3DArray( m_pColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
37 | xAllocate3DArray( m_pEncCuboid , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
38 | xAllocate3DArray( m_pBestEncCuboid , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
39 | } |
---|
40 | |
---|
41 | Void TEnc3DAsymLUT::destroy() |
---|
42 | { |
---|
43 | xFree3DArray( m_pColorInfo ); |
---|
44 | xFree3DArray( m_pColorInfoC ); |
---|
45 | xFree3DArray( m_pEncCuboid ); |
---|
46 | xFree3DArray( m_pBestEncCuboid ); |
---|
47 | TCom3DAsymLUT::destroy(); |
---|
48 | } |
---|
49 | |
---|
50 | TEnc3DAsymLUT::~TEnc3DAsymLUT() |
---|
51 | { |
---|
52 | if( m_dTotalFrameBit != 0 ) |
---|
53 | { |
---|
54 | printf( "\nTotal CGS bit: %d, %.2lf%%" , m_nTotalCGSBit , m_nTotalCGSBit * 100 / m_dTotalFrameBit ); |
---|
55 | } |
---|
56 | |
---|
57 | destroy(); |
---|
58 | } |
---|
59 | |
---|
60 | 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 , |
---|
61 | Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV , |
---|
62 | Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit ) |
---|
63 | { |
---|
64 | Int nInitP0 = rP0; |
---|
65 | Int nInitP1 = rP1; |
---|
66 | Int nInitP3 = rP3; |
---|
67 | Int nInitP7 = rP7; |
---|
68 | |
---|
69 | 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); |
---|
70 | if( N > 16 && dNorm != 0 ) |
---|
71 | { |
---|
72 | 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; |
---|
73 | 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; |
---|
74 | 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; |
---|
75 | 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; |
---|
76 | nInitP0 = xxCoeff2Vertex( dInitA , dInitB , dInitC , dInitD , y0 , u0 , v0 ) >> nResQuantBit << nResQuantBit ; |
---|
77 | nInitP1 = xxCoeff2Vertex( dInitA , dInitB , dInitC , dInitD , y0 , u0 + nLengthUV , v0 ) >> nResQuantBit << nResQuantBit ; |
---|
78 | nInitP3 = xxCoeff2Vertex( dInitA , dInitB , dInitC , dInitD , y0 , u0 + nLengthUV , v0 + nLengthUV ) >> nResQuantBit << nResQuantBit ; |
---|
79 | nInitP7 = xxCoeff2Vertex( dInitA , dInitB , dInitC , dInitD , y0 + nLengthY , u0 + nLengthUV , v0 + nLengthUV ) >> nResQuantBit << nResQuantBit ; |
---|
80 | } |
---|
81 | |
---|
82 | Int nMin = - ( 1 << ( m_nLUTBitDepth - 1 ) ); |
---|
83 | Int nMax = - nMin - ( 1 << nResQuantBit ); |
---|
84 | Int nMask = ( 1 << nResQuantBit ) - 1; |
---|
85 | |
---|
86 | Double dMinError = MAX_DOUBLE; |
---|
87 | Int testRange = 2; |
---|
88 | for( Int i = - testRange , nDeltaP01 = nInitP1 - nInitP0 - testRange * ( 1 << nResQuantBit ) ; i <= testRange ; i++ , nDeltaP01 += ( 1 << nResQuantBit ) ) |
---|
89 | { |
---|
90 | for( Int j = - testRange , nDeltaP13 = nInitP3 - nInitP1 - testRange * ( 1 << nResQuantBit ) ; j <= testRange ; j++ , nDeltaP13 += ( 1 << nResQuantBit ) ) |
---|
91 | { |
---|
92 | for( Int k = - testRange , nDeltaP37 = nInitP7 - nInitP3 - testRange * ( 1 << nResQuantBit ) ; k <= testRange ; k++ , nDeltaP37 += ( 1 << nResQuantBit ) ) |
---|
93 | { |
---|
94 | Double a = 1.0 * nDeltaP37 / nLengthY; |
---|
95 | Double b = 1.0 * nDeltaP01 / nLengthUV; |
---|
96 | Double c = 1.0 * nDeltaP13 / nLengthUV; |
---|
97 | Double d = ( Ys - a * ys - b * us - c * vs ) / N; |
---|
98 | Int nP0 = xxCoeff2Vertex( a , b , c , d , y0 , u0 , v0 ) >> nResQuantBit << nResQuantBit ; |
---|
99 | nP0 = Clip3( nMin , nMax , nP0 ); |
---|
100 | Int nP1 = Clip3( nMin , nMax , nP0 + nDeltaP01 ); |
---|
101 | Int nP3 = Clip3( nMin , nMax , nP1 + nDeltaP13 ); |
---|
102 | Int nP7 = Clip3( nMin , nMax , nP3 + nDeltaP37 ); |
---|
103 | if ( nP0 & nMask ) |
---|
104 | { |
---|
105 | nP0 -= ( nP0 & nMask ); |
---|
106 | } |
---|
107 | if ( nP1 & nMask ) |
---|
108 | { |
---|
109 | nP1 -= ( nP1 & nMask ); |
---|
110 | } |
---|
111 | if ( nP3 & nMask ) |
---|
112 | { |
---|
113 | nP3 -= ( nP3 & nMask ); |
---|
114 | } |
---|
115 | if ( nP7 & nMask ) |
---|
116 | { |
---|
117 | nP7 -= ( nP7 & nMask ); |
---|
118 | } |
---|
119 | assert( !( nP0 & nMask ) && !( nP1 & nMask ) && !( nP3 & nMask ) && !( nP7 & nMask ) ); |
---|
120 | 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 ); |
---|
121 | if( dError < dMinError ) |
---|
122 | { |
---|
123 | dMinError = dError; |
---|
124 | rP0 = ( Pel )nP0; |
---|
125 | rP1 = ( Pel )nP1; |
---|
126 | rP3 = ( Pel )nP3; |
---|
127 | rP7 = ( Pel )nP7; |
---|
128 | assert( nMin <= rP0 && rP0 <= nMax && nMin <= rP1 && rP1 <= nMax && nMin <= rP3 && rP3 <= nMax && nMin <= rP7 && rP7 <= nMax ); |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | return( dMinError ); |
---|
135 | } |
---|
136 | |
---|
137 | Double TEnc3DAsymLUT::estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc ) |
---|
138 | { |
---|
139 | xxCollectData( pCurPic , refLayerIdc ); |
---|
140 | |
---|
141 | Double dErrorLuma = 0 , dErrorChroma = 0; |
---|
142 | Int nYSize = 1 << ( getCurOctantDepth() + getCurYPartNumLog2() ); |
---|
143 | Int nUVSize = 1 << getCurOctantDepth(); |
---|
144 | Int nLengthY = 1 << ( getInputBitDepthY() - getCurOctantDepth() - getCurYPartNumLog2() ); |
---|
145 | Int nLengthUV = 1 << ( getInputBitDepthC() - getCurOctantDepth() ); |
---|
146 | for( Int yIdx = 0 ; yIdx < nYSize ; yIdx++ ) |
---|
147 | { |
---|
148 | for( Int uIdx = 0 ; uIdx < nUVSize ; uIdx++ ) |
---|
149 | { |
---|
150 | for( Int vIdx = 0 ; vIdx < nUVSize ; vIdx++ ) |
---|
151 | { |
---|
152 | SColorInfo & rCuboidColorInfo = m_pColorInfo[yIdx][uIdx][vIdx]; |
---|
153 | SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx]; |
---|
154 | SCuboid & rCuboid = xGetCuboid( yIdx , uIdx , vIdx ); |
---|
155 | Int y0 = yIdx << xGetYShift2Idx(); |
---|
156 | Int u0 = uIdx << xGetUShift2Idx(); |
---|
157 | Int v0 = vIdx << xGetVShift2Idx(); |
---|
158 | if( rCuboidColorInfo.N > 0 ) |
---|
159 | { |
---|
160 | 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 , |
---|
161 | y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y ); |
---|
162 | } |
---|
163 | if( rCuboidColorInfoC.N > 0 ) |
---|
164 | { |
---|
165 | 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 , |
---|
166 | y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U ); |
---|
167 | 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 , |
---|
168 | y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V ); |
---|
169 | } |
---|
170 | } |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | return( dErrorLuma + dErrorChroma); |
---|
175 | } |
---|
176 | |
---|
177 | Double TEnc3DAsymLUT::derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB ) |
---|
178 | { |
---|
179 | m_nLUTBitDepth = pCfg->getCGSLUTBit(); |
---|
180 | Int nCurYPartNumLog2 = 0 , nCurOctantDepth = 0; |
---|
181 | xxDerivePartNumLog2( pSlice , pCfg , nCurOctantDepth , nCurYPartNumLog2 , bSignalPPS , bElRapSliceTypeB ); |
---|
182 | xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2 ); |
---|
183 | xxCollectData( pCurPic , refLayerIdc ); |
---|
184 | Int nBestResQuanBit = 0; |
---|
185 | Double dError0 = xxDeriveVertexes( nBestResQuanBit , m_pBestEncCuboid ); |
---|
186 | Double dCurError = dError0; |
---|
187 | Double dFactor = 1 + 0.001 * ( pSlice->getDepth() + 1 ); |
---|
188 | for( Int nResQuanBit = 1 ; nResQuanBit < 4 ; nResQuanBit++ ) |
---|
189 | { |
---|
190 | Double dError = xxDeriveVertexes( nResQuanBit , m_pEncCuboid ); |
---|
191 | if( dError < dError0 * dFactor ) |
---|
192 | { |
---|
193 | nBestResQuanBit = nResQuanBit; |
---|
194 | SCuboid *** tmp = m_pBestEncCuboid; |
---|
195 | m_pBestEncCuboid = m_pEncCuboid; |
---|
196 | m_pEncCuboid = tmp; |
---|
197 | dCurError = dError; |
---|
198 | } |
---|
199 | else |
---|
200 | { |
---|
201 | break; |
---|
202 | } |
---|
203 | } |
---|
204 | setResQuantBit( nBestResQuanBit ); |
---|
205 | xSaveCuboids( m_pBestEncCuboid ); |
---|
206 | |
---|
207 | return( dCurError ); |
---|
208 | } |
---|
209 | |
---|
210 | Double TEnc3DAsymLUT::xxDeriveVertexes( Int nResQuanBit , SCuboid *** pCurCuboid ) |
---|
211 | { |
---|
212 | Double dErrorLuma = 0 , dErrorChroma = 0; |
---|
213 | Int nYSize = 1 << ( getCurOctantDepth() + getCurYPartNumLog2() ); |
---|
214 | Int nUVSize = 1 << getCurOctantDepth(); |
---|
215 | Int nLengthY = 1 << ( getInputBitDepthY() - getCurOctantDepth() - getCurYPartNumLog2() ); |
---|
216 | Int nLengthUV = 1 << ( getInputBitDepthC() - getCurOctantDepth() ); |
---|
217 | for( Int yIdx = 0 ; yIdx < nYSize ; yIdx++ ) |
---|
218 | { |
---|
219 | for( Int uIdx = 0 ; uIdx < nUVSize ; uIdx++ ) |
---|
220 | { |
---|
221 | for( Int vIdx = 0 ; vIdx < nUVSize ; vIdx++ ) |
---|
222 | { |
---|
223 | SColorInfo & rCuboidColorInfo = m_pColorInfo[yIdx][uIdx][vIdx]; |
---|
224 | SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx]; |
---|
225 | SCuboid & rCuboid = pCurCuboid[yIdx][uIdx][vIdx]; |
---|
226 | Int y0 = yIdx << xGetYShift2Idx(); |
---|
227 | Int u0 = uIdx << xGetUShift2Idx(); |
---|
228 | Int v0 = vIdx << xGetVShift2Idx(); |
---|
229 | for( Int idxVertex = 0 ; idxVertex < 4 ; idxVertex++ ) |
---|
230 | { |
---|
231 | rCuboid.P[idxVertex] = xGetCuboidVertexPredAll( yIdx , uIdx , vIdx , idxVertex , pCurCuboid ); |
---|
232 | } |
---|
233 | |
---|
234 | if( rCuboidColorInfo.N > 0 ) |
---|
235 | { |
---|
236 | 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 , |
---|
237 | y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y , nResQuanBit ); |
---|
238 | } |
---|
239 | if( rCuboidColorInfoC.N > 0 ) |
---|
240 | { |
---|
241 | 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 , |
---|
242 | y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U , nResQuanBit ); |
---|
243 | 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 , |
---|
244 | y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V , nResQuanBit ); |
---|
245 | } |
---|
246 | |
---|
247 | if( nResQuanBit > 0 ) |
---|
248 | { |
---|
249 | // check quantization |
---|
250 | for( Int idxVertex = 0 ; idxVertex < 4 ; idxVertex++ ) |
---|
251 | { |
---|
252 | SYUVP sPred = xGetCuboidVertexPredAll( yIdx , uIdx , vIdx , idxVertex , pCurCuboid ); |
---|
253 | assert( ( ( rCuboid.P[idxVertex].Y - sPred.Y ) >> nResQuanBit << nResQuanBit ) == rCuboid.P[idxVertex].Y - sPred.Y ); |
---|
254 | assert( ( ( rCuboid.P[idxVertex].U - sPred.U ) >> nResQuanBit << nResQuanBit ) == rCuboid.P[idxVertex].U - sPred.U ); |
---|
255 | assert( ( ( rCuboid.P[idxVertex].V - sPred.V ) >> nResQuanBit << nResQuanBit ) == rCuboid.P[idxVertex].V - sPred.V ); |
---|
256 | } |
---|
257 | } |
---|
258 | } |
---|
259 | } |
---|
260 | } |
---|
261 | |
---|
262 | return( dErrorLuma + dErrorChroma ); |
---|
263 | } |
---|
264 | |
---|
265 | Void TEnc3DAsymLUT::xxCollectData( TComPic * pCurPic , UInt refLayerIdc ) |
---|
266 | { |
---|
267 | Pel * pSrcY = m_pDsOrigPic->getLumaAddr(); |
---|
268 | Pel * pSrcU = m_pDsOrigPic->getCbAddr(); |
---|
269 | Pel * pSrcV = m_pDsOrigPic->getCrAddr(); |
---|
270 | Int nStrideSrcY = m_pDsOrigPic->getStride(); |
---|
271 | Int nStrideSrcC = m_pDsOrigPic->getCStride(); |
---|
272 | TComPicYuv *pRecPic = pCurPic->getSlice(pCurPic->getCurrSliceIdx())->getBaseColPic(refLayerIdc)->getPicYuvRec(); |
---|
273 | Pel * pIRLY = pRecPic->getLumaAddr(); |
---|
274 | Pel * pIRLU = pRecPic->getCbAddr(); |
---|
275 | Pel * pIRLV = pRecPic->getCrAddr(); |
---|
276 | Int nStrideILRY = pRecPic->getStride(); |
---|
277 | Int nStrideILRC = pRecPic->getCStride(); |
---|
278 | xReset3DArray( m_pColorInfo , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
279 | xReset3DArray( m_pColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() ); |
---|
280 | |
---|
281 | //alignment padding |
---|
282 | pRecPic->setBorderExtension( false ); |
---|
283 | pRecPic->extendPicBorder(); |
---|
284 | |
---|
285 | TComSlice * pSlice = pCurPic->getSlice(pCurPic->getCurrSliceIdx()); |
---|
286 | UInt refLayerId = pSlice->getVPS()->getRefLayerId(pSlice->getLayerId(), refLayerIdc); |
---|
287 | const Window &scalEL = pSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId); |
---|
288 | TComPicYuv *pcRecPicBL = pSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(); |
---|
289 | // borders of down-sampled picture |
---|
290 | Int leftDS = (scalEL.getWindowLeftOffset()*g_posScalingFactor[refLayerIdc][0]+(1<<15))>>16; |
---|
291 | Int rightDS = pcRecPicBL->getWidth() - 1 + (((scalEL.getWindowRightOffset())*g_posScalingFactor[refLayerIdc][0]+(1<<15))>>16); |
---|
292 | Int topDS = (((scalEL.getWindowTopOffset())*g_posScalingFactor[refLayerIdc][1]+(1<<15))>>16); |
---|
293 | Int bottomDS = pcRecPicBL->getHeight() - 1 + (((scalEL.getWindowBottomOffset())*g_posScalingFactor[refLayerIdc][1]+(1<<15))>>16); |
---|
294 | // overlapped region |
---|
295 | Int left = max( 0 , leftDS ); |
---|
296 | Int right = min( pcRecPicBL->getWidth() - 1 , rightDS ); |
---|
297 | Int top = max( 0 , topDS ); |
---|
298 | Int bottom = min( pcRecPicBL->getHeight() - 1 , bottomDS ); |
---|
299 | // since we do data collection only for overlapped region, the border extension is good enough |
---|
300 | |
---|
301 | for( Int i = top ; i <= bottom ; i++ ) |
---|
302 | { |
---|
303 | Int iDS = i-topDS; |
---|
304 | Int jDS = left-leftDS; |
---|
305 | Int posSrcY = iDS * nStrideSrcY + jDS; |
---|
306 | Int posIRLY = i * nStrideILRY + left; |
---|
307 | Int posSrcUV = ( iDS >> 1 ) * nStrideSrcC + (jDS>>1); |
---|
308 | Int posIRLUV = ( i >> 1 ) * nStrideILRC + (left>>1); |
---|
309 | for( Int j = left ; j <= right ; j++ , posSrcY++ , posIRLY++ , posSrcUV += !( j & 0x01 ) , posIRLUV += !( j & 0x01 ) ) |
---|
310 | { |
---|
311 | Int Y = pSrcY[posSrcY]; |
---|
312 | Int y = pIRLY[posIRLY]; |
---|
313 | Int U = pSrcU[posSrcUV]; |
---|
314 | Int u = pIRLU[posIRLUV]; |
---|
315 | Int V = pSrcV[posSrcUV]; |
---|
316 | Int v = pIRLV[posIRLUV]; |
---|
317 | |
---|
318 | // alignment |
---|
319 | //filtering u, v for luma; |
---|
320 | Int posIRLUVN = posIRLUV + ((i&1)? nStrideILRC : -nStrideILRC); |
---|
321 | if((j&1)) |
---|
322 | { |
---|
323 | u = (pIRLU[posIRLUVN] + pIRLU[posIRLUVN+1] +(u + pIRLU[posIRLUV+1])*3 +4)>>3; |
---|
324 | v = (pIRLV[posIRLUVN] + pIRLV[posIRLUVN+1] +(v + pIRLV[posIRLUV+1])*3 +4)>>3; |
---|
325 | } |
---|
326 | else |
---|
327 | { |
---|
328 | u = (pIRLU[posIRLUVN] +u*3 +2)>>2; |
---|
329 | v = (pIRLV[posIRLUVN] +v*3 +2)>>2; |
---|
330 | } |
---|
331 | |
---|
332 | SColorInfo sColorInfo; |
---|
333 | SColorInfo & rCuboidColorInfo = m_pColorInfo[y>>xGetYShift2Idx()][u>>xGetUShift2Idx()][v>>xGetVShift2Idx()]; |
---|
334 | memset(&sColorInfo, 0, sizeof(SColorInfo)); |
---|
335 | sColorInfo.Ys = Y; |
---|
336 | sColorInfo.ys = y; |
---|
337 | sColorInfo.us = u; |
---|
338 | sColorInfo.vs = v; |
---|
339 | sColorInfo.Yy = Y * y; |
---|
340 | sColorInfo.Yu = Y * u; |
---|
341 | sColorInfo.Yv = Y * v; |
---|
342 | sColorInfo.yy = y * y; |
---|
343 | sColorInfo.yu = y * u; |
---|
344 | sColorInfo.yv = y * v; |
---|
345 | sColorInfo.uu = u * u; |
---|
346 | sColorInfo.uv = u * v; |
---|
347 | sColorInfo.vv = v * v; |
---|
348 | sColorInfo.YY = Y * Y; |
---|
349 | sColorInfo.N = 1; |
---|
350 | |
---|
351 | rCuboidColorInfo += sColorInfo; |
---|
352 | |
---|
353 | if(!((i&1) || (j&1))) |
---|
354 | { |
---|
355 | // alignment |
---|
356 | y = (pIRLY[posIRLY] + pIRLY[posIRLY+nStrideILRY] + 1)>>1; |
---|
357 | |
---|
358 | u = pIRLU[posIRLUV]; |
---|
359 | v = pIRLV[posIRLUV]; |
---|
360 | SColorInfo & rCuboidColorInfoC = m_pColorInfoC[y>>xGetYShift2Idx()][u>>xGetUShift2Idx()][v>>xGetVShift2Idx()]; |
---|
361 | sColorInfo.Us = U; |
---|
362 | sColorInfo.Vs = V; |
---|
363 | sColorInfo.ys = y; |
---|
364 | sColorInfo.us = u; |
---|
365 | sColorInfo.vs = v; |
---|
366 | |
---|
367 | sColorInfo.Uy = U * y; |
---|
368 | sColorInfo.Uu = U * u; |
---|
369 | sColorInfo.Uv = U * v; |
---|
370 | sColorInfo.Vy = V * y; |
---|
371 | sColorInfo.Vu = V * u; |
---|
372 | sColorInfo.Vv = V * v; |
---|
373 | sColorInfo.yy = y * y; |
---|
374 | sColorInfo.yu = y * u; |
---|
375 | sColorInfo.yv = y * v; |
---|
376 | sColorInfo.uu = u * u; |
---|
377 | sColorInfo.uv = u * v; |
---|
378 | sColorInfo.vv = v * v; |
---|
379 | sColorInfo.UU = U * U; |
---|
380 | sColorInfo.VV = V * V; |
---|
381 | sColorInfo.N = 1; |
---|
382 | |
---|
383 | rCuboidColorInfoC += sColorInfo; |
---|
384 | } |
---|
385 | } |
---|
386 | } |
---|
387 | } |
---|
388 | |
---|
389 | Void TEnc3DAsymLUT::xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB ) |
---|
390 | { |
---|
391 | Int nSliceType = pSlice->getSliceType(); |
---|
392 | // update slice type as what will be done later |
---|
393 | if( pSlice->getActiveNumILRRefIdx() == 0 && pSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) |
---|
394 | { |
---|
395 | nSliceType = I_SLICE; |
---|
396 | } |
---|
397 | else if( !bElRapSliceTypeB ) |
---|
398 | { |
---|
399 | if( (pSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) && |
---|
400 | (pSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) && |
---|
401 | pSlice->getSliceType() == B_SLICE ) |
---|
402 | { |
---|
403 | nSliceType = P_SLICE; |
---|
404 | } |
---|
405 | } |
---|
406 | |
---|
407 | const Int nSliceTempLevel = pSlice->getDepth(); |
---|
408 | Int nPartNumLog2 = 4; |
---|
409 | if( pSlice->getBaseColPic( pSlice->getInterLayerPredLayerIdc( 0 ) )->getSlice( 0 )->isIntra() ) |
---|
410 | { |
---|
411 | nPartNumLog2 = xGetMaxPartNumLog2(); |
---|
412 | } |
---|
413 | if( m_nPrevFrameBit[nSliceType][nSliceTempLevel] && pSlice->getPPS()->getCGSFlag() ) |
---|
414 | { |
---|
415 | Double dBitCost = 1.0 * m_nPrevFrameCGSBit[nSliceType][nSliceTempLevel] / m_nPrevFrameBit[nSliceType][nSliceTempLevel]; |
---|
416 | nPartNumLog2 = m_nPrevFrameCGSPartNumLog2[nSliceType][nSliceTempLevel]; |
---|
417 | Double dBitCostT = 0.03; |
---|
418 | if( dBitCost < dBitCostT / 6.0 ) |
---|
419 | { |
---|
420 | nPartNumLog2++; |
---|
421 | } |
---|
422 | else if( dBitCost >= dBitCostT ) |
---|
423 | { |
---|
424 | nPartNumLog2--; |
---|
425 | } |
---|
426 | } |
---|
427 | else |
---|
428 | { |
---|
429 | nPartNumLog2 -= nSliceTempLevel; |
---|
430 | } |
---|
431 | nPartNumLog2 = Clip3( 0 , xGetMaxPartNumLog2() , nPartNumLog2 ); |
---|
432 | xxMapPartNum2DepthYPart( nPartNumLog2 , rOctantDepth , rYPartNumLog2 ); |
---|
433 | } |
---|
434 | |
---|
435 | Void TEnc3DAsymLUT::xxMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 ) |
---|
436 | { |
---|
437 | for( Int y = getMaxYPartNumLog2() ; y >= 0 ; y-- ) |
---|
438 | { |
---|
439 | for( Int depth = ( nPartNumLog2 - y ) >> 1 ; depth >= 0 ; depth-- ) |
---|
440 | { |
---|
441 | if( y + 3 * depth == nPartNumLog2 ) |
---|
442 | { |
---|
443 | rOctantDepth = depth; |
---|
444 | rYPartNumLog2 = y; |
---|
445 | return; |
---|
446 | } |
---|
447 | } |
---|
448 | } |
---|
449 | rOctantDepth = min( getMaxOctantDepth() , nPartNumLog2 / 3 ); |
---|
450 | rYPartNumLog2 = min( getMaxYPartNumLog2() , nPartNumLog2 - 3 * rOctantDepth ); |
---|
451 | } |
---|
452 | |
---|
453 | Void TEnc3DAsymLUT::updatePicCGSBits( TComSlice * pcSlice , Int nPPSBit ) |
---|
454 | { |
---|
455 | const Int nSliceType = pcSlice->getSliceType(); |
---|
456 | const Int nSliceTempLevel = pcSlice->getDepth(); |
---|
457 | |
---|
458 | for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
---|
459 | { |
---|
460 | UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i); |
---|
461 | m_nPrevFrameBit[nSliceType][nSliceTempLevel] = pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit(); |
---|
462 | m_dTotalFrameBit += pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit(); |
---|
463 | } |
---|
464 | m_nPrevFrameOverWritePPS[nSliceType][nSliceTempLevel] = pcSlice->getCGSOverWritePPS(); |
---|
465 | m_nPrevFrameCGSBit[nSliceType][nSliceTempLevel] = nPPSBit; |
---|
466 | m_nTotalCGSBit += nPPSBit; |
---|
467 | m_nPrevFrameCGSPartNumLog2[nSliceType][nSliceTempLevel] = getCurOctantDepth() * 3 + getCurYPartNumLog2(); |
---|
468 | } |
---|
469 | |
---|
470 | #endif |
---|