[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 |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
| 6 | * Copyright (c) 2010-2011, 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 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 | */ |
---|
[2] | 33 | |
---|
| 34 | |
---|
[5] | 35 | |
---|
[2] | 36 | /** \file TDecCAVLC.cpp |
---|
| 37 | \brief CAVLC decoder class |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | #include "TDecCAVLC.h" |
---|
| 41 | #include "SEIread.h" |
---|
| 42 | |
---|
| 43 | // ==================================================================================================================== |
---|
| 44 | // Constructor / destructor / create / destroy |
---|
| 45 | // ==================================================================================================================== |
---|
| 46 | |
---|
| 47 | TDecCavlc::TDecCavlc() |
---|
| 48 | { |
---|
| 49 | m_bAlfCtrl = false; |
---|
| 50 | m_uiMaxAlfCtrlDepth = 0; |
---|
| 51 | |
---|
| 52 | m_aaiTempScale = new Int* [ MAX_NUMBER_VIEWS ]; |
---|
| 53 | m_aaiTempOffset = new Int* [ MAX_NUMBER_VIEWS ]; |
---|
| 54 | m_aaiTempPdmScaleNomDelta = new Int* [ MAX_NUMBER_VIEWS ]; |
---|
| 55 | m_aaiTempPdmOffset = new Int* [ MAX_NUMBER_VIEWS ]; |
---|
| 56 | for( UInt uiVId = 0; uiVId < MAX_NUMBER_VIEWS; uiVId++ ) |
---|
| 57 | { |
---|
| 58 | m_aaiTempScale [ uiVId ] = new Int [ MAX_NUMBER_VIEWS ]; |
---|
| 59 | m_aaiTempOffset [ uiVId ] = new Int [ MAX_NUMBER_VIEWS ]; |
---|
| 60 | m_aaiTempPdmScaleNomDelta [ uiVId ] = new Int [ MAX_NUMBER_VIEWS ]; |
---|
| 61 | m_aaiTempPdmOffset [ uiVId ] = new Int [ MAX_NUMBER_VIEWS ]; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | TDecCavlc::~TDecCavlc() |
---|
| 66 | { |
---|
| 67 | for( UInt uiVId = 0; uiVId < MAX_NUMBER_VIEWS; uiVId++ ) |
---|
| 68 | { |
---|
| 69 | delete [] m_aaiTempScale [ uiVId ]; |
---|
| 70 | delete [] m_aaiTempOffset [ uiVId ]; |
---|
| 71 | delete [] m_aaiTempPdmScaleNomDelta [ uiVId ]; |
---|
| 72 | delete [] m_aaiTempPdmOffset [ uiVId ]; |
---|
| 73 | } |
---|
| 74 | delete [] m_aaiTempScale; |
---|
| 75 | delete [] m_aaiTempOffset; |
---|
| 76 | delete [] m_aaiTempPdmScaleNomDelta; |
---|
| 77 | delete [] m_aaiTempPdmOffset; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | // ==================================================================================================================== |
---|
| 81 | // Public member functions |
---|
| 82 | // ==================================================================================================================== |
---|
| 83 | |
---|
[50] | 84 | #if BITSTREAM_EXTRACTION |
---|
| 85 | Void TDecCavlc::parseNalUnitHeader ( NalUnitType& eNalUnitType, UInt& TemporalId, UInt& uiLayerId ) |
---|
| 86 | { |
---|
| 87 | UInt uiCode; |
---|
| 88 | |
---|
| 89 | xReadCode ( 1, uiCode ); assert( 0 == uiCode); // forbidden_zero_bit |
---|
| 90 | xReadCode ( 1, uiCode ); // nal_ref_flag |
---|
| 91 | xReadCode ( 6, uiCode ); // nal_unit_type |
---|
| 92 | eNalUnitType = (NalUnitType) uiCode; |
---|
| 93 | |
---|
| 94 | xReadCode(3, uiCode); // temporal_id |
---|
| 95 | TemporalId = uiCode; |
---|
| 96 | xReadCode(5, uiCode); // layer_id_plus1 |
---|
| 97 | assert( 1 <= uiCode ); |
---|
| 98 | uiLayerId = uiCode - 1; |
---|
| 99 | } |
---|
| 100 | #else |
---|
[2] | 101 | Void TDecCavlc::parseNalUnitHeader ( NalUnitType& eNalUnitType, UInt& TemporalId, Bool& bOutputFlag ) |
---|
| 102 | { |
---|
| 103 | UInt uiCode; |
---|
| 104 | |
---|
| 105 | xReadCode ( 1, uiCode ); assert( 0 == uiCode); // forbidden_zero_bit |
---|
| 106 | xReadCode ( 2, uiCode ); // nal_ref_idc |
---|
| 107 | xReadCode ( 5, uiCode ); // nal_unit_type |
---|
| 108 | eNalUnitType = (NalUnitType) uiCode; |
---|
| 109 | |
---|
| 110 | if ( (eNalUnitType == NAL_UNIT_CODED_SLICE) || (eNalUnitType == NAL_UNIT_CODED_SLICE_IDR) || (eNalUnitType == NAL_UNIT_CODED_SLICE_CDR) ) |
---|
| 111 | { |
---|
| 112 | xReadCode(3, uiCode); // temporal_id |
---|
| 113 | TemporalId = uiCode; |
---|
| 114 | xReadFlag(uiCode); // output_flag |
---|
| 115 | bOutputFlag = (0!=uiCode); |
---|
| 116 | xReadCode(4, uiCode); // reserved_one_4bits |
---|
| 117 | } |
---|
| 118 | else |
---|
| 119 | { |
---|
| 120 | TemporalId = 0; |
---|
| 121 | bOutputFlag = true; |
---|
| 122 | } |
---|
| 123 | } |
---|
[50] | 124 | #endif |
---|
[2] | 125 | |
---|
| 126 | /** |
---|
| 127 | * unmarshal a sequence of SEI messages from bitstream. |
---|
| 128 | */ |
---|
| 129 | void TDecCavlc::parseSEI(SEImessages& seis) |
---|
| 130 | { |
---|
| 131 | assert(!m_pcBitstream->getBitsUntilByteAligned()); |
---|
| 132 | do { |
---|
| 133 | parseSEImessage(*m_pcBitstream, seis); |
---|
| 134 | /* SEI messages are an integer number of bytes, something has failed |
---|
| 135 | * in the parsing if bitstream not byte-aligned */ |
---|
| 136 | assert(!m_pcBitstream->getBitsUntilByteAligned()); |
---|
| 137 | } while (0x80 != m_pcBitstream->peekBits(8)); |
---|
| 138 | assert(m_pcBitstream->getBitsLeft() == 8); /* rsbp_trailing_bits */ |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | Void TDecCavlc::parsePPS(TComPPS* pcPPS) |
---|
| 142 | { |
---|
| 143 | UInt uiCode; |
---|
| 144 | |
---|
| 145 | xReadUvlc( uiCode ); pcPPS->setPPSId( uiCode ); |
---|
| 146 | xReadUvlc( uiCode ); pcPPS->setSPSId( uiCode ); |
---|
| 147 | #if CONSTRAINED_INTRA_PRED |
---|
| 148 | xReadFlag ( uiCode ); pcPPS->setConstrainedIntraPred( uiCode ? true : false ); |
---|
| 149 | #endif |
---|
| 150 | |
---|
| 151 | #ifdef WEIGHT_PRED |
---|
| 152 | xReadCode( 1, uiCode ); // Use of Weighting Prediction (P_SLICE) |
---|
| 153 | pcPPS->setUseWP( uiCode==1 ); |
---|
| 154 | xReadCode( 2, uiCode ); // Use of Bi-Directional Weighting Prediction (B_SLICE) |
---|
| 155 | pcPPS->setWPBiPredIdc( uiCode ); |
---|
| 156 | printf("TDecCavlc::parsePPS():\tm_bUseWeightPred=%d\tm_uiBiPredIdc=%d\n", pcPPS->getUseWP(), pcPPS->getWPBiPredIdc()); |
---|
| 157 | #endif |
---|
| 158 | return; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | Void TDecCavlc::parseSPS(TComSPS* pcSPS) |
---|
| 162 | { |
---|
| 163 | UInt uiCode; |
---|
| 164 | Int iCode; |
---|
| 165 | |
---|
| 166 | // Structure |
---|
| 167 | xReadUvlc ( uiCode ); pcSPS->setSPSId ( uiCode ); |
---|
| 168 | xReadUvlc ( uiCode ); pcSPS->setWidth ( uiCode ); |
---|
| 169 | xReadUvlc ( uiCode ); pcSPS->setHeight ( uiCode ); |
---|
| 170 | xReadUvlc ( uiCode ); pcSPS->setPadX ( uiCode ); |
---|
| 171 | xReadUvlc ( uiCode ); pcSPS->setPadY ( uiCode ); |
---|
| 172 | |
---|
| 173 | xReadUvlc ( uiCode ); |
---|
| 174 | pcSPS->setMaxCUWidth ( uiCode ); g_uiMaxCUWidth = uiCode; |
---|
| 175 | pcSPS->setMaxCUHeight ( uiCode ); g_uiMaxCUHeight = uiCode; |
---|
| 176 | |
---|
| 177 | xReadUvlc ( uiCode ); |
---|
| 178 | pcSPS->setMaxCUDepth ( uiCode+1 ); g_uiMaxCUDepth = uiCode + 1; |
---|
| 179 | UInt uiMaxCUDepthCorrect = uiCode; |
---|
| 180 | |
---|
| 181 | xReadUvlc( uiCode ); pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 ); |
---|
| 182 | xReadUvlc( uiCode ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() ); |
---|
| 183 | pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) ); |
---|
| 184 | xReadUvlc ( uiCode ); pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 ); |
---|
| 185 | xReadUvlc ( uiCode ); pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 ); |
---|
| 186 | g_uiAddCUDepth = 0; |
---|
| 187 | while( ( pcSPS->getMaxCUWidth() >> uiMaxCUDepthCorrect ) > ( 1 << ( pcSPS->getQuadtreeTULog2MinSize() + g_uiAddCUDepth ) ) ) g_uiAddCUDepth++; |
---|
| 188 | pcSPS->setMaxCUDepth( uiMaxCUDepthCorrect+g_uiAddCUDepth ); g_uiMaxCUDepth = uiMaxCUDepthCorrect+g_uiAddCUDepth; |
---|
| 189 | // BB: these parameters may be removed completly and replaced by the fixed values |
---|
| 190 | pcSPS->setMinTrDepth( 0 ); |
---|
| 191 | pcSPS->setMaxTrDepth( 1 ); |
---|
| 192 | |
---|
| 193 | xReadUvlc( uiCode ); pcSPS->setCodedPictureBufferSize( uiCode ); |
---|
| 194 | |
---|
| 195 | // Tool on/off |
---|
| 196 | xReadFlag( uiCode ); pcSPS->setUseALF ( uiCode ? true : false ); |
---|
| 197 | xReadFlag( uiCode ); pcSPS->setUseDQP ( uiCode ? true : false ); |
---|
[5] | 198 | #if !HHI_NO_LowDelayCoding |
---|
[2] | 199 | xReadFlag( uiCode ); pcSPS->setUseLDC ( uiCode ? true : false ); |
---|
| 200 | #endif |
---|
| 201 | xReadFlag( uiCode ); pcSPS->setUseMRG ( uiCode ? true : false ); // SOPH: |
---|
| 202 | |
---|
| 203 | #if LM_CHROMA |
---|
| 204 | xReadFlag( uiCode ); pcSPS->setUseLMChroma ( uiCode ? true : false ); |
---|
| 205 | #endif |
---|
| 206 | |
---|
| 207 | #if HHI_RMP_SWITCH |
---|
| 208 | xReadFlag( uiCode ); pcSPS->setUseRMP( uiCode ? true : false ); |
---|
| 209 | #endif |
---|
| 210 | |
---|
| 211 | // AMVP mode for each depth (AM_NONE or AM_EXPL) |
---|
| 212 | for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++) |
---|
| 213 | { |
---|
| 214 | xReadFlag( uiCode ); |
---|
| 215 | pcSPS->setAMVPMode( i, (AMVP_MODE)uiCode ); |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | // Bit-depth information |
---|
| 219 | #if FULL_NBIT |
---|
| 220 | xReadUvlc( uiCode ); |
---|
| 221 | g_uiBitDepth = 8 + uiCode; |
---|
| 222 | g_uiBitIncrement = 0; |
---|
| 223 | pcSPS->setBitDepth(g_uiBitDepth); |
---|
| 224 | pcSPS->setBitIncrement(g_uiBitIncrement); |
---|
| 225 | #else |
---|
| 226 | #if ENABLE_IBDI |
---|
| 227 | xReadUvlc( uiCode ); pcSPS->setBitDepth ( uiCode+8 ); g_uiBitDepth = uiCode + 8; |
---|
| 228 | xReadUvlc( uiCode ); pcSPS->setBitIncrement ( uiCode ); g_uiBitIncrement = uiCode; |
---|
| 229 | #else |
---|
| 230 | xReadUvlc( uiCode ); |
---|
| 231 | g_uiBitDepth = 8; |
---|
| 232 | g_uiBitIncrement = uiCode; |
---|
| 233 | pcSPS->setBitDepth(g_uiBitDepth); |
---|
| 234 | pcSPS->setBitIncrement(g_uiBitIncrement); |
---|
| 235 | #endif |
---|
| 236 | #endif |
---|
| 237 | |
---|
| 238 | g_uiBASE_MAX = ((1<<(g_uiBitDepth))-1); |
---|
| 239 | |
---|
| 240 | #if IBDI_NOCLIP_RANGE |
---|
| 241 | g_uiIBDI_MAX = g_uiBASE_MAX << g_uiBitIncrement; |
---|
| 242 | #else |
---|
| 243 | g_uiIBDI_MAX = ((1<<(g_uiBitDepth+g_uiBitIncrement))-1); |
---|
| 244 | #endif |
---|
| 245 | |
---|
[5] | 246 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[2] | 247 | g_dDeltaDCsQuantOffset = Double(g_uiBitIncrement) - 2.0; |
---|
| 248 | #endif |
---|
| 249 | |
---|
| 250 | #if MTK_NONCROSS_INLOOP_FILTER |
---|
| 251 | xReadFlag( uiCode ); |
---|
| 252 | pcSPS->setLFCrossSliceBoundaryFlag( uiCode ? true : false); |
---|
| 253 | #endif |
---|
| 254 | #if MTK_SAO |
---|
| 255 | xReadFlag( uiCode ); pcSPS->setUseSAO ( uiCode ? true : false ); |
---|
| 256 | #endif |
---|
| 257 | |
---|
| 258 | xReadFlag( uiCode ); // SPS base view flag |
---|
| 259 | if( uiCode ) |
---|
| 260 | { // baseview SPS -> set standard values |
---|
| 261 | pcSPS->initMultiviewSPS ( 0 ); |
---|
[5] | 262 | #if DEPTH_MAP_GENERATION |
---|
[2] | 263 | pcSPS->setPredDepthMapGeneration( 0, false ); |
---|
[5] | 264 | #endif |
---|
| 265 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
[2] | 266 | pcSPS->setMultiviewResPredMode ( 0 ); |
---|
[5] | 267 | #endif |
---|
[2] | 268 | } |
---|
| 269 | else |
---|
| 270 | { |
---|
| 271 | xReadFlag ( uiCode ); // depth flag |
---|
| 272 | if( uiCode ) |
---|
| 273 | { |
---|
| 274 | xReadUvlc( uiCode ); // view id |
---|
| 275 | xReadSvlc( iCode ); // view order index |
---|
| 276 | pcSPS->initMultiviewSPSDepth ( uiCode, iCode ); |
---|
[5] | 277 | #if DEPTH_MAP_GENERATION |
---|
[2] | 278 | pcSPS->setPredDepthMapGeneration( uiCode, true ); |
---|
[5] | 279 | #endif |
---|
| 280 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
[2] | 281 | pcSPS->setMultiviewResPredMode ( 0 ); |
---|
[5] | 282 | #endif |
---|
| 283 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[2] | 284 | xReadFlag( uiCode ); |
---|
[5] | 285 | pcSPS->setUseDMM( uiCode ? true : false ); |
---|
[2] | 286 | #endif |
---|
[5] | 287 | #if HHI_MPI |
---|
[2] | 288 | xReadFlag( uiCode ); |
---|
| 289 | pcSPS->setUseMVI( uiCode ? true : false ); |
---|
[5] | 290 | #endif |
---|
[2] | 291 | } |
---|
| 292 | else |
---|
| 293 | { |
---|
| 294 | UInt uiViewId, uiCamParPrecision; |
---|
| 295 | Int iVOI; |
---|
| 296 | Bool bCamParSlice; |
---|
| 297 | xReadUvlc( uiViewId ); uiViewId++; |
---|
| 298 | xReadSvlc( iVOI ); |
---|
| 299 | xReadUvlc( uiCamParPrecision ); |
---|
| 300 | xReadFlag( uiCode ); bCamParSlice = ( uiCode == 1 ); |
---|
| 301 | if( !bCamParSlice ) |
---|
| 302 | { |
---|
| 303 | for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ ) |
---|
| 304 | { |
---|
| 305 | xReadSvlc( iCode ); m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode; |
---|
| 306 | xReadSvlc( iCode ); m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode; |
---|
| 307 | xReadSvlc( iCode ); m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ]; |
---|
| 308 | xReadSvlc( iCode ); m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ]; |
---|
| 309 | } |
---|
| 310 | } |
---|
| 311 | pcSPS->initMultiviewSPS( uiViewId, iVOI, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset ); |
---|
| 312 | |
---|
[5] | 313 | #if DEPTH_MAP_GENERATION |
---|
| 314 | UInt uiPredDepthMapGeneration = 0, uiPdmPrecision = 0; |
---|
| 315 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
| 316 | UInt uiMultiviewMvPredMode = 0; |
---|
| 317 | #endif |
---|
| 318 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
| 319 | UInt uiMultiviewResPredMode = 0; |
---|
| 320 | #endif |
---|
[2] | 321 | xReadUvlc( uiPredDepthMapGeneration ); |
---|
| 322 | if( uiPredDepthMapGeneration ) |
---|
| 323 | { |
---|
| 324 | xReadUvlc ( uiPdmPrecision ); |
---|
| 325 | for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ ) |
---|
| 326 | { |
---|
| 327 | xReadSvlc( iCode ); m_aaiTempPdmScaleNomDelta[ uiViewId ][ uiBaseId ] = iCode; |
---|
| 328 | xReadSvlc( iCode ); m_aaiTempPdmOffset [ uiViewId ][ uiBaseId ] = iCode; |
---|
| 329 | } |
---|
[5] | 330 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
[2] | 331 | xReadUvlc ( uiMultiviewMvPredMode ); |
---|
[5] | 332 | #endif |
---|
| 333 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
[2] | 334 | xReadFlag ( uiMultiviewResPredMode ); |
---|
[5] | 335 | #endif |
---|
[2] | 336 | } |
---|
[5] | 337 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
[2] | 338 | pcSPS->setPredDepthMapGeneration( uiViewId, false, uiPredDepthMapGeneration, uiMultiviewMvPredMode, uiPdmPrecision, m_aaiTempPdmScaleNomDelta, m_aaiTempPdmOffset ); |
---|
[5] | 339 | #else |
---|
| 340 | pcSPS->setPredDepthMapGeneration( uiViewId, false, uiPredDepthMapGeneration, 0, uiPdmPrecision, m_aaiTempPdmScaleNomDelta, m_aaiTempPdmOffset ); |
---|
| 341 | #endif |
---|
| 342 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
[2] | 343 | pcSPS->setMultiviewResPredMode ( uiMultiviewResPredMode ); |
---|
[5] | 344 | #endif |
---|
| 345 | #endif |
---|
| 346 | #if HHI_MPI |
---|
[2] | 347 | pcSPS->setUseMVI( false ); |
---|
[5] | 348 | #endif |
---|
[2] | 349 | } |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | return; |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice) |
---|
| 356 | { |
---|
| 357 | UInt uiCode; |
---|
| 358 | Int iCode; |
---|
| 359 | |
---|
| 360 | xReadFlag ( uiCode ); |
---|
| 361 | Bool bEntropySlice = uiCode ? true : false; |
---|
| 362 | if (!bEntropySlice) |
---|
| 363 | { |
---|
| 364 | xReadUvlc ( uiCode ); rpcSlice->setPPSId( uiCode ); |
---|
| 365 | xReadCode (10, uiCode); rpcSlice->setPOC (uiCode); // 9 == SPS->Log2MaxFrameNum() |
---|
| 366 | xReadUvlc ( uiCode); rpcSlice->setSliceType ((SliceType)uiCode); |
---|
| 367 | xReadSvlc ( iCode); rpcSlice->setSliceQp (iCode); |
---|
| 368 | } |
---|
| 369 | if (bEntropySlice) |
---|
| 370 | { |
---|
| 371 | rpcSlice->setNextSlice ( false ); |
---|
| 372 | rpcSlice->setNextEntropySlice ( true ); |
---|
| 373 | |
---|
| 374 | xReadUvlc(uiCode); |
---|
| 375 | rpcSlice->setEntropySliceCurStartCUAddr( uiCode ); // start CU addr for entropy slice |
---|
| 376 | } |
---|
| 377 | else |
---|
| 378 | { |
---|
| 379 | rpcSlice->setNextSlice ( true ); |
---|
| 380 | rpcSlice->setNextEntropySlice ( false ); |
---|
| 381 | |
---|
| 382 | xReadUvlc(uiCode); |
---|
| 383 | rpcSlice->setSliceCurStartCUAddr( uiCode ); // start CU addr for slice |
---|
| 384 | rpcSlice->setEntropySliceCurStartCUAddr( uiCode ); // start CU addr for entropy slice |
---|
| 385 | |
---|
| 386 | xReadFlag ( uiCode ); |
---|
| 387 | rpcSlice->setSymbolMode( uiCode ); |
---|
| 388 | |
---|
| 389 | if (!rpcSlice->isIntra()) |
---|
| 390 | xReadFlag ( uiCode); |
---|
| 391 | else |
---|
| 392 | uiCode = 1; |
---|
| 393 | |
---|
| 394 | rpcSlice->setReferenced (uiCode ? true : false); |
---|
| 395 | |
---|
| 396 | #if !HIGH_ACCURACY_BI |
---|
| 397 | #ifdef ROUNDING_CONTROL_BIPRED |
---|
| 398 | if(!rpcSlice->isIntra()) |
---|
| 399 | { |
---|
| 400 | xReadFlag( uiCode ); |
---|
| 401 | Bool b = (uiCode != 0); |
---|
| 402 | rpcSlice->setRounding(b); |
---|
| 403 | } |
---|
| 404 | #endif |
---|
| 405 | #else |
---|
| 406 | #if !HIGH_ACCURACY_BI |
---|
| 407 | if(!rpcSlice->isIntra()) |
---|
| 408 | { |
---|
| 409 | rpcSlice->setRounding(false); |
---|
| 410 | } |
---|
| 411 | #endif |
---|
| 412 | #endif |
---|
| 413 | |
---|
| 414 | xReadFlag ( uiCode); rpcSlice->setLoopFilterDisable(uiCode ? 1 : 0); |
---|
| 415 | |
---|
| 416 | if (!rpcSlice->isIntra()) |
---|
| 417 | { |
---|
| 418 | xReadCode (3, uiCode); rpcSlice->setNumRefIdx (REF_PIC_LIST_0, uiCode); |
---|
| 419 | } |
---|
| 420 | else |
---|
| 421 | { |
---|
| 422 | rpcSlice->setNumRefIdx(REF_PIC_LIST_0, 0); |
---|
| 423 | } |
---|
| 424 | if (rpcSlice->isInterB()) |
---|
| 425 | { |
---|
| 426 | xReadCode (3, uiCode); rpcSlice->setNumRefIdx (REF_PIC_LIST_1, uiCode); |
---|
| 427 | } |
---|
| 428 | else |
---|
| 429 | { |
---|
| 430 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | if (!rpcSlice->isIntra()) |
---|
| 434 | { |
---|
| 435 | for(Int i = 0; i<rpcSlice->getNumRefIdx(REF_PIC_LIST_0);i++) |
---|
| 436 | { |
---|
| 437 | xReadFlag( uiCode ) ; |
---|
| 438 | if( uiCode ) // interview |
---|
| 439 | { |
---|
| 440 | xReadUvlc( uiCode ) ; |
---|
| 441 | rpcSlice->setRefViewIdx(uiCode, REF_PIC_LIST_0, i) ; |
---|
| 442 | rpcSlice->setRefPOC(rpcSlice->getPOC(), REF_PIC_LIST_0, i) ; |
---|
| 443 | } |
---|
| 444 | else |
---|
| 445 | { |
---|
| 446 | xReadSvlc( iCode ) ; |
---|
| 447 | rpcSlice->setRefPOC(rpcSlice->getPOC()-iCode, REF_PIC_LIST_0, i) ; |
---|
| 448 | rpcSlice->setRefViewIdx(rpcSlice->getViewIdx(), REF_PIC_LIST_0, i) ; |
---|
| 449 | } |
---|
| 450 | } |
---|
| 451 | } |
---|
| 452 | else |
---|
| 453 | { |
---|
| 454 | rpcSlice->setNumRefIdx(REF_PIC_LIST_0, 0); |
---|
| 455 | } |
---|
| 456 | if( rpcSlice->isInterB()) |
---|
| 457 | { |
---|
| 458 | for(Int i = 0; i<rpcSlice->getNumRefIdx(REF_PIC_LIST_1);i++) |
---|
| 459 | { |
---|
| 460 | xReadFlag( uiCode ) ; |
---|
| 461 | if( uiCode ) // interview |
---|
| 462 | { |
---|
| 463 | xReadUvlc( uiCode ) ; |
---|
| 464 | rpcSlice->setRefViewIdx(uiCode, REF_PIC_LIST_1, i) ; |
---|
| 465 | rpcSlice->setRefPOC(rpcSlice->getPOC(), REF_PIC_LIST_1, i) ; |
---|
| 466 | } |
---|
| 467 | else |
---|
| 468 | { |
---|
| 469 | xReadSvlc( iCode ) ; |
---|
| 470 | rpcSlice->setRefPOC(rpcSlice->getPOC()-iCode, REF_PIC_LIST_1, i) ; |
---|
| 471 | rpcSlice->setRefViewIdx(rpcSlice->getViewIdx(), REF_PIC_LIST_1, i) ; |
---|
| 472 | } |
---|
| 473 | } |
---|
| 474 | } |
---|
| 475 | else |
---|
| 476 | { |
---|
| 477 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | #if DCM_COMB_LIST |
---|
| 481 | if (rpcSlice->isInterB()) |
---|
| 482 | { |
---|
| 483 | xReadFlag (uiCode); rpcSlice->setRefPicListCombinationFlag(uiCode ? 1 : 0); |
---|
| 484 | if(uiCode) |
---|
| 485 | { |
---|
| 486 | xReadUvlc(uiCode); rpcSlice->setNumRefIdx (REF_PIC_LIST_C, uiCode+1); |
---|
| 487 | |
---|
| 488 | xReadFlag (uiCode); rpcSlice->setRefPicListModificationFlagLC(uiCode ? 1 : 0); |
---|
| 489 | if(uiCode) |
---|
| 490 | { |
---|
| 491 | for (UInt i=0;i<rpcSlice->getNumRefIdx(REF_PIC_LIST_C);i++) |
---|
| 492 | { |
---|
| 493 | xReadFlag(uiCode); |
---|
| 494 | rpcSlice->setListIdFromIdxOfLC(i, uiCode); |
---|
| 495 | xReadUvlc(uiCode); |
---|
| 496 | rpcSlice->setRefIdxFromIdxOfLC(i, uiCode); |
---|
| 497 | rpcSlice->setRefIdxOfLC((RefPicList)rpcSlice->getListIdFromIdxOfLC(i), rpcSlice->getRefIdxFromIdxOfLC(i), i); |
---|
| 498 | } |
---|
| 499 | } |
---|
| 500 | } |
---|
| 501 | else |
---|
| 502 | { |
---|
| 503 | rpcSlice->setRefPicListCombinationFlag(false); |
---|
| 504 | rpcSlice->setRefPicListModificationFlagLC(false); |
---|
| 505 | rpcSlice->setNumRefIdx(REF_PIC_LIST_C, -1); |
---|
| 506 | } |
---|
| 507 | } |
---|
| 508 | #endif |
---|
| 509 | |
---|
| 510 | #if AMVP_NEIGH_COL |
---|
| 511 | if ( rpcSlice->getSliceType() == B_SLICE ) |
---|
| 512 | { |
---|
| 513 | xReadFlag (uiCode); |
---|
| 514 | rpcSlice->setColDir(uiCode); |
---|
| 515 | } |
---|
| 516 | #endif |
---|
| 517 | |
---|
| 518 | #ifdef WEIGHT_PRED |
---|
| 519 | if ( (rpcSlice->getPPS()->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (rpcSlice->getPPS()->getWPBiPredIdc() && rpcSlice->getSliceType()==B_SLICE) ) |
---|
| 520 | { |
---|
| 521 | parseWeightPredTable(rpcSlice); |
---|
| 522 | rpcSlice->initWpScaling(); |
---|
| 523 | rpcSlice->displayWpScaling(); |
---|
| 524 | } |
---|
| 525 | #endif |
---|
| 526 | if( rpcSlice->getPPS()->getPPSId() != rpcSlice->getPPSId() ) |
---|
| 527 | { |
---|
| 528 | return; |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | |
---|
| 532 | if( rpcSlice->getSPS()->hasCamParInSliceHeader() ) |
---|
| 533 | { |
---|
| 534 | UInt uiViewId = rpcSlice->getSPS()->getViewId(); |
---|
| 535 | for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ ) |
---|
| 536 | { |
---|
| 537 | xReadSvlc( iCode ); m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode; |
---|
| 538 | xReadSvlc( iCode ); m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode; |
---|
| 539 | xReadSvlc( iCode ); m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ]; |
---|
| 540 | xReadSvlc( iCode ); m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ]; |
---|
| 541 | } |
---|
| 542 | rpcSlice->initMultiviewSlice( m_aaiTempScale, m_aaiTempOffset ); |
---|
| 543 | } |
---|
| 544 | } |
---|
| 545 | return; |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | Void TDecCavlc::resetEntropy (TComSlice* pcSlice) |
---|
| 549 | { |
---|
| 550 | m_bRunLengthCoding = ! pcSlice->isIntra(); |
---|
| 551 | m_uiRun = 0; |
---|
| 552 | |
---|
| 553 | #if !CAVLC_COEF_LRG_BLK |
---|
| 554 | ::memcpy(m_uiLPTableD8, g_auiLPTableD8, 10*128*sizeof(UInt)); |
---|
| 555 | #endif |
---|
| 556 | ::memcpy(m_uiLPTableD4, g_auiLPTableD4, 3*32*sizeof(UInt)); |
---|
| 557 | ::memcpy(m_uiLastPosVlcIndex, g_auiLastPosVlcIndex, 10*sizeof(UInt)); |
---|
| 558 | |
---|
| 559 | #if CAVLC_RQT_CBP |
---|
| 560 | ::memcpy(m_uiCBP_YUV_TableD, g_auiCBP_YUV_TableD, 4*8*sizeof(UInt)); |
---|
| 561 | ::memcpy(m_uiCBP_YS_TableD, g_auiCBP_YS_TableD, 2*4*sizeof(UInt)); |
---|
| 562 | ::memcpy(m_uiCBP_YCS_TableD, g_auiCBP_YCS_TableD, 2*8*sizeof(UInt)); |
---|
| 563 | ::memcpy(m_uiCBP_4Y_TableD, g_auiCBP_4Y_TableD, 2*15*sizeof(UInt)); |
---|
| 564 | m_uiCBP_4Y_VlcIdx = 0; |
---|
| 565 | #else |
---|
| 566 | m_uiCbpVlcIdx[0] = 0; |
---|
| 567 | m_uiCbpVlcIdx[1] = 0; |
---|
| 568 | ::memcpy(m_uiCBPTableD, g_auiCBPTableD, 2*8*sizeof(UInt)); |
---|
| 569 | ::memcpy(m_uiBlkCBPTableD, g_auiBlkCBPTableD, 2*15*sizeof(UInt)); |
---|
| 570 | m_uiBlkCbpVlcIdx = 0; |
---|
| 571 | #endif |
---|
| 572 | |
---|
| 573 | #if UNIFY_INTER_TABLE |
---|
| 574 | ::memcpy(m_uiMI1TableD, g_auiComMI1TableD, 9*sizeof(UInt)); |
---|
| 575 | #else |
---|
| 576 | ::memcpy(m_uiMI1TableD, g_auiMI1TableD, 8*sizeof(UInt)); |
---|
| 577 | ::memcpy(m_uiMI2TableD, g_auiMI2TableD, 15*sizeof(UInt)); |
---|
| 578 | |
---|
| 579 | #if DCM_COMB_LIST |
---|
| 580 | if ( pcSlice->getNoBackPredFlag() || pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
| 581 | #else |
---|
| 582 | if ( pcSlice->getNoBackPredFlag() ) |
---|
| 583 | #endif |
---|
| 584 | { |
---|
| 585 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDNoL1, 8*sizeof(UInt)); |
---|
| 586 | ::memcpy(m_uiMI2TableD, g_auiMI2TableDNoL1, 15*sizeof(UInt)); |
---|
| 587 | } |
---|
| 588 | |
---|
| 589 | #if MS_LCEC_ONE_FRAME |
---|
| 590 | if ( pcSlice->getNumRefIdx(REF_PIC_LIST_0) <= 1 && pcSlice->getNumRefIdx(REF_PIC_LIST_1) <= 1 ) |
---|
| 591 | { |
---|
| 592 | if ( pcSlice->getNoBackPredFlag() || ( pcSlice->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcSlice->getNumRefIdx(REF_PIC_LIST_C) <= 1 ) ) |
---|
| 593 | { |
---|
| 594 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDOnly1RefNoL1, 8*sizeof(UInt)); |
---|
| 595 | } |
---|
| 596 | else |
---|
| 597 | { |
---|
| 598 | ::memcpy(m_uiMI1TableD, g_auiMI1TableDOnly1Ref, 8*sizeof(UInt)); |
---|
| 599 | } |
---|
| 600 | } |
---|
| 601 | #endif |
---|
| 602 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
| 603 | if (pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
| 604 | { |
---|
| 605 | m_uiMI1TableD[8] = 8; |
---|
| 606 | } |
---|
| 607 | else // GPB case |
---|
| 608 | { |
---|
| 609 | m_uiMI1TableD[8] = m_uiMI1TableD[6]; |
---|
| 610 | m_uiMI1TableD[6] = 8; |
---|
| 611 | } |
---|
| 612 | #endif |
---|
| 613 | #endif |
---|
| 614 | |
---|
| 615 | #if LCEC_INTRA_MODE |
---|
| 616 | #if MTK_DCM_MPM |
---|
| 617 | ::memcpy(m_uiIntraModeTableD17[0], g_auiIntraModeTableD17[0], 16*sizeof(UInt)); |
---|
| 618 | ::memcpy(m_uiIntraModeTableD34[0], g_auiIntraModeTableD34[0], 33*sizeof(UInt)); |
---|
| 619 | ::memcpy(m_uiIntraModeTableD17[1], g_auiIntraModeTableD17[1], 16*sizeof(UInt)); |
---|
| 620 | ::memcpy(m_uiIntraModeTableD34[1], g_auiIntraModeTableD34[1], 33*sizeof(UInt)); |
---|
| 621 | #else |
---|
| 622 | ::memcpy(m_uiIntraModeTableD17, g_auiIntraModeTableD17, 16*sizeof(UInt)); |
---|
| 623 | ::memcpy(m_uiIntraModeTableD34, g_auiIntraModeTableD34, 33*sizeof(UInt)); |
---|
| 624 | #endif |
---|
| 625 | #endif |
---|
| 626 | #if QC_LCEC_INTER_MODE |
---|
| 627 | ::memcpy(m_uiSplitTableD, g_auiInterModeTableD, 4*7*sizeof(UInt)); |
---|
| 628 | #endif |
---|
| 629 | m_uiMITableVlcIdx = 0; |
---|
| 630 | |
---|
| 631 | #if CAVLC_COUNTER_ADAPT |
---|
| 632 | #if CAVLC_RQT_CBP |
---|
| 633 | ::memset(m_ucCBP_YUV_TableCounter, 0, 4*4*sizeof(UChar)); |
---|
| 634 | ::memset(m_ucCBP_4Y_TableCounter, 0, 2*2*sizeof(UChar)); |
---|
| 635 | ::memset(m_ucCBP_YCS_TableCounter, 0, 2*4*sizeof(UChar)); |
---|
| 636 | ::memset(m_ucCBP_YS_TableCounter, 0, 2*3*sizeof(UChar)); |
---|
| 637 | #else |
---|
| 638 | ::memset(m_ucCBFTableCounter, 0, 2*4*sizeof(UChar)); |
---|
| 639 | ::memset(m_ucBlkCBPTableCounter, 0, 2*2*sizeof(UChar)); |
---|
| 640 | #endif |
---|
| 641 | |
---|
| 642 | ::memset(m_ucMI1TableCounter, 0, 4*sizeof(UChar)); |
---|
| 643 | ::memset(m_ucSplitTableCounter, 0, 4*4*sizeof(UChar)); |
---|
| 644 | |
---|
| 645 | #if CAVLC_RQT_CBP |
---|
| 646 | m_ucCBP_YUV_TableCounterSum[0] = m_ucCBP_YUV_TableCounterSum[1] = m_ucCBP_YUV_TableCounterSum[2] = m_ucCBP_YUV_TableCounterSum[3] = 0; |
---|
| 647 | m_ucCBP_4Y_TableCounterSum[0] = m_ucCBP_4Y_TableCounterSum[1] = 0; |
---|
| 648 | m_ucCBP_YCS_TableCounterSum[0] = m_ucCBP_YCS_TableCounterSum[1] = 0; |
---|
| 649 | m_ucCBP_YS_TableCounterSum[0] = m_ucCBP_YS_TableCounterSum[1] = 0; |
---|
| 650 | #else |
---|
| 651 | m_ucCBFTableCounterSum[0] = m_ucCBFTableCounterSum[1] = 0; |
---|
| 652 | m_ucBlkCBPTableCounterSum[0] = m_ucBlkCBPTableCounterSum[1] = 0; |
---|
| 653 | #endif |
---|
| 654 | |
---|
| 655 | m_ucSplitTableCounterSum[0] = m_ucSplitTableCounterSum[1] = m_ucSplitTableCounterSum[2]= m_ucSplitTableCounterSum[3] = 0; |
---|
| 656 | m_ucMI1TableCounterSum = 0; |
---|
| 657 | #endif |
---|
| 658 | } |
---|
| 659 | |
---|
| 660 | Void TDecCavlc::parseTerminatingBit( UInt& ruiBit ) |
---|
| 661 | { |
---|
| 662 | ruiBit = false; |
---|
| 663 | Int iBitsLeft = m_pcBitstream->getBitsLeft(); |
---|
| 664 | if(iBitsLeft <= 8) |
---|
| 665 | { |
---|
| 666 | UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft); |
---|
| 667 | if (uiPeekValue == (1<<(iBitsLeft-1))) |
---|
| 668 | ruiBit = true; |
---|
| 669 | } |
---|
| 670 | } |
---|
| 671 | |
---|
| 672 | Void TDecCavlc::parseAlfCtrlDepth ( UInt& ruiAlfCtrlDepth ) |
---|
| 673 | { |
---|
| 674 | UInt uiSymbol; |
---|
| 675 | xReadUnaryMaxSymbol(uiSymbol, g_uiMaxCUDepth-1); |
---|
| 676 | ruiAlfCtrlDepth = uiSymbol; |
---|
| 677 | } |
---|
| 678 | |
---|
| 679 | Void TDecCavlc::parseAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 680 | { |
---|
| 681 | if (!m_bAlfCtrl) |
---|
| 682 | return; |
---|
| 683 | |
---|
| 684 | if( uiDepth > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth)) |
---|
| 685 | { |
---|
| 686 | return; |
---|
| 687 | } |
---|
| 688 | |
---|
| 689 | UInt uiSymbol; |
---|
| 690 | xReadFlag( uiSymbol ); |
---|
| 691 | |
---|
| 692 | if (uiDepth > m_uiMaxAlfCtrlDepth) |
---|
| 693 | { |
---|
| 694 | pcCU->setAlfCtrlFlagSubParts( uiSymbol, uiAbsPartIdx, m_uiMaxAlfCtrlDepth); |
---|
| 695 | } |
---|
| 696 | else |
---|
| 697 | { |
---|
| 698 | pcCU->setAlfCtrlFlagSubParts( uiSymbol, uiAbsPartIdx, uiDepth ); |
---|
| 699 | } |
---|
| 700 | } |
---|
| 701 | |
---|
| 702 | Void TDecCavlc::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 703 | { |
---|
| 704 | #if QC_LCEC_INTER_MODE |
---|
| 705 | return; |
---|
| 706 | #else |
---|
| 707 | |
---|
| 708 | if( pcCU->getSlice()->isIntra() ) |
---|
| 709 | { |
---|
| 710 | return; |
---|
| 711 | } |
---|
| 712 | |
---|
| 713 | UInt uiSymbol = 0; |
---|
| 714 | xReadFlag( uiSymbol ); |
---|
| 715 | |
---|
| 716 | if( uiSymbol ) |
---|
| 717 | { |
---|
| 718 | pcCU->setPredModeSubParts( MODE_SKIP, uiAbsPartIdx, uiDepth ); |
---|
| 719 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
| 720 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 721 | #if HHI_MRG_SKIP |
---|
| 722 | pcCU->setMergeFlagSubParts( true , uiAbsPartIdx, 0, uiDepth ); |
---|
| 723 | #else |
---|
| 724 | TComMv cZeroMv(0,0); |
---|
| 725 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvd ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
| 726 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvd ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
| 727 | |
---|
| 728 | pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth ); |
---|
| 729 | pcCU->setCbfSubParts ( 0, 0, 0, uiAbsPartIdx, uiDepth ); |
---|
| 730 | |
---|
| 731 | if ( pcCU->getSlice()->isInterP() ) |
---|
| 732 | { |
---|
| 733 | pcCU->setInterDirSubParts( 1, uiAbsPartIdx, 0, uiDepth ); |
---|
| 734 | |
---|
| 735 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
| 736 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
| 737 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
| 738 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( NOT_VALID, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
| 739 | } |
---|
| 740 | else |
---|
| 741 | { |
---|
| 742 | pcCU->setInterDirSubParts( 3, uiAbsPartIdx, 0, uiDepth ); |
---|
| 743 | |
---|
| 744 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
| 745 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
| 746 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
| 747 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
| 748 | } |
---|
| 749 | } |
---|
| 750 | #endif // HHI_MRG_SKIP |
---|
| 751 | #endif // QC_LCEC_INTER_MODE |
---|
| 752 | } |
---|
| 753 | |
---|
| 754 | /** parse the motion vector predictor index |
---|
| 755 | * \param pcCU |
---|
| 756 | * \param riMVPIdx |
---|
| 757 | * \param iMVPNum |
---|
| 758 | * \param uiAbsPartIdx |
---|
| 759 | * \param uiDepth |
---|
| 760 | * \param eRefList |
---|
| 761 | * \returns Void |
---|
| 762 | */ |
---|
| 763 | Void TDecCavlc::parseMVPIdx( TComDataCU* pcCU, Int& riMVPIdx, Int iMVPNum, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
| 764 | { |
---|
| 765 | UInt uiSymbol; |
---|
| 766 | xReadUnaryMaxSymbol(uiSymbol, iMVPNum-1); |
---|
| 767 | riMVPIdx = uiSymbol; |
---|
| 768 | } |
---|
| 769 | |
---|
| 770 | Void TDecCavlc::parseViewIdx(Int& riViewIdx) |
---|
| 771 | { |
---|
| 772 | UInt uiSymbol; |
---|
| 773 | xReadUnaryMaxSymbol(uiSymbol, MAX_NUMBER_VIEWS); |
---|
| 774 | riViewIdx = uiSymbol; |
---|
| 775 | } |
---|
| 776 | |
---|
| 777 | #if QC_LCEC_INTER_MODE |
---|
| 778 | /** parse the split flag |
---|
| 779 | * \param pcCU |
---|
| 780 | * \param uiAbsPartIdx |
---|
| 781 | * \param uiDepth |
---|
| 782 | * \returns Void |
---|
| 783 | */ |
---|
| 784 | Void TDecCavlc::parseSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 785 | { |
---|
| 786 | if (pcCU->getSlice()->isIntra()) |
---|
| 787 | { |
---|
| 788 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 789 | { |
---|
| 790 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
| 791 | return ; |
---|
| 792 | } |
---|
| 793 | |
---|
| 794 | UInt uiSymbol; |
---|
| 795 | xReadFlag( uiSymbol ); |
---|
| 796 | pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx ); |
---|
| 797 | |
---|
| 798 | return ; |
---|
| 799 | } |
---|
| 800 | UInt tmp=0; |
---|
| 801 | UInt cx=0; |
---|
| 802 | UInt uiMode ; |
---|
| 803 | { |
---|
| 804 | UInt iMaxLen= (uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth)?5:6; |
---|
| 805 | while (tmp==0 && cx<iMaxLen) |
---|
| 806 | { |
---|
| 807 | xReadFlag( tmp ); |
---|
| 808 | cx++; |
---|
| 809 | }; |
---|
| 810 | if(tmp!=0) |
---|
| 811 | cx--; |
---|
| 812 | |
---|
| 813 | UInt uiDepthRemember = uiDepth; |
---|
| 814 | if ( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 815 | { |
---|
| 816 | uiDepth = 3; |
---|
| 817 | } |
---|
| 818 | UInt x = m_uiSplitTableD[uiDepth][cx]; |
---|
| 819 | /* Adapt table */ |
---|
| 820 | uiMode = x; |
---|
| 821 | #if CAVLC_COUNTER_ADAPT |
---|
| 822 | adaptCodeword(cx, m_ucSplitTableCounter[uiDepth], m_ucSplitTableCounterSum[uiDepth], m_uiSplitTableD[uiDepth], NULL, 4 ); |
---|
| 823 | #else |
---|
| 824 | if (cx>0) |
---|
| 825 | { |
---|
| 826 | UInt cy = Max(0,cx-1); |
---|
| 827 | UInt y = m_uiSplitTableD[uiDepth][cy]; |
---|
| 828 | m_uiSplitTableD[uiDepth][cy] = x; |
---|
| 829 | m_uiSplitTableD[uiDepth][cx] = y; |
---|
| 830 | } |
---|
| 831 | #endif |
---|
| 832 | uiDepth = uiDepthRemember; |
---|
| 833 | } |
---|
| 834 | if (uiMode==0) |
---|
| 835 | { |
---|
| 836 | pcCU->setDepthSubParts( uiDepth + 1, uiAbsPartIdx ); |
---|
| 837 | } |
---|
| 838 | else |
---|
| 839 | { |
---|
| 840 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
| 841 | pcCU->setMergeFlagSubParts(false, uiAbsPartIdx,0, uiDepth ); |
---|
| 842 | pcCU->setDepthSubParts( uiDepth , uiAbsPartIdx ); |
---|
| 843 | if (uiMode ==1) |
---|
| 844 | { |
---|
| 845 | TComMv cZeroMv(0,0); |
---|
| 846 | pcCU->setPredModeSubParts( MODE_SKIP, uiAbsPartIdx, uiDepth ); |
---|
| 847 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
| 848 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 849 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvd ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
| 850 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvd ( cZeroMv, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
| 851 | pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth ); |
---|
| 852 | pcCU->setCbfSubParts ( 0, 0, 0, uiAbsPartIdx, uiDepth ); |
---|
| 853 | |
---|
| 854 | #if HHI_MRG_SKIP |
---|
| 855 | pcCU->setMergeFlagSubParts( true, uiAbsPartIdx, 0, uiDepth ); |
---|
| 856 | #else |
---|
| 857 | if ( pcCU->getSlice()->isInterP() ) |
---|
| 858 | { |
---|
| 859 | pcCU->setInterDirSubParts( 1, uiAbsPartIdx, 0, uiDepth ); |
---|
| 860 | |
---|
| 861 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
| 862 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
| 863 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
| 864 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( NOT_VALID, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
| 865 | } |
---|
| 866 | else |
---|
| 867 | { |
---|
| 868 | pcCU->setInterDirSubParts( 3, uiAbsPartIdx, 0, uiDepth ); |
---|
| 869 | |
---|
| 870 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
| 871 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
| 872 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
| 873 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( 0, SIZE_2Nx2N, uiAbsPartIdx, 0, uiDepth ); |
---|
| 874 | } |
---|
| 875 | #endif |
---|
| 876 | } |
---|
| 877 | else if (uiMode==2) |
---|
| 878 | { |
---|
| 879 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
| 880 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
| 881 | pcCU->setMergeFlagSubParts(true, uiAbsPartIdx,0, uiDepth ); |
---|
| 882 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 883 | } |
---|
| 884 | else if (uiMode==6) |
---|
| 885 | { |
---|
| 886 | #if MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT |
---|
| 887 | if (uiDepth != g_uiMaxCUDepth - g_uiAddCUDepth) |
---|
| 888 | { |
---|
| 889 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
| 890 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth ); |
---|
| 891 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 892 | UInt uiTrLevel = 0; |
---|
| 893 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2; |
---|
| 894 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2; |
---|
| 895 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
| 896 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
| 897 | } |
---|
| 898 | else |
---|
| 899 | #endif |
---|
| 900 | { |
---|
| 901 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
| 902 | pcCU->setPartSizeSubParts( SIZE_NxN, uiAbsPartIdx, uiDepth ); |
---|
| 903 | } |
---|
| 904 | } |
---|
| 905 | else |
---|
| 906 | { |
---|
| 907 | pcCU->setPredModeSubParts( MODE_INTER, uiAbsPartIdx, uiDepth ); |
---|
| 908 | pcCU->setPartSizeSubParts( PartSize(uiMode-3), uiAbsPartIdx, uiDepth ); |
---|
| 909 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 910 | } |
---|
| 911 | } |
---|
| 912 | } |
---|
| 913 | #else |
---|
| 914 | Void TDecCavlc::parseSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 915 | { |
---|
| 916 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 917 | { |
---|
| 918 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
| 919 | return ; |
---|
| 920 | } |
---|
| 921 | |
---|
| 922 | UInt uiSymbol; |
---|
| 923 | xReadFlag( uiSymbol ); |
---|
| 924 | pcCU->setDepthSubParts( uiDepth + uiSymbol, uiAbsPartIdx ); |
---|
| 925 | |
---|
| 926 | return ; |
---|
| 927 | } |
---|
| 928 | #endif |
---|
| 929 | |
---|
| 930 | #if QC_LCEC_INTER_MODE |
---|
| 931 | |
---|
| 932 | /** parse partition size |
---|
| 933 | * \param pcCU |
---|
| 934 | * \param uiAbsPartIdx |
---|
| 935 | * \param uiDepth |
---|
| 936 | * \returns Void |
---|
| 937 | */ |
---|
| 938 | Void TDecCavlc::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 939 | { |
---|
| 940 | UInt uiMode=0; |
---|
| 941 | if ( pcCU->getSlice()->isIntra()&& pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 942 | { |
---|
| 943 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
| 944 | uiMode = 1; |
---|
| 945 | if ( uiDepth == (g_uiMaxCUDepth - g_uiAddCUDepth )) |
---|
| 946 | #endif |
---|
| 947 | { |
---|
| 948 | UInt uiSymbol; |
---|
| 949 | xReadFlag( uiSymbol ); |
---|
| 950 | uiMode = uiSymbol ? 1 : 2; |
---|
| 951 | } |
---|
| 952 | } |
---|
| 953 | #if MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT |
---|
| 954 | else if (uiDepth != (g_uiMaxCUDepth - g_uiAddCUDepth ) || pcCU->getPartitionSize(uiAbsPartIdx ) != SIZE_NxN) |
---|
| 955 | #else |
---|
| 956 | else if (pcCU->getPartitionSize(uiAbsPartIdx ) != SIZE_NxN) |
---|
| 957 | #endif |
---|
| 958 | { |
---|
| 959 | return; |
---|
| 960 | } |
---|
| 961 | else |
---|
| 962 | { |
---|
| 963 | UInt uiSymbol; |
---|
| 964 | xReadFlag( uiSymbol ); |
---|
| 965 | if(uiSymbol) |
---|
| 966 | { |
---|
| 967 | uiMode = 1; |
---|
| 968 | } |
---|
| 969 | else |
---|
| 970 | { |
---|
| 971 | #if (MTK_DISABLE_INTRA_NxN_SPLIT && !HHI_DISABLE_INTER_NxN_SPLIT) || (!MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT ) |
---|
| 972 | if ( uiDepth != (g_uiMaxCUDepth - g_uiAddCUDepth )) |
---|
| 973 | { |
---|
| 974 | #if MTK_DISABLE_INTRA_NxN_SPLIT && !HHI_DISABLE_INTER_NxN_SPLIT |
---|
| 975 | uiMode = 0; |
---|
| 976 | #elif !MTK_DISABLE_INTRA_NxN_SPLIT && HHI_DISABLE_INTER_NxN_SPLIT |
---|
| 977 | uiMode = 2; |
---|
| 978 | #endif |
---|
| 979 | } |
---|
| 980 | else |
---|
| 981 | #endif |
---|
| 982 | { |
---|
| 983 | xReadFlag( uiSymbol ); |
---|
| 984 | uiMode = uiSymbol ? 2 : 0; |
---|
| 985 | } |
---|
| 986 | } |
---|
| 987 | } |
---|
| 988 | PartSize ePartSize; |
---|
| 989 | PredMode eMode; |
---|
| 990 | if (uiMode > 0) |
---|
| 991 | { |
---|
| 992 | eMode = MODE_INTRA; |
---|
| 993 | ePartSize = (uiMode==1) ? SIZE_2Nx2N:SIZE_NxN; |
---|
| 994 | } |
---|
| 995 | else |
---|
| 996 | { |
---|
| 997 | eMode = MODE_INTER; |
---|
| 998 | ePartSize = SIZE_NxN; |
---|
| 999 | } |
---|
| 1000 | pcCU->setPredModeSubParts( eMode , uiAbsPartIdx, uiDepth ); |
---|
| 1001 | pcCU->setPartSizeSubParts( ePartSize, uiAbsPartIdx, uiDepth ); |
---|
| 1002 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 1003 | |
---|
| 1004 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA ) |
---|
| 1005 | { |
---|
| 1006 | UInt uiTrLevel = 0; |
---|
| 1007 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)] + 2; |
---|
| 1008 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()] + 2; |
---|
| 1009 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
| 1010 | if( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) |
---|
| 1011 | { |
---|
| 1012 | pcCU->setTrIdxSubParts( 1 + uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
| 1013 | } |
---|
| 1014 | else |
---|
| 1015 | { |
---|
| 1016 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
| 1017 | } |
---|
| 1018 | } |
---|
| 1019 | } |
---|
| 1020 | #else |
---|
| 1021 | Void TDecCavlc::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1022 | { |
---|
| 1023 | UInt uiSymbol, uiMode = 0; |
---|
| 1024 | PartSize eMode; |
---|
| 1025 | |
---|
| 1026 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 1027 | { |
---|
| 1028 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
| 1029 | eMode = SIZE_2Nx2N; |
---|
| 1030 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 1031 | #endif |
---|
| 1032 | { |
---|
| 1033 | xReadFlag( uiSymbol ); |
---|
| 1034 | eMode = uiSymbol ? SIZE_2Nx2N : SIZE_NxN; |
---|
| 1035 | } |
---|
| 1036 | } |
---|
| 1037 | else |
---|
| 1038 | { |
---|
| 1039 | #if HHI_RMP_SWITCH |
---|
| 1040 | if ( !pcCU->getSlice()->getSPS()->getUseRMP()) |
---|
| 1041 | { |
---|
| 1042 | xReadFlag( uiSymbol ); |
---|
| 1043 | if( uiSymbol ) |
---|
| 1044 | uiMode = 0; |
---|
| 1045 | else |
---|
| 1046 | uiMode = 3; |
---|
| 1047 | } |
---|
| 1048 | else |
---|
| 1049 | #endif |
---|
| 1050 | { |
---|
| 1051 | UInt uiMaxNumBits = 3; |
---|
| 1052 | for ( UInt ui = 0; ui < uiMaxNumBits; ui++ ) |
---|
| 1053 | { |
---|
| 1054 | xReadFlag( uiSymbol ); |
---|
| 1055 | if ( uiSymbol ) |
---|
| 1056 | { |
---|
| 1057 | break; |
---|
| 1058 | } |
---|
| 1059 | uiMode++; |
---|
| 1060 | } |
---|
| 1061 | } |
---|
| 1062 | eMode = (PartSize) uiMode; |
---|
| 1063 | |
---|
| 1064 | if (pcCU->getSlice()->isInterB() && uiMode == 3) |
---|
| 1065 | { |
---|
| 1066 | #if HHI_DISABLE_INTER_NxN_SPLIT |
---|
| 1067 | uiSymbol = 0; |
---|
| 1068 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 1069 | #endif |
---|
| 1070 | { |
---|
| 1071 | xReadFlag( uiSymbol ); |
---|
| 1072 | } |
---|
| 1073 | |
---|
| 1074 | if (uiSymbol == 0) |
---|
| 1075 | { |
---|
| 1076 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
| 1077 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
| 1078 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 1079 | #endif |
---|
| 1080 | { |
---|
| 1081 | xReadFlag( uiSymbol ); |
---|
| 1082 | } |
---|
| 1083 | if (uiSymbol == 0) |
---|
| 1084 | eMode = SIZE_2Nx2N; |
---|
| 1085 | } |
---|
| 1086 | } |
---|
| 1087 | |
---|
| 1088 | } |
---|
| 1089 | |
---|
| 1090 | pcCU->setPartSizeSubParts( eMode, uiAbsPartIdx, uiDepth ); |
---|
| 1091 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 1092 | |
---|
| 1093 | UInt uiTrLevel = 0; |
---|
| 1094 | |
---|
| 1095 | UInt uiWidthInBit = g_aucConvertToBit[pcCU->getWidth(uiAbsPartIdx)]+2; |
---|
| 1096 | UInt uiTrSizeInBit = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxTrSize()]+2; |
---|
| 1097 | uiTrLevel = uiWidthInBit >= uiTrSizeInBit ? uiWidthInBit - uiTrSizeInBit : 0; |
---|
| 1098 | |
---|
| 1099 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA ) |
---|
| 1100 | { |
---|
| 1101 | if( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) |
---|
| 1102 | { |
---|
| 1103 | pcCU->setTrIdxSubParts( 1+uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
| 1104 | } |
---|
| 1105 | else |
---|
| 1106 | { |
---|
| 1107 | pcCU->setTrIdxSubParts( uiTrLevel, uiAbsPartIdx, uiDepth ); |
---|
| 1108 | } |
---|
| 1109 | } |
---|
| 1110 | } |
---|
| 1111 | #endif |
---|
| 1112 | |
---|
| 1113 | /** parse prediction mode |
---|
| 1114 | * \param pcCU |
---|
| 1115 | * \param uiAbsPartIdx |
---|
| 1116 | * \param uiDepth |
---|
| 1117 | * \returns Void |
---|
| 1118 | */ |
---|
| 1119 | Void TDecCavlc::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1120 | { |
---|
| 1121 | if( pcCU->getSlice()->isIntra() ) |
---|
| 1122 | { |
---|
| 1123 | pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth ); |
---|
| 1124 | return ; |
---|
| 1125 | } |
---|
| 1126 | #if !QC_LCEC_INTER_MODE |
---|
| 1127 | UInt uiSymbol; |
---|
| 1128 | Int iPredMode = MODE_INTER; |
---|
| 1129 | |
---|
| 1130 | if ( pcCU->getSlice()->isInterB() ) |
---|
| 1131 | { |
---|
| 1132 | pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth ); |
---|
| 1133 | return; |
---|
| 1134 | } |
---|
| 1135 | xReadFlag( uiSymbol ); |
---|
| 1136 | iPredMode += uiSymbol; |
---|
| 1137 | |
---|
| 1138 | pcCU->setPredModeSubParts( (PredMode)iPredMode, uiAbsPartIdx, uiDepth ); |
---|
| 1139 | #endif |
---|
| 1140 | } |
---|
| 1141 | |
---|
| 1142 | #if LCEC_INTRA_MODE |
---|
| 1143 | #if MTK_DCM_MPM |
---|
| 1144 | Void TDecCavlc::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1145 | { |
---|
| 1146 | Int uiIPredMode = 0; |
---|
| 1147 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
| 1148 | |
---|
| 1149 | Int uiPreds[2] = {-1, -1}; |
---|
| 1150 | Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); |
---|
| 1151 | |
---|
| 1152 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 5 ) |
---|
| 1153 | { |
---|
| 1154 | UInt uiSymbol; |
---|
| 1155 | xReadFlag( uiSymbol ); |
---|
| 1156 | if ( uiSymbol ) |
---|
| 1157 | { |
---|
| 1158 | if(uiPredNum == 1) |
---|
| 1159 | { |
---|
| 1160 | uiIPredMode = uiPreds[0]; |
---|
| 1161 | } |
---|
| 1162 | else |
---|
| 1163 | { |
---|
| 1164 | xReadFlag( uiSymbol ); |
---|
| 1165 | uiIPredMode = uiPreds[uiSymbol]; |
---|
| 1166 | } |
---|
| 1167 | } |
---|
| 1168 | else |
---|
| 1169 | { |
---|
| 1170 | xReadFlag( uiSymbol ); uiIPredMode = uiSymbol; |
---|
| 1171 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; } |
---|
| 1172 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; } |
---|
| 1173 | |
---|
| 1174 | for(UInt i = 0; i < uiPredNum; i++) |
---|
| 1175 | { |
---|
| 1176 | if(uiIPredMode >= uiPreds[i]) { uiIPredMode ++;} |
---|
| 1177 | } |
---|
| 1178 | |
---|
| 1179 | } |
---|
| 1180 | } |
---|
| 1181 | else |
---|
| 1182 | { |
---|
| 1183 | Int iDir, iDirLarger, iRankIntraMode, iRankIntraModeLarger; |
---|
| 1184 | |
---|
| 1185 | const UInt *huff; |
---|
| 1186 | const UInt *lengthHuff; |
---|
| 1187 | UInt totMode; |
---|
| 1188 | UInt *m_uiIntraModeTableD; |
---|
| 1189 | |
---|
| 1190 | if ( g_aucIntraModeBitsAng[iIntraIdx] == 5 ) |
---|
| 1191 | { |
---|
| 1192 | totMode = (uiPredNum == 1)? 17: 16; |
---|
| 1193 | huff = huff17_2[uiPredNum - 1]; |
---|
| 1194 | lengthHuff = lengthHuff17_2[uiPredNum - 1]; |
---|
| 1195 | m_uiIntraModeTableD = m_uiIntraModeTableD17[uiPredNum - 1]; |
---|
| 1196 | } |
---|
| 1197 | else |
---|
| 1198 | { |
---|
| 1199 | totMode = (uiPredNum == 1)? 34: 33; |
---|
| 1200 | huff = huff34_2[uiPredNum - 1]; |
---|
| 1201 | lengthHuff = lengthHuff34_2[uiPredNum - 1]; |
---|
| 1202 | m_uiIntraModeTableD = m_uiIntraModeTableD34[uiPredNum - 1]; |
---|
| 1203 | } |
---|
| 1204 | |
---|
| 1205 | UInt uiCode; |
---|
| 1206 | UInt uiLength = lengthHuff[totMode - 1]; |
---|
| 1207 | |
---|
| 1208 | m_pcBitstream->pseudoRead(uiLength,uiCode); |
---|
| 1209 | if ((uiCode>>(uiLength- lengthHuff[0])) == huff[0]) |
---|
| 1210 | { |
---|
| 1211 | m_pcBitstream->read(lengthHuff[0],uiCode); |
---|
| 1212 | |
---|
| 1213 | if(uiPredNum == 1) |
---|
| 1214 | { |
---|
| 1215 | uiIPredMode = uiPreds[0]; |
---|
| 1216 | } |
---|
| 1217 | else if(uiPredNum == 2) |
---|
| 1218 | { |
---|
| 1219 | UInt uiPredIdx= 0; |
---|
| 1220 | xReadFlag( uiPredIdx ); |
---|
| 1221 | uiIPredMode = uiPreds[uiPredIdx]; |
---|
| 1222 | } |
---|
| 1223 | |
---|
| 1224 | } |
---|
| 1225 | else |
---|
| 1226 | { |
---|
| 1227 | iRankIntraMode = 0; |
---|
| 1228 | |
---|
| 1229 | for(Int i = 1; i < totMode; i++) |
---|
| 1230 | { |
---|
| 1231 | if( (uiCode>>(uiLength- lengthHuff[i])) == huff[i]) |
---|
| 1232 | { |
---|
| 1233 | m_pcBitstream->read(lengthHuff[i], uiCode); |
---|
| 1234 | iRankIntraMode = i; |
---|
| 1235 | break; |
---|
| 1236 | } |
---|
| 1237 | } |
---|
| 1238 | |
---|
| 1239 | iRankIntraMode --; |
---|
| 1240 | iDir = m_uiIntraModeTableD[iRankIntraMode]; |
---|
| 1241 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
| 1242 | iDirLarger = m_uiIntraModeTableD[iRankIntraModeLarger]; |
---|
| 1243 | m_uiIntraModeTableD[iRankIntraModeLarger] = iDir; |
---|
| 1244 | m_uiIntraModeTableD[iRankIntraMode] = iDirLarger; |
---|
| 1245 | |
---|
| 1246 | for(UInt i = 0; i < uiPredNum; i++) |
---|
| 1247 | { |
---|
| 1248 | if(iDir >= uiPreds[i]) |
---|
| 1249 | { |
---|
| 1250 | iDir ++; |
---|
| 1251 | } |
---|
| 1252 | } |
---|
| 1253 | |
---|
| 1254 | uiIPredMode = iDir; |
---|
| 1255 | |
---|
| 1256 | |
---|
| 1257 | } |
---|
| 1258 | } |
---|
| 1259 | #if ADD_PLANAR_MODE |
---|
| 1260 | if (uiIPredMode == 2) |
---|
| 1261 | { |
---|
| 1262 | UInt planarFlag; |
---|
| 1263 | xReadFlag( planarFlag ); |
---|
| 1264 | if ( planarFlag ) |
---|
| 1265 | { |
---|
| 1266 | uiIPredMode = PLANAR_IDX; |
---|
| 1267 | } |
---|
| 1268 | } |
---|
| 1269 | #endif |
---|
| 1270 | |
---|
| 1271 | pcCU->setLumaIntraDirSubParts( (UChar)uiIPredMode, uiAbsPartIdx, uiDepth ); |
---|
| 1272 | } |
---|
| 1273 | #else |
---|
| 1274 | Void TDecCavlc::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1275 | { |
---|
| 1276 | UInt uiSymbol; |
---|
| 1277 | Int uiIPredMode; |
---|
| 1278 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
| 1279 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
| 1280 | Int iDir, iDirLarger, iRankIntraMode, iRankIntraModeLarger; |
---|
| 1281 | |
---|
| 1282 | Int iLeft = pcCU->getLeftIntraDirLuma( uiAbsPartIdx ); |
---|
| 1283 | Int iAbove = pcCU->getAboveIntraDirLuma( uiAbsPartIdx ); |
---|
| 1284 | UInt ind=(iLeft==iAbove)? 0 : 1; |
---|
| 1285 | |
---|
| 1286 | const UInt *huff17=huff17_2[ind]; |
---|
| 1287 | const UInt *lengthHuff17=lengthHuff17_2[ind]; |
---|
| 1288 | const UInt *huff34=huff34_2[ind]; |
---|
| 1289 | const UInt *lengthHuff34=lengthHuff34_2[ind]; |
---|
| 1290 | |
---|
| 1291 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 5 ) |
---|
| 1292 | { |
---|
| 1293 | xReadFlag( uiSymbol ); |
---|
| 1294 | if ( uiSymbol ) |
---|
| 1295 | uiIPredMode = iMostProbable; |
---|
| 1296 | else |
---|
| 1297 | { |
---|
| 1298 | xReadFlag( uiSymbol ); uiIPredMode = uiSymbol; |
---|
| 1299 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; } |
---|
| 1300 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; } |
---|
| 1301 | if(uiIPredMode >= iMostProbable) |
---|
| 1302 | uiIPredMode ++; |
---|
| 1303 | } |
---|
| 1304 | } |
---|
| 1305 | else if ( g_aucIntraModeBitsAng[iIntraIdx] == 5 ) |
---|
| 1306 | { |
---|
| 1307 | UInt uiCode; |
---|
| 1308 | UInt uiLength = lengthHuff17[15]; |
---|
| 1309 | m_pcBitstream->pseudoRead(uiLength,uiCode); |
---|
| 1310 | if ((uiCode>>(uiLength- lengthHuff17[0])) == huff17[0]) |
---|
| 1311 | { |
---|
| 1312 | m_pcBitstream->read(lengthHuff17[0],uiCode); |
---|
| 1313 | uiIPredMode = iMostProbable; |
---|
| 1314 | } |
---|
| 1315 | else |
---|
| 1316 | { |
---|
| 1317 | iRankIntraMode = 0; |
---|
| 1318 | for (Int i=1;i<17;i++) |
---|
| 1319 | { |
---|
| 1320 | if( (uiCode>>(uiLength- lengthHuff17[i])) == huff17[i]) |
---|
| 1321 | { |
---|
| 1322 | m_pcBitstream->read(lengthHuff17[i], uiCode); |
---|
| 1323 | iRankIntraMode = i; |
---|
| 1324 | break; |
---|
| 1325 | } |
---|
| 1326 | } |
---|
| 1327 | |
---|
| 1328 | if ( iRankIntraMode > 0 ) |
---|
| 1329 | iRankIntraMode --; |
---|
| 1330 | iDir = m_uiIntraModeTableD17[iRankIntraMode]; |
---|
| 1331 | |
---|
| 1332 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
| 1333 | iDirLarger = m_uiIntraModeTableD17[iRankIntraModeLarger]; |
---|
| 1334 | |
---|
| 1335 | m_uiIntraModeTableD17[iRankIntraModeLarger] = iDir; |
---|
| 1336 | m_uiIntraModeTableD17[iRankIntraMode] = iDirLarger; |
---|
| 1337 | |
---|
| 1338 | uiIPredMode = (iDir>=iMostProbable? iDir+1: iDir); |
---|
| 1339 | } |
---|
| 1340 | } |
---|
| 1341 | else |
---|
| 1342 | { |
---|
| 1343 | UInt uiCode; |
---|
| 1344 | UInt uiLength = lengthHuff34[32]; |
---|
| 1345 | m_pcBitstream->pseudoRead(uiLength,uiCode); |
---|
| 1346 | if ((uiCode>>(uiLength- lengthHuff34[0])) == huff34[0]) |
---|
| 1347 | { |
---|
| 1348 | m_pcBitstream->read(lengthHuff34[0],uiCode); |
---|
| 1349 | uiIPredMode = iMostProbable; |
---|
| 1350 | } |
---|
| 1351 | else |
---|
| 1352 | { |
---|
| 1353 | iRankIntraMode = 0; |
---|
| 1354 | for (Int i=1;i<34;i++) |
---|
| 1355 | { |
---|
| 1356 | if( (uiCode>>(uiLength- lengthHuff34[i])) == huff34[i]) |
---|
| 1357 | { |
---|
| 1358 | m_pcBitstream->read(lengthHuff34[i], uiCode); |
---|
| 1359 | iRankIntraMode = i; |
---|
| 1360 | break; |
---|
| 1361 | } |
---|
| 1362 | } |
---|
| 1363 | |
---|
| 1364 | if ( iRankIntraMode > 0 ) |
---|
| 1365 | iRankIntraMode --; |
---|
| 1366 | iDir = m_uiIntraModeTableD34[iRankIntraMode]; |
---|
| 1367 | |
---|
| 1368 | iRankIntraModeLarger = Max(0,iRankIntraMode-1); |
---|
| 1369 | iDirLarger = m_uiIntraModeTableD34[iRankIntraModeLarger]; |
---|
| 1370 | |
---|
| 1371 | m_uiIntraModeTableD34[iRankIntraModeLarger] = iDir; |
---|
| 1372 | m_uiIntraModeTableD34[iRankIntraMode] = iDirLarger; |
---|
| 1373 | |
---|
| 1374 | uiIPredMode = (iDir>=iMostProbable? iDir+1: iDir); |
---|
| 1375 | } |
---|
| 1376 | } |
---|
| 1377 | |
---|
| 1378 | #if ADD_PLANAR_MODE |
---|
| 1379 | if (uiIPredMode == 2) |
---|
| 1380 | { |
---|
| 1381 | UInt planarFlag; |
---|
| 1382 | xReadFlag( planarFlag ); |
---|
| 1383 | if ( planarFlag ) |
---|
| 1384 | { |
---|
| 1385 | uiIPredMode = PLANAR_IDX; |
---|
| 1386 | } |
---|
| 1387 | } |
---|
| 1388 | #endif |
---|
| 1389 | pcCU->setLumaIntraDirSubParts( (UChar)uiIPredMode, uiAbsPartIdx, uiDepth ); |
---|
| 1390 | } |
---|
| 1391 | #endif |
---|
| 1392 | #else |
---|
| 1393 | Void TDecCavlc::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1394 | { |
---|
| 1395 | UInt uiSymbol; |
---|
| 1396 | Int uiIPredMode; |
---|
| 1397 | Int iMostProbable = pcCU->getMostProbableIntraDirLuma( uiAbsPartIdx ); |
---|
| 1398 | |
---|
| 1399 | xReadFlag( uiSymbol ); |
---|
| 1400 | |
---|
| 1401 | if ( uiSymbol ) |
---|
| 1402 | uiIPredMode = iMostProbable; |
---|
| 1403 | else |
---|
| 1404 | { |
---|
| 1405 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
| 1406 | if ( g_aucIntraModeBitsAng[iIntraIdx] < 6 ) |
---|
| 1407 | { |
---|
| 1408 | xReadFlag( uiSymbol ); uiIPredMode = uiSymbol; |
---|
| 1409 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 2 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; } |
---|
| 1410 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 3 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; } |
---|
| 1411 | if ( g_aucIntraModeBitsAng[iIntraIdx] > 4 ) { xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 3; } |
---|
| 1412 | } |
---|
| 1413 | else |
---|
| 1414 | { |
---|
| 1415 | xReadFlag( uiSymbol ); uiIPredMode = uiSymbol; |
---|
| 1416 | xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 1; |
---|
| 1417 | xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 2; |
---|
| 1418 | xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 3; |
---|
| 1419 | xReadFlag( uiSymbol ); uiIPredMode |= uiSymbol << 4; |
---|
| 1420 | |
---|
| 1421 | if (uiIPredMode == 31) |
---|
| 1422 | { // Escape coding for the last two modes |
---|
| 1423 | xReadFlag( uiSymbol ); |
---|
| 1424 | uiIPredMode = uiSymbol ? 32 : 31; |
---|
| 1425 | } |
---|
| 1426 | } |
---|
| 1427 | |
---|
| 1428 | if (uiIPredMode >= iMostProbable) |
---|
| 1429 | uiIPredMode++; |
---|
| 1430 | } |
---|
| 1431 | |
---|
| 1432 | #if ADD_PLANAR_MODE |
---|
| 1433 | if (uiIPredMode == 2) |
---|
| 1434 | { |
---|
| 1435 | UInt planarFlag; |
---|
| 1436 | xReadFlag( planarFlag ); |
---|
| 1437 | if ( planarFlag ) |
---|
| 1438 | { |
---|
| 1439 | uiIPredMode = PLANAR_IDX; |
---|
| 1440 | } |
---|
| 1441 | } |
---|
| 1442 | #endif |
---|
| 1443 | pcCU->setLumaIntraDirSubParts( (UChar)uiIPredMode, uiAbsPartIdx, uiDepth ); |
---|
| 1444 | } |
---|
| 1445 | #endif |
---|
| 1446 | |
---|
| 1447 | Void TDecCavlc::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1448 | { |
---|
| 1449 | UInt uiSymbol; |
---|
| 1450 | #if CHROMA_CODEWORD |
---|
| 1451 | UInt uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
| 1452 | #if ADD_PLANAR_MODE |
---|
| 1453 | if ( (uiMode == 2 ) || (uiMode == PLANAR_IDX) ) |
---|
| 1454 | { |
---|
| 1455 | uiMode = 4; |
---|
| 1456 | } |
---|
| 1457 | #endif |
---|
| 1458 | #if LM_CHROMA |
---|
| 1459 | Int iMaxMode = pcCU->getSlice()->getSPS()->getUseLMChroma() ? 3 : 4; |
---|
| 1460 | |
---|
| 1461 | Int iMax = uiMode < iMaxMode ? 3 : 4; |
---|
| 1462 | |
---|
| 1463 | xReadUnaryMaxSymbol( uiSymbol, iMax ); |
---|
| 1464 | |
---|
| 1465 | //switch codeword |
---|
| 1466 | if (uiSymbol == 0) |
---|
| 1467 | { |
---|
| 1468 | uiSymbol = 4; |
---|
| 1469 | } |
---|
| 1470 | else if (uiSymbol == 1 && pcCU->getSlice()->getSPS()->getUseLMChroma()) |
---|
| 1471 | { |
---|
| 1472 | uiSymbol = 3; |
---|
| 1473 | } |
---|
| 1474 | else |
---|
| 1475 | { |
---|
| 1476 | #if CHROMA_CODEWORD_SWITCH |
---|
| 1477 | uiSymbol = ChromaMapping[iMax-3][uiSymbol]; |
---|
| 1478 | #endif |
---|
| 1479 | |
---|
| 1480 | if (pcCU->getSlice()->getSPS()->getUseLMChroma()) |
---|
| 1481 | uiSymbol --; |
---|
| 1482 | |
---|
| 1483 | if (uiSymbol <= uiMode) |
---|
| 1484 | uiSymbol --; |
---|
| 1485 | } |
---|
| 1486 | |
---|
| 1487 | #else // -- LM_CHROMA |
---|
| 1488 | |
---|
| 1489 | Int iMax = uiMode < 4 ? 3 : 4; |
---|
| 1490 | xReadUnaryMaxSymbol( uiSymbol, iMax ); |
---|
| 1491 | |
---|
| 1492 | //switch codeword |
---|
| 1493 | if (uiSymbol == 0) |
---|
| 1494 | { |
---|
| 1495 | uiSymbol = 4; |
---|
| 1496 | } |
---|
| 1497 | #if CHROMA_CODEWORD_SWITCH |
---|
| 1498 | else |
---|
| 1499 | { |
---|
| 1500 | uiSymbol = ChromaMapping[iMax-3][uiSymbol]; |
---|
| 1501 | if (uiSymbol <= uiMode) |
---|
| 1502 | { |
---|
| 1503 | uiSymbol --; |
---|
| 1504 | } |
---|
| 1505 | } |
---|
| 1506 | #else |
---|
| 1507 | else if (uiSymbol <= uiMode) |
---|
| 1508 | { |
---|
| 1509 | uiSymbol --; |
---|
| 1510 | } |
---|
| 1511 | #endif |
---|
| 1512 | #endif // --> LM_CHROMA |
---|
| 1513 | |
---|
| 1514 | //printf("uiMode %d, chroma %d, codeword %d, imax %d\n", uiMode, uiSymbol, uiRead, iMax); |
---|
| 1515 | #else |
---|
| 1516 | xReadFlag( uiSymbol ); |
---|
| 1517 | |
---|
| 1518 | if ( uiSymbol ) |
---|
| 1519 | { |
---|
| 1520 | xReadUnaryMaxSymbol( uiSymbol, 3 ); |
---|
| 1521 | uiSymbol++; |
---|
| 1522 | } |
---|
| 1523 | #endif |
---|
| 1524 | |
---|
| 1525 | #if ADD_PLANAR_MODE |
---|
| 1526 | if (uiSymbol == 2) |
---|
| 1527 | { |
---|
| 1528 | #if CHROMA_CODEWORD |
---|
| 1529 | uiMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
| 1530 | if (uiMode == 2) |
---|
| 1531 | { |
---|
| 1532 | uiSymbol = PLANAR_IDX; |
---|
| 1533 | } |
---|
| 1534 | else if (uiMode != PLANAR_IDX) |
---|
| 1535 | #endif |
---|
| 1536 | { |
---|
| 1537 | UInt planarFlag; |
---|
| 1538 | xReadFlag( planarFlag ); |
---|
| 1539 | if ( planarFlag ) |
---|
| 1540 | { |
---|
| 1541 | uiSymbol = PLANAR_IDX; |
---|
| 1542 | } |
---|
| 1543 | } |
---|
| 1544 | } |
---|
| 1545 | #endif |
---|
| 1546 | pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth ); |
---|
| 1547 | |
---|
| 1548 | return ; |
---|
| 1549 | } |
---|
| 1550 | |
---|
| 1551 | Void TDecCavlc::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1552 | { |
---|
| 1553 | UInt uiSymbol; |
---|
| 1554 | |
---|
| 1555 | #if UNIFY_INTER_TABLE |
---|
| 1556 | #if DCM_COMB_LIST |
---|
| 1557 | UInt uiNumRefIdxOfLC = pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C); |
---|
| 1558 | #endif |
---|
| 1559 | #define min(a, b) (((a) < (b)) ? (a) : (b)) |
---|
| 1560 | #if DCM_COMB_LIST |
---|
| 1561 | UInt uiValNumRefIdxOfLC = min(4,pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)); |
---|
| 1562 | #endif |
---|
| 1563 | UInt uiValNumRefIdxOfL0 = min(2,pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0)); |
---|
| 1564 | UInt uiValNumRefIdxOfL1 = min(2,pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)); |
---|
| 1565 | |
---|
| 1566 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
| 1567 | { |
---|
| 1568 | UInt uiIndex,tmp; |
---|
| 1569 | #if CAVLC_COUNTER_ADAPT |
---|
| 1570 | Int x,cx; |
---|
| 1571 | #else |
---|
| 1572 | Int x,cx,y,cy; |
---|
| 1573 | #endif |
---|
| 1574 | |
---|
| 1575 | UInt *m_uiMITableD = m_uiMI1TableD; |
---|
| 1576 | |
---|
| 1577 | UInt uiMaxVal; |
---|
| 1578 | #if DCM_COMB_LIST |
---|
| 1579 | if (uiNumRefIdxOfLC > 0) |
---|
| 1580 | { |
---|
| 1581 | uiMaxVal = uiValNumRefIdxOfLC + uiValNumRefIdxOfL0*uiValNumRefIdxOfL1; |
---|
| 1582 | } |
---|
| 1583 | else |
---|
| 1584 | #endif |
---|
| 1585 | if (pcCU->getSlice()->getNoBackPredFlag()) |
---|
| 1586 | { |
---|
| 1587 | uiMaxVal = uiValNumRefIdxOfL0 + uiValNumRefIdxOfL0*uiValNumRefIdxOfL1; |
---|
| 1588 | } |
---|
| 1589 | else |
---|
| 1590 | { |
---|
| 1591 | uiMaxVal = uiValNumRefIdxOfL0 + uiValNumRefIdxOfL1 + uiValNumRefIdxOfL0*uiValNumRefIdxOfL1; |
---|
| 1592 | } |
---|
| 1593 | |
---|
| 1594 | xReadUnaryMaxSymbol( tmp, uiMaxVal ); |
---|
| 1595 | |
---|
| 1596 | x = m_uiMITableD[tmp]; |
---|
| 1597 | uiIndex = x; |
---|
| 1598 | |
---|
| 1599 | /* Adapt table */ |
---|
| 1600 | |
---|
| 1601 | cx = tmp; |
---|
| 1602 | #if CAVLC_COUNTER_ADAPT |
---|
| 1603 | adaptCodeword(cx, m_ucMI1TableCounter, m_ucMI1TableCounterSum, m_uiMITableD, NULL, 4 ); |
---|
| 1604 | #else |
---|
| 1605 | cy = Max(0,cx-1); |
---|
| 1606 | y = m_uiMITableD[cy]; |
---|
| 1607 | m_uiMITableD[cy] = x; |
---|
| 1608 | m_uiMITableD[cx] = y; |
---|
| 1609 | m_uiMITableVlcIdx += cx == m_uiMITableVlcIdx ? 0 : (cx < m_uiMITableVlcIdx ? -1 : 1); |
---|
| 1610 | #endif |
---|
| 1611 | |
---|
| 1612 | if (uiIndex < uiMaxVal) |
---|
| 1613 | { |
---|
| 1614 | #if DCM_COMB_LIST |
---|
| 1615 | if (uiNumRefIdxOfLC > 0) |
---|
| 1616 | { |
---|
| 1617 | if (uiIndex < uiValNumRefIdxOfLC) |
---|
| 1618 | { |
---|
| 1619 | ruiInterDir = 1; |
---|
| 1620 | m_iRefFrame0[uiAbsPartIdx] = uiIndex; |
---|
| 1621 | } |
---|
| 1622 | else |
---|
| 1623 | { |
---|
| 1624 | UInt uiTmp = uiIndex-uiValNumRefIdxOfLC; |
---|
| 1625 | ruiInterDir = 3; |
---|
| 1626 | |
---|
| 1627 | m_iRefFrame0[uiAbsPartIdx] = uiTmp/uiValNumRefIdxOfL1; //uiValNumRefIdxOfL1 == 1 or 2, so division can be converted to shift op |
---|
| 1628 | m_iRefFrame1[uiAbsPartIdx] = uiTmp%uiValNumRefIdxOfL1; |
---|
| 1629 | } |
---|
| 1630 | } |
---|
| 1631 | else |
---|
| 1632 | #endif |
---|
| 1633 | if (pcCU->getSlice()->getNoBackPredFlag()) |
---|
| 1634 | { |
---|
| 1635 | if (uiIndex < uiValNumRefIdxOfL0) |
---|
| 1636 | { |
---|
| 1637 | ruiInterDir = 1; |
---|
| 1638 | m_iRefFrame0[uiAbsPartIdx] = uiIndex; |
---|
| 1639 | } |
---|
| 1640 | else |
---|
| 1641 | { |
---|
| 1642 | UInt uiTmp = uiIndex-uiValNumRefIdxOfL0; |
---|
| 1643 | ruiInterDir = 3; |
---|
| 1644 | |
---|
| 1645 | m_iRefFrame0[uiAbsPartIdx] = uiTmp/uiValNumRefIdxOfL1; //uiValNumRefIdxOfL1 == 1 or 2, so division can be converted to shift op |
---|
| 1646 | m_iRefFrame1[uiAbsPartIdx] = uiTmp%uiValNumRefIdxOfL1; |
---|
| 1647 | } |
---|
| 1648 | } |
---|
| 1649 | else |
---|
| 1650 | { |
---|
| 1651 | if (uiIndex < uiValNumRefIdxOfL0) |
---|
| 1652 | { |
---|
| 1653 | ruiInterDir = 1; |
---|
| 1654 | m_iRefFrame0[uiAbsPartIdx] = uiIndex; |
---|
| 1655 | } |
---|
| 1656 | else if (uiIndex < uiValNumRefIdxOfL1) |
---|
| 1657 | { |
---|
| 1658 | ruiInterDir = 2; |
---|
| 1659 | m_iRefFrame1[uiAbsPartIdx] = uiIndex-uiValNumRefIdxOfL0; |
---|
| 1660 | } |
---|
| 1661 | else |
---|
| 1662 | { |
---|
| 1663 | UInt uiTmp = uiIndex-uiValNumRefIdxOfL0-uiValNumRefIdxOfL1; |
---|
| 1664 | ruiInterDir = 3; |
---|
| 1665 | |
---|
| 1666 | m_iRefFrame0[uiAbsPartIdx] = uiTmp/uiValNumRefIdxOfL1; //uiValNumRefIdxOfL1 == 1 or 2, so division can be converted to shift op |
---|
| 1667 | m_iRefFrame1[uiAbsPartIdx] = uiTmp%uiValNumRefIdxOfL1; |
---|
| 1668 | } |
---|
| 1669 | } |
---|
| 1670 | |
---|
| 1671 | return; |
---|
| 1672 | } |
---|
| 1673 | } |
---|
| 1674 | #else //UNIFY_INTER_TABLE |
---|
| 1675 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
| 1676 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
| 1677 | #else |
---|
| 1678 | if(pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2) |
---|
| 1679 | #endif |
---|
| 1680 | { |
---|
| 1681 | UInt uiIndex,uiInterDir,tmp; |
---|
| 1682 | |
---|
| 1683 | #if CAVLC_COUNTER_ADAPT |
---|
| 1684 | Int x,cx; |
---|
| 1685 | #else |
---|
| 1686 | Int x,cx,y,cy; |
---|
| 1687 | #endif |
---|
| 1688 | |
---|
| 1689 | #if MS_LCEC_LOOKUP_TABLE_MAX_VALUE |
---|
| 1690 | UInt uiMaxVal = 7; |
---|
| 1691 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
| 1692 | uiMaxVal = 8; |
---|
| 1693 | #endif |
---|
| 1694 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 1 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 1 ) |
---|
| 1695 | { |
---|
| 1696 | if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 1 ) ) |
---|
| 1697 | { |
---|
| 1698 | uiMaxVal = 1; |
---|
| 1699 | } |
---|
| 1700 | else |
---|
| 1701 | { |
---|
| 1702 | uiMaxVal = 2; |
---|
| 1703 | } |
---|
| 1704 | } |
---|
| 1705 | else if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 ) |
---|
| 1706 | { |
---|
| 1707 | if ( pcCU->getSlice()->getNoBackPredFlag() || ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 2 ) ) |
---|
| 1708 | { |
---|
| 1709 | uiMaxVal = 5; |
---|
| 1710 | } |
---|
| 1711 | else |
---|
| 1712 | { |
---|
| 1713 | uiMaxVal = 7; |
---|
| 1714 | } |
---|
| 1715 | } |
---|
| 1716 | else if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0 ) |
---|
| 1717 | { |
---|
| 1718 | uiMaxVal = 4+1+MS_LCEC_UNI_EXCEPTION_THRES; |
---|
| 1719 | } |
---|
| 1720 | |
---|
| 1721 | xReadUnaryMaxSymbol( tmp, uiMaxVal ); |
---|
| 1722 | #else |
---|
| 1723 | UInt vlcn = g_auiMITableVlcNum[m_uiMITableVlcIdx]; |
---|
| 1724 | tmp = xReadVlc( vlcn ); |
---|
| 1725 | #endif |
---|
| 1726 | |
---|
| 1727 | UInt *m_uiMITableD = m_uiMI1TableD; |
---|
| 1728 | x = m_uiMITableD[tmp]; |
---|
| 1729 | uiIndex = x; |
---|
| 1730 | |
---|
| 1731 | /* Adapt table */ |
---|
| 1732 | |
---|
| 1733 | cx = tmp; |
---|
| 1734 | |
---|
| 1735 | #if CAVLC_COUNTER_ADAPT |
---|
| 1736 | adaptCodeword(cx, m_ucMI1TableCounter, m_ucMI1TableCounterSum, m_uiMITableD, NULL, 4 ); |
---|
| 1737 | #else |
---|
| 1738 | cy = Max(0,cx-1); |
---|
| 1739 | y = m_uiMITableD[cy]; |
---|
| 1740 | m_uiMITableD[cy] = x; |
---|
| 1741 | m_uiMITableD[cx] = y; |
---|
| 1742 | m_uiMITableVlcIdx += cx == m_uiMITableVlcIdx ? 0 : (cx < m_uiMITableVlcIdx ? -1 : 1); |
---|
| 1743 | #endif |
---|
| 1744 | { |
---|
| 1745 | uiInterDir = Min(2,uiIndex>>1); |
---|
| 1746 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
| 1747 | if ( uiIndex >=4 ) |
---|
| 1748 | { |
---|
| 1749 | uiInterDir = 2; |
---|
| 1750 | } |
---|
| 1751 | else |
---|
| 1752 | { |
---|
| 1753 | uiInterDir = 0; |
---|
| 1754 | } |
---|
| 1755 | #endif |
---|
| 1756 | #if DCM_COMB_LIST |
---|
| 1757 | if(uiInterDir!=2 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C)>0) |
---|
| 1758 | { |
---|
| 1759 | uiInterDir = 0; |
---|
| 1760 | m_iRefFrame0[uiAbsPartIdx] = uiIndex; |
---|
| 1761 | } |
---|
| 1762 | else |
---|
| 1763 | #endif |
---|
| 1764 | if (uiInterDir==0) |
---|
| 1765 | { |
---|
| 1766 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
| 1767 | m_iRefFrame0[uiAbsPartIdx] = uiIndex; |
---|
| 1768 | #else |
---|
| 1769 | m_iRefFrame0[uiAbsPartIdx] = uiIndex&1; |
---|
| 1770 | #endif |
---|
| 1771 | } |
---|
| 1772 | else if (uiInterDir==1) |
---|
| 1773 | m_iRefFrame1[uiAbsPartIdx] = uiIndex&1; |
---|
| 1774 | else |
---|
| 1775 | { |
---|
| 1776 | m_iRefFrame0[uiAbsPartIdx] = (uiIndex>>1)&1; |
---|
| 1777 | m_iRefFrame1[uiAbsPartIdx] = (uiIndex>>0)&1; |
---|
| 1778 | } |
---|
| 1779 | } |
---|
| 1780 | ruiInterDir = uiInterDir+1; |
---|
| 1781 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
| 1782 | if ( x < 8 ) |
---|
| 1783 | #endif |
---|
| 1784 | { |
---|
| 1785 | return; |
---|
| 1786 | } |
---|
| 1787 | } |
---|
| 1788 | #endif //UNIFY_INTER_TABLE |
---|
| 1789 | |
---|
| 1790 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
| 1791 | m_iRefFrame0[uiAbsPartIdx] = 1000; |
---|
| 1792 | m_iRefFrame1[uiAbsPartIdx] = 1000; |
---|
| 1793 | #endif |
---|
| 1794 | |
---|
| 1795 | xReadFlag( uiSymbol ); |
---|
| 1796 | |
---|
| 1797 | if ( uiSymbol ) |
---|
| 1798 | { |
---|
| 1799 | uiSymbol = 2; |
---|
| 1800 | } |
---|
| 1801 | #if DCM_COMB_LIST |
---|
| 1802 | else if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) |
---|
| 1803 | { |
---|
| 1804 | uiSymbol = 0; |
---|
| 1805 | } |
---|
| 1806 | #endif |
---|
| 1807 | else if ( pcCU->getSlice()->getNoBackPredFlag() ) |
---|
| 1808 | { |
---|
| 1809 | uiSymbol = 0; |
---|
| 1810 | } |
---|
| 1811 | else |
---|
| 1812 | { |
---|
| 1813 | xReadFlag( uiSymbol ); |
---|
| 1814 | } |
---|
| 1815 | uiSymbol++; |
---|
| 1816 | ruiInterDir = uiSymbol; |
---|
| 1817 | return; |
---|
| 1818 | } |
---|
| 1819 | |
---|
| 1820 | Void TDecCavlc::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
| 1821 | { |
---|
| 1822 | UInt uiSymbol; |
---|
| 1823 | |
---|
| 1824 | if (pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) <= 2 && pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) <= 2 && pcCU->getSlice()->isInterB()) |
---|
| 1825 | { |
---|
| 1826 | #if DCM_COMB_LIST |
---|
| 1827 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C ) > 0 && eRefList==REF_PIC_LIST_C) |
---|
| 1828 | { |
---|
| 1829 | riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx]; |
---|
| 1830 | } |
---|
| 1831 | else |
---|
| 1832 | #endif |
---|
| 1833 | if (eRefList==REF_PIC_LIST_0) |
---|
| 1834 | { |
---|
| 1835 | riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx]; |
---|
| 1836 | } |
---|
| 1837 | if (eRefList==REF_PIC_LIST_1) |
---|
| 1838 | { |
---|
| 1839 | riRefFrmIdx = m_iRefFrame1[uiAbsPartIdx]; |
---|
| 1840 | } |
---|
| 1841 | return; |
---|
| 1842 | } |
---|
| 1843 | |
---|
| 1844 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
| 1845 | if ( ( m_iRefFrame0[uiAbsPartIdx] != 1000 || m_iRefFrame1[uiAbsPartIdx] != 1000 ) && |
---|
| 1846 | pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
| 1847 | { |
---|
| 1848 | if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C ) > 0 && eRefList==REF_PIC_LIST_C ) |
---|
| 1849 | { |
---|
| 1850 | riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx]; |
---|
| 1851 | } |
---|
| 1852 | else if (eRefList==REF_PIC_LIST_0) |
---|
| 1853 | { |
---|
| 1854 | riRefFrmIdx = m_iRefFrame0[uiAbsPartIdx]; |
---|
| 1855 | } |
---|
| 1856 | else if (eRefList==REF_PIC_LIST_1) |
---|
| 1857 | { |
---|
| 1858 | riRefFrmIdx = m_iRefFrame1[uiAbsPartIdx]; |
---|
| 1859 | } |
---|
| 1860 | return; |
---|
| 1861 | } |
---|
| 1862 | |
---|
| 1863 | UInt uiRefFrmIdxMinus = 0; |
---|
| 1864 | if ( pcCU->getSlice()->getRefIdxCombineCoding() ) |
---|
| 1865 | { |
---|
| 1866 | if ( pcCU->getInterDir( uiAbsPartIdx ) != 3 ) |
---|
| 1867 | { |
---|
| 1868 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 ) |
---|
| 1869 | { |
---|
| 1870 | uiRefFrmIdxMinus = 4; |
---|
| 1871 | } |
---|
| 1872 | else |
---|
| 1873 | { |
---|
| 1874 | uiRefFrmIdxMinus = MS_LCEC_UNI_EXCEPTION_THRES+1; |
---|
| 1875 | } |
---|
| 1876 | } |
---|
| 1877 | else if ( eRefList == REF_PIC_LIST_1 && pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiAbsPartIdx ) < 2 ) |
---|
| 1878 | { |
---|
| 1879 | uiRefFrmIdxMinus = 2; |
---|
| 1880 | } |
---|
| 1881 | } |
---|
| 1882 | if ( pcCU->getSlice()->getNumRefIdx( eRefList ) - uiRefFrmIdxMinus <= 1 ) |
---|
| 1883 | { |
---|
| 1884 | uiSymbol = 0; |
---|
| 1885 | riRefFrmIdx = uiSymbol; |
---|
| 1886 | riRefFrmIdx += uiRefFrmIdxMinus; |
---|
| 1887 | return; |
---|
| 1888 | } |
---|
| 1889 | #endif |
---|
| 1890 | |
---|
| 1891 | xReadFlag ( uiSymbol ); |
---|
| 1892 | if ( uiSymbol ) |
---|
| 1893 | { |
---|
| 1894 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
| 1895 | xReadUnaryMaxSymbol( uiSymbol, pcCU->getSlice()->getNumRefIdx( eRefList )-2 - uiRefFrmIdxMinus ); |
---|
| 1896 | #else |
---|
| 1897 | xReadUnaryMaxSymbol( uiSymbol, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
| 1898 | #endif |
---|
| 1899 | |
---|
| 1900 | uiSymbol++; |
---|
| 1901 | } |
---|
| 1902 | riRefFrmIdx = uiSymbol; |
---|
| 1903 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
| 1904 | riRefFrmIdx += uiRefFrmIdxMinus; |
---|
| 1905 | #endif |
---|
| 1906 | |
---|
| 1907 | return; |
---|
| 1908 | } |
---|
| 1909 | |
---|
| 1910 | Void TDecCavlc::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
| 1911 | { |
---|
| 1912 | Int iHor, iVer; |
---|
| 1913 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
| 1914 | Int iHorPred, iVerPred; |
---|
| 1915 | |
---|
| 1916 | TComDataCU* pcCUL = pcCU->getPULeft ( uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
| 1917 | TComDataCU* pcCUA = pcCU->getPUAbove( uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
| 1918 | |
---|
| 1919 | TComCUMvField* pcCUMvFieldL = ( pcCUL == NULL || pcCUL->isIntra( uiAbsPartIdxL ) ) ? NULL : pcCUL->getCUMvField( eRefList ); |
---|
| 1920 | TComCUMvField* pcCUMvFieldA = ( pcCUA == NULL || pcCUA->isIntra( uiAbsPartIdxA ) ) ? NULL : pcCUA->getCUMvField( eRefList ); |
---|
| 1921 | |
---|
| 1922 | iHorPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsHor() ) + |
---|
| 1923 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsHor() ); |
---|
| 1924 | iVerPred = ( (pcCUMvFieldL == NULL) ? 0 : pcCUMvFieldL->getMvd( uiAbsPartIdxL ).getAbsVer() ) + |
---|
| 1925 | ( (pcCUMvFieldA == NULL) ? 0 : pcCUMvFieldA->getMvd( uiAbsPartIdxA ).getAbsVer() ); |
---|
| 1926 | |
---|
| 1927 | TComMv cTmpMv( 0, 0 ); |
---|
| 1928 | pcCU->getCUMvField( eRefList )->setAllMv( cTmpMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
| 1929 | |
---|
| 1930 | xReadSvlc( iHor ); |
---|
| 1931 | xReadSvlc( iVer ); |
---|
| 1932 | |
---|
| 1933 | // set mvd |
---|
| 1934 | TComMv cMv( iHor, iVer ); |
---|
| 1935 | pcCU->getCUMvField( eRefList )->setAllMvd( cMv, pcCU->getPartitionSize( uiAbsPartIdx ), uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
| 1936 | |
---|
| 1937 | return; |
---|
| 1938 | } |
---|
| 1939 | |
---|
| 1940 | Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1941 | { |
---|
| 1942 | UInt uiDQp; |
---|
| 1943 | Int iDQp; |
---|
| 1944 | |
---|
| 1945 | xReadFlag( uiDQp ); |
---|
| 1946 | |
---|
| 1947 | if ( uiDQp == 0 ) |
---|
| 1948 | { |
---|
| 1949 | uiDQp = pcCU->getSlice()->getSliceQp(); |
---|
| 1950 | } |
---|
| 1951 | else |
---|
| 1952 | { |
---|
| 1953 | xReadSvlc( iDQp ); |
---|
| 1954 | uiDQp = pcCU->getSlice()->getSliceQp() + iDQp; |
---|
| 1955 | } |
---|
| 1956 | |
---|
| 1957 | pcCU->setQPSubParts( uiDQp, uiAbsPartIdx, uiDepth ); |
---|
| 1958 | } |
---|
| 1959 | |
---|
| 1960 | #if CAVLC_RQT_CBP |
---|
| 1961 | /** Function for parsing cbf and split |
---|
| 1962 | * \param pcCU pointer to CU |
---|
| 1963 | * \param uiAbsPartIdx CU index |
---|
| 1964 | * \param uiTrDepth Transform depth |
---|
| 1965 | * \param uiDepth CU Depth |
---|
| 1966 | * \param uiSubdiv split flag |
---|
| 1967 | * \returns |
---|
| 1968 | * This function performs parsing for cbf and split flag |
---|
| 1969 | */ |
---|
| 1970 | Void TDecCavlc::parseCbfTrdiv( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiTrDepth, UInt uiDepth, UInt& uiSubdiv ) |
---|
| 1971 | { |
---|
| 1972 | UInt uiCbf,tmp; |
---|
| 1973 | UInt uiCBP,uiCbfY,uiCbfU,uiCbfV; |
---|
| 1974 | UInt n,cx; |
---|
| 1975 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ] + 2; |
---|
| 1976 | UInt uiQPartNumParent = pcCU->getPic()->getNumPartInCU() >> ((uiDepth-1) << 1); |
---|
| 1977 | UInt uiQPartNumCurr = pcCU->getPic()->getNumPartInCU() >> ((uiDepth) << 1); |
---|
| 1978 | |
---|
| 1979 | UInt uiFlagPattern = xGetFlagPattern( pcCU, uiAbsPartIdx, uiDepth, uiSubdiv ); |
---|
| 1980 | |
---|
| 1981 | n = pcCU->isIntra( uiAbsPartIdx ) ? 0 : 1; |
---|
| 1982 | uiCbfY = uiCbfU = uiCbfV = 0; |
---|
| 1983 | |
---|
| 1984 | if(uiFlagPattern < 8) |
---|
| 1985 | { |
---|
| 1986 | if( uiLog2TrSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
| 1987 | { |
---|
| 1988 | if(uiFlagPattern & 0x04) |
---|
| 1989 | { |
---|
| 1990 | xReadFlag(uiCbfU); |
---|
| 1991 | } |
---|
| 1992 | if(uiFlagPattern & 0x02) |
---|
| 1993 | { |
---|
| 1994 | xReadFlag(uiCbfV); |
---|
| 1995 | } |
---|
| 1996 | } |
---|
| 1997 | else |
---|
| 1998 | { |
---|
| 1999 | uiCbfU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1)?1:0; |
---|
| 2000 | uiCbfV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1)?1:0; |
---|
| 2001 | } |
---|
| 2002 | if(uiFlagPattern & 0x01) |
---|
| 2003 | { |
---|
| 2004 | parseTransformSubdivFlag( uiSubdiv, 0); |
---|
| 2005 | } |
---|
| 2006 | } |
---|
| 2007 | else |
---|
| 2008 | { |
---|
| 2009 | if(uiFlagPattern == 8) |
---|
| 2010 | { |
---|
| 2011 | if (uiAbsPartIdx % uiQPartNumParent ==0) |
---|
| 2012 | { |
---|
| 2013 | parseBlockCbf(pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth,uiDepth, uiQPartNumCurr); |
---|
| 2014 | } |
---|
| 2015 | uiCbfY = ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA ) >> uiTrDepth) & 0x1; |
---|
| 2016 | if( uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
| 2017 | { |
---|
| 2018 | uiCbfU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1)?1:0; |
---|
| 2019 | uiCbfV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1)?1:0; |
---|
| 2020 | } |
---|
| 2021 | } |
---|
| 2022 | else if(uiFlagPattern == 9) |
---|
| 2023 | { |
---|
| 2024 | bool bNeedToDecode = true; |
---|
| 2025 | if ( n==1 && (uiAbsPartIdx%uiQPartNumParent) / uiQPartNumCurr == 3 ) // last one |
---|
| 2026 | { |
---|
| 2027 | UInt uiTempAbsPartIdx = uiAbsPartIdx/uiQPartNumParent*uiQPartNumParent; |
---|
| 2028 | if ( pcCU->getCbf( uiTempAbsPartIdx + uiQPartNumCurr*0, TEXT_LUMA, uiTrDepth ) || |
---|
| 2029 | pcCU->getCbf( uiTempAbsPartIdx + uiQPartNumCurr*1, TEXT_LUMA, uiTrDepth ) || |
---|
| 2030 | pcCU->getCbf( uiTempAbsPartIdx + uiQPartNumCurr*2, TEXT_LUMA, uiTrDepth ) ) |
---|
| 2031 | { |
---|
| 2032 | bNeedToDecode = true; |
---|
| 2033 | } |
---|
| 2034 | else |
---|
| 2035 | { |
---|
| 2036 | bNeedToDecode = false; |
---|
| 2037 | xReadFlag( uiSubdiv ); |
---|
| 2038 | uiCbfY = 1; |
---|
| 2039 | } |
---|
| 2040 | } |
---|
| 2041 | if ( bNeedToDecode ) |
---|
| 2042 | { |
---|
| 2043 | UInt uiSymbol; |
---|
| 2044 | xReadUnaryMaxSymbol(cx, n?2:3); |
---|
| 2045 | uiSymbol = m_uiCBP_YS_TableD[n][cx]; |
---|
| 2046 | uiCbfY = uiSymbol >> 1; |
---|
| 2047 | uiSubdiv = uiSymbol & 0x01; |
---|
| 2048 | adaptCodeword(cx, m_ucCBP_YS_TableCounter[n], m_ucCBP_YS_TableCounterSum[n], m_uiCBP_YS_TableD[n], NULL, 3); |
---|
| 2049 | } |
---|
| 2050 | } |
---|
| 2051 | else if (uiFlagPattern == 14) |
---|
| 2052 | { |
---|
| 2053 | UInt uiIdx = uiTrDepth? (2 + n) : n; |
---|
| 2054 | xReadUnaryMaxSymbol(cx, 7); |
---|
| 2055 | uiCBP = m_uiCBP_YUV_TableD[uiIdx][cx]; |
---|
| 2056 | adaptCodeword(cx, m_ucCBP_YUV_TableCounter[uiIdx], m_ucCBP_YUV_TableCounterSum[uiIdx], m_uiCBP_YUV_TableD[uiIdx], NULL, 4); |
---|
| 2057 | uiCbfY = (uiCBP>>2)&1; |
---|
| 2058 | uiCbfU = (uiCBP>>1)&1; |
---|
| 2059 | uiCbfV = (uiCBP>>0)&1; |
---|
| 2060 | } |
---|
| 2061 | else if ( uiFlagPattern == 11 || uiFlagPattern == 13 || uiFlagPattern == 15) |
---|
| 2062 | { |
---|
| 2063 | UInt uiSymbol, i; |
---|
| 2064 | m_pcBitstream->pseudoRead(6, uiSymbol); |
---|
| 2065 | for (i=0;i<8;i++) |
---|
| 2066 | { |
---|
| 2067 | if( (uiSymbol>>(6 - g_auiCBP_YCS_TableLen[n][i])) == g_auiCBP_YCS_Table[n][i] && g_auiCBP_YCS_TableLen[n][i]) |
---|
| 2068 | { |
---|
| 2069 | m_pcBitstream->read(g_auiCBP_YCS_TableLen[n][i],uiSymbol); |
---|
| 2070 | uiSymbol =i; |
---|
| 2071 | break; |
---|
| 2072 | } |
---|
| 2073 | } |
---|
| 2074 | |
---|
| 2075 | uiCBP = m_uiCBP_YCS_TableD[n][uiSymbol]; |
---|
| 2076 | adaptCodeword(uiSymbol, m_ucCBP_YCS_TableCounter[n], m_ucCBP_YCS_TableCounterSum[n], m_uiCBP_YCS_TableD[n], NULL, 4); |
---|
| 2077 | uiCbfY = uiCBP >> 2; |
---|
| 2078 | UInt uiCbfUV = (uiCBP >> 1)& 0x01; |
---|
| 2079 | uiSubdiv = uiCBP & 0x01; |
---|
| 2080 | |
---|
| 2081 | uiCbfU = 0; uiCbfV = 0; |
---|
| 2082 | if (uiFlagPattern == 15) |
---|
| 2083 | { |
---|
| 2084 | if(uiCbfUV) |
---|
| 2085 | { |
---|
| 2086 | xReadUnaryMaxSymbol( uiSymbol , 2); |
---|
| 2087 | uiSymbol = n? (uiSymbol + 1): (3 - uiSymbol); |
---|
| 2088 | uiCbfU = uiSymbol >> 1; |
---|
| 2089 | uiCbfV = uiSymbol & 0x01; |
---|
| 2090 | } |
---|
| 2091 | } |
---|
| 2092 | else |
---|
| 2093 | { |
---|
| 2094 | uiCbfU = (uiFlagPattern & 0x04) ? uiCbfUV: 0; |
---|
| 2095 | uiCbfV = (uiFlagPattern & 0x02) ? uiCbfUV: 0; |
---|
| 2096 | } |
---|
| 2097 | } |
---|
| 2098 | else if (uiFlagPattern == 10 || uiFlagPattern == 12) |
---|
| 2099 | { |
---|
| 2100 | UInt uiSymbol; |
---|
| 2101 | xReadUnaryMaxSymbol(tmp, 3); |
---|
| 2102 | uiSymbol = g_auiCBP_YC_TableD[n][tmp]; |
---|
| 2103 | uiCbfY = uiSymbol >> 1; |
---|
| 2104 | |
---|
| 2105 | uiCbfU = uiCbfV = 0; |
---|
| 2106 | if(uiSymbol & 0x01) |
---|
| 2107 | { |
---|
| 2108 | uiCbfU = (uiFlagPattern & 0x04)? 1 : 0; |
---|
| 2109 | uiCbfV = (uiFlagPattern & 0x02)? 1 : 0; |
---|
| 2110 | } |
---|
| 2111 | } |
---|
| 2112 | } |
---|
| 2113 | |
---|
| 2114 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA ); |
---|
| 2115 | pcCU->setCbfSubParts( uiCbf | ( uiCbfY << uiTrDepth ), TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
| 2116 | |
---|
| 2117 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U ); |
---|
| 2118 | pcCU->setCbfSubParts( uiCbf | ( uiCbfU << uiTrDepth ), TEXT_CHROMA_U, uiAbsPartIdx, uiDepth ); |
---|
| 2119 | |
---|
| 2120 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V ); |
---|
| 2121 | pcCU->setCbfSubParts( uiCbf | ( uiCbfV << uiTrDepth ), TEXT_CHROMA_V, uiAbsPartIdx, uiDepth ); |
---|
| 2122 | |
---|
| 2123 | if(!pcCU->isIntra(uiAbsPartIdx) && uiCbfY == 0 && uiCbfU == 0 && uiCbfV == 0) |
---|
| 2124 | { |
---|
| 2125 | uiSubdiv = 0; |
---|
| 2126 | } |
---|
| 2127 | |
---|
| 2128 | return; |
---|
| 2129 | } |
---|
| 2130 | |
---|
| 2131 | /** Function for parsing cbf and split |
---|
| 2132 | * \param pcCU pointer to CU |
---|
| 2133 | * \param uiAbsPartIdx CU index |
---|
| 2134 | * \param uiDepth CU Depth |
---|
| 2135 | * \param uiSubdiv split flag |
---|
| 2136 | * \returns flag pattern |
---|
| 2137 | * This function gets flagpattern for cbf and split flag |
---|
| 2138 | */ |
---|
| 2139 | UInt TDecCavlc::xGetFlagPattern( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiSubdiv ) |
---|
| 2140 | { |
---|
| 2141 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
| 2142 | UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
| 2143 | UInt patternYUV, patternDiv; |
---|
| 2144 | UInt bY, bU, bV; |
---|
| 2145 | |
---|
| 2146 | |
---|
| 2147 | UInt uiFullDepth = pcCU->getDepth(uiAbsPartIdx) + uiTrDepth; |
---|
| 2148 | UInt uiLog2TrSize = g_aucConvertToBit[ pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiFullDepth ] + 2; |
---|
| 2149 | if(uiTrDepth == 0) |
---|
| 2150 | { |
---|
| 2151 | patternYUV = 7; |
---|
| 2152 | } |
---|
| 2153 | else if( uiLog2TrSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
| 2154 | { |
---|
| 2155 | bY = pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, uiTrDepth - 1)?1:0; |
---|
| 2156 | bU = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1)?1:0; |
---|
| 2157 | bV = pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1)?1:0; |
---|
| 2158 | patternYUV = (bY<<2) + (bU<<1) + bV; |
---|
| 2159 | } |
---|
| 2160 | else |
---|
| 2161 | { |
---|
| 2162 | bY = pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA, uiTrDepth - 1)?1:0; |
---|
| 2163 | patternYUV = bY<<2; |
---|
| 2164 | } |
---|
| 2165 | |
---|
| 2166 | |
---|
| 2167 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
| 2168 | { |
---|
| 2169 | patternDiv = 0; uiSubdiv = 1; |
---|
| 2170 | } |
---|
| 2171 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
| 2172 | { |
---|
| 2173 | patternDiv = 0; uiSubdiv = 1; |
---|
| 2174 | } |
---|
| 2175 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
| 2176 | { |
---|
| 2177 | patternDiv = 0; uiSubdiv = 0; |
---|
| 2178 | } |
---|
| 2179 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
| 2180 | { |
---|
| 2181 | patternDiv = 0; uiSubdiv = 0; |
---|
| 2182 | } |
---|
| 2183 | else |
---|
| 2184 | { |
---|
| 2185 | patternDiv = 1; |
---|
| 2186 | } |
---|
| 2187 | |
---|
| 2188 | return ((patternYUV<<1)+patternDiv); |
---|
| 2189 | } |
---|
| 2190 | #endif |
---|
| 2191 | Void TDecCavlc::parseCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) |
---|
| 2192 | { |
---|
| 2193 | if (eType == TEXT_ALL) |
---|
| 2194 | { |
---|
| 2195 | UInt uiCbf,tmp; |
---|
| 2196 | UInt uiCBP,uiCbfY,uiCbfU,uiCbfV; |
---|
| 2197 | |
---|
| 2198 | #if CAVLC_COUNTER_ADAPT |
---|
| 2199 | Int n, cx; |
---|
| 2200 | #else |
---|
| 2201 | Int n,x,cx,y,cy; |
---|
| 2202 | #endif |
---|
| 2203 | |
---|
| 2204 | /* Start adaptation */ |
---|
| 2205 | n = pcCU->isIntra( uiAbsPartIdx ) ? 0 : 1; |
---|
| 2206 | #if CAVLC_RQT_CBP |
---|
| 2207 | UInt vlcn = 0; |
---|
| 2208 | #else |
---|
| 2209 | UInt vlcn = g_auiCbpVlcNum[n][m_uiCbpVlcIdx[n]]; |
---|
| 2210 | #endif |
---|
| 2211 | tmp = xReadVlc( vlcn ); |
---|
| 2212 | #if CAVLC_RQT_CBP |
---|
| 2213 | uiCBP = m_uiCBP_YUV_TableD[n][tmp]; |
---|
| 2214 | #else |
---|
| 2215 | uiCBP = m_uiCBPTableD[n][tmp]; |
---|
| 2216 | #endif |
---|
| 2217 | |
---|
| 2218 | /* Adapt LP table */ |
---|
| 2219 | cx = tmp; |
---|
| 2220 | |
---|
| 2221 | #if CAVLC_COUNTER_ADAPT |
---|
| 2222 | #if CAVLC_RQT_CBP |
---|
| 2223 | adaptCodeword(cx, m_ucCBP_YUV_TableCounter[n], m_ucCBP_YUV_TableCounterSum[n], m_uiCBP_YUV_TableD[n], NULL, 4); |
---|
| 2224 | #else |
---|
| 2225 | adaptCodeword(cx, m_ucCBFTableCounter[n], m_ucCBFTableCounterSum[n], m_uiCBPTableD[n], NULL, 4); |
---|
| 2226 | #endif |
---|
| 2227 | #else |
---|
| 2228 | cy = Max(0,cx-1); |
---|
| 2229 | x = uiCBP; |
---|
| 2230 | y = m_uiCBPTableD[n][cy]; |
---|
| 2231 | m_uiCBPTableD[n][cy] = x; |
---|
| 2232 | m_uiCBPTableD[n][cx] = y; |
---|
| 2233 | m_uiCbpVlcIdx[n] += cx == m_uiCbpVlcIdx[n] ? 0 : (cx < m_uiCbpVlcIdx[n] ? -1 : 1); |
---|
| 2234 | #endif |
---|
| 2235 | |
---|
| 2236 | uiCbfY = (uiCBP>>0)&1; |
---|
| 2237 | uiCbfU = (uiCBP>>1)&1; |
---|
| 2238 | uiCbfV = (uiCBP>>2)&1; |
---|
| 2239 | |
---|
| 2240 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA ); |
---|
| 2241 | pcCU->setCbfSubParts( uiCbf | ( uiCbfY << uiTrDepth ), TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
| 2242 | |
---|
| 2243 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U ); |
---|
| 2244 | pcCU->setCbfSubParts( uiCbf | ( uiCbfU << uiTrDepth ), TEXT_CHROMA_U, uiAbsPartIdx, uiDepth ); |
---|
| 2245 | |
---|
| 2246 | uiCbf = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V ); |
---|
| 2247 | pcCU->setCbfSubParts( uiCbf | ( uiCbfV << uiTrDepth ), TEXT_CHROMA_V, uiAbsPartIdx, uiDepth ); |
---|
| 2248 | } |
---|
| 2249 | } |
---|
| 2250 | |
---|
| 2251 | Void TDecCavlc::parseBlockCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth, UInt uiQPartNum ) |
---|
| 2252 | { |
---|
| 2253 | assert(uiTrDepth > 0); |
---|
| 2254 | UInt uiCbf4, uiCbf; |
---|
| 2255 | |
---|
| 2256 | #if CAVLC_COUNTER_ADAPT |
---|
| 2257 | Int cx; |
---|
| 2258 | #else |
---|
| 2259 | Int x,cx,y,cy; |
---|
| 2260 | #endif |
---|
| 2261 | |
---|
| 2262 | UInt tmp; |
---|
| 2263 | |
---|
| 2264 | UInt n = (pcCU->isIntra(uiAbsPartIdx) && eType == TEXT_LUMA)? 0:1; |
---|
| 2265 | #if CAVLC_RQT_CBP |
---|
| 2266 | UInt vlcn = (n==0)?g_auiCBP_4Y_VlcNum[m_uiCBP_4Y_VlcIdx]:11; |
---|
| 2267 | #else |
---|
| 2268 | UInt vlcn = (n==0)?g_auiBlkCbpVlcNum[m_uiBlkCbpVlcIdx]:11; |
---|
| 2269 | #endif |
---|
| 2270 | tmp = xReadVlc( vlcn ); |
---|
| 2271 | #if CAVLC_RQT_CBP |
---|
| 2272 | uiCbf4 = m_uiCBP_4Y_TableD[n][tmp]; |
---|
| 2273 | #else |
---|
| 2274 | uiCbf4 = m_uiBlkCBPTableD[n][tmp]; |
---|
| 2275 | #endif |
---|
| 2276 | |
---|
| 2277 | cx = tmp; |
---|
| 2278 | |
---|
| 2279 | #if CAVLC_COUNTER_ADAPT |
---|
| 2280 | #if CAVLC_RQT_CBP |
---|
| 2281 | adaptCodeword(cx, m_ucCBP_4Y_TableCounter[n], m_ucCBP_4Y_TableCounterSum[n], m_uiCBP_4Y_TableD[n], NULL, 2); |
---|
| 2282 | #else |
---|
| 2283 | adaptCodeword(cx, m_ucBlkCBPTableCounter[n], m_ucBlkCBPTableCounterSum[n], m_uiBlkCBPTableD[n], NULL, 2); |
---|
| 2284 | #endif |
---|
| 2285 | #else |
---|
| 2286 | cy = Max(0,cx-1); |
---|
| 2287 | x = uiCbf4; |
---|
| 2288 | y = m_uiBlkCBPTableD[n][cy]; |
---|
| 2289 | m_uiBlkCBPTableD[n][cy] = x; |
---|
| 2290 | m_uiBlkCBPTableD[n][cx] = y; |
---|
| 2291 | #endif |
---|
| 2292 | |
---|
| 2293 | #if CAVLC_RQT_CBP |
---|
| 2294 | if(n==0) |
---|
| 2295 | m_uiCBP_4Y_VlcIdx += cx == m_uiCBP_4Y_VlcIdx ? 0 : (cx < m_uiCBP_4Y_VlcIdx ? -1 : 1); |
---|
| 2296 | #else |
---|
| 2297 | if(n==0) |
---|
| 2298 | m_uiBlkCbpVlcIdx += cx == m_uiBlkCbpVlcIdx ? 0 : (cx < m_uiBlkCbpVlcIdx ? -1 : 1); |
---|
| 2299 | #endif |
---|
| 2300 | |
---|
| 2301 | uiCbf4++; |
---|
| 2302 | uiCbf = pcCU->getCbf( uiAbsPartIdx, eType ); |
---|
| 2303 | pcCU->setCbfSubParts( uiCbf | ( ((uiCbf4>>3)&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); uiAbsPartIdx += uiQPartNum; |
---|
| 2304 | uiCbf = pcCU->getCbf( uiAbsPartIdx, eType ); |
---|
| 2305 | pcCU->setCbfSubParts( uiCbf | ( ((uiCbf4>>2)&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); uiAbsPartIdx += uiQPartNum; |
---|
| 2306 | uiCbf = pcCU->getCbf( uiAbsPartIdx, eType ); |
---|
| 2307 | pcCU->setCbfSubParts( uiCbf | ( ((uiCbf4>>1)&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); uiAbsPartIdx += uiQPartNum; |
---|
| 2308 | uiCbf = pcCU->getCbf( uiAbsPartIdx, eType ); |
---|
| 2309 | pcCU->setCbfSubParts( uiCbf | ( (uiCbf4&0x01) << uiTrDepth ), eType, uiAbsPartIdx, uiDepth ); |
---|
| 2310 | |
---|
| 2311 | return; |
---|
| 2312 | } |
---|
| 2313 | |
---|
| 2314 | Void TDecCavlc::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
| 2315 | { |
---|
| 2316 | |
---|
| 2317 | if ( uiWidth > pcCU->getSlice()->getSPS()->getMaxTrSize() ) |
---|
| 2318 | { |
---|
| 2319 | uiWidth = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
| 2320 | uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize(); |
---|
| 2321 | } |
---|
| 2322 | UInt uiSize = uiWidth*uiHeight; |
---|
| 2323 | |
---|
| 2324 | // point to coefficient |
---|
| 2325 | TCoeff* piCoeff = pcCoef; |
---|
| 2326 | |
---|
| 2327 | // initialize scan |
---|
| 2328 | const UInt* pucScan; |
---|
| 2329 | |
---|
| 2330 | #if CAVLC_COEF_LRG_BLK |
---|
| 2331 | UInt maxBlSize = (eTType==TEXT_LUMA)? 32:8; |
---|
| 2332 | UInt uiBlSize = Min(maxBlSize,uiWidth); |
---|
| 2333 | UInt uiConvBit = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : uiBlSize]; |
---|
| 2334 | UInt uiNoCoeff = uiBlSize*uiBlSize; |
---|
| 2335 | #else |
---|
| 2336 | //UInt uiConvBit = g_aucConvertToBit[ Min(8,uiWidth) ]; |
---|
| 2337 | UInt uiConvBit = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth) ]; |
---|
| 2338 | #endif |
---|
| 2339 | pucScan = g_auiFrameScanXY [ uiConvBit + 1 ]; |
---|
| 2340 | |
---|
| 2341 | #if QC_MDCS |
---|
| 2342 | UInt uiBlkPos; |
---|
| 2343 | #if CAVLC_COEF_LRG_BLK |
---|
| 2344 | UInt uiLog2BlkSize = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : uiBlSize] + 2; |
---|
| 2345 | #else |
---|
| 2346 | UInt uiLog2BlkSize = g_aucConvertToBit[ pcCU->isIntra( uiAbsPartIdx ) ? uiWidth : Min(8,uiWidth) ] + 2; |
---|
| 2347 | #endif |
---|
| 2348 | const UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
| 2349 | #endif //QC_MDCS |
---|
| 2350 | |
---|
| 2351 | UInt uiDecodeDCCoeff = 0; |
---|
| 2352 | Int dcCoeff = 0; |
---|
| 2353 | if (pcCU->isIntra(uiAbsPartIdx)) |
---|
| 2354 | { |
---|
| 2355 | UInt uiAbsPartIdxL, uiAbsPartIdxA; |
---|
| 2356 | TComDataCU* pcCUL = pcCU->getPULeft (uiAbsPartIdxL, pcCU->getZorderIdxInCU() + uiAbsPartIdx); |
---|
| 2357 | TComDataCU* pcCUA = pcCU->getPUAbove(uiAbsPartIdxA, pcCU->getZorderIdxInCU() + uiAbsPartIdx); |
---|
| 2358 | if (pcCUL == NULL && pcCUA == NULL) |
---|
| 2359 | { |
---|
| 2360 | uiDecodeDCCoeff = 1; |
---|
| 2361 | dcCoeff = xReadVlc(eTType == TEXT_LUMA ? 3 : 1); |
---|
| 2362 | if (dcCoeff) |
---|
| 2363 | { |
---|
| 2364 | UInt sign; |
---|
| 2365 | xReadFlag(sign); |
---|
| 2366 | if (sign) |
---|
| 2367 | { |
---|
| 2368 | dcCoeff = -dcCoeff; |
---|
| 2369 | } |
---|
| 2370 | } |
---|
| 2371 | } |
---|
| 2372 | } |
---|
| 2373 | |
---|
| 2374 | UInt uiScanning; |
---|
| 2375 | |
---|
| 2376 | #if CAVLC_COEF_LRG_BLK |
---|
| 2377 | static TCoeff scoeff[1024]; |
---|
| 2378 | #else |
---|
| 2379 | TCoeff scoeff[64]; |
---|
| 2380 | #endif |
---|
| 2381 | Int iBlockType; |
---|
| 2382 | if( uiSize == 2*2 ) |
---|
| 2383 | { |
---|
| 2384 | // hack: re-use 4x4 coding |
---|
| 2385 | #if QC_MOD_LCEC |
---|
| 2386 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
| 2387 | iBlockType = eTType-2; |
---|
| 2388 | else |
---|
| 2389 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
| 2390 | #else |
---|
| 2391 | iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType(); |
---|
| 2392 | #endif |
---|
| 2393 | |
---|
| 2394 | #if CAVLC_COEF_LRG_BLK |
---|
| 2395 | xParseCoeff( scoeff, iBlockType, 4 ); |
---|
| 2396 | #else |
---|
| 2397 | xParseCoeff4x4( scoeff, iBlockType ); |
---|
| 2398 | #endif |
---|
| 2399 | |
---|
| 2400 | for (uiScanning=0; uiScanning<4; uiScanning++) |
---|
| 2401 | { |
---|
| 2402 | #if QC_MDCS |
---|
| 2403 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
| 2404 | piCoeff[ uiBlkPos ] = scoeff[15-uiScanning]; |
---|
| 2405 | #else |
---|
| 2406 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[15-uiScanning]; |
---|
| 2407 | #endif //QC_MDCS |
---|
| 2408 | } |
---|
| 2409 | } |
---|
| 2410 | else if ( uiSize == 4*4 ) |
---|
| 2411 | { |
---|
| 2412 | #if QC_MOD_LCEC |
---|
| 2413 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
| 2414 | iBlockType = eTType-2; |
---|
| 2415 | else |
---|
| 2416 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
| 2417 | #else |
---|
| 2418 | iBlockType = pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType(); |
---|
| 2419 | #endif |
---|
| 2420 | #if CAVLC_COEF_LRG_BLK |
---|
| 2421 | xParseCoeff( scoeff, iBlockType, 4 ); |
---|
| 2422 | #else |
---|
| 2423 | xParseCoeff4x4( scoeff, iBlockType ); |
---|
| 2424 | #endif |
---|
| 2425 | |
---|
| 2426 | for (uiScanning=0; uiScanning<16; uiScanning++) |
---|
| 2427 | { |
---|
| 2428 | #if QC_MDCS |
---|
| 2429 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
| 2430 | piCoeff[ uiBlkPos ] = scoeff[15-uiScanning]; |
---|
| 2431 | #else |
---|
| 2432 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[15-uiScanning]; |
---|
| 2433 | #endif //QC_MDCS |
---|
| 2434 | } |
---|
| 2435 | } |
---|
| 2436 | else if ( uiSize == 8*8 ) |
---|
| 2437 | { |
---|
| 2438 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) //8x8 specific |
---|
| 2439 | iBlockType = eTType-2; |
---|
| 2440 | else |
---|
| 2441 | iBlockType = 2 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
| 2442 | #if CAVLC_COEF_LRG_BLK |
---|
| 2443 | xParseCoeff( scoeff, iBlockType, 8 ); |
---|
| 2444 | #else |
---|
| 2445 | xParseCoeff8x8( scoeff, iBlockType ); |
---|
| 2446 | #endif |
---|
| 2447 | |
---|
| 2448 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
| 2449 | { |
---|
| 2450 | #if QC_MDCS |
---|
| 2451 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
| 2452 | piCoeff[ uiBlkPos ] = scoeff[63-uiScanning]; |
---|
| 2453 | #else |
---|
| 2454 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[63-uiScanning]; |
---|
| 2455 | #endif //QC_MDCS |
---|
| 2456 | } |
---|
| 2457 | |
---|
| 2458 | } |
---|
| 2459 | else |
---|
| 2460 | { |
---|
| 2461 | if (!pcCU->isIntra( uiAbsPartIdx )) |
---|
| 2462 | { |
---|
| 2463 | memset(piCoeff,0,sizeof(TCoeff)*uiSize); |
---|
| 2464 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
| 2465 | iBlockType = eTType-2; |
---|
| 2466 | else |
---|
| 2467 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
| 2468 | #if CAVLC_COEF_LRG_BLK |
---|
| 2469 | xParseCoeff( scoeff, iBlockType, uiBlSize ); |
---|
| 2470 | #else |
---|
| 2471 | xParseCoeff8x8( scoeff, iBlockType ); |
---|
| 2472 | #endif |
---|
| 2473 | |
---|
| 2474 | #if CAVLC_COEF_LRG_BLK |
---|
| 2475 | for (uiScanning=0; uiScanning<uiNoCoeff; uiScanning++) |
---|
| 2476 | { |
---|
| 2477 | #if QC_MDCS |
---|
| 2478 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
| 2479 | uiBlkPos = (uiBlkPos/uiBlSize)* uiWidth + (uiBlkPos&(uiBlSize-1)); |
---|
| 2480 | piCoeff[ uiBlkPos ] = scoeff[uiNoCoeff-uiScanning-1]; |
---|
| 2481 | #else |
---|
| 2482 | piCoeff[(pucScan[uiScanning]/uiBlSize)*uiWidth + (pucScan[uiScanning]&(uiBlSize-1))]=scoeff[uiNoCoeff-uiScanning-1]; |
---|
| 2483 | #endif |
---|
| 2484 | } |
---|
| 2485 | #else |
---|
| 2486 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
| 2487 | { |
---|
| 2488 | #if QC_MDCS |
---|
| 2489 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
| 2490 | uiBlkPos = (uiBlkPos/8)* uiWidth + uiBlkPos%8; |
---|
| 2491 | piCoeff[ uiBlkPos ] = scoeff[63-uiScanning]; |
---|
| 2492 | #else |
---|
| 2493 | piCoeff[(pucScan[uiScanning]/8)*uiWidth + (pucScan[uiScanning]%8)] = scoeff[63-uiScanning]; |
---|
| 2494 | #endif //QC_MDCS |
---|
| 2495 | } |
---|
| 2496 | #endif |
---|
| 2497 | return; |
---|
| 2498 | } |
---|
| 2499 | |
---|
| 2500 | if(pcCU->isIntra( uiAbsPartIdx )) |
---|
| 2501 | { |
---|
| 2502 | memset(piCoeff,0,sizeof(TCoeff)*uiSize); |
---|
| 2503 | |
---|
| 2504 | if (eTType==TEXT_CHROMA_U || eTType==TEXT_CHROMA_V) |
---|
| 2505 | iBlockType = eTType-2; |
---|
| 2506 | else |
---|
| 2507 | iBlockType = 5 + ( pcCU->isIntra(uiAbsPartIdx) ? 0 : pcCU->getSlice()->getSliceType() ); |
---|
| 2508 | |
---|
| 2509 | #if CAVLC_COEF_LRG_BLK |
---|
| 2510 | xParseCoeff( scoeff, iBlockType, uiBlSize ); |
---|
| 2511 | for (uiScanning=0; uiScanning<uiNoCoeff; uiScanning++) |
---|
| 2512 | { |
---|
| 2513 | #if QC_MDCS |
---|
| 2514 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
| 2515 | piCoeff[ uiBlkPos ] = scoeff[uiNoCoeff - uiScanning - 1]; |
---|
| 2516 | #else |
---|
| 2517 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[uiNoCoeff - uiScanning - 1]; |
---|
| 2518 | #endif //QC_MDCS |
---|
| 2519 | } |
---|
| 2520 | #else |
---|
| 2521 | xParseCoeff8x8( scoeff, iBlockType ); |
---|
| 2522 | |
---|
| 2523 | for (uiScanning=0; uiScanning<64; uiScanning++) |
---|
| 2524 | { |
---|
| 2525 | #if QC_MDCS |
---|
| 2526 | uiBlkPos = g_auiSigLastScan[uiScanIdx][uiLog2BlkSize-1][uiScanning]; |
---|
| 2527 | piCoeff[ uiBlkPos ] = scoeff[63-uiScanning]; |
---|
| 2528 | #else |
---|
| 2529 | piCoeff[ pucScan[ uiScanning ] ] = scoeff[63-uiScanning]; |
---|
| 2530 | #endif //QC_MDCS |
---|
| 2531 | } |
---|
| 2532 | #endif |
---|
| 2533 | } |
---|
| 2534 | } |
---|
| 2535 | |
---|
| 2536 | if (uiDecodeDCCoeff == 1) |
---|
| 2537 | { |
---|
| 2538 | piCoeff[0] = dcCoeff; |
---|
| 2539 | } |
---|
| 2540 | |
---|
| 2541 | return ; |
---|
| 2542 | } |
---|
| 2543 | |
---|
| 2544 | Void TDecCavlc::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) |
---|
| 2545 | { |
---|
| 2546 | xReadFlag( ruiSubdivFlag ); |
---|
| 2547 | } |
---|
| 2548 | |
---|
| 2549 | Void TDecCavlc::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) |
---|
| 2550 | { |
---|
| 2551 | UInt uiSymbol; |
---|
| 2552 | xReadFlag( uiSymbol ); |
---|
| 2553 | pcCU->setCbfSubParts( uiSymbol << uiTrDepth, eType, uiAbsPartIdx, uiDepth ); |
---|
| 2554 | } |
---|
| 2555 | |
---|
| 2556 | Void TDecCavlc::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf ) |
---|
| 2557 | { |
---|
| 2558 | UInt uiSymbol; |
---|
| 2559 | xReadFlag( uiSymbol ); |
---|
| 2560 | uiQtRootCbf = uiSymbol; |
---|
| 2561 | } |
---|
| 2562 | |
---|
| 2563 | Void TDecCavlc::parseAlfFlag (UInt& ruiVal) |
---|
| 2564 | { |
---|
| 2565 | xReadFlag( ruiVal ); |
---|
| 2566 | } |
---|
| 2567 | |
---|
| 2568 | #if TSB_ALF_HEADER |
---|
| 2569 | Void TDecCavlc::parseAlfFlagNum( UInt& ruiVal, UInt minValue, UInt depth ) |
---|
| 2570 | { |
---|
| 2571 | UInt uiLength = 0; |
---|
| 2572 | UInt maxValue = (minValue << (depth*2)); |
---|
| 2573 | UInt temp = maxValue - minValue; |
---|
| 2574 | for(UInt i=0; i<32; i++) |
---|
| 2575 | { |
---|
| 2576 | if(temp&0x1) |
---|
| 2577 | { |
---|
| 2578 | uiLength = i+1; |
---|
| 2579 | } |
---|
| 2580 | temp = (temp >> 1); |
---|
| 2581 | } |
---|
| 2582 | if(uiLength) |
---|
| 2583 | { |
---|
| 2584 | xReadCode( uiLength, ruiVal ); |
---|
| 2585 | } |
---|
| 2586 | else |
---|
| 2587 | { |
---|
| 2588 | ruiVal = 0; |
---|
| 2589 | } |
---|
| 2590 | ruiVal += minValue; |
---|
| 2591 | } |
---|
| 2592 | |
---|
| 2593 | Void TDecCavlc::parseAlfCtrlFlag( UInt &ruiAlfCtrlFlag ) |
---|
| 2594 | { |
---|
| 2595 | UInt uiSymbol; |
---|
| 2596 | xReadFlag( uiSymbol ); |
---|
| 2597 | ruiAlfCtrlFlag = uiSymbol; |
---|
| 2598 | } |
---|
| 2599 | #endif |
---|
| 2600 | |
---|
| 2601 | Void TDecCavlc::parseAlfUvlc (UInt& ruiVal) |
---|
| 2602 | { |
---|
| 2603 | xReadUvlc( ruiVal ); |
---|
| 2604 | } |
---|
| 2605 | |
---|
| 2606 | Void TDecCavlc::parseAlfSvlc (Int& riVal) |
---|
| 2607 | { |
---|
| 2608 | xReadSvlc( riVal ); |
---|
| 2609 | } |
---|
| 2610 | |
---|
| 2611 | |
---|
| 2612 | |
---|
| 2613 | #if MTK_SAO |
---|
| 2614 | Void TDecCavlc::parseAoFlag (UInt& ruiVal) |
---|
| 2615 | { |
---|
| 2616 | xReadFlag( ruiVal ); |
---|
| 2617 | } |
---|
| 2618 | Void TDecCavlc::parseAoUvlc (UInt& ruiVal) |
---|
| 2619 | { |
---|
| 2620 | xReadUvlc( ruiVal ); |
---|
| 2621 | } |
---|
| 2622 | |
---|
| 2623 | Void TDecCavlc::parseAoSvlc (Int& riVal) |
---|
| 2624 | { |
---|
| 2625 | xReadSvlc( riVal ); |
---|
| 2626 | } |
---|
| 2627 | #endif |
---|
| 2628 | |
---|
| 2629 | Void TDecCavlc::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
| 2630 | { |
---|
| 2631 | #if QC_LCEC_INTER_MODE |
---|
| 2632 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) |
---|
| 2633 | return; |
---|
| 2634 | #endif |
---|
| 2635 | UInt uiSymbol; |
---|
| 2636 | xReadFlag( uiSymbol ); |
---|
| 2637 | pcCU->setMergeFlagSubParts( uiSymbol ? true : false, uiAbsPartIdx, uiPUIdx, uiDepth ); |
---|
| 2638 | } |
---|
| 2639 | |
---|
| 2640 | |
---|
[5] | 2641 | #if HHI_INTER_VIEW_MOTION_PRED || HHI_MPI |
---|
[2] | 2642 | Void |
---|
| 2643 | TDecCavlc::parseMergeIndexMV( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 2644 | { |
---|
| 2645 | UInt uiNumCand = 0; |
---|
[5] | 2646 | #if HHI_MPI |
---|
[2] | 2647 | const Bool bMVIAvailable = pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE; |
---|
[5] | 2648 | const UInt uiMviMergePos = bMVIAvailable ? HHI_MPI_MERGE_POS : MRG_MAX_NUM_CANDS; |
---|
[2] | 2649 | if( bMVIAvailable ) |
---|
| 2650 | uiNumCand++; |
---|
| 2651 | #endif |
---|
| 2652 | for( UInt uiIdx = 0; uiIdx < MRG_MAX_NUM_CANDS; uiIdx++ ) |
---|
| 2653 | { |
---|
| 2654 | if( pcCU->getNeighbourCandIdx( uiIdx, uiAbsPartIdx ) == uiIdx + 1 ) |
---|
| 2655 | { |
---|
| 2656 | uiNumCand++; |
---|
| 2657 | } |
---|
| 2658 | } |
---|
| 2659 | AOF( uiNumCand > 1 ); |
---|
| 2660 | UInt uiUnaryIdx = 0; |
---|
| 2661 | for( ; uiUnaryIdx < uiNumCand - 1; uiUnaryIdx++ ) |
---|
| 2662 | { |
---|
| 2663 | UInt uiSymbol = 0; |
---|
| 2664 | xReadFlag( uiSymbol ); |
---|
| 2665 | if( uiSymbol == 0 ) |
---|
| 2666 | { |
---|
| 2667 | break; |
---|
| 2668 | } |
---|
| 2669 | } |
---|
| 2670 | ruiMergeIndex = uiUnaryIdx; |
---|
| 2671 | for( UInt uiIdx = 0; uiIdx <= ruiMergeIndex; uiIdx++ ) |
---|
| 2672 | { |
---|
[5] | 2673 | #if HHI_MPI |
---|
[2] | 2674 | if( uiIdx > uiMviMergePos ) |
---|
| 2675 | { |
---|
| 2676 | if( pcCU->getNeighbourCandIdx( uiIdx - 1, uiAbsPartIdx ) != uiIdx ) |
---|
| 2677 | { |
---|
| 2678 | ruiMergeIndex++; |
---|
| 2679 | } |
---|
| 2680 | } |
---|
| 2681 | else if( uiIdx < uiMviMergePos ) |
---|
| 2682 | #endif |
---|
| 2683 | if( pcCU->getNeighbourCandIdx( uiIdx, uiAbsPartIdx ) != uiIdx + 1 ) |
---|
| 2684 | { |
---|
| 2685 | ruiMergeIndex++; |
---|
| 2686 | } |
---|
| 2687 | } |
---|
[5] | 2688 | #if HHI_MPI |
---|
[2] | 2689 | if( ruiMergeIndex > uiMviMergePos ) |
---|
| 2690 | { |
---|
| 2691 | ruiMergeIndex--; |
---|
| 2692 | } |
---|
| 2693 | else if( ruiMergeIndex == uiMviMergePos ) |
---|
| 2694 | { |
---|
| 2695 | pcCU->setTextureModeDepthSubParts( uiDepth, uiAbsPartIdx, uiDepth ); |
---|
| 2696 | } |
---|
| 2697 | #endif |
---|
| 2698 | } |
---|
[5] | 2699 | #endif |
---|
[2] | 2700 | |
---|
| 2701 | |
---|
| 2702 | /** parse merge index |
---|
| 2703 | * \param pcCU |
---|
| 2704 | * \param ruiMergeIndex |
---|
| 2705 | * \param uiAbsPartIdx |
---|
| 2706 | * \param uiDepth |
---|
| 2707 | * \returns Void |
---|
| 2708 | */ |
---|
| 2709 | Void TDecCavlc::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 2710 | { |
---|
[5] | 2711 | #if HHI_INTER_VIEW_MOTION_PRED || HHI_MPI |
---|
| 2712 | if( |
---|
| 2713 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
| 2714 | ( pcCU->getSlice()->getSPS()->getViewId() > 0 && ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ) || |
---|
[2] | 2715 | #endif |
---|
[5] | 2716 | #if HHI_MPI |
---|
| 2717 | ( pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) || |
---|
| 2718 | #endif |
---|
| 2719 | 0 |
---|
| 2720 | ) |
---|
[2] | 2721 | { |
---|
| 2722 | parseMergeIndexMV( pcCU, ruiMergeIndex, uiAbsPartIdx, uiDepth ); |
---|
| 2723 | return; |
---|
| 2724 | } |
---|
[5] | 2725 | #endif |
---|
[2] | 2726 | |
---|
| 2727 | Bool bLeftInvolved = false; |
---|
| 2728 | Bool bAboveInvolved = false; |
---|
| 2729 | Bool bCollocatedInvolved = false; |
---|
| 2730 | Bool bCornerInvolved = false; |
---|
| 2731 | UInt uiNumCand = 0; |
---|
| 2732 | for( UInt uiIter = 0; uiIter < MRG_MAX_NUM_CANDS; ++uiIter ) |
---|
| 2733 | { |
---|
| 2734 | if( pcCU->getNeighbourCandIdx( uiIter, uiAbsPartIdx ) == uiIter + 1 ) |
---|
| 2735 | { |
---|
| 2736 | uiNumCand++; |
---|
| 2737 | if( uiIter == 0 ) |
---|
| 2738 | { |
---|
| 2739 | bLeftInvolved = true; |
---|
| 2740 | } |
---|
| 2741 | else if( uiIter == 1 ) |
---|
| 2742 | { |
---|
| 2743 | bAboveInvolved = true; |
---|
| 2744 | } |
---|
| 2745 | else if( uiIter == 2 ) |
---|
| 2746 | { |
---|
| 2747 | bCollocatedInvolved = true; |
---|
| 2748 | } |
---|
| 2749 | else if( uiIter == 3 ) |
---|
| 2750 | { |
---|
| 2751 | bCornerInvolved = true; |
---|
| 2752 | } |
---|
| 2753 | } |
---|
| 2754 | } |
---|
| 2755 | assert( uiNumCand > 1 ); |
---|
| 2756 | UInt uiUnaryIdx = 0; |
---|
| 2757 | for( ; uiUnaryIdx < uiNumCand - 1; ++uiUnaryIdx ) |
---|
| 2758 | { |
---|
| 2759 | UInt uiSymbol = 0; |
---|
| 2760 | xReadFlag( uiSymbol ); |
---|
| 2761 | if( uiSymbol == 0 ) |
---|
| 2762 | { |
---|
| 2763 | break; |
---|
| 2764 | } |
---|
| 2765 | } |
---|
| 2766 | if( !bLeftInvolved ) |
---|
| 2767 | { |
---|
| 2768 | ++uiUnaryIdx; |
---|
| 2769 | } |
---|
| 2770 | if( !bAboveInvolved && uiUnaryIdx >= 1 ) |
---|
| 2771 | { |
---|
| 2772 | ++uiUnaryIdx; |
---|
| 2773 | } |
---|
| 2774 | if( !bCollocatedInvolved && uiUnaryIdx >= 2 ) |
---|
| 2775 | { |
---|
| 2776 | ++uiUnaryIdx; |
---|
| 2777 | } |
---|
| 2778 | if( !bCornerInvolved && uiUnaryIdx >= 3 ) |
---|
| 2779 | { |
---|
| 2780 | ++uiUnaryIdx; |
---|
| 2781 | } |
---|
| 2782 | ruiMergeIndex = uiUnaryIdx; |
---|
| 2783 | } |
---|
| 2784 | |
---|
| 2785 | |
---|
| 2786 | Void |
---|
| 2787 | TDecCavlc::parseResPredFlag( TComDataCU* pcCU, Bool& rbResPredFlag, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 2788 | { |
---|
| 2789 | UInt uiSymbol = 0; |
---|
| 2790 | xReadFlag( uiSymbol ); |
---|
| 2791 | rbResPredFlag = ( uiSymbol != 0 ); |
---|
| 2792 | } |
---|
| 2793 | |
---|
| 2794 | |
---|
| 2795 | // ==================================================================================================================== |
---|
| 2796 | // Protected member functions |
---|
| 2797 | // ==================================================================================================================== |
---|
| 2798 | |
---|
| 2799 | Void TDecCavlc::xReadCode (UInt uiLength, UInt& ruiCode) |
---|
| 2800 | { |
---|
| 2801 | assert ( uiLength > 0 ); |
---|
| 2802 | m_pcBitstream->read (uiLength, ruiCode); |
---|
| 2803 | } |
---|
| 2804 | |
---|
| 2805 | Void TDecCavlc::xReadUvlc( UInt& ruiVal) |
---|
| 2806 | { |
---|
| 2807 | UInt uiVal = 0; |
---|
| 2808 | UInt uiCode = 0; |
---|
| 2809 | UInt uiLength; |
---|
| 2810 | m_pcBitstream->read( 1, uiCode ); |
---|
| 2811 | |
---|
| 2812 | if( 0 == uiCode ) |
---|
| 2813 | { |
---|
| 2814 | uiLength = 0; |
---|
| 2815 | |
---|
| 2816 | while( ! ( uiCode & 1 )) |
---|
| 2817 | { |
---|
| 2818 | m_pcBitstream->read( 1, uiCode ); |
---|
| 2819 | uiLength++; |
---|
| 2820 | } |
---|
| 2821 | |
---|
| 2822 | m_pcBitstream->read( uiLength, uiVal ); |
---|
| 2823 | |
---|
| 2824 | uiVal += (1 << uiLength)-1; |
---|
| 2825 | } |
---|
| 2826 | |
---|
| 2827 | ruiVal = uiVal; |
---|
| 2828 | } |
---|
| 2829 | |
---|
| 2830 | Void TDecCavlc::xReadSvlc( Int& riVal) |
---|
| 2831 | { |
---|
| 2832 | UInt uiBits = 0; |
---|
| 2833 | m_pcBitstream->read( 1, uiBits ); |
---|
| 2834 | if( 0 == uiBits ) |
---|
| 2835 | { |
---|
| 2836 | UInt uiLength = 0; |
---|
| 2837 | |
---|
| 2838 | while( ! ( uiBits & 1 )) |
---|
| 2839 | { |
---|
| 2840 | m_pcBitstream->read( 1, uiBits ); |
---|
| 2841 | uiLength++; |
---|
| 2842 | } |
---|
| 2843 | |
---|
| 2844 | m_pcBitstream->read( uiLength, uiBits ); |
---|
| 2845 | |
---|
| 2846 | uiBits += (1 << uiLength); |
---|
| 2847 | riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1); |
---|
| 2848 | } |
---|
| 2849 | else |
---|
| 2850 | { |
---|
| 2851 | riVal = 0; |
---|
| 2852 | } |
---|
| 2853 | } |
---|
| 2854 | |
---|
| 2855 | Void TDecCavlc::xReadFlag (UInt& ruiCode) |
---|
| 2856 | { |
---|
| 2857 | m_pcBitstream->read( 1, ruiCode ); |
---|
| 2858 | } |
---|
| 2859 | |
---|
| 2860 | Void TDecCavlc::xReadUnaryMaxSymbol( UInt& ruiSymbol, UInt uiMaxSymbol ) |
---|
| 2861 | { |
---|
| 2862 | if (uiMaxSymbol == 0) |
---|
| 2863 | { |
---|
| 2864 | ruiSymbol = 0; |
---|
| 2865 | return; |
---|
| 2866 | } |
---|
| 2867 | |
---|
| 2868 | xReadFlag( ruiSymbol ); |
---|
| 2869 | |
---|
| 2870 | if (ruiSymbol == 0 || uiMaxSymbol == 1) |
---|
| 2871 | { |
---|
| 2872 | return; |
---|
| 2873 | } |
---|
| 2874 | |
---|
| 2875 | UInt uiSymbol = 0; |
---|
| 2876 | UInt uiCont; |
---|
| 2877 | |
---|
| 2878 | do |
---|
| 2879 | { |
---|
| 2880 | xReadFlag( uiCont ); |
---|
| 2881 | uiSymbol++; |
---|
| 2882 | } |
---|
| 2883 | while( uiCont && (uiSymbol < uiMaxSymbol-1) ); |
---|
| 2884 | |
---|
| 2885 | if( uiCont && (uiSymbol == uiMaxSymbol-1) ) |
---|
| 2886 | { |
---|
| 2887 | uiSymbol++; |
---|
| 2888 | } |
---|
| 2889 | |
---|
| 2890 | ruiSymbol = uiSymbol; |
---|
| 2891 | } |
---|
| 2892 | |
---|
| 2893 | Void TDecCavlc::xReadExGolombLevel( UInt& ruiSymbol ) |
---|
| 2894 | { |
---|
| 2895 | UInt uiSymbol ; |
---|
| 2896 | UInt uiCount = 0; |
---|
| 2897 | do |
---|
| 2898 | { |
---|
| 2899 | xReadFlag( uiSymbol ); |
---|
| 2900 | uiCount++; |
---|
| 2901 | } |
---|
| 2902 | while( uiSymbol && (uiCount != 13)); |
---|
| 2903 | |
---|
| 2904 | ruiSymbol = uiCount-1; |
---|
| 2905 | |
---|
| 2906 | if( uiSymbol ) |
---|
| 2907 | { |
---|
| 2908 | xReadEpExGolomb( uiSymbol, 0 ); |
---|
| 2909 | ruiSymbol += uiSymbol+1; |
---|
| 2910 | } |
---|
| 2911 | |
---|
| 2912 | return; |
---|
| 2913 | } |
---|
| 2914 | |
---|
| 2915 | Void TDecCavlc::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount ) |
---|
| 2916 | { |
---|
| 2917 | UInt uiSymbol = 0; |
---|
| 2918 | UInt uiBit = 1; |
---|
| 2919 | |
---|
| 2920 | |
---|
| 2921 | while( uiBit ) |
---|
| 2922 | { |
---|
| 2923 | xReadFlag( uiBit ); |
---|
| 2924 | uiSymbol += uiBit << uiCount++; |
---|
| 2925 | } |
---|
| 2926 | |
---|
| 2927 | uiCount--; |
---|
| 2928 | while( uiCount-- ) |
---|
| 2929 | { |
---|
| 2930 | xReadFlag( uiBit ); |
---|
| 2931 | uiSymbol += uiBit << uiCount; |
---|
| 2932 | } |
---|
| 2933 | |
---|
| 2934 | ruiSymbol = uiSymbol; |
---|
| 2935 | |
---|
| 2936 | return; |
---|
| 2937 | } |
---|
| 2938 | |
---|
| 2939 | UInt TDecCavlc::xGetBit() |
---|
| 2940 | { |
---|
| 2941 | UInt ruiCode; |
---|
| 2942 | m_pcBitstream->read( 1, ruiCode ); |
---|
| 2943 | return ruiCode; |
---|
| 2944 | } |
---|
| 2945 | |
---|
| 2946 | Int TDecCavlc::xReadVlc( Int n ) |
---|
| 2947 | { |
---|
| 2948 | #if CAVLC_COEF_LRG_BLK |
---|
| 2949 | assert( n>=0 && n<=13 ); |
---|
| 2950 | #else |
---|
| 2951 | assert( n>=0 && n<=11 ); |
---|
| 2952 | #endif |
---|
| 2953 | |
---|
| 2954 | UInt zeroes=0, done=0, tmp; |
---|
| 2955 | UInt cw, bit; |
---|
| 2956 | UInt val = 0; |
---|
| 2957 | UInt first; |
---|
| 2958 | UInt lead = 0; |
---|
| 2959 | |
---|
| 2960 | if (n < 5) |
---|
| 2961 | { |
---|
| 2962 | while (!done && zeroes < 6) |
---|
| 2963 | { |
---|
| 2964 | xReadFlag( bit ); |
---|
| 2965 | if (bit) |
---|
| 2966 | { |
---|
| 2967 | if (n) |
---|
| 2968 | { |
---|
| 2969 | xReadCode( n, cw ); |
---|
| 2970 | } |
---|
| 2971 | else |
---|
| 2972 | { |
---|
| 2973 | cw = 0; |
---|
| 2974 | } |
---|
| 2975 | done = 1; |
---|
| 2976 | } |
---|
| 2977 | else |
---|
| 2978 | { |
---|
| 2979 | zeroes++; |
---|
| 2980 | } |
---|
| 2981 | } |
---|
| 2982 | if ( done ) |
---|
| 2983 | { |
---|
| 2984 | val = (zeroes<<n)+cw; |
---|
| 2985 | } |
---|
| 2986 | else |
---|
| 2987 | { |
---|
| 2988 | lead = n; |
---|
| 2989 | while (!done) |
---|
| 2990 | { |
---|
| 2991 | xReadFlag( first ); |
---|
| 2992 | if ( !first ) |
---|
| 2993 | { |
---|
| 2994 | lead++; |
---|
| 2995 | } |
---|
| 2996 | else |
---|
| 2997 | { |
---|
| 2998 | if ( lead ) |
---|
| 2999 | { |
---|
| 3000 | xReadCode( lead, tmp ); |
---|
| 3001 | } |
---|
| 3002 | else |
---|
| 3003 | { |
---|
| 3004 | tmp = 0; |
---|
| 3005 | } |
---|
| 3006 | val = 6 * (1 << n) + (1 << lead) + tmp - (1 << n); |
---|
| 3007 | done = 1; |
---|
| 3008 | } |
---|
| 3009 | } |
---|
| 3010 | } |
---|
| 3011 | } |
---|
| 3012 | else if (n < 8) |
---|
| 3013 | { |
---|
| 3014 | while (!done) |
---|
| 3015 | { |
---|
| 3016 | xReadFlag( bit ); |
---|
| 3017 | if ( bit ) |
---|
| 3018 | { |
---|
| 3019 | xReadCode( n-4, cw ); |
---|
| 3020 | done = 1; |
---|
| 3021 | } |
---|
| 3022 | else |
---|
| 3023 | { |
---|
| 3024 | zeroes++; |
---|
| 3025 | } |
---|
| 3026 | } |
---|
| 3027 | val = (zeroes<<(n-4))+cw; |
---|
| 3028 | } |
---|
| 3029 | else if (n == 8) |
---|
| 3030 | { |
---|
| 3031 | if ( xGetBit() ) |
---|
| 3032 | { |
---|
| 3033 | val = 0; |
---|
| 3034 | } |
---|
| 3035 | else if ( xGetBit() ) |
---|
| 3036 | { |
---|
| 3037 | val = 1; |
---|
| 3038 | } |
---|
| 3039 | else |
---|
| 3040 | { |
---|
| 3041 | val = 2; |
---|
| 3042 | } |
---|
| 3043 | } |
---|
| 3044 | else if (n == 9) |
---|
| 3045 | { |
---|
| 3046 | if ( xGetBit() ) |
---|
| 3047 | { |
---|
| 3048 | if ( xGetBit() ) |
---|
| 3049 | { |
---|
| 3050 | xReadCode(3, val); |
---|
| 3051 | val += 3; |
---|
| 3052 | } |
---|
| 3053 | else if ( xGetBit() ) |
---|
| 3054 | { |
---|
| 3055 | val = xGetBit() + 1; |
---|
| 3056 | } |
---|
| 3057 | else |
---|
| 3058 | { |
---|
| 3059 | val = 0; |
---|
| 3060 | } |
---|
| 3061 | } |
---|
| 3062 | else |
---|
| 3063 | { |
---|
| 3064 | while (!done) |
---|
| 3065 | { |
---|
| 3066 | xReadFlag( bit ); |
---|
| 3067 | if ( bit ) |
---|
| 3068 | { |
---|
| 3069 | xReadCode(4, cw); |
---|
| 3070 | done = 1; |
---|
| 3071 | } |
---|
| 3072 | else |
---|
| 3073 | { |
---|
| 3074 | zeroes++; |
---|
| 3075 | } |
---|
| 3076 | } |
---|
| 3077 | val = (zeroes<<4)+cw+11; |
---|
| 3078 | } |
---|
| 3079 | } |
---|
| 3080 | else if (n == 10) |
---|
| 3081 | { |
---|
| 3082 | while (!done) |
---|
| 3083 | { |
---|
| 3084 | xReadFlag( first ); |
---|
| 3085 | if ( !first ) |
---|
| 3086 | { |
---|
| 3087 | lead++; |
---|
| 3088 | } |
---|
| 3089 | else |
---|
| 3090 | { |
---|
| 3091 | if ( !lead ) |
---|
| 3092 | { |
---|
| 3093 | val = 0; |
---|
| 3094 | } |
---|
| 3095 | else |
---|
| 3096 | { |
---|
| 3097 | xReadCode(lead, val); |
---|
| 3098 | val += (1<<lead); |
---|
| 3099 | val--; |
---|
| 3100 | } |
---|
| 3101 | done = 1; |
---|
| 3102 | } |
---|
| 3103 | } |
---|
| 3104 | } |
---|
| 3105 | else if (n == 11) |
---|
| 3106 | { |
---|
| 3107 | UInt code; |
---|
| 3108 | xReadCode(3, val); |
---|
| 3109 | if(val) |
---|
| 3110 | { |
---|
| 3111 | xReadCode(1, code); |
---|
| 3112 | val = (val<<1)|code; |
---|
| 3113 | val--; |
---|
| 3114 | } |
---|
| 3115 | } |
---|
| 3116 | #if CAVLC_COEF_LRG_BLK |
---|
| 3117 | else if (n == 12) |
---|
| 3118 | { |
---|
| 3119 | while (!done) |
---|
| 3120 | { |
---|
| 3121 | m_pcBitstream->pseudoRead(32,val); |
---|
| 3122 | if (val) |
---|
| 3123 | { |
---|
| 3124 | tmp = 31; |
---|
| 3125 | while(!done) |
---|
| 3126 | { |
---|
| 3127 | if( val>>tmp ) |
---|
| 3128 | { |
---|
| 3129 | xReadCode(32-tmp, val); |
---|
| 3130 | lead += 31-tmp; |
---|
| 3131 | xReadCode(6, val); |
---|
| 3132 | val += (lead<<6); |
---|
| 3133 | done = 1; |
---|
| 3134 | } |
---|
| 3135 | tmp--; |
---|
| 3136 | } |
---|
| 3137 | } |
---|
| 3138 | else |
---|
| 3139 | { |
---|
| 3140 | xReadCode(32, val); |
---|
| 3141 | lead += 32; |
---|
| 3142 | } |
---|
| 3143 | } |
---|
| 3144 | } |
---|
| 3145 | else if (n == 13) |
---|
| 3146 | { |
---|
| 3147 | while (!done) |
---|
| 3148 | { |
---|
| 3149 | m_pcBitstream->pseudoRead(32,val); |
---|
| 3150 | if (val) |
---|
| 3151 | { |
---|
| 3152 | tmp = 31; |
---|
| 3153 | while(!done) |
---|
| 3154 | { |
---|
| 3155 | if(val>>tmp) |
---|
| 3156 | { |
---|
| 3157 | xReadCode(32-tmp, cw); |
---|
| 3158 | zeroes += 31-tmp; |
---|
| 3159 | xReadCode(4, cw); |
---|
| 3160 | done = 1; |
---|
| 3161 | } |
---|
| 3162 | tmp--; |
---|
| 3163 | } |
---|
| 3164 | } |
---|
| 3165 | else |
---|
| 3166 | { |
---|
| 3167 | xReadCode(32, val); |
---|
| 3168 | zeroes += 32; |
---|
| 3169 | } |
---|
| 3170 | } |
---|
| 3171 | val = (zeroes<<4)+cw; |
---|
| 3172 | } |
---|
| 3173 | #endif |
---|
| 3174 | |
---|
| 3175 | return val; |
---|
| 3176 | } |
---|
| 3177 | |
---|
| 3178 | #if !CAVLC_COEF_LRG_BLK |
---|
| 3179 | Void TDecCavlc::xParseCoeff4x4( TCoeff* scoeff, Int n ) |
---|
| 3180 | { |
---|
| 3181 | Int i; |
---|
| 3182 | UInt sign; |
---|
| 3183 | Int tmp; |
---|
| 3184 | Int vlc,cn,this_pos; |
---|
| 3185 | Int maxrun; |
---|
| 3186 | Int last_position; |
---|
| 3187 | Int atable[5] = {4,6,14,28,0xfffffff}; |
---|
| 3188 | Int vlc_adaptive=0; |
---|
| 3189 | Int done; |
---|
| 3190 | LastCoeffStruct combo; |
---|
| 3191 | |
---|
| 3192 | #if QC_MOD_LCEC |
---|
| 3193 | Int nTab; |
---|
| 3194 | Int tr1; |
---|
| 3195 | nTab=max(0,n-2); |
---|
| 3196 | #endif |
---|
| 3197 | |
---|
| 3198 | for (i = 0; i < 16; i++) |
---|
| 3199 | { |
---|
| 3200 | scoeff[i] = 0; |
---|
| 3201 | } |
---|
| 3202 | |
---|
| 3203 | { |
---|
| 3204 | /* Get the last nonzero coeff */ |
---|
| 3205 | Int x,y,cx,cy,vlcNum; |
---|
| 3206 | Int vlcTable[8] = {2,2,2}; |
---|
| 3207 | |
---|
| 3208 | /* Decode according to current LP table */ |
---|
| 3209 | #if QC_MOD_LCEC |
---|
| 3210 | vlcNum = vlcTable[nTab]; |
---|
| 3211 | tmp = xReadVlc( vlcNum ); |
---|
| 3212 | cn = m_uiLPTableD4[nTab][tmp]; |
---|
| 3213 | #else |
---|
| 3214 | vlcNum = vlcTable[n]; |
---|
| 3215 | |
---|
| 3216 | tmp = xReadVlc( vlcNum ); |
---|
| 3217 | cn = m_uiLPTableD4[n][tmp]; |
---|
| 3218 | #endif |
---|
| 3219 | combo.level = (cn>15); |
---|
| 3220 | combo.last_pos = cn&0x0f; |
---|
| 3221 | |
---|
| 3222 | /* Adapt LP table */ |
---|
| 3223 | cx = tmp; |
---|
| 3224 | cy = Max( 0, cx-1 ); |
---|
| 3225 | x = cn; |
---|
| 3226 | #if QC_MOD_LCEC |
---|
| 3227 | y = m_uiLPTableD4[nTab][cy]; |
---|
| 3228 | m_uiLPTableD4[nTab][cy] = x; |
---|
| 3229 | m_uiLPTableD4[nTab][cx] = y; |
---|
| 3230 | #else |
---|
| 3231 | y = m_uiLPTableD4[n][cy]; |
---|
| 3232 | m_uiLPTableD4[n][cy] = x; |
---|
| 3233 | m_uiLPTableD4[n][cx] = y; |
---|
| 3234 | #endif |
---|
| 3235 | } |
---|
| 3236 | |
---|
| 3237 | if ( combo.level == 1 ) |
---|
| 3238 | { |
---|
| 3239 | tmp = xReadVlc( 0 ); |
---|
| 3240 | sign = tmp&1; |
---|
| 3241 | tmp = (tmp>>1)+2; |
---|
| 3242 | } |
---|
| 3243 | else |
---|
| 3244 | { |
---|
| 3245 | tmp = 1; |
---|
| 3246 | xReadFlag( sign ); |
---|
| 3247 | } |
---|
| 3248 | |
---|
| 3249 | #if QC_MOD_LCEC |
---|
| 3250 | if (tmp>1) |
---|
| 3251 | { |
---|
| 3252 | tr1=0; |
---|
| 3253 | } |
---|
| 3254 | else |
---|
| 3255 | { |
---|
| 3256 | tr1=1; |
---|
| 3257 | } |
---|
| 3258 | #endif |
---|
| 3259 | |
---|
| 3260 | if ( sign ) |
---|
| 3261 | { |
---|
| 3262 | tmp = -tmp; |
---|
| 3263 | } |
---|
| 3264 | |
---|
| 3265 | last_position = combo.last_pos; |
---|
| 3266 | this_pos = 15 - last_position; |
---|
| 3267 | scoeff[this_pos] = tmp; |
---|
| 3268 | i = this_pos; |
---|
| 3269 | i++; |
---|
| 3270 | |
---|
| 3271 | done = 0; |
---|
| 3272 | { |
---|
| 3273 | while (!done && i < 16) |
---|
| 3274 | { |
---|
| 3275 | maxrun = 15-i; |
---|
| 3276 | #if QC_MOD_LCEC |
---|
| 3277 | if(n==2) |
---|
| 3278 | vlc = g_auiVlcTable8x8Intra[maxrun]; |
---|
| 3279 | else |
---|
| 3280 | vlc = g_auiVlcTable8x8Inter[maxrun]; |
---|
| 3281 | #else |
---|
| 3282 | if (maxrun > 27) |
---|
| 3283 | { |
---|
| 3284 | maxrun = 28; |
---|
| 3285 | vlc = 3; |
---|
| 3286 | } |
---|
| 3287 | else |
---|
| 3288 | { |
---|
| 3289 | vlc = g_auiVlcTable8x8[maxrun]; |
---|
| 3290 | } |
---|
| 3291 | #endif |
---|
| 3292 | |
---|
| 3293 | /* Go into run mode */ |
---|
| 3294 | cn = xReadVlc( vlc ); |
---|
| 3295 | #if QC_MOD_LCEC |
---|
| 3296 | if(n==2) |
---|
| 3297 | { |
---|
| 3298 | xRunLevelIndInv(&combo, maxrun, g_auiLumaRunTr14x4[tr1][maxrun], cn); |
---|
| 3299 | } |
---|
| 3300 | else |
---|
| 3301 | #endif |
---|
| 3302 | { |
---|
| 3303 | #if RUNLEVEL_TABLE_CUT |
---|
| 3304 | xRunLevelIndInterInv(&combo, maxrun, cn); |
---|
| 3305 | #else |
---|
| 3306 | combo = g_acstructLumaRun8x8[maxrun][cn]; |
---|
| 3307 | #endif |
---|
| 3308 | } |
---|
| 3309 | i += combo.last_pos; |
---|
| 3310 | /* No sign for last zeroes */ |
---|
| 3311 | if (i < 16) |
---|
| 3312 | { |
---|
| 3313 | if (combo.level == 1) |
---|
| 3314 | { |
---|
| 3315 | tmp = xReadVlc( 0 ); |
---|
| 3316 | sign = tmp&1; |
---|
| 3317 | tmp = (tmp>>1)+2; |
---|
| 3318 | done = 1; |
---|
| 3319 | } |
---|
| 3320 | else |
---|
| 3321 | { |
---|
| 3322 | tmp = 1; |
---|
| 3323 | xReadFlag( sign ); |
---|
| 3324 | } |
---|
| 3325 | if ( sign ) |
---|
| 3326 | { |
---|
| 3327 | tmp = -tmp; |
---|
| 3328 | } |
---|
| 3329 | scoeff[i] = tmp; |
---|
| 3330 | } |
---|
| 3331 | i++; |
---|
| 3332 | #if QC_MOD_LCEC |
---|
| 3333 | if (tr1>0 && tr1<MAX_TR1) |
---|
| 3334 | { |
---|
| 3335 | tr1++; |
---|
| 3336 | } |
---|
| 3337 | #endif |
---|
| 3338 | } |
---|
| 3339 | } |
---|
| 3340 | if (i < 16) |
---|
| 3341 | { |
---|
| 3342 | /* Get the rest in level mode */ |
---|
| 3343 | while ( i < 16 ) |
---|
| 3344 | { |
---|
| 3345 | tmp = xReadVlc( vlc_adaptive ); |
---|
| 3346 | if ( tmp > atable[vlc_adaptive] ) |
---|
| 3347 | { |
---|
| 3348 | vlc_adaptive++; |
---|
| 3349 | } |
---|
| 3350 | if ( tmp ) |
---|
| 3351 | { |
---|
| 3352 | xReadFlag( sign ); |
---|
| 3353 | if ( sign ) |
---|
| 3354 | { |
---|
| 3355 | tmp = -tmp; |
---|
| 3356 | } |
---|
| 3357 | } |
---|
| 3358 | scoeff[i] = tmp; |
---|
| 3359 | i++; |
---|
| 3360 | } |
---|
| 3361 | } |
---|
| 3362 | |
---|
| 3363 | return; |
---|
| 3364 | } |
---|
| 3365 | #endif |
---|
| 3366 | |
---|
| 3367 | #if QC_MOD_LCEC |
---|
| 3368 | |
---|
| 3369 | Void TDecCavlc::xRunLevelIndInv(LastCoeffStruct *combo, Int maxrun, UInt lrg1Pos, UInt cn) |
---|
| 3370 | { |
---|
| 3371 | int lev, run; |
---|
| 3372 | if (lrg1Pos>0) |
---|
| 3373 | { |
---|
| 3374 | if(cn < min(lrg1Pos, maxrun+2)) |
---|
| 3375 | { |
---|
| 3376 | lev = 0; |
---|
| 3377 | run = cn; |
---|
| 3378 | } |
---|
| 3379 | else if(cn < (maxrun<<1) + 4 - (Int)lrg1Pos) |
---|
| 3380 | { |
---|
| 3381 | if((cn+lrg1Pos)&1) |
---|
| 3382 | { |
---|
| 3383 | lev = 0; |
---|
| 3384 | run = (cn + lrg1Pos - 1) >> 1; |
---|
| 3385 | } |
---|
| 3386 | else |
---|
| 3387 | { |
---|
| 3388 | lev = 1; |
---|
| 3389 | run = (cn - lrg1Pos)>>1; |
---|
| 3390 | } |
---|
| 3391 | } |
---|
| 3392 | else |
---|
| 3393 | { |
---|
| 3394 | lev = 1; |
---|
| 3395 | run = cn - maxrun - 2; |
---|
| 3396 | } |
---|
| 3397 | } |
---|
| 3398 | else |
---|
| 3399 | { |
---|
| 3400 | if( cn & 1 ) |
---|
| 3401 | { |
---|
| 3402 | lev = 0; run = (cn-1)>>1; |
---|
| 3403 | } |
---|
| 3404 | else |
---|
| 3405 | { |
---|
| 3406 | run = cn >> 1; |
---|
| 3407 | lev = (run <= maxrun)?1:0; |
---|
| 3408 | } |
---|
| 3409 | } |
---|
| 3410 | combo->level = lev; |
---|
| 3411 | combo->last_pos = run; |
---|
| 3412 | } |
---|
| 3413 | |
---|
| 3414 | #if RUNLEVEL_TABLE_CUT |
---|
| 3415 | /** Function for deriving run and level value in CAVLC run-level coding |
---|
| 3416 | * \param combo pointer to a struct of run and level |
---|
| 3417 | * \param maxrun maximum length of run for a given coefficient location |
---|
| 3418 | * \param cn codeword index |
---|
| 3419 | * \returns |
---|
| 3420 | * This function derives run and level value in CAVLC run-level coding based on codeword index and maximum run value. |
---|
| 3421 | */ |
---|
| 3422 | Void TDecCavlc::xRunLevelIndInterInv(LastCoeffStruct *combo, Int maxrun, UInt cn) |
---|
| 3423 | { |
---|
| 3424 | if (maxrun<28) |
---|
| 3425 | { |
---|
| 3426 | if(cn > maxrun+1) |
---|
| 3427 | { |
---|
| 3428 | combo->level = 1; |
---|
| 3429 | combo->last_pos = g_acstructLumaRun8x8[maxrun][cn-maxrun-1]; |
---|
| 3430 | } |
---|
| 3431 | else |
---|
| 3432 | { |
---|
| 3433 | combo->level = 0; |
---|
| 3434 | combo->last_pos = g_acstructLumaRun8x8[maxrun][cn]; |
---|
| 3435 | } |
---|
| 3436 | } |
---|
| 3437 | else |
---|
| 3438 | { |
---|
| 3439 | if(cn<maxrun+2) |
---|
| 3440 | { |
---|
| 3441 | combo->level = 0; |
---|
| 3442 | combo->last_pos = cn; |
---|
| 3443 | } |
---|
| 3444 | else |
---|
| 3445 | { |
---|
| 3446 | combo->level = 1; |
---|
| 3447 | combo->last_pos = cn-maxrun-2; |
---|
| 3448 | } |
---|
| 3449 | } |
---|
| 3450 | } |
---|
| 3451 | #endif |
---|
| 3452 | #endif |
---|
| 3453 | |
---|
| 3454 | |
---|
| 3455 | #if !CAVLC_COEF_LRG_BLK |
---|
| 3456 | Void TDecCavlc::xParseCoeff8x8(TCoeff* scoeff, int n) |
---|
| 3457 | { |
---|
| 3458 | Int i; |
---|
| 3459 | UInt sign; |
---|
| 3460 | Int tmp; |
---|
| 3461 | LastCoeffStruct combo; |
---|
| 3462 | Int vlc,cn,this_pos; |
---|
| 3463 | Int maxrun; |
---|
| 3464 | Int last_position; |
---|
| 3465 | Int atable[5] = {4,6,14,28,0xfffffff}; |
---|
| 3466 | Int vlc_adaptive=0; |
---|
| 3467 | Int done; |
---|
| 3468 | #if QC_MOD_LCEC |
---|
| 3469 | Int tr1; |
---|
| 3470 | #endif |
---|
| 3471 | |
---|
| 3472 | static const Int switch_thr[10] = {49,49,0,49,49,0,49,49,49,49}; |
---|
| 3473 | Int sum_big_coef = 0; |
---|
| 3474 | |
---|
| 3475 | for (i = 0; i < 64; i++) |
---|
| 3476 | { |
---|
| 3477 | scoeff[i] = 0; |
---|
| 3478 | } |
---|
| 3479 | |
---|
| 3480 | /* Get the last nonzero coeff */ |
---|
| 3481 | { |
---|
| 3482 | Int x,y,cx,cy,vlcNum; |
---|
| 3483 | |
---|
| 3484 | /* Decode according to current LP table */ |
---|
| 3485 | // ADAPT_VLC_NUM |
---|
| 3486 | vlcNum = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])]; |
---|
| 3487 | tmp = xReadVlc( vlcNum ); |
---|
| 3488 | cn = m_uiLPTableD8[n][tmp]; |
---|
| 3489 | combo.level = (cn>63); |
---|
| 3490 | combo.last_pos = cn&0x3f; |
---|
| 3491 | |
---|
| 3492 | /* Adapt LP table */ |
---|
| 3493 | cx = tmp; |
---|
| 3494 | cy = Max(0,cx-1); |
---|
| 3495 | x = cn; |
---|
| 3496 | y = m_uiLPTableD8[n][cy]; |
---|
| 3497 | m_uiLPTableD8[n][cy] = x; |
---|
| 3498 | m_uiLPTableD8[n][cx] = y; |
---|
| 3499 | |
---|
| 3500 | // ADAPT_VLC_NUM |
---|
| 3501 | m_uiLastPosVlcIndex[n] += cx == m_uiLastPosVlcIndex[n] ? 0 : (cx < m_uiLastPosVlcIndex[n] ? -1 : 1); |
---|
| 3502 | } |
---|
| 3503 | |
---|
| 3504 | if (combo.level == 1) |
---|
| 3505 | { |
---|
| 3506 | tmp = xReadVlc( 0 ); |
---|
| 3507 | sign = tmp&1; |
---|
| 3508 | tmp = (tmp>>1)+2; |
---|
| 3509 | } |
---|
| 3510 | else |
---|
| 3511 | { |
---|
| 3512 | tmp = 1; |
---|
| 3513 | xReadFlag( sign ); |
---|
| 3514 | } |
---|
| 3515 | |
---|
| 3516 | #if QC_MOD_LCEC |
---|
| 3517 | if (tmp>1) |
---|
| 3518 | { |
---|
| 3519 | tr1=0; |
---|
| 3520 | } |
---|
| 3521 | else |
---|
| 3522 | { |
---|
| 3523 | tr1=1; |
---|
| 3524 | } |
---|
| 3525 | #endif |
---|
| 3526 | |
---|
| 3527 | if ( sign ) |
---|
| 3528 | { |
---|
| 3529 | tmp = -tmp; |
---|
| 3530 | } |
---|
| 3531 | |
---|
| 3532 | last_position = combo.last_pos; |
---|
| 3533 | this_pos = 63 - last_position; |
---|
| 3534 | scoeff[this_pos] = tmp; |
---|
| 3535 | i = this_pos; |
---|
| 3536 | i++; |
---|
| 3537 | |
---|
| 3538 | done = 0; |
---|
| 3539 | { |
---|
| 3540 | while (!done && i < 64) |
---|
| 3541 | { |
---|
| 3542 | maxrun = 63-i; |
---|
| 3543 | #if QC_MOD_LCEC |
---|
| 3544 | if (n == 2 || n == 5) |
---|
| 3545 | vlc = g_auiVlcTable8x8Intra[Min(maxrun,28)]; |
---|
| 3546 | else |
---|
| 3547 | vlc = g_auiVlcTable8x8Inter[Min(maxrun,28)]; |
---|
| 3548 | #else |
---|
| 3549 | if (maxrun > 27) |
---|
| 3550 | { |
---|
| 3551 | maxrun = 28; |
---|
| 3552 | vlc = 3; |
---|
| 3553 | } |
---|
| 3554 | else |
---|
| 3555 | { |
---|
| 3556 | vlc = g_auiVlcTable8x8[maxrun]; |
---|
| 3557 | } |
---|
| 3558 | #endif |
---|
| 3559 | |
---|
| 3560 | /* Go into run mode */ |
---|
| 3561 | cn = xReadVlc( vlc ); |
---|
| 3562 | #if QC_MOD_LCEC |
---|
| 3563 | if (n == 2 || n == 5) |
---|
| 3564 | xRunLevelIndInv(&combo, maxrun, g_auiLumaRunTr18x8[tr1][min(maxrun,28)], cn); |
---|
| 3565 | else |
---|
| 3566 | #if RUNLEVEL_TABLE_CUT |
---|
| 3567 | xRunLevelIndInterInv(&combo, maxrun, cn); |
---|
| 3568 | #else |
---|
| 3569 | combo = g_acstructLumaRun8x8[Min(maxrun,28)][cn]; |
---|
| 3570 | #endif |
---|
| 3571 | #else |
---|
| 3572 | combo = g_acstructLumaRun8x8[maxrun][cn]; |
---|
| 3573 | #endif |
---|
| 3574 | i += combo.last_pos; |
---|
| 3575 | /* No sign for last zeroes */ |
---|
| 3576 | if (i < 64) |
---|
| 3577 | { |
---|
| 3578 | if (combo.level == 1) |
---|
| 3579 | { |
---|
| 3580 | tmp = xReadVlc( 0 ); |
---|
| 3581 | sign = tmp&1; |
---|
| 3582 | tmp = (tmp>>1)+2; |
---|
| 3583 | |
---|
| 3584 | sum_big_coef += tmp; |
---|
| 3585 | if (i > switch_thr[n] || sum_big_coef > 2) |
---|
| 3586 | { |
---|
| 3587 | done = 1; |
---|
| 3588 | } |
---|
| 3589 | } |
---|
| 3590 | else |
---|
| 3591 | { |
---|
| 3592 | tmp = 1; |
---|
| 3593 | xReadFlag( sign ); |
---|
| 3594 | } |
---|
| 3595 | if ( sign ) |
---|
| 3596 | { |
---|
| 3597 | tmp = -tmp; |
---|
| 3598 | } |
---|
| 3599 | scoeff[i] = tmp; |
---|
| 3600 | } |
---|
| 3601 | i++; |
---|
| 3602 | #if QC_MOD_LCEC |
---|
| 3603 | if (tr1==0 || combo.level != 0) |
---|
| 3604 | { |
---|
| 3605 | tr1=0; |
---|
| 3606 | } |
---|
| 3607 | else if( tr1 < MAX_TR1) |
---|
| 3608 | { |
---|
| 3609 | tr1++; |
---|
| 3610 | } |
---|
| 3611 | #endif |
---|
| 3612 | } |
---|
| 3613 | } |
---|
| 3614 | if (i < 64) |
---|
| 3615 | { |
---|
| 3616 | /* Get the rest in level mode */ |
---|
| 3617 | while (i<64) |
---|
| 3618 | { |
---|
| 3619 | tmp = xReadVlc( vlc_adaptive ); |
---|
| 3620 | |
---|
| 3621 | if (tmp>atable[vlc_adaptive]) |
---|
| 3622 | { |
---|
| 3623 | vlc_adaptive++; |
---|
| 3624 | } |
---|
| 3625 | if (tmp) |
---|
| 3626 | { |
---|
| 3627 | xReadFlag( sign ); |
---|
| 3628 | if ( sign ) |
---|
| 3629 | { |
---|
| 3630 | tmp = -tmp; |
---|
| 3631 | } |
---|
| 3632 | } |
---|
| 3633 | scoeff[i] = tmp; |
---|
| 3634 | i++; |
---|
| 3635 | } |
---|
| 3636 | } |
---|
| 3637 | return; |
---|
| 3638 | } |
---|
| 3639 | #endif |
---|
| 3640 | |
---|
| 3641 | |
---|
| 3642 | #if CAVLC_COEF_LRG_BLK |
---|
| 3643 | /** Function for parsing a block of transform coeffcients in CAVLC. |
---|
| 3644 | * \param scoeff pointer to transform coefficient buffer |
---|
| 3645 | * \param n block type information, e.g. luma, chroma, intra, inter, etc. |
---|
| 3646 | * \param blSize block size |
---|
| 3647 | * \returns |
---|
| 3648 | * This function performs parsing for a block of transform coefficient in CAVLC. |
---|
| 3649 | */ |
---|
| 3650 | Void TDecCavlc::xParseCoeff(TCoeff* scoeff, int n, Int blSize) |
---|
| 3651 | { |
---|
| 3652 | static const Int switch_thr[10] = {49,49,0,49,49,0,49,49,49,49}; |
---|
| 3653 | Int i, noCoeff=blSize*blSize;; |
---|
| 3654 | UInt sign; |
---|
| 3655 | LastCoeffStruct combo; |
---|
| 3656 | Int cn, maxrun, tmprun; |
---|
| 3657 | Int atable[5] = {4,6,14,28,0xfffffff}; |
---|
| 3658 | Int done, tr1, tmp; |
---|
| 3659 | Int sum_big_coef = 0; |
---|
| 3660 | |
---|
| 3661 | memset(scoeff,0,sizeof(TCoeff)*noCoeff); |
---|
| 3662 | |
---|
| 3663 | /* Get the last nonzero coeff */ |
---|
| 3664 | if(blSize >=8 ) |
---|
| 3665 | { |
---|
| 3666 | /* Decode according to current LP table */ |
---|
| 3667 | // ADAPT_VLC_NUM |
---|
| 3668 | tmp = g_auiLastPosVlcNum[n][Min(16,m_uiLastPosVlcIndex[n])]; |
---|
| 3669 | cn = xReadVlc( tmp ); |
---|
| 3670 | xLastLevelIndInv(combo.level, combo.last_pos, blSize, cn); |
---|
| 3671 | |
---|
| 3672 | /* Adapt LP table */ |
---|
| 3673 | cn = (blSize==8)?cn:(cn>>2); |
---|
| 3674 | // ADAPT_VLC_NUM |
---|
| 3675 | m_uiLastPosVlcIndex[n] += cn == m_uiLastPosVlcIndex[n] ? 0 : (cn < m_uiLastPosVlcIndex[n] ? -1 : 1); |
---|
| 3676 | } |
---|
| 3677 | else |
---|
| 3678 | { |
---|
| 3679 | /* Get the last nonzero coeff */ |
---|
| 3680 | Int y,cy; |
---|
| 3681 | Int nTab = max(0,n-2); |
---|
| 3682 | |
---|
| 3683 | /* Decode according to current LP table */ |
---|
| 3684 | tmp = xReadVlc( 2 ); |
---|
| 3685 | cn = m_uiLPTableD4[nTab][tmp]; |
---|
| 3686 | combo.level = (cn>15)?1:0; |
---|
| 3687 | combo.last_pos = cn&0x0f; |
---|
| 3688 | |
---|
| 3689 | /* Adapt LP table */ |
---|
| 3690 | cy = Max( 0, tmp-1 ); |
---|
| 3691 | y = m_uiLPTableD4[nTab][cy]; |
---|
| 3692 | m_uiLPTableD4[nTab][cy] = cn; |
---|
| 3693 | m_uiLPTableD4[nTab][tmp] = y; |
---|
| 3694 | } |
---|
| 3695 | |
---|
| 3696 | if (combo.level == 1) |
---|
| 3697 | { |
---|
| 3698 | tmp = xReadVlc( 0 ); |
---|
| 3699 | sign = tmp&1; |
---|
| 3700 | tmp = (tmp>>1)+2; |
---|
| 3701 | tr1=0; |
---|
| 3702 | } |
---|
| 3703 | else |
---|
| 3704 | { |
---|
| 3705 | tmp = 1; |
---|
| 3706 | xReadFlag( sign ); |
---|
| 3707 | tr1=1; |
---|
| 3708 | } |
---|
| 3709 | |
---|
| 3710 | i = noCoeff - 1 - combo.last_pos; |
---|
| 3711 | scoeff[i++] = sign? -tmp:tmp; |
---|
| 3712 | |
---|
| 3713 | done = 0; |
---|
| 3714 | const UInt *vlcTable = (n == 2||n == 5)? ((blSize<=8)? g_auiVlcTable8x8Intra:g_auiVlcTable16x16Intra): |
---|
| 3715 | ((blSize<=8)? g_auiVlcTable8x8Inter:g_auiVlcTable16x16Inter); |
---|
| 3716 | const UInt **pLumaRunTr1 = (blSize==4)? g_pLumaRunTr14x4:g_pLumaRunTr18x8; |
---|
| 3717 | while (!done && i < noCoeff) |
---|
| 3718 | { |
---|
| 3719 | maxrun = noCoeff - 1 -i; |
---|
| 3720 | tmprun = min(maxrun,28); |
---|
| 3721 | tmp = vlcTable[tmprun]; |
---|
| 3722 | |
---|
| 3723 | /* Go into run mode */ |
---|
| 3724 | cn = xReadVlc( tmp ); |
---|
| 3725 | if (n == 2 || n == 5) |
---|
| 3726 | { |
---|
| 3727 | xRunLevelIndInv(&combo, maxrun, pLumaRunTr1[tr1][tmprun], cn); |
---|
| 3728 | } |
---|
| 3729 | else |
---|
| 3730 | { |
---|
| 3731 | xRunLevelIndInterInv(&combo, maxrun, cn); |
---|
| 3732 | } |
---|
| 3733 | |
---|
| 3734 | i += combo.last_pos; |
---|
| 3735 | if (i < noCoeff) |
---|
| 3736 | { |
---|
| 3737 | if (combo.level == 1) |
---|
| 3738 | { |
---|
| 3739 | tmp = xReadVlc( 0 ); |
---|
| 3740 | sign = tmp&1; |
---|
| 3741 | tmp = (tmp>>1)+2; |
---|
| 3742 | |
---|
| 3743 | sum_big_coef += tmp; |
---|
| 3744 | if (blSize==4 ||i > switch_thr[n] || sum_big_coef > 2) |
---|
| 3745 | { |
---|
| 3746 | done = 1; |
---|
| 3747 | } |
---|
| 3748 | } |
---|
| 3749 | else |
---|
| 3750 | { |
---|
| 3751 | tmp = 1; |
---|
| 3752 | xReadFlag( sign ); |
---|
| 3753 | } |
---|
| 3754 | scoeff[i++] = sign? -tmp:tmp; |
---|
| 3755 | } |
---|
| 3756 | |
---|
| 3757 | if (tr1==0 || combo.level != 0) |
---|
| 3758 | { |
---|
| 3759 | tr1=0; |
---|
| 3760 | } |
---|
| 3761 | else if( tr1 < MAX_TR1) |
---|
| 3762 | { |
---|
| 3763 | tr1++; |
---|
| 3764 | } |
---|
| 3765 | } |
---|
| 3766 | |
---|
| 3767 | if (i < noCoeff) |
---|
| 3768 | { |
---|
| 3769 | /* Get the rest in level mode */ |
---|
| 3770 | Int vlc_adaptive = 0; |
---|
| 3771 | while (i < noCoeff) |
---|
| 3772 | { |
---|
| 3773 | tmp = xReadVlc( vlc_adaptive ); |
---|
| 3774 | |
---|
| 3775 | if (tmp) |
---|
| 3776 | { |
---|
| 3777 | xReadFlag( sign ); |
---|
| 3778 | scoeff[i] = sign?-tmp:tmp; |
---|
| 3779 | if (tmp > atable[vlc_adaptive]) |
---|
| 3780 | { |
---|
| 3781 | vlc_adaptive++; |
---|
| 3782 | } |
---|
| 3783 | } |
---|
| 3784 | i++; |
---|
| 3785 | } |
---|
| 3786 | } |
---|
| 3787 | |
---|
| 3788 | return; |
---|
| 3789 | } |
---|
| 3790 | |
---|
| 3791 | #endif |
---|
| 3792 | |
---|
| 3793 | #ifdef WEIGHT_PRED |
---|
| 3794 | Void TDecCavlc::parseWeightPredTable( TComSlice* pcSlice ) |
---|
| 3795 | { |
---|
| 3796 | wpScalingParam *wp; |
---|
| 3797 | Bool bChroma = true; // color always present in HEVC ? |
---|
| 3798 | TComPPS* pps = pcSlice->getPPS(); |
---|
| 3799 | SliceType eSliceType = pcSlice->getSliceType(); |
---|
| 3800 | Int nbRef = (eSliceType == B_SLICE ) ? (2) : (1); |
---|
| 3801 | UInt uiLog2WeightDenomLuma, uiLog2WeightDenomChroma; |
---|
| 3802 | UInt uiMode = 0; |
---|
| 3803 | |
---|
| 3804 | if ( (eSliceType==P_SLICE && pps->getUseWP()) || (eSliceType==B_SLICE && pps->getWPBiPredIdc()==1) ) |
---|
| 3805 | uiMode = 1; |
---|
| 3806 | else if ( eSliceType==B_SLICE && pps->getWPBiPredIdc()==2 ) |
---|
| 3807 | uiMode = 2; |
---|
| 3808 | |
---|
| 3809 | if ( uiMode == 1 ) // explicit |
---|
| 3810 | { |
---|
| 3811 | printf("\nTDecCavlc::parseWeightPredTable(poc=%d) explicit...\n", pcSlice->getPOC()); |
---|
| 3812 | |
---|
| 3813 | // decode luma_log2_weight_denom : |
---|
| 3814 | xReadUvlc( uiLog2WeightDenomLuma ); // ue(v): luma_log2_weight_denom |
---|
| 3815 | if( bChroma ) { // color always present in HEVC ? |
---|
| 3816 | xReadUvlc( uiLog2WeightDenomChroma ); // ue(v): chroma_log2_weight_denom |
---|
| 3817 | } |
---|
| 3818 | |
---|
| 3819 | for ( Int numRef=0 ; numRef<nbRef ; numRef++ ) { |
---|
| 3820 | RefPicList eRefPicList = ( numRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
| 3821 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) { |
---|
| 3822 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
| 3823 | |
---|
| 3824 | wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma; |
---|
| 3825 | wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma; |
---|
| 3826 | wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma; |
---|
| 3827 | |
---|
| 3828 | UInt uiCode; |
---|
| 3829 | xReadFlag( uiCode ); // u(1): luma_weight_l0_flag |
---|
| 3830 | wp[0].bPresentFlag = ( uiCode == 1 ); |
---|
| 3831 | if ( wp[0].bPresentFlag ) { |
---|
| 3832 | xReadSvlc( wp[0].iWeight ); // se(v): luma_weight_l0[i] |
---|
| 3833 | xReadSvlc( wp[0].iOffset ); // se(v): luma_offset_l0[i] |
---|
| 3834 | } |
---|
| 3835 | else { |
---|
| 3836 | wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom); |
---|
| 3837 | wp[0].iOffset = 0; |
---|
| 3838 | } |
---|
| 3839 | if ( bChroma ) { |
---|
| 3840 | xReadFlag( uiCode ); // u(1): chroma_weight_l0_flag |
---|
| 3841 | wp[1].bPresentFlag = ( uiCode == 1 ); |
---|
| 3842 | wp[2].bPresentFlag = ( uiCode == 1 ); |
---|
| 3843 | if ( wp[1].bPresentFlag ) { |
---|
| 3844 | for ( Int j=1 ; j<3 ; j++ ) { |
---|
| 3845 | xReadSvlc( wp[j].iWeight ); // se(v): chroma_weight_l0[i][j] |
---|
| 3846 | xReadSvlc( wp[j].iOffset ); // se(v): chroma_offset_l0[i][j] |
---|
| 3847 | } |
---|
| 3848 | } |
---|
| 3849 | else { |
---|
| 3850 | for ( Int j=1 ; j<3 ; j++ ) { |
---|
| 3851 | wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom); |
---|
| 3852 | wp[j].iOffset = 0; |
---|
| 3853 | } |
---|
| 3854 | } |
---|
| 3855 | } |
---|
| 3856 | } |
---|
| 3857 | |
---|
| 3858 | // Just for displayWpScaling(): |
---|
| 3859 | for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) { |
---|
| 3860 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
| 3861 | |
---|
| 3862 | wp[0].bPresentFlag = false; |
---|
| 3863 | wp[1].bPresentFlag = false; |
---|
| 3864 | wp[2].bPresentFlag = false; |
---|
| 3865 | } |
---|
| 3866 | |
---|
| 3867 | } |
---|
| 3868 | |
---|
| 3869 | } |
---|
| 3870 | else if ( uiMode == 2 ) // implicit |
---|
| 3871 | { |
---|
| 3872 | printf("\nTDecCavlc::parseWeightPredTable(poc=%d) implicit...\n", pcSlice->getPOC()); |
---|
| 3873 | } |
---|
| 3874 | else |
---|
| 3875 | assert(0); |
---|
| 3876 | } |
---|
| 3877 | #endif |
---|