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