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