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