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