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