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