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