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