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