[313] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
| 6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
| 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file TEncCu.cpp |
---|
| 35 | \brief Coding Unit (CU) encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include <stdio.h> |
---|
| 39 | #include "TEncTop.h" |
---|
| 40 | #include "TEncCu.h" |
---|
| 41 | #include "TEncAnalyze.h" |
---|
| 42 | |
---|
| 43 | #include <cmath> |
---|
| 44 | #include <algorithm> |
---|
| 45 | using namespace std; |
---|
| 46 | |
---|
| 47 | //! \ingroup TLibEncoder |
---|
| 48 | //! \{ |
---|
| 49 | |
---|
| 50 | // ==================================================================================================================== |
---|
| 51 | // Constructor / destructor / create / destroy |
---|
| 52 | // ==================================================================================================================== |
---|
| 53 | |
---|
| 54 | /** |
---|
| 55 | \param uiTotalDepth total number of allowable depth |
---|
| 56 | \param uiMaxWidth largest CU width |
---|
| 57 | \param uiMaxHeight largest CU height |
---|
| 58 | */ |
---|
| 59 | Void TEncCu::create(UChar uhTotalDepth, UInt uiMaxWidth, UInt uiMaxHeight) |
---|
| 60 | { |
---|
| 61 | Int i; |
---|
| 62 | |
---|
| 63 | m_uhTotalDepth = uhTotalDepth + 1; |
---|
| 64 | m_ppcBestCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
| 65 | m_ppcTempCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
| 66 | |
---|
| 67 | m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 68 | m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 69 | m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 70 | m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 71 | m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 72 | m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 73 | m_ppcOrigYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 74 | |
---|
| 75 | UInt uiNumPartitions; |
---|
| 76 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
| 77 | { |
---|
| 78 | uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 ); |
---|
| 79 | UInt uiWidth = uiMaxWidth >> i; |
---|
| 80 | UInt uiHeight = uiMaxHeight >> i; |
---|
| 81 | |
---|
| 82 | m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
| 83 | m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
| 84 | |
---|
| 85 | m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight); |
---|
| 86 | m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight); |
---|
| 87 | m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight); |
---|
| 88 | |
---|
| 89 | m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight); |
---|
| 90 | m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight); |
---|
| 91 | m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight); |
---|
| 92 | |
---|
| 93 | m_ppcOrigYuv [i] = new TComYuv; m_ppcOrigYuv [i]->create(uiWidth, uiHeight); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | m_bEncodeDQP = false; |
---|
| 97 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT |
---|
| 98 | m_LCUPredictionSAD = 0; |
---|
| 99 | m_addSADDepth = 0; |
---|
| 100 | m_temporalSAD = 0; |
---|
| 101 | #endif |
---|
| 102 | |
---|
| 103 | // initialize partition order. |
---|
| 104 | UInt* piTmp = &g_auiZscanToRaster[0]; |
---|
| 105 | initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp); |
---|
| 106 | initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
| 107 | |
---|
| 108 | // initialize conversion matrix from partition index to pel |
---|
| 109 | initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | Void TEncCu::destroy() |
---|
| 113 | { |
---|
| 114 | Int i; |
---|
| 115 | |
---|
| 116 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
| 117 | { |
---|
| 118 | if(m_ppcBestCU[i]) |
---|
| 119 | { |
---|
| 120 | m_ppcBestCU[i]->destroy(); delete m_ppcBestCU[i]; m_ppcBestCU[i] = NULL; |
---|
| 121 | } |
---|
| 122 | if(m_ppcTempCU[i]) |
---|
| 123 | { |
---|
| 124 | m_ppcTempCU[i]->destroy(); delete m_ppcTempCU[i]; m_ppcTempCU[i] = NULL; |
---|
| 125 | } |
---|
| 126 | if(m_ppcPredYuvBest[i]) |
---|
| 127 | { |
---|
| 128 | m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL; |
---|
| 129 | } |
---|
| 130 | if(m_ppcResiYuvBest[i]) |
---|
| 131 | { |
---|
| 132 | m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL; |
---|
| 133 | } |
---|
| 134 | if(m_ppcRecoYuvBest[i]) |
---|
| 135 | { |
---|
| 136 | m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL; |
---|
| 137 | } |
---|
| 138 | if(m_ppcPredYuvTemp[i]) |
---|
| 139 | { |
---|
| 140 | m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL; |
---|
| 141 | } |
---|
| 142 | if(m_ppcResiYuvTemp[i]) |
---|
| 143 | { |
---|
| 144 | m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL; |
---|
| 145 | } |
---|
| 146 | if(m_ppcRecoYuvTemp[i]) |
---|
| 147 | { |
---|
| 148 | m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL; |
---|
| 149 | } |
---|
| 150 | if(m_ppcOrigYuv[i]) |
---|
| 151 | { |
---|
| 152 | m_ppcOrigYuv[i]->destroy(); delete m_ppcOrigYuv[i]; m_ppcOrigYuv[i] = NULL; |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | if(m_ppcBestCU) |
---|
| 156 | { |
---|
| 157 | delete [] m_ppcBestCU; |
---|
| 158 | m_ppcBestCU = NULL; |
---|
| 159 | } |
---|
| 160 | if(m_ppcTempCU) |
---|
| 161 | { |
---|
| 162 | delete [] m_ppcTempCU; |
---|
| 163 | m_ppcTempCU = NULL; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | if(m_ppcPredYuvBest) |
---|
| 167 | { |
---|
| 168 | delete [] m_ppcPredYuvBest; |
---|
| 169 | m_ppcPredYuvBest = NULL; |
---|
| 170 | } |
---|
| 171 | if(m_ppcResiYuvBest) |
---|
| 172 | { |
---|
| 173 | delete [] m_ppcResiYuvBest; |
---|
| 174 | m_ppcResiYuvBest = NULL; |
---|
| 175 | } |
---|
| 176 | if(m_ppcRecoYuvBest) |
---|
| 177 | { |
---|
| 178 | delete [] m_ppcRecoYuvBest; |
---|
| 179 | m_ppcRecoYuvBest = NULL; |
---|
| 180 | } |
---|
| 181 | if(m_ppcPredYuvTemp) |
---|
| 182 | { |
---|
| 183 | delete [] m_ppcPredYuvTemp; |
---|
| 184 | m_ppcPredYuvTemp = NULL; |
---|
| 185 | } |
---|
| 186 | if(m_ppcResiYuvTemp) |
---|
| 187 | { |
---|
| 188 | delete [] m_ppcResiYuvTemp; |
---|
| 189 | m_ppcResiYuvTemp = NULL; |
---|
| 190 | } |
---|
| 191 | if(m_ppcRecoYuvTemp) |
---|
| 192 | { |
---|
| 193 | delete [] m_ppcRecoYuvTemp; |
---|
| 194 | m_ppcRecoYuvTemp = NULL; |
---|
| 195 | } |
---|
| 196 | if(m_ppcOrigYuv) |
---|
| 197 | { |
---|
| 198 | delete [] m_ppcOrigYuv; |
---|
| 199 | m_ppcOrigYuv = NULL; |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | /** \param pcEncTop pointer of encoder class |
---|
| 204 | */ |
---|
| 205 | Void TEncCu::init( TEncTop* pcEncTop ) |
---|
| 206 | { |
---|
| 207 | m_pcEncCfg = pcEncTop; |
---|
| 208 | m_pcPredSearch = pcEncTop->getPredSearch(); |
---|
| 209 | m_pcTrQuant = pcEncTop->getTrQuant(); |
---|
| 210 | m_pcBitCounter = pcEncTop->getBitCounter(); |
---|
| 211 | m_pcRdCost = pcEncTop->getRdCost(); |
---|
| 212 | |
---|
| 213 | #if SVC_EXTENSION |
---|
| 214 | m_ppcTEncTop = pcEncTop->getLayerEnc(); |
---|
| 215 | for(UInt i=0 ; i< m_uhTotalDepth-1 ; i++) |
---|
| 216 | { |
---|
| 217 | m_ppcBestCU[i]->setLayerId(pcEncTop->getLayerId()); |
---|
| 218 | m_ppcTempCU[i]->setLayerId(pcEncTop->getLayerId()); |
---|
| 219 | } |
---|
| 220 | #endif |
---|
| 221 | |
---|
| 222 | m_pcEntropyCoder = pcEncTop->getEntropyCoder(); |
---|
| 223 | m_pcCavlcCoder = pcEncTop->getCavlcCoder(); |
---|
| 224 | m_pcSbacCoder = pcEncTop->getSbacCoder(); |
---|
| 225 | m_pcBinCABAC = pcEncTop->getBinCABAC(); |
---|
| 226 | |
---|
| 227 | m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder(); |
---|
| 228 | m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder(); |
---|
| 229 | |
---|
| 230 | m_bUseSBACRD = pcEncTop->getUseSBACRD(); |
---|
| 231 | m_pcRateCtrl = pcEncTop->getRateCtrl(); |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | // ==================================================================================================================== |
---|
| 235 | // Public member functions |
---|
| 236 | // ==================================================================================================================== |
---|
| 237 | |
---|
| 238 | /** \param rpcCU pointer of CU data class |
---|
| 239 | */ |
---|
| 240 | Void TEncCu::compressCU( TComDataCU*& rpcCU ) |
---|
| 241 | { |
---|
| 242 | // initialize CU data |
---|
| 243 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
| 244 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
| 245 | |
---|
| 246 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT |
---|
| 247 | m_addSADDepth = 0; |
---|
| 248 | m_LCUPredictionSAD = 0; |
---|
| 249 | m_temporalSAD = 0; |
---|
| 250 | #endif |
---|
| 251 | |
---|
| 252 | // analysis of CU |
---|
| 253 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
---|
| 254 | |
---|
| 255 | #if ADAPTIVE_QP_SELECTION |
---|
| 256 | if( m_pcEncCfg->getUseAdaptQpSelect() ) |
---|
| 257 | { |
---|
| 258 | if(rpcCU->getSlice()->getSliceType()!=I_SLICE) //IIII |
---|
| 259 | { |
---|
| 260 | xLcuCollectARLStats( rpcCU); |
---|
| 261 | } |
---|
| 262 | } |
---|
| 263 | #endif |
---|
| 264 | } |
---|
| 265 | /** \param pcCU pointer of CU data class |
---|
| 266 | */ |
---|
| 267 | Void TEncCu::encodeCU ( TComDataCU* pcCU ) |
---|
| 268 | { |
---|
| 269 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
| 270 | { |
---|
| 271 | setdQPFlag(true); |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | // Encode CU data |
---|
| 275 | xEncodeCU( pcCU, 0, 0 ); |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | // ==================================================================================================================== |
---|
| 279 | // Protected member functions |
---|
| 280 | // ==================================================================================================================== |
---|
| 281 | /** Derive small set of test modes for AMP encoder speed-up |
---|
| 282 | *\param rpcBestCU |
---|
| 283 | *\param eParentPartSize |
---|
| 284 | *\param bTestAMP_Hor |
---|
| 285 | *\param bTestAMP_Ver |
---|
| 286 | *\param bTestMergeAMP_Hor |
---|
| 287 | *\param bTestMergeAMP_Ver |
---|
| 288 | *\returns Void |
---|
| 289 | */ |
---|
| 290 | #if AMP_ENC_SPEEDUP |
---|
| 291 | #if AMP_MRG |
---|
| 292 | Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver) |
---|
| 293 | #else |
---|
| 294 | Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver) |
---|
| 295 | #endif |
---|
| 296 | { |
---|
| 297 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
| 298 | { |
---|
| 299 | bTestAMP_Hor = true; |
---|
| 300 | } |
---|
| 301 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
| 302 | { |
---|
| 303 | bTestAMP_Ver = true; |
---|
| 304 | } |
---|
| 305 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->getMergeFlag(0) == false && rpcBestCU->isSkipped(0) == false ) |
---|
| 306 | { |
---|
| 307 | bTestAMP_Hor = true; |
---|
| 308 | bTestAMP_Ver = true; |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | #if AMP_MRG |
---|
| 312 | //! Utilizing the partition size of parent PU |
---|
| 313 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
| 314 | { |
---|
| 315 | bTestMergeAMP_Hor = true; |
---|
| 316 | bTestMergeAMP_Ver = true; |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | if ( eParentPartSize == SIZE_NONE ) //! if parent is intra |
---|
| 320 | { |
---|
| 321 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
| 322 | { |
---|
| 323 | bTestMergeAMP_Hor = true; |
---|
| 324 | } |
---|
| 325 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
| 326 | { |
---|
| 327 | bTestMergeAMP_Ver = true; |
---|
| 328 | } |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->isSkipped(0) == false ) |
---|
| 332 | { |
---|
| 333 | bTestMergeAMP_Hor = true; |
---|
| 334 | bTestMergeAMP_Ver = true; |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | if ( rpcBestCU->getWidth(0) == 64 ) |
---|
| 338 | { |
---|
| 339 | bTestAMP_Hor = false; |
---|
| 340 | bTestAMP_Ver = false; |
---|
| 341 | } |
---|
| 342 | #else |
---|
| 343 | //! Utilizing the partition size of parent PU |
---|
| 344 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
| 345 | { |
---|
| 346 | bTestAMP_Hor = true; |
---|
| 347 | bTestAMP_Ver = true; |
---|
| 348 | } |
---|
| 349 | |
---|
| 350 | if ( eParentPartSize == SIZE_2Nx2N ) |
---|
| 351 | { |
---|
| 352 | bTestAMP_Hor = false; |
---|
| 353 | bTestAMP_Ver = false; |
---|
| 354 | } |
---|
| 355 | #endif |
---|
| 356 | } |
---|
| 357 | #endif |
---|
| 358 | |
---|
| 359 | // ==================================================================================================================== |
---|
| 360 | // Protected member functions |
---|
| 361 | // ==================================================================================================================== |
---|
| 362 | /** Compress a CU block recursively with enabling sub-LCU-level delta QP |
---|
| 363 | *\param rpcBestCU |
---|
| 364 | *\param rpcTempCU |
---|
| 365 | *\param uiDepth |
---|
| 366 | *\returns Void |
---|
| 367 | * |
---|
| 368 | *- for loop of QP value to compress the current CU with all possible QP |
---|
| 369 | */ |
---|
| 370 | #if AMP_ENC_SPEEDUP |
---|
| 371 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth, PartSize eParentPartSize ) |
---|
| 372 | #else |
---|
| 373 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
| 374 | #endif |
---|
| 375 | { |
---|
| 376 | TComPic* pcPic = rpcBestCU->getPic(); |
---|
| 377 | |
---|
| 378 | // get Original YUV data from picture |
---|
| 379 | m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
| 380 | |
---|
| 381 | // variable for Early CU determination |
---|
| 382 | Bool bSubBranch = true; |
---|
| 383 | |
---|
| 384 | // variable for Cbf fast mode PU decision |
---|
| 385 | Bool doNotBlockPu = true; |
---|
| 386 | Bool earlyDetectionSkipMode = false; |
---|
| 387 | |
---|
| 388 | Bool bBoundary = false; |
---|
| 389 | UInt uiLPelX = rpcBestCU->getCUPelX(); |
---|
| 390 | UInt uiRPelX = uiLPelX + rpcBestCU->getWidth(0) - 1; |
---|
| 391 | UInt uiTPelY = rpcBestCU->getCUPelY(); |
---|
| 392 | UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1; |
---|
| 393 | |
---|
| 394 | Int iBaseQP = xComputeQP( rpcBestCU, uiDepth ); |
---|
| 395 | Int iMinQP; |
---|
| 396 | Int iMaxQP; |
---|
| 397 | Bool isAddLowestQP = false; |
---|
[389] | 398 | #if REPN_FORMAT_IN_VPS |
---|
| 399 | Int lowestQP = -rpcTempCU->getSlice()->getQpBDOffsetY(); |
---|
| 400 | #else |
---|
[313] | 401 | Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
[389] | 402 | #endif |
---|
[313] | 403 | |
---|
| 404 | if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
| 405 | { |
---|
| 406 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
[389] | 407 | #if REPN_FORMAT_IN_VPS |
---|
[313] | 408 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
| 409 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
[389] | 410 | #else |
---|
| 411 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
| 412 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
| 413 | #endif |
---|
[313] | 414 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
| 415 | { |
---|
| 416 | isAddLowestQP = true; |
---|
| 417 | iMinQP = iMinQP - 1; |
---|
| 418 | } |
---|
| 419 | } |
---|
| 420 | else |
---|
| 421 | { |
---|
| 422 | iMinQP = rpcTempCU->getQP(0); |
---|
| 423 | iMaxQP = rpcTempCU->getQP(0); |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 427 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
| 428 | { |
---|
| 429 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
| 430 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
| 431 | } |
---|
| 432 | #else |
---|
| 433 | if(m_pcEncCfg->getUseRateCtrl()) |
---|
| 434 | { |
---|
| 435 | Int qp = m_pcRateCtrl->getUnitQP(); |
---|
| 436 | iMinQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
| 437 | iMaxQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
| 438 | } |
---|
| 439 | #endif |
---|
| 440 | |
---|
| 441 | // If slice start or slice end is within this cu... |
---|
| 442 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
| 443 | Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart(); |
---|
| 444 | Bool bSliceEnd = (pcSlice->getSliceSegmentCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart()); |
---|
[389] | 445 | #if REPN_FORMAT_IN_VPS |
---|
| 446 | Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getPicHeightInLumaSamples() ); |
---|
| 447 | #else |
---|
[313] | 448 | Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ); |
---|
[389] | 449 | #endif |
---|
[313] | 450 | // We need to split, so don't try these modes. |
---|
| 451 | if(!bSliceEnd && !bSliceStart && bInsidePicture ) |
---|
| 452 | { |
---|
| 453 | #if (ENCODER_FAST_MODE) |
---|
| 454 | Bool testInter = true; |
---|
| 455 | if (rpcBestCU->getLayerId() > 0) |
---|
| 456 | { |
---|
[431] | 457 | if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx()) |
---|
| 458 | { |
---|
| 459 | testInter = false; |
---|
| 460 | } |
---|
| 461 | if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx()) |
---|
| 462 | { |
---|
| 463 | testInter = false; |
---|
| 464 | } |
---|
[313] | 465 | #if M0457_IL_SAMPLE_PRED_ONLY_FLAG |
---|
[431] | 466 | if( pcSlice->getInterLayerSamplePredOnlyFlag() ) |
---|
| 467 | { |
---|
| 468 | testInter = false; |
---|
| 469 | } |
---|
[313] | 470 | #endif |
---|
| 471 | } |
---|
| 472 | #endif |
---|
| 473 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
| 474 | { |
---|
| 475 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
| 476 | { |
---|
| 477 | iQP = lowestQP; |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 481 | |
---|
| 482 | // do inter modes, SKIP and 2Nx2N |
---|
| 483 | #if (ENCODER_FAST_MODE == 1) |
---|
| 484 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter ) |
---|
| 485 | #else |
---|
| 486 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
| 487 | #endif |
---|
| 488 | { |
---|
| 489 | // 2Nx2N |
---|
| 490 | if(m_pcEncCfg->getUseEarlySkipDetection()) |
---|
| 491 | { |
---|
| 492 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N |
---|
| 493 | } |
---|
| 494 | // SKIP |
---|
| 495 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N |
---|
| 496 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[431] | 497 | |
---|
[313] | 498 | #if (ENCODER_FAST_MODE == 2) |
---|
| 499 | if (testInter) |
---|
| 500 | { |
---|
| 501 | #endif |
---|
| 502 | if(!m_pcEncCfg->getUseEarlySkipDetection()) |
---|
| 503 | { |
---|
| 504 | // 2Nx2N, NxN |
---|
[431] | 505 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 506 | if(m_pcEncCfg->getUseCbfFastMode()) |
---|
[313] | 507 | { |
---|
[431] | 508 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
[313] | 509 | } |
---|
| 510 | } |
---|
| 511 | #if (ENCODER_FAST_MODE == 2) |
---|
[431] | 512 | } |
---|
[313] | 513 | #endif |
---|
| 514 | } |
---|
| 515 | |
---|
| 516 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
| 517 | { |
---|
| 518 | iQP = iMinQP; |
---|
| 519 | } |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT |
---|
| 523 | if ( uiDepth <= m_addSADDepth ) |
---|
| 524 | { |
---|
| 525 | m_LCUPredictionSAD += m_temporalSAD; |
---|
| 526 | m_addSADDepth = uiDepth; |
---|
| 527 | } |
---|
| 528 | #endif |
---|
| 529 | |
---|
| 530 | if(!earlyDetectionSkipMode) |
---|
| 531 | { |
---|
| 532 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
| 533 | { |
---|
| 534 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
| 535 | { |
---|
| 536 | iQP = lowestQP; |
---|
| 537 | } |
---|
| 538 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 539 | |
---|
| 540 | // do inter modes, NxN, 2NxN, and Nx2N |
---|
| 541 | #if (ENCODER_FAST_MODE) |
---|
[431] | 542 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter ) |
---|
[313] | 543 | #else |
---|
| 544 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
| 545 | #endif |
---|
| 546 | { |
---|
| 547 | // 2Nx2N, NxN |
---|
[431] | 548 | if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) )) |
---|
[313] | 549 | { |
---|
[431] | 550 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu) |
---|
[313] | 551 | { |
---|
[431] | 552 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
| 553 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[313] | 554 | } |
---|
| 555 | } |
---|
| 556 | |
---|
| 557 | // 2NxN, Nx2N |
---|
| 558 | if(doNotBlockPu) |
---|
| 559 | { |
---|
| 560 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N ); |
---|
| 561 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 562 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
| 563 | { |
---|
| 564 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 565 | } |
---|
| 566 | } |
---|
| 567 | if(doNotBlockPu) |
---|
| 568 | { |
---|
| 569 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN ); |
---|
| 570 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 571 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN) |
---|
| 572 | { |
---|
| 573 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 574 | } |
---|
| 575 | } |
---|
| 576 | |
---|
| 577 | #if 1 |
---|
| 578 | //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
---|
| 579 | if( pcPic->getSlice(0)->getSPS()->getAMPAcc(uiDepth) ) |
---|
| 580 | { |
---|
| 581 | #if AMP_ENC_SPEEDUP |
---|
| 582 | Bool bTestAMP_Hor = false, bTestAMP_Ver = false; |
---|
| 583 | |
---|
| 584 | #if AMP_MRG |
---|
| 585 | Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false; |
---|
| 586 | |
---|
| 587 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver); |
---|
| 588 | #else |
---|
| 589 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver); |
---|
| 590 | #endif |
---|
| 591 | |
---|
| 592 | //! Do horizontal AMP |
---|
| 593 | if ( bTestAMP_Hor ) |
---|
| 594 | { |
---|
| 595 | if(doNotBlockPu) |
---|
| 596 | { |
---|
| 597 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
| 598 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 599 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
| 600 | { |
---|
| 601 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 602 | } |
---|
| 603 | } |
---|
| 604 | if(doNotBlockPu) |
---|
| 605 | { |
---|
| 606 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
| 607 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 608 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
| 609 | { |
---|
| 610 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 611 | } |
---|
| 612 | } |
---|
| 613 | } |
---|
| 614 | #if AMP_MRG |
---|
| 615 | else if ( bTestMergeAMP_Hor ) |
---|
| 616 | { |
---|
| 617 | if(doNotBlockPu) |
---|
| 618 | { |
---|
| 619 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true ); |
---|
| 620 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 621 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
| 622 | { |
---|
| 623 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 624 | } |
---|
| 625 | } |
---|
| 626 | if(doNotBlockPu) |
---|
| 627 | { |
---|
| 628 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true ); |
---|
| 629 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 630 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
| 631 | { |
---|
| 632 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 633 | } |
---|
| 634 | } |
---|
| 635 | } |
---|
| 636 | #endif |
---|
| 637 | |
---|
| 638 | //! Do horizontal AMP |
---|
| 639 | if ( bTestAMP_Ver ) |
---|
| 640 | { |
---|
| 641 | if(doNotBlockPu) |
---|
| 642 | { |
---|
| 643 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
| 644 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 645 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
| 646 | { |
---|
| 647 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 648 | } |
---|
| 649 | } |
---|
| 650 | if(doNotBlockPu) |
---|
| 651 | { |
---|
| 652 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
| 653 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 654 | } |
---|
| 655 | } |
---|
| 656 | #if AMP_MRG |
---|
| 657 | else if ( bTestMergeAMP_Ver ) |
---|
| 658 | { |
---|
| 659 | if(doNotBlockPu) |
---|
| 660 | { |
---|
| 661 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true ); |
---|
| 662 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 663 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
| 664 | { |
---|
| 665 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 666 | } |
---|
| 667 | } |
---|
| 668 | if(doNotBlockPu) |
---|
| 669 | { |
---|
| 670 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true ); |
---|
| 671 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 672 | } |
---|
| 673 | } |
---|
| 674 | #endif |
---|
| 675 | |
---|
| 676 | #else |
---|
| 677 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
| 678 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 679 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
| 680 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 681 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
| 682 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 683 | |
---|
| 684 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
| 685 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 686 | |
---|
| 687 | #endif |
---|
| 688 | } |
---|
| 689 | #endif |
---|
| 690 | } |
---|
| 691 | |
---|
| 692 | // do normal intra modes |
---|
| 693 | // speedup for inter frames |
---|
| 694 | #if (ENCODER_FAST_MODE) |
---|
| 695 | if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
| 696 | !testInter || |
---|
| 697 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
| 698 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
| 699 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) // avoid very complex intra if it is unlikely |
---|
| 700 | #else |
---|
| 701 | if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
| 702 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
| 703 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
| 704 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) // avoid very complex intra if it is unlikely |
---|
| 705 | #endif |
---|
| 706 | { |
---|
| 707 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); |
---|
| 708 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 709 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 710 | { |
---|
| 711 | if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) ) |
---|
| 712 | { |
---|
| 713 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
| 714 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 715 | } |
---|
| 716 | } |
---|
| 717 | } |
---|
| 718 | |
---|
| 719 | // test PCM |
---|
| 720 | if(pcPic->getSlice(0)->getSPS()->getUsePCM() |
---|
| 721 | && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize()) |
---|
| 722 | && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) ) |
---|
| 723 | { |
---|
| 724 | UInt uiRawBits = (2 * g_bitDepthY + g_bitDepthC) * rpcBestCU->getWidth(0) * rpcBestCU->getHeight(0) / 2; |
---|
| 725 | UInt uiBestBits = rpcBestCU->getTotalBits(); |
---|
| 726 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0))) |
---|
| 727 | { |
---|
| 728 | xCheckIntraPCM (rpcBestCU, rpcTempCU); |
---|
| 729 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 730 | } |
---|
| 731 | } |
---|
| 732 | #if (ENCODER_FAST_MODE) |
---|
| 733 | if(pcPic->getLayerId() > 0) |
---|
| 734 | { |
---|
| 735 | for(Int refLayer = 0; refLayer < pcSlice->getActiveNumILRRefIdx(); refLayer++) |
---|
| 736 | { |
---|
| 737 | xCheckRDCostILRUni( rpcBestCU, rpcTempCU, pcSlice->getInterLayerPredLayerIdc(refLayer)); |
---|
| 738 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 739 | } |
---|
| 740 | } |
---|
| 741 | #endif |
---|
| 742 | |
---|
| 743 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
| 744 | { |
---|
| 745 | iQP = iMinQP; |
---|
| 746 | } |
---|
| 747 | } |
---|
| 748 | } |
---|
| 749 | |
---|
| 750 | m_pcEntropyCoder->resetBits(); |
---|
| 751 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
---|
| 752 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
| 753 | if(m_pcEncCfg->getUseSBACRD()) |
---|
| 754 | { |
---|
| 755 | rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 756 | } |
---|
| 757 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
| 758 | |
---|
| 759 | // Early CU determination |
---|
| 760 | if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) ) |
---|
| 761 | { |
---|
| 762 | bSubBranch = false; |
---|
| 763 | } |
---|
| 764 | else |
---|
| 765 | { |
---|
| 766 | bSubBranch = true; |
---|
| 767 | } |
---|
| 768 | } |
---|
| 769 | else if(!(bSliceEnd && bInsidePicture)) |
---|
| 770 | { |
---|
| 771 | bBoundary = true; |
---|
| 772 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT |
---|
| 773 | m_addSADDepth++; |
---|
| 774 | #endif |
---|
| 775 | } |
---|
| 776 | |
---|
| 777 | // copy orginal YUV samples to PCM buffer |
---|
| 778 | if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false)) |
---|
| 779 | { |
---|
| 780 | xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]); |
---|
| 781 | } |
---|
| 782 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
| 783 | { |
---|
| 784 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
[389] | 785 | #if REPN_FORMAT_IN_VPS |
---|
| 786 | iMinQP = Clip3( -rpcTempCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
| 787 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
| 788 | #else |
---|
[313] | 789 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
| 790 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
[389] | 791 | #endif |
---|
[313] | 792 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
| 793 | { |
---|
| 794 | isAddLowestQP = true; |
---|
| 795 | iMinQP = iMinQP - 1; |
---|
| 796 | } |
---|
| 797 | } |
---|
| 798 | else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
| 799 | { |
---|
| 800 | iMinQP = iBaseQP; |
---|
| 801 | iMaxQP = iBaseQP; |
---|
| 802 | } |
---|
| 803 | else |
---|
| 804 | { |
---|
| 805 | Int iStartQP; |
---|
| 806 | if( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr()) |
---|
| 807 | { |
---|
| 808 | iStartQP = rpcTempCU->getQP(0); |
---|
| 809 | } |
---|
| 810 | else |
---|
| 811 | { |
---|
| 812 | UInt uiCurSliceStartPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
| 813 | iStartQP = rpcTempCU->getQP(uiCurSliceStartPartIdx); |
---|
| 814 | } |
---|
| 815 | iMinQP = iStartQP; |
---|
| 816 | iMaxQP = iStartQP; |
---|
| 817 | } |
---|
| 818 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 819 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
| 820 | { |
---|
| 821 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
| 822 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
| 823 | } |
---|
| 824 | #else |
---|
| 825 | if(m_pcEncCfg->getUseRateCtrl()) |
---|
| 826 | { |
---|
| 827 | Int qp = m_pcRateCtrl->getUnitQP(); |
---|
| 828 | iMinQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
| 829 | iMaxQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
| 830 | } |
---|
| 831 | #endif |
---|
| 832 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
| 833 | { |
---|
| 834 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
| 835 | { |
---|
| 836 | iQP = lowestQP; |
---|
| 837 | } |
---|
| 838 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 839 | |
---|
| 840 | // further split |
---|
[431] | 841 | if( bSubBranch && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
[313] | 842 | { |
---|
| 843 | UChar uhNextDepth = uiDepth+1; |
---|
| 844 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
| 845 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
| 846 | |
---|
| 847 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
| 848 | { |
---|
| 849 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
| 850 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
| 851 | |
---|
| 852 | Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getSliceSegmentCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
[389] | 853 | #if REPN_FORMAT_IN_VPS |
---|
| 854 | if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getPicHeightInLumaSamples() ) ) |
---|
| 855 | #else |
---|
[313] | 856 | if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
[389] | 857 | #endif |
---|
[313] | 858 | { |
---|
| 859 | if( m_bUseSBACRD ) |
---|
| 860 | { |
---|
| 861 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
| 862 | { |
---|
| 863 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
| 864 | } |
---|
| 865 | else |
---|
| 866 | { |
---|
| 867 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
| 868 | } |
---|
| 869 | } |
---|
| 870 | |
---|
| 871 | #if AMP_ENC_SPEEDUP |
---|
| 872 | if ( rpcBestCU->isIntra(0) ) |
---|
| 873 | { |
---|
| 874 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, SIZE_NONE ); |
---|
| 875 | } |
---|
| 876 | else |
---|
| 877 | { |
---|
| 878 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, rpcBestCU->getPartitionSize(0) ); |
---|
| 879 | } |
---|
| 880 | #else |
---|
| 881 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
---|
| 882 | #endif |
---|
| 883 | |
---|
| 884 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
| 885 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
| 886 | } |
---|
| 887 | else if (bInSlice) |
---|
| 888 | { |
---|
| 889 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
| 890 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
| 891 | } |
---|
| 892 | } |
---|
| 893 | |
---|
| 894 | if( !bBoundary ) |
---|
| 895 | { |
---|
| 896 | m_pcEntropyCoder->resetBits(); |
---|
| 897 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
| 898 | |
---|
| 899 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
| 900 | if(m_pcEncCfg->getUseSBACRD()) |
---|
| 901 | { |
---|
| 902 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 903 | } |
---|
| 904 | } |
---|
| 905 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 906 | |
---|
| 907 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) |
---|
| 908 | { |
---|
| 909 | Bool hasResidual = false; |
---|
| 910 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
| 911 | { |
---|
| 912 | if( ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getSliceSegmentCurStartCUAddr() ) && |
---|
| 913 | ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) |
---|
| 914 | { |
---|
| 915 | hasResidual = true; |
---|
| 916 | break; |
---|
| 917 | } |
---|
| 918 | } |
---|
| 919 | |
---|
| 920 | UInt uiTargetPartIdx; |
---|
| 921 | if ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getSliceSegmentCurStartCUAddr() ) |
---|
| 922 | { |
---|
| 923 | uiTargetPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
| 924 | } |
---|
| 925 | else |
---|
| 926 | { |
---|
| 927 | uiTargetPartIdx = 0; |
---|
| 928 | } |
---|
| 929 | if ( hasResidual ) |
---|
| 930 | { |
---|
| 931 | #if !RDO_WITHOUT_DQP_BITS |
---|
| 932 | m_pcEntropyCoder->resetBits(); |
---|
| 933 | m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false ); |
---|
| 934 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
| 935 | if(m_pcEncCfg->getUseSBACRD()) |
---|
| 936 | { |
---|
| 937 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 938 | } |
---|
| 939 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 940 | #endif |
---|
| 941 | |
---|
| 942 | Bool foundNonZeroCbf = false; |
---|
| 943 | rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( uiTargetPartIdx ), rpcTempCU, 0, uiDepth, foundNonZeroCbf ); |
---|
| 944 | assert( foundNonZeroCbf ); |
---|
| 945 | } |
---|
| 946 | else |
---|
| 947 | { |
---|
| 948 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP |
---|
| 949 | } |
---|
| 950 | } |
---|
| 951 | |
---|
| 952 | if( m_bUseSBACRD ) |
---|
| 953 | { |
---|
| 954 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
| 955 | } |
---|
| 956 | Bool isEndOfSlice = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES |
---|
| 957 | && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3); |
---|
| 958 | Bool isEndOfSliceSegment = rpcBestCU->getSlice()->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES |
---|
| 959 | && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceSegmentArgument()<<3); |
---|
| 960 | if(isEndOfSlice||isEndOfSliceSegment) |
---|
| 961 | { |
---|
| 962 | rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1; |
---|
| 963 | } |
---|
| 964 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth); // RD compare current larger prediction |
---|
| 965 | } // with sub partitioned prediction. |
---|
| 966 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
| 967 | { |
---|
| 968 | iQP = iMinQP; |
---|
| 969 | } |
---|
| 970 | } |
---|
| 971 | |
---|
| 972 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
| 973 | |
---|
| 974 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, uiDepth, rpcBestCU, uiLPelX, uiTPelY ); // Copy Yuv data to picture Yuv |
---|
| 975 | if( bBoundary ||(bSliceEnd && bInsidePicture)) |
---|
| 976 | { |
---|
| 977 | return; |
---|
| 978 | } |
---|
| 979 | |
---|
| 980 | // Assert if Best prediction mode is NONE |
---|
| 981 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
| 982 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); |
---|
| 983 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
---|
| 984 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
| 985 | } |
---|
| 986 | |
---|
| 987 | /** finish encoding a cu and handle end-of-slice conditions |
---|
| 988 | * \param pcCU |
---|
| 989 | * \param uiAbsPartIdx |
---|
| 990 | * \param uiDepth |
---|
| 991 | * \returns Void |
---|
| 992 | */ |
---|
| 993 | Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 994 | { |
---|
| 995 | TComPic* pcPic = pcCU->getPic(); |
---|
| 996 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
| 997 | |
---|
| 998 | //Calculate end address |
---|
| 999 | UInt uiCUAddr = pcCU->getSCUAddr()+uiAbsPartIdx; |
---|
| 1000 | |
---|
| 1001 | UInt uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
---|
| 1002 | UInt uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
---|
| 1003 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 1004 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
[389] | 1005 | #if REPN_FORMAT_IN_VPS |
---|
| 1006 | UInt uiWidth = pcSlice->getPicWidthInLumaSamples(); |
---|
| 1007 | UInt uiHeight = pcSlice->getPicHeightInLumaSamples(); |
---|
| 1008 | #else |
---|
[313] | 1009 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
| 1010 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
[389] | 1011 | #endif |
---|
[313] | 1012 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
| 1013 | { |
---|
| 1014 | uiInternalAddress--; |
---|
| 1015 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 1016 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 1017 | } |
---|
| 1018 | uiInternalAddress++; |
---|
| 1019 | if(uiInternalAddress==pcCU->getPic()->getNumPartInCU()) |
---|
| 1020 | { |
---|
| 1021 | uiInternalAddress = 0; |
---|
| 1022 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
---|
| 1023 | } |
---|
| 1024 | UInt uiRealEndAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
---|
| 1025 | |
---|
| 1026 | // Encode slice finish |
---|
| 1027 | Bool bTerminateSlice = false; |
---|
| 1028 | if (uiCUAddr+(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)) == uiRealEndAddress) |
---|
| 1029 | { |
---|
| 1030 | bTerminateSlice = true; |
---|
| 1031 | } |
---|
| 1032 | UInt uiGranularityWidth = g_uiMaxCUWidth; |
---|
| 1033 | uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1034 | uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1035 | Bool granularityBoundary=((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth)) |
---|
| 1036 | &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)); |
---|
| 1037 | |
---|
| 1038 | if(granularityBoundary) |
---|
| 1039 | { |
---|
| 1040 | // The 1-terminating bit is added to all streams, so don't add it here when it's 1. |
---|
| 1041 | if (!bTerminateSlice) |
---|
| 1042 | m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 ); |
---|
| 1043 | } |
---|
| 1044 | |
---|
| 1045 | Int numberOfWrittenBits = 0; |
---|
| 1046 | if (m_pcBitCounter) |
---|
| 1047 | { |
---|
| 1048 | numberOfWrittenBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
| 1049 | } |
---|
| 1050 | |
---|
| 1051 | // Calculate slice end IF this CU puts us over slice bit size. |
---|
| 1052 | UInt iGranularitySize = pcCU->getPic()->getNumPartInCU(); |
---|
| 1053 | Int iGranularityEnd = ((pcCU->getSCUAddr()+uiAbsPartIdx)/iGranularitySize)*iGranularitySize; |
---|
| 1054 | if(iGranularityEnd<=pcSlice->getSliceSegmentCurStartCUAddr()) |
---|
| 1055 | { |
---|
| 1056 | iGranularityEnd+=max(iGranularitySize,(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1))); |
---|
| 1057 | } |
---|
| 1058 | // Set slice end parameter |
---|
| 1059 | if(pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceBits()+numberOfWrittenBits>pcSlice->getSliceArgument()<<3) |
---|
| 1060 | { |
---|
| 1061 | pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd); |
---|
| 1062 | pcSlice->setSliceCurEndCUAddr(iGranularityEnd); |
---|
| 1063 | return; |
---|
| 1064 | } |
---|
| 1065 | // Set dependent slice end parameter |
---|
| 1066 | if(pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceSegmentBits()+numberOfWrittenBits > pcSlice->getSliceSegmentArgument()<<3) |
---|
| 1067 | { |
---|
| 1068 | pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd); |
---|
| 1069 | return; |
---|
| 1070 | } |
---|
| 1071 | if(granularityBoundary) |
---|
| 1072 | { |
---|
| 1073 | pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) ); |
---|
| 1074 | pcSlice->setSliceSegmentBits(pcSlice->getSliceSegmentBits()+numberOfWrittenBits); |
---|
| 1075 | if (m_pcBitCounter) |
---|
| 1076 | { |
---|
| 1077 | m_pcEntropyCoder->resetBits(); |
---|
| 1078 | } |
---|
| 1079 | } |
---|
| 1080 | } |
---|
| 1081 | |
---|
| 1082 | /** Compute QP for each CU |
---|
| 1083 | * \param pcCU Target CU |
---|
| 1084 | * \param uiDepth CU depth |
---|
| 1085 | * \returns quantization parameter |
---|
| 1086 | */ |
---|
| 1087 | Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth ) |
---|
| 1088 | { |
---|
| 1089 | Int iBaseQp = pcCU->getSlice()->getSliceQp(); |
---|
| 1090 | Int iQpOffset = 0; |
---|
| 1091 | if ( m_pcEncCfg->getUseAdaptiveQP() ) |
---|
| 1092 | { |
---|
| 1093 | TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() ); |
---|
| 1094 | UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 ); |
---|
| 1095 | TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth ); |
---|
| 1096 | UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth(); |
---|
| 1097 | UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight(); |
---|
| 1098 | UInt uiAQUStride = pcAQLayer->getAQPartStride(); |
---|
| 1099 | TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit(); |
---|
| 1100 | |
---|
| 1101 | Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0); |
---|
| 1102 | Double dAvgAct = pcAQLayer->getAvgActivity(); |
---|
| 1103 | Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity(); |
---|
| 1104 | Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct); |
---|
| 1105 | Double dQpOffset = log(dNormAct) / log(2.0) * 6.0; |
---|
| 1106 | iQpOffset = Int(floor( dQpOffset + 0.49999 )); |
---|
| 1107 | } |
---|
[389] | 1108 | #if REPN_FORMAT_IN_VPS |
---|
| 1109 | return Clip3(-pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset ); |
---|
| 1110 | #else |
---|
[313] | 1111 | return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset ); |
---|
[389] | 1112 | #endif |
---|
[313] | 1113 | } |
---|
| 1114 | |
---|
| 1115 | /** encode a CU block recursively |
---|
| 1116 | * \param pcCU |
---|
| 1117 | * \param uiAbsPartIdx |
---|
| 1118 | * \param uiDepth |
---|
| 1119 | * \returns Void |
---|
| 1120 | */ |
---|
| 1121 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1122 | { |
---|
| 1123 | TComPic* pcPic = pcCU->getPic(); |
---|
| 1124 | |
---|
| 1125 | Bool bBoundary = false; |
---|
| 1126 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1127 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
| 1128 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1129 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
| 1130 | |
---|
| 1131 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
| 1132 | // If slice start is within this cu... |
---|
| 1133 | Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
| 1134 | pcSlice->getSliceSegmentCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) ); |
---|
| 1135 | // We need to split, so don't try these modes. |
---|
[389] | 1136 | #if REPN_FORMAT_IN_VPS |
---|
| 1137 | if(!bSliceStart&&( uiRPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples() ) ) |
---|
| 1138 | #else |
---|
[313] | 1139 | if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
[389] | 1140 | #endif |
---|
[313] | 1141 | { |
---|
| 1142 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 1143 | } |
---|
| 1144 | else |
---|
| 1145 | { |
---|
| 1146 | bBoundary = true; |
---|
| 1147 | } |
---|
| 1148 | |
---|
| 1149 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) |
---|
| 1150 | { |
---|
| 1151 | UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
| 1152 | if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
| 1153 | { |
---|
| 1154 | setdQPFlag(true); |
---|
| 1155 | } |
---|
| 1156 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
| 1157 | { |
---|
| 1158 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1159 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1160 | Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
[389] | 1161 | #if REPN_FORMAT_IN_VPS |
---|
| 1162 | if(bInSlice&&( uiLPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples() ) ) |
---|
| 1163 | #else |
---|
[313] | 1164 | if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
[389] | 1165 | #endif |
---|
[313] | 1166 | { |
---|
| 1167 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
| 1168 | } |
---|
| 1169 | } |
---|
| 1170 | return; |
---|
| 1171 | } |
---|
| 1172 | |
---|
| 1173 | if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
| 1174 | { |
---|
| 1175 | setdQPFlag(true); |
---|
| 1176 | } |
---|
| 1177 | if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 1178 | { |
---|
| 1179 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx ); |
---|
| 1180 | } |
---|
| 1181 | if( !pcCU->getSlice()->isIntra() ) |
---|
| 1182 | { |
---|
| 1183 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
| 1184 | } |
---|
| 1185 | |
---|
| 1186 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
| 1187 | { |
---|
| 1188 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
| 1189 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
| 1190 | return; |
---|
| 1191 | } |
---|
| 1192 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
| 1193 | |
---|
| 1194 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 1195 | |
---|
| 1196 | if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
| 1197 | { |
---|
| 1198 | m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx ); |
---|
| 1199 | |
---|
| 1200 | if(pcCU->getIPCMFlag(uiAbsPartIdx)) |
---|
| 1201 | { |
---|
| 1202 | // Encode slice finish |
---|
| 1203 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
| 1204 | return; |
---|
| 1205 | } |
---|
| 1206 | } |
---|
| 1207 | |
---|
| 1208 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
| 1209 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
| 1210 | |
---|
| 1211 | // Encode Coefficients |
---|
| 1212 | Bool bCodeDQP = getdQPFlag(); |
---|
| 1213 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx), bCodeDQP ); |
---|
| 1214 | setdQPFlag( bCodeDQP ); |
---|
| 1215 | |
---|
| 1216 | // --- write terminating bit --- |
---|
| 1217 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
| 1218 | } |
---|
| 1219 | |
---|
| 1220 | #if RATE_CONTROL_INTRA |
---|
| 1221 | Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) |
---|
| 1222 | { |
---|
| 1223 | Int k, i, j, jj; |
---|
| 1224 | Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0; |
---|
| 1225 | |
---|
| 1226 | for( k = 0; k < 64; k += 8 ) |
---|
| 1227 | { |
---|
| 1228 | diff[k+0] = piOrg[0] ; |
---|
| 1229 | diff[k+1] = piOrg[1] ; |
---|
| 1230 | diff[k+2] = piOrg[2] ; |
---|
| 1231 | diff[k+3] = piOrg[3] ; |
---|
| 1232 | diff[k+4] = piOrg[4] ; |
---|
| 1233 | diff[k+5] = piOrg[5] ; |
---|
| 1234 | diff[k+6] = piOrg[6] ; |
---|
| 1235 | diff[k+7] = piOrg[7] ; |
---|
| 1236 | |
---|
| 1237 | piOrg += iStrideOrg; |
---|
| 1238 | } |
---|
| 1239 | |
---|
| 1240 | //horizontal |
---|
| 1241 | for (j=0; j < 8; j++) |
---|
| 1242 | { |
---|
| 1243 | jj = j << 3; |
---|
| 1244 | m2[j][0] = diff[jj ] + diff[jj+4]; |
---|
| 1245 | m2[j][1] = diff[jj+1] + diff[jj+5]; |
---|
| 1246 | m2[j][2] = diff[jj+2] + diff[jj+6]; |
---|
| 1247 | m2[j][3] = diff[jj+3] + diff[jj+7]; |
---|
| 1248 | m2[j][4] = diff[jj ] - diff[jj+4]; |
---|
| 1249 | m2[j][5] = diff[jj+1] - diff[jj+5]; |
---|
| 1250 | m2[j][6] = diff[jj+2] - diff[jj+6]; |
---|
| 1251 | m2[j][7] = diff[jj+3] - diff[jj+7]; |
---|
| 1252 | |
---|
| 1253 | m1[j][0] = m2[j][0] + m2[j][2]; |
---|
| 1254 | m1[j][1] = m2[j][1] + m2[j][3]; |
---|
| 1255 | m1[j][2] = m2[j][0] - m2[j][2]; |
---|
| 1256 | m1[j][3] = m2[j][1] - m2[j][3]; |
---|
| 1257 | m1[j][4] = m2[j][4] + m2[j][6]; |
---|
| 1258 | m1[j][5] = m2[j][5] + m2[j][7]; |
---|
| 1259 | m1[j][6] = m2[j][4] - m2[j][6]; |
---|
| 1260 | m1[j][7] = m2[j][5] - m2[j][7]; |
---|
| 1261 | |
---|
| 1262 | m2[j][0] = m1[j][0] + m1[j][1]; |
---|
| 1263 | m2[j][1] = m1[j][0] - m1[j][1]; |
---|
| 1264 | m2[j][2] = m1[j][2] + m1[j][3]; |
---|
| 1265 | m2[j][3] = m1[j][2] - m1[j][3]; |
---|
| 1266 | m2[j][4] = m1[j][4] + m1[j][5]; |
---|
| 1267 | m2[j][5] = m1[j][4] - m1[j][5]; |
---|
| 1268 | m2[j][6] = m1[j][6] + m1[j][7]; |
---|
| 1269 | m2[j][7] = m1[j][6] - m1[j][7]; |
---|
| 1270 | } |
---|
| 1271 | |
---|
| 1272 | //vertical |
---|
| 1273 | for (i=0; i < 8; i++) |
---|
| 1274 | { |
---|
| 1275 | m3[0][i] = m2[0][i] + m2[4][i]; |
---|
| 1276 | m3[1][i] = m2[1][i] + m2[5][i]; |
---|
| 1277 | m3[2][i] = m2[2][i] + m2[6][i]; |
---|
| 1278 | m3[3][i] = m2[3][i] + m2[7][i]; |
---|
| 1279 | m3[4][i] = m2[0][i] - m2[4][i]; |
---|
| 1280 | m3[5][i] = m2[1][i] - m2[5][i]; |
---|
| 1281 | m3[6][i] = m2[2][i] - m2[6][i]; |
---|
| 1282 | m3[7][i] = m2[3][i] - m2[7][i]; |
---|
| 1283 | |
---|
| 1284 | m1[0][i] = m3[0][i] + m3[2][i]; |
---|
| 1285 | m1[1][i] = m3[1][i] + m3[3][i]; |
---|
| 1286 | m1[2][i] = m3[0][i] - m3[2][i]; |
---|
| 1287 | m1[3][i] = m3[1][i] - m3[3][i]; |
---|
| 1288 | m1[4][i] = m3[4][i] + m3[6][i]; |
---|
| 1289 | m1[5][i] = m3[5][i] + m3[7][i]; |
---|
| 1290 | m1[6][i] = m3[4][i] - m3[6][i]; |
---|
| 1291 | m1[7][i] = m3[5][i] - m3[7][i]; |
---|
| 1292 | |
---|
| 1293 | m2[0][i] = m1[0][i] + m1[1][i]; |
---|
| 1294 | m2[1][i] = m1[0][i] - m1[1][i]; |
---|
| 1295 | m2[2][i] = m1[2][i] + m1[3][i]; |
---|
| 1296 | m2[3][i] = m1[2][i] - m1[3][i]; |
---|
| 1297 | m2[4][i] = m1[4][i] + m1[5][i]; |
---|
| 1298 | m2[5][i] = m1[4][i] - m1[5][i]; |
---|
| 1299 | m2[6][i] = m1[6][i] + m1[7][i]; |
---|
| 1300 | m2[7][i] = m1[6][i] - m1[7][i]; |
---|
| 1301 | } |
---|
| 1302 | |
---|
| 1303 | for (i = 0; i < 8; i++) |
---|
| 1304 | { |
---|
| 1305 | for (j = 0; j < 8; j++) |
---|
| 1306 | { |
---|
| 1307 | iSumHad += abs(m2[i][j]); |
---|
| 1308 | } |
---|
| 1309 | } |
---|
| 1310 | iSumHad -= abs(m2[0][0]); |
---|
| 1311 | iSumHad =(iSumHad+2)>>2; |
---|
| 1312 | return(iSumHad); |
---|
| 1313 | } |
---|
| 1314 | |
---|
| 1315 | Int TEncCu::updateLCUDataISlice(TComDataCU* pcCU, Int LCUIdx, Int width, Int height) |
---|
| 1316 | { |
---|
| 1317 | Int xBl, yBl; |
---|
| 1318 | const Int iBlkSize = 8; |
---|
| 1319 | |
---|
| 1320 | Pel* pOrgInit = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0); |
---|
| 1321 | Int iStrideOrig = pcCU->getPic()->getPicYuvOrg()->getStride(); |
---|
| 1322 | Pel *pOrg; |
---|
| 1323 | |
---|
| 1324 | Int iSumHad = 0; |
---|
| 1325 | for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize) |
---|
| 1326 | { |
---|
| 1327 | for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize) |
---|
| 1328 | { |
---|
| 1329 | pOrg = pOrgInit + iStrideOrig*yBl + xBl; |
---|
| 1330 | iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig); |
---|
| 1331 | } |
---|
| 1332 | } |
---|
| 1333 | return(iSumHad); |
---|
| 1334 | } |
---|
| 1335 | #endif |
---|
| 1336 | |
---|
| 1337 | /** check RD costs for a CU block encoded with merge |
---|
| 1338 | * \param rpcBestCU |
---|
| 1339 | * \param rpcTempCU |
---|
| 1340 | * \returns Void |
---|
| 1341 | */ |
---|
| 1342 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode ) |
---|
| 1343 | { |
---|
| 1344 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
| 1345 | TComMvField cMvFieldNeighbours[ 2 * MRG_MAX_NUM_CANDS ]; // double length for mv of both lists |
---|
| 1346 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
| 1347 | Int numValidMergeCand = 0; |
---|
| 1348 | |
---|
| 1349 | for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) |
---|
| 1350 | { |
---|
| 1351 | uhInterDirNeighbours[ui] = 0; |
---|
| 1352 | } |
---|
| 1353 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
| 1354 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1355 | rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); |
---|
| 1356 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); |
---|
| 1357 | |
---|
| 1358 | Int mergeCandBuffer[MRG_MAX_NUM_CANDS]; |
---|
| 1359 | for( UInt ui = 0; ui < numValidMergeCand; ++ui ) |
---|
| 1360 | { |
---|
| 1361 | mergeCandBuffer[ui] = 0; |
---|
| 1362 | } |
---|
| 1363 | |
---|
| 1364 | Bool bestIsSkip = false; |
---|
| 1365 | |
---|
| 1366 | UInt iteration; |
---|
| 1367 | if ( rpcTempCU->isLosslessCoded(0)) |
---|
| 1368 | { |
---|
| 1369 | iteration = 1; |
---|
| 1370 | } |
---|
| 1371 | else |
---|
| 1372 | { |
---|
| 1373 | iteration = 2; |
---|
| 1374 | } |
---|
| 1375 | |
---|
| 1376 | for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
| 1377 | { |
---|
| 1378 | for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) |
---|
| 1379 | { |
---|
| 1380 | #if REF_IDX_ME_ZEROMV |
---|
| 1381 | Bool bZeroMVILR = rpcTempCU->xCheckZeroMVILRMerge(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]); |
---|
| 1382 | if(bZeroMVILR) |
---|
| 1383 | { |
---|
| 1384 | #endif |
---|
| 1385 | if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1)) |
---|
| 1386 | { |
---|
| 1387 | if( !(bestIsSkip && uiNoResidual == 0) ) |
---|
| 1388 | { |
---|
| 1389 | // set MC parameters |
---|
| 1390 | rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1391 | rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); |
---|
| 1392 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1393 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1394 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1395 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1396 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
| 1397 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
| 1398 | |
---|
| 1399 | // do MC |
---|
| 1400 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
| 1401 | // estimate residual and encode everything |
---|
| 1402 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
| 1403 | m_ppcOrigYuv [uhDepth], |
---|
| 1404 | m_ppcPredYuvTemp[uhDepth], |
---|
| 1405 | m_ppcResiYuvTemp[uhDepth], |
---|
| 1406 | m_ppcResiYuvBest[uhDepth], |
---|
| 1407 | m_ppcRecoYuvTemp[uhDepth], |
---|
| 1408 | (uiNoResidual? true:false)); |
---|
| 1409 | |
---|
| 1410 | |
---|
| 1411 | if ( uiNoResidual == 0 && rpcTempCU->getQtRootCbf(0) == 0 ) |
---|
| 1412 | { |
---|
| 1413 | // If no residual when allowing for one, then set mark to not try case where residual is forced to 0 |
---|
| 1414 | mergeCandBuffer[uiMergeCand] = 1; |
---|
| 1415 | } |
---|
| 1416 | |
---|
| 1417 | rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth ); |
---|
| 1418 | Int orgQP = rpcTempCU->getQP( 0 ); |
---|
| 1419 | xCheckDQP( rpcTempCU ); |
---|
| 1420 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
| 1421 | rpcTempCU->initEstData( uhDepth, orgQP ); |
---|
| 1422 | |
---|
| 1423 | if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) |
---|
| 1424 | { |
---|
| 1425 | bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; |
---|
| 1426 | } |
---|
| 1427 | } |
---|
| 1428 | #if REF_IDX_ME_ZEROMV |
---|
| 1429 | } |
---|
| 1430 | #endif |
---|
| 1431 | } |
---|
| 1432 | } |
---|
| 1433 | |
---|
| 1434 | if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection()) |
---|
| 1435 | { |
---|
| 1436 | if(rpcBestCU->getQtRootCbf( 0 ) == 0) |
---|
| 1437 | { |
---|
| 1438 | if( rpcBestCU->getMergeFlag( 0 )) |
---|
| 1439 | { |
---|
| 1440 | *earlyDetectionSkipMode = true; |
---|
| 1441 | } |
---|
| 1442 | else |
---|
| 1443 | { |
---|
| 1444 | Int absoulte_MV=0; |
---|
| 1445 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
| 1446 | { |
---|
| 1447 | if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
| 1448 | { |
---|
| 1449 | TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx )); |
---|
| 1450 | Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor(); |
---|
| 1451 | Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer(); |
---|
| 1452 | absoulte_MV+=iHor+iVer; |
---|
| 1453 | } |
---|
| 1454 | } |
---|
| 1455 | |
---|
| 1456 | if(absoulte_MV == 0) |
---|
| 1457 | { |
---|
| 1458 | *earlyDetectionSkipMode = true; |
---|
| 1459 | } |
---|
| 1460 | } |
---|
| 1461 | } |
---|
| 1462 | } |
---|
| 1463 | } |
---|
| 1464 | } |
---|
| 1465 | |
---|
| 1466 | |
---|
| 1467 | #if AMP_MRG |
---|
| 1468 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bUseMRG) |
---|
| 1469 | #else |
---|
| 1470 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
| 1471 | #endif |
---|
| 1472 | { |
---|
| 1473 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
| 1474 | |
---|
| 1475 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
| 1476 | |
---|
| 1477 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
| 1478 | |
---|
| 1479 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
| 1480 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
| 1481 | rpcTempCU->setCUTransquantBypassSubParts ( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); |
---|
| 1482 | |
---|
| 1483 | #if AMP_MRG |
---|
| 1484 | rpcTempCU->setMergeAMP (true); |
---|
| 1485 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], false, bUseMRG ); |
---|
| 1486 | #else |
---|
| 1487 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
| 1488 | #endif |
---|
| 1489 | |
---|
| 1490 | #if AMP_MRG |
---|
| 1491 | if ( !rpcTempCU->getMergeAMP() ) |
---|
| 1492 | { |
---|
| 1493 | return; |
---|
| 1494 | } |
---|
| 1495 | #endif |
---|
| 1496 | |
---|
| 1497 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT |
---|
| 1498 | if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth ) |
---|
| 1499 | { |
---|
| 1500 | UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(), |
---|
| 1501 | m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(), |
---|
| 1502 | rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) ); |
---|
| 1503 | m_temporalSAD = (Int)SAD; |
---|
| 1504 | } |
---|
| 1505 | #endif |
---|
| 1506 | |
---|
| 1507 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); |
---|
| 1508 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 1509 | |
---|
| 1510 | xCheckDQP( rpcTempCU ); |
---|
| 1511 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
| 1512 | } |
---|
| 1513 | |
---|
| 1514 | Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize ) |
---|
| 1515 | { |
---|
| 1516 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
| 1517 | |
---|
| 1518 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
| 1519 | |
---|
| 1520 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
| 1521 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
| 1522 | rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth ); |
---|
| 1523 | |
---|
| 1524 | Bool bSeparateLumaChroma = true; // choose estimation mode |
---|
| 1525 | UInt uiPreCalcDistC = 0; |
---|
| 1526 | if( !bSeparateLumaChroma ) |
---|
| 1527 | { |
---|
| 1528 | m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] ); |
---|
| 1529 | } |
---|
| 1530 | m_pcPredSearch ->estIntraPredQT ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma ); |
---|
| 1531 | |
---|
| 1532 | m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() ); |
---|
| 1533 | |
---|
| 1534 | m_pcPredSearch ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC ); |
---|
| 1535 | |
---|
| 1536 | m_pcEntropyCoder->resetBits(); |
---|
[345] | 1537 | |
---|
[313] | 1538 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 1539 | { |
---|
| 1540 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
| 1541 | } |
---|
| 1542 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
| 1543 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
| 1544 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
| 1545 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0, true ); |
---|
| 1546 | m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true ); |
---|
| 1547 | |
---|
| 1548 | // Encode Coefficients |
---|
| 1549 | Bool bCodeDQP = getdQPFlag(); |
---|
| 1550 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0), bCodeDQP ); |
---|
| 1551 | setdQPFlag( bCodeDQP ); |
---|
| 1552 | |
---|
| 1553 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
| 1554 | |
---|
| 1555 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
| 1556 | if(m_pcEncCfg->getUseSBACRD()) |
---|
| 1557 | { |
---|
| 1558 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 1559 | } |
---|
| 1560 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 1561 | |
---|
| 1562 | xCheckDQP( rpcTempCU ); |
---|
| 1563 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth); |
---|
| 1564 | } |
---|
| 1565 | |
---|
| 1566 | /** Check R-D costs for a CU with PCM mode. |
---|
| 1567 | * \param rpcBestCU pointer to best mode CU data structure |
---|
| 1568 | * \param rpcTempCU pointer to testing mode CU data structure |
---|
| 1569 | * \returns Void |
---|
| 1570 | * |
---|
| 1571 | * \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. |
---|
| 1572 | */ |
---|
| 1573 | Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
| 1574 | { |
---|
| 1575 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
| 1576 | |
---|
| 1577 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
| 1578 | |
---|
| 1579 | rpcTempCU->setIPCMFlag(0, true); |
---|
| 1580 | rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); |
---|
| 1581 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
| 1582 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
| 1583 | rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth ); |
---|
| 1584 | rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth ); |
---|
| 1585 | |
---|
| 1586 | m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); |
---|
| 1587 | |
---|
| 1588 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
| 1589 | |
---|
| 1590 | m_pcEntropyCoder->resetBits(); |
---|
[345] | 1591 | |
---|
[313] | 1592 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 1593 | { |
---|
| 1594 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
| 1595 | } |
---|
| 1596 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
| 1597 | m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); |
---|
| 1598 | m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); |
---|
| 1599 | m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); |
---|
| 1600 | |
---|
| 1601 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
| 1602 | |
---|
| 1603 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
| 1604 | if(m_pcEncCfg->getUseSBACRD()) |
---|
| 1605 | { |
---|
| 1606 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 1607 | } |
---|
| 1608 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 1609 | |
---|
| 1610 | xCheckDQP( rpcTempCU ); |
---|
| 1611 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); |
---|
| 1612 | } |
---|
| 1613 | |
---|
| 1614 | /** check whether current try is the best with identifying the depth of current try |
---|
| 1615 | * \param rpcBestCU |
---|
| 1616 | * \param rpcTempCU |
---|
| 1617 | * \returns Void |
---|
| 1618 | */ |
---|
| 1619 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
| 1620 | { |
---|
| 1621 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
| 1622 | { |
---|
| 1623 | TComYuv* pcYuv; |
---|
| 1624 | // Change Information data |
---|
| 1625 | TComDataCU* pcCU = rpcBestCU; |
---|
| 1626 | rpcBestCU = rpcTempCU; |
---|
| 1627 | rpcTempCU = pcCU; |
---|
| 1628 | |
---|
| 1629 | // Change Prediction data |
---|
| 1630 | pcYuv = m_ppcPredYuvBest[uiDepth]; |
---|
| 1631 | m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; |
---|
| 1632 | m_ppcPredYuvTemp[uiDepth] = pcYuv; |
---|
| 1633 | |
---|
| 1634 | // Change Reconstruction data |
---|
| 1635 | pcYuv = m_ppcRecoYuvBest[uiDepth]; |
---|
| 1636 | m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; |
---|
| 1637 | m_ppcRecoYuvTemp[uiDepth] = pcYuv; |
---|
| 1638 | |
---|
| 1639 | pcYuv = NULL; |
---|
| 1640 | pcCU = NULL; |
---|
| 1641 | |
---|
| 1642 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
---|
| 1643 | m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
| 1644 | } |
---|
| 1645 | } |
---|
| 1646 | |
---|
| 1647 | Void TEncCu::xCheckDQP( TComDataCU* pcCU ) |
---|
| 1648 | { |
---|
| 1649 | UInt uiDepth = pcCU->getDepth( 0 ); |
---|
| 1650 | |
---|
| 1651 | if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
| 1652 | { |
---|
| 1653 | if ( pcCU->getCbf( 0, TEXT_LUMA, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_U, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_V, 0 ) ) |
---|
| 1654 | { |
---|
| 1655 | #if !RDO_WITHOUT_DQP_BITS |
---|
| 1656 | m_pcEntropyCoder->resetBits(); |
---|
| 1657 | m_pcEntropyCoder->encodeQP( pcCU, 0, false ); |
---|
| 1658 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
| 1659 | if(m_pcEncCfg->getUseSBACRD()) |
---|
| 1660 | { |
---|
| 1661 | pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 1662 | } |
---|
| 1663 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
| 1664 | #endif |
---|
| 1665 | } |
---|
| 1666 | else |
---|
| 1667 | { |
---|
| 1668 | pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
| 1669 | } |
---|
| 1670 | } |
---|
| 1671 | } |
---|
| 1672 | |
---|
| 1673 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
| 1674 | { |
---|
| 1675 | pDst->iN = pSrc->iN; |
---|
| 1676 | for (Int i = 0; i < pSrc->iN; i++) |
---|
| 1677 | { |
---|
| 1678 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
| 1679 | } |
---|
| 1680 | } |
---|
| 1681 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY ) |
---|
| 1682 | { |
---|
| 1683 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
| 1684 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
| 1685 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
| 1686 | Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
| 1687 | pcSlice->getSliceSegmentCurStartCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
| 1688 | Bool bSliceEnd = pcSlice->getSliceSegmentCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
| 1689 | pcSlice->getSliceSegmentCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
[389] | 1690 | #if REPN_FORMAT_IN_VPS |
---|
| 1691 | if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples() ) ) |
---|
| 1692 | #else |
---|
[313] | 1693 | if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
[389] | 1694 | #endif |
---|
[313] | 1695 | { |
---|
| 1696 | UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; |
---|
| 1697 | UInt uiSrcBlkWidth = rpcPic->getNumPartInWidth() >> (uiSrcDepth); |
---|
| 1698 | UInt uiBlkWidth = rpcPic->getNumPartInWidth() >> (uiDepth); |
---|
| 1699 | UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
| 1700 | UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
| 1701 | UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; |
---|
| 1702 | m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
| 1703 | } |
---|
| 1704 | else |
---|
| 1705 | { |
---|
| 1706 | UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
| 1707 | |
---|
| 1708 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
| 1709 | { |
---|
| 1710 | UInt uiSubCULPelX = uiLPelX + ( g_uiMaxCUWidth >>(uiDepth+1) )*( uiPartUnitIdx & 1 ); |
---|
| 1711 | UInt uiSubCUTPelY = uiTPelY + ( g_uiMaxCUHeight>>(uiDepth+1) )*( uiPartUnitIdx >> 1 ); |
---|
| 1712 | |
---|
| 1713 | Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getSliceSegmentCurStartCUAddr() && |
---|
| 1714 | rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
[389] | 1715 | #if REPN_FORMAT_IN_VPS |
---|
| 1716 | if(bInSlice&&( uiSubCULPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getPicHeightInLumaSamples() ) ) |
---|
| 1717 | #else |
---|
[313] | 1718 | if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
[389] | 1719 | #endif |
---|
[313] | 1720 | { |
---|
| 1721 | xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY ); // Copy Yuv data to picture Yuv |
---|
| 1722 | } |
---|
| 1723 | } |
---|
| 1724 | } |
---|
| 1725 | } |
---|
| 1726 | |
---|
| 1727 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
| 1728 | { |
---|
| 1729 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
| 1730 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
| 1731 | } |
---|
| 1732 | |
---|
| 1733 | /** Function for filling the PCM buffer of a CU using its original sample array |
---|
| 1734 | * \param pcCU pointer to current CU |
---|
| 1735 | * \param pcOrgYuv pointer to original sample array |
---|
| 1736 | * \returns Void |
---|
| 1737 | */ |
---|
| 1738 | Void TEncCu::xFillPCMBuffer ( TComDataCU*& pCU, TComYuv* pOrgYuv ) |
---|
| 1739 | { |
---|
| 1740 | |
---|
| 1741 | UInt width = pCU->getWidth(0); |
---|
| 1742 | UInt height = pCU->getHeight(0); |
---|
| 1743 | |
---|
| 1744 | Pel* pSrcY = pOrgYuv->getLumaAddr(0, width); |
---|
| 1745 | Pel* pDstY = pCU->getPCMSampleY(); |
---|
| 1746 | UInt srcStride = pOrgYuv->getStride(); |
---|
| 1747 | |
---|
| 1748 | for(Int y = 0; y < height; y++ ) |
---|
| 1749 | { |
---|
| 1750 | for(Int x = 0; x < width; x++ ) |
---|
| 1751 | { |
---|
| 1752 | pDstY[x] = pSrcY[x]; |
---|
| 1753 | } |
---|
| 1754 | pDstY += width; |
---|
| 1755 | pSrcY += srcStride; |
---|
| 1756 | } |
---|
| 1757 | |
---|
| 1758 | Pel* pSrcCb = pOrgYuv->getCbAddr(); |
---|
| 1759 | Pel* pSrcCr = pOrgYuv->getCrAddr();; |
---|
| 1760 | |
---|
| 1761 | Pel* pDstCb = pCU->getPCMSampleCb(); |
---|
| 1762 | Pel* pDstCr = pCU->getPCMSampleCr();; |
---|
| 1763 | |
---|
| 1764 | UInt srcStrideC = pOrgYuv->getCStride(); |
---|
| 1765 | UInt heightC = height >> 1; |
---|
| 1766 | UInt widthC = width >> 1; |
---|
| 1767 | |
---|
| 1768 | for(Int y = 0; y < heightC; y++ ) |
---|
| 1769 | { |
---|
| 1770 | for(Int x = 0; x < widthC; x++ ) |
---|
| 1771 | { |
---|
| 1772 | pDstCb[x] = pSrcCb[x]; |
---|
| 1773 | pDstCr[x] = pSrcCr[x]; |
---|
| 1774 | } |
---|
| 1775 | pDstCb += widthC; |
---|
| 1776 | pDstCr += widthC; |
---|
| 1777 | pSrcCb += srcStrideC; |
---|
| 1778 | pSrcCr += srcStrideC; |
---|
| 1779 | } |
---|
| 1780 | } |
---|
| 1781 | |
---|
| 1782 | #if ADAPTIVE_QP_SELECTION |
---|
| 1783 | /** Collect ARL statistics from one block |
---|
| 1784 | */ |
---|
| 1785 | Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, Int* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) |
---|
| 1786 | { |
---|
| 1787 | for( Int n = 0; n < NumCoeffInCU; n++ ) |
---|
| 1788 | { |
---|
| 1789 | Int u = abs( rpcCoeff[ n ] ); |
---|
| 1790 | Int absc = rpcArlCoeff[ n ]; |
---|
| 1791 | |
---|
| 1792 | if( u != 0 ) |
---|
| 1793 | { |
---|
| 1794 | if( u < LEVEL_RANGE ) |
---|
| 1795 | { |
---|
| 1796 | cSum[ u ] += ( Double )absc; |
---|
| 1797 | numSamples[ u ]++; |
---|
| 1798 | } |
---|
| 1799 | else |
---|
| 1800 | { |
---|
| 1801 | cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); |
---|
| 1802 | numSamples[ LEVEL_RANGE ]++; |
---|
| 1803 | } |
---|
| 1804 | } |
---|
| 1805 | } |
---|
| 1806 | |
---|
| 1807 | return 0; |
---|
| 1808 | } |
---|
| 1809 | |
---|
| 1810 | /** Collect ARL statistics from one LCU |
---|
| 1811 | * \param pcCU |
---|
| 1812 | */ |
---|
| 1813 | Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU ) |
---|
| 1814 | { |
---|
| 1815 | Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to datatype and quantization output |
---|
| 1816 | UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output |
---|
| 1817 | |
---|
| 1818 | TCoeff* pCoeffY = rpcCU->getCoeffY(); |
---|
| 1819 | Int* pArlCoeffY = rpcCU->getArlCoeffY(); |
---|
| 1820 | |
---|
| 1821 | UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth; |
---|
| 1822 | UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; |
---|
| 1823 | |
---|
| 1824 | memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); |
---|
| 1825 | memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); |
---|
| 1826 | |
---|
| 1827 | // Collect stats to cSum[][] and numSamples[][] |
---|
| 1828 | for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ ) |
---|
| 1829 | { |
---|
| 1830 | UInt uiTrIdx = rpcCU->getTransformIdx(i); |
---|
| 1831 | |
---|
| 1832 | if(rpcCU->getPredictionMode(i) == MODE_INTER) |
---|
| 1833 | if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) ) |
---|
| 1834 | { |
---|
| 1835 | xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); |
---|
| 1836 | }//Note that only InterY is processed. QP rounding is based on InterY data only. |
---|
| 1837 | |
---|
| 1838 | pCoeffY += uiMinNumCoeffInCU; |
---|
| 1839 | pArlCoeffY += uiMinNumCoeffInCU; |
---|
| 1840 | } |
---|
| 1841 | |
---|
| 1842 | for(Int u=1; u<LEVEL_RANGE;u++) |
---|
| 1843 | { |
---|
| 1844 | m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; |
---|
| 1845 | m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; |
---|
| 1846 | } |
---|
| 1847 | m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; |
---|
| 1848 | m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; |
---|
| 1849 | } |
---|
| 1850 | #endif |
---|
| 1851 | |
---|
| 1852 | #if (ENCODER_FAST_MODE) |
---|
| 1853 | Void TEncCu::xCheckRDCostILRUni(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, UInt refLayerId) |
---|
| 1854 | { |
---|
| 1855 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
| 1856 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
| 1857 | #if SKIP_FLAG |
---|
| 1858 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
| 1859 | #endif |
---|
| 1860 | rpcTempCU->setPartSizeSubParts ( SIZE_2Nx2N, 0, uhDepth ); //2Nx2N |
---|
| 1861 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
| 1862 | rpcTempCU->setCUTransquantBypassSubParts ( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); |
---|
| 1863 | Bool exitILR = m_pcPredSearch->predInterSearchILRUni( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], refLayerId ); |
---|
| 1864 | if(!exitILR) |
---|
| 1865 | { |
---|
| 1866 | return; |
---|
| 1867 | } |
---|
| 1868 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); |
---|
| 1869 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 1870 | xCheckDQP( rpcTempCU ); |
---|
| 1871 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
| 1872 | return; |
---|
| 1873 | } |
---|
| 1874 | #endif |
---|
| 1875 | //! \} |
---|