| 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 |
|---|
| 4 | * granted under this license. |
|---|
| 5 | * |
|---|
| 6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
|---|
| 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. |
|---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
|---|
| 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 | */ |
|---|
| 33 | |
|---|
| 34 | /** \file TEncEntropy.cpp |
|---|
| 35 | \brief entropy encoder class |
|---|
| 36 | */ |
|---|
| 37 | |
|---|
| 38 | #include "TEncEntropy.h" |
|---|
| 39 | #include "TLibCommon/TypeDef.h" |
|---|
| 40 | #include "TLibCommon/TComSampleAdaptiveOffset.h" |
|---|
| 41 | |
|---|
| 42 | //! \ingroup TLibEncoder |
|---|
| 43 | //! \{ |
|---|
| 44 | |
|---|
| 45 | Void TEncEntropy::setEntropyCoder ( TEncEntropyIf* e, TComSlice* pcSlice ) |
|---|
| 46 | { |
|---|
| 47 | m_pcEntropyCoderIf = e; |
|---|
| 48 | m_pcEntropyCoderIf->setSlice ( pcSlice ); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice ) |
|---|
| 52 | { |
|---|
| 53 | if (pcSlice->getSPS()->getUseSAO()) |
|---|
| 54 | { |
|---|
| 55 | SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam(); |
|---|
| 56 | pcSlice->setSaoEnabledFlag (saoParam->bSaoFlag[0]); |
|---|
| 57 | { |
|---|
| 58 | pcSlice->setSaoEnabledFlagChroma (saoParam->bSaoFlag[1]); |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | m_pcEntropyCoderIf->codeSliceHeader( pcSlice ); |
|---|
| 63 | return; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | Void TEncEntropy::encodeTilesWPPEntryPoint( TComSlice* pSlice ) |
|---|
| 67 | { |
|---|
| 68 | m_pcEntropyCoderIf->codeTilesWPPEntryPoint( pSlice ); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | Void TEncEntropy::encodeTerminatingBit ( UInt uiIsLast ) |
|---|
| 72 | { |
|---|
| 73 | m_pcEntropyCoderIf->codeTerminatingBit( uiIsLast ); |
|---|
| 74 | |
|---|
| 75 | return; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | Void TEncEntropy::encodeSliceFinish() |
|---|
| 79 | { |
|---|
| 80 | m_pcEntropyCoderIf->codeSliceFinish(); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | Void TEncEntropy::encodePPS( TComPPS* pcPPS ) |
|---|
| 84 | { |
|---|
| 85 | m_pcEntropyCoderIf->codePPS( pcPPS ); |
|---|
| 86 | return; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | #if H_3D |
|---|
| 90 | Void TEncEntropy::encodeSPS( TComSPS* pcSPS, Int viewIndex, Bool depthFlag ) |
|---|
| 91 | { |
|---|
| 92 | m_pcEntropyCoderIf->codeSPS( pcSPS, viewIndex, depthFlag ); |
|---|
| 93 | return; |
|---|
| 94 | } |
|---|
| 95 | #else |
|---|
| 96 | Void TEncEntropy::encodeSPS( TComSPS* pcSPS ) |
|---|
| 97 | { |
|---|
| 98 | m_pcEntropyCoderIf->codeSPS( pcSPS ); |
|---|
| 99 | return; |
|---|
| 100 | } |
|---|
| 101 | #endif |
|---|
| 102 | |
|---|
| 103 | Void TEncEntropy::encodeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
|---|
| 104 | { |
|---|
| 105 | if( bRD ) |
|---|
| 106 | { |
|---|
| 107 | uiAbsPartIdx = 0; |
|---|
| 108 | } |
|---|
| 109 | m_pcEntropyCoderIf->codeCUTransquantBypassFlag( pcCU, uiAbsPartIdx ); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | Void TEncEntropy::encodeVPS( TComVPS* pcVPS ) |
|---|
| 113 | { |
|---|
| 114 | m_pcEntropyCoderIf->codeVPS( pcVPS ); |
|---|
| 115 | return; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | Void TEncEntropy::encodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
|---|
| 119 | { |
|---|
| 120 | if ( pcCU->getSlice()->isIntra() ) |
|---|
| 121 | { |
|---|
| 122 | return; |
|---|
| 123 | } |
|---|
| 124 | if( bRD ) |
|---|
| 125 | { |
|---|
| 126 | uiAbsPartIdx = 0; |
|---|
| 127 | } |
|---|
| 128 | m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx ); |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | /** encode merge flag |
|---|
| 132 | * \param pcCU |
|---|
| 133 | * \param uiAbsPartIdx |
|---|
| 134 | * \returns Void |
|---|
| 135 | */ |
|---|
| 136 | Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
|---|
| 137 | { |
|---|
| 138 | // at least one merge candidate exists |
|---|
| 139 | m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx ); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | /** encode merge index |
|---|
| 143 | * \param pcCU |
|---|
| 144 | * \param uiAbsPartIdx |
|---|
| 145 | * \param uiPUIdx |
|---|
| 146 | * \param bRD |
|---|
| 147 | * \returns Void |
|---|
| 148 | */ |
|---|
| 149 | Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
|---|
| 150 | { |
|---|
| 151 | if( bRD ) |
|---|
| 152 | { |
|---|
| 153 | uiAbsPartIdx = 0; |
|---|
| 154 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
|---|
| 155 | } |
|---|
| 156 | m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx ); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | #if H_3D_IC |
|---|
| 160 | Void TEncEntropy::encodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
|---|
| 161 | { |
|---|
| 162 | if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() ) |
|---|
| 163 | { |
|---|
| 164 | return; |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | if( !pcCU->getSlice()->getApplyIC() ) |
|---|
| 168 | return; |
|---|
| 169 | |
|---|
| 170 | if( bRD ) |
|---|
| 171 | { |
|---|
| 172 | uiAbsPartIdx = 0; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | if( pcCU->isICFlagRequired( uiAbsPartIdx ) ) |
|---|
| 176 | m_pcEntropyCoderIf->codeICFlag( pcCU, uiAbsPartIdx ); |
|---|
| 177 | } |
|---|
| 178 | #endif |
|---|
| 179 | |
|---|
| 180 | #if H_3D_ARP |
|---|
| 181 | Void TEncEntropy::encodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
|---|
| 182 | { |
|---|
| 183 | if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) ) |
|---|
| 184 | { |
|---|
| 185 | return; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | if ( pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_2Nx2N ) |
|---|
| 189 | { |
|---|
| 190 | assert(pcCU->getARPW (uiAbsPartIdx) == 0); |
|---|
| 191 | } |
|---|
| 192 | else |
|---|
| 193 | { |
|---|
| 194 | m_pcEntropyCoderIf->codeARPW( pcCU, uiAbsPartIdx ); |
|---|
| 195 | } |
|---|
| 196 | } |
|---|
| 197 | #endif |
|---|
| 198 | |
|---|
| 199 | /** encode prediction mode |
|---|
| 200 | * \param pcCU |
|---|
| 201 | * \param uiAbsPartIdx |
|---|
| 202 | * \param bRD |
|---|
| 203 | * \returns Void |
|---|
| 204 | */ |
|---|
| 205 | Void TEncEntropy::encodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
|---|
| 206 | { |
|---|
| 207 | if( bRD ) |
|---|
| 208 | { |
|---|
| 209 | uiAbsPartIdx = 0; |
|---|
| 210 | } |
|---|
| 211 | if ( pcCU->getSlice()->isIntra() ) |
|---|
| 212 | { |
|---|
| 213 | return; |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx ); |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | // Split mode |
|---|
| 220 | Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
|---|
| 221 | { |
|---|
| 222 | if( bRD ) |
|---|
| 223 | { |
|---|
| 224 | uiAbsPartIdx = 0; |
|---|
| 225 | } |
|---|
| 226 | m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | /** encode partition size |
|---|
| 230 | * \param pcCU |
|---|
| 231 | * \param uiAbsPartIdx |
|---|
| 232 | * \param uiDepth |
|---|
| 233 | * \param bRD |
|---|
| 234 | * \returns Void |
|---|
| 235 | */ |
|---|
| 236 | Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
|---|
| 237 | { |
|---|
| 238 | if( bRD ) |
|---|
| 239 | { |
|---|
| 240 | uiAbsPartIdx = 0; |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | #if H_3D_DBBP |
|---|
| 244 | PartSize eVirtualPartSize = pcCU->getPartitionSize(uiAbsPartIdx); |
|---|
| 245 | if( pcCU->getDBBPFlag(uiAbsPartIdx) ) |
|---|
| 246 | { |
|---|
| 247 | // temporarily change partition size for DBBP blocks |
|---|
| 248 | pcCU->setPartSizeSubParts(RWTH_DBBP_PACK_MODE, uiAbsPartIdx, uiDepth); |
|---|
| 249 | } |
|---|
| 250 | #endif |
|---|
| 251 | |
|---|
| 252 | m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
|---|
| 253 | |
|---|
| 254 | #if H_3D_DBBP |
|---|
| 255 | if( pcCU->getSlice()->getVPS()->getUseDBBP(pcCU->getSlice()->getLayerIdInVps()) && pcCU->getPartitionSize(uiAbsPartIdx) == RWTH_DBBP_PACK_MODE ) |
|---|
| 256 | { |
|---|
| 257 | encodeDBBPFlag(pcCU, uiAbsPartIdx, bRD); |
|---|
| 258 | |
|---|
| 259 | if( pcCU->getDBBPFlag(uiAbsPartIdx) ) |
|---|
| 260 | { |
|---|
| 261 | AOF( pcCU->getPartitionSize(uiAbsPartIdx) == RWTH_DBBP_PACK_MODE ); |
|---|
| 262 | // restore virtual partition size for DBBP blocks |
|---|
| 263 | pcCU->setPartSizeSubParts(eVirtualPartSize, uiAbsPartIdx, uiDepth); |
|---|
| 264 | } |
|---|
| 265 | } |
|---|
| 266 | #endif |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | /** Encode I_PCM information. |
|---|
| 270 | * \param pcCU pointer to CU |
|---|
| 271 | * \param uiAbsPartIdx CU index |
|---|
| 272 | * \param bRD flag indicating estimation or encoding |
|---|
| 273 | * \returns Void |
|---|
| 274 | */ |
|---|
| 275 | Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
|---|
| 276 | { |
|---|
| 277 | if(!pcCU->getSlice()->getSPS()->getUsePCM() |
|---|
| 278 | || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize()) |
|---|
| 279 | || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize())) |
|---|
| 280 | { |
|---|
| 281 | return; |
|---|
| 282 | } |
|---|
| 283 | #if H_3D_DIM_SDC |
|---|
| 284 | if( pcCU->getSDCFlag(uiAbsPartIdx) ) |
|---|
| 285 | { |
|---|
| 286 | return; |
|---|
| 287 | } |
|---|
| 288 | #endif |
|---|
| 289 | |
|---|
| 290 | if( bRD ) |
|---|
| 291 | { |
|---|
| 292 | uiAbsPartIdx = 0; |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx ); |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP ) |
|---|
| 299 | { |
|---|
| 300 | const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth; |
|---|
| 301 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
|---|
| 302 | UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA , uiTrIdx ); |
|---|
| 303 | UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
|---|
| 304 | UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
|---|
| 305 | |
|---|
| 306 | if(uiTrIdx==0) |
|---|
| 307 | { |
|---|
| 308 | m_bakAbsPartIdxCU = uiAbsPartIdx; |
|---|
| 309 | } |
|---|
| 310 | if( uiLog2TrafoSize == 2 ) |
|---|
| 311 | { |
|---|
| 312 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
|---|
| 313 | if( ( uiAbsPartIdx % partNum ) == 0 ) |
|---|
| 314 | { |
|---|
| 315 | m_uiBakAbsPartIdx = uiAbsPartIdx; |
|---|
| 316 | m_uiBakChromaOffset = offsetChroma; |
|---|
| 317 | } |
|---|
| 318 | else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
|---|
| 319 | { |
|---|
| 320 | cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
|---|
| 321 | cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
|---|
| 322 | } |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
|---|
| 326 | { |
|---|
| 327 | assert( uiSubdiv ); |
|---|
| 328 | } |
|---|
| 329 | else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) && (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) ) |
|---|
| 330 | { |
|---|
| 331 | if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
|---|
| 332 | { |
|---|
| 333 | assert( uiSubdiv ); |
|---|
| 334 | } |
|---|
| 335 | else |
|---|
| 336 | { |
|---|
| 337 | assert(!uiSubdiv ); |
|---|
| 338 | } |
|---|
| 339 | } |
|---|
| 340 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
|---|
| 341 | { |
|---|
| 342 | assert( uiSubdiv ); |
|---|
| 343 | } |
|---|
| 344 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
|---|
| 345 | { |
|---|
| 346 | assert( !uiSubdiv ); |
|---|
| 347 | } |
|---|
| 348 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
|---|
| 349 | { |
|---|
| 350 | assert( !uiSubdiv ); |
|---|
| 351 | } |
|---|
| 352 | else |
|---|
| 353 | { |
|---|
| 354 | assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
|---|
| 355 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
|---|
| 359 | const Bool bFirstCbfOfCU = uiTrDepthCurr == 0; |
|---|
| 360 | if( bFirstCbfOfCU || uiLog2TrafoSize > 2 ) |
|---|
| 361 | { |
|---|
| 362 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ) |
|---|
| 363 | { |
|---|
| 364 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
|---|
| 365 | } |
|---|
| 366 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ) |
|---|
| 367 | { |
|---|
| 368 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
|---|
| 369 | } |
|---|
| 370 | } |
|---|
| 371 | else if( uiLog2TrafoSize == 2 ) |
|---|
| 372 | { |
|---|
| 373 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ); |
|---|
| 374 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ); |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | if( uiSubdiv ) |
|---|
| 378 | { |
|---|
| 379 | UInt size; |
|---|
| 380 | width >>= 1; |
|---|
| 381 | height >>= 1; |
|---|
| 382 | size = width*height; |
|---|
| 383 | uiTrIdx++; |
|---|
| 384 | ++uiDepth; |
|---|
| 385 | const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
|---|
| 386 | |
|---|
| 387 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
|---|
| 388 | |
|---|
| 389 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
|---|
| 390 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
|---|
| 391 | |
|---|
| 392 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
|---|
| 393 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
|---|
| 394 | |
|---|
| 395 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
|---|
| 396 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
|---|
| 397 | } |
|---|
| 398 | else |
|---|
| 399 | { |
|---|
| 400 | #if !H_MV_ENC_DEC_TRAC |
|---|
| 401 | { |
|---|
| 402 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
|---|
| 403 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
|---|
| 404 | DTRACE_CABAC_V( uiAbsPartIdx ); |
|---|
| 405 | DTRACE_CABAC_T( "\tdepth=" ); |
|---|
| 406 | DTRACE_CABAC_V( uiDepth ); |
|---|
| 407 | DTRACE_CABAC_T( "\ttrdepth=" ); |
|---|
| 408 | DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) ); |
|---|
| 409 | DTRACE_CABAC_T( "\n" ); |
|---|
| 410 | } |
|---|
| 411 | #endif |
|---|
| 412 | |
|---|
| 413 | if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
|---|
| 414 | { |
|---|
| 415 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) ); |
|---|
| 416 | // printf( "saved one bin! " ); |
|---|
| 417 | } |
|---|
| 418 | else |
|---|
| 419 | { |
|---|
| 420 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) ); |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | if ( cbfY || cbfU || cbfV ) |
|---|
| 425 | { |
|---|
| 426 | // dQP: only for LCU once |
|---|
| 427 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
|---|
| 428 | { |
|---|
| 429 | if ( bCodeDQP ) |
|---|
| 430 | { |
|---|
| 431 | encodeQP( pcCU, m_bakAbsPartIdxCU ); |
|---|
| 432 | bCodeDQP = false; |
|---|
| 433 | } |
|---|
| 434 | } |
|---|
| 435 | } |
|---|
| 436 | if( cbfY ) |
|---|
| 437 | { |
|---|
| 438 | Int trWidth = width; |
|---|
| 439 | Int trHeight = height; |
|---|
| 440 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
|---|
| 441 | } |
|---|
| 442 | if( uiLog2TrafoSize > 2 ) |
|---|
| 443 | { |
|---|
| 444 | Int trWidth = width >> 1; |
|---|
| 445 | Int trHeight = height >> 1; |
|---|
| 446 | if( cbfU ) |
|---|
| 447 | { |
|---|
| 448 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
|---|
| 449 | } |
|---|
| 450 | if( cbfV ) |
|---|
| 451 | { |
|---|
| 452 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
|---|
| 453 | } |
|---|
| 454 | } |
|---|
| 455 | else |
|---|
| 456 | { |
|---|
| 457 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
|---|
| 458 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
|---|
| 459 | { |
|---|
| 460 | Int trWidth = width; |
|---|
| 461 | Int trHeight = height; |
|---|
| 462 | if( cbfU ) |
|---|
| 463 | { |
|---|
| 464 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
|---|
| 465 | } |
|---|
| 466 | if( cbfV ) |
|---|
| 467 | { |
|---|
| 468 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
|---|
| 469 | } |
|---|
| 470 | } |
|---|
| 471 | } |
|---|
| 472 | } |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | // Intra direction for Luma |
|---|
| 476 | Void TEncEntropy::encodeIntraDirModeLuma ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU ) |
|---|
| 477 | { |
|---|
| 478 | m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU); |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | // Intra direction for Chroma |
|---|
| 482 | Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
|---|
| 483 | { |
|---|
| 484 | if( bRD ) |
|---|
| 485 | { |
|---|
| 486 | uiAbsPartIdx = 0; |
|---|
| 487 | } |
|---|
| 488 | |
|---|
| 489 | m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx ); |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
|---|
| 493 | { |
|---|
| 494 | if( bRD ) |
|---|
| 495 | { |
|---|
| 496 | uiAbsPartIdx = 0; |
|---|
| 497 | } |
|---|
| 498 | if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode. |
|---|
| 499 | { |
|---|
| 500 | encodeIntraDirModeLuma ( pcCU, uiAbsPartIdx,true ); |
|---|
| 501 | #if H_3D_DIM_SDC |
|---|
| 502 | if(!pcCU->getSDCFlag(uiAbsPartIdx)) |
|---|
| 503 | #endif |
|---|
| 504 | encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD ); |
|---|
| 505 | } |
|---|
| 506 | else // if it is Inter mode, encode motion vector and reference index |
|---|
| 507 | { |
|---|
| 508 | encodePUWise( pcCU, uiAbsPartIdx, bRD ); |
|---|
| 509 | } |
|---|
| 510 | } |
|---|
| 511 | |
|---|
| 512 | /** encode motion information for every PU block |
|---|
| 513 | * \param pcCU |
|---|
| 514 | * \param uiAbsPartIdx |
|---|
| 515 | * \param bRD |
|---|
| 516 | * \returns Void |
|---|
| 517 | */ |
|---|
| 518 | Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
|---|
| 519 | { |
|---|
| 520 | if ( bRD ) |
|---|
| 521 | { |
|---|
| 522 | uiAbsPartIdx = 0; |
|---|
| 523 | } |
|---|
| 524 | |
|---|
| 525 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
|---|
| 526 | UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) ); |
|---|
| 527 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ); |
|---|
| 528 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4; |
|---|
| 529 | |
|---|
| 530 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
|---|
| 531 | { |
|---|
| 532 | #if H_MV_ENC_DEC_TRAC |
|---|
| 533 | DTRACE_PU_S("=========== prediction_unit ===========\n") |
|---|
| 534 | //Todo: |
|---|
| 535 | //DTRACE_PU("x0", uiLPelX) |
|---|
| 536 | //DTRACE_PU("x1", uiTPelY) |
|---|
| 537 | #endif |
|---|
| 538 | encodeMergeFlag( pcCU, uiSubPartIdx ); |
|---|
| 539 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
|---|
| 540 | { |
|---|
| 541 | encodeMergeIndex( pcCU, uiSubPartIdx ); |
|---|
| 542 | } |
|---|
| 543 | else |
|---|
| 544 | { |
|---|
| 545 | encodeInterDirPU( pcCU, uiSubPartIdx ); |
|---|
| 546 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
|---|
| 547 | { |
|---|
| 548 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
|---|
| 549 | { |
|---|
| 550 | encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
|---|
| 551 | encodeMvdPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
|---|
| 552 | encodeMVPIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
|---|
| 553 | } |
|---|
| 554 | } |
|---|
| 555 | } |
|---|
| 556 | } |
|---|
| 557 | |
|---|
| 558 | return; |
|---|
| 559 | } |
|---|
| 560 | |
|---|
| 561 | Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
|---|
| 562 | { |
|---|
| 563 | if ( !pcCU->getSlice()->isInterB() ) |
|---|
| 564 | { |
|---|
| 565 | return; |
|---|
| 566 | } |
|---|
| 567 | |
|---|
| 568 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
|---|
| 569 | return; |
|---|
| 570 | } |
|---|
| 571 | |
|---|
| 572 | /** encode reference frame index for a PU block |
|---|
| 573 | * \param pcCU |
|---|
| 574 | * \param uiAbsPartIdx |
|---|
| 575 | * \param eRefList |
|---|
| 576 | * \returns Void |
|---|
| 577 | */ |
|---|
| 578 | Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
|---|
| 579 | { |
|---|
| 580 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
|---|
| 581 | { |
|---|
| 582 | if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) ) |
|---|
| 583 | { |
|---|
| 584 | return; |
|---|
| 585 | } |
|---|
| 586 | |
|---|
| 587 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
|---|
| 588 | { |
|---|
| 589 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
|---|
| 590 | } |
|---|
| 591 | } |
|---|
| 592 | |
|---|
| 593 | return; |
|---|
| 594 | } |
|---|
| 595 | |
|---|
| 596 | /** encode motion vector difference for a PU block |
|---|
| 597 | * \param pcCU |
|---|
| 598 | * \param uiAbsPartIdx |
|---|
| 599 | * \param eRefList |
|---|
| 600 | * \returns Void |
|---|
| 601 | */ |
|---|
| 602 | Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
|---|
| 603 | { |
|---|
| 604 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
|---|
| 605 | |
|---|
| 606 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
|---|
| 607 | { |
|---|
| 608 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
|---|
| 609 | } |
|---|
| 610 | return; |
|---|
| 611 | } |
|---|
| 612 | |
|---|
| 613 | Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
|---|
| 614 | { |
|---|
| 615 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) ) |
|---|
| 616 | { |
|---|
| 617 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
|---|
| 618 | } |
|---|
| 619 | |
|---|
| 620 | return; |
|---|
| 621 | } |
|---|
| 622 | |
|---|
| 623 | Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
|---|
| 624 | { |
|---|
| 625 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth ); |
|---|
| 626 | } |
|---|
| 627 | |
|---|
| 628 | Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
|---|
| 629 | { |
|---|
| 630 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx ); |
|---|
| 631 | } |
|---|
| 632 | |
|---|
| 633 | Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
|---|
| 634 | { |
|---|
| 635 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
|---|
| 636 | } |
|---|
| 637 | |
|---|
| 638 | Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
|---|
| 639 | { |
|---|
| 640 | m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth ); |
|---|
| 641 | } |
|---|
| 642 | Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU ) |
|---|
| 643 | { |
|---|
| 644 | m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU ); |
|---|
| 645 | } |
|---|
| 646 | |
|---|
| 647 | // dQP |
|---|
| 648 | Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
|---|
| 649 | { |
|---|
| 650 | if( bRD ) |
|---|
| 651 | { |
|---|
| 652 | uiAbsPartIdx = 0; |
|---|
| 653 | } |
|---|
| 654 | |
|---|
| 655 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
|---|
| 656 | { |
|---|
| 657 | m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx ); |
|---|
| 658 | } |
|---|
| 659 | } |
|---|
| 660 | |
|---|
| 661 | |
|---|
| 662 | // texture |
|---|
| 663 | /** encode coefficients |
|---|
| 664 | * \param pcCU |
|---|
| 665 | * \param uiAbsPartIdx |
|---|
| 666 | * \param uiDepth |
|---|
| 667 | * \param uiWidth |
|---|
| 668 | * \param uiHeight |
|---|
| 669 | */ |
|---|
| 670 | Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP ) |
|---|
| 671 | { |
|---|
| 672 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
|---|
| 673 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
|---|
| 674 | UInt uiChromaOffset = uiLumaOffset>>2; |
|---|
| 675 | |
|---|
| 676 | #if H_3D_DIM_SDC |
|---|
| 677 | if( pcCU->getSDCFlag( uiAbsPartIdx ) ) |
|---|
| 678 | { |
|---|
| 679 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
|---|
| 680 | assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 ); |
|---|
| 681 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 ); |
|---|
| 682 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 ); |
|---|
| 683 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 ); |
|---|
| 684 | return; |
|---|
| 685 | } |
|---|
| 686 | #endif |
|---|
| 687 | |
|---|
| 688 | #if H_3D_INTER_SDC |
|---|
| 689 | if( pcCU->getInterSDCFlag( uiAbsPartIdx ) ) |
|---|
| 690 | { |
|---|
| 691 | assert( !pcCU->isSkipped( uiAbsPartIdx ) ); |
|---|
| 692 | assert( !pcCU->isIntra( uiAbsPartIdx) ); |
|---|
| 693 | assert( pcCU->getSlice()->getIsDepth() ); |
|---|
| 694 | |
|---|
| 695 | encodeInterSDCResidualData( pcCU, uiAbsPartIdx, false ); |
|---|
| 696 | return; |
|---|
| 697 | } |
|---|
| 698 | #endif |
|---|
| 699 | |
|---|
| 700 | if( pcCU->isIntra(uiAbsPartIdx) ) |
|---|
| 701 | { |
|---|
| 702 | #if !H_MV |
|---|
| 703 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
|---|
| 704 | DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" ) |
|---|
| 705 | DTRACE_CABAC_V( uiDepth ) |
|---|
| 706 | DTRACE_CABAC_T( "\n" ) |
|---|
| 707 | #endif |
|---|
| 708 | } |
|---|
| 709 | else |
|---|
| 710 | { |
|---|
| 711 | if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) ) |
|---|
| 712 | { |
|---|
| 713 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
|---|
| 714 | } |
|---|
| 715 | if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) ) |
|---|
| 716 | { |
|---|
| 717 | return; |
|---|
| 718 | } |
|---|
| 719 | } |
|---|
| 720 | |
|---|
| 721 | xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP); |
|---|
| 722 | } |
|---|
| 723 | |
|---|
| 724 | Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType ) |
|---|
| 725 | { |
|---|
| 726 | // This is for Transform unit processing. This may be used at mode selection stage for Inter. |
|---|
| 727 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType ); |
|---|
| 728 | } |
|---|
| 729 | |
|---|
| 730 | Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) |
|---|
| 731 | { |
|---|
| 732 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA; |
|---|
| 733 | |
|---|
| 734 | m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType ); |
|---|
| 735 | } |
|---|
| 736 | |
|---|
| 737 | /** Encode SAO Offset |
|---|
| 738 | * \param saoLcuParam SAO LCU paramters |
|---|
| 739 | */ |
|---|
| 740 | Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx) |
|---|
| 741 | { |
|---|
| 742 | UInt uiSymbol; |
|---|
| 743 | Int i; |
|---|
| 744 | |
|---|
| 745 | uiSymbol = saoLcuParam->typeIdx + 1; |
|---|
| 746 | if (compIdx!=2) |
|---|
| 747 | { |
|---|
| 748 | m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol); |
|---|
| 749 | } |
|---|
| 750 | if (uiSymbol) |
|---|
| 751 | { |
|---|
| 752 | if (saoLcuParam->typeIdx < 4 && compIdx != 2) |
|---|
| 753 | { |
|---|
| 754 | saoLcuParam->subTypeIdx = saoLcuParam->typeIdx; |
|---|
| 755 | } |
|---|
| 756 | Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY; |
|---|
| 757 | Int offsetTh = 1 << min(bitDepth - 5,5); |
|---|
| 758 | if( saoLcuParam->typeIdx == SAO_BO ) |
|---|
| 759 | { |
|---|
| 760 | for( i=0; i< saoLcuParam->length; i++) |
|---|
| 761 | { |
|---|
| 762 | UInt absOffset = ( (saoLcuParam->offset[i] < 0) ? -saoLcuParam->offset[i] : saoLcuParam->offset[i]); |
|---|
| 763 | m_pcEntropyCoderIf->codeSaoMaxUvlc(absOffset, offsetTh-1); |
|---|
| 764 | } |
|---|
| 765 | for( i=0; i< saoLcuParam->length; i++) |
|---|
| 766 | { |
|---|
| 767 | if (saoLcuParam->offset[i] != 0) |
|---|
| 768 | { |
|---|
| 769 | UInt sign = (saoLcuParam->offset[i] < 0) ? 1 : 0 ; |
|---|
| 770 | m_pcEntropyCoderIf->codeSAOSign(sign); |
|---|
| 771 | } |
|---|
| 772 | } |
|---|
| 773 | uiSymbol = (UInt) (saoLcuParam->subTypeIdx); |
|---|
| 774 | m_pcEntropyCoderIf->codeSaoUflc(5, uiSymbol); |
|---|
| 775 | } |
|---|
| 776 | else if( saoLcuParam->typeIdx < 4 ) |
|---|
| 777 | { |
|---|
| 778 | m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[0], offsetTh-1); |
|---|
| 779 | m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[1], offsetTh-1); |
|---|
| 780 | m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[2], offsetTh-1); |
|---|
| 781 | m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[3], offsetTh-1); |
|---|
| 782 | if (compIdx!=2) |
|---|
| 783 | { |
|---|
| 784 | uiSymbol = (UInt) (saoLcuParam->subTypeIdx); |
|---|
| 785 | m_pcEntropyCoderIf->codeSaoUflc(2, uiSymbol); |
|---|
| 786 | } |
|---|
| 787 | } |
|---|
| 788 | } |
|---|
| 789 | } |
|---|
| 790 | |
|---|
| 791 | /** Encode SAO unit interleaving |
|---|
| 792 | * \param rx |
|---|
| 793 | * \param ry |
|---|
| 794 | * \param pSaoParam |
|---|
| 795 | * \param pcCU |
|---|
| 796 | * \param iCUAddrInSlice |
|---|
| 797 | * \param iCUAddrUpInSlice |
|---|
| 798 | * \param bLFCrossSliceBoundaryFlag |
|---|
| 799 | */ |
|---|
| 800 | Void TEncEntropy::encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp) |
|---|
| 801 | { |
|---|
| 802 | if (saoFlag) |
|---|
| 803 | { |
|---|
| 804 | if (rx>0 && cuAddrInSlice!=0 && allowMergeLeft) |
|---|
| 805 | { |
|---|
| 806 | m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeLeftFlag); |
|---|
| 807 | } |
|---|
| 808 | else |
|---|
| 809 | { |
|---|
| 810 | saoLcuParam->mergeLeftFlag = 0; |
|---|
| 811 | } |
|---|
| 812 | if (saoLcuParam->mergeLeftFlag == 0) |
|---|
| 813 | { |
|---|
| 814 | if ( (ry > 0) && (cuAddrUpInSlice>=0) && allowMergeUp ) |
|---|
| 815 | { |
|---|
| 816 | m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeUpFlag); |
|---|
| 817 | } |
|---|
| 818 | else |
|---|
| 819 | { |
|---|
| 820 | saoLcuParam->mergeUpFlag = 0; |
|---|
| 821 | } |
|---|
| 822 | if (!saoLcuParam->mergeUpFlag) |
|---|
| 823 | { |
|---|
| 824 | encodeSaoOffset(saoLcuParam, compIdx); |
|---|
| 825 | } |
|---|
| 826 | } |
|---|
| 827 | } |
|---|
| 828 | } |
|---|
| 829 | |
|---|
| 830 | Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ) |
|---|
| 831 | { |
|---|
| 832 | Int count = 0; |
|---|
| 833 | |
|---|
| 834 | for ( Int i = 0; i < uiSize; i++ ) |
|---|
| 835 | { |
|---|
| 836 | count += pcCoef[i] != 0; |
|---|
| 837 | } |
|---|
| 838 | |
|---|
| 839 | return count; |
|---|
| 840 | } |
|---|
| 841 | |
|---|
| 842 | /** encode quantization matrix |
|---|
| 843 | * \param scalingList quantization matrix information |
|---|
| 844 | */ |
|---|
| 845 | Void TEncEntropy::encodeScalingList( TComScalingList* scalingList ) |
|---|
| 846 | { |
|---|
| 847 | m_pcEntropyCoderIf->codeScalingList( scalingList ); |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | #if H_3D_INTER_SDC |
|---|
| 851 | Void TEncEntropy::encodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
|---|
| 852 | { |
|---|
| 853 | if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) |
|---|
| 854 | { |
|---|
| 855 | return; |
|---|
| 856 | } |
|---|
| 857 | |
|---|
| 858 | if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) ) |
|---|
| 859 | { |
|---|
| 860 | return; |
|---|
| 861 | } |
|---|
| 862 | |
|---|
| 863 | if( bRD ) |
|---|
| 864 | { |
|---|
| 865 | uiAbsPartIdx = 0; |
|---|
| 866 | } |
|---|
| 867 | |
|---|
| 868 | m_pcEntropyCoderIf->codeInterSDCFlag( pcCU, uiAbsPartIdx ); |
|---|
| 869 | } |
|---|
| 870 | |
|---|
| 871 | Void TEncEntropy::encodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
|---|
| 872 | { |
|---|
| 873 | if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) |
|---|
| 874 | { |
|---|
| 875 | return; |
|---|
| 876 | } |
|---|
| 877 | |
|---|
| 878 | if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) ) |
|---|
| 879 | { |
|---|
| 880 | return; |
|---|
| 881 | } |
|---|
| 882 | |
|---|
| 883 | if( bRD ) |
|---|
| 884 | { |
|---|
| 885 | uiAbsPartIdx = 0; |
|---|
| 886 | } |
|---|
| 887 | |
|---|
| 888 | // number of segments depends on prediction mode for INTRA |
|---|
| 889 | UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 ); |
|---|
| 890 | |
|---|
| 891 | // encode residual data for each segment |
|---|
| 892 | for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ ) |
|---|
| 893 | { |
|---|
| 894 | m_pcEntropyCoderIf->codeInterSDCResidualData( pcCU, uiAbsPartIdx, uiSeg ); |
|---|
| 895 | } |
|---|
| 896 | } |
|---|
| 897 | #endif |
|---|
| 898 | |
|---|
| 899 | #if H_3D_DBBP |
|---|
| 900 | Void TEncEntropy::encodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
|---|
| 901 | { |
|---|
| 902 | if( bRD ) |
|---|
| 903 | { |
|---|
| 904 | uiAbsPartIdx = 0; |
|---|
| 905 | } |
|---|
| 906 | m_pcEntropyCoderIf->codeDBBPFlag( pcCU, uiAbsPartIdx ); |
|---|
| 907 | } |
|---|
| 908 | #endif |
|---|
| 909 | |
|---|
| 910 | //! \} |
|---|