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