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