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-2016, ITU/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 ITU/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 | /** \file TEncCu.cpp |
---|
35 | \brief Coding Unit (CU) encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include <stdio.h> |
---|
39 | #include "TEncTop.h" |
---|
40 | #include "TEncCu.h" |
---|
41 | #include "TEncAnalyze.h" |
---|
42 | #include "TLibCommon/Debug.h" |
---|
43 | |
---|
44 | #include <cmath> |
---|
45 | #include <algorithm> |
---|
46 | using namespace std; |
---|
47 | |
---|
48 | |
---|
49 | //! \ingroup TLibEncoder |
---|
50 | //! \{ |
---|
51 | |
---|
52 | // ==================================================================================================================== |
---|
53 | // Constructor / destructor / create / destroy |
---|
54 | // ==================================================================================================================== |
---|
55 | |
---|
56 | /** |
---|
57 | \param uhTotalDepth total number of allowable depth |
---|
58 | \param uiMaxWidth largest CU width |
---|
59 | \param uiMaxHeight largest CU height |
---|
60 | \param chromaFormat chroma format |
---|
61 | */ |
---|
62 | Void TEncCu::create(UChar uhTotalDepth, UInt uiMaxWidth, UInt uiMaxHeight, ChromaFormat chromaFormat) |
---|
63 | { |
---|
64 | Int i; |
---|
65 | |
---|
66 | m_uhTotalDepth = uhTotalDepth + 1; |
---|
67 | m_ppcBestCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
68 | m_ppcTempCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
69 | |
---|
70 | #if NH_3D_ARP |
---|
71 | m_ppcWeightedTempCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
72 | #endif |
---|
73 | |
---|
74 | m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
75 | m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
76 | m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
77 | m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
78 | m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
79 | m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
80 | m_ppcOrigYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
81 | #if NH_3D_DBBP |
---|
82 | m_ppcOrigYuvDBBP = new TComYuv*[m_uhTotalDepth-1]; |
---|
83 | #endif |
---|
84 | |
---|
85 | UInt uiNumPartitions; |
---|
86 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
87 | { |
---|
88 | uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 ); |
---|
89 | UInt uiWidth = uiMaxWidth >> i; |
---|
90 | UInt uiHeight = uiMaxHeight >> i; |
---|
91 | |
---|
92 | m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( chromaFormat, uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
93 | m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( chromaFormat, uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
94 | #if NH_3D_ARP |
---|
95 | m_ppcWeightedTempCU[i] = new TComDataCU; m_ppcWeightedTempCU[i]->create( chromaFormat, uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
96 | #endif |
---|
97 | |
---|
98 | m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
99 | m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
100 | m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
101 | |
---|
102 | m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
103 | m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
104 | m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
105 | |
---|
106 | m_ppcOrigYuv [i] = new TComYuv; m_ppcOrigYuv [i]->create(uiWidth, uiHeight, chromaFormat); |
---|
107 | #if NH_3D_DBBP |
---|
108 | m_ppcOrigYuvDBBP[i] = new TComYuv; m_ppcOrigYuvDBBP[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
109 | #endif |
---|
110 | |
---|
111 | } |
---|
112 | |
---|
113 | m_bEncodeDQP = false; |
---|
114 | |
---|
115 | #if KWU_RC_MADPRED_E0227 |
---|
116 | m_LCUPredictionSAD = 0; |
---|
117 | m_addSADDepth = 0; |
---|
118 | m_temporalSAD = 0; |
---|
119 | m_spatialSAD = 0; |
---|
120 | #endif |
---|
121 | |
---|
122 | m_stillToCodeChromaQpOffsetFlag = false; |
---|
123 | m_cuChromaQpOffsetIdxPlus1 = 0; |
---|
124 | m_bFastDeltaQP = false; |
---|
125 | |
---|
126 | // initialize partition order. |
---|
127 | UInt* piTmp = &g_auiZscanToRaster[0]; |
---|
128 | initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp); |
---|
129 | initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
130 | |
---|
131 | // initialize conversion matrix from partition index to pel |
---|
132 | initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
133 | } |
---|
134 | |
---|
135 | Void TEncCu::destroy() |
---|
136 | { |
---|
137 | Int i; |
---|
138 | |
---|
139 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
140 | { |
---|
141 | if(m_ppcBestCU[i]) |
---|
142 | { |
---|
143 | m_ppcBestCU[i]->destroy(); delete m_ppcBestCU[i]; m_ppcBestCU[i] = NULL; |
---|
144 | } |
---|
145 | if(m_ppcTempCU[i]) |
---|
146 | { |
---|
147 | m_ppcTempCU[i]->destroy(); delete m_ppcTempCU[i]; m_ppcTempCU[i] = NULL; |
---|
148 | } |
---|
149 | #if NH_3D_ARP |
---|
150 | if(m_ppcWeightedTempCU[i]) |
---|
151 | { |
---|
152 | m_ppcWeightedTempCU[i]->destroy(); delete m_ppcWeightedTempCU[i]; m_ppcWeightedTempCU[i] = NULL; |
---|
153 | } |
---|
154 | #endif |
---|
155 | if(m_ppcPredYuvBest[i]) |
---|
156 | { |
---|
157 | m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL; |
---|
158 | } |
---|
159 | if(m_ppcResiYuvBest[i]) |
---|
160 | { |
---|
161 | m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL; |
---|
162 | } |
---|
163 | if(m_ppcRecoYuvBest[i]) |
---|
164 | { |
---|
165 | m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL; |
---|
166 | } |
---|
167 | if(m_ppcPredYuvTemp[i]) |
---|
168 | { |
---|
169 | m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL; |
---|
170 | } |
---|
171 | if(m_ppcResiYuvTemp[i]) |
---|
172 | { |
---|
173 | m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL; |
---|
174 | } |
---|
175 | if(m_ppcRecoYuvTemp[i]) |
---|
176 | { |
---|
177 | m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL; |
---|
178 | } |
---|
179 | if(m_ppcOrigYuv[i]) |
---|
180 | { |
---|
181 | m_ppcOrigYuv[i]->destroy(); delete m_ppcOrigYuv[i]; m_ppcOrigYuv[i] = NULL; |
---|
182 | } |
---|
183 | #if NH_3D_DBBP |
---|
184 | if(m_ppcOrigYuvDBBP[i]) |
---|
185 | { |
---|
186 | m_ppcOrigYuvDBBP[i]->destroy(); delete m_ppcOrigYuvDBBP[i]; m_ppcOrigYuvDBBP[i] = NULL; |
---|
187 | } |
---|
188 | #endif |
---|
189 | } |
---|
190 | if(m_ppcBestCU) |
---|
191 | { |
---|
192 | delete [] m_ppcBestCU; |
---|
193 | m_ppcBestCU = NULL; |
---|
194 | } |
---|
195 | if(m_ppcTempCU) |
---|
196 | { |
---|
197 | delete [] m_ppcTempCU; |
---|
198 | m_ppcTempCU = NULL; |
---|
199 | } |
---|
200 | |
---|
201 | #if NH_3D_ARP |
---|
202 | if(m_ppcWeightedTempCU) |
---|
203 | { |
---|
204 | delete [] m_ppcWeightedTempCU; |
---|
205 | m_ppcWeightedTempCU = NULL; |
---|
206 | } |
---|
207 | #endif |
---|
208 | if(m_ppcPredYuvBest) |
---|
209 | { |
---|
210 | delete [] m_ppcPredYuvBest; |
---|
211 | m_ppcPredYuvBest = NULL; |
---|
212 | } |
---|
213 | if(m_ppcResiYuvBest) |
---|
214 | { |
---|
215 | delete [] m_ppcResiYuvBest; |
---|
216 | m_ppcResiYuvBest = NULL; |
---|
217 | } |
---|
218 | if(m_ppcRecoYuvBest) |
---|
219 | { |
---|
220 | delete [] m_ppcRecoYuvBest; |
---|
221 | m_ppcRecoYuvBest = NULL; |
---|
222 | } |
---|
223 | if(m_ppcPredYuvTemp) |
---|
224 | { |
---|
225 | delete [] m_ppcPredYuvTemp; |
---|
226 | m_ppcPredYuvTemp = NULL; |
---|
227 | } |
---|
228 | if(m_ppcResiYuvTemp) |
---|
229 | { |
---|
230 | delete [] m_ppcResiYuvTemp; |
---|
231 | m_ppcResiYuvTemp = NULL; |
---|
232 | } |
---|
233 | if(m_ppcRecoYuvTemp) |
---|
234 | { |
---|
235 | delete [] m_ppcRecoYuvTemp; |
---|
236 | m_ppcRecoYuvTemp = NULL; |
---|
237 | } |
---|
238 | if(m_ppcOrigYuv) |
---|
239 | { |
---|
240 | delete [] m_ppcOrigYuv; |
---|
241 | m_ppcOrigYuv = NULL; |
---|
242 | } |
---|
243 | #if NH_3D_DBBP |
---|
244 | if(m_ppcOrigYuvDBBP) |
---|
245 | { |
---|
246 | delete [] m_ppcOrigYuvDBBP; |
---|
247 | m_ppcOrigYuvDBBP = NULL; |
---|
248 | } |
---|
249 | #endif |
---|
250 | } |
---|
251 | |
---|
252 | /** \param pcEncTop pointer of encoder class |
---|
253 | */ |
---|
254 | Void TEncCu::init( TEncTop* pcEncTop ) |
---|
255 | { |
---|
256 | m_pcEncCfg = pcEncTop; |
---|
257 | m_pcPredSearch = pcEncTop->getPredSearch(); |
---|
258 | m_pcTrQuant = pcEncTop->getTrQuant(); |
---|
259 | m_pcRdCost = pcEncTop->getRdCost(); |
---|
260 | |
---|
261 | m_pcEntropyCoder = pcEncTop->getEntropyCoder(); |
---|
262 | m_pcBinCABAC = pcEncTop->getBinCABAC(); |
---|
263 | |
---|
264 | m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder(); |
---|
265 | m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder(); |
---|
266 | |
---|
267 | m_pcRateCtrl = pcEncTop->getRateCtrl(); |
---|
268 | } |
---|
269 | |
---|
270 | // ==================================================================================================================== |
---|
271 | // Public member functions |
---|
272 | // ==================================================================================================================== |
---|
273 | |
---|
274 | /** |
---|
275 | \param pCtu pointer of CU data class |
---|
276 | */ |
---|
277 | Void TEncCu::compressCtu( TComDataCU* pCtu ) |
---|
278 | { |
---|
279 | // initialize CU data |
---|
280 | m_ppcBestCU[0]->initCtu( pCtu->getPic(), pCtu->getCtuRsAddr() ); |
---|
281 | m_ppcTempCU[0]->initCtu( pCtu->getPic(), pCtu->getCtuRsAddr() ); |
---|
282 | |
---|
283 | #if NH_3D_ARP |
---|
284 | m_ppcWeightedTempCU[0]->initCtu( pCtu->getPic(), pCtu->getCtuRsAddr() ); |
---|
285 | #endif |
---|
286 | |
---|
287 | #if KWU_RC_MADPRED_E0227 |
---|
288 | m_LCUPredictionSAD = 0; |
---|
289 | m_addSADDepth = 0; |
---|
290 | m_temporalSAD = 0; |
---|
291 | m_spatialSAD = 0; |
---|
292 | #endif |
---|
293 | |
---|
294 | // analysis of CU |
---|
295 | DEBUG_STRING_NEW(sDebug) |
---|
296 | |
---|
297 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
298 | DEBUG_STRING_OUTPUT(std::cout, sDebug) |
---|
299 | |
---|
300 | #if ADAPTIVE_QP_SELECTION |
---|
301 | if( m_pcEncCfg->getUseAdaptQpSelect() ) |
---|
302 | { |
---|
303 | if(pCtu->getSlice()->getSliceType()!=I_SLICE) //IIII |
---|
304 | { |
---|
305 | xCtuCollectARLStats( pCtu ); |
---|
306 | } |
---|
307 | } |
---|
308 | #endif |
---|
309 | } |
---|
310 | /** \param pCtu pointer of CU data class |
---|
311 | */ |
---|
312 | Void TEncCu::encodeCtu ( TComDataCU* pCtu ) |
---|
313 | { |
---|
314 | if ( pCtu->getSlice()->getPPS()->getUseDQP() ) |
---|
315 | { |
---|
316 | setdQPFlag(true); |
---|
317 | } |
---|
318 | |
---|
319 | if ( pCtu->getSlice()->getUseChromaQpAdj() ) |
---|
320 | { |
---|
321 | setCodeChromaQpAdjFlag(true); |
---|
322 | } |
---|
323 | |
---|
324 | // Encode CU data |
---|
325 | xEncodeCU( pCtu, 0, 0 ); |
---|
326 | } |
---|
327 | |
---|
328 | // ==================================================================================================================== |
---|
329 | // Protected member functions |
---|
330 | // ==================================================================================================================== |
---|
331 | //! Derive small set of test modes for AMP encoder speed-up |
---|
332 | #if AMP_ENC_SPEEDUP |
---|
333 | #if AMP_MRG |
---|
334 | Void TEncCu::deriveTestModeAMP (TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver) |
---|
335 | #else |
---|
336 | Void TEncCu::deriveTestModeAMP (TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver) |
---|
337 | #endif |
---|
338 | { |
---|
339 | if ( pcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
340 | { |
---|
341 | bTestAMP_Hor = true; |
---|
342 | } |
---|
343 | else if ( pcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
344 | { |
---|
345 | bTestAMP_Ver = true; |
---|
346 | } |
---|
347 | else if ( pcBestCU->getPartitionSize(0) == SIZE_2Nx2N && pcBestCU->getMergeFlag(0) == false && pcBestCU->isSkipped(0) == false ) |
---|
348 | { |
---|
349 | bTestAMP_Hor = true; |
---|
350 | bTestAMP_Ver = true; |
---|
351 | } |
---|
352 | |
---|
353 | #if AMP_MRG |
---|
354 | //! Utilizing the partition size of parent PU |
---|
355 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
356 | { |
---|
357 | bTestMergeAMP_Hor = true; |
---|
358 | bTestMergeAMP_Ver = true; |
---|
359 | } |
---|
360 | |
---|
361 | if ( eParentPartSize == NUMBER_OF_PART_SIZES ) //! if parent is intra |
---|
362 | { |
---|
363 | if ( pcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
364 | { |
---|
365 | bTestMergeAMP_Hor = true; |
---|
366 | } |
---|
367 | else if ( pcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
368 | { |
---|
369 | bTestMergeAMP_Ver = true; |
---|
370 | } |
---|
371 | } |
---|
372 | |
---|
373 | if ( pcBestCU->getPartitionSize(0) == SIZE_2Nx2N && pcBestCU->isSkipped(0) == false ) |
---|
374 | { |
---|
375 | bTestMergeAMP_Hor = true; |
---|
376 | bTestMergeAMP_Ver = true; |
---|
377 | } |
---|
378 | |
---|
379 | if ( pcBestCU->getWidth(0) == 64 ) |
---|
380 | { |
---|
381 | bTestAMP_Hor = false; |
---|
382 | bTestAMP_Ver = false; |
---|
383 | } |
---|
384 | #else |
---|
385 | //! Utilizing the partition size of parent PU |
---|
386 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
387 | { |
---|
388 | bTestAMP_Hor = true; |
---|
389 | bTestAMP_Ver = true; |
---|
390 | } |
---|
391 | |
---|
392 | if ( eParentPartSize == SIZE_2Nx2N ) |
---|
393 | { |
---|
394 | bTestAMP_Hor = false; |
---|
395 | bTestAMP_Ver = false; |
---|
396 | } |
---|
397 | #endif |
---|
398 | } |
---|
399 | #endif |
---|
400 | |
---|
401 | |
---|
402 | // ==================================================================================================================== |
---|
403 | // Protected member functions |
---|
404 | // ==================================================================================================================== |
---|
405 | /** Compress a CU block recursively with enabling sub-CTU-level delta QP |
---|
406 | * - for loop of QP value to compress the current CU with all possible QP |
---|
407 | */ |
---|
408 | #if AMP_ENC_SPEEDUP |
---|
409 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, const UInt uiDepth DEBUG_STRING_FN_DECLARE(sDebug_), PartSize eParentPartSize ) |
---|
410 | #else |
---|
411 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, const UInt uiDepth ) |
---|
412 | #endif |
---|
413 | { |
---|
414 | TComPic* pcPic = rpcBestCU->getPic(); |
---|
415 | DEBUG_STRING_NEW(sDebug) |
---|
416 | const TComPPS &pps=*(rpcTempCU->getSlice()->getPPS()); |
---|
417 | const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS()); |
---|
418 | |
---|
419 | // These are only used if getFastDeltaQp() is true |
---|
420 | const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>sps.getLog2DiffMaxMinCodingBlockSize(), sps.getMaxCUHeight(), 32u); |
---|
421 | |
---|
422 | #if NH_3D_QTL |
---|
423 | #if NH_3D_QTLPC |
---|
424 | Bool bLimQtPredFalg = pcPic->getSlice(0)->getQtPredFlag(); |
---|
425 | #else |
---|
426 | Bool bLimQtPredFalg = false; |
---|
427 | #endif |
---|
428 | TComPic *pcTexture = rpcBestCU->getSlice()->getTexturePic(); |
---|
429 | |
---|
430 | Bool depthMapDetect = (pcTexture != NULL); |
---|
431 | Bool bIntraSliceDetect = (rpcBestCU->getSlice()->getSliceType() == I_SLICE); |
---|
432 | |
---|
433 | Bool rapPic = (rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA); |
---|
434 | |
---|
435 | Bool bTry2NxN = true; |
---|
436 | Bool bTryNx2N = true; |
---|
437 | #endif |
---|
438 | |
---|
439 | // get Original YUV data from picture |
---|
440 | m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getCtuRsAddr(), rpcBestCU->getZorderIdxInCtu() ); |
---|
441 | |
---|
442 | #if NH_3D_QTL |
---|
443 | Bool bTrySplit = true; |
---|
444 | Bool bTrySplitDQP = true; |
---|
445 | #endif |
---|
446 | // variable for Cbf fast mode PU decision |
---|
447 | Bool doNotBlockPu = true; |
---|
448 | Bool earlyDetectionSkipMode = false; |
---|
449 | |
---|
450 | #if NH_3D_NBDV |
---|
451 | DisInfo DvInfo; |
---|
452 | DvInfo.m_acNBDV.setZero(); |
---|
453 | DvInfo.m_aVIdxCan = 0; |
---|
454 | #if NH_3D_NBDV_REF |
---|
455 | DvInfo.m_acDoNBDV.setZero(); |
---|
456 | #endif |
---|
457 | #endif |
---|
458 | const UInt uiLPelX = rpcBestCU->getCUPelX(); |
---|
459 | const UInt uiRPelX = uiLPelX + rpcBestCU->getWidth(0) - 1; |
---|
460 | const UInt uiTPelY = rpcBestCU->getCUPelY(); |
---|
461 | const UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1; |
---|
462 | const UInt uiWidth = rpcBestCU->getWidth(0); |
---|
463 | |
---|
464 | #if NH_MV_ENC_DEC_TRAC |
---|
465 | #if ENC_DEC_TRACE |
---|
466 | stopAtPos ( rpcBestCU->getSlice()->getPOC(), |
---|
467 | rpcBestCU->getSlice()->getLayerId(), |
---|
468 | rpcBestCU->getCUPelX(), |
---|
469 | rpcBestCU->getCUPelY(), |
---|
470 | rpcBestCU->getWidth(0), |
---|
471 | rpcBestCU->getHeight(0) ); |
---|
472 | #endif |
---|
473 | #endif |
---|
474 | |
---|
475 | Int iBaseQP = xComputeQP( rpcBestCU, uiDepth ); |
---|
476 | Int iMinQP; |
---|
477 | Int iMaxQP; |
---|
478 | Bool isAddLowestQP = false; |
---|
479 | |
---|
480 | const UInt numberValidComponents = rpcBestCU->getPic()->getNumberValidComponents(); |
---|
481 | |
---|
482 | if( uiDepth <= pps.getMaxCuDQPDepth() ) |
---|
483 | { |
---|
484 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
485 | iMinQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP ); |
---|
486 | iMaxQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP ); |
---|
487 | } |
---|
488 | else |
---|
489 | { |
---|
490 | iMinQP = rpcTempCU->getQP(0); |
---|
491 | iMaxQP = rpcTempCU->getQP(0); |
---|
492 | } |
---|
493 | |
---|
494 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
495 | { |
---|
496 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
497 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
498 | } |
---|
499 | |
---|
500 | // transquant-bypass (TQB) processing loop variable initialisation --- |
---|
501 | |
---|
502 | const Int lowestQP = iMinQP; // For TQB, use this QP which is the lowest non TQB QP tested (rather than QP'=0) - that way delta QPs are smaller, and TQB can be tested at all CU levels. |
---|
503 | |
---|
504 | if ( (pps.getTransquantBypassEnableFlag()) ) |
---|
505 | { |
---|
506 | isAddLowestQP = true; // mark that the first iteration is to cost TQB mode. |
---|
507 | iMinQP = iMinQP - 1; // increase loop variable range by 1, to allow testing of TQB mode along with other QPs |
---|
508 | if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) |
---|
509 | { |
---|
510 | iMaxQP = iMinQP; |
---|
511 | } |
---|
512 | } |
---|
513 | |
---|
514 | #if NH_3D_IC |
---|
515 | Bool bICEnabled = rpcTempCU->getSlice()->getViewIndex() && ( rpcTempCU->getSlice()->getSliceType() == P_SLICE || rpcTempCU->getSlice()->getSliceType() == B_SLICE ) && !rpcTempCU->getSlice()->getIsDepth(); |
---|
516 | bICEnabled = bICEnabled && rpcTempCU->getSlice()->getApplyIC(); |
---|
517 | #endif |
---|
518 | |
---|
519 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
520 | |
---|
521 | const Bool bBoundary = !( uiRPelX < sps.getPicWidthInLumaSamples() && uiBPelY < sps.getPicHeightInLumaSamples() ); |
---|
522 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
523 | Bool bIVFMerge = false; |
---|
524 | Int iIVFMaxD = 0; |
---|
525 | Bool bFMD = false; |
---|
526 | Bool bSubBranch = true; |
---|
527 | #endif |
---|
528 | if ( !bBoundary ) |
---|
529 | { |
---|
530 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
531 | { |
---|
532 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); |
---|
533 | |
---|
534 | if (bIsLosslessMode) |
---|
535 | { |
---|
536 | iQP = lowestQP; |
---|
537 | } |
---|
538 | |
---|
539 | #if NH_3D_QTL |
---|
540 | bTrySplit = true; |
---|
541 | #endif |
---|
542 | |
---|
543 | m_cuChromaQpOffsetIdxPlus1 = 0; |
---|
544 | if (pcSlice->getUseChromaQpAdj()) |
---|
545 | { |
---|
546 | /* Pre-estimation of chroma QP based on input block activity may be performed |
---|
547 | * here, using for example m_ppcOrigYuv[uiDepth] */ |
---|
548 | /* To exercise the current code, the index used for adjustment is based on |
---|
549 | * block position |
---|
550 | */ |
---|
551 | Int lgMinCuSize = sps.getLog2MinCodingBlockSize() + |
---|
552 | std::max<Int>(0, sps.getLog2DiffMaxMinCodingBlockSize()-Int(pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth())); |
---|
553 | m_cuChromaQpOffsetIdxPlus1 = ((uiLPelX >> lgMinCuSize) + (uiTPelY >> lgMinCuSize)) % (pps.getPpsRangeExtension().getChromaQpOffsetListLen() + 1); |
---|
554 | } |
---|
555 | |
---|
556 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
557 | #if NH_3D_QTL |
---|
558 | //logic for setting bTrySplit using the partition information that is stored of the texture colocated CU |
---|
559 | #if H_3D_FCO |
---|
560 | if(depthMapDetect && !bIntraSliceDetect && !rapPic && ( m_pcEncCfg->getUseQTL() || bLimQtPredFalg ) && pcTexture->getReconMark()) |
---|
561 | #else |
---|
562 | if(depthMapDetect && !bIntraSliceDetect && !rapPic && ( m_pcEncCfg->getUseQTL() || bLimQtPredFalg )) |
---|
563 | #endif |
---|
564 | { |
---|
565 | TComDataCU* pcTextureCU = pcTexture->getCtu( rpcBestCU->getCtuRsAddr() ); //Corresponding texture LCU |
---|
566 | UInt uiCUIdx = rpcBestCU->getZorderIdxInCtu(); |
---|
567 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); //Depth cannot be more partitioned than the texture. |
---|
568 | if (pcTextureCU->getDepth(uiCUIdx) > uiDepth || pcTextureCU->getPartitionSize(uiCUIdx) == SIZE_NxN) //Texture was split. |
---|
569 | { |
---|
570 | bTrySplit = true; |
---|
571 | bTryNx2N = true; |
---|
572 | bTry2NxN = true; |
---|
573 | } |
---|
574 | else |
---|
575 | { |
---|
576 | bTrySplit = false; |
---|
577 | bTryNx2N = false; |
---|
578 | bTry2NxN = false; |
---|
579 | if( pcTextureCU->getDepth(uiCUIdx) == uiDepth && pcTextureCU->getPartitionSize(uiCUIdx) != SIZE_2Nx2N) |
---|
580 | { |
---|
581 | if(pcTextureCU->getPartitionSize(uiCUIdx)==SIZE_2NxN || pcTextureCU->getPartitionSize(uiCUIdx)==SIZE_2NxnU|| pcTextureCU->getPartitionSize(uiCUIdx)==SIZE_2NxnD) |
---|
582 | { |
---|
583 | bTry2NxN = true; |
---|
584 | } |
---|
585 | else |
---|
586 | { |
---|
587 | bTryNx2N = true; |
---|
588 | } |
---|
589 | } |
---|
590 | } |
---|
591 | } |
---|
592 | #endif |
---|
593 | |
---|
594 | #if NH_3D_NBDV |
---|
595 | if( rpcTempCU->getSlice()->getSliceType() != I_SLICE ) |
---|
596 | { |
---|
597 | #if NH_3D_ARP && NH_3D_IV_MERGE && NH_3D_VSP |
---|
598 | if( rpcTempCU->getSlice()->getIvResPredFlag() || rpcTempCU->getSlice()->getIvMvPredFlag() || rpcTempCU->getSlice()->getViewSynthesisPredFlag() ) |
---|
599 | #else |
---|
600 | #if NH_3D_IV_MERGE && NH_3D_VSP |
---|
601 | if( rpcTempCU->getSlice()->getIvMvPredFlag() || rpcTempCU->getSlice()->getViewSynthesisPredFlag() ) |
---|
602 | #else |
---|
603 | #if NH_3D_ARP && NH_3D_VSP |
---|
604 | if( rpcTempCU->getSlice()->getIvResPredFlag() || rpcTempCU->getSlice()->getViewSynthesisPredFlag() ) |
---|
605 | #else |
---|
606 | #if NH_3D_VSP |
---|
607 | if( rpcTempCU->getSlice()->getViewSynthesisPredFlag() ) |
---|
608 | #else |
---|
609 | #if NH_3D_ARP |
---|
610 | if( rpcTempCU->getSlice()->getIvResPredFlag() ) |
---|
611 | #else |
---|
612 | #if H_3D_IV_MERGE |
---|
613 | if( rpcTempCU->getSlice()->getVPS()->getIvMvPredFlag(rpcTempCU->getSlice()->getLayerId()) ) |
---|
614 | #else |
---|
615 | #if NH_3D_DBBP |
---|
616 | if( rpcTempCU->getSlice()->getDepthBasedBlkPartFlag() ) |
---|
617 | #else |
---|
618 | if (0) |
---|
619 | #endif |
---|
620 | #endif |
---|
621 | #endif |
---|
622 | #endif |
---|
623 | #endif |
---|
624 | #endif |
---|
625 | #endif |
---|
626 | { |
---|
627 | PartSize ePartTemp = rpcTempCU->getPartitionSize(0); |
---|
628 | rpcTempCU->setPartSizeSubParts(SIZE_2Nx2N, 0, uiDepth); |
---|
629 | #if NH_3D_IV_MERGE |
---|
630 | if (rpcTempCU->getSlice()->getIsDepth() ) |
---|
631 | { |
---|
632 | rpcTempCU->getDispforDepth(0, 0, &DvInfo); |
---|
633 | } |
---|
634 | else |
---|
635 | { |
---|
636 | #endif |
---|
637 | #if NH_3D_NBDV_REF |
---|
638 | if( rpcTempCU->getSlice()->getDepthRefinementFlag() ) |
---|
639 | { |
---|
640 | rpcTempCU->getDisMvpCandNBDV(&DvInfo, true); |
---|
641 | } |
---|
642 | else |
---|
643 | #endif |
---|
644 | { |
---|
645 | rpcTempCU->getDisMvpCandNBDV(&DvInfo); |
---|
646 | } |
---|
647 | #if NH_3D_IV_MERGE |
---|
648 | } |
---|
649 | #endif |
---|
650 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
651 | rpcBestCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
652 | rpcTempCU->setPartSizeSubParts( ePartTemp, 0, uiDepth ); |
---|
653 | } |
---|
654 | } |
---|
655 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
656 | if(rpcTempCU->getSlice()->getViewIndex() && !rpcTempCU->getSlice()->getIsDepth() && rpcTempCU->getSlice()->getDefaultRefViewIdxAvailableFlag() ) |
---|
657 | { |
---|
658 | PartSize ePartTemp = rpcTempCU->getPartitionSize(0); |
---|
659 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
660 | rpcTempCU->getIVNStatus( 0, &DvInfo, bIVFMerge, iIVFMaxD); |
---|
661 | rpcTempCU->setPartSizeSubParts( ePartTemp, 0, uiDepth ); |
---|
662 | } |
---|
663 | #endif |
---|
664 | #endif |
---|
665 | // do inter modes, SKIP and 2Nx2N |
---|
666 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
667 | { |
---|
668 | #if NH_3D_IC |
---|
669 | for( UInt uiICId = 0; uiICId < ( bICEnabled ? 2 : 1 ); uiICId++ ) |
---|
670 | { |
---|
671 | Bool bICFlag = uiICId ? true : false; |
---|
672 | #endif |
---|
673 | // 2Nx2N |
---|
674 | if(m_pcEncCfg->getUseEarlySkipDetection()) |
---|
675 | { |
---|
676 | #if NH_3D_IC |
---|
677 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
---|
678 | #endif |
---|
679 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
680 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD ); rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N |
---|
681 | #else |
---|
682 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
683 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N |
---|
684 | #endif |
---|
685 | #if NH_3D_VSP || NH_3D_DBBP |
---|
686 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
687 | #endif |
---|
688 | } |
---|
689 | // SKIP |
---|
690 | #if NH_3D_IC |
---|
691 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
---|
692 | #endif |
---|
693 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU DEBUG_STRING_PASS_INTO(sDebug), &earlyDetectionSkipMode );//by Merge for inter_2Nx2N |
---|
694 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
695 | bFMD = bIVFMerge && rpcBestCU->isSkipped(0); |
---|
696 | #endif |
---|
697 | |
---|
698 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
699 | #if NH_3D_VSP || NH_3D_DBBP |
---|
700 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
701 | #endif |
---|
702 | |
---|
703 | if(!m_pcEncCfg->getUseEarlySkipDetection()) |
---|
704 | { |
---|
705 | // 2Nx2N, NxN |
---|
706 | #if NH_3D_IC |
---|
707 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
---|
708 | #endif |
---|
709 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
710 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD ); rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
711 | #else |
---|
712 | |
---|
713 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
714 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
715 | #endif |
---|
716 | #if NH_3D_VSP || NH_3D_DBBP |
---|
717 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
718 | #endif |
---|
719 | #if NH_3D_DBBP |
---|
720 | if( rpcTempCU->getSlice()->getDepthBasedBlkPartFlag() && rpcTempCU->getSlice()->getDefaultRefViewIdxAvailableFlag() ) |
---|
721 | { |
---|
722 | xCheckRDCostInterDBBP( rpcBestCU, rpcTempCU DEBUG_STRING_PASS_INTO(sDebug), false ); |
---|
723 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
724 | #if NH_3D_VSP || NH_3D_DBBP |
---|
725 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
726 | #endif |
---|
727 | } |
---|
728 | #endif |
---|
729 | |
---|
730 | if(m_pcEncCfg->getUseCbfFastMode()) |
---|
731 | { |
---|
732 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
733 | } |
---|
734 | } |
---|
735 | #if NH_3D_IC |
---|
736 | } |
---|
737 | #endif |
---|
738 | } |
---|
739 | #if NH_3D_QTL |
---|
740 | if(depthMapDetect && !bIntraSliceDetect && !rapPic && ( m_pcEncCfg->getUseQTL() || bLimQtPredFalg )) |
---|
741 | { |
---|
742 | bTrySplitDQP = bTrySplit; |
---|
743 | } |
---|
744 | #endif |
---|
745 | |
---|
746 | if (bIsLosslessMode) // Restore loop variable if lossless mode was searched. |
---|
747 | { |
---|
748 | iQP = iMinQP; |
---|
749 | } |
---|
750 | } |
---|
751 | |
---|
752 | #if KWU_RC_MADPRED_E0227 |
---|
753 | if ( uiDepth <= m_addSADDepth ) |
---|
754 | { |
---|
755 | m_LCUPredictionSAD += m_temporalSAD; |
---|
756 | m_addSADDepth = uiDepth; |
---|
757 | } |
---|
758 | #endif |
---|
759 | #if NH_3D_ENC_DEPTH |
---|
760 | if( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) |
---|
761 | { |
---|
762 | earlyDetectionSkipMode = false; |
---|
763 | } |
---|
764 | #endif |
---|
765 | #if NH_3D_DIS |
---|
766 | rpcTempCU->initEstData( uiDepth, iMinQP, isAddLowestQP ); |
---|
767 | if( rpcBestCU->getSlice()->getDepthIntraSkipFlag() ) |
---|
768 | { |
---|
769 | xCheckRDCostDIS( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
770 | rpcTempCU->initEstData( uiDepth, iMinQP, isAddLowestQP ); |
---|
771 | } |
---|
772 | #endif |
---|
773 | if(!earlyDetectionSkipMode) |
---|
774 | { |
---|
775 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
776 | { |
---|
777 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); // If lossless, then iQP is irrelevant for subsequent modules. |
---|
778 | |
---|
779 | if (bIsLosslessMode) |
---|
780 | { |
---|
781 | iQP = lowestQP; |
---|
782 | } |
---|
783 | |
---|
784 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
785 | |
---|
786 | // do inter modes, NxN, 2NxN, and Nx2N |
---|
787 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
788 | { |
---|
789 | // 2Nx2N, NxN |
---|
790 | |
---|
791 | if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) )) |
---|
792 | { |
---|
793 | if( uiDepth == sps.getLog2DiffMaxMinCodingBlockSize() && doNotBlockPu |
---|
794 | #if NH_3D_QTL |
---|
795 | && bTrySplit |
---|
796 | #endif |
---|
797 | ) |
---|
798 | { |
---|
799 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
800 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug), bFMD ); |
---|
801 | #else |
---|
802 | |
---|
803 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
804 | #endif |
---|
805 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
806 | #if NH_3D_VSP || NH_3D_DBBP |
---|
807 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
808 | #endif |
---|
809 | |
---|
810 | } |
---|
811 | } |
---|
812 | |
---|
813 | if(doNotBlockPu |
---|
814 | #if NH_3D_QTL |
---|
815 | && bTryNx2N |
---|
816 | #endif |
---|
817 | ) |
---|
818 | { |
---|
819 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
820 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD ); |
---|
821 | #else |
---|
822 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
823 | #endif |
---|
824 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
825 | #if NH_3D_VSP || NH_3D_DBBP |
---|
826 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
827 | #endif |
---|
828 | |
---|
829 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
830 | { |
---|
831 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
832 | } |
---|
833 | } |
---|
834 | if(doNotBlockPu |
---|
835 | #if NH_3D_QTL |
---|
836 | && bTry2NxN |
---|
837 | #endif |
---|
838 | ) |
---|
839 | { |
---|
840 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
841 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN DEBUG_STRING_PASS_INTO(sDebug), bFMD ); |
---|
842 | #else |
---|
843 | |
---|
844 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
845 | #endif |
---|
846 | |
---|
847 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
848 | #if NH_3D_VSP || NH_3D_DBBP |
---|
849 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
850 | #endif |
---|
851 | |
---|
852 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN) |
---|
853 | { |
---|
854 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
855 | } |
---|
856 | } |
---|
857 | |
---|
858 | //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
---|
859 | if(sps.getUseAMP() && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) |
---|
860 | { |
---|
861 | #if AMP_ENC_SPEEDUP |
---|
862 | Bool bTestAMP_Hor = false, bTestAMP_Ver = false; |
---|
863 | |
---|
864 | #if AMP_MRG |
---|
865 | Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false; |
---|
866 | |
---|
867 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver); |
---|
868 | #else |
---|
869 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver); |
---|
870 | #endif |
---|
871 | |
---|
872 | //! Do horizontal AMP |
---|
873 | if ( bTestAMP_Hor ) |
---|
874 | { |
---|
875 | if(doNotBlockPu |
---|
876 | #if NH_3D_QTL |
---|
877 | && bTry2NxN |
---|
878 | #endif |
---|
879 | ) |
---|
880 | { |
---|
881 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
882 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug), bFMD ); |
---|
883 | #else |
---|
884 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
885 | #endif |
---|
886 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
887 | #if NH_3D_VSP || NH_3D_DBBP |
---|
888 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
889 | #endif |
---|
890 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
891 | { |
---|
892 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
893 | } |
---|
894 | } |
---|
895 | if(doNotBlockPu |
---|
896 | #if NH_3D_QTL |
---|
897 | && bTry2NxN |
---|
898 | #endif |
---|
899 | ) |
---|
900 | { |
---|
901 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
902 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug), bFMD ); |
---|
903 | #else |
---|
904 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
905 | #endif |
---|
906 | |
---|
907 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
908 | #if NH_3D_VSP || NH_3D_DBBP |
---|
909 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
910 | #endif |
---|
911 | |
---|
912 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
913 | { |
---|
914 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
915 | } |
---|
916 | } |
---|
917 | } |
---|
918 | #if AMP_MRG |
---|
919 | else if ( bTestMergeAMP_Hor ) |
---|
920 | { |
---|
921 | if(doNotBlockPu |
---|
922 | #if NH_3D_QTL |
---|
923 | && bTry2NxN |
---|
924 | #endif |
---|
925 | ) |
---|
926 | { |
---|
927 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
928 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug), bFMD, true ); |
---|
929 | #else |
---|
930 | |
---|
931 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
932 | #endif |
---|
933 | |
---|
934 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
935 | #if NH_3D_VSP || NH_3D_DBBP |
---|
936 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
937 | #endif |
---|
938 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
939 | { |
---|
940 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
941 | } |
---|
942 | } |
---|
943 | if(doNotBlockPu |
---|
944 | #if NH_3D_QTL |
---|
945 | && bTry2NxN |
---|
946 | #endif |
---|
947 | ) |
---|
948 | { |
---|
949 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
950 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug), bFMD, true ); |
---|
951 | #else |
---|
952 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
953 | #endif |
---|
954 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
955 | #if NH_3D_VSP || NH_3D_DBBP |
---|
956 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
957 | #endif |
---|
958 | |
---|
959 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
960 | { |
---|
961 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
962 | } |
---|
963 | } |
---|
964 | } |
---|
965 | #endif |
---|
966 | |
---|
967 | //! Do horizontal AMP |
---|
968 | if ( bTestAMP_Ver ) |
---|
969 | { |
---|
970 | if(doNotBlockPu |
---|
971 | #if NH_3D_QTL |
---|
972 | && bTryNx2N |
---|
973 | #endif |
---|
974 | ) |
---|
975 | { |
---|
976 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
977 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD ); |
---|
978 | #else |
---|
979 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
980 | #endif |
---|
981 | |
---|
982 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
983 | #if NH_3D_VSP || NH_3D_DBBP |
---|
984 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
985 | #endif |
---|
986 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
987 | { |
---|
988 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
989 | } |
---|
990 | } |
---|
991 | if(doNotBlockPu |
---|
992 | #if NH_3D_QTL |
---|
993 | && bTryNx2N |
---|
994 | #endif |
---|
995 | ) |
---|
996 | { |
---|
997 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
998 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD ); |
---|
999 | #else |
---|
1000 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
1001 | #endif |
---|
1002 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
1003 | #if NH_3D_VSP || NH_3D_DBBP |
---|
1004 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
1005 | #endif |
---|
1006 | } |
---|
1007 | } |
---|
1008 | #if AMP_MRG |
---|
1009 | else if ( bTestMergeAMP_Ver ) |
---|
1010 | { |
---|
1011 | if(doNotBlockPu |
---|
1012 | #if NH_3D_QTL |
---|
1013 | && bTryNx2N |
---|
1014 | #endif |
---|
1015 | ) |
---|
1016 | { |
---|
1017 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
1018 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD, true ); |
---|
1019 | #else |
---|
1020 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
1021 | #endif |
---|
1022 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
1023 | #if NH_3D_VSP || NH_3D_DBBP |
---|
1024 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
1025 | #endif |
---|
1026 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
1027 | { |
---|
1028 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1029 | } |
---|
1030 | } |
---|
1031 | if(doNotBlockPu |
---|
1032 | #if NH_3D_QTL |
---|
1033 | && bTryNx2N |
---|
1034 | #endif |
---|
1035 | ) |
---|
1036 | { |
---|
1037 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
1038 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD, true ); |
---|
1039 | #else |
---|
1040 | |
---|
1041 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
1042 | #endif |
---|
1043 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
1044 | #if NH_3D_VSP || NH_3D_DBBP |
---|
1045 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
1046 | #endif |
---|
1047 | |
---|
1048 | } |
---|
1049 | } |
---|
1050 | #endif |
---|
1051 | |
---|
1052 | #else |
---|
1053 | #if NH_3D_QTL |
---|
1054 | if (bTry2NxN) |
---|
1055 | { |
---|
1056 | #endif |
---|
1057 | |
---|
1058 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
1059 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
1060 | #if NH_3D_VSP || NH_3D_DBBP |
---|
1061 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
1062 | #endif |
---|
1063 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
1064 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
1065 | #if NH_3D_VSP || NH_3D_DBBP |
---|
1066 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
1067 | #endif |
---|
1068 | #if NH_3D_QTL |
---|
1069 | } |
---|
1070 | if (bTryNx2N) |
---|
1071 | { |
---|
1072 | #endif |
---|
1073 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
1074 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
1075 | #if NH_3D_VSP || NH_3D_DBBP |
---|
1076 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
1077 | #endif |
---|
1078 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
1079 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
1080 | #if NH_3D_VSP || NH_3D_DBBP |
---|
1081 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
1082 | #endif |
---|
1083 | #if NH_3D_QTL |
---|
1084 | } |
---|
1085 | #endif |
---|
1086 | |
---|
1087 | |
---|
1088 | #endif |
---|
1089 | } |
---|
1090 | } |
---|
1091 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
1092 | if(!bFMD) |
---|
1093 | { |
---|
1094 | #endif |
---|
1095 | |
---|
1096 | // do normal intra modes |
---|
1097 | // speedup for inter frames |
---|
1098 | |
---|
1099 | if((rpcBestCU->getSlice()->getSliceType() == I_SLICE) || |
---|
1100 | ((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && ( |
---|
1101 | (rpcBestCU->getCbf( 0, COMPONENT_Y ) != 0) || |
---|
1102 | ((rpcBestCU->getCbf( 0, COMPONENT_Cb ) != 0) && (numberValidComponents > COMPONENT_Cb)) || |
---|
1103 | ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr)) // avoid very complex intra if it is unlikely |
---|
1104 | #if NH_3D_ENC_DEPTH |
---|
1105 | || rpcBestCU->getSlice()->getIsDepth() |
---|
1106 | #endif |
---|
1107 | ))) |
---|
1108 | { |
---|
1109 | #if NH_3D_ENC_DEPTH |
---|
1110 | Bool bOnlyIVP = false; |
---|
1111 | Bool bUseIVP = true; |
---|
1112 | if( (rpcBestCU->getSlice()->getSliceType() != I_SLICE) && |
---|
1113 | !( (rpcBestCU->getCbf( 0, COMPONENT_Y ) != 0) || |
---|
1114 | ((rpcBestCU->getCbf( 0, COMPONENT_Cb ) != 0) && (numberValidComponents > COMPONENT_Cb)) || |
---|
1115 | ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr)) ) && |
---|
1116 | (rpcBestCU->getSlice()->getIsDepth() && !(rpcBestCU->getSlice()->isIRAP())) ) |
---|
1117 | { |
---|
1118 | bOnlyIVP = true; |
---|
1119 | bUseIVP = rpcBestCU->getSlice()->getIntraContourFlag(); |
---|
1120 | } |
---|
1121 | if( bUseIVP ) |
---|
1122 | { |
---|
1123 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug), bOnlyIVP ); |
---|
1124 | #else |
---|
1125 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
1126 | #endif |
---|
1127 | #if KWU_RC_MADPRED_E0227 |
---|
1128 | if ( uiDepth <= m_addSADDepth ) |
---|
1129 | { |
---|
1130 | m_LCUPredictionSAD += m_spatialSAD; |
---|
1131 | m_addSADDepth = uiDepth; |
---|
1132 | } |
---|
1133 | #endif |
---|
1134 | |
---|
1135 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
1136 | if( uiDepth == sps.getLog2DiffMaxMinCodingBlockSize() ) |
---|
1137 | { |
---|
1138 | #if NH_3D_QTL //Try IntraNxN |
---|
1139 | if(bTrySplit) |
---|
1140 | { |
---|
1141 | #endif |
---|
1142 | if( rpcTempCU->getWidth(0) > ( 1 << sps.getQuadtreeTULog2MinSize() ) ) |
---|
1143 | { |
---|
1144 | #if NH_3D_ENC_DEPTH |
---|
1145 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug), bOnlyIVP ); |
---|
1146 | #else |
---|
1147 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
1148 | #endif |
---|
1149 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
1150 | } |
---|
1151 | #if NH_3D_QTL |
---|
1152 | } |
---|
1153 | #endif |
---|
1154 | } |
---|
1155 | #if NH_3D_ENC_DEPTH |
---|
1156 | } |
---|
1157 | #endif |
---|
1158 | } |
---|
1159 | |
---|
1160 | // test PCM |
---|
1161 | if(sps.getUsePCM() |
---|
1162 | && rpcTempCU->getWidth(0) <= (1<<sps.getPCMLog2MaxSize()) |
---|
1163 | && rpcTempCU->getWidth(0) >= (1<<sps.getPCMLog2MinSize()) ) |
---|
1164 | { |
---|
1165 | UInt uiRawBits = getTotalBits(rpcBestCU->getWidth(0), rpcBestCU->getHeight(0), rpcBestCU->getPic()->getChromaFormat(), sps.getBitDepths().recon); |
---|
1166 | UInt uiBestBits = rpcBestCU->getTotalBits(); |
---|
1167 | #if NH_3D_VSO // M7 |
---|
1168 | Double dRDCostTemp = m_pcRdCost->getUseLambdaScaleVSO() ? m_pcRdCost->calcRdCostVSO(uiRawBits, 0) : m_pcRdCost->calcRdCost(uiRawBits, 0); |
---|
1169 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > dRDCostTemp )) |
---|
1170 | #else |
---|
1171 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0))) |
---|
1172 | #endif |
---|
1173 | |
---|
1174 | { |
---|
1175 | xCheckIntraPCM (rpcBestCU, rpcTempCU); |
---|
1176 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
1177 | } |
---|
1178 | } |
---|
1179 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
1180 | } |
---|
1181 | #endif |
---|
1182 | if (bIsLosslessMode) // Restore loop variable if lossless mode was searched. |
---|
1183 | { |
---|
1184 | iQP = iMinQP; |
---|
1185 | } |
---|
1186 | } |
---|
1187 | } |
---|
1188 | |
---|
1189 | if( rpcBestCU->getTotalCost()!=MAX_DOUBLE ) |
---|
1190 | { |
---|
1191 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
1192 | m_pcEntropyCoder->resetBits(); |
---|
1193 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
---|
1194 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
1195 | rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1196 | #if NH_3D_VSO // M8 |
---|
1197 | if ( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
1198 | { |
---|
1199 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
1200 | } |
---|
1201 | else |
---|
1202 | #endif |
---|
1203 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
1204 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
1205 | } |
---|
1206 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
1207 | if(rpcBestCU->getSlice()->getViewIndex() && !rpcBestCU->getSlice()->getIsDepth() && (uiDepth >=iIVFMaxD) && rpcBestCU->isSkipped(0)) |
---|
1208 | { |
---|
1209 | bSubBranch = false; |
---|
1210 | } |
---|
1211 | #endif |
---|
1212 | } |
---|
1213 | |
---|
1214 | // copy original YUV samples to PCM buffer |
---|
1215 | if( rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false)) |
---|
1216 | { |
---|
1217 | xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]); |
---|
1218 | } |
---|
1219 | |
---|
1220 | if( uiDepth == pps.getMaxCuDQPDepth() ) |
---|
1221 | { |
---|
1222 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
1223 | iMinQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP ); |
---|
1224 | iMaxQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP ); |
---|
1225 | } |
---|
1226 | else if( uiDepth < pps.getMaxCuDQPDepth() ) |
---|
1227 | { |
---|
1228 | iMinQP = iBaseQP; |
---|
1229 | iMaxQP = iBaseQP; |
---|
1230 | } |
---|
1231 | else |
---|
1232 | { |
---|
1233 | const Int iStartQP = rpcTempCU->getQP(0); |
---|
1234 | iMinQP = iStartQP; |
---|
1235 | iMaxQP = iStartQP; |
---|
1236 | } |
---|
1237 | |
---|
1238 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
1239 | { |
---|
1240 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
1241 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
1242 | } |
---|
1243 | |
---|
1244 | if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) |
---|
1245 | { |
---|
1246 | iMaxQP = iMinQP; // If all TUs are forced into using transquant bypass, do not loop here. |
---|
1247 | } |
---|
1248 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
1249 | bSubBranch = bSubBranch && (bBoundary || !( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isSkipped(0) )); |
---|
1250 | #else |
---|
1251 | const Bool bSubBranch = bBoundary || !( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isSkipped(0) ); |
---|
1252 | #endif |
---|
1253 | #if NH_3D_QTL |
---|
1254 | if( bSubBranch && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() && (!getFastDeltaQp() || uiWidth > fastDeltaQPCuMaxSize || bBoundary) && bTrySplitDQP ) |
---|
1255 | #else |
---|
1256 | if( bSubBranch && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() && (!getFastDeltaQp() || uiWidth > fastDeltaQPCuMaxSize || bBoundary)) |
---|
1257 | #endif |
---|
1258 | { |
---|
1259 | // further split |
---|
1260 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
1261 | { |
---|
1262 | const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true. |
---|
1263 | |
---|
1264 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
1265 | |
---|
1266 | #if NH_3D_VSO // M9 |
---|
1267 | // reset Model |
---|
1268 | if( m_pcRdCost->getUseRenModel() ) |
---|
1269 | { |
---|
1270 | UInt uiWidthOy = m_ppcOrigYuv[uiDepth]->getWidth ( COMPONENT_Y ); |
---|
1271 | UInt uiHeightOy = m_ppcOrigYuv[uiDepth]->getHeight( COMPONENT_Y ); |
---|
1272 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getAddr ( COMPONENT_Y, 0 ); |
---|
1273 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride( COMPONENT_Y ); |
---|
1274 | m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidthOy, uiHeightOy ); |
---|
1275 | } |
---|
1276 | #endif |
---|
1277 | UChar uhNextDepth = uiDepth+1; |
---|
1278 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
1279 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
1280 | DEBUG_STRING_NEW(sTempDebug) |
---|
1281 | |
---|
1282 | #if NH_3D_ARP |
---|
1283 | m_ppcWeightedTempCU[uhNextDepth]->setSlice( m_ppcWeightedTempCU[ uiDepth]->getSlice()); |
---|
1284 | m_ppcWeightedTempCU[uhNextDepth]->setPic ( m_ppcWeightedTempCU[ uiDepth] ); |
---|
1285 | #endif |
---|
1286 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
1287 | { |
---|
1288 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
1289 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
1290 | |
---|
1291 | if( ( pcSubBestPartCU->getCUPelX() < sps.getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < sps.getPicHeightInLumaSamples() ) ) |
---|
1292 | { |
---|
1293 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
1294 | { |
---|
1295 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
1296 | } |
---|
1297 | else |
---|
1298 | { |
---|
1299 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
1300 | } |
---|
1301 | |
---|
1302 | #if AMP_ENC_SPEEDUP |
---|
1303 | DEBUG_STRING_NEW(sChild) |
---|
1304 | if ( !(rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isInter(0)) ) |
---|
1305 | { |
---|
1306 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), NUMBER_OF_PART_SIZES ); |
---|
1307 | } |
---|
1308 | else |
---|
1309 | { |
---|
1310 | |
---|
1311 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), rpcBestCU->getPartitionSize(0) ); |
---|
1312 | } |
---|
1313 | DEBUG_STRING_APPEND(sTempDebug, sChild) |
---|
1314 | #else |
---|
1315 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
---|
1316 | #endif |
---|
1317 | |
---|
1318 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
1319 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
1320 | } |
---|
1321 | else |
---|
1322 | { |
---|
1323 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
1324 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
1325 | } |
---|
1326 | } |
---|
1327 | |
---|
1328 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
1329 | if( !bBoundary ) |
---|
1330 | { |
---|
1331 | m_pcEntropyCoder->resetBits(); |
---|
1332 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
1333 | |
---|
1334 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
1335 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1336 | } |
---|
1337 | #if NH_3D_VSO // M10 |
---|
1338 | if ( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
1339 | { |
---|
1340 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1341 | } |
---|
1342 | else |
---|
1343 | #endif |
---|
1344 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1345 | |
---|
1346 | if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP()) |
---|
1347 | { |
---|
1348 | Bool hasResidual = false; |
---|
1349 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
1350 | { |
---|
1351 | if( ( rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Y) |
---|
1352 | || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cb) && (numberValidComponents > COMPONENT_Cb)) |
---|
1353 | || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cr) && (numberValidComponents > COMPONENT_Cr)) ) ) |
---|
1354 | { |
---|
1355 | hasResidual = true; |
---|
1356 | break; |
---|
1357 | } |
---|
1358 | } |
---|
1359 | |
---|
1360 | if ( hasResidual ) |
---|
1361 | { |
---|
1362 | m_pcEntropyCoder->resetBits(); |
---|
1363 | m_pcEntropyCoder->encodeQP( rpcTempCU, 0, false ); |
---|
1364 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
1365 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1366 | #if NH_3D_VSO // M11 |
---|
1367 | if ( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
1368 | { |
---|
1369 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1370 | } |
---|
1371 | else |
---|
1372 | #endif |
---|
1373 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1374 | |
---|
1375 | Bool foundNonZeroCbf = false; |
---|
1376 | rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( 0 ), 0, uiDepth, foundNonZeroCbf ); |
---|
1377 | assert( foundNonZeroCbf ); |
---|
1378 | } |
---|
1379 | else |
---|
1380 | { |
---|
1381 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
1382 | } |
---|
1383 | } |
---|
1384 | |
---|
1385 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1386 | |
---|
1387 | // If the configuration being tested exceeds the maximum number of bytes for a slice / slice-segment, then |
---|
1388 | // a proper RD evaluation cannot be performed. Therefore, termination of the |
---|
1389 | // slice/slice-segment must be made prior to this CTU. |
---|
1390 | // This can be achieved by forcing the decision to be that of the rpcTempCU. |
---|
1391 | // The exception is each slice / slice-segment must have at least one CTU. |
---|
1392 | if (rpcBestCU->getTotalCost()!=MAX_DOUBLE) |
---|
1393 | { |
---|
1394 | const Bool isEndOfSlice = pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES |
---|
1395 | && ((pcSlice->getSliceBits()+rpcBestCU->getTotalBits())>pcSlice->getSliceArgument()<<3) |
---|
1396 | && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceCurStartCtuTsAddr()) |
---|
1397 | && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()); |
---|
1398 | const Bool isEndOfSliceSegment = pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES |
---|
1399 | && ((pcSlice->getSliceSegmentBits()+rpcBestCU->getTotalBits()) > pcSlice->getSliceSegmentArgument()<<3) |
---|
1400 | && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()); |
---|
1401 | // Do not need to check slice condition for slice-segment since a slice-segment is a subset of a slice. |
---|
1402 | if(isEndOfSlice||isEndOfSliceSegment) |
---|
1403 | { |
---|
1404 | rpcBestCU->getTotalCost()=MAX_DOUBLE; |
---|
1405 | } |
---|
1406 | } |
---|
1407 | |
---|
1408 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTempDebug) DEBUG_STRING_PASS_INTO(false) ); // RD compare current larger prediction |
---|
1409 | // with sub partitioned prediction. |
---|
1410 | } |
---|
1411 | } |
---|
1412 | #if NH_3D_VSO // M12 |
---|
1413 | if( m_pcRdCost->getUseRenModel() ) |
---|
1414 | { |
---|
1415 | UInt uiWidthRy = m_ppcRecoYuvBest[uiDepth]->getWidth ( COMPONENT_Y ); |
---|
1416 | UInt uiHeightRy = m_ppcRecoYuvBest[uiDepth]->getHeight ( COMPONENT_Y ); |
---|
1417 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getAddr ( COMPONENT_Y, 0 ); |
---|
1418 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride ( COMPONENT_Y ); |
---|
1419 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidthRy, uiHeightRy ); |
---|
1420 | } |
---|
1421 | #endif |
---|
1422 | |
---|
1423 | DEBUG_STRING_APPEND(sDebug_, sDebug); |
---|
1424 | |
---|
1425 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
1426 | |
---|
1427 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getCtuRsAddr(), rpcBestCU->getZorderIdxInCtu(), uiDepth, uiDepth ); // Copy Yuv data to picture Yuv |
---|
1428 | if (bBoundary) |
---|
1429 | { |
---|
1430 | return; |
---|
1431 | } |
---|
1432 | |
---|
1433 | // Assert if Best prediction mode is NONE |
---|
1434 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
1435 | assert( rpcBestCU->getPartitionSize ( 0 ) != NUMBER_OF_PART_SIZES ); |
---|
1436 | assert( rpcBestCU->getPredictionMode( 0 ) != NUMBER_OF_PREDICTION_MODES ); |
---|
1437 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
1438 | } |
---|
1439 | |
---|
1440 | /** finish encoding a cu and handle end-of-slice conditions |
---|
1441 | * \param pcCU |
---|
1442 | * \param uiAbsPartIdx |
---|
1443 | * \param uiDepth |
---|
1444 | * \returns Void |
---|
1445 | */ |
---|
1446 | Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1447 | { |
---|
1448 | TComPic* pcPic = pcCU->getPic(); |
---|
1449 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
1450 | |
---|
1451 | //Calculate end address |
---|
1452 | const Int currentCTUTsAddr = pcPic->getPicSym()->getCtuRsToTsAddrMap(pcCU->getCtuRsAddr()); |
---|
1453 | const Bool isLastSubCUOfCtu = pcCU->isLastSubCUOfCtu(uiAbsPartIdx); |
---|
1454 | if ( isLastSubCUOfCtu ) |
---|
1455 | { |
---|
1456 | // The 1-terminating bit is added to all streams, so don't add it here when it's 1. |
---|
1457 | // i.e. when the slice segment CurEnd CTU address is the current CTU address+1. |
---|
1458 | if (pcSlice->getSliceSegmentCurEndCtuTsAddr() != currentCTUTsAddr+1) |
---|
1459 | { |
---|
1460 | m_pcEntropyCoder->encodeTerminatingBit( 0 ); |
---|
1461 | } |
---|
1462 | } |
---|
1463 | } |
---|
1464 | |
---|
1465 | /** Compute QP for each CU |
---|
1466 | * \param pcCU Target CU |
---|
1467 | * \param uiDepth CU depth |
---|
1468 | * \returns quantization parameter |
---|
1469 | */ |
---|
1470 | Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth ) |
---|
1471 | { |
---|
1472 | Int iBaseQp = pcCU->getSlice()->getSliceQp(); |
---|
1473 | Int iQpOffset = 0; |
---|
1474 | if ( m_pcEncCfg->getUseAdaptiveQP() ) |
---|
1475 | { |
---|
1476 | TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() ); |
---|
1477 | UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 ); |
---|
1478 | TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth ); |
---|
1479 | UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth(); |
---|
1480 | UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight(); |
---|
1481 | UInt uiAQUStride = pcAQLayer->getAQPartStride(); |
---|
1482 | TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit(); |
---|
1483 | |
---|
1484 | Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0); |
---|
1485 | Double dAvgAct = pcAQLayer->getAvgActivity(); |
---|
1486 | Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity(); |
---|
1487 | Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct); |
---|
1488 | Double dQpOffset = log(dNormAct) / log(2.0) * 6.0; |
---|
1489 | iQpOffset = Int(floor( dQpOffset + 0.49999 )); |
---|
1490 | } |
---|
1491 | |
---|
1492 | return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQp+iQpOffset ); |
---|
1493 | } |
---|
1494 | |
---|
1495 | /** encode a CU block recursively |
---|
1496 | * \param pcCU |
---|
1497 | * \param uiAbsPartIdx |
---|
1498 | * \param uiDepth |
---|
1499 | * \returns Void |
---|
1500 | */ |
---|
1501 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1502 | { |
---|
1503 | TComPic *const pcPic = pcCU->getPic(); |
---|
1504 | TComSlice *const pcSlice = pcCU->getSlice(); |
---|
1505 | const TComSPS &sps =*(pcSlice->getSPS()); |
---|
1506 | const TComPPS &pps =*(pcSlice->getPPS()); |
---|
1507 | |
---|
1508 | const UInt maxCUWidth = sps.getMaxCUWidth(); |
---|
1509 | const UInt maxCUHeight = sps.getMaxCUHeight(); |
---|
1510 | |
---|
1511 | Bool bBoundary = false; |
---|
1512 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1513 | const UInt uiRPelX = uiLPelX + (maxCUWidth>>uiDepth) - 1; |
---|
1514 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1515 | const UInt uiBPelY = uiTPelY + (maxCUHeight>>uiDepth) - 1; |
---|
1516 | |
---|
1517 | #if NH_MV_ENC_DEC_TRAC |
---|
1518 | DTRACE_CU_S("=========== coding_quadtree ===========\n") |
---|
1519 | DTRACE_CU("x0", uiLPelX) |
---|
1520 | DTRACE_CU("x1", uiTPelY) |
---|
1521 | DTRACE_CU("log2CbSize", maxCUWidth>>uiDepth ) |
---|
1522 | DTRACE_CU("cqtDepth" , uiDepth) |
---|
1523 | #endif |
---|
1524 | |
---|
1525 | if( ( uiRPelX < sps.getPicWidthInLumaSamples() ) && ( uiBPelY < sps.getPicHeightInLumaSamples() ) ) |
---|
1526 | { |
---|
1527 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1528 | } |
---|
1529 | else |
---|
1530 | { |
---|
1531 | bBoundary = true; |
---|
1532 | } |
---|
1533 | |
---|
1534 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) ) || bBoundary ) |
---|
1535 | { |
---|
1536 | UInt uiQNumParts = ( pcPic->getNumPartitionsInCtu() >> (uiDepth<<1) )>>2; |
---|
1537 | if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP()) |
---|
1538 | { |
---|
1539 | setdQPFlag(true); |
---|
1540 | } |
---|
1541 | |
---|
1542 | if( uiDepth == pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcSlice->getUseChromaQpAdj()) |
---|
1543 | { |
---|
1544 | setCodeChromaQpAdjFlag(true); |
---|
1545 | } |
---|
1546 | |
---|
1547 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
1548 | { |
---|
1549 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1550 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1551 | if( ( uiLPelX < sps.getPicWidthInLumaSamples() ) && ( uiTPelY < sps.getPicHeightInLumaSamples() ) ) |
---|
1552 | { |
---|
1553 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
1554 | } |
---|
1555 | } |
---|
1556 | return; |
---|
1557 | } |
---|
1558 | |
---|
1559 | #if NH_MV_ENC_DEC_TRAC |
---|
1560 | DTRACE_CU_S("=========== coding_unit ===========\n") |
---|
1561 | #endif |
---|
1562 | |
---|
1563 | |
---|
1564 | if( uiDepth <= pps.getMaxCuDQPDepth() && pps.getUseDQP()) |
---|
1565 | { |
---|
1566 | setdQPFlag(true); |
---|
1567 | } |
---|
1568 | |
---|
1569 | if( uiDepth <= pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcSlice->getUseChromaQpAdj()) |
---|
1570 | { |
---|
1571 | setCodeChromaQpAdjFlag(true); |
---|
1572 | } |
---|
1573 | |
---|
1574 | if (pps.getTransquantBypassEnableFlag()) |
---|
1575 | { |
---|
1576 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx ); |
---|
1577 | } |
---|
1578 | |
---|
1579 | if( !pcSlice->isIntra() ) |
---|
1580 | { |
---|
1581 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
1582 | } |
---|
1583 | |
---|
1584 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1585 | { |
---|
1586 | #if NH_MV_ENC_DEC_TRAC |
---|
1587 | DTRACE_PU_S("=========== prediction_unit ===========\n") |
---|
1588 | DTRACE_PU("x0", uiLPelX) |
---|
1589 | DTRACE_PU("x1", uiTPelY) |
---|
1590 | #endif |
---|
1591 | |
---|
1592 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
1593 | #if NH_3D_ARP |
---|
1594 | m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx ); |
---|
1595 | #endif |
---|
1596 | #if NH_3D_IC |
---|
1597 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
1598 | #endif |
---|
1599 | |
---|
1600 | finishCU(pcCU,uiAbsPartIdx); |
---|
1601 | return; |
---|
1602 | } |
---|
1603 | |
---|
1604 | #if NH_3D_DIS |
---|
1605 | m_pcEntropyCoder->encodeDIS( pcCU, uiAbsPartIdx ); |
---|
1606 | if(!pcCU->getDISFlag(uiAbsPartIdx)) |
---|
1607 | { |
---|
1608 | #endif |
---|
1609 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
1610 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1611 | |
---|
1612 | if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
1613 | { |
---|
1614 | m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx ); |
---|
1615 | |
---|
1616 | if(pcCU->getIPCMFlag(uiAbsPartIdx)) |
---|
1617 | { |
---|
1618 | #if NH_3D_SDC_INTRA |
---|
1619 | m_pcEntropyCoder->encodeSDCFlag( pcCU, uiAbsPartIdx ); |
---|
1620 | #endif |
---|
1621 | |
---|
1622 | // Encode slice finish |
---|
1623 | finishCU(pcCU,uiAbsPartIdx); |
---|
1624 | return; |
---|
1625 | } |
---|
1626 | } |
---|
1627 | |
---|
1628 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1629 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
1630 | #if NH_3D_DBBP |
---|
1631 | m_pcEntropyCoder->encodeDBBPFlag( pcCU, uiAbsPartIdx ); |
---|
1632 | #endif |
---|
1633 | #if NH_3D_SDC_INTRA |
---|
1634 | m_pcEntropyCoder->encodeSDCFlag( pcCU, uiAbsPartIdx ); |
---|
1635 | #endif |
---|
1636 | #if NH_3D_ARP |
---|
1637 | m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx ); |
---|
1638 | #endif |
---|
1639 | #if NH_3D_IC |
---|
1640 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
1641 | #endif |
---|
1642 | |
---|
1643 | // Encode Coefficients |
---|
1644 | Bool bCodeDQP = getdQPFlag(); |
---|
1645 | Bool codeChromaQpAdj = getCodeChromaQpAdjFlag(); |
---|
1646 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, bCodeDQP, codeChromaQpAdj ); |
---|
1647 | setCodeChromaQpAdjFlag( codeChromaQpAdj ); |
---|
1648 | setdQPFlag( bCodeDQP ); |
---|
1649 | #if NH_3D_DIS |
---|
1650 | } |
---|
1651 | #endif |
---|
1652 | |
---|
1653 | |
---|
1654 | // --- write terminating bit --- |
---|
1655 | finishCU(pcCU,uiAbsPartIdx); |
---|
1656 | } |
---|
1657 | |
---|
1658 | Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) |
---|
1659 | { |
---|
1660 | Int k, i, j, jj; |
---|
1661 | Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0; |
---|
1662 | |
---|
1663 | for( k = 0; k < 64; k += 8 ) |
---|
1664 | { |
---|
1665 | diff[k+0] = piOrg[0] ; |
---|
1666 | diff[k+1] = piOrg[1] ; |
---|
1667 | diff[k+2] = piOrg[2] ; |
---|
1668 | diff[k+3] = piOrg[3] ; |
---|
1669 | diff[k+4] = piOrg[4] ; |
---|
1670 | diff[k+5] = piOrg[5] ; |
---|
1671 | diff[k+6] = piOrg[6] ; |
---|
1672 | diff[k+7] = piOrg[7] ; |
---|
1673 | |
---|
1674 | piOrg += iStrideOrg; |
---|
1675 | } |
---|
1676 | |
---|
1677 | //horizontal |
---|
1678 | for (j=0; j < 8; j++) |
---|
1679 | { |
---|
1680 | jj = j << 3; |
---|
1681 | m2[j][0] = diff[jj ] + diff[jj+4]; |
---|
1682 | m2[j][1] = diff[jj+1] + diff[jj+5]; |
---|
1683 | m2[j][2] = diff[jj+2] + diff[jj+6]; |
---|
1684 | m2[j][3] = diff[jj+3] + diff[jj+7]; |
---|
1685 | m2[j][4] = diff[jj ] - diff[jj+4]; |
---|
1686 | m2[j][5] = diff[jj+1] - diff[jj+5]; |
---|
1687 | m2[j][6] = diff[jj+2] - diff[jj+6]; |
---|
1688 | m2[j][7] = diff[jj+3] - diff[jj+7]; |
---|
1689 | |
---|
1690 | m1[j][0] = m2[j][0] + m2[j][2]; |
---|
1691 | m1[j][1] = m2[j][1] + m2[j][3]; |
---|
1692 | m1[j][2] = m2[j][0] - m2[j][2]; |
---|
1693 | m1[j][3] = m2[j][1] - m2[j][3]; |
---|
1694 | m1[j][4] = m2[j][4] + m2[j][6]; |
---|
1695 | m1[j][5] = m2[j][5] + m2[j][7]; |
---|
1696 | m1[j][6] = m2[j][4] - m2[j][6]; |
---|
1697 | m1[j][7] = m2[j][5] - m2[j][7]; |
---|
1698 | |
---|
1699 | m2[j][0] = m1[j][0] + m1[j][1]; |
---|
1700 | m2[j][1] = m1[j][0] - m1[j][1]; |
---|
1701 | m2[j][2] = m1[j][2] + m1[j][3]; |
---|
1702 | m2[j][3] = m1[j][2] - m1[j][3]; |
---|
1703 | m2[j][4] = m1[j][4] + m1[j][5]; |
---|
1704 | m2[j][5] = m1[j][4] - m1[j][5]; |
---|
1705 | m2[j][6] = m1[j][6] + m1[j][7]; |
---|
1706 | m2[j][7] = m1[j][6] - m1[j][7]; |
---|
1707 | } |
---|
1708 | |
---|
1709 | //vertical |
---|
1710 | for (i=0; i < 8; i++) |
---|
1711 | { |
---|
1712 | m3[0][i] = m2[0][i] + m2[4][i]; |
---|
1713 | m3[1][i] = m2[1][i] + m2[5][i]; |
---|
1714 | m3[2][i] = m2[2][i] + m2[6][i]; |
---|
1715 | m3[3][i] = m2[3][i] + m2[7][i]; |
---|
1716 | m3[4][i] = m2[0][i] - m2[4][i]; |
---|
1717 | m3[5][i] = m2[1][i] - m2[5][i]; |
---|
1718 | m3[6][i] = m2[2][i] - m2[6][i]; |
---|
1719 | m3[7][i] = m2[3][i] - m2[7][i]; |
---|
1720 | |
---|
1721 | m1[0][i] = m3[0][i] + m3[2][i]; |
---|
1722 | m1[1][i] = m3[1][i] + m3[3][i]; |
---|
1723 | m1[2][i] = m3[0][i] - m3[2][i]; |
---|
1724 | m1[3][i] = m3[1][i] - m3[3][i]; |
---|
1725 | m1[4][i] = m3[4][i] + m3[6][i]; |
---|
1726 | m1[5][i] = m3[5][i] + m3[7][i]; |
---|
1727 | m1[6][i] = m3[4][i] - m3[6][i]; |
---|
1728 | m1[7][i] = m3[5][i] - m3[7][i]; |
---|
1729 | |
---|
1730 | m2[0][i] = m1[0][i] + m1[1][i]; |
---|
1731 | m2[1][i] = m1[0][i] - m1[1][i]; |
---|
1732 | m2[2][i] = m1[2][i] + m1[3][i]; |
---|
1733 | m2[3][i] = m1[2][i] - m1[3][i]; |
---|
1734 | m2[4][i] = m1[4][i] + m1[5][i]; |
---|
1735 | m2[5][i] = m1[4][i] - m1[5][i]; |
---|
1736 | m2[6][i] = m1[6][i] + m1[7][i]; |
---|
1737 | m2[7][i] = m1[6][i] - m1[7][i]; |
---|
1738 | } |
---|
1739 | |
---|
1740 | for (i = 0; i < 8; i++) |
---|
1741 | { |
---|
1742 | for (j = 0; j < 8; j++) |
---|
1743 | { |
---|
1744 | iSumHad += abs(m2[i][j]); |
---|
1745 | } |
---|
1746 | } |
---|
1747 | iSumHad -= abs(m2[0][0]); |
---|
1748 | iSumHad =(iSumHad+2)>>2; |
---|
1749 | return(iSumHad); |
---|
1750 | } |
---|
1751 | |
---|
1752 | Int TEncCu::updateCtuDataISlice(TComDataCU* pCtu, Int width, Int height) |
---|
1753 | { |
---|
1754 | Int xBl, yBl; |
---|
1755 | const Int iBlkSize = 8; |
---|
1756 | |
---|
1757 | Pel* pOrgInit = pCtu->getPic()->getPicYuvOrg()->getAddr(COMPONENT_Y, pCtu->getCtuRsAddr(), 0); |
---|
1758 | Int iStrideOrig = pCtu->getPic()->getPicYuvOrg()->getStride(COMPONENT_Y); |
---|
1759 | Pel *pOrg; |
---|
1760 | |
---|
1761 | Int iSumHad = 0; |
---|
1762 | for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize) |
---|
1763 | { |
---|
1764 | for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize) |
---|
1765 | { |
---|
1766 | pOrg = pOrgInit + iStrideOrig*yBl + xBl; |
---|
1767 | iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig); |
---|
1768 | } |
---|
1769 | } |
---|
1770 | return(iSumHad); |
---|
1771 | } |
---|
1772 | |
---|
1773 | /** check RD costs for a CU block encoded with merge |
---|
1774 | * \param rpcBestCU |
---|
1775 | * \param rpcTempCU |
---|
1776 | * \param earlyDetectionSkipMode |
---|
1777 | */ |
---|
1778 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU DEBUG_STRING_FN_DECLARE(sDebug), Bool *earlyDetectionSkipMode ) |
---|
1779 | { |
---|
1780 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
1781 | if(getFastDeltaQp()) |
---|
1782 | { |
---|
1783 | return; // never check merge in fast deltaqp mode |
---|
1784 | } |
---|
1785 | |
---|
1786 | #if NH_MV |
---|
1787 | D_PRINT_INC_INDENT( g_traceModeCheck, "xCheckRDCostMerge2Nx2N" ); |
---|
1788 | #endif |
---|
1789 | |
---|
1790 | #if NH_3D_MLC |
---|
1791 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists |
---|
1792 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM]; |
---|
1793 | #else |
---|
1794 | TComMvField cMvFieldNeighbours[2 * MRG_MAX_NUM_CANDS]; // double length for mv of both lists |
---|
1795 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
1796 | #endif |
---|
1797 | Int numValidMergeCand = 0; |
---|
1798 | const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0); |
---|
1799 | |
---|
1800 | for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) |
---|
1801 | { |
---|
1802 | uhInterDirNeighbours[ui] = 0; |
---|
1803 | } |
---|
1804 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1805 | #if NH_3D_IC |
---|
1806 | Bool bICFlag = rpcTempCU->getICFlag( 0 ); |
---|
1807 | #endif |
---|
1808 | #if NH_3D_VSO // M1 //necessary here? |
---|
1809 | if( m_pcRdCost->getUseRenModel() ) |
---|
1810 | { |
---|
1811 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y ); |
---|
1812 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( COMPONENT_Y ); |
---|
1813 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getAddr ( COMPONENT_Y ); |
---|
1814 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride( COMPONENT_Y ); |
---|
1815 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1816 | } |
---|
1817 | #endif |
---|
1818 | |
---|
1819 | #if NH_3D_ARP |
---|
1820 | DisInfo cOrigDisInfo = rpcTempCU->getDvInfo(0); |
---|
1821 | #else |
---|
1822 | #endif |
---|
1823 | |
---|
1824 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level |
---|
1825 | |
---|
1826 | #if NH_3D_SPIVMP |
---|
1827 | Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM]; |
---|
1828 | memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM); |
---|
1829 | TComMvField* pcMvFieldSP; |
---|
1830 | UChar* puhInterDirSP; |
---|
1831 | pcMvFieldSP = new TComMvField[rpcTempCU->getPic()->getPicSym()->getNumPartitionsInCtu()*2]; |
---|
1832 | puhInterDirSP = new UChar[rpcTempCU->getPic()->getPicSym()->getNumPartitionsInCtu()]; |
---|
1833 | #endif |
---|
1834 | |
---|
1835 | #if NH_3D_VSP |
---|
1836 | #if !NH_3D_ARP |
---|
1837 | Int vspFlag[MRG_MAX_NUM_CANDS_MEM]; |
---|
1838 | memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM); |
---|
1839 | #if NH_3D_MLC |
---|
1840 | rpcTempCU->initAvailableFlags(); |
---|
1841 | #endif |
---|
1842 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
1843 | #if NH_3D_MLC |
---|
1844 | rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours |
---|
1845 | #if NH_3D_SPIVMP |
---|
1846 | , pcMvFieldSP, puhInterDirSP |
---|
1847 | #endif |
---|
1848 | , numValidMergeCand |
---|
1849 | ); |
---|
1850 | |
---|
1851 | rpcTempCU->buildMCL( cMvFieldNeighbours,uhInterDirNeighbours, vspFlag |
---|
1852 | #if NH_3D_SPIVMP |
---|
1853 | , bSPIVMPFlag |
---|
1854 | #endif |
---|
1855 | , numValidMergeCand |
---|
1856 | ); |
---|
1857 | #endif |
---|
1858 | #endif |
---|
1859 | #else |
---|
1860 | #if NH_3D_MLC |
---|
1861 | rpcTempCU->initAvailableFlags(); |
---|
1862 | #endif |
---|
1863 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); |
---|
1864 | #if NH_3D_MLC |
---|
1865 | rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours |
---|
1866 | #if H_3D_SPIVMP |
---|
1867 | , pcMvFieldSP, puhInterDirSP |
---|
1868 | #endif |
---|
1869 | , numValidMergeCand |
---|
1870 | ); |
---|
1871 | #if NH_3D_MLC |
---|
1872 | rpcTempCU->buildMCL( cMvFieldNeighbours,uhInterDirNeighbours |
---|
1873 | #if H_3D_SPIVMP |
---|
1874 | , bSPIVMPFlag |
---|
1875 | #endif |
---|
1876 | , numValidMergeCand |
---|
1877 | ); |
---|
1878 | #endif |
---|
1879 | #endif |
---|
1880 | #endif |
---|
1881 | |
---|
1882 | #if NH_3D_MLC |
---|
1883 | Int mergeCandBuffer[MRG_MAX_NUM_CANDS_MEM]; |
---|
1884 | #else |
---|
1885 | Int mergeCandBuffer[MRG_MAX_NUM_CANDS]; |
---|
1886 | #endif |
---|
1887 | #if NH_3D_MLC |
---|
1888 | for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) |
---|
1889 | #else |
---|
1890 | for( UInt ui = 0; ui < numValidMergeCand; ++ui ) |
---|
1891 | #endif |
---|
1892 | { |
---|
1893 | mergeCandBuffer[ui] = 0; |
---|
1894 | } |
---|
1895 | |
---|
1896 | Bool bestIsSkip = false; |
---|
1897 | |
---|
1898 | UInt iteration; |
---|
1899 | if ( rpcTempCU->isLosslessCoded(0)) |
---|
1900 | { |
---|
1901 | iteration = 1; |
---|
1902 | } |
---|
1903 | else |
---|
1904 | { |
---|
1905 | iteration = 2; |
---|
1906 | } |
---|
1907 | DEBUG_STRING_NEW(bestStr) |
---|
1908 | |
---|
1909 | #if NH_3D_ARP |
---|
1910 | Int nARPWMax = rpcTempCU->getSlice()->getARPStepNum() - 1; |
---|
1911 | #if NH_3D_IC |
---|
1912 | if( nARPWMax < 0 || bICFlag ) |
---|
1913 | #else |
---|
1914 | if( nARPWMax < 0 ) |
---|
1915 | #endif |
---|
1916 | { |
---|
1917 | nARPWMax = 0; |
---|
1918 | } |
---|
1919 | for( Int nARPW=nARPWMax; nARPW >= 0 ; nARPW-- ) |
---|
1920 | { |
---|
1921 | #if NH_3D |
---|
1922 | #if DEBUG_STRING |
---|
1923 | bestStr.clear(); |
---|
1924 | #endif |
---|
1925 | #endif |
---|
1926 | #if NH_3D_IV_MERGE |
---|
1927 | memset( mergeCandBuffer, 0, MRG_MAX_NUM_CANDS_MEM*sizeof(Int) ); |
---|
1928 | #else |
---|
1929 | memset( mergeCandBuffer, 0, MRG_MAX_NUM_CANDS * sizeof(Int) ); |
---|
1930 | #endif |
---|
1931 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1932 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
1933 | #if NH_3D_IC |
---|
1934 | rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth ); |
---|
1935 | #endif |
---|
1936 | rpcTempCU->getDvInfo(0) = cOrigDisInfo; |
---|
1937 | rpcTempCU->setDvInfoSubParts(cOrigDisInfo, 0, uhDepth ); |
---|
1938 | #if NH_3D_VSP |
---|
1939 | Int vspFlag[MRG_MAX_NUM_CANDS_MEM]; |
---|
1940 | memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM); |
---|
1941 | #endif |
---|
1942 | #if NH_3D |
---|
1943 | #if NH_3D_MLC |
---|
1944 | rpcTempCU->initAvailableFlags(); |
---|
1945 | #endif |
---|
1946 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
1947 | rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours |
---|
1948 | #if NH_3D_SPIVMP |
---|
1949 | , pcMvFieldSP, puhInterDirSP |
---|
1950 | #endif |
---|
1951 | , numValidMergeCand |
---|
1952 | ); |
---|
1953 | |
---|
1954 | rpcTempCU->buildMCL( cMvFieldNeighbours,uhInterDirNeighbours |
---|
1955 | #if NH_3D_VSP |
---|
1956 | , vspFlag |
---|
1957 | #endif |
---|
1958 | #if NH_3D_SPIVMP |
---|
1959 | , bSPIVMPFlag |
---|
1960 | #endif |
---|
1961 | , numValidMergeCand |
---|
1962 | ); |
---|
1963 | |
---|
1964 | #else |
---|
1965 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); |
---|
1966 | #endif |
---|
1967 | |
---|
1968 | |
---|
1969 | #endif |
---|
1970 | |
---|
1971 | for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
1972 | { |
---|
1973 | #if NH_MV |
---|
1974 | D_PRINT_INC_INDENT ( g_traceModeCheck, "uiNoResidual: " + n2s( uiNoResidual) ); |
---|
1975 | #endif |
---|
1976 | |
---|
1977 | for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) |
---|
1978 | { |
---|
1979 | #if NH_3D_IC |
---|
1980 | if( rpcTempCU->getSlice()->getApplyIC() && rpcTempCU->getSlice()->getIcSkipParseFlag() ) |
---|
1981 | { |
---|
1982 | if( bICFlag && uiMergeCand == 0 ) |
---|
1983 | { |
---|
1984 | continue; |
---|
1985 | } |
---|
1986 | } |
---|
1987 | #endif |
---|
1988 | #if NH_MV |
---|
1989 | D_PRINT_INC_INDENT ( g_traceModeCheck, "uiMergeCand: "+ n2s(uiMergeCand) ); |
---|
1990 | #endif |
---|
1991 | |
---|
1992 | if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1)) |
---|
1993 | { |
---|
1994 | if( !(bestIsSkip && uiNoResidual == 0) ) |
---|
1995 | { |
---|
1996 | DEBUG_STRING_NEW(tmpStr) |
---|
1997 | // set MC parameters |
---|
1998 | rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to CTU level |
---|
1999 | #if NH_3D_IC |
---|
2000 | rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth ); |
---|
2001 | #endif |
---|
2002 | rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag, 0, uhDepth ); |
---|
2003 | rpcTempCU->setChromaQpAdjSubParts( bTransquantBypassFlag ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uhDepth ); |
---|
2004 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level |
---|
2005 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to CTU level |
---|
2006 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to CTU level |
---|
2007 | #if NH_3D_ARP |
---|
2008 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
2009 | #endif |
---|
2010 | |
---|
2011 | #if NH_3D_VSP |
---|
2012 | rpcTempCU->setVSPFlagSubParts( vspFlag[uiMergeCand], 0, 0, uhDepth ); |
---|
2013 | #endif |
---|
2014 | #if NH_3D_SPIVMP |
---|
2015 | rpcTempCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeCand], 0, 0, uhDepth); |
---|
2016 | if (bSPIVMPFlag[uiMergeCand]) |
---|
2017 | { |
---|
2018 | UInt uiSPAddr; |
---|
2019 | Int iWidth = rpcTempCU->getWidth(0); |
---|
2020 | Int iHeight = rpcTempCU->getHeight(0); |
---|
2021 | Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; |
---|
2022 | rpcTempCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); |
---|
2023 | for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++) |
---|
2024 | { |
---|
2025 | rpcTempCU->getSPAbsPartIdx(0, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr); |
---|
2026 | rpcTempCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight); |
---|
2027 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight); |
---|
2028 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight); |
---|
2029 | } |
---|
2030 | } |
---|
2031 | else |
---|
2032 | #endif |
---|
2033 | { |
---|
2034 | #if NH_3D_VSP |
---|
2035 | if ( vspFlag[uiMergeCand] ) |
---|
2036 | { |
---|
2037 | UInt partAddr; |
---|
2038 | Int vspSize; |
---|
2039 | Int width, height; |
---|
2040 | rpcTempCU->getPartIndexAndSize( 0, partAddr, width, height ); |
---|
2041 | if( uhInterDirNeighbours[ uiMergeCand ] & 0x01 ) |
---|
2042 | { |
---|
2043 | rpcTempCU->setMvFieldPUForVSP( rpcTempCU, partAddr, width, height, REF_PIC_LIST_0, cMvFieldNeighbours[ 2*uiMergeCand + 0 ].getRefIdx(), vspSize ); |
---|
2044 | rpcTempCU->setVSPFlag( partAddr, vspSize ); |
---|
2045 | } |
---|
2046 | else |
---|
2047 | { |
---|
2048 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
2049 | } |
---|
2050 | if( uhInterDirNeighbours[ uiMergeCand ] & 0x02 ) |
---|
2051 | { |
---|
2052 | rpcTempCU->setMvFieldPUForVSP( rpcTempCU, partAddr, width, height, REF_PIC_LIST_1 , cMvFieldNeighbours[ 2*uiMergeCand + 1 ].getRefIdx(), vspSize ); |
---|
2053 | rpcTempCU->setVSPFlag( partAddr, vspSize ); |
---|
2054 | } |
---|
2055 | else |
---|
2056 | { |
---|
2057 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
2058 | } |
---|
2059 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
2060 | } |
---|
2061 | else |
---|
2062 | { |
---|
2063 | #endif |
---|
2064 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to CTU level |
---|
2065 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
2066 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
2067 | #if NH_3D_VSP |
---|
2068 | } |
---|
2069 | #endif |
---|
2070 | } |
---|
2071 | // do MC |
---|
2072 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
2073 | // estimate residual and encode everything |
---|
2074 | #if NH_3D_VSO //M2 |
---|
2075 | if( m_pcRdCost->getUseRenModel() ) |
---|
2076 | { //Reset |
---|
2077 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y ); |
---|
2078 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight ( COMPONENT_Y ); |
---|
2079 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getAddr ( COMPONENT_Y ); |
---|
2080 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride ( COMPONENT_Y ); |
---|
2081 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2082 | } |
---|
2083 | #endif |
---|
2084 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
2085 | m_ppcOrigYuv [uhDepth], |
---|
2086 | m_ppcPredYuvTemp[uhDepth], |
---|
2087 | m_ppcResiYuvTemp[uhDepth], |
---|
2088 | m_ppcResiYuvBest[uhDepth], |
---|
2089 | m_ppcRecoYuvTemp[uhDepth], |
---|
2090 | (uiNoResidual != 0) DEBUG_STRING_PASS_INTO(tmpStr) ); |
---|
2091 | |
---|
2092 | #if DEBUG_STRING |
---|
2093 | DebugInterPredResiReco(tmpStr, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0))); |
---|
2094 | #endif |
---|
2095 | |
---|
2096 | if ((uiNoResidual == 0) && (rpcTempCU->getQtRootCbf(0) == 0)) |
---|
2097 | { |
---|
2098 | // If no residual when allowing for one, then set mark to not try case where residual is forced to 0 |
---|
2099 | mergeCandBuffer[uiMergeCand] = 1; |
---|
2100 | } |
---|
2101 | #if NH_3D_DIS |
---|
2102 | rpcTempCU->setDISFlagSubParts( false, 0, uhDepth ); |
---|
2103 | #endif |
---|
2104 | #if NH_3D_VSP |
---|
2105 | if( rpcTempCU->getSkipFlag(0) ) |
---|
2106 | { |
---|
2107 | rpcTempCU->setTrIdxSubParts(0, 0, uhDepth); |
---|
2108 | } |
---|
2109 | #endif |
---|
2110 | #if NH_3D_SDC_INTER |
---|
2111 | TComDataCU *rpcTempCUPre = rpcTempCU; |
---|
2112 | #endif |
---|
2113 | Int orgQP = rpcTempCU->getQP( 0 ); |
---|
2114 | xCheckDQP( rpcTempCU ); |
---|
2115 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(bestStr) DEBUG_STRING_PASS_INTO(tmpStr)); |
---|
2116 | #if NH_3D_SDC_INTER |
---|
2117 | if( rpcTempCU->getSlice()->getInterSdcFlag() && !uiNoResidual ) |
---|
2118 | { |
---|
2119 | Double dOffsetCost[3] = {MAX_DOUBLE,MAX_DOUBLE,MAX_DOUBLE}; |
---|
2120 | for( Int uiOffest = 1 ; uiOffest <= 5 ; uiOffest++ ) |
---|
2121 | { |
---|
2122 | if( uiOffest > 3) |
---|
2123 | { |
---|
2124 | if ( dOffsetCost[0] < (0.9*dOffsetCost[1]) && dOffsetCost[0] < (0.9*dOffsetCost[2]) ) |
---|
2125 | { |
---|
2126 | continue; |
---|
2127 | } |
---|
2128 | if ( dOffsetCost[1] < dOffsetCost[0] && dOffsetCost[0] < dOffsetCost[2] && uiOffest == 5) |
---|
2129 | { |
---|
2130 | continue; |
---|
2131 | } |
---|
2132 | if ( dOffsetCost[0] < dOffsetCost[1] && dOffsetCost[2] < dOffsetCost[0] && uiOffest == 4) |
---|
2133 | { |
---|
2134 | continue; |
---|
2135 | } |
---|
2136 | } |
---|
2137 | if( rpcTempCU != rpcTempCUPre ) |
---|
2138 | { |
---|
2139 | rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag ); |
---|
2140 | rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth ); |
---|
2141 | } |
---|
2142 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
2143 | #if NH_3D_DIS |
---|
2144 | rpcTempCU->setDISFlagSubParts( false, 0, uhDepth ); |
---|
2145 | #endif |
---|
2146 | rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth ); |
---|
2147 | rpcTempCU->setCbfSubParts( 1, COMPONENT_Y, 0, uhDepth ); |
---|
2148 | #if NH_3D_VSO //M2 |
---|
2149 | if( m_pcRdCost->getUseRenModel() ) |
---|
2150 | { //Reset |
---|
2151 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y ); |
---|
2152 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight ( COMPONENT_Y ); |
---|
2153 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getAddr ( COMPONENT_Y ); |
---|
2154 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride ( COMPONENT_Y ); |
---|
2155 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2156 | } |
---|
2157 | #endif |
---|
2158 | Int iSdcOffset = 0; |
---|
2159 | if(uiOffest % 2 == 0) |
---|
2160 | { |
---|
2161 | iSdcOffset = uiOffest >> 1; |
---|
2162 | } |
---|
2163 | else |
---|
2164 | { |
---|
2165 | iSdcOffset = -1 * (uiOffest >> 1); |
---|
2166 | } |
---|
2167 | m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU, |
---|
2168 | m_ppcOrigYuv[uhDepth], |
---|
2169 | ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth], |
---|
2170 | m_ppcResiYuvTemp[uhDepth], |
---|
2171 | m_ppcRecoYuvTemp[uhDepth], |
---|
2172 | iSdcOffset, |
---|
2173 | uhDepth ); |
---|
2174 | if (uiOffest <= 3 ) |
---|
2175 | { |
---|
2176 | dOffsetCost [uiOffest -1] = rpcTempCU->getTotalCost(); |
---|
2177 | } |
---|
2178 | |
---|
2179 | xCheckDQP( rpcTempCU ); |
---|
2180 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(bestStr) DEBUG_STRING_PASS_INTO(tmpStr) ); |
---|
2181 | } |
---|
2182 | } |
---|
2183 | #endif |
---|
2184 | |
---|
2185 | rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag ); |
---|
2186 | |
---|
2187 | if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) |
---|
2188 | { |
---|
2189 | #if NH_3D_SDC_INTER |
---|
2190 | if( rpcTempCU->getSlice()->getInterSdcFlag() ) |
---|
2191 | { |
---|
2192 | bestIsSkip = !rpcBestCU->getSDCFlag( 0 ) && ( rpcBestCU->getQtRootCbf(0) == 0 ); |
---|
2193 | } |
---|
2194 | else |
---|
2195 | { |
---|
2196 | #endif |
---|
2197 | bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; |
---|
2198 | #if NH_3D_SDC_INTER |
---|
2199 | } |
---|
2200 | #endif |
---|
2201 | } |
---|
2202 | } |
---|
2203 | } |
---|
2204 | #if NH_MV |
---|
2205 | D_DEC_INDENT( g_traceModeCheck ); |
---|
2206 | #endif |
---|
2207 | } |
---|
2208 | |
---|
2209 | if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection()) |
---|
2210 | { |
---|
2211 | if(rpcBestCU->getQtRootCbf( 0 ) == 0) |
---|
2212 | { |
---|
2213 | if( rpcBestCU->getMergeFlag( 0 )) |
---|
2214 | { |
---|
2215 | *earlyDetectionSkipMode = true; |
---|
2216 | } |
---|
2217 | else if(m_pcEncCfg->getMotionEstimationSearchMethod() != MESEARCH_SELECTIVE) |
---|
2218 | { |
---|
2219 | Int absoulte_MV=0; |
---|
2220 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
2221 | { |
---|
2222 | if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
2223 | { |
---|
2224 | TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx )); |
---|
2225 | Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor(); |
---|
2226 | Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer(); |
---|
2227 | absoulte_MV+=iHor+iVer; |
---|
2228 | } |
---|
2229 | } |
---|
2230 | |
---|
2231 | if(absoulte_MV == 0) |
---|
2232 | { |
---|
2233 | *earlyDetectionSkipMode = true; |
---|
2234 | } |
---|
2235 | } |
---|
2236 | } |
---|
2237 | } |
---|
2238 | #if NH_MV |
---|
2239 | D_DEC_INDENT( g_traceModeCheck ); |
---|
2240 | #endif |
---|
2241 | } |
---|
2242 | DEBUG_STRING_APPEND(sDebug, bestStr) |
---|
2243 | #if NH_3D_ARP |
---|
2244 | } |
---|
2245 | #endif |
---|
2246 | #if NH_3D_SPIVMP |
---|
2247 | delete[] pcMvFieldSP; |
---|
2248 | delete[] puhInterDirSP; |
---|
2249 | #endif |
---|
2250 | #if NH_MV |
---|
2251 | D_DEC_INDENT( g_traceModeCheck ); |
---|
2252 | #endif |
---|
2253 | } |
---|
2254 | |
---|
2255 | |
---|
2256 | #if AMP_MRG |
---|
2257 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
2258 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize DEBUG_STRING_FN_DECLARE(sDebug), Bool bFMD, Bool bUseMRG) |
---|
2259 | #else |
---|
2260 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize DEBUG_STRING_FN_DECLARE(sDebug), Bool bUseMRG) |
---|
2261 | #endif |
---|
2262 | #else |
---|
2263 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
2264 | #endif |
---|
2265 | { |
---|
2266 | DEBUG_STRING_NEW(sTest) |
---|
2267 | |
---|
2268 | if(getFastDeltaQp()) |
---|
2269 | { |
---|
2270 | const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS()); |
---|
2271 | const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>(sps.getLog2DiffMaxMinCodingBlockSize()), sps.getMaxCUHeight(), 32u); |
---|
2272 | if(ePartSize != SIZE_2Nx2N || rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxSize) |
---|
2273 | { |
---|
2274 | return; // only check necessary 2Nx2N Inter in fast deltaqp mode |
---|
2275 | } |
---|
2276 | } |
---|
2277 | |
---|
2278 | #if NH_MV |
---|
2279 | D_PRINT_INC_INDENT(g_traceModeCheck, "xCheckRDCostInter; ePartSize:" + n2s( ePartSize) ); |
---|
2280 | #endif |
---|
2281 | |
---|
2282 | |
---|
2283 | // prior to this, rpcTempCU will have just been reset using rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
2284 | #if NH_3D_ARP |
---|
2285 | const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0); |
---|
2286 | #endif |
---|
2287 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
2288 | if(!(bFMD && (ePartSize == SIZE_2Nx2N))) //have motion estimation or merge check |
---|
2289 | { |
---|
2290 | #endif |
---|
2291 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
2292 | #if NH_3D_ARP |
---|
2293 | Bool bFirstTime = true; |
---|
2294 | Int nARPWMax = rpcTempCU->getSlice()->getARPStepNum() - 1; |
---|
2295 | #if NH_3D_IC |
---|
2296 | if( nARPWMax < 0 || ePartSize != SIZE_2Nx2N || rpcTempCU->getICFlag(0) ) |
---|
2297 | #else |
---|
2298 | if( nARPWMax < 0 || ePartSize != SIZE_2Nx2N ) |
---|
2299 | #endif |
---|
2300 | { |
---|
2301 | nARPWMax = 0; |
---|
2302 | } |
---|
2303 | |
---|
2304 | for( Int nARPW = 0; nARPW <= nARPWMax; nARPW++ ) |
---|
2305 | { |
---|
2306 | #if DEBUG_STRING && NH_MV_ENC_DEC_TRAC |
---|
2307 | sTest.clear(); |
---|
2308 | #endif |
---|
2309 | |
---|
2310 | if( !bFirstTime && rpcTempCU->getSlice()->getIvResPredFlag() ) |
---|
2311 | { |
---|
2312 | rpcTempCU->initEstData( rpcTempCU->getDepth(0), rpcTempCU->getQP(0),bTransquantBypassFlag ); |
---|
2313 | } |
---|
2314 | #endif |
---|
2315 | #if NH_3D_VSO // M3 |
---|
2316 | if( m_pcRdCost->getUseRenModel() ) |
---|
2317 | { |
---|
2318 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y ); |
---|
2319 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( COMPONENT_Y ); |
---|
2320 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getAddr ( COMPONENT_Y ); |
---|
2321 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride( COMPONENT_Y ); |
---|
2322 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2323 | } |
---|
2324 | #endif |
---|
2325 | #if NH_3D_DIS |
---|
2326 | rpcTempCU->setDISFlagSubParts( false, 0, uhDepth ); |
---|
2327 | #endif |
---|
2328 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
2329 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
2330 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uhDepth ); |
---|
2331 | #if NH_3D_ARP |
---|
2332 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
2333 | #endif |
---|
2334 | #if NH_3D_ARP |
---|
2335 | if( bFirstTime == false && nARPWMax ) |
---|
2336 | { |
---|
2337 | rpcTempCU->copyPartFrom( m_ppcWeightedTempCU[uhDepth] , 0 , uhDepth ); |
---|
2338 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
2339 | |
---|
2340 | m_pcPredSearch->motionCompensation( rpcTempCU , m_ppcPredYuvTemp[uhDepth] ); |
---|
2341 | } |
---|
2342 | else |
---|
2343 | { |
---|
2344 | bFirstTime = false; |
---|
2345 | #endif |
---|
2346 | #if AMP_MRG |
---|
2347 | rpcTempCU->setMergeAMP (true); |
---|
2348 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
2349 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] DEBUG_STRING_PASS_INTO(sTest), bFMD, false, bUseMRG ); |
---|
2350 | #else |
---|
2351 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] DEBUG_STRING_PASS_INTO(sTest), false, bUseMRG ); |
---|
2352 | #endif |
---|
2353 | |
---|
2354 | #else |
---|
2355 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
2356 | #endif |
---|
2357 | #if NH_3D_ARP |
---|
2358 | if( nARPWMax ) |
---|
2359 | { |
---|
2360 | m_ppcWeightedTempCU[uhDepth]->copyPartFrom( rpcTempCU , 0 , uhDepth ); |
---|
2361 | } |
---|
2362 | } |
---|
2363 | #endif |
---|
2364 | |
---|
2365 | #if AMP_MRG |
---|
2366 | if ( !rpcTempCU->getMergeAMP() ) |
---|
2367 | { |
---|
2368 | #if NH_3D_ARP |
---|
2369 | if( nARPWMax ) |
---|
2370 | { |
---|
2371 | continue; |
---|
2372 | } |
---|
2373 | else |
---|
2374 | #endif |
---|
2375 | { |
---|
2376 | #if NH_MV |
---|
2377 | D_DEC_INDENT( g_traceModeCheck ); |
---|
2378 | #endif |
---|
2379 | return; |
---|
2380 | } |
---|
2381 | } |
---|
2382 | #endif |
---|
2383 | #if KWU_RC_MADPRED_E0227 |
---|
2384 | if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth ) |
---|
2385 | { |
---|
2386 | UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(), |
---|
2387 | m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(), |
---|
2388 | rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) ); |
---|
2389 | m_temporalSAD = (Int)SAD; |
---|
2390 | } |
---|
2391 | #endif |
---|
2392 | |
---|
2393 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false DEBUG_STRING_PASS_INTO(sTest) ); |
---|
2394 | #if NH_3D_VSP |
---|
2395 | if( rpcTempCU->getQtRootCbf(0)==0 ) |
---|
2396 | { |
---|
2397 | rpcTempCU->setTrIdxSubParts(0, 0, uhDepth); |
---|
2398 | } |
---|
2399 | #endif |
---|
2400 | #if NH_3D_VSO // M4 |
---|
2401 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
2402 | { |
---|
2403 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2404 | } |
---|
2405 | else |
---|
2406 | #endif |
---|
2407 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2408 | |
---|
2409 | #if DEBUG_STRING |
---|
2410 | DebugInterPredResiReco(sTest, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0))); |
---|
2411 | #endif |
---|
2412 | #if NH_3D_SDC_INTER |
---|
2413 | TComDataCU *rpcTempCUPre = rpcTempCU; |
---|
2414 | #endif |
---|
2415 | |
---|
2416 | xCheckDQP( rpcTempCU ); |
---|
2417 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest)); |
---|
2418 | #if NH_3D_SDC_INTER |
---|
2419 | if( rpcTempCU->getSlice()->getInterSdcFlag() && ePartSize == SIZE_2Nx2N) |
---|
2420 | { |
---|
2421 | Double dOffsetCost[3] = {MAX_DOUBLE,MAX_DOUBLE,MAX_DOUBLE}; |
---|
2422 | for( Int uiOffest = 1 ; uiOffest <= 5 ; uiOffest++ ) |
---|
2423 | { |
---|
2424 | if( uiOffest > 3) |
---|
2425 | { |
---|
2426 | if ( dOffsetCost[0] < (0.9*dOffsetCost[1]) && dOffsetCost[0] < (0.9*dOffsetCost[2]) ) |
---|
2427 | { |
---|
2428 | continue; |
---|
2429 | } |
---|
2430 | if ( dOffsetCost[1] < dOffsetCost[0] && dOffsetCost[0] < dOffsetCost[2] && uiOffest == 5) |
---|
2431 | { |
---|
2432 | continue; |
---|
2433 | } |
---|
2434 | if ( dOffsetCost[0] < dOffsetCost[1] && dOffsetCost[2] < dOffsetCost[0] && uiOffest == 4) |
---|
2435 | { |
---|
2436 | continue; |
---|
2437 | } |
---|
2438 | } |
---|
2439 | |
---|
2440 | if( rpcTempCU != rpcTempCUPre ) |
---|
2441 | { |
---|
2442 | Int orgQP = rpcBestCU->getQP( 0 ); |
---|
2443 | rpcTempCU->initEstData( uhDepth, orgQP ,bTransquantBypassFlag ); |
---|
2444 | rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth ); |
---|
2445 | } |
---|
2446 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
2447 | #if NH_3D_DIS |
---|
2448 | rpcTempCU->setDISFlagSubParts( false, 0, uhDepth ); |
---|
2449 | #endif |
---|
2450 | rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth ); |
---|
2451 | rpcTempCU->setCbfSubParts( 1, COMPONENT_Y, 0, uhDepth ); |
---|
2452 | #if NH_3D_VSO // M3 |
---|
2453 | if( m_pcRdCost->getUseRenModel() ) |
---|
2454 | { |
---|
2455 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y ); |
---|
2456 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( COMPONENT_Y ); |
---|
2457 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getAddr ( COMPONENT_Y ); |
---|
2458 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride( COMPONENT_Y ); |
---|
2459 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2460 | } |
---|
2461 | #endif |
---|
2462 | |
---|
2463 | Int iSdcOffset = 0; |
---|
2464 | if(uiOffest % 2 == 0) |
---|
2465 | { |
---|
2466 | iSdcOffset = uiOffest >> 1; |
---|
2467 | } |
---|
2468 | else |
---|
2469 | { |
---|
2470 | iSdcOffset = -1 * (uiOffest >> 1); |
---|
2471 | } |
---|
2472 | m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU, |
---|
2473 | m_ppcOrigYuv[uhDepth], |
---|
2474 | ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth], |
---|
2475 | m_ppcResiYuvTemp[uhDepth], |
---|
2476 | m_ppcRecoYuvTemp[uhDepth], |
---|
2477 | iSdcOffset, |
---|
2478 | uhDepth ); |
---|
2479 | if (uiOffest <= 3 ) |
---|
2480 | { |
---|
2481 | dOffsetCost [uiOffest -1] = rpcTempCU->getTotalCost(); |
---|
2482 | } |
---|
2483 | |
---|
2484 | xCheckDQP( rpcTempCU ); |
---|
2485 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest)); |
---|
2486 | } |
---|
2487 | |
---|
2488 | } |
---|
2489 | #endif |
---|
2490 | #if NH_3D_ARP |
---|
2491 | } |
---|
2492 | #endif |
---|
2493 | #if NH_3D_FAST_TEXTURE_ENCODING |
---|
2494 | } |
---|
2495 | #endif |
---|
2496 | #if NH_MV |
---|
2497 | D_DEC_INDENT( g_traceModeCheck ); |
---|
2498 | #endif |
---|
2499 | } |
---|
2500 | |
---|
2501 | #if NH_3D_DBBP |
---|
2502 | Void TEncCu::xInvalidateOriginalSegments( TComYuv* pOrigYuv, TComYuv* pOrigYuvTemp, Bool* pMask, UInt uiValidSegment ) |
---|
2503 | { |
---|
2504 | UInt uiWidth = pOrigYuv->getWidth (COMPONENT_Y); |
---|
2505 | UInt uiHeight = pOrigYuv->getHeight(COMPONENT_Y); |
---|
2506 | Pel* piSrc = pOrigYuv->getAddr(COMPONENT_Y); |
---|
2507 | UInt uiSrcStride = pOrigYuv->getStride(COMPONENT_Y); |
---|
2508 | Pel* piDst = pOrigYuvTemp->getAddr(COMPONENT_Y); |
---|
2509 | UInt uiDstStride = pOrigYuvTemp->getStride(COMPONENT_Y); |
---|
2510 | |
---|
2511 | UInt uiMaskStride= MAX_CU_SIZE; |
---|
2512 | |
---|
2513 | AOF( uiWidth == uiHeight ); |
---|
2514 | |
---|
2515 | // backup pointer |
---|
2516 | Bool* pMaskStart = pMask; |
---|
2517 | |
---|
2518 | for (Int y=0; y<uiHeight; y++) |
---|
2519 | { |
---|
2520 | for (Int x=0; x<uiWidth; x++) |
---|
2521 | { |
---|
2522 | UChar ucSegment = (UChar)pMask[x]; |
---|
2523 | AOF( ucSegment < 2 ); |
---|
2524 | |
---|
2525 | piDst[x] = (ucSegment==uiValidSegment)?piSrc[x]:DBBP_INVALID_SHORT; |
---|
2526 | } |
---|
2527 | |
---|
2528 | piSrc += uiSrcStride; |
---|
2529 | piDst += uiDstStride; |
---|
2530 | pMask += uiMaskStride; |
---|
2531 | } |
---|
2532 | |
---|
2533 | // now invalidate chroma |
---|
2534 | Pel* piSrcU = pOrigYuv->getAddr(COMPONENT_Cb); |
---|
2535 | Pel* piSrcV = pOrigYuv->getAddr(COMPONENT_Cr); |
---|
2536 | UInt uiSrcStrideC = pOrigYuv->getStride(COMPONENT_Cb); |
---|
2537 | Pel* piDstU = pOrigYuvTemp->getAddr(COMPONENT_Cb); |
---|
2538 | Pel* piDstV = pOrigYuvTemp->getAddr(COMPONENT_Cr); |
---|
2539 | UInt uiDstStrideC = pOrigYuvTemp->getStride(COMPONENT_Cb); |
---|
2540 | pMask = pMaskStart; |
---|
2541 | |
---|
2542 | for (Int y=0; y<uiHeight/2; y++) |
---|
2543 | { |
---|
2544 | for (Int x=0; x<uiWidth/2; x++) |
---|
2545 | { |
---|
2546 | UChar ucSegment = (UChar)pMask[x*2]; |
---|
2547 | AOF( ucSegment < 2 ); |
---|
2548 | |
---|
2549 | piDstU[x] = (ucSegment==uiValidSegment)?piSrcU[x]:DBBP_INVALID_SHORT; |
---|
2550 | piDstV[x] = (ucSegment==uiValidSegment)?piSrcV[x]:DBBP_INVALID_SHORT; |
---|
2551 | } |
---|
2552 | |
---|
2553 | piSrcU += uiSrcStrideC; |
---|
2554 | piSrcV += uiSrcStrideC; |
---|
2555 | piDstU += uiDstStrideC; |
---|
2556 | piDstV += uiDstStrideC; |
---|
2557 | pMask += 2*uiMaskStride; |
---|
2558 | } |
---|
2559 | } |
---|
2560 | #endif |
---|
2561 | |
---|
2562 | #if NH_3D_DBBP |
---|
2563 | Void TEncCu::xCheckRDCostInterDBBP( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU DEBUG_STRING_FN_DECLARE(sDebug), Bool bUseMRG ) |
---|
2564 | { |
---|
2565 | DEBUG_STRING_NEW(sTest) |
---|
2566 | AOF( !rpcTempCU->getSlice()->getIsDepth() ); |
---|
2567 | |
---|
2568 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
2569 | |
---|
2570 | #if NH_3D_VSO |
---|
2571 | if( m_pcRdCost->getUseRenModel() ) |
---|
2572 | { |
---|
2573 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y ); |
---|
2574 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( COMPONENT_Y ); |
---|
2575 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getAddr ( COMPONENT_Y ); |
---|
2576 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride( COMPONENT_Y ); |
---|
2577 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2578 | } |
---|
2579 | #endif |
---|
2580 | |
---|
2581 | UInt uiWidth = rpcTempCU->getWidth(0); |
---|
2582 | UInt uiHeight = rpcTempCU->getHeight(0); |
---|
2583 | AOF( uiWidth == uiHeight ); |
---|
2584 | |
---|
2585 | #if NH_3D_DBBP |
---|
2586 | if(uiWidth <= 8) |
---|
2587 | { |
---|
2588 | return; |
---|
2589 | } |
---|
2590 | #endif |
---|
2591 | |
---|
2592 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
2593 | |
---|
2594 | // fetch virtual depth block |
---|
2595 | UInt uiDepthStride = 0; |
---|
2596 | #if H_3D_FCO |
---|
2597 | Pel* pDepthPels = rpcTempCU->getVirtualDepthBlock(rpcTempCU->getZorderIdxInCU(), uiWidth, uiHeight, uiDepthStride); |
---|
2598 | #else |
---|
2599 | Pel* pDepthPels = rpcTempCU->getVirtualDepthBlock(0, uiWidth, uiHeight, uiDepthStride); |
---|
2600 | #endif |
---|
2601 | AOF( pDepthPels != NULL ); |
---|
2602 | AOF( uiDepthStride != 0 ); |
---|
2603 | |
---|
2604 | PartSize eVirtualPartSize = m_pcPredSearch->getPartitionSizeFromDepth(pDepthPels, uiDepthStride, uiWidth, rpcTempCU); |
---|
2605 | |
---|
2606 | // derive partitioning from depth |
---|
2607 | Bool pMask[MAX_CU_SIZE*MAX_CU_SIZE]; |
---|
2608 | Bool bValidMask = m_pcPredSearch->getSegmentMaskFromDepth(pDepthPels, uiDepthStride, uiWidth, uiHeight, pMask, rpcTempCU); |
---|
2609 | |
---|
2610 | if( !bValidMask ) |
---|
2611 | { |
---|
2612 | return; |
---|
2613 | } |
---|
2614 | |
---|
2615 | // find optimal motion/disparity vector for each segment |
---|
2616 | DisInfo originalDvInfo = rpcTempCU->getDvInfo(0); |
---|
2617 | DbbpTmpData* pDBBPTmpData = rpcTempCU->getDBBPTmpData(); |
---|
2618 | TComYuv* apPredYuv[2] = { m_ppcRecoYuvTemp[uhDepth], m_ppcPredYuvTemp[uhDepth] }; |
---|
2619 | |
---|
2620 | // find optimal motion vector fields for both segments (as 2Nx2N) |
---|
2621 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
2622 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
2623 | rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); |
---|
2624 | for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ ) |
---|
2625 | { |
---|
2626 | rpcTempCU->setDBBPFlagSubParts(true, 0, 0, uhDepth); |
---|
2627 | rpcTempCU->setDvInfoSubParts(originalDvInfo, 0, uhDepth); |
---|
2628 | |
---|
2629 | // invalidate all other segments in original YUV |
---|
2630 | xInvalidateOriginalSegments(m_ppcOrigYuv[uhDepth], m_ppcOrigYuvDBBP[uhDepth], pMask, uiSegment); |
---|
2631 | |
---|
2632 | // do motion estimation for this segment |
---|
2633 | m_pcRdCost->setUseMask(true); |
---|
2634 | rpcTempCU->getDBBPTmpData()->eVirtualPartSize = eVirtualPartSize; |
---|
2635 | rpcTempCU->getDBBPTmpData()->uiVirtualPartIndex = uiSegment; |
---|
2636 | m_pcPredSearch->predInterSearch( rpcTempCU, m_ppcOrigYuvDBBP[uhDepth], apPredYuv[uiSegment], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth] DEBUG_STRING_PASS_INTO(sTest), false, bUseMRG ); |
---|
2637 | m_pcRdCost->setUseMask(false); |
---|
2638 | |
---|
2639 | // extract motion parameters of full block for this segment |
---|
2640 | pDBBPTmpData->auhInterDir[uiSegment] = rpcTempCU->getInterDir(0); |
---|
2641 | |
---|
2642 | pDBBPTmpData->abMergeFlag[uiSegment] = rpcTempCU->getMergeFlag(0); |
---|
2643 | pDBBPTmpData->auhMergeIndex[uiSegment] = rpcTempCU->getMergeIndex(0); |
---|
2644 | |
---|
2645 | #if NH_3D_VSP |
---|
2646 | AOF( rpcTempCU->getSPIVMPFlag(0) == false ); |
---|
2647 | AOF( rpcTempCU->getVSPFlag(0) == 0 ); |
---|
2648 | #endif |
---|
2649 | |
---|
2650 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
2651 | { |
---|
2652 | RefPicList eRefList = (RefPicList)uiRefListIdx; |
---|
2653 | |
---|
2654 | pDBBPTmpData->acMvd[uiSegment][eRefList] = rpcTempCU->getCUMvField(eRefList)->getMvd(0); |
---|
2655 | pDBBPTmpData->aiMvpNum[uiSegment][eRefList] = rpcTempCU->getMVPNum(eRefList, 0); |
---|
2656 | pDBBPTmpData->aiMvpIdx[uiSegment][eRefList] = rpcTempCU->getMVPIdx(eRefList, 0); |
---|
2657 | |
---|
2658 | rpcTempCU->getMvField(rpcTempCU, 0, eRefList, pDBBPTmpData->acMvField[uiSegment][eRefList]); |
---|
2659 | } |
---|
2660 | } |
---|
2661 | |
---|
2662 | // store final motion/disparity information in each PU using derived partitioning |
---|
2663 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
2664 | rpcTempCU->setPartSizeSubParts ( eVirtualPartSize, 0, uhDepth ); |
---|
2665 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
2666 | |
---|
2667 | UInt uiPUOffset = ( g_auiPUOffset[UInt( eVirtualPartSize )] << ( ( rpcTempCU->getSlice()->getSPS()->getMaxTotalCUDepth() - uhDepth ) << 1 ) ) >> 4; |
---|
2668 | for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ ) |
---|
2669 | { |
---|
2670 | UInt uiPartAddr = uiSegment*uiPUOffset; |
---|
2671 | |
---|
2672 | rpcTempCU->setDBBPFlagSubParts(true, uiPartAddr, uiSegment, uhDepth); |
---|
2673 | |
---|
2674 | // now set stored information from 2Nx2N motion search to each partition |
---|
2675 | rpcTempCU->setInterDirSubParts(pDBBPTmpData->auhInterDir[uiSegment], uiPartAddr, uiSegment, uhDepth); // interprets depth relative to LCU level |
---|
2676 | |
---|
2677 | rpcTempCU->setMergeFlagSubParts(pDBBPTmpData->abMergeFlag[uiSegment], uiPartAddr, uiSegment, uhDepth); |
---|
2678 | rpcTempCU->setMergeIndexSubParts(pDBBPTmpData->auhMergeIndex[uiSegment], uiPartAddr, uiSegment, uhDepth); |
---|
2679 | |
---|
2680 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
2681 | { |
---|
2682 | RefPicList eRefList = (RefPicList)uiRefListIdx; |
---|
2683 | |
---|
2684 | rpcTempCU->getCUMvField( eRefList )->setAllMvd(pDBBPTmpData->acMvd[uiSegment][eRefList], eVirtualPartSize, uiPartAddr, 0, uiSegment); |
---|
2685 | rpcTempCU->setMVPNum(eRefList, uiPartAddr, pDBBPTmpData->aiMvpNum[uiSegment][eRefList]); |
---|
2686 | rpcTempCU->setMVPIdx(eRefList, uiPartAddr, pDBBPTmpData->aiMvpIdx[uiSegment][eRefList]); |
---|
2687 | |
---|
2688 | rpcTempCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], eVirtualPartSize, uiPartAddr, 0, uiSegment ); // interprets depth relative to rpcTempCU level |
---|
2689 | } |
---|
2690 | } |
---|
2691 | |
---|
2692 | // reconstruct final prediction signal by combining both segments |
---|
2693 | Int bitDepthY = rpcTempCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA); |
---|
2694 | m_pcPredSearch->combineSegmentsWithMask(apPredYuv, m_ppcPredYuvTemp[uhDepth], pMask, uiWidth, uiHeight, 0, eVirtualPartSize, bitDepthY); |
---|
2695 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false DEBUG_STRING_PASS_INTO(sTest) ); |
---|
2696 | |
---|
2697 | xCheckDQP( rpcTempCU ); |
---|
2698 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest) ); |
---|
2699 | } |
---|
2700 | #endif |
---|
2701 | #if NH_3D_DIS |
---|
2702 | Void TEncCu::xCheckRDCostDIS( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize DEBUG_STRING_FN_DECLARE(sDebug) ) |
---|
2703 | { |
---|
2704 | DEBUG_STRING_NEW(sTest) |
---|
2705 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
2706 | if( !rpcBestCU->getSlice()->getIsDepth() || (eSize != SIZE_2Nx2N)) |
---|
2707 | { |
---|
2708 | return; |
---|
2709 | } |
---|
2710 | |
---|
2711 | #if NH_MV |
---|
2712 | D_PRINT_INC_INDENT(g_traceModeCheck, "xCheckRDCostDIS" ); |
---|
2713 | #endif |
---|
2714 | |
---|
2715 | #if NH_3D_VSO // M5 |
---|
2716 | if( m_pcRdCost->getUseRenModel() ) |
---|
2717 | { |
---|
2718 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth ( COMPONENT_Y ); |
---|
2719 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight ( COMPONENT_Y ); |
---|
2720 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getAddr ( COMPONENT_Y ); |
---|
2721 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride ( COMPONENT_Y ); |
---|
2722 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2723 | } |
---|
2724 | #endif |
---|
2725 | |
---|
2726 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
2727 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
2728 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
2729 | rpcTempCU->setCUTransquantBypassSubParts( rpcTempCU->getCUTransquantBypass(0), 0, uiDepth ); |
---|
2730 | |
---|
2731 | rpcTempCU->setTrIdxSubParts(0, 0, uiDepth); |
---|
2732 | rpcTempCU->setCbfSubParts(0, COMPONENT_Y, 0, uiDepth); |
---|
2733 | rpcTempCU->setDISFlagSubParts(true, 0, uiDepth); |
---|
2734 | rpcTempCU->setIntraDirSubParts(CHANNEL_TYPE_LUMA, DC_IDX, 0, uiDepth); |
---|
2735 | #if NH_3D_SDC_INTRA |
---|
2736 | rpcTempCU->setSDCFlagSubParts( false, 0, uiDepth); |
---|
2737 | #endif |
---|
2738 | |
---|
2739 | UInt uiPreCalcDistC; |
---|
2740 | m_pcPredSearch ->estIntraPredDIS ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, false ); |
---|
2741 | |
---|
2742 | #if ENC_DEC_TRACE && NH_MV_ENC_DEC_TRAC |
---|
2743 | Int oldTraceCopyBack = g_traceCopyBack; |
---|
2744 | g_traceCopyBack = false; |
---|
2745 | #endif |
---|
2746 | m_ppcRecoYuvTemp[uiDepth]->copyToPicComponent(COMPONENT_Y, rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getCtuRsAddr(), rpcTempCU->getZorderIdxInCtu() ); |
---|
2747 | #if ENC_DEC_TRACE && NH_MV_ENC_DEC_TRAC |
---|
2748 | g_traceCopyBack = oldTraceCopyBack; |
---|
2749 | #endif |
---|
2750 | |
---|
2751 | m_pcEntropyCoder->resetBits(); |
---|
2752 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
2753 | { |
---|
2754 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
2755 | } |
---|
2756 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
2757 | m_pcEntropyCoder->encodeDIS( rpcTempCU, 0, true ); |
---|
2758 | |
---|
2759 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
2760 | |
---|
2761 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2762 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2763 | |
---|
2764 | #if NH_3D_VSO // M6 |
---|
2765 | if( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
2766 | { |
---|
2767 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2768 | } |
---|
2769 | else |
---|
2770 | #endif |
---|
2771 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2772 | |
---|
2773 | xCheckDQP( rpcTempCU ); |
---|
2774 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest) ); |
---|
2775 | #if NH_MV |
---|
2776 | D_DEC_INDENT( g_traceModeCheck ); |
---|
2777 | #endif |
---|
2778 | } |
---|
2779 | #endif |
---|
2780 | Void TEncCu::xCheckRDCostIntra( TComDataCU *&rpcBestCU, |
---|
2781 | TComDataCU *&rpcTempCU, |
---|
2782 | PartSize eSize |
---|
2783 | DEBUG_STRING_FN_DECLARE(sDebug) |
---|
2784 | #if NH_3D_ENC_DEPTH |
---|
2785 | , Bool bOnlyIVP |
---|
2786 | #endif |
---|
2787 | ) |
---|
2788 | { |
---|
2789 | DEBUG_STRING_NEW(sTest) |
---|
2790 | |
---|
2791 | if(getFastDeltaQp()) |
---|
2792 | { |
---|
2793 | const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS()); |
---|
2794 | const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>(sps.getLog2DiffMaxMinCodingBlockSize()), sps.getMaxCUHeight(), 32u); |
---|
2795 | if(rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxSize) |
---|
2796 | { |
---|
2797 | return; // only check necessary 2Nx2N Intra in fast deltaqp mode |
---|
2798 | } |
---|
2799 | } |
---|
2800 | #if NH_MV |
---|
2801 | D_PRINT_INC_INDENT (g_traceModeCheck, "xCheckRDCostIntra; eSize: " + n2s(eSize) ); |
---|
2802 | #endif |
---|
2803 | |
---|
2804 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
2805 | #if NH_3D_VSO // M5 |
---|
2806 | if( m_pcRdCost->getUseRenModel() ) |
---|
2807 | { |
---|
2808 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth ( COMPONENT_Y ); |
---|
2809 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight ( COMPONENT_Y ); |
---|
2810 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getAddr ( COMPONENT_Y ); |
---|
2811 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride ( COMPONENT_Y ); |
---|
2812 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2813 | } |
---|
2814 | #endif |
---|
2815 | |
---|
2816 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
2817 | #if NH_3D_DIS |
---|
2818 | rpcTempCU->setDISFlagSubParts( false, 0, uiDepth ); |
---|
2819 | #endif |
---|
2820 | |
---|
2821 | |
---|
2822 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
2823 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
2824 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uiDepth ); |
---|
2825 | |
---|
2826 | Pel resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE]; |
---|
2827 | |
---|
2828 | m_pcPredSearch->estIntraPredLumaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) |
---|
2829 | #if NH_3D_ENC_DEPTH |
---|
2830 | , bOnlyIVP |
---|
2831 | #endif |
---|
2832 | ); |
---|
2833 | |
---|
2834 | m_ppcRecoYuvTemp[uiDepth]->copyToPicComponent(COMPONENT_Y, rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getCtuRsAddr(), rpcTempCU->getZorderIdxInCtu() ); |
---|
2835 | |
---|
2836 | if (rpcBestCU->getPic()->getChromaFormat()!=CHROMA_400) |
---|
2837 | { |
---|
2838 | m_pcPredSearch->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) ); |
---|
2839 | } |
---|
2840 | |
---|
2841 | #if NH_3D_SDC_INTRA |
---|
2842 | if( rpcTempCU->getSDCFlag( 0 ) ) |
---|
2843 | { |
---|
2844 | assert( rpcTempCU->getTransformIdx(0) == 0 ); |
---|
2845 | assert( rpcTempCU->getCbf(0, COMPONENT_Y) == 1 ); |
---|
2846 | } |
---|
2847 | #endif |
---|
2848 | |
---|
2849 | m_pcEntropyCoder->resetBits(); |
---|
2850 | |
---|
2851 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
2852 | { |
---|
2853 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
2854 | } |
---|
2855 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
2856 | #if NH_3D_DIS |
---|
2857 | m_pcEntropyCoder->encodeDIS( rpcTempCU, 0, true ); |
---|
2858 | if(!rpcTempCU->getDISFlag(0)) |
---|
2859 | { |
---|
2860 | #endif |
---|
2861 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
2862 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
2863 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0 ); |
---|
2864 | m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true ); |
---|
2865 | #if NH_3D_SDC_INTRA |
---|
2866 | m_pcEntropyCoder->encodeSDCFlag( rpcTempCU, 0, true ); |
---|
2867 | #endif |
---|
2868 | |
---|
2869 | // Encode Coefficients |
---|
2870 | Bool bCodeDQP = getdQPFlag(); |
---|
2871 | Bool codeChromaQpAdjFlag = getCodeChromaQpAdjFlag(); |
---|
2872 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, bCodeDQP, codeChromaQpAdjFlag ); |
---|
2873 | setCodeChromaQpAdjFlag( codeChromaQpAdjFlag ); |
---|
2874 | setdQPFlag( bCodeDQP ); |
---|
2875 | #if NH_3D_DIS |
---|
2876 | } |
---|
2877 | #endif |
---|
2878 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
2879 | |
---|
2880 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2881 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2882 | #if NH_3D_VSO // M6 |
---|
2883 | if( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
2884 | { |
---|
2885 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2886 | } |
---|
2887 | else |
---|
2888 | #endif |
---|
2889 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2890 | |
---|
2891 | xCheckDQP( rpcTempCU ); |
---|
2892 | |
---|
2893 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest)); |
---|
2894 | |
---|
2895 | #if NH_MV |
---|
2896 | D_DEC_INDENT( g_traceModeCheck ); |
---|
2897 | #endif |
---|
2898 | } |
---|
2899 | |
---|
2900 | |
---|
2901 | /** Check R-D costs for a CU with PCM mode. |
---|
2902 | * \param rpcBestCU pointer to best mode CU data structure |
---|
2903 | * \param rpcTempCU pointer to testing mode CU data structure |
---|
2904 | * \returns Void |
---|
2905 | * |
---|
2906 | * \note Current PCM implementation encodes sample values in a lossless way. The distortion of PCM mode CUs are zero. PCM mode is selected if the best mode yields bits greater than that of PCM mode. |
---|
2907 | */ |
---|
2908 | Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
2909 | { |
---|
2910 | if(getFastDeltaQp()) |
---|
2911 | { |
---|
2912 | const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS()); |
---|
2913 | const UInt fastDeltaQPCuMaxPCMSize = Clip3((UInt)1<<sps.getPCMLog2MinSize(), (UInt)1<<sps.getPCMLog2MaxSize(), 32u); |
---|
2914 | if (rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxPCMSize) |
---|
2915 | { |
---|
2916 | return; // only check necessary PCM in fast deltaqp mode |
---|
2917 | } |
---|
2918 | } |
---|
2919 | |
---|
2920 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
2921 | |
---|
2922 | #if NH_3D_VSO // VERY NEW |
---|
2923 | if( m_pcRdCost->getUseRenModel() ) |
---|
2924 | { |
---|
2925 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth ( COMPONENT_Y ); |
---|
2926 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight ( COMPONENT_Y ); |
---|
2927 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getAddr ( COMPONENT_Y ); |
---|
2928 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride ( COMPONENT_Y ); |
---|
2929 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2930 | } |
---|
2931 | #endif |
---|
2932 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
2933 | #if NH_3D_DIS |
---|
2934 | rpcTempCU->setDISFlagSubParts( false, 0, uiDepth ); |
---|
2935 | #endif |
---|
2936 | rpcTempCU->setIPCMFlag(0, true); |
---|
2937 | rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); |
---|
2938 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
2939 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
2940 | rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth ); |
---|
2941 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uiDepth ); |
---|
2942 | |
---|
2943 | m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); |
---|
2944 | |
---|
2945 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
2946 | |
---|
2947 | m_pcEntropyCoder->resetBits(); |
---|
2948 | |
---|
2949 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
2950 | { |
---|
2951 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
2952 | } |
---|
2953 | |
---|
2954 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
2955 | #if NH_3D_DIS |
---|
2956 | m_pcEntropyCoder->encodeDIS( rpcTempCU, 0, true ); |
---|
2957 | #endif |
---|
2958 | m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); |
---|
2959 | m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); |
---|
2960 | m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); |
---|
2961 | #if NH_3D_SDC_INTRA |
---|
2962 | m_pcEntropyCoder->encodeSDCFlag( rpcTempCU, 0, true ); |
---|
2963 | #endif |
---|
2964 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
2965 | |
---|
2966 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2967 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2968 | #if NH_3D_VSO // M44 |
---|
2969 | if ( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
2970 | { |
---|
2971 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2972 | } |
---|
2973 | else |
---|
2974 | #endif |
---|
2975 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2976 | |
---|
2977 | xCheckDQP( rpcTempCU ); |
---|
2978 | DEBUG_STRING_NEW(a) |
---|
2979 | DEBUG_STRING_NEW(b) |
---|
2980 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(a) DEBUG_STRING_PASS_INTO(b)); |
---|
2981 | } |
---|
2982 | |
---|
2983 | /** check whether current try is the best with identifying the depth of current try |
---|
2984 | * \param rpcBestCU |
---|
2985 | * \param rpcTempCU |
---|
2986 | * \param uiDepth |
---|
2987 | */ |
---|
2988 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth DEBUG_STRING_FN_DECLARE(sParent) DEBUG_STRING_FN_DECLARE(sTest) DEBUG_STRING_PASS_INTO(Bool bAddSizeInfo) ) |
---|
2989 | { |
---|
2990 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
2991 | { |
---|
2992 | TComYuv* pcYuv; |
---|
2993 | // Change Information data |
---|
2994 | TComDataCU* pcCU = rpcBestCU; |
---|
2995 | rpcBestCU = rpcTempCU; |
---|
2996 | rpcTempCU = pcCU; |
---|
2997 | |
---|
2998 | // Change Prediction data |
---|
2999 | pcYuv = m_ppcPredYuvBest[uiDepth]; |
---|
3000 | m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; |
---|
3001 | m_ppcPredYuvTemp[uiDepth] = pcYuv; |
---|
3002 | |
---|
3003 | // Change Reconstruction data |
---|
3004 | pcYuv = m_ppcRecoYuvBest[uiDepth]; |
---|
3005 | m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; |
---|
3006 | m_ppcRecoYuvTemp[uiDepth] = pcYuv; |
---|
3007 | |
---|
3008 | pcYuv = NULL; |
---|
3009 | pcCU = NULL; |
---|
3010 | |
---|
3011 | // store temp best CI for next CU coding |
---|
3012 | m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
3013 | |
---|
3014 | |
---|
3015 | #if DEBUG_STRING |
---|
3016 | DEBUG_STRING_SWAP(sParent, sTest) |
---|
3017 | const PredMode predMode=rpcBestCU->getPredictionMode(0); |
---|
3018 | if ((DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode)) && bAddSizeInfo) |
---|
3019 | { |
---|
3020 | std::stringstream ss(stringstream::out); |
---|
3021 | ss <<"###: " << (predMode==MODE_INTRA?"Intra ":"Inter ") << partSizeToString[rpcBestCU->getPartitionSize(0)] << " CU at " << rpcBestCU->getCUPelX() << ", " << rpcBestCU->getCUPelY() << " width=" << UInt(rpcBestCU->getWidth(0)) << std::endl; |
---|
3022 | sParent+=ss.str(); |
---|
3023 | } |
---|
3024 | #endif |
---|
3025 | } |
---|
3026 | } |
---|
3027 | |
---|
3028 | Void TEncCu::xCheckDQP( TComDataCU* pcCU ) |
---|
3029 | { |
---|
3030 | UInt uiDepth = pcCU->getDepth( 0 ); |
---|
3031 | |
---|
3032 | const TComPPS &pps = *(pcCU->getSlice()->getPPS()); |
---|
3033 | if ( pps.getUseDQP() && uiDepth <= pps.getMaxCuDQPDepth() ) |
---|
3034 | { |
---|
3035 | if ( pcCU->getQtRootCbf( 0) ) |
---|
3036 | { |
---|
3037 | m_pcEntropyCoder->resetBits(); |
---|
3038 | m_pcEntropyCoder->encodeQP( pcCU, 0, false ); |
---|
3039 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
3040 | pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
3041 | #if NH_3D_VSO // M45 |
---|
3042 | if ( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
3043 | { |
---|
3044 | pcCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
3045 | } |
---|
3046 | else |
---|
3047 | #endif |
---|
3048 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
3049 | } |
---|
3050 | else |
---|
3051 | { |
---|
3052 | pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
3053 | } |
---|
3054 | } |
---|
3055 | } |
---|
3056 | |
---|
3057 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
3058 | { |
---|
3059 | pDst->iN = pSrc->iN; |
---|
3060 | for (Int i = 0; i < pSrc->iN; i++) |
---|
3061 | { |
---|
3062 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
3063 | } |
---|
3064 | } |
---|
3065 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth ) |
---|
3066 | { |
---|
3067 | UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; |
---|
3068 | UInt uiSrcBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiSrcDepth); |
---|
3069 | UInt uiBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiDepth); |
---|
3070 | UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
3071 | UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
3072 | UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; |
---|
3073 | m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
3074 | |
---|
3075 | #if ENC_DEC_TRACE && NH_MV_ENC_DEC_TRAC |
---|
3076 | Bool oldtraceCopyBack = g_traceCopyBack; |
---|
3077 | g_traceCopyBack = false; |
---|
3078 | #endif |
---|
3079 | m_ppcPredYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvPred (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
3080 | |
---|
3081 | #if ENC_DEC_TRACE && NH_MV_ENC_DEC_TRAC |
---|
3082 | g_traceCopyBack = oldtraceCopyBack; |
---|
3083 | #endif |
---|
3084 | } |
---|
3085 | |
---|
3086 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
3087 | { |
---|
3088 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
3089 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
3090 | m_ppcPredYuvBest[uiNextDepth]->copyToPartYuv( m_ppcPredYuvBest[uiCurrDepth], uiPartUnitIdx); |
---|
3091 | } |
---|
3092 | |
---|
3093 | /** Function for filling the PCM buffer of a CU using its original sample array |
---|
3094 | * \param pCU pointer to current CU |
---|
3095 | * \param pOrgYuv pointer to original sample array |
---|
3096 | */ |
---|
3097 | Void TEncCu::xFillPCMBuffer ( TComDataCU* pCU, TComYuv* pOrgYuv ) |
---|
3098 | { |
---|
3099 | const ChromaFormat format = pCU->getPic()->getChromaFormat(); |
---|
3100 | const UInt numberValidComponents = getNumberValidComponents(format); |
---|
3101 | for (UInt componentIndex = 0; componentIndex < numberValidComponents; componentIndex++) |
---|
3102 | { |
---|
3103 | const ComponentID component = ComponentID(componentIndex); |
---|
3104 | |
---|
3105 | const UInt width = pCU->getWidth(0) >> getComponentScaleX(component, format); |
---|
3106 | const UInt height = pCU->getHeight(0) >> getComponentScaleY(component, format); |
---|
3107 | |
---|
3108 | Pel *source = pOrgYuv->getAddr(component, 0, width); |
---|
3109 | Pel *destination = pCU->getPCMSample(component); |
---|
3110 | |
---|
3111 | const UInt sourceStride = pOrgYuv->getStride(component); |
---|
3112 | |
---|
3113 | for (Int line = 0; line < height; line++) |
---|
3114 | { |
---|
3115 | for (Int column = 0; column < width; column++) |
---|
3116 | { |
---|
3117 | destination[column] = source[column]; |
---|
3118 | } |
---|
3119 | |
---|
3120 | source += sourceStride; |
---|
3121 | destination += width; |
---|
3122 | } |
---|
3123 | } |
---|
3124 | } |
---|
3125 | |
---|
3126 | #if ADAPTIVE_QP_SELECTION |
---|
3127 | /** Collect ARL statistics from one block |
---|
3128 | */ |
---|
3129 | Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, TCoeff* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) |
---|
3130 | { |
---|
3131 | for( Int n = 0; n < NumCoeffInCU; n++ ) |
---|
3132 | { |
---|
3133 | TCoeff u = abs( rpcCoeff[ n ] ); |
---|
3134 | TCoeff absc = rpcArlCoeff[ n ]; |
---|
3135 | |
---|
3136 | if( u != 0 ) |
---|
3137 | { |
---|
3138 | if( u < LEVEL_RANGE ) |
---|
3139 | { |
---|
3140 | cSum[ u ] += ( Double )absc; |
---|
3141 | numSamples[ u ]++; |
---|
3142 | } |
---|
3143 | else |
---|
3144 | { |
---|
3145 | cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); |
---|
3146 | numSamples[ LEVEL_RANGE ]++; |
---|
3147 | } |
---|
3148 | } |
---|
3149 | } |
---|
3150 | |
---|
3151 | return 0; |
---|
3152 | } |
---|
3153 | |
---|
3154 | //! Collect ARL statistics from one CTU |
---|
3155 | Void TEncCu::xCtuCollectARLStats(TComDataCU* pCtu ) |
---|
3156 | { |
---|
3157 | Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to data type and quantization output |
---|
3158 | UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to data type and quantization output |
---|
3159 | |
---|
3160 | TCoeff* pCoeffY = pCtu->getCoeff(COMPONENT_Y); |
---|
3161 | TCoeff* pArlCoeffY = pCtu->getArlCoeff(COMPONENT_Y); |
---|
3162 | const TComSPS &sps = *(pCtu->getSlice()->getSPS()); |
---|
3163 | |
---|
3164 | const UInt uiMinCUWidth = sps.getMaxCUWidth() >> sps.getMaxTotalCUDepth(); // NOTE: ed - this is not the minimum CU width. It is the square-root of the number of coefficients per part. |
---|
3165 | const UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; // NOTE: ed - what is this? |
---|
3166 | |
---|
3167 | memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); |
---|
3168 | memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); |
---|
3169 | |
---|
3170 | // Collect stats to cSum[][] and numSamples[][] |
---|
3171 | for(Int i = 0; i < pCtu->getTotalNumPart(); i ++ ) |
---|
3172 | { |
---|
3173 | UInt uiTrIdx = pCtu->getTransformIdx(i); |
---|
3174 | |
---|
3175 | if(pCtu->isInter(i) && pCtu->getCbf( i, COMPONENT_Y, uiTrIdx ) ) |
---|
3176 | { |
---|
3177 | xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); |
---|
3178 | }//Note that only InterY is processed. QP rounding is based on InterY data only. |
---|
3179 | |
---|
3180 | pCoeffY += uiMinNumCoeffInCU; |
---|
3181 | pArlCoeffY += uiMinNumCoeffInCU; |
---|
3182 | } |
---|
3183 | |
---|
3184 | for(Int u=1; u<LEVEL_RANGE;u++) |
---|
3185 | { |
---|
3186 | m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; |
---|
3187 | m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; |
---|
3188 | } |
---|
3189 | m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; |
---|
3190 | m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; |
---|
3191 | } |
---|
3192 | #endif |
---|
3193 | |
---|
3194 | //! \} |
---|