1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2011, ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | |
---|
35 | /** \file TEncCU.cpp |
---|
36 | \brief CU encoder class |
---|
37 | */ |
---|
38 | |
---|
39 | #include <stdio.h> |
---|
40 | #include "TEncTop.h" |
---|
41 | #include "TEncCu.h" |
---|
42 | #include "TEncAnalyze.h" |
---|
43 | |
---|
44 | // ==================================================================================================================== |
---|
45 | // Constructor / destructor / create / destroy |
---|
46 | // ==================================================================================================================== |
---|
47 | |
---|
48 | /** |
---|
49 | \param uiTotalDepth total number of allowable depth |
---|
50 | \param uiMaxWidth largest CU width |
---|
51 | \param uiMaxHeight largest CU height |
---|
52 | */ |
---|
53 | Void TEncCu::create(UChar uhTotalDepth, UInt uiMaxWidth, UInt uiMaxHeight) |
---|
54 | { |
---|
55 | Int i; |
---|
56 | |
---|
57 | m_uhTotalDepth = uhTotalDepth + 1; |
---|
58 | m_ppcBestCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
59 | m_ppcTempCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
60 | |
---|
61 | m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
62 | m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
63 | m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
64 | m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
65 | m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
66 | m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
67 | m_ppcOrigYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
68 | m_ppcResPredTmp = new TComYuv*[m_uhTotalDepth-1]; |
---|
69 | #if POZNAN_AVAIL_MAP |
---|
70 | m_ppcAvailYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
71 | #endif |
---|
72 | #if POZNAN_SYNTH_VIEW |
---|
73 | m_ppcSynthYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
74 | #endif |
---|
75 | |
---|
76 | |
---|
77 | #if HHI_MPI |
---|
78 | m_puhDepthSaved = new UChar[1ll<<( ( m_uhTotalDepth - 1 )<<1 )]; |
---|
79 | m_puhWidthSaved = new UChar[1ll<<( ( m_uhTotalDepth - 1 )<<1 )]; |
---|
80 | m_puhHeightSaved = new UChar[1ll<<( ( m_uhTotalDepth - 1 )<<1 )]; |
---|
81 | #endif |
---|
82 | UInt uiNumPartitions; |
---|
83 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
84 | { |
---|
85 | uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 ); |
---|
86 | UInt uiWidth = uiMaxWidth >> i; |
---|
87 | UInt uiHeight = uiMaxHeight >> i; |
---|
88 | |
---|
89 | m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false ); |
---|
90 | m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false ); |
---|
91 | |
---|
92 | m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight); |
---|
93 | m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight); |
---|
94 | m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight); |
---|
95 | |
---|
96 | m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight); |
---|
97 | m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight); |
---|
98 | m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight); |
---|
99 | |
---|
100 | m_ppcOrigYuv [i] = new TComYuv; m_ppcOrigYuv [i]->create(uiWidth, uiHeight); |
---|
101 | |
---|
102 | #if POZNAN_AVAIL_MAP |
---|
103 | m_ppcAvailYuv [i] = new TComYuv; m_ppcAvailYuv [i]->create(uiWidth, uiHeight); |
---|
104 | #endif |
---|
105 | #if POZNAN_SYNTH_VIEW |
---|
106 | m_ppcSynthYuv [i] = new TComYuv; m_ppcSynthYuv [i]->create(uiWidth, uiHeight); |
---|
107 | #endif |
---|
108 | |
---|
109 | |
---|
110 | m_ppcResPredTmp [i] = new TComYuv; m_ppcResPredTmp [i]->create(uiWidth, uiHeight); |
---|
111 | } |
---|
112 | |
---|
113 | // initialize partition order. |
---|
114 | UInt* piTmp = &g_auiZscanToRaster[0]; |
---|
115 | initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp); |
---|
116 | initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
117 | |
---|
118 | // initialize conversion matrix from partition index to pel |
---|
119 | initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
120 | } |
---|
121 | |
---|
122 | Void TEncCu::destroy() |
---|
123 | { |
---|
124 | Int i; |
---|
125 | |
---|
126 | #if HHI_MPI |
---|
127 | delete[] m_puhDepthSaved; m_puhDepthSaved = NULL; |
---|
128 | delete[] m_puhWidthSaved; m_puhWidthSaved = NULL; |
---|
129 | delete[] m_puhHeightSaved; m_puhHeightSaved = NULL; |
---|
130 | #endif |
---|
131 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
132 | { |
---|
133 | if(m_ppcBestCU[i]) |
---|
134 | { |
---|
135 | m_ppcBestCU[i]->destroy(); delete m_ppcBestCU[i]; m_ppcBestCU[i] = NULL; |
---|
136 | } |
---|
137 | if(m_ppcTempCU[i]) |
---|
138 | { |
---|
139 | m_ppcTempCU[i]->destroy(); delete m_ppcTempCU[i]; m_ppcTempCU[i] = NULL; |
---|
140 | } |
---|
141 | if(m_ppcPredYuvBest[i]) |
---|
142 | { |
---|
143 | m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL; |
---|
144 | } |
---|
145 | if(m_ppcResiYuvBest[i]) |
---|
146 | { |
---|
147 | m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL; |
---|
148 | } |
---|
149 | if(m_ppcRecoYuvBest[i]) |
---|
150 | { |
---|
151 | m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL; |
---|
152 | } |
---|
153 | if(m_ppcPredYuvTemp[i]) |
---|
154 | { |
---|
155 | m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL; |
---|
156 | } |
---|
157 | if(m_ppcResiYuvTemp[i]) |
---|
158 | { |
---|
159 | m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL; |
---|
160 | } |
---|
161 | if(m_ppcRecoYuvTemp[i]) |
---|
162 | { |
---|
163 | m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL; |
---|
164 | } |
---|
165 | if(m_ppcOrigYuv[i]) |
---|
166 | { |
---|
167 | m_ppcOrigYuv[i]->destroy(); delete m_ppcOrigYuv[i]; m_ppcOrigYuv[i] = NULL; |
---|
168 | } |
---|
169 | #if POZNAN_AVAIL_MAP |
---|
170 | if(m_ppcAvailYuv[i]) |
---|
171 | { |
---|
172 | m_ppcAvailYuv[i]->destroy(); delete m_ppcAvailYuv[i]; m_ppcAvailYuv[i] = NULL; |
---|
173 | } |
---|
174 | #endif |
---|
175 | #if POZNAN_SYNTH_VIEW |
---|
176 | if(m_ppcSynthYuv[i]) |
---|
177 | { |
---|
178 | m_ppcSynthYuv[i]->destroy(); delete m_ppcSynthYuv[i]; m_ppcSynthYuv[i] = NULL; |
---|
179 | } |
---|
180 | #endif |
---|
181 | if(m_ppcResPredTmp[i]) |
---|
182 | { |
---|
183 | m_ppcResPredTmp [i]->destroy(); delete m_ppcResPredTmp[i]; m_ppcResPredTmp[i] = NULL; |
---|
184 | } |
---|
185 | } |
---|
186 | if(m_ppcBestCU) |
---|
187 | { |
---|
188 | delete [] m_ppcBestCU; |
---|
189 | m_ppcBestCU = NULL; |
---|
190 | } |
---|
191 | if(m_ppcTempCU) |
---|
192 | { |
---|
193 | delete [] m_ppcTempCU; |
---|
194 | m_ppcTempCU = NULL; |
---|
195 | } |
---|
196 | |
---|
197 | if(m_ppcPredYuvBest) |
---|
198 | { |
---|
199 | delete [] m_ppcPredYuvBest; |
---|
200 | m_ppcPredYuvBest = NULL; |
---|
201 | } |
---|
202 | if(m_ppcResiYuvBest) |
---|
203 | { |
---|
204 | delete [] m_ppcResiYuvBest; |
---|
205 | m_ppcResiYuvBest = NULL; |
---|
206 | } |
---|
207 | if(m_ppcRecoYuvBest) |
---|
208 | { |
---|
209 | delete [] m_ppcRecoYuvBest; |
---|
210 | m_ppcRecoYuvBest = NULL; |
---|
211 | } |
---|
212 | if(m_ppcPredYuvTemp) |
---|
213 | { |
---|
214 | delete [] m_ppcPredYuvTemp; |
---|
215 | m_ppcPredYuvTemp = NULL; |
---|
216 | } |
---|
217 | if(m_ppcResiYuvTemp) |
---|
218 | { |
---|
219 | delete [] m_ppcResiYuvTemp; |
---|
220 | m_ppcResiYuvTemp = NULL; |
---|
221 | } |
---|
222 | if(m_ppcRecoYuvTemp) |
---|
223 | { |
---|
224 | delete [] m_ppcRecoYuvTemp; |
---|
225 | m_ppcRecoYuvTemp = NULL; |
---|
226 | } |
---|
227 | if(m_ppcOrigYuv) |
---|
228 | { |
---|
229 | delete [] m_ppcOrigYuv; |
---|
230 | m_ppcOrigYuv = NULL; |
---|
231 | } |
---|
232 | #if POZNAN_AVAIL_MAP |
---|
233 | if(m_ppcAvailYuv) |
---|
234 | { |
---|
235 | delete [] m_ppcAvailYuv; |
---|
236 | m_ppcAvailYuv = NULL; |
---|
237 | } |
---|
238 | #endif |
---|
239 | #if POZNAN_SYNTH_VIEW |
---|
240 | if(m_ppcSynthYuv) |
---|
241 | { |
---|
242 | delete [] m_ppcSynthYuv; |
---|
243 | m_ppcSynthYuv = NULL; |
---|
244 | } |
---|
245 | #endif |
---|
246 | if(m_ppcResPredTmp) |
---|
247 | { |
---|
248 | delete [] m_ppcResPredTmp; |
---|
249 | m_ppcResPredTmp = NULL; |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | /** \param pcEncTop pointer of encoder class |
---|
254 | */ |
---|
255 | Void TEncCu::init( TEncTop* pcEncTop ) |
---|
256 | { |
---|
257 | m_pcEncCfg = pcEncTop; |
---|
258 | m_pcEncTop = pcEncTop; |
---|
259 | m_pcPredSearch = pcEncTop->getPredSearch(); |
---|
260 | m_pcTrQuant = pcEncTop->getTrQuant(); |
---|
261 | m_pcBitCounter = pcEncTop->getBitCounter(); |
---|
262 | m_pcRdCost = pcEncTop->getRdCost(); |
---|
263 | |
---|
264 | m_pcEntropyCoder = pcEncTop->getEntropyCoder(); |
---|
265 | m_pcCavlcCoder = pcEncTop->getCavlcCoder(); |
---|
266 | m_pcSbacCoder = pcEncTop->getSbacCoder(); |
---|
267 | m_pcBinCABAC = pcEncTop->getBinCABAC(); |
---|
268 | |
---|
269 | m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder(); |
---|
270 | m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder(); |
---|
271 | |
---|
272 | m_bUseSBACRD = pcEncTop->getUseSBACRD(); |
---|
273 | } |
---|
274 | |
---|
275 | // ==================================================================================================================== |
---|
276 | // Public member functions |
---|
277 | // ==================================================================================================================== |
---|
278 | |
---|
279 | /** \param rpcCU pointer of CU data class |
---|
280 | */ |
---|
281 | Void TEncCu::compressCU( TComDataCU*& rpcCU ) |
---|
282 | { |
---|
283 | // single-QP coding mode |
---|
284 | if ( rpcCU->getSlice()->getSPS()->getUseDQP() == false ) |
---|
285 | { |
---|
286 | // initialize CU data |
---|
287 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
288 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
289 | |
---|
290 | // analysis of CU |
---|
291 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
---|
292 | } |
---|
293 | // multiple-QP coding mode |
---|
294 | else |
---|
295 | { |
---|
296 | Int iQP = rpcCU->getSlice()->getSliceQp(); |
---|
297 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
298 | Int i; |
---|
299 | Int iBestQP = iQP; |
---|
300 | Double fBestCost = MAX_DOUBLE; |
---|
301 | |
---|
302 | rpcCU->getSlice()->setSliceQp( iQP ); |
---|
303 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
304 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
305 | m_ppcBestCU[0]->setQPSubParts( iQP, 0, 0 ); |
---|
306 | m_ppcTempCU[0]->setQPSubParts( iQP, 0, 0 ); |
---|
307 | |
---|
308 | // first try |
---|
309 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
---|
310 | |
---|
311 | // for non-zero residual case |
---|
312 | if ( !( m_ppcBestCU[0]->isSkipped( 0 ) && m_ppcBestCU[0]->getDepth( 0 ) == 0 ) ) |
---|
313 | { |
---|
314 | // add dQP bits |
---|
315 | m_pcEntropyCoder->resetBits(); |
---|
316 | m_pcEntropyCoder->encodeQP( m_ppcBestCU[0], 0, false ); |
---|
317 | m_ppcBestCU[0]->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
318 | |
---|
319 | |
---|
320 | #if HHI_VSO |
---|
321 | if ( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
322 | { |
---|
323 | m_ppcBestCU[0]->getTotalCost() = m_pcRdCost->calcRdCostVSO( m_ppcBestCU[0]->getTotalBits(), m_ppcBestCU[0]->getTotalDistortion() ); |
---|
324 | } |
---|
325 | else |
---|
326 | #endif |
---|
327 | { |
---|
328 | m_ppcBestCU[0]->getTotalCost() = m_pcRdCost->calcRdCost( m_ppcBestCU[0]->getTotalBits(), m_ppcBestCU[0]->getTotalDistortion() ); |
---|
329 | } |
---|
330 | |
---|
331 | fBestCost = m_ppcBestCU[0]->getTotalCost(); |
---|
332 | |
---|
333 | // try every case |
---|
334 | for ( i=iQP-idQP; i<=iQP+idQP; i++ ) |
---|
335 | { |
---|
336 | if ( i == iQP ) continue; |
---|
337 | |
---|
338 | rpcCU->getSlice()->setSliceQp( i ); |
---|
339 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
340 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
341 | m_ppcBestCU[0]->setQPSubParts( i, 0, 0 ); |
---|
342 | m_ppcTempCU[0]->setQPSubParts( i, 0, 0 ); |
---|
343 | |
---|
344 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
---|
345 | |
---|
346 | // add dQP bits |
---|
347 | rpcCU->getSlice()->setSliceQp( iQP ); |
---|
348 | m_pcEntropyCoder->resetBits(); |
---|
349 | m_pcEntropyCoder->encodeQP( m_ppcBestCU[0], 0, false ); |
---|
350 | m_ppcBestCU[0]->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
351 | |
---|
352 | #if HHI_VSO |
---|
353 | if (m_pcRdCost->getUseLambdaScaleVSO()) |
---|
354 | { |
---|
355 | m_ppcBestCU[0]->getTotalCost() = m_pcRdCost->calcRdCostVSO( m_ppcBestCU[0]->getTotalBits(), m_ppcBestCU[0]->getTotalDistortion() ); |
---|
356 | } |
---|
357 | else |
---|
358 | #endif |
---|
359 | { |
---|
360 | m_ppcBestCU[0]->getTotalCost() = m_pcRdCost->calcRdCost( m_ppcBestCU[0]->getTotalBits(), m_ppcBestCU[0]->getTotalDistortion() ); |
---|
361 | } |
---|
362 | |
---|
363 | if ( fBestCost > m_ppcBestCU[0]->getTotalCost() ) |
---|
364 | { |
---|
365 | fBestCost = m_ppcBestCU[0]->getTotalCost(); |
---|
366 | iBestQP = i; |
---|
367 | } |
---|
368 | } |
---|
369 | |
---|
370 | // perform best case |
---|
371 | rpcCU->getSlice()->setSliceQp( iBestQP ); |
---|
372 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
373 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
374 | m_ppcBestCU[0]->setQPSubParts( iBestQP, 0, 0 ); |
---|
375 | m_ppcTempCU[0]->setQPSubParts( iBestQP, 0, 0 ); |
---|
376 | |
---|
377 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
---|
378 | |
---|
379 | // add dQP bits |
---|
380 | rpcCU->getSlice()->setSliceQp( iQP ); |
---|
381 | m_pcEntropyCoder->resetBits(); |
---|
382 | m_pcEntropyCoder->encodeQP( m_ppcBestCU[0], 0, false ); |
---|
383 | m_ppcBestCU[0]->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
384 | |
---|
385 | #if HHI_VSO |
---|
386 | if (m_pcRdCost->getUseLambdaScaleVSO()) |
---|
387 | { |
---|
388 | m_ppcBestCU[0]->getTotalCost() = m_pcRdCost->calcRdCostVSO( m_ppcBestCU[0]->getTotalBits(), m_ppcBestCU[0]->getTotalDistortion() ); |
---|
389 | } |
---|
390 | else |
---|
391 | #endif |
---|
392 | { |
---|
393 | m_ppcBestCU[0]->getTotalCost() = m_pcRdCost->calcRdCost( m_ppcBestCU[0]->getTotalBits(), m_ppcBestCU[0]->getTotalDistortion() ); |
---|
394 | } |
---|
395 | } |
---|
396 | } |
---|
397 | } |
---|
398 | |
---|
399 | /** \param pcCU pointer of CU data class, bForceTerminate when set to true terminates slice (default is false). |
---|
400 | */ |
---|
401 | Void TEncCu::encodeCU ( TComDataCU* pcCU, Bool bForceTerminate ) |
---|
402 | { |
---|
403 | #if SNY_DQP |
---|
404 | if ( pcCU->getSlice()->getSPS()->getUseDQP() ) |
---|
405 | { |
---|
406 | pcCU->setdQPFlag(true); |
---|
407 | } |
---|
408 | #endif//SNY_DQP |
---|
409 | // encode CU data |
---|
410 | xEncodeCU( pcCU, 0, 0 ); |
---|
411 | |
---|
412 | #if SNY_DQP |
---|
413 | // dQP: only for LCU |
---|
414 | if ( pcCU->getSlice()->getSPS()->getUseDQP() ) |
---|
415 | { |
---|
416 | if ( pcCU->isSkipped( 0 ) && pcCU->getDepth( 0 ) == 0 ) |
---|
417 | { |
---|
418 | } |
---|
419 | else if ( pcCU->getdQPFlag())// non-skip |
---|
420 | { |
---|
421 | |
---|
422 | m_pcEntropyCoder->encodeQP( pcCU, 0 ); |
---|
423 | pcCU->setdQPFlag(false); |
---|
424 | } |
---|
425 | } |
---|
426 | #else |
---|
427 | // dQP: only for LCU |
---|
428 | if ( pcCU->getSlice()->getSPS()->getUseDQP() ) |
---|
429 | { |
---|
430 | if ( pcCU->isSkipped( 0 ) && pcCU->getDepth( 0 ) == 0 ) |
---|
431 | { |
---|
432 | } |
---|
433 | else |
---|
434 | { |
---|
435 | m_pcEntropyCoder->encodeQP( pcCU, 0 ); |
---|
436 | } |
---|
437 | } |
---|
438 | #endif//SNY_DQP |
---|
439 | |
---|
440 | //--- write terminating bit --- |
---|
441 | Bool bTerminateSlice = bForceTerminate; |
---|
442 | UInt uiCUAddr = pcCU->getAddr(); |
---|
443 | |
---|
444 | if (uiCUAddr == (pcCU->getPic()->getNumCUsInFrame()-1) ) |
---|
445 | bTerminateSlice = true; |
---|
446 | |
---|
447 | if (uiCUAddr == (pcCU->getSlice()->getSliceCurEndCUAddr()-1)) |
---|
448 | bTerminateSlice = true; |
---|
449 | |
---|
450 | m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 ); |
---|
451 | |
---|
452 | // Encode slice finish |
---|
453 | if ( bTerminateSlice ) |
---|
454 | { |
---|
455 | m_pcEntropyCoder->encodeSliceFinish(); |
---|
456 | } |
---|
457 | } |
---|
458 | |
---|
459 | // ==================================================================================================================== |
---|
460 | // Protected member functions |
---|
461 | // ==================================================================================================================== |
---|
462 | |
---|
463 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
464 | { |
---|
465 | TComPic* pcPic = rpcBestCU->getPic(); |
---|
466 | |
---|
467 | // get Original YUV data from picture |
---|
468 | m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
469 | #if POZNAN_AVAIL_MAP |
---|
470 | if (pcPic->getPicYuvAvail()) m_ppcAvailYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvAvail(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
471 | #endif |
---|
472 | #if POZNAN_SYNTH_VIEW |
---|
473 | if (pcPic->getPicYuvSynth()) m_ppcSynthYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvSynth(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
474 | #endif |
---|
475 | |
---|
476 | #if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU |
---|
477 | Bool bWholeCUCanBeSynthesized = false; |
---|
478 | Bool bOneSubCUCanNotBeSynthesied = false; |
---|
479 | Bool bSubCUCanBeSynthesized[4]; |
---|
480 | Bool * pbSubCUCanBeSynthesized = bSubCUCanBeSynthesized; |
---|
481 | pcPic->checkSynthesisAvailability(rpcBestCU, rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, pbSubCUCanBeSynthesized); //KUBA SYNTH |
---|
482 | Int iSubCUCanNotBeSynthesized = 0; |
---|
483 | Int iSubCUCanBeSynthesizedCnt = 0; |
---|
484 | for(Int i = 0; i < 4; i++) |
---|
485 | { |
---|
486 | if (!bSubCUCanBeSynthesized[i]) |
---|
487 | { |
---|
488 | iSubCUCanNotBeSynthesized = i; |
---|
489 | } |
---|
490 | else |
---|
491 | { |
---|
492 | iSubCUCanBeSynthesizedCnt ++; |
---|
493 | } |
---|
494 | } |
---|
495 | if(iSubCUCanBeSynthesizedCnt == 4) |
---|
496 | { |
---|
497 | bWholeCUCanBeSynthesized = true; |
---|
498 | } |
---|
499 | else if(iSubCUCanBeSynthesizedCnt == 3) |
---|
500 | { |
---|
501 | bOneSubCUCanNotBeSynthesied = true; |
---|
502 | } |
---|
503 | #endif |
---|
504 | // variables for fast encoder decision |
---|
505 | TComDataCU* pcTempCU; |
---|
506 | Bool bEarlySkip = false; |
---|
507 | Bool bTrySplit = true; |
---|
508 | Double fRD_Skip = MAX_DOUBLE; |
---|
509 | |
---|
510 | static Double afCost[ MAX_CU_DEPTH ]; |
---|
511 | static Int aiNum [ MAX_CU_DEPTH ]; |
---|
512 | |
---|
513 | if ( rpcBestCU->getAddr() == 0 ) |
---|
514 | { |
---|
515 | ::memset( afCost, 0, sizeof( afCost ) ); |
---|
516 | ::memset( aiNum, 0, sizeof( aiNum ) ); |
---|
517 | } |
---|
518 | |
---|
519 | Bool bBoundary = false; |
---|
520 | UInt uiLPelX = rpcBestCU->getCUPelX(); |
---|
521 | UInt uiRPelX = uiLPelX + rpcBestCU->getWidth(0) - 1; |
---|
522 | UInt uiTPelY = rpcBestCU->getCUPelY(); |
---|
523 | UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1; |
---|
524 | |
---|
525 | #if ( HHI_INTERVIEW_SKIP) |
---|
526 | Bool bFullyRenderedSec = true ; |
---|
527 | if( m_pcEncCfg->getInterViewSkip() ) |
---|
528 | { |
---|
529 | Pel* pUsedSamples ; |
---|
530 | UInt uiStride ; |
---|
531 | pUsedSamples = pcPic->getUsedPelsMap()->getLumaAddr( rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
532 | uiStride = pcPic->getUsedPelsMap()->getStride(); |
---|
533 | |
---|
534 | for ( Int y=0; y<m_ppcOrigYuv[uiDepth]->getHeight(); y++) |
---|
535 | { |
---|
536 | for ( Int x=0; x<m_ppcOrigYuv[uiDepth]->getWidth(); x++) |
---|
537 | { |
---|
538 | if( pUsedSamples[x] !=0 ) |
---|
539 | { |
---|
540 | bFullyRenderedSec = false ; |
---|
541 | break ; |
---|
542 | } |
---|
543 | } |
---|
544 | if ( !bFullyRenderedSec ) |
---|
545 | { |
---|
546 | break; |
---|
547 | } |
---|
548 | pUsedSamples += uiStride ; |
---|
549 | } |
---|
550 | } |
---|
551 | else |
---|
552 | { |
---|
553 | bFullyRenderedSec = false ; |
---|
554 | } |
---|
555 | #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE |
---|
556 | if( bFullyRenderedSec ) |
---|
557 | { |
---|
558 | m_pcRdCost->setLambdaScale( m_pcEncCfg->getInterViewSkipLambdaScale() ); |
---|
559 | } |
---|
560 | else |
---|
561 | { |
---|
562 | m_pcRdCost->setLambdaScale( 1 ); |
---|
563 | } |
---|
564 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
565 | #endif |
---|
566 | |
---|
567 | #endif |
---|
568 | if( ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getWidth() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getHeight() ) ) |
---|
569 | { |
---|
570 | // do CU Skip |
---|
571 | #if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU |
---|
572 | if(bWholeCUCanBeSynthesized) |
---|
573 | { |
---|
574 | rpcBestCU->getTotalCost() = 0; // Cost of synthesised CU is zero |
---|
575 | rpcBestCU->getTotalBits() = 0; // Cost of synthesised CU is zero |
---|
576 | rpcBestCU->getTotalDistortion() = 0; // Distortion of synthesised CU is zero |
---|
577 | rpcBestCU->setPredModeSubParts( MODE_SYNTH, 0, uiDepth ); |
---|
578 | rpcBestCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
579 | #if POZNAN_FILL_OCCLUDED_CU_WITH_SYNTHESIS |
---|
580 | m_ppcRecoYuvBest[uiDepth]->copyFromPicYuv(pcPic->getPicYuvSynth(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU()); // First copy synthesis YUV part to CU encoder reconstruction YUV structure |
---|
581 | #else |
---|
582 | m_ppcRecoYuvBest[uiDepth]->copyFromPicYuv(pcPic->getPicYuvAvail(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU()); // First copy synthesis YUV part to CU encoder reconstruction YUV structure |
---|
583 | #endif |
---|
584 | UInt uiInitTrDepth = rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1; |
---|
585 | rpcBestCU->copyToPic(uiDepth, 0, uiInitTrDepth); |
---|
586 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth ); // Next copy it to reconstruction YUV buffer in coded picture |
---|
587 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); //Not needed any more ?? |
---|
588 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
---|
589 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
590 | |
---|
591 | #if HHI_VSO//?? |
---|
592 | if( m_pcRdCost->getUseRenModel() ) |
---|
593 | { |
---|
594 | UInt uiWidth = rpcBestCU->getWidth ( 0 ); |
---|
595 | UInt uiHeight = rpcBestCU->getHeight( 0 ); |
---|
596 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 ); |
---|
597 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride(); |
---|
598 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
599 | } |
---|
600 | #endif |
---|
601 | return; |
---|
602 | } |
---|
603 | else if (bOneSubCUCanNotBeSynthesied && (uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )) // If only one from subCU can not be synthesised than force NxN split but donot signal it in the stream |
---|
604 | { |
---|
605 | //printf("CUSkip - OneCanNotBe %d %d %d\n",rpcBestCU->getCUPelX(),rpcBestCU->getCUPelY(),rpcBestCU->getWidth()); |
---|
606 | // further split !!!!go to line 866!!! |
---|
607 | #if HHI_VSO |
---|
608 | // reset Model |
---|
609 | if( m_pcRdCost->getUseRenModel() ) |
---|
610 | { |
---|
611 | UInt uiWidth = m_ppcBestCU[uiDepth]->getWidth ( 0 ); |
---|
612 | UInt uiHeight = m_ppcBestCU[uiDepth]->getHeight( 0 ); |
---|
613 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 ); |
---|
614 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride(); |
---|
615 | m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
616 | } |
---|
617 | #endif |
---|
618 | |
---|
619 | UChar uhNextDepth = uiDepth + 1; |
---|
620 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
621 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
622 | |
---|
623 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) //UInt uiPartUnitIdx = iSubCUNotSynthesied; |
---|
624 | { |
---|
625 | pcSubBestPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
626 | pcSubTempPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
627 | // pcSubBestPartCU->setLastCodedQP( rpcBestCU->getLastCodedQP() ); |
---|
628 | // pcSubTempPartCU->setLastCodedQP( rpcBestCU->getLastCodedQP() ); |
---|
629 | |
---|
630 | if( ( pcSubBestPartCU->getCUPelX() < pcSubBestPartCU->getSlice()->getSPS()->getWidth() ) && ( pcSubBestPartCU->getCUPelY() < pcSubBestPartCU->getSlice()->getSPS()->getHeight() ) ) |
---|
631 | { |
---|
632 | if( m_bUseSBACRD ) |
---|
633 | { |
---|
634 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
635 | { |
---|
636 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
637 | } |
---|
638 | else |
---|
639 | { |
---|
640 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
641 | } |
---|
642 | } |
---|
643 | |
---|
644 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); //Compress SubCU's |
---|
645 | |
---|
646 | #if HHI_VSO |
---|
647 | if( m_pcRdCost->getUseRenModel() ) |
---|
648 | { |
---|
649 | UInt uiWidth = pcSubBestPartCU->getWidth ( 0 ); |
---|
650 | UInt uiHeight = pcSubBestPartCU->getHeight( 0 ); |
---|
651 | Pel* piSrc = m_ppcRecoYuvBest[pcSubBestPartCU->getDepth(0)]->getLumaAddr( 0 ); |
---|
652 | UInt uiSrcStride = m_ppcRecoYuvBest[pcSubBestPartCU->getDepth(0)]->getStride(); |
---|
653 | m_pcRdCost->setRenModelData( pcSubBestPartCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
654 | } |
---|
655 | #endif |
---|
656 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
657 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
658 | } |
---|
659 | } |
---|
660 | |
---|
661 | if( !bBoundary ) |
---|
662 | { |
---|
663 | m_pcEntropyCoder->resetBits(); |
---|
664 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
665 | |
---|
666 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
667 | } |
---|
668 | |
---|
669 | #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE |
---|
670 | if( bFullyRenderedSec ) |
---|
671 | { |
---|
672 | m_pcRdCost->setLambdaScale( m_pcEncCfg->getInterViewSkipLambdaScale() ); |
---|
673 | } |
---|
674 | else |
---|
675 | { |
---|
676 | m_pcRdCost->setLambdaScale( 1 ); |
---|
677 | } |
---|
678 | #endif |
---|
679 | #if HHI_VSO |
---|
680 | if ( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
681 | { |
---|
682 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
683 | } |
---|
684 | else |
---|
685 | #endif |
---|
686 | { |
---|
687 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
688 | } |
---|
689 | |
---|
690 | if( m_bUseSBACRD ) |
---|
691 | { |
---|
692 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
693 | } |
---|
694 | //Copy Tmp to Best |
---|
695 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); //Roznica z naszym koder // RD compare current larger prediction |
---|
696 | |
---|
697 | #if HHI_VSO |
---|
698 | if( m_pcRdCost->getUseRenModel() ) |
---|
699 | { |
---|
700 | UInt uiWidth = rpcBestCU->getWidth ( 0 ); |
---|
701 | UInt uiHeight = rpcBestCU->getHeight( 0 ); |
---|
702 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 ); |
---|
703 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride(); |
---|
704 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
705 | } |
---|
706 | #endif |
---|
707 | //Copy result to pic |
---|
708 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
709 | |
---|
710 | if( bBoundary ) |
---|
711 | return; |
---|
712 | |
---|
713 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth ); // Copy Yuv data to picture Yuv |
---|
714 | |
---|
715 | // Assert if Best prediction mode is NONE |
---|
716 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
717 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); //Not needed any more? |
---|
718 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
---|
719 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
720 | return; |
---|
721 | } |
---|
722 | #endif |
---|
723 | |
---|
724 | // do inter modes |
---|
725 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
726 | { |
---|
727 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
728 | // check availability of residual prediction |
---|
729 | Bool bResPredAvailable = false; |
---|
730 | Bool bResPredAllowed = (!rpcBestCU->getSlice()->getSPS()->isDepth () ); |
---|
731 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getViewId () ); |
---|
732 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getMultiviewResPredMode() ); |
---|
733 | if( bResPredAllowed ) |
---|
734 | { |
---|
735 | bResPredAvailable = rpcBestCU->getResidualSamples( 0, m_ppcResPredTmp[uiDepth] ); |
---|
736 | } |
---|
737 | |
---|
738 | for( UInt uiResPrdId = 0; uiResPrdId < ( bResPredAvailable ? 2 : 1 ); uiResPrdId++ ) |
---|
739 | { |
---|
740 | Bool bResPredFlag = ( uiResPrdId > 0 ); |
---|
741 | #endif |
---|
742 | |
---|
743 | // SKIP |
---|
744 | pcTempCU = rpcTempCU; |
---|
745 | |
---|
746 | if( pcPic->getSlice(0)->getSPS()->getUseMRG() ) |
---|
747 | { |
---|
748 | #if !HHI_MRG_SKIP |
---|
749 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
750 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
751 | #endif |
---|
752 | xCheckRDCostAMVPSkip ( rpcBestCU, rpcTempCU ); rpcTempCU->initEstData(); |
---|
753 | #endif |
---|
754 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
755 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
756 | #endif |
---|
757 | #if HHI_INTERVIEW_SKIP |
---|
758 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
759 | #else |
---|
760 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU ); rpcTempCU->initEstData(); |
---|
761 | #endif |
---|
762 | } |
---|
763 | else |
---|
764 | { |
---|
765 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
766 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
767 | #endif |
---|
768 | xCheckRDCostAMVPSkip ( rpcBestCU, rpcTempCU ); rpcTempCU->initEstData(); |
---|
769 | } |
---|
770 | |
---|
771 | // fast encoder decision for early skip |
---|
772 | if ( m_pcEncCfg->getUseFastEnc() ) |
---|
773 | { |
---|
774 | Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ]; |
---|
775 | if ( aiNum [ iIdx ] > 5 && fRD_Skip < EARLY_SKIP_THRES*afCost[ iIdx ]/aiNum[ iIdx ] ) |
---|
776 | { |
---|
777 | bEarlySkip = true; |
---|
778 | bTrySplit = false; |
---|
779 | } |
---|
780 | } |
---|
781 | |
---|
782 | // 2Nx2N, NxN |
---|
783 | if ( !bEarlySkip ) |
---|
784 | { |
---|
785 | #if HHI_DISABLE_INTER_NxN_SPLIT |
---|
786 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
787 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
788 | #endif |
---|
789 | #if HHI_INTERVIEW_SKIP |
---|
790 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
791 | #else |
---|
792 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData(); |
---|
793 | #endif |
---|
794 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
795 | { |
---|
796 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
797 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
798 | #endif |
---|
799 | #if HHI_INTERVIEW_SKIP |
---|
800 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
801 | #else |
---|
802 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); rpcTempCU->initEstData(); |
---|
803 | #endif |
---|
804 | } |
---|
805 | #else |
---|
806 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
807 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
808 | #endif |
---|
809 | #if HHI_INTERVIEW_SKIP |
---|
810 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
811 | #else |
---|
812 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData(); |
---|
813 | #endif |
---|
814 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
815 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
816 | #endif |
---|
817 | #if HHI_INTERVIEW_SKIP |
---|
818 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
819 | #else |
---|
820 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); rpcTempCU->initEstData(); |
---|
821 | #endif |
---|
822 | #endif |
---|
823 | } |
---|
824 | |
---|
825 | #if HHI_RMP_SWITCH |
---|
826 | if( pcPic->getSlice(0)->getSPS()->getUseRMP() ) |
---|
827 | #endif |
---|
828 | { // 2NxN, Nx2N |
---|
829 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
830 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
831 | #endif |
---|
832 | #if HHI_INTERVIEW_SKIP |
---|
833 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
834 | #else |
---|
835 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N ); rpcTempCU->initEstData(); |
---|
836 | #endif |
---|
837 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
838 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
839 | #endif |
---|
840 | #if HHI_INTERVIEW_SKIP |
---|
841 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
842 | #else |
---|
843 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN ); rpcTempCU->initEstData(); |
---|
844 | #endif |
---|
845 | } |
---|
846 | |
---|
847 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
848 | } // uiResPrdId |
---|
849 | #endif |
---|
850 | } |
---|
851 | |
---|
852 | // do normal intra modes |
---|
853 | if ( !bEarlySkip ) |
---|
854 | { |
---|
855 | // speedup for inter frames |
---|
856 | #if HHI_INTERVIEW_SKIP |
---|
857 | if( ( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
858 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
859 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
860 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) && !bFullyRenderedSec ) // avoid very complex intra if it is unlikely |
---|
861 | #else |
---|
862 | if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
863 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
864 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
865 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) // avoid very complex intra if it is unlikely |
---|
866 | #endif |
---|
867 | { |
---|
868 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData(); |
---|
869 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
870 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
871 | #endif |
---|
872 | { |
---|
873 | if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) ) |
---|
874 | { |
---|
875 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); rpcTempCU->initEstData(); |
---|
876 | } |
---|
877 | } |
---|
878 | } |
---|
879 | } |
---|
880 | |
---|
881 | m_pcEntropyCoder->resetBits(); |
---|
882 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
---|
883 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
884 | |
---|
885 | #if HHI_VSO |
---|
886 | if (m_pcRdCost->getUseLambdaScaleVSO()) |
---|
887 | { |
---|
888 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
889 | } |
---|
890 | else |
---|
891 | #endif |
---|
892 | { |
---|
893 | #if HHI_INTERVIEW_SKIP |
---|
894 | if( m_pcEncCfg->getInterViewSkip()) |
---|
895 | { |
---|
896 | TComYuv* pRec = m_ppcRecoYuvBest[ uiDepth ]; |
---|
897 | TComYuv* pOrg = m_ppcOrigYuv [ uiDepth ]; |
---|
898 | Pel* pUsedY = pcPic->getUsedPelsMap()->getLumaAddr( rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
899 | Pel* pUsedU = pcPic->getUsedPelsMap()->getCbAddr ( rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
900 | Pel* pUsedV = pcPic->getUsedPelsMap()->getCrAddr ( rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
901 | Int iUStrdY = pcPic->getUsedPelsMap()->getStride (); |
---|
902 | Int iUStrdC = pcPic->getUsedPelsMap()->getCStride (); |
---|
903 | UInt uiWdt = rpcBestCU->getWidth ( 0 ); |
---|
904 | UInt uiHgt = rpcBestCU->getHeight( 0 ); |
---|
905 | UInt uiDist = ( m_pcRdCost->getDistPart( pRec->getLumaAddr(), pRec->getStride(), pOrg->getLumaAddr(), pOrg->getStride(), pUsedY, iUStrdY, uiWdt, uiHgt ) |
---|
906 | + m_pcRdCost->getDistPart( pRec->getCbAddr(), pRec->getCStride(), pOrg->getCbAddr(), pOrg->getCStride(), pUsedU, iUStrdC, uiWdt >> 1, uiHgt >> 1 ) |
---|
907 | + m_pcRdCost->getDistPart( pRec->getCrAddr(), pRec->getCStride(), pOrg->getCrAddr(), pOrg->getCStride(), pUsedV, iUStrdC, uiWdt >> 1, uiHgt >> 1 ) ); |
---|
908 | // printf("\nD(as is) = %d, D(new) = %d, diff = %d", rpcBestCU->getTotalDistortion(), uiDist, Int(rpcBestCU->getTotalDistortion()-uiDist) ); |
---|
909 | rpcBestCU->getTotalDistortion() = uiDist; |
---|
910 | } |
---|
911 | #endif |
---|
912 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
913 | } |
---|
914 | |
---|
915 | |
---|
916 | // accumulate statistics for early skip |
---|
917 | if ( m_pcEncCfg->getUseFastEnc() ) |
---|
918 | { |
---|
919 | if ( rpcBestCU->isSkipped(0) ) |
---|
920 | { |
---|
921 | Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ]; |
---|
922 | afCost[ iIdx ] += rpcBestCU->getTotalCost(); |
---|
923 | aiNum [ iIdx ] ++; |
---|
924 | } |
---|
925 | } |
---|
926 | #if HHI_MPI |
---|
927 | if( rpcBestCU->getSlice()->getSPS()->getUseMVI() && rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
928 | { |
---|
929 | xCheckRDCostMvInheritance( rpcBestCU, rpcTempCU, uiDepth, false, false ); rpcTempCU->initEstData(); |
---|
930 | rpcTempCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, 0, uiDepth ); |
---|
931 | rpcTempCU->setDepthSubParts( uiDepth, 0 ); |
---|
932 | xCheckRDCostMvInheritance( rpcBestCU, rpcTempCU, uiDepth, true, false ); rpcTempCU->initEstData(); |
---|
933 | } |
---|
934 | #endif |
---|
935 | } |
---|
936 | else |
---|
937 | { |
---|
938 | bBoundary = true; |
---|
939 | } |
---|
940 | |
---|
941 | // further split |
---|
942 | if( bTrySplit && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
943 | { |
---|
944 | #if HHI_VSO |
---|
945 | // reset Model |
---|
946 | if( m_pcRdCost->getUseRenModel() ) |
---|
947 | { |
---|
948 | UInt uiWidth = m_ppcBestCU[uiDepth]->getWidth ( 0 ); |
---|
949 | UInt uiHeight = m_ppcBestCU[uiDepth]->getHeight( 0 ); |
---|
950 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 ); |
---|
951 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride(); |
---|
952 | m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
953 | } |
---|
954 | #endif |
---|
955 | |
---|
956 | UChar uhNextDepth = uiDepth+1; |
---|
957 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
958 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
959 | |
---|
960 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
961 | { |
---|
962 | pcSubBestPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
963 | pcSubTempPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
964 | |
---|
965 | if( ( pcSubBestPartCU->getCUPelX() < pcSubBestPartCU->getSlice()->getSPS()->getWidth() ) && ( pcSubBestPartCU->getCUPelY() < pcSubBestPartCU->getSlice()->getSPS()->getHeight() ) ) |
---|
966 | { |
---|
967 | if( m_bUseSBACRD ) |
---|
968 | { |
---|
969 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
970 | { |
---|
971 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
972 | } |
---|
973 | else |
---|
974 | { |
---|
975 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
976 | } |
---|
977 | } |
---|
978 | |
---|
979 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
---|
980 | |
---|
981 | #if HHI_VSO |
---|
982 | if( m_pcRdCost->getUseRenModel() ) |
---|
983 | { |
---|
984 | UInt uiWidth = pcSubBestPartCU->getWidth ( 0 ); |
---|
985 | UInt uiHeight = pcSubBestPartCU->getHeight( 0 ); |
---|
986 | Pel* piSrc = m_ppcRecoYuvBest[pcSubBestPartCU->getDepth(0)]->getLumaAddr( 0 ); |
---|
987 | UInt uiSrcStride = m_ppcRecoYuvBest[pcSubBestPartCU->getDepth(0)]->getStride(); |
---|
988 | m_pcRdCost->setRenModelData( pcSubBestPartCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
989 | } |
---|
990 | #endif |
---|
991 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
992 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
993 | } |
---|
994 | } |
---|
995 | |
---|
996 | if( !bBoundary ) |
---|
997 | { |
---|
998 | m_pcEntropyCoder->resetBits(); |
---|
999 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
1000 | |
---|
1001 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
1002 | } |
---|
1003 | |
---|
1004 | #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE |
---|
1005 | if( bFullyRenderedSec ) |
---|
1006 | { |
---|
1007 | m_pcRdCost->setLambdaScale( m_pcEncCfg->getInterViewSkipLambdaScale() ); |
---|
1008 | } |
---|
1009 | else |
---|
1010 | { |
---|
1011 | m_pcRdCost->setLambdaScale( 1 ); |
---|
1012 | } |
---|
1013 | #endif |
---|
1014 | #if HHI_VSO |
---|
1015 | if ( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
1016 | { |
---|
1017 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1018 | } |
---|
1019 | else |
---|
1020 | #endif |
---|
1021 | { |
---|
1022 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1023 | } |
---|
1024 | |
---|
1025 | if( m_bUseSBACRD ) |
---|
1026 | { |
---|
1027 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1028 | } |
---|
1029 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); // RD compare current larger prediction |
---|
1030 | |
---|
1031 | #if HHI_VSO |
---|
1032 | if( m_pcRdCost->getUseRenModel() ) |
---|
1033 | { |
---|
1034 | UInt uiWidth = rpcBestCU->getWidth ( 0 ); |
---|
1035 | UInt uiHeight = rpcBestCU->getHeight( 0 ); |
---|
1036 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 ); |
---|
1037 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride(); |
---|
1038 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1039 | } |
---|
1040 | #endif |
---|
1041 | } // with sub partitioned prediction. |
---|
1042 | |
---|
1043 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
1044 | |
---|
1045 | if( bBoundary ) |
---|
1046 | return; |
---|
1047 | |
---|
1048 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth ); // Copy Yuv data to picture Yuv |
---|
1049 | |
---|
1050 | // Assert if Best prediction mode is NONE |
---|
1051 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
1052 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); |
---|
1053 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
---|
1054 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
1055 | } |
---|
1056 | |
---|
1057 | /** encode a CU block recursively |
---|
1058 | * \param pcCU |
---|
1059 | * \param uiAbsPartIdx |
---|
1060 | * \param uiDepth |
---|
1061 | * \returns Void |
---|
1062 | */ |
---|
1063 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1064 | { |
---|
1065 | TComPic* pcPic = pcCU->getPic(); |
---|
1066 | |
---|
1067 | #if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU |
---|
1068 | if( pcCU->isCUSkiped( uiAbsPartIdx ) && uiDepth == pcCU->getDepth( uiAbsPartIdx )) //If CU Skiped no information is coded into stream |
---|
1069 | return; |
---|
1070 | #endif |
---|
1071 | |
---|
1072 | Bool bBoundary = false; |
---|
1073 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1074 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
1075 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1076 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
1077 | |
---|
1078 | #if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU |
---|
1079 | Bool bDontSendSplitFlag = false; |
---|
1080 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) //check if CU has 3 synthesied subCU - no split flag is send in that case |
---|
1081 | { |
---|
1082 | UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
1083 | Int iCUSkipCounter = 0; |
---|
1084 | UInt uiAbsPartIdxTmp = uiAbsPartIdx; |
---|
1085 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdxTmp+=uiQNumParts ) |
---|
1086 | { |
---|
1087 | if(pcCU->isCUSkiped(uiAbsPartIdxTmp) && (pcCU->getDepth( uiAbsPartIdxTmp ) == uiDepth + 1) ) |
---|
1088 | { |
---|
1089 | iCUSkipCounter++; |
---|
1090 | } |
---|
1091 | } |
---|
1092 | if(iCUSkipCounter == 3) |
---|
1093 | { |
---|
1094 | bDontSendSplitFlag = true; |
---|
1095 | } |
---|
1096 | } |
---|
1097 | #endif |
---|
1098 | |
---|
1099 | if( ( uiRPelX < pcCU->getSlice()->getSPS()->getWidth() ) && ( uiBPelY < pcCU->getSlice()->getSPS()->getHeight() ) ) |
---|
1100 | { |
---|
1101 | #if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU |
---|
1102 | if(!bDontSendSplitFlag) |
---|
1103 | #endif |
---|
1104 | #if HHI_MPI |
---|
1105 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 || uiDepth < pcCU->getTextureModeDepth( uiAbsPartIdx ) ) |
---|
1106 | #endif |
---|
1107 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1108 | } |
---|
1109 | else |
---|
1110 | { |
---|
1111 | bBoundary = true; |
---|
1112 | } |
---|
1113 | |
---|
1114 | #if HHI_MPI |
---|
1115 | if( uiDepth == pcCU->getTextureModeDepth( uiAbsPartIdx ) ) |
---|
1116 | { |
---|
1117 | xSaveDepthWidthHeight( pcCU ); |
---|
1118 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
1119 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
1120 | |
---|
1121 | if( ( uiRPelX < pcCU->getSlice()->getSPS()->getWidth() ) && ( uiBPelY < pcCU->getSlice()->getSPS()->getHeight() ) ) |
---|
1122 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1123 | if( !pcCU->getSlice()->isIntra() ) |
---|
1124 | { |
---|
1125 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
1126 | } |
---|
1127 | |
---|
1128 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1129 | { |
---|
1130 | #if HHI_MRG_SKIP |
---|
1131 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 ); |
---|
1132 | #else |
---|
1133 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) //if ( ref. frame list0 has at least 1 entry ) |
---|
1134 | { |
---|
1135 | m_pcEntropyCoder->encodeMVPIdx( pcCU, uiAbsPartIdx, REF_PIC_LIST_0); |
---|
1136 | } |
---|
1137 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) //if ( ref. frame list1 has at least 1 entry ) |
---|
1138 | { |
---|
1139 | m_pcEntropyCoder->encodeMVPIdx( pcCU, uiAbsPartIdx, REF_PIC_LIST_1); |
---|
1140 | } |
---|
1141 | #endif |
---|
1142 | xRestoreDepthWidthHeight( pcCU ); |
---|
1143 | return; |
---|
1144 | } |
---|
1145 | |
---|
1146 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
1147 | |
---|
1148 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1149 | |
---|
1150 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1151 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
1152 | xRestoreDepthWidthHeight( pcCU ); |
---|
1153 | } |
---|
1154 | #endif |
---|
1155 | |
---|
1156 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) |
---|
1157 | { |
---|
1158 | UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
1159 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
1160 | { |
---|
1161 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1162 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1163 | |
---|
1164 | if( ( uiLPelX < pcCU->getSlice()->getSPS()->getWidth() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getHeight() ) ) |
---|
1165 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
1166 | } |
---|
1167 | return; |
---|
1168 | } |
---|
1169 | |
---|
1170 | #if TSB_ALF_HEADER |
---|
1171 | #else |
---|
1172 | m_pcEntropyCoder->encodeAlfCtrlFlag( pcCU, uiAbsPartIdx ); |
---|
1173 | #endif |
---|
1174 | |
---|
1175 | #if HHI_MPI |
---|
1176 | if( !pcCU->getSlice()->isIntra() && pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
---|
1177 | #else |
---|
1178 | if( !pcCU->getSlice()->isIntra() ) |
---|
1179 | #endif |
---|
1180 | { |
---|
1181 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
1182 | } |
---|
1183 | |
---|
1184 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1185 | { |
---|
1186 | #if HHI_MRG_SKIP |
---|
1187 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 ); |
---|
1188 | #else |
---|
1189 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) //if ( ref. frame list0 has at least 1 entry ) |
---|
1190 | { |
---|
1191 | m_pcEntropyCoder->encodeMVPIdx( pcCU, uiAbsPartIdx, REF_PIC_LIST_0); |
---|
1192 | } |
---|
1193 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) //if ( ref. frame list1 has at least 1 entry ) |
---|
1194 | { |
---|
1195 | m_pcEntropyCoder->encodeMVPIdx( pcCU, uiAbsPartIdx, REF_PIC_LIST_1); |
---|
1196 | } |
---|
1197 | #endif |
---|
1198 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1199 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
---|
1200 | #endif |
---|
1201 | return; |
---|
1202 | } |
---|
1203 | #if HHI_MPI |
---|
1204 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
---|
1205 | { |
---|
1206 | #endif |
---|
1207 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
1208 | |
---|
1209 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1210 | |
---|
1211 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1212 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
1213 | |
---|
1214 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1215 | if( !pcCU->isIntra( uiAbsPartIdx ) ) |
---|
1216 | { |
---|
1217 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
---|
1218 | } |
---|
1219 | #endif |
---|
1220 | #if HHI_MPI |
---|
1221 | } |
---|
1222 | #endif |
---|
1223 | |
---|
1224 | // Encode Coefficients |
---|
1225 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx) ); |
---|
1226 | } |
---|
1227 | |
---|
1228 | Void TEncCu::xCheckRDCostSkip( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool bSkipRes ) |
---|
1229 | { |
---|
1230 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1231 | |
---|
1232 | #if HHI_VSO |
---|
1233 | if( m_pcRdCost->getUseRenModel() ) |
---|
1234 | { |
---|
1235 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1236 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1237 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1238 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1239 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1240 | } |
---|
1241 | #endif |
---|
1242 | |
---|
1243 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
1244 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
1245 | |
---|
1246 | m_pcPredSearch->predInterSkipSearch ( rpcTempCU, |
---|
1247 | m_ppcOrigYuv [uhDepth], |
---|
1248 | m_ppcPredYuvTemp[uhDepth], |
---|
1249 | m_ppcResiYuvTemp[uhDepth], |
---|
1250 | m_ppcRecoYuvTemp[uhDepth] ); |
---|
1251 | |
---|
1252 | m_pcPredSearch->encodeResAndCalcRdInterCU ( rpcTempCU, |
---|
1253 | m_ppcOrigYuv [uhDepth], |
---|
1254 | m_ppcPredYuvTemp[uhDepth], |
---|
1255 | m_ppcResiYuvTemp[uhDepth], |
---|
1256 | m_ppcResiYuvBest[uhDepth], |
---|
1257 | m_ppcRecoYuvTemp[uhDepth], |
---|
1258 | m_ppcResPredTmp [uhDepth], |
---|
1259 | bSkipRes ); |
---|
1260 | |
---|
1261 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
1262 | } |
---|
1263 | |
---|
1264 | /** check RD costs for a CU block encoded with merge |
---|
1265 | * \param rpcBestCU |
---|
1266 | * \param rpcTempCU |
---|
1267 | * \returns Void |
---|
1268 | */ |
---|
1269 | #if HHI_INTERVIEW_SKIP |
---|
1270 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool bSkipRes ) |
---|
1271 | #else |
---|
1272 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
1273 | #endif |
---|
1274 | { |
---|
1275 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
1276 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
1277 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
1278 | UInt uiNeighbourCandIdx[MRG_MAX_NUM_CANDS]; //MVs with same idx => same cand |
---|
1279 | |
---|
1280 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1281 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
1282 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
1283 | #endif |
---|
1284 | |
---|
1285 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS; ++ui ) |
---|
1286 | { |
---|
1287 | uhInterDirNeighbours[ui] = 0; |
---|
1288 | uiNeighbourCandIdx[ui] = 0; |
---|
1289 | } |
---|
1290 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1291 | |
---|
1292 | #if HHI_VSO |
---|
1293 | if( m_pcRdCost->getUseRenModel() ) |
---|
1294 | { |
---|
1295 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1296 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1297 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1298 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1299 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1300 | } |
---|
1301 | #endif |
---|
1302 | |
---|
1303 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1304 | rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours,uhInterDirNeighbours, uiNeighbourCandIdx ); |
---|
1305 | |
---|
1306 | Bool bValidCands = false; |
---|
1307 | for( UInt uiMergeCand = 0; uiMergeCand < MRG_MAX_NUM_CANDS; ++uiMergeCand ) |
---|
1308 | { |
---|
1309 | if( uiNeighbourCandIdx[uiMergeCand] == ( uiMergeCand + 1 ) ) |
---|
1310 | { |
---|
1311 | #if HHI_MRG_SKIP |
---|
1312 | TComYuv* pcPredYuvTemp = NULL; |
---|
1313 | #if HHI_INTERVIEW_SKIP |
---|
1314 | for( UInt uiNoResidual = (bSkipRes ? 1:0); uiNoResidual < 2; ++uiNoResidual ) |
---|
1315 | #else |
---|
1316 | for( UInt uiNoResidual = 0; uiNoResidual < 2; ++uiNoResidual ) |
---|
1317 | #endif |
---|
1318 | { |
---|
1319 | #endif |
---|
1320 | bValidCands = true; |
---|
1321 | // set MC parameters |
---|
1322 | #if HHI_MRG_SKIP |
---|
1323 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1324 | #else |
---|
1325 | rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1326 | #endif |
---|
1327 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1328 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1329 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1330 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1331 | for( UInt uiInner = 0; uiInner < MRG_MAX_NUM_CANDS; uiInner++ ) |
---|
1332 | { |
---|
1333 | rpcTempCU->setNeighbourCandIdxSubParts( uiInner, uiNeighbourCandIdx[uiInner], 0, 0,uhDepth ); |
---|
1334 | } |
---|
1335 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand].getMv(), cMvFieldNeighbours[0 + 2*uiMergeCand].getRefIdx(), SIZE_2Nx2N, 0, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1336 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand].getMv(), cMvFieldNeighbours[1 + 2*uiMergeCand].getRefIdx(), SIZE_2Nx2N, 0, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1337 | |
---|
1338 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1339 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
1340 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
1341 | #endif |
---|
1342 | |
---|
1343 | #if HHI_MRG_SKIP |
---|
1344 | // do MC |
---|
1345 | #if HHI_INTERVIEW_SKIP |
---|
1346 | if ( (uiNoResidual == 0) || bSkipRes ){ |
---|
1347 | #else |
---|
1348 | if ( uiNoResidual == 0 ){ |
---|
1349 | #endif |
---|
1350 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1351 | // save pred adress |
---|
1352 | pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth]; |
---|
1353 | |
---|
1354 | } |
---|
1355 | else { |
---|
1356 | if ( pcPredYuvTemp != m_ppcPredYuvTemp[uhDepth]) { |
---|
1357 | //adress changes take best (old temp) |
---|
1358 | pcPredYuvTemp = m_ppcPredYuvBest[uhDepth]; |
---|
1359 | } |
---|
1360 | } |
---|
1361 | #if HHI_VSO |
---|
1362 | if( m_pcRdCost->getUseRenModel() ) |
---|
1363 | { //Reset |
---|
1364 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1365 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1366 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1367 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1368 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1369 | } |
---|
1370 | #endif |
---|
1371 | |
---|
1372 | // estimate residual and encode everything |
---|
1373 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
1374 | m_ppcOrigYuv [uhDepth], |
---|
1375 | pcPredYuvTemp, |
---|
1376 | m_ppcResiYuvTemp[uhDepth], |
---|
1377 | m_ppcResiYuvBest[uhDepth], |
---|
1378 | m_ppcRecoYuvTemp[uhDepth], |
---|
1379 | m_ppcResPredTmp [uhDepth], |
---|
1380 | (uiNoResidual? true:false) ); |
---|
1381 | Bool bQtRootCbf = rpcTempCU->getQtRootCbf(0) == 1; |
---|
1382 | #else |
---|
1383 | // do MC |
---|
1384 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1385 | |
---|
1386 | // estimate residual and encode everything |
---|
1387 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
1388 | m_ppcOrigYuv [uhDepth], |
---|
1389 | m_ppcPredYuvTemp[uhDepth], |
---|
1390 | m_ppcResiYuvTemp[uhDepth], |
---|
1391 | m_ppcResiYuvBest[uhDepth], |
---|
1392 | m_ppcRecoYuvTemp[uhDepth], |
---|
1393 | m_ppcResPredTmp [uhDepth], |
---|
1394 | false ); |
---|
1395 | #endif |
---|
1396 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth ); |
---|
1397 | |
---|
1398 | rpcTempCU->initEstData(); |
---|
1399 | #if HHI_MRG_SKIP |
---|
1400 | if (!bQtRootCbf) |
---|
1401 | break; |
---|
1402 | } |
---|
1403 | #endif |
---|
1404 | } |
---|
1405 | } |
---|
1406 | } |
---|
1407 | |
---|
1408 | #if HHI_INTERVIEW_SKIP |
---|
1409 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bSkipRes) |
---|
1410 | #else |
---|
1411 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
1412 | #endif |
---|
1413 | { |
---|
1414 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1415 | |
---|
1416 | #if HHI_VSO |
---|
1417 | if( m_pcRdCost->getUseRenModel() ) |
---|
1418 | { |
---|
1419 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1420 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1421 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1422 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1423 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1424 | } |
---|
1425 | #endif |
---|
1426 | |
---|
1427 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
1428 | |
---|
1429 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1430 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
1431 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
1432 | #endif |
---|
1433 | rpcTempCU->setPartSizeSubParts ( SIZE_2Nx2N, 0, uhDepth ); |
---|
1434 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1435 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
1436 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
1437 | #endif |
---|
1438 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
1439 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
1440 | |
---|
1441 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1442 | if( rpcTempCU->getResPredFlag( 0 ) ) |
---|
1443 | { // subtract residual prediction from original in motion search |
---|
1444 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ), true ); |
---|
1445 | } |
---|
1446 | #endif |
---|
1447 | #if HHI_INTERVIEW_SKIP |
---|
1448 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes ); |
---|
1449 | #else |
---|
1450 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
1451 | #endif |
---|
1452 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1453 | if( rpcTempCU->getResPredFlag( 0 ) ) |
---|
1454 | { // add residual prediction to original again |
---|
1455 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ) ); |
---|
1456 | } |
---|
1457 | #endif |
---|
1458 | |
---|
1459 | #if PART_MRG |
---|
1460 | if (rpcTempCU->getWidth(0) > 8 && !rpcTempCU->getMergeFlag(0) && (ePartSize != SIZE_2Nx2N && ePartSize != SIZE_NxN)) |
---|
1461 | { |
---|
1462 | return; |
---|
1463 | } |
---|
1464 | #endif |
---|
1465 | #if HHI_INTERVIEW_SKIP |
---|
1466 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth],bSkipRes ); |
---|
1467 | #else |
---|
1468 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth], false ); |
---|
1469 | #endif |
---|
1470 | |
---|
1471 | #if HHI_VSO |
---|
1472 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
1473 | { |
---|
1474 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1475 | } |
---|
1476 | else |
---|
1477 | #endif |
---|
1478 | { |
---|
1479 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1480 | } |
---|
1481 | |
---|
1482 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
1483 | } |
---|
1484 | |
---|
1485 | Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize ) |
---|
1486 | { |
---|
1487 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
1488 | |
---|
1489 | #if HHI_VSO |
---|
1490 | if( m_pcRdCost->getUseRenModel() ) |
---|
1491 | { |
---|
1492 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1493 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1494 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr( ); |
---|
1495 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride(); |
---|
1496 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1497 | } |
---|
1498 | #endif |
---|
1499 | |
---|
1500 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
1501 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
1502 | |
---|
1503 | Bool bSeparateLumaChroma = true; // choose estimation mode |
---|
1504 | Dist uiPreCalcDistC = 0; |
---|
1505 | if( !bSeparateLumaChroma ) |
---|
1506 | { |
---|
1507 | m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] ); |
---|
1508 | } |
---|
1509 | m_pcPredSearch ->estIntraPredQT ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma ); |
---|
1510 | |
---|
1511 | #if LM_CHROMA |
---|
1512 | m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() ); |
---|
1513 | #endif |
---|
1514 | |
---|
1515 | m_pcPredSearch ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC ); |
---|
1516 | |
---|
1517 | m_pcEntropyCoder->resetBits(); |
---|
1518 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
1519 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
1520 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
1521 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0, true ); |
---|
1522 | |
---|
1523 | // Encode Coefficients |
---|
1524 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0) ); |
---|
1525 | |
---|
1526 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1527 | |
---|
1528 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1529 | #if HHI_VSO |
---|
1530 | if( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
1531 | { |
---|
1532 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1533 | } |
---|
1534 | else |
---|
1535 | #endif |
---|
1536 | { |
---|
1537 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1538 | } |
---|
1539 | |
---|
1540 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); |
---|
1541 | } |
---|
1542 | |
---|
1543 | // check whether current try is the best |
---|
1544 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UChar uhDepth ) |
---|
1545 | { |
---|
1546 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
1547 | { |
---|
1548 | TComYuv* pcYuv; |
---|
1549 | |
---|
1550 | // Change Information data |
---|
1551 | TComDataCU* pcCU = rpcBestCU; |
---|
1552 | rpcBestCU = rpcTempCU; |
---|
1553 | rpcTempCU = pcCU; |
---|
1554 | |
---|
1555 | // Change Prediction data |
---|
1556 | pcYuv = m_ppcPredYuvBest[uhDepth]; |
---|
1557 | m_ppcPredYuvBest[uhDepth] = m_ppcPredYuvTemp[uhDepth]; |
---|
1558 | m_ppcPredYuvTemp[uhDepth] = pcYuv; |
---|
1559 | |
---|
1560 | // Change Reconstruction data |
---|
1561 | pcYuv = m_ppcRecoYuvBest[uhDepth]; |
---|
1562 | m_ppcRecoYuvBest[uhDepth] = m_ppcRecoYuvTemp[uhDepth]; |
---|
1563 | m_ppcRecoYuvTemp[uhDepth] = pcYuv; |
---|
1564 | |
---|
1565 | pcYuv = NULL; |
---|
1566 | pcCU = NULL; |
---|
1567 | |
---|
1568 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
---|
1569 | m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_NEXT_BEST]); |
---|
1570 | } |
---|
1571 | } |
---|
1572 | |
---|
1573 | Void TEncCu::xCheckRDCostAMVPSkip ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
1574 | { |
---|
1575 | UChar uhDepth = rpcTempCU->getDepth(0); |
---|
1576 | |
---|
1577 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1578 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
1579 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
1580 | #endif |
---|
1581 | |
---|
1582 | AMVPInfo cAMVPInfo0; |
---|
1583 | cAMVPInfo0.iN = 0; |
---|
1584 | |
---|
1585 | AMVPInfo cAMVPInfo1; |
---|
1586 | cAMVPInfo1.iN = 0; |
---|
1587 | |
---|
1588 | if (rpcTempCU->getAMVPMode(0) == AM_EXPL) |
---|
1589 | { |
---|
1590 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
1591 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
1592 | |
---|
1593 | if ( rpcTempCU->getSlice()->isInterP() && rpcTempCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
1594 | { |
---|
1595 | rpcTempCU->fillMvpCand(0, 0, REF_PIC_LIST_0, 0, &cAMVPInfo0); |
---|
1596 | } |
---|
1597 | else if ( rpcTempCU->getSlice()->isInterB() && |
---|
1598 | rpcTempCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 && |
---|
1599 | rpcTempCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
1600 | { |
---|
1601 | rpcTempCU->fillMvpCand(0, 0, REF_PIC_LIST_0, 0, &cAMVPInfo0); |
---|
1602 | rpcTempCU->fillMvpCand(0, 0, REF_PIC_LIST_1, 0, &cAMVPInfo1); |
---|
1603 | } |
---|
1604 | else |
---|
1605 | { |
---|
1606 | assert( 0 ); |
---|
1607 | } |
---|
1608 | } |
---|
1609 | |
---|
1610 | Int iMVP0, iMVP1; |
---|
1611 | |
---|
1612 | for (iMVP0 = (cAMVPInfo0.iN > 0? 0:-1); iMVP0 < cAMVPInfo0.iN; iMVP0++) |
---|
1613 | { |
---|
1614 | for (iMVP1 = (cAMVPInfo1.iN > 0? 0:-1); iMVP1 < cAMVPInfo1.iN; iMVP1++) |
---|
1615 | { |
---|
1616 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
1617 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
1618 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1619 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
1620 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
1621 | #endif |
---|
1622 | |
---|
1623 | if (rpcTempCU->getSlice()->isInterB()) |
---|
1624 | rpcTempCU->setInterDirSubParts( 3, 0, 0, uhDepth ); |
---|
1625 | |
---|
1626 | rpcTempCU->setMVPIdxSubParts( iMVP0, REF_PIC_LIST_0, 0, 0, uhDepth ); |
---|
1627 | rpcTempCU->setMVPIdxSubParts( iMVP1, REF_PIC_LIST_1, 0, 0, uhDepth ); |
---|
1628 | |
---|
1629 | rpcTempCU->setMVPNumSubParts( cAMVPInfo0.iN, REF_PIC_LIST_0, 0, 0, uhDepth ); |
---|
1630 | rpcTempCU->setMVPNumSubParts( cAMVPInfo1.iN, REF_PIC_LIST_1, 0, 0, uhDepth ); |
---|
1631 | |
---|
1632 | xCopyAMVPInfo(&cAMVPInfo0, rpcTempCU->getCUMvField(REF_PIC_LIST_0)->getAMVPInfo()); |
---|
1633 | xCopyAMVPInfo(&cAMVPInfo1, rpcTempCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()); |
---|
1634 | xCheckRDCostSkip ( rpcBestCU, rpcTempCU, true ); rpcTempCU->initEstData(); |
---|
1635 | } |
---|
1636 | } |
---|
1637 | } |
---|
1638 | |
---|
1639 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
1640 | { |
---|
1641 | pDst->iN = pSrc->iN; |
---|
1642 | for (Int i = 0; i < pSrc->iN; i++) |
---|
1643 | { |
---|
1644 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
1645 | } |
---|
1646 | } |
---|
1647 | |
---|
1648 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsZorderIdx, UInt uiDepth) |
---|
1649 | { |
---|
1650 | m_ppcRecoYuvBest[uiDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsZorderIdx ); |
---|
1651 | } |
---|
1652 | |
---|
1653 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
1654 | { |
---|
1655 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
1656 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
1657 | } |
---|
1658 | |
---|
1659 | #if HHI_MPI |
---|
1660 | Void TEncCu::xCheckRDCostMvInheritance( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UChar uhTextureModeDepth, Bool bSkipResidual, Bool bRecursiveCall ) |
---|
1661 | { |
---|
1662 | assert( rpcTempCU->getSlice()->getSPS()->isDepth() ); |
---|
1663 | TComDataCU *pcTextureCU = rpcTempCU->getSlice()->getTexturePic()->getCU( rpcTempCU->getAddr() ); |
---|
1664 | |
---|
1665 | const UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1666 | assert( bRecursiveCall == ( uhDepth != uhTextureModeDepth ) ); |
---|
1667 | |
---|
1668 | if( uhDepth == uhTextureModeDepth ) |
---|
1669 | { |
---|
1670 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
---|
1671 | { |
---|
1672 | if( pcTextureCU->isIntra( rpcTempCU->getZorderIdxInCU() + ui ) |
---|
1673 | #if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU |
---|
1674 | || pcTextureCU->isCUSkiped( rpcTempCU->getZorderIdxInCU() + ui ) |
---|
1675 | #endif |
---|
1676 | ) |
---|
1677 | { |
---|
1678 | return; |
---|
1679 | } |
---|
1680 | } |
---|
1681 | } |
---|
1682 | |
---|
1683 | #if HHI_VSO |
---|
1684 | if( m_pcRdCost->getUseRenModel() && !bRecursiveCall) |
---|
1685 | { |
---|
1686 | UInt uiWidth = m_ppcTempCU [uhDepth]->getWidth ( 0 ); |
---|
1687 | UInt uiHeight = m_ppcTempCU [uhDepth]->getHeight( 0 ); |
---|
1688 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( 0 ); |
---|
1689 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1690 | m_pcRdCost->setRenModelData( m_ppcTempCU[uhDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1691 | } |
---|
1692 | #endif |
---|
1693 | |
---|
1694 | Bool bSplit = uhDepth < pcTextureCU->getDepth( rpcTempCU->getZorderIdxInCU() ); |
---|
1695 | if( bSplit ) |
---|
1696 | { |
---|
1697 | const UChar uhNextDepth = uhDepth+1; |
---|
1698 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
1699 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
1700 | |
---|
1701 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
1702 | { |
---|
1703 | pcSubBestPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
1704 | pcSubTempPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
1705 | |
---|
1706 | if( ( pcSubBestPartCU->getCUPelX() < pcSubBestPartCU->getSlice()->getSPS()->getWidth() ) && ( pcSubBestPartCU->getCUPelY() < pcSubBestPartCU->getSlice()->getSPS()->getHeight() ) ) |
---|
1707 | { |
---|
1708 | if( m_bUseSBACRD ) |
---|
1709 | { |
---|
1710 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
1711 | { |
---|
1712 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhDepth][CI_CURR_BEST]); |
---|
1713 | } |
---|
1714 | else |
---|
1715 | { |
---|
1716 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
1717 | } |
---|
1718 | } |
---|
1719 | |
---|
1720 | xCheckRDCostMvInheritance( pcSubBestPartCU, pcSubTempPartCU, uhTextureModeDepth, bSkipResidual, true ); |
---|
1721 | |
---|
1722 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
1723 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
1724 | } |
---|
1725 | } |
---|
1726 | |
---|
1727 | if( uhDepth == uhTextureModeDepth ) |
---|
1728 | { |
---|
1729 | xAddMVISignallingBits( rpcTempCU ); |
---|
1730 | } |
---|
1731 | |
---|
1732 | if( m_bUseSBACRD ) |
---|
1733 | { |
---|
1734 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]); |
---|
1735 | } |
---|
1736 | } |
---|
1737 | else |
---|
1738 | { |
---|
1739 | rpcTempCU->setTextureModeDepthSubParts( uhTextureModeDepth, 0, uhDepth ); |
---|
1740 | rpcTempCU->copyTextureMotionDataFrom( pcTextureCU, uhDepth, rpcTempCU->getZorderIdxInCU() ); |
---|
1741 | rpcTempCU->setPartSizeSubParts( SIZE_NxN, 0, uhDepth ); |
---|
1742 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
---|
1743 | { |
---|
1744 | assert( rpcTempCU->getInterDir( ui ) != 0 ); |
---|
1745 | assert( rpcTempCU->getPredictionMode( ui ) != MODE_NONE ); |
---|
1746 | } |
---|
1747 | rpcTempCU->setPredModeSubParts( bSkipResidual ? MODE_SKIP : MODE_INTER, 0, uhDepth ); |
---|
1748 | m_pcPredSearch->motionCompensation( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1749 | |
---|
1750 | // get Original YUV data from picture |
---|
1751 | m_ppcOrigYuv[uhDepth]->copyFromPicYuv( rpcBestCU->getPic()->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
1752 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth], bSkipResidual ); |
---|
1753 | |
---|
1754 | if( uhDepth == uhTextureModeDepth ) |
---|
1755 | { |
---|
1756 | xAddMVISignallingBits( rpcTempCU ); |
---|
1757 | } |
---|
1758 | } |
---|
1759 | |
---|
1760 | #if HHI_VSO |
---|
1761 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
1762 | { |
---|
1763 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1764 | } |
---|
1765 | else |
---|
1766 | #endif |
---|
1767 | { |
---|
1768 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1769 | } |
---|
1770 | |
---|
1771 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
1772 | |
---|
1773 | #if HHI_VSO |
---|
1774 | if( !bSplit && bRecursiveCall && m_pcRdCost->getUseRenModel() ) |
---|
1775 | { |
---|
1776 | UInt uiWidth = rpcBestCU->getWidth ( 0 ); |
---|
1777 | UInt uiHeight = rpcBestCU->getHeight( 0 ); |
---|
1778 | Pel* piSrc = m_ppcRecoYuvBest[uhDepth]->getLumaAddr( 0 ); |
---|
1779 | UInt uiSrcStride = m_ppcRecoYuvBest[uhDepth]->getStride(); |
---|
1780 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1781 | } |
---|
1782 | #endif |
---|
1783 | } |
---|
1784 | |
---|
1785 | Void TEncCu::xAddMVISignallingBits( TComDataCU* pcCU ) |
---|
1786 | { |
---|
1787 | const UChar uhDepth = pcCU->getTextureModeDepth( 0 ); |
---|
1788 | m_pcEntropyCoder->resetBits(); |
---|
1789 | xSaveDepthWidthHeight( pcCU ); |
---|
1790 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uhDepth, g_uiMaxCUHeight>>uhDepth, 0, uhDepth ); |
---|
1791 | pcCU->setDepthSubParts( uhDepth, 0 ); |
---|
1792 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
1793 | pcCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); |
---|
1794 | pcCU->setMergeIndexSubParts( 0, 0, 0, uhDepth ); |
---|
1795 | |
---|
1796 | { |
---|
1797 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
1798 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
1799 | UInt uiNeighbourCandIdx[MRG_MAX_NUM_CANDS]; //MVs with same idx => same cand |
---|
1800 | |
---|
1801 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS; ++ui ) |
---|
1802 | { |
---|
1803 | uhInterDirNeighbours[ui] = 0; |
---|
1804 | uiNeighbourCandIdx[ui] = 0; |
---|
1805 | } |
---|
1806 | pcCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours,uhInterDirNeighbours, uiNeighbourCandIdx ); |
---|
1807 | for( UInt uiMergeCand = 0; uiMergeCand < MRG_MAX_NUM_CANDS; uiMergeCand++ ) |
---|
1808 | { |
---|
1809 | pcCU->setNeighbourCandIdxSubParts( uiMergeCand, uiNeighbourCandIdx[uiMergeCand], 0, 0,uhDepth ); |
---|
1810 | } |
---|
1811 | } |
---|
1812 | |
---|
1813 | // check for skip mode |
---|
1814 | { |
---|
1815 | Bool bAllZero = true; |
---|
1816 | for( UInt ui = 0; ui < pcCU->getTotalNumPart(); ui++ ) |
---|
1817 | { |
---|
1818 | if( pcCU->getCbf( ui, TEXT_LUMA ) || pcCU->getCbf( ui, TEXT_CHROMA_U ) || pcCU->getCbf( ui, TEXT_CHROMA_V ) ) |
---|
1819 | { |
---|
1820 | bAllZero = false; |
---|
1821 | break; |
---|
1822 | } |
---|
1823 | } |
---|
1824 | if( bAllZero ) |
---|
1825 | pcCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
1826 | } |
---|
1827 | |
---|
1828 | |
---|
1829 | m_pcEntropyCoder->encodeSplitFlag( pcCU, 0, uhDepth, true ); |
---|
1830 | m_pcEntropyCoder->encodeSkipFlag( pcCU, 0, true ); |
---|
1831 | |
---|
1832 | if( pcCU->isSkipped( 0 ) ) |
---|
1833 | { |
---|
1834 | #if HHI_MRG_SKIP |
---|
1835 | m_pcEntropyCoder->encodeMergeIndex( pcCU, 0, 0, true ); |
---|
1836 | #else |
---|
1837 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) //if ( ref. frame list0 has at least 1 entry ) |
---|
1838 | { |
---|
1839 | m_pcEntropyCoder->encodeMVPIdx( pcCU, 0, REF_PIC_LIST_0, true ); |
---|
1840 | } |
---|
1841 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) //if ( ref. frame list1 has at least 1 entry ) |
---|
1842 | { |
---|
1843 | m_pcEntropyCoder->encodeMVPIdx( pcCU, 0, REF_PIC_LIST_1, true ); |
---|
1844 | } |
---|
1845 | #endif |
---|
1846 | } |
---|
1847 | else |
---|
1848 | { |
---|
1849 | m_pcEntropyCoder->encodePredMode( pcCU, 0, true ); |
---|
1850 | m_pcEntropyCoder->encodePartSize( pcCU, 0, uhDepth, true ); |
---|
1851 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1852 | m_pcEntropyCoder->encodePredInfo( pcCU, 0, true ); |
---|
1853 | } |
---|
1854 | xRestoreDepthWidthHeight( pcCU ); |
---|
1855 | |
---|
1856 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1857 | } |
---|
1858 | |
---|
1859 | Void TEncCu::xSaveDepthWidthHeight( TComDataCU* pcCU ) |
---|
1860 | { |
---|
1861 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
---|
1862 | memcpy( m_puhDepthSaved, pcCU->getDepth(), iSizeInUchar ); |
---|
1863 | memcpy( m_puhWidthSaved, pcCU->getWidth(), iSizeInUchar ); |
---|
1864 | memcpy( m_puhHeightSaved, pcCU->getHeight(), iSizeInUchar ); |
---|
1865 | } |
---|
1866 | |
---|
1867 | Void TEncCu::xRestoreDepthWidthHeight( TComDataCU* pcCU ) |
---|
1868 | { |
---|
1869 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
---|
1870 | memcpy( pcCU->getDepth(), m_puhDepthSaved, iSizeInUchar ); |
---|
1871 | memcpy( pcCU->getWidth(), m_puhWidthSaved, iSizeInUchar ); |
---|
1872 | memcpy( pcCU->getHeight(), m_puhHeightSaved, iSizeInUchar ); |
---|
1873 | } |
---|
1874 | #endif |
---|