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