[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 | |
---|
[1210] | 443 | #if NH_3D_NBDV |
---|
[608] | 444 | DisInfo DvInfo; |
---|
| 445 | DvInfo.m_acNBDV.setZero(); |
---|
| 446 | DvInfo.m_aVIdxCan = 0; |
---|
[1217] | 447 | #if NH_3D_NBDV_REF |
---|
[608] | 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 | |
---|
[1210] | 586 | #if NH_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); |
---|
[1210] | 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 |
---|
[1217] | 613 | #if NH_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 |
---|
[608] | 735 | #if H_3D_DIM_ENC |
---|
| 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) || |
---|
| 1077 | ((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && ( |
---|
| 1078 | (rpcBestCU->getCbf( 0, COMPONENT_Y ) != 0) || |
---|
| 1079 | ((rpcBestCU->getCbf( 0, COMPONENT_Cb ) != 0) && (numberValidComponents > COMPONENT_Cb)) || |
---|
| 1080 | ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr))) |
---|
| 1081 | // avoid very complex intra if it is unlikely |
---|
[608] | 1082 | #if H_3D_DIM_ENC |
---|
[1196] | 1083 | || rpcBestCU->getSlice()->getIsDepth() |
---|
[189] | 1084 | #endif |
---|
[1200] | 1085 | )) |
---|
| 1086 | { |
---|
[1084] | 1087 | #if H_3D_DIM |
---|
[1039] | 1088 | Bool bOnlyIVP = false; |
---|
[1133] | 1089 | Bool bUseIVP = true; |
---|
[1039] | 1090 | if( rpcBestCU->getSlice()->getIsDepth() && !(rpcBestCU->getSlice()->isIRAP()) && |
---|
[1196] | 1091 | rpcBestCU->getSlice()->getSliceType() != I_SLICE && |
---|
| 1092 | rpcBestCU->getCbf( 0, TEXT_LUMA ) == 0 && |
---|
| 1093 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) == 0 && |
---|
| 1094 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) == 0 |
---|
[1039] | 1095 | ) |
---|
| 1096 | { |
---|
| 1097 | bOnlyIVP = true; |
---|
[1133] | 1098 | bUseIVP = rpcBestCU->getSlice()->getIntraContourFlag(); |
---|
[1039] | 1099 | } |
---|
[1133] | 1100 | if( bUseIVP ) |
---|
| 1101 | { |
---|
[1196] | 1102 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bOnlyIVP ); |
---|
[1039] | 1103 | #else |
---|
[1200] | 1104 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, intraCost, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
[1039] | 1105 | #endif |
---|
[872] | 1106 | #if KWU_RC_MADPRED_E0227 |
---|
[655] | 1107 | if ( uiDepth <= m_addSADDepth ) |
---|
| 1108 | { |
---|
| 1109 | m_LCUPredictionSAD += m_spatialSAD; |
---|
| 1110 | m_addSADDepth = uiDepth; |
---|
| 1111 | } |
---|
| 1112 | #endif |
---|
| 1113 | |
---|
[1200] | 1114 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
| 1115 | if( uiDepth == sps.getLog2DiffMaxMinCodingBlockSize() ) |
---|
| 1116 | { |
---|
[608] | 1117 | #if H_3D_QTLPC //Try IntraNxN |
---|
| 1118 | if(bTrySplit) |
---|
[116] | 1119 | { |
---|
[189] | 1120 | #endif |
---|
[1200] | 1121 | if( rpcTempCU->getWidth(0) > ( 1 << sps.getQuadtreeTULog2MinSize() ) ) |
---|
| 1122 | { |
---|
| 1123 | Double tmpIntraCost; |
---|
[1084] | 1124 | #if H_3D_DIM |
---|
[1200] | 1125 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN, bOnlyIVP ); |
---|
[1039] | 1126 | #else |
---|
[1200] | 1127 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, tmpIntraCost, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
[1039] | 1128 | #endif |
---|
[1200] | 1129 | |
---|
| 1130 | intraCost = std::min(intraCost, tmpIntraCost); |
---|
| 1131 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
| 1132 | } |
---|
[608] | 1133 | #if H_3D_QTLPC |
---|
[116] | 1134 | } |
---|
[608] | 1135 | #endif |
---|
[1200] | 1136 | } |
---|
[1196] | 1137 | #if H_3D |
---|
[2] | 1138 | } |
---|
[1133] | 1139 | #endif |
---|
[1196] | 1140 | } |
---|
[1200] | 1141 | |
---|
[608] | 1142 | // test PCM |
---|
[1200] | 1143 | if(sps.getUsePCM() |
---|
| 1144 | && rpcTempCU->getWidth(0) <= (1<<sps.getPCMLog2MaxSize()) |
---|
| 1145 | && rpcTempCU->getWidth(0) >= (1<<sps.getPCMLog2MinSize()) ) |
---|
[608] | 1146 | { |
---|
[1200] | 1147 | UInt uiRawBits = getTotalBits(rpcBestCU->getWidth(0), rpcBestCU->getHeight(0), rpcBestCU->getPic()->getChromaFormat(), sps.getBitDepths().recon); |
---|
[608] | 1148 | UInt uiBestBits = rpcBestCU->getTotalBits(); |
---|
[1200] | 1149 | #if NH_3D_VSO // M7 |
---|
| 1150 | Double dRDCostTemp = m_pcRdCost->getUseLambdaScaleVSO() ? m_pcRdCost->calcRdCostVSO(uiRawBits, 0) : m_pcRdCost->calcRdCost(uiRawBits, 0); |
---|
[608] | 1151 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > dRDCostTemp )) |
---|
[56] | 1152 | #else |
---|
[608] | 1153 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0))) |
---|
[56] | 1154 | #endif |
---|
[1200] | 1155 | |
---|
[608] | 1156 | { |
---|
| 1157 | xCheckIntraPCM (rpcBestCU, rpcTempCU); |
---|
[872] | 1158 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[608] | 1159 | } |
---|
| 1160 | } |
---|
[655] | 1161 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 1162 | } |
---|
[189] | 1163 | #endif |
---|
[1200] | 1164 | if (bIsLosslessMode) // Restore loop variable if lossless mode was searched. |
---|
[296] | 1165 | { |
---|
[608] | 1166 | iQP = iMinQP; |
---|
[296] | 1167 | } |
---|
[56] | 1168 | } |
---|
[2] | 1169 | } |
---|
| 1170 | |
---|
[1200] | 1171 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
[2] | 1172 | m_pcEntropyCoder->resetBits(); |
---|
| 1173 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
---|
| 1174 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
[1200] | 1175 | rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 1176 | #if NH_3D_VSO // M8 |
---|
[608] | 1177 | if ( m_pcRdCost->getUseVSO() ) |
---|
[1200] | 1178 | { |
---|
[608] | 1179 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
[1200] | 1180 | } |
---|
[2] | 1181 | else |
---|
[5] | 1182 | #endif |
---|
[1200] | 1183 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
| 1184 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
[2] | 1185 | |
---|
[56] | 1186 | // Early CU determination |
---|
[608] | 1187 | if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) ) |
---|
[2] | 1188 | { |
---|
[56] | 1189 | bSubBranch = false; |
---|
[2] | 1190 | } |
---|
[56] | 1191 | else |
---|
| 1192 | { |
---|
| 1193 | bSubBranch = true; |
---|
| 1194 | } |
---|
[655] | 1195 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 1196 | if(rpcBestCU->getSlice()->getViewIndex() && !rpcBestCU->getSlice()->getIsDepth() && (uiDepth >=iIVFMaxD) && rpcBestCU->isSkipped(0)) |
---|
| 1197 | { |
---|
| 1198 | bSubBranch = false; |
---|
| 1199 | } |
---|
[2] | 1200 | #endif |
---|
| 1201 | } |
---|
[1200] | 1202 | else |
---|
[2] | 1203 | { |
---|
| 1204 | bBoundary = true; |
---|
| 1205 | } |
---|
| 1206 | |
---|
[56] | 1207 | // copy orginal YUV samples to PCM buffer |
---|
| 1208 | if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false)) |
---|
[2] | 1209 | { |
---|
[56] | 1210 | xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]); |
---|
| 1211 | } |
---|
[1200] | 1212 | |
---|
| 1213 | if( uiDepth == pps.getMaxCuDQPDepth() ) |
---|
[56] | 1214 | { |
---|
| 1215 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
[1200] | 1216 | iMinQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP ); |
---|
| 1217 | iMaxQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP ); |
---|
[56] | 1218 | } |
---|
[1200] | 1219 | else if( uiDepth < pps.getMaxCuDQPDepth() ) |
---|
[56] | 1220 | { |
---|
| 1221 | iMinQP = iBaseQP; |
---|
| 1222 | iMaxQP = iBaseQP; |
---|
| 1223 | } |
---|
| 1224 | else |
---|
| 1225 | { |
---|
[1200] | 1226 | const Int iStartQP = rpcTempCU->getQP(0); |
---|
[56] | 1227 | iMinQP = iStartQP; |
---|
| 1228 | iMaxQP = iStartQP; |
---|
| 1229 | } |
---|
[1200] | 1230 | |
---|
[608] | 1231 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
| 1232 | { |
---|
| 1233 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
| 1234 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
| 1235 | } |
---|
[872] | 1236 | |
---|
| 1237 | if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) |
---|
[608] | 1238 | { |
---|
[1200] | 1239 | iMaxQP = iMinQP; // If all TUs are forced into using transquant bypass, do not loop here. |
---|
[608] | 1240 | } |
---|
[1200] | 1241 | |
---|
[56] | 1242 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
| 1243 | { |
---|
[872] | 1244 | const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true. |
---|
[1200] | 1245 | |
---|
[872] | 1246 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[2] | 1247 | |
---|
[56] | 1248 | // further split |
---|
[655] | 1249 | #if H_3D_QTLPC |
---|
[56] | 1250 | if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
[655] | 1251 | #else |
---|
[1200] | 1252 | if( bSubBranch && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) |
---|
[655] | 1253 | #endif |
---|
[2] | 1254 | { |
---|
[1200] | 1255 | #if NH_3D_VSO // M9 |
---|
[56] | 1256 | // reset Model |
---|
| 1257 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 1258 | { |
---|
[1200] | 1259 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth ( COMPONENT_Y ); |
---|
| 1260 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight( COMPONENT_Y ); |
---|
| 1261 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getAddr ( COMPONENT_Y, 0 ); |
---|
| 1262 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride( COMPONENT_Y ); |
---|
[81] | 1263 | m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
[56] | 1264 | } |
---|
| 1265 | #endif |
---|
| 1266 | UChar uhNextDepth = uiDepth+1; |
---|
| 1267 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
| 1268 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
[1200] | 1269 | DEBUG_STRING_NEW(sTempDebug) |
---|
[2] | 1270 | |
---|
[56] | 1271 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
[2] | 1272 | { |
---|
[56] | 1273 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
| 1274 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
| 1275 | |
---|
[1200] | 1276 | if( ( pcSubBestPartCU->getCUPelX() < sps.getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < sps.getPicHeightInLumaSamples() ) ) |
---|
[2] | 1277 | { |
---|
[1200] | 1278 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
| 1279 | { |
---|
| 1280 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
| 1281 | } |
---|
| 1282 | else |
---|
| 1283 | { |
---|
| 1284 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
| 1285 | } |
---|
[56] | 1286 | |
---|
| 1287 | #if AMP_ENC_SPEEDUP |
---|
[1200] | 1288 | DEBUG_STRING_NEW(sChild) |
---|
| 1289 | if ( !rpcBestCU->isInter(0) ) |
---|
[56] | 1290 | { |
---|
[1200] | 1291 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), NUMBER_OF_PART_SIZES ); |
---|
[56] | 1292 | } |
---|
[2] | 1293 | else |
---|
| 1294 | { |
---|
[1200] | 1295 | |
---|
| 1296 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), rpcBestCU->getPartitionSize(0) ); |
---|
[2] | 1297 | } |
---|
[1200] | 1298 | DEBUG_STRING_APPEND(sTempDebug, sChild) |
---|
[56] | 1299 | #else |
---|
| 1300 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
---|
| 1301 | #endif |
---|
[2] | 1302 | |
---|
[56] | 1303 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
| 1304 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
| 1305 | } |
---|
[1200] | 1306 | else |
---|
[2] | 1307 | { |
---|
[56] | 1308 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
| 1309 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
[2] | 1310 | } |
---|
| 1311 | } |
---|
| 1312 | |
---|
[1200] | 1313 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
[56] | 1314 | if( !bBoundary ) |
---|
| 1315 | { |
---|
| 1316 | m_pcEntropyCoder->resetBits(); |
---|
| 1317 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
[2] | 1318 | |
---|
[56] | 1319 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
[1200] | 1320 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 1321 | } |
---|
| 1322 | #if NH_3D_VSO // M10 |
---|
[56] | 1323 | if ( m_pcRdCost->getUseVSO() ) |
---|
[1200] | 1324 | { |
---|
[56] | 1325 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[1200] | 1326 | } |
---|
[56] | 1327 | else |
---|
[5] | 1328 | #endif |
---|
[1200] | 1329 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[2] | 1330 | |
---|
[1200] | 1331 | if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP()) |
---|
[56] | 1332 | { |
---|
[608] | 1333 | Bool hasResidual = false; |
---|
[56] | 1334 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
| 1335 | { |
---|
[1200] | 1336 | if( ( rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Y) |
---|
| 1337 | || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cb) && (numberValidComponents > COMPONENT_Cb)) |
---|
| 1338 | || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cr) && (numberValidComponents > COMPONENT_Cr)) ) ) |
---|
[56] | 1339 | { |
---|
[608] | 1340 | hasResidual = true; |
---|
[56] | 1341 | break; |
---|
| 1342 | } |
---|
| 1343 | } |
---|
[2] | 1344 | |
---|
[1200] | 1345 | UInt uiTargetPartIdx = 0; |
---|
[608] | 1346 | if ( hasResidual ) |
---|
[56] | 1347 | { |
---|
| 1348 | m_pcEntropyCoder->resetBits(); |
---|
| 1349 | m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false ); |
---|
| 1350 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
[1200] | 1351 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 1352 | #if NH_3D_VSO // M11 |
---|
[608] | 1353 | if ( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
[1200] | 1354 | { |
---|
[608] | 1355 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[1200] | 1356 | } |
---|
[56] | 1357 | else |
---|
[5] | 1358 | #endif |
---|
[1200] | 1359 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[608] | 1360 | |
---|
| 1361 | Bool foundNonZeroCbf = false; |
---|
[1200] | 1362 | rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth, foundNonZeroCbf ); |
---|
[608] | 1363 | assert( foundNonZeroCbf ); |
---|
[56] | 1364 | } |
---|
| 1365 | else |
---|
| 1366 | { |
---|
| 1367 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP |
---|
| 1368 | } |
---|
| 1369 | } |
---|
[2] | 1370 | |
---|
[1200] | 1371 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
| 1372 | |
---|
| 1373 | // If the configuration being tested exceeds the maximum number of bytes for a slice / slice-segment, then |
---|
| 1374 | // a proper RD evaluation cannot be performed. Therefore, termination of the |
---|
| 1375 | // slice/slice-segment must be made prior to this CTU. |
---|
| 1376 | // This can be achieved by forcing the decision to be that of the rpcTempCU. |
---|
| 1377 | // The exception is each slice / slice-segment must have at least one CTU. |
---|
| 1378 | const Bool isEndOfSlice = pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES |
---|
| 1379 | && ((pcSlice->getSliceBits()+rpcBestCU->getTotalBits())>pcSlice->getSliceArgument()<<3) |
---|
| 1380 | && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceCurStartCtuTsAddr()) |
---|
| 1381 | && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()); |
---|
| 1382 | const Bool isEndOfSliceSegment = pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES |
---|
| 1383 | && ((pcSlice->getSliceSegmentBits()+rpcBestCU->getTotalBits()) > pcSlice->getSliceSegmentArgument()<<3) |
---|
| 1384 | && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()); |
---|
| 1385 | // Do not need to check slice condition for slice-segment since a slice-segment is a subset of a slice. |
---|
[608] | 1386 | if(isEndOfSlice||isEndOfSliceSegment) |
---|
[56] | 1387 | { |
---|
[1200] | 1388 | rpcBestCU->getTotalCost()=MAX_DOUBLE; |
---|
[56] | 1389 | } |
---|
[1200] | 1390 | |
---|
| 1391 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTempDebug) DEBUG_STRING_PASS_INTO(false) ); // RD compare current larger prediction |
---|
| 1392 | // with sub partitioned prediction. |
---|
[116] | 1393 | } |
---|
[1200] | 1394 | } |
---|
| 1395 | #if NH_3D_VSO // M12 |
---|
[56] | 1396 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 1397 | { |
---|
[1200] | 1398 | UInt uiWidth = m_ppcRecoYuvBest[uiDepth]->getWidth ( COMPONENT_Y ); |
---|
| 1399 | UInt uiHeight = m_ppcRecoYuvBest[uiDepth]->getHeight ( COMPONENT_Y ); |
---|
| 1400 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getAddr ( COMPONENT_Y, 0 ); |
---|
| 1401 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride ( COMPONENT_Y ); |
---|
[116] | 1402 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
[56] | 1403 | } |
---|
| 1404 | #endif |
---|
[1200] | 1405 | |
---|
| 1406 | DEBUG_STRING_APPEND(sDebug_, sDebug); |
---|
| 1407 | |
---|
[2] | 1408 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
| 1409 | |
---|
[1200] | 1410 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getCtuRsAddr(), rpcBestCU->getZorderIdxInCtu(), uiDepth, uiDepth ); // Copy Yuv data to picture Yuv |
---|
| 1411 | if (bBoundary) |
---|
[56] | 1412 | { |
---|
[2] | 1413 | return; |
---|
[56] | 1414 | } |
---|
[2] | 1415 | |
---|
| 1416 | // Assert if Best prediction mode is NONE |
---|
| 1417 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
[1200] | 1418 | assert( rpcBestCU->getPartitionSize ( 0 ) != NUMBER_OF_PART_SIZES ); |
---|
| 1419 | assert( rpcBestCU->getPredictionMode( 0 ) != NUMBER_OF_PREDICTION_MODES ); |
---|
| 1420 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
[2] | 1421 | } |
---|
| 1422 | |
---|
[56] | 1423 | /** finish encoding a cu and handle end-of-slice conditions |
---|
| 1424 | * \param pcCU |
---|
| 1425 | * \param uiAbsPartIdx |
---|
[1200] | 1426 | * \param uiDepth |
---|
[56] | 1427 | * \returns Void |
---|
| 1428 | */ |
---|
[1200] | 1429 | Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
[56] | 1430 | { |
---|
| 1431 | TComPic* pcPic = pcCU->getPic(); |
---|
| 1432 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
| 1433 | |
---|
| 1434 | //Calculate end address |
---|
[1200] | 1435 | const Int currentCTUTsAddr = pcPic->getPicSym()->getCtuRsToTsAddrMap(pcCU->getCtuRsAddr()); |
---|
| 1436 | const Bool isLastSubCUOfCtu = pcCU->isLastSubCUOfCtu(uiAbsPartIdx); |
---|
| 1437 | if ( isLastSubCUOfCtu ) |
---|
[56] | 1438 | { |
---|
| 1439 | // The 1-terminating bit is added to all streams, so don't add it here when it's 1. |
---|
[1200] | 1440 | // i.e. when the slice segment CurEnd CTU address is the current CTU address+1. |
---|
| 1441 | if (pcSlice->getSliceSegmentCurEndCtuTsAddr() != currentCTUTsAddr+1) |
---|
[56] | 1442 | { |
---|
[1200] | 1443 | m_pcEntropyCoder->encodeTerminatingBit( 0 ); |
---|
[56] | 1444 | } |
---|
| 1445 | } |
---|
| 1446 | } |
---|
| 1447 | |
---|
| 1448 | /** Compute QP for each CU |
---|
| 1449 | * \param pcCU Target CU |
---|
| 1450 | * \param uiDepth CU depth |
---|
| 1451 | * \returns quantization parameter |
---|
| 1452 | */ |
---|
| 1453 | Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth ) |
---|
| 1454 | { |
---|
| 1455 | Int iBaseQp = pcCU->getSlice()->getSliceQp(); |
---|
| 1456 | Int iQpOffset = 0; |
---|
| 1457 | if ( m_pcEncCfg->getUseAdaptiveQP() ) |
---|
| 1458 | { |
---|
| 1459 | TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() ); |
---|
| 1460 | UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 ); |
---|
| 1461 | TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth ); |
---|
| 1462 | UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth(); |
---|
| 1463 | UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight(); |
---|
| 1464 | UInt uiAQUStride = pcAQLayer->getAQPartStride(); |
---|
| 1465 | TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit(); |
---|
| 1466 | |
---|
| 1467 | Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0); |
---|
| 1468 | Double dAvgAct = pcAQLayer->getAvgActivity(); |
---|
| 1469 | Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity(); |
---|
| 1470 | Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct); |
---|
| 1471 | Double dQpOffset = log(dNormAct) / log(2.0) * 6.0; |
---|
| 1472 | iQpOffset = Int(floor( dQpOffset + 0.49999 )); |
---|
| 1473 | } |
---|
[1200] | 1474 | |
---|
| 1475 | return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQp+iQpOffset ); |
---|
[56] | 1476 | } |
---|
| 1477 | |
---|
[2] | 1478 | /** encode a CU block recursively |
---|
| 1479 | * \param pcCU |
---|
| 1480 | * \param uiAbsPartIdx |
---|
[1200] | 1481 | * \param uiDepth |
---|
[2] | 1482 | * \returns Void |
---|
| 1483 | */ |
---|
| 1484 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1485 | { |
---|
[1200] | 1486 | TComPic *const pcPic = pcCU->getPic(); |
---|
| 1487 | TComSlice *const pcSlice = pcCU->getSlice(); |
---|
| 1488 | const TComSPS &sps =*(pcSlice->getSPS()); |
---|
| 1489 | const TComPPS &pps =*(pcSlice->getPPS()); |
---|
| 1490 | |
---|
| 1491 | const UInt maxCUWidth = sps.getMaxCUWidth(); |
---|
| 1492 | const UInt maxCUHeight = sps.getMaxCUHeight(); |
---|
| 1493 | |
---|
| 1494 | Bool bBoundary = false; |
---|
| 1495 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1496 | const UInt uiRPelX = uiLPelX + (maxCUWidth>>uiDepth) - 1; |
---|
| 1497 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1498 | const UInt uiBPelY = uiTPelY + (maxCUHeight>>uiDepth) - 1; |
---|
| 1499 | |
---|
[608] | 1500 | #if H_MV_ENC_DEC_TRAC |
---|
| 1501 | DTRACE_CU_S("=========== coding_quadtree ===========\n") |
---|
| 1502 | DTRACE_CU("x0", uiLPelX) |
---|
| 1503 | DTRACE_CU("x1", uiTPelY) |
---|
[1200] | 1504 | DTRACE_CU("log2CbSize", maxCUWidth>>uiDepth ) |
---|
[608] | 1505 | DTRACE_CU("cqtDepth" , uiDepth) |
---|
| 1506 | #endif |
---|
[443] | 1507 | |
---|
[1200] | 1508 | if( ( uiRPelX < sps.getPicWidthInLumaSamples() ) && ( uiBPelY < sps.getPicHeightInLumaSamples() ) ) |
---|
[2] | 1509 | { |
---|
[56] | 1510 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
[2] | 1511 | } |
---|
| 1512 | else |
---|
| 1513 | { |
---|
| 1514 | bBoundary = true; |
---|
| 1515 | } |
---|
[1200] | 1516 | |
---|
| 1517 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) ) || bBoundary ) |
---|
[2] | 1518 | { |
---|
[1200] | 1519 | UInt uiQNumParts = ( pcPic->getNumPartitionsInCtu() >> (uiDepth<<1) )>>2; |
---|
| 1520 | if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP()) |
---|
[56] | 1521 | { |
---|
| 1522 | setdQPFlag(true); |
---|
| 1523 | } |
---|
[1200] | 1524 | |
---|
| 1525 | if( uiDepth == pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcSlice->getUseChromaQpAdj()) |
---|
| 1526 | { |
---|
| 1527 | setCodeChromaQpAdjFlag(true); |
---|
| 1528 | } |
---|
| 1529 | |
---|
[2] | 1530 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
| 1531 | { |
---|
| 1532 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1533 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
[1200] | 1534 | if( ( uiLPelX < sps.getPicWidthInLumaSamples() ) && ( uiTPelY < sps.getPicHeightInLumaSamples() ) ) |
---|
[56] | 1535 | { |
---|
[2] | 1536 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
[56] | 1537 | } |
---|
[2] | 1538 | } |
---|
| 1539 | return; |
---|
| 1540 | } |
---|
[1200] | 1541 | |
---|
[608] | 1542 | #if H_MV_ENC_DEC_TRAC |
---|
| 1543 | DTRACE_CU_S("=========== coding_unit ===========\n") |
---|
| 1544 | #endif |
---|
| 1545 | |
---|
[1200] | 1546 | |
---|
| 1547 | if( uiDepth <= pps.getMaxCuDQPDepth() && pps.getUseDQP()) |
---|
[56] | 1548 | { |
---|
| 1549 | setdQPFlag(true); |
---|
| 1550 | } |
---|
[1200] | 1551 | |
---|
| 1552 | if( uiDepth <= pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcSlice->getUseChromaQpAdj()) |
---|
[608] | 1553 | { |
---|
[1200] | 1554 | setCodeChromaQpAdjFlag(true); |
---|
| 1555 | } |
---|
| 1556 | |
---|
| 1557 | if (pps.getTransquantBypassEnableFlag()) |
---|
| 1558 | { |
---|
[608] | 1559 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx ); |
---|
| 1560 | } |
---|
[1200] | 1561 | |
---|
| 1562 | if( !pcSlice->isIntra() ) |
---|
[2] | 1563 | { |
---|
| 1564 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
| 1565 | } |
---|
[1200] | 1566 | |
---|
[2] | 1567 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
| 1568 | { |
---|
[608] | 1569 | #if H_MV_ENC_DEC_TRAC |
---|
| 1570 | DTRACE_PU_S("=========== prediction_unit ===========\n") |
---|
| 1571 | DTRACE_PU("x0", uiLPelX) |
---|
| 1572 | DTRACE_PU("x1", uiTPelY) |
---|
[115] | 1573 | #endif |
---|
[1200] | 1574 | |
---|
[608] | 1575 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
| 1576 | #if H_3D_ARP |
---|
| 1577 | m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx ); |
---|
[443] | 1578 | #endif |
---|
[833] | 1579 | #if H_3D_IC |
---|
| 1580 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
| 1581 | #endif |
---|
[1200] | 1582 | |
---|
| 1583 | finishCU(pcCU,uiAbsPartIdx); |
---|
[2] | 1584 | return; |
---|
| 1585 | } |
---|
[1200] | 1586 | |
---|
[1196] | 1587 | #if H_3D |
---|
[1179] | 1588 | m_pcEntropyCoder->encodeDIS( pcCU, uiAbsPartIdx ); |
---|
| 1589 | if(!pcCU->getDISFlag(uiAbsPartIdx)) |
---|
| 1590 | { |
---|
[1039] | 1591 | #endif |
---|
[56] | 1592 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
| 1593 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
[1200] | 1594 | |
---|
[56] | 1595 | if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
| 1596 | { |
---|
| 1597 | m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx ); |
---|
[1200] | 1598 | |
---|
[56] | 1599 | if(pcCU->getIPCMFlag(uiAbsPartIdx)) |
---|
| 1600 | { |
---|
[1179] | 1601 | #if H_3D_DIM_SDC |
---|
| 1602 | m_pcEntropyCoder->encodeSDCFlag( pcCU, uiAbsPartIdx, false ); |
---|
| 1603 | #endif |
---|
[1200] | 1604 | |
---|
[56] | 1605 | // Encode slice finish |
---|
[1200] | 1606 | finishCU(pcCU,uiAbsPartIdx); |
---|
[56] | 1607 | return; |
---|
| 1608 | } |
---|
| 1609 | } |
---|
[2] | 1610 | |
---|
[56] | 1611 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
| 1612 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
[1196] | 1613 | #if H_3D |
---|
[1179] | 1614 | m_pcEntropyCoder->encodeDBBPFlag( pcCU, uiAbsPartIdx ); |
---|
[1196] | 1615 | #endif |
---|
[1179] | 1616 | #if H_3D_DIM_SDC |
---|
| 1617 | m_pcEntropyCoder->encodeSDCFlag( pcCU, uiAbsPartIdx, false ); |
---|
| 1618 | #endif |
---|
[608] | 1619 | #if H_3D_ARP |
---|
| 1620 | m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx ); |
---|
[296] | 1621 | #endif |
---|
[833] | 1622 | #if H_3D_IC |
---|
| 1623 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
| 1624 | #endif |
---|
[1200] | 1625 | |
---|
[2] | 1626 | // Encode Coefficients |
---|
[56] | 1627 | Bool bCodeDQP = getdQPFlag(); |
---|
[1200] | 1628 | Bool codeChromaQpAdj = getCodeChromaQpAdjFlag(); |
---|
| 1629 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, bCodeDQP, codeChromaQpAdj ); |
---|
| 1630 | setCodeChromaQpAdjFlag( codeChromaQpAdj ); |
---|
[56] | 1631 | setdQPFlag( bCodeDQP ); |
---|
[1196] | 1632 | #if H_3D |
---|
[1179] | 1633 | } |
---|
[1039] | 1634 | #endif |
---|
[1200] | 1635 | |
---|
| 1636 | |
---|
[56] | 1637 | // --- write terminating bit --- |
---|
[1200] | 1638 | finishCU(pcCU,uiAbsPartIdx); |
---|
[2] | 1639 | } |
---|
| 1640 | |
---|
[1200] | 1641 | Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) |
---|
[608] | 1642 | { |
---|
| 1643 | Int k, i, j, jj; |
---|
| 1644 | Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0; |
---|
| 1645 | |
---|
| 1646 | for( k = 0; k < 64; k += 8 ) |
---|
| 1647 | { |
---|
| 1648 | diff[k+0] = piOrg[0] ; |
---|
| 1649 | diff[k+1] = piOrg[1] ; |
---|
| 1650 | diff[k+2] = piOrg[2] ; |
---|
| 1651 | diff[k+3] = piOrg[3] ; |
---|
| 1652 | diff[k+4] = piOrg[4] ; |
---|
| 1653 | diff[k+5] = piOrg[5] ; |
---|
| 1654 | diff[k+6] = piOrg[6] ; |
---|
| 1655 | diff[k+7] = piOrg[7] ; |
---|
[1200] | 1656 | |
---|
[608] | 1657 | piOrg += iStrideOrg; |
---|
| 1658 | } |
---|
[1200] | 1659 | |
---|
[608] | 1660 | //horizontal |
---|
| 1661 | for (j=0; j < 8; j++) |
---|
| 1662 | { |
---|
| 1663 | jj = j << 3; |
---|
| 1664 | m2[j][0] = diff[jj ] + diff[jj+4]; |
---|
| 1665 | m2[j][1] = diff[jj+1] + diff[jj+5]; |
---|
| 1666 | m2[j][2] = diff[jj+2] + diff[jj+6]; |
---|
| 1667 | m2[j][3] = diff[jj+3] + diff[jj+7]; |
---|
| 1668 | m2[j][4] = diff[jj ] - diff[jj+4]; |
---|
| 1669 | m2[j][5] = diff[jj+1] - diff[jj+5]; |
---|
| 1670 | m2[j][6] = diff[jj+2] - diff[jj+6]; |
---|
| 1671 | m2[j][7] = diff[jj+3] - diff[jj+7]; |
---|
[1200] | 1672 | |
---|
[608] | 1673 | m1[j][0] = m2[j][0] + m2[j][2]; |
---|
| 1674 | m1[j][1] = m2[j][1] + m2[j][3]; |
---|
| 1675 | m1[j][2] = m2[j][0] - m2[j][2]; |
---|
| 1676 | m1[j][3] = m2[j][1] - m2[j][3]; |
---|
| 1677 | m1[j][4] = m2[j][4] + m2[j][6]; |
---|
| 1678 | m1[j][5] = m2[j][5] + m2[j][7]; |
---|
| 1679 | m1[j][6] = m2[j][4] - m2[j][6]; |
---|
| 1680 | m1[j][7] = m2[j][5] - m2[j][7]; |
---|
[1200] | 1681 | |
---|
[608] | 1682 | m2[j][0] = m1[j][0] + m1[j][1]; |
---|
| 1683 | m2[j][1] = m1[j][0] - m1[j][1]; |
---|
| 1684 | m2[j][2] = m1[j][2] + m1[j][3]; |
---|
| 1685 | m2[j][3] = m1[j][2] - m1[j][3]; |
---|
| 1686 | m2[j][4] = m1[j][4] + m1[j][5]; |
---|
| 1687 | m2[j][5] = m1[j][4] - m1[j][5]; |
---|
| 1688 | m2[j][6] = m1[j][6] + m1[j][7]; |
---|
| 1689 | m2[j][7] = m1[j][6] - m1[j][7]; |
---|
| 1690 | } |
---|
[1200] | 1691 | |
---|
[608] | 1692 | //vertical |
---|
| 1693 | for (i=0; i < 8; i++) |
---|
| 1694 | { |
---|
| 1695 | m3[0][i] = m2[0][i] + m2[4][i]; |
---|
| 1696 | m3[1][i] = m2[1][i] + m2[5][i]; |
---|
| 1697 | m3[2][i] = m2[2][i] + m2[6][i]; |
---|
| 1698 | m3[3][i] = m2[3][i] + m2[7][i]; |
---|
| 1699 | m3[4][i] = m2[0][i] - m2[4][i]; |
---|
| 1700 | m3[5][i] = m2[1][i] - m2[5][i]; |
---|
| 1701 | m3[6][i] = m2[2][i] - m2[6][i]; |
---|
| 1702 | m3[7][i] = m2[3][i] - m2[7][i]; |
---|
[1200] | 1703 | |
---|
[608] | 1704 | m1[0][i] = m3[0][i] + m3[2][i]; |
---|
| 1705 | m1[1][i] = m3[1][i] + m3[3][i]; |
---|
| 1706 | m1[2][i] = m3[0][i] - m3[2][i]; |
---|
| 1707 | m1[3][i] = m3[1][i] - m3[3][i]; |
---|
| 1708 | m1[4][i] = m3[4][i] + m3[6][i]; |
---|
| 1709 | m1[5][i] = m3[5][i] + m3[7][i]; |
---|
| 1710 | m1[6][i] = m3[4][i] - m3[6][i]; |
---|
| 1711 | m1[7][i] = m3[5][i] - m3[7][i]; |
---|
[1200] | 1712 | |
---|
[608] | 1713 | m2[0][i] = m1[0][i] + m1[1][i]; |
---|
| 1714 | m2[1][i] = m1[0][i] - m1[1][i]; |
---|
| 1715 | m2[2][i] = m1[2][i] + m1[3][i]; |
---|
| 1716 | m2[3][i] = m1[2][i] - m1[3][i]; |
---|
| 1717 | m2[4][i] = m1[4][i] + m1[5][i]; |
---|
| 1718 | m2[5][i] = m1[4][i] - m1[5][i]; |
---|
| 1719 | m2[6][i] = m1[6][i] + m1[7][i]; |
---|
| 1720 | m2[7][i] = m1[6][i] - m1[7][i]; |
---|
| 1721 | } |
---|
[1200] | 1722 | |
---|
[608] | 1723 | for (i = 0; i < 8; i++) |
---|
| 1724 | { |
---|
| 1725 | for (j = 0; j < 8; j++) |
---|
| 1726 | { |
---|
| 1727 | iSumHad += abs(m2[i][j]); |
---|
| 1728 | } |
---|
| 1729 | } |
---|
| 1730 | iSumHad -= abs(m2[0][0]); |
---|
| 1731 | iSumHad =(iSumHad+2)>>2; |
---|
| 1732 | return(iSumHad); |
---|
| 1733 | } |
---|
| 1734 | |
---|
[1200] | 1735 | Int TEncCu::updateCtuDataISlice(TComDataCU* pCtu, Int width, Int height) |
---|
[608] | 1736 | { |
---|
[1200] | 1737 | Int xBl, yBl; |
---|
[608] | 1738 | const Int iBlkSize = 8; |
---|
| 1739 | |
---|
[1200] | 1740 | Pel* pOrgInit = pCtu->getPic()->getPicYuvOrg()->getAddr(COMPONENT_Y, pCtu->getCtuRsAddr(), 0); |
---|
| 1741 | Int iStrideOrig = pCtu->getPic()->getPicYuvOrg()->getStride(COMPONENT_Y); |
---|
[608] | 1742 | Pel *pOrg; |
---|
| 1743 | |
---|
| 1744 | Int iSumHad = 0; |
---|
| 1745 | for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize) |
---|
| 1746 | { |
---|
| 1747 | for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize) |
---|
| 1748 | { |
---|
[1200] | 1749 | pOrg = pOrgInit + iStrideOrig*yBl + xBl; |
---|
[608] | 1750 | iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig); |
---|
| 1751 | } |
---|
| 1752 | } |
---|
| 1753 | return(iSumHad); |
---|
| 1754 | } |
---|
| 1755 | |
---|
[2] | 1756 | /** check RD costs for a CU block encoded with merge |
---|
| 1757 | * \param rpcBestCU |
---|
| 1758 | * \param rpcTempCU |
---|
[1200] | 1759 | * \param earlyDetectionSkipMode |
---|
[2] | 1760 | */ |
---|
[1200] | 1761 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU DEBUG_STRING_FN_DECLARE(sDebug), Bool *earlyDetectionSkipMode ) |
---|
[2] | 1762 | { |
---|
| 1763 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
[1233] | 1764 | #if NH_3D_MLC |
---|
[56] | 1765 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists |
---|
| 1766 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM]; |
---|
| 1767 | #else |
---|
[608] | 1768 | TComMvField cMvFieldNeighbours[2 * MRG_MAX_NUM_CANDS]; // double length for mv of both lists |
---|
[2] | 1769 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
[56] | 1770 | #endif |
---|
| 1771 | Int numValidMergeCand = 0; |
---|
[872] | 1772 | const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0); |
---|
[2] | 1773 | |
---|
[608] | 1774 | for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) |
---|
[2] | 1775 | { |
---|
| 1776 | uhInterDirNeighbours[ui] = 0; |
---|
| 1777 | } |
---|
| 1778 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
[608] | 1779 | #if H_3D_IC |
---|
| 1780 | Bool bICFlag = rpcTempCU->getICFlag( 0 ); |
---|
| 1781 | #endif |
---|
[1200] | 1782 | #if NH_3D_VSO // M1 //necessary here? |
---|
[2] | 1783 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 1784 | { |
---|
[1200] | 1785 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y ); |
---|
| 1786 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( COMPONENT_Y ); |
---|
| 1787 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getAddr ( COMPONENT_Y ); |
---|
| 1788 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride( COMPONENT_Y ); |
---|
[81] | 1789 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
[2] | 1790 | } |
---|
[5] | 1791 | #endif |
---|
[2] | 1792 | |
---|
[773] | 1793 | #if H_3D_ARP |
---|
[724] | 1794 | DisInfo cOrigDisInfo = rpcTempCU->getDvInfo(0); |
---|
| 1795 | #else |
---|
| 1796 | #endif |
---|
[608] | 1797 | |
---|
[1200] | 1798 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level |
---|
[1233] | 1799 | |
---|
[608] | 1800 | #if H_3D_VSP |
---|
[773] | 1801 | #if !H_3D_ARP |
---|
[608] | 1802 | Int vspFlag[MRG_MAX_NUM_CANDS_MEM]; |
---|
| 1803 | memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM); |
---|
| 1804 | InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM]; |
---|
[1233] | 1805 | #if NH_3D_MLC |
---|
| 1806 | rpcTempCU->initAvailableFlags(); |
---|
| 1807 | #endif |
---|
[724] | 1808 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
[1233] | 1809 | #if NH_3D_MLC |
---|
| 1810 | rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours |
---|
| 1811 | #if H_3D_SPIVMP |
---|
| 1812 | , pcMvFieldSP, puhInterDirSP |
---|
[724] | 1813 | #endif |
---|
[1233] | 1814 | , numValidMergeCand |
---|
| 1815 | ); |
---|
| 1816 | |
---|
| 1817 | rpcTempCU->buildMCL( cMvFieldNeighbours,uhInterDirNeighbours, vspFlag |
---|
| 1818 | #if H_3D_SPIVMP |
---|
| 1819 | , bSPIVMPFlag |
---|
| 1820 | #endif |
---|
| 1821 | , numValidMergeCand |
---|
| 1822 | ); |
---|
| 1823 | #endif |
---|
| 1824 | #endif |
---|
[724] | 1825 | #else |
---|
[1233] | 1826 | #if NH_3D_MLC |
---|
| 1827 | rpcTempCU->initAvailableFlags(); |
---|
| 1828 | #endif |
---|
[608] | 1829 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); |
---|
[1233] | 1830 | #if NH_3D_MLC |
---|
| 1831 | rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours |
---|
| 1832 | #if H_3D_SPIVMP |
---|
| 1833 | , pcMvFieldSP, puhInterDirSP |
---|
[443] | 1834 | #endif |
---|
[1233] | 1835 | , numValidMergeCand |
---|
| 1836 | ); |
---|
| 1837 | #if NH_3D_MLC |
---|
| 1838 | rpcTempCU->buildMCL( cMvFieldNeighbours,uhInterDirNeighbours |
---|
| 1839 | #if H_3D_SPIVMP |
---|
| 1840 | , bSPIVMPFlag |
---|
[724] | 1841 | #endif |
---|
[1233] | 1842 | , numValidMergeCand |
---|
| 1843 | ); |
---|
| 1844 | #endif |
---|
| 1845 | #endif |
---|
| 1846 | #endif |
---|
| 1847 | |
---|
| 1848 | |
---|
| 1849 | |
---|
| 1850 | |
---|
| 1851 | |
---|
| 1852 | |
---|
| 1853 | |
---|
| 1854 | |
---|
| 1855 | #if NH_3D_MLC |
---|
[608] | 1856 | Int mergeCandBuffer[MRG_MAX_NUM_CANDS_MEM]; |
---|
[296] | 1857 | #else |
---|
[608] | 1858 | Int mergeCandBuffer[MRG_MAX_NUM_CANDS]; |
---|
[296] | 1859 | #endif |
---|
[773] | 1860 | #if H_3D_ARP |
---|
[724] | 1861 | for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) |
---|
| 1862 | #else |
---|
[1233] | 1863 | #if NH_3D_MLC |
---|
| 1864 | for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) |
---|
| 1865 | #else |
---|
[1200] | 1866 | for( UInt ui = 0; ui < numValidMergeCand; ++ui ) |
---|
[724] | 1867 | #endif |
---|
[1233] | 1868 | #endif |
---|
[608] | 1869 | { |
---|
| 1870 | mergeCandBuffer[ui] = 0; |
---|
| 1871 | } |
---|
[2] | 1872 | |
---|
[56] | 1873 | Bool bestIsSkip = false; |
---|
[608] | 1874 | |
---|
| 1875 | UInt iteration; |
---|
| 1876 | if ( rpcTempCU->isLosslessCoded(0)) |
---|
[443] | 1877 | { |
---|
[608] | 1878 | iteration = 1; |
---|
| 1879 | } |
---|
[1200] | 1880 | else |
---|
[2] | 1881 | { |
---|
[608] | 1882 | iteration = 2; |
---|
| 1883 | } |
---|
[1200] | 1884 | DEBUG_STRING_NEW(bestStr) |
---|
[608] | 1885 | |
---|
| 1886 | #if H_3D_ARP |
---|
| 1887 | Int nARPWMax = rpcTempCU->getSlice()->getARPStepNum() - 1; |
---|
[1179] | 1888 | if( nARPWMax < 0 || bICFlag ) |
---|
[608] | 1889 | { |
---|
| 1890 | nARPWMax = 0; |
---|
| 1891 | } |
---|
| 1892 | for( Int nARPW=nARPWMax; nARPW >= 0 ; nARPW-- ) |
---|
| 1893 | { |
---|
[724] | 1894 | memset( mergeCandBuffer, 0, MRG_MAX_NUM_CANDS_MEM*sizeof(Int) ); |
---|
| 1895 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1896 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
| 1897 | #if H_3D_IC |
---|
| 1898 | rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth ); |
---|
| 1899 | #endif |
---|
| 1900 | rpcTempCU->getDvInfo(0) = cOrigDisInfo; |
---|
| 1901 | rpcTempCU->setDvInfoSubParts(cOrigDisInfo, 0, 0, uhDepth ); |
---|
| 1902 | Int vspFlag[MRG_MAX_NUM_CANDS_MEM]; |
---|
| 1903 | memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM); |
---|
[773] | 1904 | #if H_3D_SPIVMP |
---|
[724] | 1905 | Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM]; |
---|
| 1906 | memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM); |
---|
| 1907 | TComMvField* pcMvFieldSP; |
---|
| 1908 | UChar* puhInterDirSP; |
---|
| 1909 | pcMvFieldSP = new TComMvField[rpcTempCU->getPic()->getPicSym()->getNumPartition()*2]; |
---|
| 1910 | puhInterDirSP = new UChar[rpcTempCU->getPic()->getPicSym()->getNumPartition()]; |
---|
| 1911 | #endif |
---|
[773] | 1912 | #if H_3D |
---|
[724] | 1913 | rpcTempCU->initAvailableFlags(); |
---|
| 1914 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
[950] | 1915 | rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours |
---|
[773] | 1916 | #if H_3D_SPIVMP |
---|
[950] | 1917 | , pcMvFieldSP, puhInterDirSP |
---|
| 1918 | #endif |
---|
[724] | 1919 | , numValidMergeCand |
---|
| 1920 | ); |
---|
[950] | 1921 | |
---|
[1233] | 1922 | rpcTempCU->buildMCL( cMvFieldNeighbours,uhInterDirNeighbours |
---|
| 1923 | #if H_3D_VSP |
---|
| 1924 | , vspFlag |
---|
| 1925 | #endif |
---|
[950] | 1926 | #if H_3D_SPIVMP |
---|
| 1927 | , bSPIVMPFlag |
---|
| 1928 | #endif |
---|
| 1929 | , numValidMergeCand |
---|
| 1930 | ); |
---|
| 1931 | |
---|
[724] | 1932 | #else |
---|
[1039] | 1933 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag, numValidMergeCand ); |
---|
[724] | 1934 | #endif |
---|
[773] | 1935 | |
---|
[1039] | 1936 | |
---|
[724] | 1937 | #endif |
---|
[833] | 1938 | |
---|
[608] | 1939 | for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
| 1940 | { |
---|
| 1941 | for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) |
---|
[1200] | 1942 | { |
---|
[608] | 1943 | #if H_3D_IC |
---|
[1196] | 1944 | if( rpcTempCU->getSlice()->getApplyIC() && rpcTempCU->getSlice()->getIcSkipParseFlag() ) |
---|
| 1945 | { |
---|
| 1946 | if( bICFlag && uiMergeCand == 0 ) |
---|
[443] | 1947 | { |
---|
[1196] | 1948 | continue; |
---|
[443] | 1949 | } |
---|
[1196] | 1950 | } |
---|
[443] | 1951 | #endif |
---|
[1200] | 1952 | |
---|
[1196] | 1953 | if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1)) |
---|
| 1954 | { |
---|
[56] | 1955 | if( !(bestIsSkip && uiNoResidual == 0) ) |
---|
| 1956 | { |
---|
[1200] | 1957 | DEBUG_STRING_NEW(tmpStr) |
---|
[56] | 1958 | // set MC parameters |
---|
[1200] | 1959 | rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to CTU level |
---|
[608] | 1960 | #if H_3D_IC |
---|
| 1961 | rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth ); |
---|
[443] | 1962 | #endif |
---|
[608] | 1963 | #if H_3D_ARP |
---|
| 1964 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
| 1965 | #endif |
---|
[1200] | 1966 | rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag, 0, uhDepth ); |
---|
| 1967 | rpcTempCU->setChromaQpAdjSubParts( bTransquantBypassFlag ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uhDepth ); |
---|
| 1968 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level |
---|
| 1969 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to CTU level |
---|
| 1970 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to CTU level |
---|
[608] | 1971 | #if H_3D_VSP |
---|
| 1972 | rpcTempCU->setVSPFlagSubParts( vspFlag[uiMergeCand], 0, 0, uhDepth ); |
---|
[443] | 1973 | #endif |
---|
[773] | 1974 | #if H_3D_SPIVMP |
---|
[724] | 1975 | rpcTempCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeCand], 0, 0, uhDepth); |
---|
| 1976 | if (bSPIVMPFlag[uiMergeCand]) |
---|
| 1977 | { |
---|
| 1978 | UInt uiSPAddr; |
---|
| 1979 | Int iWidth = rpcTempCU->getWidth(0); |
---|
| 1980 | Int iHeight = rpcTempCU->getHeight(0); |
---|
| 1981 | Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; |
---|
| 1982 | rpcTempCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); |
---|
| 1983 | for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++) |
---|
| 1984 | { |
---|
| 1985 | rpcTempCU->getSPAbsPartIdx(0, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr); |
---|
| 1986 | rpcTempCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight); |
---|
| 1987 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight); |
---|
| 1988 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight); |
---|
| 1989 | } |
---|
| 1990 | } |
---|
| 1991 | else |
---|
[833] | 1992 | #endif |
---|
[884] | 1993 | #if H_3D_VSP |
---|
| 1994 | { |
---|
[1196] | 1995 | if ( vspFlag[uiMergeCand] ) |
---|
[833] | 1996 | { |
---|
[1196] | 1997 | UInt partAddr; |
---|
| 1998 | Int vspSize; |
---|
| 1999 | Int width, height; |
---|
| 2000 | rpcTempCU->getPartIndexAndSize( 0, partAddr, width, height ); |
---|
| 2001 | if( uhInterDirNeighbours[ uiMergeCand ] & 0x01 ) |
---|
| 2002 | { |
---|
| 2003 | rpcTempCU->setMvFieldPUForVSP( rpcTempCU, partAddr, width, height, REF_PIC_LIST_0, cMvFieldNeighbours[ 2*uiMergeCand + 0 ].getRefIdx(), vspSize ); |
---|
| 2004 | rpcTempCU->setVSPFlag( partAddr, vspSize ); |
---|
| 2005 | } |
---|
| 2006 | else |
---|
| 2007 | { |
---|
| 2008 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
| 2009 | } |
---|
| 2010 | if( uhInterDirNeighbours[ uiMergeCand ] & 0x02 ) |
---|
| 2011 | { |
---|
| 2012 | rpcTempCU->setMvFieldPUForVSP( rpcTempCU, partAddr, width, height, REF_PIC_LIST_1 , cMvFieldNeighbours[ 2*uiMergeCand + 1 ].getRefIdx(), vspSize ); |
---|
| 2013 | rpcTempCU->setVSPFlag( partAddr, vspSize ); |
---|
| 2014 | } |
---|
| 2015 | else |
---|
| 2016 | { |
---|
| 2017 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
| 2018 | } |
---|
| 2019 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
[833] | 2020 | } |
---|
| 2021 | else |
---|
| 2022 | { |
---|
[1196] | 2023 | #endif |
---|
[1200] | 2024 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to CTU level |
---|
| 2025 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
| 2026 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
[1196] | 2027 | #if H_3D_VSP |
---|
[833] | 2028 | } |
---|
| 2029 | } |
---|
[724] | 2030 | #endif |
---|
[1196] | 2031 | // do MC |
---|
| 2032 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
| 2033 | // estimate residual and encode everything |
---|
[1200] | 2034 | #if NH_3D_VSO //M2 |
---|
[1196] | 2035 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 2036 | { //Reset |
---|
[1200] | 2037 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y ); |
---|
| 2038 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight ( COMPONENT_Y ); |
---|
| 2039 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getAddr ( COMPONENT_Y ); |
---|
| 2040 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride ( COMPONENT_Y ); |
---|
[1196] | 2041 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
[724] | 2042 | } |
---|
[872] | 2043 | #endif |
---|
[1196] | 2044 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
[1200] | 2045 | m_ppcOrigYuv [uhDepth], |
---|
| 2046 | m_ppcPredYuvTemp[uhDepth], |
---|
| 2047 | m_ppcResiYuvTemp[uhDepth], |
---|
| 2048 | m_ppcResiYuvBest[uhDepth], |
---|
| 2049 | m_ppcRecoYuvTemp[uhDepth], |
---|
| 2050 | (uiNoResidual != 0) DEBUG_STRING_PASS_INTO(tmpStr) ); |
---|
[608] | 2051 | |
---|
[1200] | 2052 | #if DEBUG_STRING |
---|
| 2053 | DebugInterPredResiReco(tmpStr, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0))); |
---|
| 2054 | #endif |
---|
[608] | 2055 | |
---|
[1200] | 2056 | if ((uiNoResidual == 0) && (rpcTempCU->getQtRootCbf(0) == 0)) |
---|
[1196] | 2057 | { |
---|
[608] | 2058 | // If no residual when allowing for one, then set mark to not try case where residual is forced to 0 |
---|
[1196] | 2059 | mergeCandBuffer[uiMergeCand] = 1; |
---|
| 2060 | } |
---|
| 2061 | #if H_3D |
---|
[1179] | 2062 | rpcTempCU->setDISFlagSubParts( false, 0, uhDepth ); |
---|
[1039] | 2063 | #endif |
---|
[884] | 2064 | #if H_3D_VSP // possible bug fix |
---|
[833] | 2065 | if( rpcTempCU->getSkipFlag(0) ) |
---|
| 2066 | { |
---|
| 2067 | rpcTempCU->setTrIdxSubParts(0, 0, uhDepth); |
---|
| 2068 | } |
---|
| 2069 | #endif |
---|
[655] | 2070 | #if H_3D_INTER_SDC |
---|
[608] | 2071 | TComDataCU *rpcTempCUPre = rpcTempCU; |
---|
[296] | 2072 | #endif |
---|
[608] | 2073 | Int orgQP = rpcTempCU->getQP( 0 ); |
---|
| 2074 | xCheckDQP( rpcTempCU ); |
---|
[1200] | 2075 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(bestStr) DEBUG_STRING_PASS_INTO(tmpStr)); |
---|
[655] | 2076 | #if H_3D_INTER_SDC |
---|
[1124] | 2077 | if( rpcTempCU->getSlice()->getInterSdcFlag() && !uiNoResidual ) |
---|
[608] | 2078 | { |
---|
[1039] | 2079 | Double dOffsetCost[3] = {MAX_DOUBLE,MAX_DOUBLE,MAX_DOUBLE}; |
---|
| 2080 | for( Int uiOffest = 1 ; uiOffest <= 5 ; uiOffest++ ) |
---|
[833] | 2081 | { |
---|
[1039] | 2082 | if( uiOffest > 3) |
---|
| 2083 | { |
---|
| 2084 | if ( dOffsetCost[0] < (0.9*dOffsetCost[1]) && dOffsetCost[0] < (0.9*dOffsetCost[2]) ) |
---|
| 2085 | { |
---|
| 2086 | continue; |
---|
| 2087 | } |
---|
| 2088 | if ( dOffsetCost[1] < dOffsetCost[0] && dOffsetCost[0] < dOffsetCost[2] && uiOffest == 5) |
---|
| 2089 | { |
---|
| 2090 | continue; |
---|
| 2091 | } |
---|
| 2092 | if ( dOffsetCost[0] < dOffsetCost[1] && dOffsetCost[2] < dOffsetCost[0] && uiOffest == 4) |
---|
| 2093 | { |
---|
| 2094 | continue; |
---|
| 2095 | } |
---|
| 2096 | } |
---|
[833] | 2097 | if( rpcTempCU != rpcTempCUPre ) |
---|
| 2098 | { |
---|
[872] | 2099 | rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag ); |
---|
[833] | 2100 | rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth ); |
---|
| 2101 | } |
---|
| 2102 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
[1196] | 2103 | #if H_3D |
---|
[1179] | 2104 | rpcTempCU->setDISFlagSubParts( false, 0, uhDepth ); |
---|
[1039] | 2105 | #endif |
---|
[833] | 2106 | rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth ); |
---|
| 2107 | rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth ); |
---|
[1200] | 2108 | #if NH_3D_VSO //M2 |
---|
[833] | 2109 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 2110 | { //Reset |
---|
[1200] | 2111 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y ); |
---|
| 2112 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight ( COMPONENT_Y ); |
---|
| 2113 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getAddr ( COMPONENT_Y ); |
---|
| 2114 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride ( COMPONENT_Y ); |
---|
[833] | 2115 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
| 2116 | } |
---|
| 2117 | #endif |
---|
[1039] | 2118 | Int iSdcOffset = 0; |
---|
| 2119 | if(uiOffest % 2 == 0) |
---|
| 2120 | { |
---|
| 2121 | iSdcOffset = uiOffest >> 1; |
---|
| 2122 | } |
---|
| 2123 | else |
---|
| 2124 | { |
---|
| 2125 | iSdcOffset = -1 * (uiOffest >> 1); |
---|
| 2126 | } |
---|
[833] | 2127 | m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU, |
---|
| 2128 | m_ppcOrigYuv[uhDepth], |
---|
| 2129 | ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth], |
---|
| 2130 | m_ppcResiYuvTemp[uhDepth], |
---|
| 2131 | m_ppcRecoYuvTemp[uhDepth], |
---|
[1039] | 2132 | iSdcOffset, |
---|
| 2133 | uhDepth ); |
---|
| 2134 | if (uiOffest <= 3 ) |
---|
| 2135 | { |
---|
| 2136 | dOffsetCost [uiOffest -1] = rpcTempCU->getTotalCost(); |
---|
| 2137 | } |
---|
[833] | 2138 | |
---|
| 2139 | xCheckDQP( rpcTempCU ); |
---|
| 2140 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
| 2141 | } |
---|
[56] | 2142 | } |
---|
[296] | 2143 | #endif |
---|
[1200] | 2144 | |
---|
[872] | 2145 | rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag ); |
---|
[608] | 2146 | |
---|
[1196] | 2147 | if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) |
---|
| 2148 | { |
---|
[655] | 2149 | #if H_3D_INTER_SDC |
---|
[1196] | 2150 | if( rpcTempCU->getSlice()->getInterSdcFlag() ) |
---|
| 2151 | { |
---|
| 2152 | bestIsSkip = !rpcBestCU->getSDCFlag( 0 ) && ( rpcBestCU->getQtRootCbf(0) == 0 ); |
---|
| 2153 | } |
---|
| 2154 | else |
---|
| 2155 | { |
---|
[296] | 2156 | #endif |
---|
[1200] | 2157 | bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; |
---|
[655] | 2158 | #if H_3D_INTER_SDC |
---|
[1196] | 2159 | } |
---|
| 2160 | #endif |
---|
| 2161 | } |
---|
[608] | 2162 | } |
---|
| 2163 | } |
---|
| 2164 | } |
---|
[2] | 2165 | |
---|
[1196] | 2166 | if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection()) |
---|
[608] | 2167 | { |
---|
[1196] | 2168 | if(rpcBestCU->getQtRootCbf( 0 ) == 0) |
---|
[608] | 2169 | { |
---|
[1196] | 2170 | if( rpcBestCU->getMergeFlag( 0 )) |
---|
[608] | 2171 | { |
---|
[1196] | 2172 | *earlyDetectionSkipMode = true; |
---|
| 2173 | } |
---|
[1200] | 2174 | else if(m_pcEncCfg->getFastSearch() != SELECTIVE) |
---|
[1196] | 2175 | { |
---|
| 2176 | Int absoulte_MV=0; |
---|
| 2177 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
[56] | 2178 | { |
---|
[1196] | 2179 | if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
| 2180 | { |
---|
| 2181 | TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx )); |
---|
| 2182 | Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor(); |
---|
| 2183 | Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer(); |
---|
| 2184 | absoulte_MV+=iHor+iVer; |
---|
| 2185 | } |
---|
[56] | 2186 | } |
---|
[2] | 2187 | |
---|
[1196] | 2188 | if(absoulte_MV == 0) |
---|
| 2189 | { |
---|
| 2190 | *earlyDetectionSkipMode = true; |
---|
| 2191 | } |
---|
[56] | 2192 | } |
---|
[2] | 2193 | } |
---|
| 2194 | } |
---|
| 2195 | } |
---|
[1200] | 2196 | DEBUG_STRING_APPEND(sDebug, bestStr) |
---|
[773] | 2197 | #if H_3D_SPIVMP |
---|
[735] | 2198 | delete[] pcMvFieldSP; |
---|
| 2199 | delete[] puhInterDirSP; |
---|
[724] | 2200 | #endif |
---|
[608] | 2201 | #if H_3D_ARP |
---|
| 2202 | } |
---|
[443] | 2203 | #endif |
---|
[1200] | 2204 | |
---|
[2] | 2205 | } |
---|
| 2206 | |
---|
[608] | 2207 | |
---|
[56] | 2208 | #if AMP_MRG |
---|
[655] | 2209 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 2210 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bFMD, Bool bUseMRG) |
---|
[56] | 2211 | #else |
---|
[1200] | 2212 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize DEBUG_STRING_FN_DECLARE(sDebug), Bool bUseMRG) |
---|
[56] | 2213 | #endif |
---|
| 2214 | #else |
---|
[2] | 2215 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
| 2216 | #endif |
---|
[608] | 2217 | { |
---|
[1200] | 2218 | DEBUG_STRING_NEW(sTest) |
---|
| 2219 | |
---|
| 2220 | // prior to this, rpcTempCU will have just been reset using rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[872] | 2221 | #if H_3D |
---|
| 2222 | const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0); |
---|
| 2223 | #endif |
---|
[655] | 2224 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 2225 | if(!(bFMD && (ePartSize == SIZE_2Nx2N))) //have motion estimation or merge check |
---|
| 2226 | { |
---|
[56] | 2227 | #endif |
---|
[1200] | 2228 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
[608] | 2229 | #if H_3D_ARP |
---|
[1196] | 2230 | Bool bFirstTime = true; |
---|
| 2231 | Int nARPWMax = rpcTempCU->getSlice()->getARPStepNum() - 1; |
---|
| 2232 | if( nARPWMax < 0 || ePartSize != SIZE_2Nx2N || rpcTempCU->getICFlag(0) ) |
---|
| 2233 | { |
---|
| 2234 | nARPWMax = 0; |
---|
| 2235 | } |
---|
[608] | 2236 | |
---|
[1196] | 2237 | for( Int nARPW = 0; nARPW <= nARPWMax; nARPW++ ) |
---|
[608] | 2238 | { |
---|
[1196] | 2239 | if( !bFirstTime && rpcTempCU->getSlice()->getIvResPredFlag() ) |
---|
| 2240 | { |
---|
| 2241 | rpcTempCU->initEstData( rpcTempCU->getDepth(0), rpcTempCU->getQP(0),bTransquantBypassFlag ); |
---|
| 2242 | } |
---|
[608] | 2243 | #endif |
---|
[1200] | 2244 | #if NH_3D_VSO // M3 |
---|
[1196] | 2245 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 2246 | { |
---|
[1200] | 2247 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y ); |
---|
| 2248 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( COMPONENT_Y ); |
---|
| 2249 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getAddr ( COMPONENT_Y ); |
---|
| 2250 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride( COMPONENT_Y ); |
---|
[1196] | 2251 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
| 2252 | } |
---|
[608] | 2253 | #endif |
---|
[1196] | 2254 | #if H_3D |
---|
| 2255 | rpcTempCU->setDISFlagSubParts( false, 0, uhDepth ); |
---|
[1039] | 2256 | #endif |
---|
[1200] | 2257 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
| 2258 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
| 2259 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uhDepth ); |
---|
[608] | 2260 | #if H_3D_ARP |
---|
[1196] | 2261 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
[5] | 2262 | #endif |
---|
[608] | 2263 | #if H_3D_ARP |
---|
[1196] | 2264 | if( bFirstTime == false && nARPWMax ) |
---|
| 2265 | { |
---|
| 2266 | rpcTempCU->copyPartFrom( m_ppcWeightedTempCU[uhDepth] , 0 , uhDepth ); |
---|
| 2267 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
[608] | 2268 | |
---|
[1196] | 2269 | m_pcPredSearch->motionCompensation( rpcTempCU , m_ppcPredYuvTemp[uhDepth] ); |
---|
| 2270 | } |
---|
| 2271 | else |
---|
| 2272 | { |
---|
| 2273 | bFirstTime = false; |
---|
[443] | 2274 | #endif |
---|
[56] | 2275 | #if AMP_MRG |
---|
[1200] | 2276 | rpcTempCU->setMergeAMP (true); |
---|
[655] | 2277 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[1196] | 2278 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bFMD, false, bUseMRG ); |
---|
[56] | 2279 | #else |
---|
[1200] | 2280 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] DEBUG_STRING_PASS_INTO(sTest), false, bUseMRG ); |
---|
[56] | 2281 | #endif |
---|
[1200] | 2282 | |
---|
| 2283 | #else |
---|
| 2284 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
[2] | 2285 | #endif |
---|
[608] | 2286 | #if H_3D_ARP |
---|
[1196] | 2287 | if( nARPWMax ) |
---|
| 2288 | { |
---|
| 2289 | m_ppcWeightedTempCU[uhDepth]->copyPartFrom( rpcTempCU , 0 , uhDepth ); |
---|
| 2290 | } |
---|
| 2291 | } |
---|
[443] | 2292 | #endif |
---|
[56] | 2293 | |
---|
| 2294 | #if AMP_MRG |
---|
[1200] | 2295 | if ( !rpcTempCU->getMergeAMP() ) |
---|
| 2296 | { |
---|
[608] | 2297 | #if H_3D_ARP |
---|
[1196] | 2298 | if( nARPWMax ) |
---|
| 2299 | { |
---|
| 2300 | continue; |
---|
| 2301 | } |
---|
| 2302 | else |
---|
[443] | 2303 | #endif |
---|
[1200] | 2304 | return; |
---|
| 2305 | } |
---|
[2] | 2306 | #endif |
---|
[872] | 2307 | #if KWU_RC_MADPRED_E0227 |
---|
[1196] | 2308 | if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth ) |
---|
| 2309 | { |
---|
| 2310 | UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(), |
---|
| 2311 | m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(), |
---|
| 2312 | rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) ); |
---|
| 2313 | m_temporalSAD = (Int)SAD; |
---|
| 2314 | } |
---|
[56] | 2315 | #endif |
---|
[1200] | 2316 | |
---|
| 2317 | 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] | 2318 | #if H_3D_VSP // possible bug fix |
---|
[1196] | 2319 | if( rpcTempCU->getQtRootCbf(0)==0 ) |
---|
| 2320 | { |
---|
| 2321 | rpcTempCU->setTrIdxSubParts(0, 0, uhDepth); |
---|
| 2322 | } |
---|
[833] | 2323 | #endif |
---|
[1200] | 2324 | #if NH_3D_VSO // M4 |
---|
| 2325 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
| 2326 | { |
---|
| 2327 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 2328 | } |
---|
| 2329 | else |
---|
[5] | 2330 | #endif |
---|
[1200] | 2331 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 2332 | |
---|
| 2333 | #if DEBUG_STRING |
---|
| 2334 | DebugInterPredResiReco(sTest, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0))); |
---|
| 2335 | #endif |
---|
[655] | 2336 | #if H_3D_INTER_SDC |
---|
[1196] | 2337 | TComDataCU *rpcTempCUPre = rpcTempCU; |
---|
[608] | 2338 | #endif |
---|
[1200] | 2339 | |
---|
| 2340 | xCheckDQP( rpcTempCU ); |
---|
| 2341 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest)); |
---|
[655] | 2342 | #if H_3D_INTER_SDC |
---|
[1196] | 2343 | if( rpcTempCU->getSlice()->getInterSdcFlag() && ePartSize == SIZE_2Nx2N) |
---|
[1039] | 2344 | { |
---|
[1196] | 2345 | Double dOffsetCost[3] = {MAX_DOUBLE,MAX_DOUBLE,MAX_DOUBLE}; |
---|
| 2346 | for( Int uiOffest = 1 ; uiOffest <= 5 ; uiOffest++ ) |
---|
[1039] | 2347 | { |
---|
[1196] | 2348 | if( uiOffest > 3) |
---|
| 2349 | { |
---|
| 2350 | if ( dOffsetCost[0] < (0.9*dOffsetCost[1]) && dOffsetCost[0] < (0.9*dOffsetCost[2]) ) |
---|
| 2351 | { |
---|
| 2352 | continue; |
---|
| 2353 | } |
---|
| 2354 | if ( dOffsetCost[1] < dOffsetCost[0] && dOffsetCost[0] < dOffsetCost[2] && uiOffest == 5) |
---|
| 2355 | { |
---|
| 2356 | continue; |
---|
| 2357 | } |
---|
| 2358 | if ( dOffsetCost[0] < dOffsetCost[1] && dOffsetCost[2] < dOffsetCost[0] && uiOffest == 4) |
---|
| 2359 | { |
---|
| 2360 | continue; |
---|
| 2361 | } |
---|
| 2362 | } |
---|
[1084] | 2363 | |
---|
[1196] | 2364 | if( rpcTempCU != rpcTempCUPre ) |
---|
| 2365 | { |
---|
| 2366 | Int orgQP = rpcBestCU->getQP( 0 ); |
---|
| 2367 | rpcTempCU->initEstData( uhDepth, orgQP ,bTransquantBypassFlag ); |
---|
| 2368 | rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth ); |
---|
| 2369 | } |
---|
| 2370 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
| 2371 | #if H_3D |
---|
| 2372 | rpcTempCU->setDISFlagSubParts( false, 0, uhDepth ); |
---|
[1039] | 2373 | #endif |
---|
[1196] | 2374 | rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth ); |
---|
| 2375 | rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth ); |
---|
[1200] | 2376 | #if NH_3D_VSO // M3 |
---|
[1196] | 2377 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 2378 | { |
---|
[1200] | 2379 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y ); |
---|
| 2380 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( COMPONENT_Y ); |
---|
| 2381 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getAddr ( COMPONENT_Y ); |
---|
| 2382 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride( COMPONENT_Y ); |
---|
[1196] | 2383 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
| 2384 | } |
---|
[833] | 2385 | #endif |
---|
| 2386 | |
---|
[1196] | 2387 | Int iSdcOffset = 0; |
---|
| 2388 | if(uiOffest % 2 == 0) |
---|
| 2389 | { |
---|
| 2390 | iSdcOffset = uiOffest >> 1; |
---|
| 2391 | } |
---|
| 2392 | else |
---|
| 2393 | { |
---|
| 2394 | iSdcOffset = -1 * (uiOffest >> 1); |
---|
| 2395 | } |
---|
| 2396 | m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU, |
---|
| 2397 | m_ppcOrigYuv[uhDepth], |
---|
| 2398 | ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth], |
---|
| 2399 | m_ppcResiYuvTemp[uhDepth], |
---|
| 2400 | m_ppcRecoYuvTemp[uhDepth], |
---|
| 2401 | iSdcOffset, |
---|
| 2402 | uhDepth ); |
---|
| 2403 | if (uiOffest <= 3 ) |
---|
| 2404 | { |
---|
| 2405 | dOffsetCost [uiOffest -1] = rpcTempCU->getTotalCost(); |
---|
| 2406 | } |
---|
[833] | 2407 | |
---|
[1196] | 2408 | xCheckDQP( rpcTempCU ); |
---|
| 2409 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
| 2410 | } |
---|
[2] | 2411 | |
---|
[1196] | 2412 | } |
---|
[443] | 2413 | #endif |
---|
[608] | 2414 | #if H_3D_ARP |
---|
[1196] | 2415 | } |
---|
[608] | 2416 | #endif |
---|
[655] | 2417 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 2418 | } |
---|
| 2419 | #endif |
---|
[2] | 2420 | } |
---|
| 2421 | |
---|
[833] | 2422 | #if H_3D_DBBP |
---|
| 2423 | Void TEncCu::xInvalidateOriginalSegments( TComYuv* pOrigYuv, TComYuv* pOrigYuvTemp, Bool* pMask, UInt uiValidSegment ) |
---|
| 2424 | { |
---|
| 2425 | UInt uiWidth = pOrigYuv->getWidth ( ); |
---|
| 2426 | UInt uiHeight = pOrigYuv->getHeight( ); |
---|
| 2427 | Pel* piSrc = pOrigYuv->getLumaAddr( ); |
---|
| 2428 | UInt uiSrcStride = pOrigYuv->getStride(); |
---|
| 2429 | Pel* piDst = pOrigYuvTemp->getLumaAddr( ); |
---|
| 2430 | UInt uiDstStride = pOrigYuvTemp->getStride(); |
---|
| 2431 | |
---|
| 2432 | UInt uiMaskStride= MAX_CU_SIZE; |
---|
| 2433 | |
---|
| 2434 | AOF( uiWidth == uiHeight ); |
---|
| 2435 | |
---|
| 2436 | // backup pointer |
---|
| 2437 | Bool* pMaskStart = pMask; |
---|
| 2438 | |
---|
| 2439 | for (Int y=0; y<uiHeight; y++) |
---|
| 2440 | { |
---|
| 2441 | for (Int x=0; x<uiWidth; x++) |
---|
| 2442 | { |
---|
| 2443 | UChar ucSegment = (UChar)pMask[x]; |
---|
| 2444 | AOF( ucSegment < 2 ); |
---|
| 2445 | |
---|
| 2446 | piDst[x] = (ucSegment==uiValidSegment)?piSrc[x]:DBBP_INVALID_SHORT; |
---|
| 2447 | } |
---|
| 2448 | |
---|
| 2449 | piSrc += uiSrcStride; |
---|
| 2450 | piDst += uiDstStride; |
---|
| 2451 | pMask += uiMaskStride; |
---|
| 2452 | } |
---|
| 2453 | |
---|
| 2454 | // now invalidate chroma |
---|
| 2455 | Pel* piSrcU = pOrigYuv->getCbAddr(); |
---|
| 2456 | Pel* piSrcV = pOrigYuv->getCrAddr(); |
---|
| 2457 | UInt uiSrcStrideC = pOrigYuv->getCStride(); |
---|
| 2458 | Pel* piDstU = pOrigYuvTemp->getCbAddr( ); |
---|
| 2459 | Pel* piDstV = pOrigYuvTemp->getCrAddr( ); |
---|
| 2460 | UInt uiDstStrideC = pOrigYuvTemp->getCStride(); |
---|
| 2461 | pMask = pMaskStart; |
---|
| 2462 | |
---|
| 2463 | for (Int y=0; y<uiHeight/2; y++) |
---|
| 2464 | { |
---|
| 2465 | for (Int x=0; x<uiWidth/2; x++) |
---|
| 2466 | { |
---|
| 2467 | UChar ucSegment = (UChar)pMask[x*2]; |
---|
| 2468 | AOF( ucSegment < 2 ); |
---|
| 2469 | |
---|
| 2470 | piDstU[x] = (ucSegment==uiValidSegment)?piSrcU[x]:DBBP_INVALID_SHORT; |
---|
| 2471 | piDstV[x] = (ucSegment==uiValidSegment)?piSrcV[x]:DBBP_INVALID_SHORT; |
---|
| 2472 | } |
---|
| 2473 | |
---|
| 2474 | piSrcU += uiSrcStrideC; |
---|
| 2475 | piSrcV += uiSrcStrideC; |
---|
| 2476 | piDstU += uiDstStrideC; |
---|
| 2477 | piDstV += uiDstStrideC; |
---|
| 2478 | pMask += 2*uiMaskStride; |
---|
| 2479 | } |
---|
| 2480 | } |
---|
[1179] | 2481 | |
---|
| 2482 | Void TEncCu::xCheckRDCostDIS( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize ) |
---|
| 2483 | { |
---|
| 2484 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
| 2485 | if( !rpcBestCU->getSlice()->getIsDepth() || (eSize != SIZE_2Nx2N)) |
---|
| 2486 | { |
---|
| 2487 | return; |
---|
| 2488 | } |
---|
| 2489 | |
---|
[1200] | 2490 | #if NH_3D_VSO // M5 |
---|
[1179] | 2491 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 2492 | { |
---|
[1200] | 2493 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth ( COMPONENT_Y ); |
---|
| 2494 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight ( COMPONENT_Y ); |
---|
| 2495 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getAddr ( COMPONENT_Y ); |
---|
| 2496 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride ( COMPONENT_Y ); |
---|
[1179] | 2497 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
| 2498 | } |
---|
| 2499 | #endif |
---|
| 2500 | |
---|
| 2501 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
| 2502 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
| 2503 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
| 2504 | rpcTempCU->setCUTransquantBypassSubParts( rpcTempCU->getCUTransquantBypass(0), 0, uiDepth ); |
---|
| 2505 | |
---|
| 2506 | rpcTempCU->setTrIdxSubParts(0, 0, uiDepth); |
---|
| 2507 | rpcTempCU->setCbfSubParts(0, 1, 1, 0, uiDepth); |
---|
| 2508 | rpcTempCU->setDISFlagSubParts(true, 0, uiDepth); |
---|
| 2509 | rpcTempCU->setLumaIntraDirSubParts (DC_IDX, 0, uiDepth); |
---|
| 2510 | #if H_3D_DIM_SDC |
---|
| 2511 | rpcTempCU->setSDCFlagSubParts( false, 0, uiDepth); |
---|
| 2512 | #endif |
---|
| 2513 | |
---|
| 2514 | UInt uiPreCalcDistC; |
---|
| 2515 | m_pcPredSearch ->estIntraPredDIS ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, false ); |
---|
| 2516 | |
---|
| 2517 | #if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC |
---|
| 2518 | Int oldTraceCopyBack = g_traceCopyBack; |
---|
| 2519 | g_traceCopyBack = false; |
---|
| 2520 | #endif |
---|
| 2521 | m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() ); |
---|
| 2522 | #if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC |
---|
| 2523 | g_traceCopyBack = oldTraceCopyBack; |
---|
| 2524 | #endif |
---|
| 2525 | |
---|
| 2526 | |
---|
| 2527 | m_pcEntropyCoder->resetBits(); |
---|
| 2528 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 2529 | { |
---|
| 2530 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
| 2531 | } |
---|
| 2532 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
| 2533 | m_pcEntropyCoder->encodeDIS( rpcTempCU, 0, true ); |
---|
| 2534 | |
---|
| 2535 | |
---|
| 2536 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
| 2537 | |
---|
| 2538 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
| 2539 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 2540 | |
---|
| 2541 | |
---|
[1200] | 2542 | #if NH_3D_VSO // M6 |
---|
| 2543 | if( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
| 2544 | { |
---|
[1179] | 2545 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[1200] | 2546 | } |
---|
[1179] | 2547 | else |
---|
| 2548 | #endif |
---|
| 2549 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 2550 | |
---|
| 2551 | |
---|
| 2552 | xCheckDQP( rpcTempCU ); |
---|
| 2553 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth); |
---|
| 2554 | } |
---|
[833] | 2555 | |
---|
| 2556 | Void TEncCu::xCheckRDCostInterDBBP( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool bUseMRG ) |
---|
| 2557 | { |
---|
| 2558 | AOF( !rpcTempCU->getSlice()->getIsDepth() ); |
---|
| 2559 | |
---|
| 2560 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
| 2561 | |
---|
[1200] | 2562 | #if NH_3D_VSO |
---|
[833] | 2563 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 2564 | { |
---|
[1200] | 2565 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y ); |
---|
| 2566 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( COMPONENT_Y ); |
---|
| 2567 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getAddr ( COMPONENT_Y ); |
---|
| 2568 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride( COMPONENT_Y ); |
---|
[833] | 2569 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
| 2570 | } |
---|
| 2571 | #endif |
---|
| 2572 | |
---|
| 2573 | UInt uiWidth = rpcTempCU->getWidth(0); |
---|
| 2574 | UInt uiHeight = rpcTempCU->getHeight(0); |
---|
| 2575 | AOF( uiWidth == uiHeight ); |
---|
| 2576 | |
---|
[1084] | 2577 | #if H_3D_DBBP |
---|
| 2578 | // Is this correct here, was under the macro SEC_DBBP_DISALLOW_8x8_I0078, however the function is related to Single Depth Mode |
---|
[1039] | 2579 | if(uiWidth <= 8) |
---|
| 2580 | { |
---|
| 2581 | return; |
---|
| 2582 | } |
---|
| 2583 | #endif |
---|
| 2584 | |
---|
[833] | 2585 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
| 2586 | |
---|
| 2587 | // fetch virtual depth block |
---|
| 2588 | UInt uiDepthStride = 0; |
---|
[1084] | 2589 | #if H_3D_FCO |
---|
[1066] | 2590 | Pel* pDepthPels = rpcTempCU->getVirtualDepthBlock(rpcTempCU->getZorderIdxInCU(), uiWidth, uiHeight, uiDepthStride); |
---|
| 2591 | #else |
---|
[833] | 2592 | Pel* pDepthPels = rpcTempCU->getVirtualDepthBlock(0, uiWidth, uiHeight, uiDepthStride); |
---|
[1066] | 2593 | #endif |
---|
[833] | 2594 | AOF( pDepthPels != NULL ); |
---|
| 2595 | AOF( uiDepthStride != 0 ); |
---|
| 2596 | |
---|
[1179] | 2597 | PartSize eVirtualPartSize = m_pcPredSearch->getPartitionSizeFromDepth(pDepthPels, uiDepthStride, uiWidth, rpcTempCU); |
---|
| 2598 | |
---|
[833] | 2599 | // derive partitioning from depth |
---|
[1179] | 2600 | Bool pMask[MAX_CU_SIZE*MAX_CU_SIZE]; |
---|
| 2601 | Bool bValidMask = m_pcPredSearch->getSegmentMaskFromDepth(pDepthPels, uiDepthStride, uiWidth, uiHeight, pMask, rpcTempCU); |
---|
[833] | 2602 | |
---|
| 2603 | if( !bValidMask ) |
---|
| 2604 | { |
---|
| 2605 | return; |
---|
| 2606 | } |
---|
| 2607 | |
---|
| 2608 | // find optimal motion/disparity vector for each segment |
---|
| 2609 | DisInfo originalDvInfo = rpcTempCU->getDvInfo(0); |
---|
[1196] | 2610 | DbbpTmpData* pDBBPTmpData = rpcTempCU->getDBBPTmpData(); |
---|
[833] | 2611 | TComYuv* apPredYuv[2] = { m_ppcRecoYuvTemp[uhDepth], m_ppcPredYuvTemp[uhDepth] }; |
---|
| 2612 | |
---|
| 2613 | // find optimal motion vector fields for both segments (as 2Nx2N) |
---|
| 2614 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
| 2615 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
| 2616 | rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); |
---|
| 2617 | for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ ) |
---|
| 2618 | { |
---|
| 2619 | rpcTempCU->setDBBPFlagSubParts(true, 0, 0, uhDepth); |
---|
| 2620 | rpcTempCU->setDvInfoSubParts(originalDvInfo, 0, uhDepth); |
---|
| 2621 | |
---|
| 2622 | // invalidate all other segments in original YUV |
---|
| 2623 | xInvalidateOriginalSegments(m_ppcOrigYuv[uhDepth], m_ppcOrigYuvDBBP[uhDepth], pMask, uiSegment); |
---|
| 2624 | |
---|
| 2625 | // do motion estimation for this segment |
---|
| 2626 | m_pcRdCost->setUseMask(true); |
---|
| 2627 | rpcTempCU->getDBBPTmpData()->eVirtualPartSize = eVirtualPartSize; |
---|
| 2628 | rpcTempCU->getDBBPTmpData()->uiVirtualPartIndex = uiSegment; |
---|
| 2629 | m_pcPredSearch->predInterSearch( rpcTempCU, m_ppcOrigYuvDBBP[uhDepth], apPredYuv[uiSegment], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], false, false, bUseMRG ); |
---|
| 2630 | m_pcRdCost->setUseMask(false); |
---|
| 2631 | |
---|
| 2632 | // extract motion parameters of full block for this segment |
---|
| 2633 | pDBBPTmpData->auhInterDir[uiSegment] = rpcTempCU->getInterDir(0); |
---|
| 2634 | |
---|
| 2635 | pDBBPTmpData->abMergeFlag[uiSegment] = rpcTempCU->getMergeFlag(0); |
---|
| 2636 | pDBBPTmpData->auhMergeIndex[uiSegment] = rpcTempCU->getMergeIndex(0); |
---|
| 2637 | |
---|
[950] | 2638 | AOF( rpcTempCU->getSPIVMPFlag(0) == false ); |
---|
| 2639 | AOF( rpcTempCU->getVSPFlag(0) == 0 ); |
---|
[833] | 2640 | |
---|
| 2641 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
| 2642 | { |
---|
| 2643 | RefPicList eRefList = (RefPicList)uiRefListIdx; |
---|
| 2644 | |
---|
| 2645 | pDBBPTmpData->acMvd[uiSegment][eRefList] = rpcTempCU->getCUMvField(eRefList)->getMvd(0); |
---|
| 2646 | pDBBPTmpData->aiMvpNum[uiSegment][eRefList] = rpcTempCU->getMVPNum(eRefList, 0); |
---|
| 2647 | pDBBPTmpData->aiMvpIdx[uiSegment][eRefList] = rpcTempCU->getMVPIdx(eRefList, 0); |
---|
| 2648 | |
---|
| 2649 | rpcTempCU->getMvField(rpcTempCU, 0, eRefList, pDBBPTmpData->acMvField[uiSegment][eRefList]); |
---|
| 2650 | } |
---|
| 2651 | } |
---|
| 2652 | |
---|
| 2653 | // store final motion/disparity information in each PU using derived partitioning |
---|
| 2654 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
| 2655 | rpcTempCU->setPartSizeSubParts ( eVirtualPartSize, 0, uhDepth ); |
---|
| 2656 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
| 2657 | |
---|
| 2658 | UInt uiPUOffset = ( g_auiPUOffset[UInt( eVirtualPartSize )] << ( ( rpcTempCU->getSlice()->getSPS()->getMaxCUDepth() - uhDepth ) << 1 ) ) >> 4; |
---|
| 2659 | for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ ) |
---|
| 2660 | { |
---|
| 2661 | UInt uiPartAddr = uiSegment*uiPUOffset; |
---|
| 2662 | |
---|
| 2663 | rpcTempCU->setDBBPFlagSubParts(true, uiPartAddr, uiSegment, uhDepth); |
---|
| 2664 | |
---|
| 2665 | // now set stored information from 2Nx2N motion search to each partition |
---|
| 2666 | rpcTempCU->setInterDirSubParts(pDBBPTmpData->auhInterDir[uiSegment], uiPartAddr, uiSegment, uhDepth); // interprets depth relative to LCU level |
---|
| 2667 | |
---|
| 2668 | rpcTempCU->setMergeFlagSubParts(pDBBPTmpData->abMergeFlag[uiSegment], uiPartAddr, uiSegment, uhDepth); |
---|
| 2669 | rpcTempCU->setMergeIndexSubParts(pDBBPTmpData->auhMergeIndex[uiSegment], uiPartAddr, uiSegment, uhDepth); |
---|
[976] | 2670 | |
---|
[833] | 2671 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
| 2672 | { |
---|
| 2673 | RefPicList eRefList = (RefPicList)uiRefListIdx; |
---|
| 2674 | |
---|
| 2675 | rpcTempCU->getCUMvField( eRefList )->setAllMvd(pDBBPTmpData->acMvd[uiSegment][eRefList], eVirtualPartSize, uiPartAddr, 0, uiSegment); |
---|
| 2676 | rpcTempCU->setMVPNum(eRefList, uiPartAddr, pDBBPTmpData->aiMvpNum[uiSegment][eRefList]); |
---|
| 2677 | rpcTempCU->setMVPIdx(eRefList, uiPartAddr, pDBBPTmpData->aiMvpIdx[uiSegment][eRefList]); |
---|
| 2678 | |
---|
| 2679 | rpcTempCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], eVirtualPartSize, uiPartAddr, 0, uiSegment ); // interprets depth relative to rpcTempCU level |
---|
| 2680 | } |
---|
| 2681 | } |
---|
| 2682 | |
---|
| 2683 | // reconstruct final prediction signal by combining both segments |
---|
[1039] | 2684 | m_pcPredSearch->combineSegmentsWithMask(apPredYuv, m_ppcPredYuvTemp[uhDepth], pMask, uiWidth, uiHeight, 0, eVirtualPartSize); |
---|
[833] | 2685 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); |
---|
| 2686 | |
---|
| 2687 | xCheckDQP( rpcTempCU ); |
---|
| 2688 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
| 2689 | } |
---|
| 2690 | #endif |
---|
[1196] | 2691 | |
---|
[1084] | 2692 | #if H_3D_DIM |
---|
[1039] | 2693 | Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize, Bool bOnlyIVP ) |
---|
| 2694 | #else |
---|
[1200] | 2695 | Void TEncCu::xCheckRDCostIntra( TComDataCU *&rpcBestCU, |
---|
| 2696 | TComDataCU *&rpcTempCU, |
---|
| 2697 | Double &cost, |
---|
| 2698 | PartSize eSize |
---|
| 2699 | DEBUG_STRING_FN_DECLARE(sDebug) ) |
---|
[1039] | 2700 | #endif |
---|
[2] | 2701 | { |
---|
[1200] | 2702 | DEBUG_STRING_NEW(sTest) |
---|
| 2703 | |
---|
| 2704 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
| 2705 | #if NH_3D_VSO // M5 |
---|
[2] | 2706 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 2707 | { |
---|
[1200] | 2708 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth ( COMPONENT_Y ); |
---|
| 2709 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight ( COMPONENT_Y ); |
---|
| 2710 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getAddr ( COMPONENT_Y ); |
---|
| 2711 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride ( COMPONENT_Y ); |
---|
[81] | 2712 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
[2] | 2713 | } |
---|
[5] | 2714 | #endif |
---|
[2] | 2715 | |
---|
[608] | 2716 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
[1196] | 2717 | #if H_3D |
---|
[1179] | 2718 | rpcTempCU->setDISFlagSubParts( false, 0, uiDepth ); |
---|
[1039] | 2719 | #endif |
---|
[1200] | 2720 | |
---|
| 2721 | |
---|
[2] | 2722 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
| 2723 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
[1200] | 2724 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uiDepth ); |
---|
| 2725 | |
---|
| 2726 | Pel resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE]; |
---|
| 2727 | |
---|
| 2728 | m_pcPredSearch->estIntraPredLumaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) ); |
---|
| 2729 | |
---|
| 2730 | m_ppcRecoYuvTemp[uiDepth]->copyToPicComponent(COMPONENT_Y, rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getCtuRsAddr(), rpcTempCU->getZorderIdxInCtu() ); |
---|
| 2731 | |
---|
| 2732 | if (rpcBestCU->getPic()->getChromaFormat()!=CHROMA_400) |
---|
[2] | 2733 | { |
---|
[1084] | 2734 | #if H_3D_DIM |
---|
[1200] | 2735 | m_pcPredSearch->estIntraPredQT ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma, bOnlyIVP ); |
---|
[1039] | 2736 | #else |
---|
[1200] | 2737 | m_pcPredSearch->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) ); |
---|
[1039] | 2738 | #endif |
---|
[1200] | 2739 | } |
---|
[608] | 2740 | #if H_3D_DIM_SDC |
---|
[189] | 2741 | if( !rpcTempCU->getSDCFlag( 0 ) ) |
---|
| 2742 | #endif |
---|
[1200] | 2743 | |
---|
[2] | 2744 | m_pcEntropyCoder->resetBits(); |
---|
[1200] | 2745 | |
---|
[608] | 2746 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 2747 | { |
---|
| 2748 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
| 2749 | } |
---|
[1196] | 2750 | #if H_3D |
---|
[1179] | 2751 | m_pcEntropyCoder->encodeDIS( rpcTempCU, 0, true ); |
---|
| 2752 | if(!rpcTempCU->getDISFlag(0)) |
---|
| 2753 | { |
---|
[1039] | 2754 | #endif |
---|
[1200] | 2755 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
| 2756 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
| 2757 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
| 2758 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0 ); |
---|
| 2759 | m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true ); |
---|
[884] | 2760 | #if H_3D_DIM_SDC |
---|
[1196] | 2761 | m_pcEntropyCoder->encodeSDCFlag( rpcTempCU, 0, true ); |
---|
[833] | 2762 | #endif |
---|
[2] | 2763 | |
---|
[1200] | 2764 | // Encode Coefficients |
---|
| 2765 | Bool bCodeDQP = getdQPFlag(); |
---|
| 2766 | Bool codeChromaQpAdjFlag = getCodeChromaQpAdjFlag(); |
---|
| 2767 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, bCodeDQP, codeChromaQpAdjFlag ); |
---|
| 2768 | setCodeChromaQpAdjFlag( codeChromaQpAdjFlag ); |
---|
| 2769 | setdQPFlag( bCodeDQP ); |
---|
[1196] | 2770 | #if H_3D |
---|
[1179] | 2771 | } |
---|
| 2772 | #endif |
---|
[872] | 2773 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
[1200] | 2774 | |
---|
[2] | 2775 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
[1196] | 2776 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
[1200] | 2777 | #if NH_3D_VSO // M6 |
---|
[608] | 2778 | if( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
[1200] | 2779 | { |
---|
[608] | 2780 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[1200] | 2781 | } |
---|
[2] | 2782 | else |
---|
[5] | 2783 | #endif |
---|
[1200] | 2784 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 2785 | |
---|
[56] | 2786 | xCheckDQP( rpcTempCU ); |
---|
[1200] | 2787 | |
---|
| 2788 | cost = rpcTempCU->getTotalCost(); |
---|
| 2789 | |
---|
| 2790 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest)); |
---|
[56] | 2791 | } |
---|
[2] | 2792 | |
---|
[1200] | 2793 | |
---|
| 2794 | /** Check R-D costs for a CU with PCM mode. |
---|
[56] | 2795 | * \param rpcBestCU pointer to best mode CU data structure |
---|
| 2796 | * \param rpcTempCU pointer to testing mode CU data structure |
---|
| 2797 | * \returns Void |
---|
[1200] | 2798 | * |
---|
[56] | 2799 | * \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. |
---|
| 2800 | */ |
---|
| 2801 | Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
| 2802 | { |
---|
| 2803 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
| 2804 | |
---|
[1200] | 2805 | #if NH_3D_VSO // VERY NEW |
---|
| 2806 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 2807 | { |
---|
| 2808 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth ( COMPONENT_Y ); |
---|
| 2809 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight ( COMPONENT_Y ); |
---|
| 2810 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getAddr ( COMPONENT_Y ); |
---|
| 2811 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride ( COMPONENT_Y ); |
---|
| 2812 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
| 2813 | } |
---|
| 2814 | #endif |
---|
| 2815 | |
---|
[608] | 2816 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
[1196] | 2817 | #if H_3D |
---|
[1179] | 2818 | rpcTempCU->setDISFlagSubParts( false, 0, uiDepth ); |
---|
[1039] | 2819 | #endif |
---|
[56] | 2820 | rpcTempCU->setIPCMFlag(0, true); |
---|
| 2821 | rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); |
---|
| 2822 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
| 2823 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
[608] | 2824 | rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth ); |
---|
[1200] | 2825 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uiDepth ); |
---|
[56] | 2826 | |
---|
| 2827 | m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); |
---|
| 2828 | |
---|
[872] | 2829 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
[56] | 2830 | |
---|
| 2831 | m_pcEntropyCoder->resetBits(); |
---|
[1200] | 2832 | |
---|
[608] | 2833 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 2834 | { |
---|
| 2835 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
| 2836 | } |
---|
[1200] | 2837 | |
---|
[56] | 2838 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
[1196] | 2839 | #if H_3D |
---|
[1179] | 2840 | m_pcEntropyCoder->encodeDIS( rpcTempCU, 0, true ); |
---|
[1039] | 2841 | #endif |
---|
[56] | 2842 | m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); |
---|
| 2843 | m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); |
---|
| 2844 | m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); |
---|
[1179] | 2845 | #if H_3D_DIM_SDC |
---|
| 2846 | m_pcEntropyCoder->encodeSDCFlag( rpcTempCU, 0, true ); |
---|
| 2847 | #endif |
---|
[872] | 2848 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
[56] | 2849 | |
---|
| 2850 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
[1200] | 2851 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 2852 | #if NH_3D_VSO // M44 |
---|
[56] | 2853 | if ( m_pcRdCost->getUseVSO() ) |
---|
[1200] | 2854 | { |
---|
[56] | 2855 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[1200] | 2856 | } |
---|
[56] | 2857 | else |
---|
| 2858 | #endif |
---|
[1200] | 2859 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[56] | 2860 | |
---|
| 2861 | xCheckDQP( rpcTempCU ); |
---|
[1200] | 2862 | DEBUG_STRING_NEW(a) |
---|
| 2863 | DEBUG_STRING_NEW(b) |
---|
| 2864 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(a) DEBUG_STRING_PASS_INTO(b)); |
---|
[2] | 2865 | } |
---|
| 2866 | |
---|
[56] | 2867 | /** check whether current try is the best with identifying the depth of current try |
---|
| 2868 | * \param rpcBestCU |
---|
| 2869 | * \param rpcTempCU |
---|
[1200] | 2870 | * \param uiDepth |
---|
[56] | 2871 | */ |
---|
[1200] | 2872 | 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] | 2873 | { |
---|
[56] | 2874 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
| 2875 | { |
---|
| 2876 | TComYuv* pcYuv; |
---|
| 2877 | // Change Information data |
---|
| 2878 | TComDataCU* pcCU = rpcBestCU; |
---|
| 2879 | rpcBestCU = rpcTempCU; |
---|
| 2880 | rpcTempCU = pcCU; |
---|
[2] | 2881 | |
---|
[56] | 2882 | // Change Prediction data |
---|
| 2883 | pcYuv = m_ppcPredYuvBest[uiDepth]; |
---|
| 2884 | m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; |
---|
| 2885 | m_ppcPredYuvTemp[uiDepth] = pcYuv; |
---|
[2] | 2886 | |
---|
[56] | 2887 | // Change Reconstruction data |
---|
| 2888 | pcYuv = m_ppcRecoYuvBest[uiDepth]; |
---|
| 2889 | m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; |
---|
| 2890 | m_ppcRecoYuvTemp[uiDepth] = pcYuv; |
---|
[2] | 2891 | |
---|
[56] | 2892 | pcYuv = NULL; |
---|
| 2893 | pcCU = NULL; |
---|
[2] | 2894 | |
---|
[872] | 2895 | // store temp best CI for next CU coding |
---|
[1200] | 2896 | m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
| 2897 | |
---|
| 2898 | |
---|
| 2899 | #if DEBUG_STRING |
---|
| 2900 | DEBUG_STRING_SWAP(sParent, sTest) |
---|
| 2901 | const PredMode predMode=rpcBestCU->getPredictionMode(0); |
---|
| 2902 | if ((DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode)) && bAddSizeInfo) |
---|
| 2903 | { |
---|
| 2904 | std::stringstream ss(stringstream::out); |
---|
| 2905 | ss <<"###: " << (predMode==MODE_INTRA?"Intra ":"Inter ") << partSizeToString[rpcBestCU->getPartitionSize(0)] << " CU at " << rpcBestCU->getCUPelX() << ", " << rpcBestCU->getCUPelY() << " width=" << UInt(rpcBestCU->getWidth(0)) << std::endl; |
---|
| 2906 | sParent+=ss.str(); |
---|
| 2907 | } |
---|
| 2908 | #endif |
---|
[56] | 2909 | } |
---|
| 2910 | } |
---|
| 2911 | |
---|
| 2912 | Void TEncCu::xCheckDQP( TComDataCU* pcCU ) |
---|
| 2913 | { |
---|
| 2914 | UInt uiDepth = pcCU->getDepth( 0 ); |
---|
| 2915 | |
---|
[1200] | 2916 | const TComPPS &pps = *(pcCU->getSlice()->getPPS()); |
---|
| 2917 | if ( pps.getUseDQP() && uiDepth <= pps.getMaxCuDQPDepth() ) |
---|
[2] | 2918 | { |
---|
[1200] | 2919 | if ( pcCU->getQtRootCbf( 0) ) |
---|
[56] | 2920 | { |
---|
| 2921 | m_pcEntropyCoder->resetBits(); |
---|
| 2922 | m_pcEntropyCoder->encodeQP( pcCU, 0, false ); |
---|
| 2923 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
[1200] | 2924 | pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 2925 | #if NH_3D_VSO // M45 |
---|
[608] | 2926 | if ( m_pcRdCost->getUseVSO() ) |
---|
[1200] | 2927 | { |
---|
[608] | 2928 | pcCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
[1200] | 2929 | } |
---|
[56] | 2930 | else |
---|
| 2931 | #endif |
---|
[1200] | 2932 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
[2] | 2933 | } |
---|
[56] | 2934 | else |
---|
[2] | 2935 | { |
---|
[56] | 2936 | pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
[2] | 2937 | } |
---|
[56] | 2938 | } |
---|
| 2939 | } |
---|
| 2940 | |
---|
[2] | 2941 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
| 2942 | { |
---|
| 2943 | pDst->iN = pSrc->iN; |
---|
| 2944 | for (Int i = 0; i < pSrc->iN; i++) |
---|
| 2945 | { |
---|
| 2946 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
| 2947 | } |
---|
| 2948 | } |
---|
[1200] | 2949 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth ) |
---|
[56] | 2950 | { |
---|
[1200] | 2951 | UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; |
---|
| 2952 | UInt uiSrcBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiSrcDepth); |
---|
| 2953 | UInt uiBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiDepth); |
---|
| 2954 | UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
| 2955 | UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
| 2956 | UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; |
---|
| 2957 | m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
[2] | 2958 | |
---|
[1200] | 2959 | m_ppcPredYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvPred (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
[2] | 2960 | } |
---|
| 2961 | |
---|
| 2962 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
| 2963 | { |
---|
| 2964 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
| 2965 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
[1200] | 2966 | m_ppcPredYuvBest[uiNextDepth]->copyToPartYuv( m_ppcPredYuvBest[uiCurrDepth], uiPartUnitIdx); |
---|
[2] | 2967 | } |
---|
| 2968 | |
---|
[1200] | 2969 | /** Function for filling the PCM buffer of a CU using its original sample array |
---|
| 2970 | * \param pCU pointer to current CU |
---|
| 2971 | * \param pOrgYuv pointer to original sample array |
---|
[56] | 2972 | */ |
---|
[1200] | 2973 | Void TEncCu::xFillPCMBuffer ( TComDataCU* pCU, TComYuv* pOrgYuv ) |
---|
[56] | 2974 | { |
---|
[1200] | 2975 | const ChromaFormat format = pCU->getPic()->getChromaFormat(); |
---|
| 2976 | const UInt numberValidComponents = getNumberValidComponents(format); |
---|
| 2977 | for (UInt componentIndex = 0; componentIndex < numberValidComponents; componentIndex++) |
---|
[56] | 2978 | { |
---|
[1200] | 2979 | const ComponentID component = ComponentID(componentIndex); |
---|
[56] | 2980 | |
---|
[1200] | 2981 | const UInt width = pCU->getWidth(0) >> getComponentScaleX(component, format); |
---|
| 2982 | const UInt height = pCU->getHeight(0) >> getComponentScaleY(component, format); |
---|
[56] | 2983 | |
---|
[1200] | 2984 | Pel *source = pOrgYuv->getAddr(component, 0, width); |
---|
| 2985 | Pel *destination = pCU->getPCMSample(component); |
---|
[56] | 2986 | |
---|
[1200] | 2987 | const UInt sourceStride = pOrgYuv->getStride(component); |
---|
[56] | 2988 | |
---|
[1200] | 2989 | for (Int line = 0; line < height; line++) |
---|
[56] | 2990 | { |
---|
[1200] | 2991 | for (Int column = 0; column < width; column++) |
---|
| 2992 | { |
---|
| 2993 | destination[column] = source[column]; |
---|
| 2994 | } |
---|
| 2995 | |
---|
| 2996 | source += sourceStride; |
---|
| 2997 | destination += width; |
---|
[56] | 2998 | } |
---|
| 2999 | } |
---|
| 3000 | } |
---|
| 3001 | |
---|
| 3002 | #if ADAPTIVE_QP_SELECTION |
---|
| 3003 | /** Collect ARL statistics from one block |
---|
| 3004 | */ |
---|
[1200] | 3005 | Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, TCoeff* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) |
---|
[56] | 3006 | { |
---|
| 3007 | for( Int n = 0; n < NumCoeffInCU; n++ ) |
---|
| 3008 | { |
---|
[1200] | 3009 | TCoeff u = abs( rpcCoeff[ n ] ); |
---|
| 3010 | TCoeff absc = rpcArlCoeff[ n ]; |
---|
[56] | 3011 | |
---|
| 3012 | if( u != 0 ) |
---|
| 3013 | { |
---|
| 3014 | if( u < LEVEL_RANGE ) |
---|
| 3015 | { |
---|
| 3016 | cSum[ u ] += ( Double )absc; |
---|
| 3017 | numSamples[ u ]++; |
---|
| 3018 | } |
---|
[1200] | 3019 | else |
---|
[56] | 3020 | { |
---|
| 3021 | cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); |
---|
| 3022 | numSamples[ LEVEL_RANGE ]++; |
---|
| 3023 | } |
---|
| 3024 | } |
---|
| 3025 | } |
---|
| 3026 | |
---|
| 3027 | return 0; |
---|
| 3028 | } |
---|
| 3029 | |
---|
[1200] | 3030 | //! Collect ARL statistics from one CTU |
---|
| 3031 | Void TEncCu::xCtuCollectARLStats(TComDataCU* pCtu ) |
---|
[56] | 3032 | { |
---|
[1200] | 3033 | Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to data type and quantization output |
---|
| 3034 | UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to data type and quantization output |
---|
[56] | 3035 | |
---|
[1200] | 3036 | TCoeff* pCoeffY = pCtu->getCoeff(COMPONENT_Y); |
---|
| 3037 | TCoeff* pArlCoeffY = pCtu->getArlCoeff(COMPONENT_Y); |
---|
| 3038 | const TComSPS &sps = *(pCtu->getSlice()->getSPS()); |
---|
[56] | 3039 | |
---|
[1200] | 3040 | 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. |
---|
| 3041 | const UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; // NOTE: ed - what is this? |
---|
[56] | 3042 | |
---|
| 3043 | memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); |
---|
| 3044 | memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); |
---|
| 3045 | |
---|
| 3046 | // Collect stats to cSum[][] and numSamples[][] |
---|
[1200] | 3047 | for(Int i = 0; i < pCtu->getTotalNumPart(); i ++ ) |
---|
[56] | 3048 | { |
---|
[1200] | 3049 | UInt uiTrIdx = pCtu->getTransformIdx(i); |
---|
[56] | 3050 | |
---|
[1200] | 3051 | if(pCtu->isInter(i) && pCtu->getCbf( i, COMPONENT_Y, uiTrIdx ) ) |
---|
[56] | 3052 | { |
---|
| 3053 | xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); |
---|
| 3054 | }//Note that only InterY is processed. QP rounding is based on InterY data only. |
---|
[1200] | 3055 | |
---|
[56] | 3056 | pCoeffY += uiMinNumCoeffInCU; |
---|
| 3057 | pArlCoeffY += uiMinNumCoeffInCU; |
---|
| 3058 | } |
---|
| 3059 | |
---|
| 3060 | for(Int u=1; u<LEVEL_RANGE;u++) |
---|
| 3061 | { |
---|
| 3062 | m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; |
---|
| 3063 | m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; |
---|
| 3064 | } |
---|
| 3065 | m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; |
---|
| 3066 | m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; |
---|
| 3067 | } |
---|
| 3068 | #endif |
---|
[1200] | 3069 | |
---|
[56] | 3070 | //! \} |
---|