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