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