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