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