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