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