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