[5] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[56] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[56] | 6 | * Copyright (c) 2010-2012, ITU/ISO/IEC |
---|
[5] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
[2] | 33 | |
---|
| 34 | /** \file TEncSbac.cpp |
---|
| 35 | \brief SBAC encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TEncTop.h" |
---|
| 39 | #include "TEncSbac.h" |
---|
| 40 | |
---|
| 41 | #include <map> |
---|
[56] | 42 | #include <algorithm> |
---|
[2] | 43 | |
---|
[189] | 44 | #if RWTH_SDC_DLT_B0036 |
---|
| 45 | #define GetNumDepthValues() (pcCU->getSlice()->getSPS()->getNumDepthValues()) |
---|
| 46 | #define GetBitsPerDepthValue() (pcCU->getSlice()->getSPS()->getBitsPerDepthValue()) |
---|
| 47 | #endif |
---|
| 48 | |
---|
[56] | 49 | //! \ingroup TLibEncoder |
---|
| 50 | //! \{ |
---|
[2] | 51 | |
---|
| 52 | // ==================================================================================================================== |
---|
| 53 | // Constructor / destructor / create / destroy |
---|
| 54 | // ==================================================================================================================== |
---|
| 55 | |
---|
| 56 | TEncSbac::TEncSbac() |
---|
| 57 | // new structure here |
---|
| 58 | : m_pcBitIf ( NULL ) |
---|
| 59 | , m_pcSlice ( NULL ) |
---|
| 60 | , m_pcBinIf ( NULL ) |
---|
| 61 | , m_bAlfCtrl ( false ) |
---|
| 62 | , m_uiCoeffCost ( 0 ) |
---|
| 63 | , m_uiMaxAlfCtrlDepth ( 0 ) |
---|
[56] | 64 | , m_numContextModels ( 0 ) |
---|
| 65 | , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels ) |
---|
| 66 | , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[189] | 67 | #if LGE_ILLUCOMP_B0045 |
---|
| 68 | , m_cCUICFlagSCModel ( 1, 1, NUM_IC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 69 | #endif |
---|
[56] | 70 | , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 71 | , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 72 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
| 73 | , m_cResPredFlagSCModel ( 1, 1, NUM_RES_PRED_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[2] | 74 | #endif |
---|
[56] | 75 | , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 76 | , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 77 | , m_cCUAlfCtrlFlagSCModel ( 1, 1, NUM_ALF_CTRL_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 78 | , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 79 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 80 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 81 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 82 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 83 | , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 84 | , m_cCUQtCbfSCModel ( 1, 2, NUM_QT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 85 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 86 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 87 | , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 88 | , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 89 | , m_cCuCtxLastX ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 90 | , m_cCuCtxLastY ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 91 | , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 92 | , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 93 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 94 | , m_cALFFlagSCModel ( 1, 1, NUM_ALF_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 95 | , m_cALFUvlcSCModel ( 1, 1, NUM_ALF_UVLC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 96 | , m_cALFSvlcSCModel ( 1, 1, NUM_ALF_SVLC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 97 | #if AMP_CTX |
---|
| 98 | , m_cCUAMPSCModel ( 1, 1, NUM_CU_AMP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[2] | 99 | #else |
---|
[56] | 100 | , m_cCUXPosiSCModel ( 1, 1, NUM_CU_X_POS_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 101 | , m_cCUYPosiSCModel ( 1, 1, NUM_CU_Y_POS_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[2] | 102 | #endif |
---|
[56] | 103 | , m_cSaoFlagSCModel ( 1, 1, NUM_SAO_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 104 | , m_cSaoUvlcSCModel ( 1, 1, NUM_SAO_UVLC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 105 | , m_cSaoSvlcSCModel ( 1, 1, NUM_SAO_SVLC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 106 | #if SAO_UNIT_INTERLEAVING |
---|
| 107 | , m_cSaoMergeLeftSCModel ( 1, 1, NUM_SAO_MERGE_LEFT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 108 | , m_cSaoMergeUpSCModel ( 1, 1, NUM_SAO_MERGE_UP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 109 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[2] | 110 | #endif |
---|
[5] | 111 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[56] | 112 | , m_cDmmFlagSCModel ( 1, 1, NUM_DMM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 113 | , m_cDmmModeSCModel ( 1, 1, NUM_DMM_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 114 | , m_cDmmDataSCModel ( 1, 1, NUM_DMM_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[2] | 115 | #endif |
---|
[189] | 116 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 117 | , m_cEdgeIntraSCModel ( 1, 1, NUM_EDGE_INTRA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 118 | #if LGE_EDGE_INTRA_DELTA_DC |
---|
| 119 | , m_cEdgeIntraDeltaDCSCModel ( 1, 1, NUM_EDGE_INTRA_DELTA_DC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 120 | #endif |
---|
| 121 | #endif |
---|
[189] | 122 | #if RWTH_SDC_DLT_B0036 |
---|
| 123 | , m_cSDCFlagSCModel ( 1, 1, SDC_NUM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 124 | , m_cSDCResidualFlagSCModel ( 1, 2, SDC_NUM_RESIDUAL_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 125 | , m_cSDCResidualSignFlagSCModel ( 1, 2, SDC_NUM_SIGN_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 126 | , m_cSDCResidualSCModel ( 1, 2, SDC_NUM_RESIDUAL_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 127 | , m_cSDCPredModeSCModel ( 1, 3, SDC_NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 128 | #endif |
---|
[2] | 129 | { |
---|
[56] | 130 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
| 131 | m_iSliceGranularity = 0; |
---|
[2] | 132 | } |
---|
| 133 | |
---|
| 134 | TEncSbac::~TEncSbac() |
---|
| 135 | { |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | // ==================================================================================================================== |
---|
| 139 | // Public member functions |
---|
| 140 | // ==================================================================================================================== |
---|
| 141 | |
---|
| 142 | Void TEncSbac::resetEntropy () |
---|
| 143 | { |
---|
| 144 | Int iQp = m_pcSlice->getSliceQp(); |
---|
| 145 | SliceType eSliceType = m_pcSlice->getSliceType(); |
---|
| 146 | |
---|
[56] | 147 | #if CABAC_INIT_FLAG |
---|
| 148 | Int encCABACTableIdx = m_pcSlice->getPPS()->getEncCABACTableIdx(); |
---|
| 149 | if (!m_pcSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && m_pcSlice->getPPS()->getCabacInitPresentFlag()) |
---|
| 150 | { |
---|
| 151 | eSliceType = (SliceType) encCABACTableIdx; |
---|
| 152 | } |
---|
| 153 | #endif |
---|
| 154 | |
---|
| 155 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
[2] | 156 | |
---|
[56] | 157 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
[189] | 158 | #if LGE_ILLUCOMP_B0045 |
---|
| 159 | m_cCUICFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_IC_FLAG ); |
---|
| 160 | #endif |
---|
[56] | 161 | m_cCUAlfCtrlFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_CTRL_FLAG ); |
---|
| 162 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
| 163 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
| 164 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
| 165 | m_cResPredFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RES_PRED_FLAG ); |
---|
[2] | 166 | #endif |
---|
[56] | 167 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
| 168 | #if AMP_CTX |
---|
| 169 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
[2] | 170 | #else |
---|
[56] | 171 | m_cCUXPosiSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_X_POS ); |
---|
| 172 | m_cCUYPosiSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_Y_POS ); |
---|
[2] | 173 | #endif |
---|
[56] | 174 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
| 175 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
| 176 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
| 177 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
| 178 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
| 179 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
| 180 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
| 181 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
| 182 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
| 183 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
| 184 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
| 185 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 186 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 187 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
| 188 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
| 189 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
| 190 | m_cALFFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_FLAG ); |
---|
| 191 | m_cALFUvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_UVLC ); |
---|
| 192 | m_cALFSvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_SVLC ); |
---|
| 193 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
| 194 | m_cSaoFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_FLAG ); |
---|
| 195 | m_cSaoUvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_UVLC ); |
---|
| 196 | m_cSaoSvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_SVLC ); |
---|
| 197 | #if SAO_UNIT_INTERLEAVING |
---|
| 198 | m_cSaoMergeLeftSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG ); |
---|
| 199 | m_cSaoMergeUpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_UP_FLAG ); |
---|
| 200 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
[2] | 201 | #endif |
---|
[5] | 202 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[56] | 203 | m_cDmmFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM_FLAG ); |
---|
| 204 | m_cDmmModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM_MODE ); |
---|
| 205 | m_cDmmDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM_DATA ); |
---|
[2] | 206 | #endif |
---|
[189] | 207 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 208 | m_cEdgeIntraSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_EDGE_INTRA ); |
---|
| 209 | #if LGE_EDGE_INTRA_DELTA_DC |
---|
| 210 | m_cEdgeIntraDeltaDCSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_EDGE_INTRA_DELTA_DC ); |
---|
| 211 | #endif |
---|
| 212 | #endif |
---|
[189] | 213 | #if RWTH_SDC_DLT_B0036 |
---|
| 214 | m_cSDCFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG ); |
---|
| 215 | m_cSDCResidualFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG ); |
---|
| 216 | m_cSDCResidualSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL ); |
---|
| 217 | m_cSDCResidualSignFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_SIGN_FLAG ); |
---|
| 218 | m_cSDCPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_PRED_MODE ); |
---|
| 219 | #endif |
---|
[2] | 220 | |
---|
| 221 | // new structure |
---|
| 222 | m_uiLastQp = iQp; |
---|
| 223 | |
---|
| 224 | m_pcBinIf->start(); |
---|
| 225 | |
---|
| 226 | return; |
---|
| 227 | } |
---|
| 228 | |
---|
[56] | 229 | #if CABAC_INIT_FLAG |
---|
| 230 | /** The function does the following: |
---|
| 231 | * If current slice type is P/B then it determines the distance of initialisation type 1 and 2 from the current CABAC states and |
---|
| 232 | * stores the index of the closest table. This index is used for the next P/B slice when cabac_init_present_flag is true. |
---|
| 233 | */ |
---|
| 234 | Void TEncSbac::determineCabacInitIdx() |
---|
| 235 | { |
---|
| 236 | Int qp = m_pcSlice->getSliceQp(); |
---|
| 237 | |
---|
| 238 | if (!m_pcSlice->isIntra()) |
---|
| 239 | { |
---|
| 240 | SliceType aSliceTypeChoices[] = {B_SLICE, P_SLICE}; |
---|
| 241 | |
---|
| 242 | UInt bestCost = MAX_UINT; |
---|
| 243 | SliceType bestSliceType = aSliceTypeChoices[0]; |
---|
| 244 | for (UInt idx=0; idx<2; idx++) |
---|
| 245 | { |
---|
| 246 | UInt curCost = 0; |
---|
| 247 | SliceType curSliceType = aSliceTypeChoices[idx]; |
---|
| 248 | |
---|
| 249 | curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
| 250 | curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
[189] | 251 | #if LGE_ILLUCOMP_B0045 |
---|
| 252 | curCost += m_cCUICFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_IC_FLAG ); |
---|
| 253 | #endif |
---|
[56] | 254 | curCost += m_cCUAlfCtrlFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ALF_CTRL_FLAG ); |
---|
| 255 | curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
| 256 | curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
| 257 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
| 258 | curCost += m_cResPredFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_RES_PRED_FLAG); |
---|
| 259 | #endif |
---|
| 260 | curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); |
---|
| 261 | #if AMP_CTX |
---|
| 262 | curCost += m_cCUAMPSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_AMP_POS ); |
---|
[42] | 263 | #else |
---|
[56] | 264 | curCost += m_cCUXPosiSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_X_POS ); |
---|
| 265 | curCost += m_cCUYPosiSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_Y_POS ); |
---|
[42] | 266 | #endif |
---|
[56] | 267 | curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); |
---|
| 268 | curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
| 269 | curCost += m_cCUChromaPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
| 270 | curCost += m_cCUInterDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTER_DIR ); |
---|
| 271 | curCost += m_cCUMvdSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVD ); |
---|
| 272 | curCost += m_cCURefPicSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_REF_PIC ); |
---|
| 273 | curCost += m_cCUDeltaQpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DQP ); |
---|
| 274 | curCost += m_cCUQtCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_CBF ); |
---|
| 275 | curCost += m_cCUQtRootCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
| 276 | curCost += m_cCUSigCoeffGroupSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
| 277 | curCost += m_cCUSigSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_FLAG ); |
---|
| 278 | curCost += m_cCuCtxLastX.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
| 279 | curCost += m_cCuCtxLastY.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
| 280 | curCost += m_cCUOneSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ONE_FLAG ); |
---|
| 281 | curCost += m_cCUAbsSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ABS_FLAG ); |
---|
| 282 | curCost += m_cMVPIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVP_IDX ); |
---|
| 283 | curCost += m_cALFFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ALF_FLAG ); |
---|
| 284 | curCost += m_cALFUvlcSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ALF_UVLC ); |
---|
| 285 | curCost += m_cALFSvlcSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ALF_SVLC ); |
---|
| 286 | curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
| 287 | curCost += m_cSaoFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_FLAG ); |
---|
| 288 | curCost += m_cSaoUvlcSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_UVLC ); |
---|
| 289 | curCost += m_cSaoSvlcSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_SVLC ); |
---|
| 290 | #if SAO_UNIT_INTERLEAVING |
---|
| 291 | curCost += m_cSaoMergeLeftSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG ); |
---|
| 292 | curCost += m_cSaoMergeUpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_UP_FLAG ); |
---|
| 293 | curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
| 294 | #endif |
---|
| 295 | |
---|
| 296 | if (curCost < bestCost) |
---|
| 297 | { |
---|
| 298 | bestSliceType = curSliceType; |
---|
| 299 | bestCost = curCost; |
---|
| 300 | } |
---|
| 301 | } |
---|
| 302 | m_pcSlice->getPPS()->setEncCABACTableIdx( bestSliceType ); |
---|
| 303 | } |
---|
| 304 | else |
---|
| 305 | { |
---|
| 306 | m_pcSlice->getPPS()->setEncCABACTableIdx( I_SLICE ); |
---|
| 307 | } |
---|
[101] | 308 | |
---|
[189] | 309 | #if CABAC_INIT_FLAG && FIX_POZNAN_CABAC_INIT_FLAG |
---|
[101] | 310 | m_pcSlice->getPPS()->setEncPrevPOC( m_pcSlice->getPOC() ); |
---|
| 311 | #endif |
---|
[56] | 312 | } |
---|
| 313 | #endif |
---|
| 314 | |
---|
| 315 | |
---|
| 316 | /** The function does the followng: Write out terminate bit. Flush CABAC. Intialize CABAC states. Start CABAC. |
---|
| 317 | */ |
---|
| 318 | Void TEncSbac::updateContextTables( SliceType eSliceType, Int iQp, Bool bExecuteFinish ) |
---|
[2] | 319 | { |
---|
[56] | 320 | m_pcBinIf->encodeBinTrm(1); |
---|
| 321 | if (bExecuteFinish) m_pcBinIf->finish(); |
---|
| 322 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
| 323 | |
---|
| 324 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
[189] | 325 | #if LGE_ILLUCOMP_B0045 |
---|
| 326 | m_cCUICFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_IC_FLAG ); |
---|
| 327 | #endif |
---|
[56] | 328 | m_cCUAlfCtrlFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_CTRL_FLAG ); |
---|
| 329 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
| 330 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
| 331 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
| 332 | m_cResPredFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RES_PRED_FLAG ); |
---|
| 333 | #endif |
---|
| 334 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
| 335 | #if AMP_CTX |
---|
| 336 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
| 337 | #else |
---|
| 338 | m_cCUXPosiSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_X_POS ); |
---|
| 339 | m_cCUYPosiSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_Y_POS ); |
---|
| 340 | #endif |
---|
| 341 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
| 342 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
| 343 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
| 344 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
| 345 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
| 346 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
| 347 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
| 348 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
| 349 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
| 350 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
| 351 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
| 352 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 353 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 354 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
| 355 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
| 356 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
| 357 | m_cALFFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_FLAG ); |
---|
| 358 | m_cALFUvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_UVLC ); |
---|
| 359 | m_cALFSvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_SVLC ); |
---|
| 360 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
| 361 | m_cSaoFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_FLAG ); |
---|
| 362 | m_cSaoUvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_UVLC ); |
---|
| 363 | m_cSaoSvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_SVLC ); |
---|
| 364 | #if SAO_UNIT_INTERLEAVING |
---|
| 365 | m_cSaoMergeLeftSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG ); |
---|
| 366 | m_cSaoMergeUpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_UP_FLAG ); |
---|
| 367 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
| 368 | #endif |
---|
| 369 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
| 370 | m_cDmmFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM_FLAG ); |
---|
| 371 | m_cDmmModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM_MODE ); |
---|
| 372 | m_cDmmDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM_DATA ); |
---|
| 373 | #endif |
---|
[189] | 374 | #if RWTH_SDC_DLT_B0036 |
---|
| 375 | m_cSDCFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG ); |
---|
| 376 | m_cSDCResidualFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG ); |
---|
| 377 | m_cSDCResidualSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL ); |
---|
| 378 | m_cSDCResidualSignFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_SIGN_FLAG ); |
---|
| 379 | m_cSDCPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_PRED_MODE ); |
---|
| 380 | #endif |
---|
[56] | 381 | |
---|
| 382 | m_pcBinIf->start(); |
---|
[2] | 383 | } |
---|
| 384 | |
---|
[56] | 385 | Void TEncSbac::writeTileMarker( UInt uiTileIdx, UInt uiBitsUsed ) |
---|
| 386 | { |
---|
| 387 | for (Int iShift=uiBitsUsed-1; iShift>=0; iShift--) |
---|
| 388 | { |
---|
| 389 | m_pcBinIf->encodeBinEP ( (uiTileIdx & (1 << iShift)) >> iShift ); |
---|
| 390 | } |
---|
| 391 | } |
---|
| 392 | |
---|
[2] | 393 | void TEncSbac::codeSEI(const SEI&) |
---|
| 394 | { |
---|
| 395 | assert(0); |
---|
| 396 | } |
---|
| 397 | |
---|
[210] | 398 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
---|
[77] | 399 | Void TEncSbac::codeVPS( TComVPS* pcVPS ) |
---|
| 400 | { |
---|
[100] | 401 | assert (0); |
---|
[77] | 402 | return; |
---|
| 403 | } |
---|
| 404 | #endif |
---|
| 405 | |
---|
[56] | 406 | #if HHI_MPI |
---|
| 407 | Void TEncSbac::codeSPS( TComSPS* pcSPS, Bool bIsDepth ) |
---|
| 408 | #else |
---|
[2] | 409 | Void TEncSbac::codeSPS( TComSPS* pcSPS ) |
---|
[56] | 410 | #endif |
---|
[2] | 411 | { |
---|
| 412 | assert (0); |
---|
| 413 | return; |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | Void TEncSbac::codePPS( TComPPS* pcPPS ) |
---|
| 417 | { |
---|
| 418 | assert (0); |
---|
| 419 | return; |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | Void TEncSbac::codeSliceHeader( TComSlice* pcSlice ) |
---|
| 423 | { |
---|
| 424 | assert (0); |
---|
| 425 | return; |
---|
| 426 | } |
---|
| 427 | |
---|
[56] | 428 | #if TILES_WPP_ENTRY_POINT_SIGNALLING |
---|
| 429 | Void TEncSbac::codeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
| 430 | { |
---|
| 431 | assert (0); |
---|
| 432 | return; |
---|
| 433 | } |
---|
| 434 | #else |
---|
| 435 | Void TEncSbac::codeSliceHeaderSubstreamTable( TComSlice* pcSlice ) |
---|
| 436 | { |
---|
| 437 | assert (0); |
---|
| 438 | } |
---|
| 439 | #endif |
---|
| 440 | |
---|
[2] | 441 | Void TEncSbac::codeTerminatingBit( UInt uilsLast ) |
---|
| 442 | { |
---|
| 443 | m_pcBinIf->encodeBinTrm( uilsLast ); |
---|
| 444 | } |
---|
| 445 | |
---|
| 446 | Void TEncSbac::codeSliceFinish() |
---|
| 447 | { |
---|
| 448 | m_pcBinIf->finish(); |
---|
| 449 | } |
---|
| 450 | |
---|
[56] | 451 | #if OL_FLUSH |
---|
| 452 | Void TEncSbac::codeFlush() |
---|
| 453 | { |
---|
| 454 | m_pcBinIf->flush(); |
---|
| 455 | } |
---|
[2] | 456 | |
---|
[56] | 457 | Void TEncSbac::encodeStart() |
---|
| 458 | { |
---|
| 459 | m_pcBinIf->start(); |
---|
| 460 | } |
---|
| 461 | #endif |
---|
[2] | 462 | |
---|
| 463 | Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
| 464 | { |
---|
| 465 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] ); |
---|
| 466 | |
---|
| 467 | if( 0 == uiSymbol) |
---|
| 468 | { |
---|
| 469 | return; |
---|
| 470 | } |
---|
| 471 | |
---|
| 472 | while( uiSymbol-- ) |
---|
| 473 | { |
---|
| 474 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] ); |
---|
| 475 | } |
---|
| 476 | |
---|
| 477 | return; |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
| 481 | { |
---|
| 482 | if (uiMaxSymbol == 0) |
---|
| 483 | { |
---|
| 484 | return; |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] ); |
---|
| 488 | |
---|
| 489 | if ( uiSymbol == 0 ) |
---|
| 490 | { |
---|
| 491 | return; |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
| 495 | |
---|
| 496 | while( --uiSymbol ) |
---|
| 497 | { |
---|
| 498 | m_pcBinIf->encodeBin( 1, pcSCModel[ iOffset ] ); |
---|
| 499 | } |
---|
| 500 | if( bCodeLast ) |
---|
| 501 | { |
---|
| 502 | m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] ); |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | return; |
---|
| 506 | } |
---|
| 507 | |
---|
| 508 | Void TEncSbac::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
| 509 | { |
---|
[56] | 510 | UInt bins = 0; |
---|
| 511 | Int numBins = 0; |
---|
| 512 | |
---|
[2] | 513 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
| 514 | { |
---|
[56] | 515 | bins = 2 * bins + 1; |
---|
| 516 | numBins++; |
---|
| 517 | uiSymbol -= 1 << uiCount; |
---|
[2] | 518 | uiCount ++; |
---|
| 519 | } |
---|
[56] | 520 | bins = 2 * bins + 0; |
---|
| 521 | numBins++; |
---|
[2] | 522 | |
---|
[56] | 523 | bins = (bins << uiCount) | uiSymbol; |
---|
| 524 | numBins += uiCount; |
---|
| 525 | |
---|
| 526 | assert( numBins <= 32 ); |
---|
| 527 | m_pcBinIf->encodeBinsEP( bins, numBins ); |
---|
[2] | 528 | } |
---|
| 529 | |
---|
| 530 | /** Coding of coeff_abs_level_minus3 |
---|
| 531 | * \param uiSymbol value of coeff_abs_level_minus3 |
---|
| 532 | * \param ruiGoRiceParam reference to Rice parameter |
---|
| 533 | * \returns Void |
---|
| 534 | */ |
---|
| 535 | Void TEncSbac::xWriteGoRiceExGolomb( UInt uiSymbol, UInt &ruiGoRiceParam ) |
---|
| 536 | { |
---|
| 537 | UInt uiMaxVlc = g_auiGoRiceRange[ ruiGoRiceParam ]; |
---|
| 538 | Bool bExGolomb = ( uiSymbol > uiMaxVlc ); |
---|
| 539 | UInt uiCodeWord = min<UInt>( uiSymbol, ( uiMaxVlc + 1 ) ); |
---|
| 540 | UInt uiQuotient = uiCodeWord >> ruiGoRiceParam; |
---|
| 541 | UInt uiMaxPreLen = g_auiGoRicePrefixLen[ ruiGoRiceParam ]; |
---|
[56] | 542 | |
---|
| 543 | UInt binValues; |
---|
| 544 | Int numBins; |
---|
| 545 | |
---|
| 546 | if ( uiQuotient >= uiMaxPreLen ) |
---|
[2] | 547 | { |
---|
[56] | 548 | numBins = uiMaxPreLen; |
---|
| 549 | binValues = ( 1 << numBins ) - 1; |
---|
[2] | 550 | } |
---|
| 551 | else |
---|
| 552 | { |
---|
[56] | 553 | numBins = uiQuotient + 1; |
---|
| 554 | binValues = ( 1 << numBins ) - 2; |
---|
[2] | 555 | } |
---|
[56] | 556 | |
---|
| 557 | m_pcBinIf->encodeBinsEP( ( binValues << ruiGoRiceParam ) + uiCodeWord - ( uiQuotient << ruiGoRiceParam ), numBins + ruiGoRiceParam ); |
---|
| 558 | |
---|
| 559 | #if EIGHT_BITS_RICE_CODE |
---|
| 560 | ruiGoRiceParam = g_aauiGoRiceUpdate[ ruiGoRiceParam ][ min<UInt>( uiSymbol, 23 ) ]; |
---|
| 561 | #else |
---|
[2] | 562 | ruiGoRiceParam = g_aauiGoRiceUpdate[ ruiGoRiceParam ][ min<UInt>( uiSymbol, 15 ) ]; |
---|
[56] | 563 | #endif |
---|
| 564 | |
---|
[2] | 565 | if( bExGolomb ) |
---|
| 566 | { |
---|
| 567 | uiSymbol -= uiMaxVlc + 1; |
---|
| 568 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | |
---|
[56] | 572 | // SBAC RD |
---|
| 573 | Void TEncSbac::load ( TEncSbac* pSrc) |
---|
[2] | 574 | { |
---|
[56] | 575 | this->xCopyFrom(pSrc); |
---|
[2] | 576 | } |
---|
| 577 | |
---|
[56] | 578 | Void TEncSbac::loadIntraDirModeLuma( TEncSbac* pSrc) |
---|
[2] | 579 | { |
---|
[56] | 580 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
| 581 | |
---|
| 582 | this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); |
---|
[2] | 583 | } |
---|
| 584 | |
---|
[56] | 585 | |
---|
[2] | 586 | Void TEncSbac::store( TEncSbac* pDest) |
---|
| 587 | { |
---|
| 588 | pDest->xCopyFrom( this ); |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | |
---|
| 592 | Void TEncSbac::xCopyFrom( TEncSbac* pSrc ) |
---|
| 593 | { |
---|
| 594 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
| 595 | |
---|
| 596 | this->m_uiCoeffCost = pSrc->m_uiCoeffCost; |
---|
| 597 | this->m_uiLastQp = pSrc->m_uiLastQp; |
---|
| 598 | |
---|
[56] | 599 | memcpy( m_contextModels, pSrc->m_contextModels, m_numContextModels * sizeof( ContextModel ) ); |
---|
[2] | 600 | } |
---|
| 601 | |
---|
[56] | 602 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
| 603 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Int iNum ) |
---|
| 604 | #else |
---|
[2] | 605 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
[56] | 606 | #endif |
---|
[2] | 607 | { |
---|
| 608 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
[56] | 609 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
| 610 | #else |
---|
| 611 | Int iNum = AMVP_MAX_NUM_CANDS; |
---|
| 612 | #endif |
---|
[2] | 613 | |
---|
| 614 | xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1); |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 618 | { |
---|
| 619 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
[189] | 620 | |
---|
| 621 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
| 622 | TComSPS *sps = pcCU->getPic()->getSlice(0)->getSPS(); |
---|
| 623 | TComPic *pcTexture = pcCU->getSlice()->getTexturePic(); |
---|
| 624 | Bool bDepthMapDetect = (pcTexture != NULL); |
---|
| 625 | Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE); |
---|
| 626 | |
---|
| 627 | if(bDepthMapDetect && !bIntraSliceDetect && sps->getUseQTLPC() && pcCU->getPic()->getReduceBitsFlag()) |
---|
| 628 | { |
---|
| 629 | TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr()); |
---|
| 630 | UInt uiCUIdx = (pcCU->getZorderIdxInCU() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU(); |
---|
| 631 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); |
---|
| 632 | if (pcTextureCU->getDepth(uiCUIdx) == uiDepth && pcTextureCU->getPartitionSize( uiCUIdx ) != SIZE_NxN) |
---|
| 633 | { |
---|
| 634 | assert( eSize == SIZE_2Nx2N ); |
---|
| 635 | return; |
---|
| 636 | } |
---|
| 637 | } |
---|
[115] | 638 | #endif |
---|
[189] | 639 | |
---|
[2] | 640 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 641 | { |
---|
| 642 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 643 | { |
---|
| 644 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
| 645 | } |
---|
| 646 | return; |
---|
| 647 | } |
---|
| 648 | |
---|
| 649 | switch(eSize) |
---|
| 650 | { |
---|
[116] | 651 | case SIZE_2Nx2N: |
---|
[2] | 652 | { |
---|
| 653 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 654 | break; |
---|
| 655 | } |
---|
[116] | 656 | case SIZE_2NxN: |
---|
| 657 | case SIZE_2NxnU: |
---|
| 658 | case SIZE_2NxnD: |
---|
[2] | 659 | { |
---|
| 660 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 661 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
[56] | 662 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
| 663 | { |
---|
| 664 | if (eSize == SIZE_2NxN) |
---|
| 665 | { |
---|
| 666 | #if AMP_CTX |
---|
| 667 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 668 | #else |
---|
| 669 | m_pcBinIf->encodeBin(1, m_cCUYPosiSCModel.get( 0, 0, 0 )); |
---|
| 670 | #endif |
---|
| 671 | } |
---|
| 672 | else |
---|
| 673 | { |
---|
| 674 | #if AMP_CTX |
---|
| 675 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 676 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
| 677 | #else |
---|
| 678 | m_pcBinIf->encodeBin(0, m_cCUYPosiSCModel.get( 0, 0, 0 )); |
---|
| 679 | m_pcBinIf->encodeBin((eSize == SIZE_2NxnU? 0: 1), m_cCUYPosiSCModel.get( 0, 0, 1 )); |
---|
| 680 | #endif |
---|
| 681 | } |
---|
| 682 | } |
---|
[2] | 683 | break; |
---|
| 684 | } |
---|
[116] | 685 | case SIZE_Nx2N: |
---|
| 686 | case SIZE_nLx2N: |
---|
| 687 | case SIZE_nRx2N: |
---|
[2] | 688 | { |
---|
| 689 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 690 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
[56] | 691 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getSlice()->getSPS()->getDisInter4x4() && pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
| 692 | { |
---|
| 693 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
| 694 | } |
---|
| 695 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
| 696 | { |
---|
| 697 | if (eSize == SIZE_Nx2N) |
---|
| 698 | { |
---|
| 699 | #if AMP_CTX |
---|
| 700 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 701 | #else |
---|
| 702 | m_pcBinIf->encodeBin(1, m_cCUXPosiSCModel.get( 0, 0, 0 )); |
---|
| 703 | #endif |
---|
| 704 | } |
---|
| 705 | else |
---|
| 706 | { |
---|
| 707 | #if AMP_CTX |
---|
| 708 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 709 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
| 710 | #else |
---|
| 711 | m_pcBinIf->encodeBin(0, m_cCUXPosiSCModel.get( 0, 0, 0 )); |
---|
| 712 | m_pcBinIf->encodeBin((eSize == SIZE_nLx2N? 0: 1), m_cCUXPosiSCModel.get( 0, 0, 1 )); |
---|
| 713 | #endif |
---|
| 714 | } |
---|
| 715 | } |
---|
[2] | 716 | break; |
---|
| 717 | } |
---|
[116] | 718 | case SIZE_NxN: |
---|
[2] | 719 | { |
---|
[56] | 720 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getSlice()->getSPS()->getDisInter4x4() && pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
[2] | 721 | { |
---|
| 722 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
[56] | 723 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
| 724 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
[2] | 725 | } |
---|
| 726 | break; |
---|
| 727 | } |
---|
[116] | 728 | default: |
---|
[2] | 729 | { |
---|
| 730 | assert(0); |
---|
| 731 | } |
---|
| 732 | } |
---|
| 733 | } |
---|
| 734 | |
---|
| 735 | /** code prediction mode |
---|
| 736 | * \param pcCU |
---|
| 737 | * \param uiAbsPartIdx |
---|
| 738 | * \returns Void |
---|
| 739 | */ |
---|
| 740 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 741 | { |
---|
[189] | 742 | #if RWTH_SDC_DLT_B0036 |
---|
| 743 | if ( pcCU->getSlice()->isIntra() ) |
---|
| 744 | { |
---|
| 745 | assert( pcCU->isIntra(uiAbsPartIdx) ); |
---|
| 746 | return; |
---|
| 747 | } |
---|
| 748 | #endif |
---|
| 749 | |
---|
[2] | 750 | // get context function is here |
---|
| 751 | Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); |
---|
[56] | 752 | m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 753 | } |
---|
| 754 | |
---|
| 755 | Void TEncSbac::codeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 756 | { |
---|
| 757 | if (!m_bAlfCtrl) |
---|
| 758 | return; |
---|
| 759 | |
---|
| 760 | if( pcCU->getDepth(uiAbsPartIdx) > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth)) |
---|
| 761 | { |
---|
| 762 | return; |
---|
| 763 | } |
---|
| 764 | |
---|
[56] | 765 | const UInt uiSymbol = pcCU->getAlfCtrlFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 766 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUAlfCtrlFlagSCModel.get( 0 ) ); |
---|
[2] | 767 | } |
---|
| 768 | |
---|
| 769 | Void TEncSbac::codeAlfCtrlDepth() |
---|
| 770 | { |
---|
| 771 | if (!m_bAlfCtrl) |
---|
| 772 | return; |
---|
| 773 | |
---|
| 774 | UInt uiDepth = m_uiMaxAlfCtrlDepth; |
---|
| 775 | xWriteUnaryMaxSymbol(uiDepth, m_cALFUvlcSCModel.get(0), 1, g_uiMaxCUDepth-1); |
---|
| 776 | } |
---|
| 777 | |
---|
| 778 | /** code skip flag |
---|
| 779 | * \param pcCU |
---|
| 780 | * \param uiAbsPartIdx |
---|
| 781 | * \returns Void |
---|
| 782 | */ |
---|
| 783 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 784 | { |
---|
| 785 | // get context function is here |
---|
| 786 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
| 787 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
| 788 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
[56] | 789 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 790 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
| 791 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
| 792 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
| 793 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 794 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 795 | DTRACE_CABAC_T( "\n"); |
---|
| 796 | } |
---|
| 797 | |
---|
[189] | 798 | #if LGE_ILLUCOMP_B0045 |
---|
| 799 | /** code Illumination Compensation flag |
---|
| 800 | * \param pcCU |
---|
| 801 | * \param uiAbsPartIdx |
---|
| 802 | * \returns Void |
---|
| 803 | */ |
---|
| 804 | Void TEncSbac::codeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 805 | { |
---|
| 806 | // get context function is here |
---|
| 807 | UInt uiSymbol = pcCU->getICFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 808 | UInt uiCtxIC = pcCU->getCtxICFlag( uiAbsPartIdx ) ; |
---|
| 809 | m_pcBinIf->encodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, uiCtxIC ) ); |
---|
| 810 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 811 | DTRACE_CABAC_T( "\tICFlag" ); |
---|
| 812 | DTRACE_CABAC_T( "\tuiCtxIC: "); |
---|
| 813 | DTRACE_CABAC_V( uiCtxIC ); |
---|
| 814 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 815 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 816 | DTRACE_CABAC_T( "\n"); |
---|
| 817 | } |
---|
| 818 | #endif |
---|
| 819 | |
---|
[2] | 820 | /** code merge flag |
---|
| 821 | * \param pcCU |
---|
| 822 | * \param uiAbsPartIdx |
---|
| 823 | * \returns Void |
---|
| 824 | */ |
---|
| 825 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 826 | { |
---|
[56] | 827 | const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 828 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
[2] | 829 | |
---|
[56] | 830 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 831 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
| 832 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 833 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
| 834 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
| 835 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
| 836 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 837 | DTRACE_CABAC_T( "\n" ); |
---|
| 838 | } |
---|
| 839 | |
---|
[56] | 840 | /** code merge index |
---|
| 841 | * \param pcCU |
---|
| 842 | * \param uiAbsPartIdx |
---|
| 843 | * \returns Void |
---|
| 844 | */ |
---|
| 845 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
[2] | 846 | { |
---|
[56] | 847 | UInt uiNumCand = MRG_MAX_NUM_CANDS; |
---|
| 848 | #if !MRG_IDX_CTX_RED |
---|
| 849 | UInt auiCtx[4] = { 0, 1, 2, 3 }; |
---|
| 850 | #endif |
---|
| 851 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
| 852 | uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
[5] | 853 | #if HHI_MPI |
---|
[2] | 854 | const Bool bMVIAvailable = pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE; |
---|
| 855 | if( bMVIAvailable ) |
---|
| 856 | { |
---|
| 857 | const Bool bUseMVI = pcCU->getTextureModeDepth( uiAbsPartIdx ) != -1; |
---|
| 858 | if( bUseMVI ) |
---|
| 859 | { |
---|
[58] | 860 | uiUnaryIdx = (UInt)HHI_MPI_MERGE_POS; |
---|
[2] | 861 | } |
---|
[58] | 862 | else if( (Int)uiUnaryIdx >= (Int)HHI_MPI_MERGE_POS ) |
---|
[2] | 863 | { |
---|
[56] | 864 | uiUnaryIdx++; |
---|
[2] | 865 | } |
---|
| 866 | } |
---|
| 867 | #endif |
---|
[56] | 868 | if ( uiNumCand > 1 ) |
---|
[2] | 869 | { |
---|
[56] | 870 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
[2] | 871 | { |
---|
[56] | 872 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
| 873 | #if MRG_IDX_CTX_RED |
---|
| 874 | if ( ui==0 ) |
---|
[2] | 875 | { |
---|
[56] | 876 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 877 | } |
---|
[56] | 878 | else |
---|
[2] | 879 | { |
---|
[56] | 880 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
[2] | 881 | } |
---|
[56] | 882 | #else |
---|
| 883 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, auiCtx[ui] ) ); |
---|
| 884 | #endif |
---|
| 885 | if( uiSymbol == 0 ) |
---|
[2] | 886 | { |
---|
[56] | 887 | break; |
---|
[2] | 888 | } |
---|
| 889 | } |
---|
| 890 | } |
---|
[56] | 891 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 892 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
| 893 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
| 894 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
| 895 | DTRACE_CABAC_T( "\n" ); |
---|
| 896 | } |
---|
| 897 | |
---|
[5] | 898 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
[56] | 899 | Void |
---|
[2] | 900 | TEncSbac::codeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 901 | { |
---|
[56] | 902 | UInt uiCtx = pcCU->getCtxResPredFlag( uiAbsPartIdx ); |
---|
[2] | 903 | UInt uiSymbol = ( pcCU->getResPredFlag( uiAbsPartIdx ) ? 1 : 0 ); |
---|
| 904 | m_pcBinIf->encodeBin( uiSymbol, m_cResPredFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
| 905 | } |
---|
[5] | 906 | #endif |
---|
[2] | 907 | |
---|
| 908 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 909 | { |
---|
| 910 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 911 | return; |
---|
| 912 | |
---|
| 913 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
| 914 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
| 915 | |
---|
| 916 | assert( uiCtx < 3 ); |
---|
[189] | 917 | |
---|
| 918 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
| 919 | Bool bCodeSplitFlag = true; |
---|
| 920 | |
---|
| 921 | TComSPS *sps = pcCU->getPic()->getSlice(0)->getSPS(); |
---|
| 922 | TComPic *pcTexture = pcCU->getSlice()->getTexturePic(); |
---|
| 923 | Bool bDepthMapDetect = (pcTexture != NULL); |
---|
| 924 | Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE); |
---|
| 925 | |
---|
| 926 | if(bDepthMapDetect && !bIntraSliceDetect && sps->getUseQTLPC() && pcCU->getPic()->getReduceBitsFlag()) |
---|
[115] | 927 | { |
---|
[189] | 928 | TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr()); |
---|
| 929 | UInt uiCUIdx = (pcCU->getZorderIdxInCU() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU(); |
---|
| 930 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); |
---|
| 931 | bCodeSplitFlag = (pcTextureCU->getDepth(uiCUIdx) > uiDepth); |
---|
[115] | 932 | } |
---|
[189] | 933 | |
---|
| 934 | if(!bCodeSplitFlag) |
---|
| 935 | { |
---|
| 936 | assert(uiCurrSplitFlag == 0); |
---|
| 937 | return; |
---|
| 938 | } |
---|
[115] | 939 | #endif |
---|
[189] | 940 | |
---|
| 941 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
[56] | 942 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 943 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
| 944 | return; |
---|
| 945 | } |
---|
| 946 | |
---|
| 947 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
| 948 | { |
---|
| 949 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
[56] | 950 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 951 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
| 952 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 953 | DTRACE_CABAC_V( uiSymbol ) |
---|
| 954 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 955 | DTRACE_CABAC_V( uiCtx ) |
---|
| 956 | DTRACE_CABAC_T( "\n" ) |
---|
| 957 | } |
---|
[100] | 958 | |
---|
[189] | 959 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 960 | Void TEncSbac::xCodeEdgeIntraInfo( TComDataCU* pcCU, UInt uiPartIdx ) |
---|
| 961 | { |
---|
| 962 | UInt uiDepth = pcCU->getDepth( uiPartIdx ) + (pcCU->getPartitionSize( uiPartIdx ) == SIZE_NxN ? 1 : 0); |
---|
| 963 | UInt uiCtxEdgeIntra = pcCU->getCtxEdgeIntra( uiPartIdx ); |
---|
| 964 | UChar* pucSymbolList = pcCU->getEdgeCode( uiPartIdx ); |
---|
| 965 | UChar ucEdgeNumber = pcCU->getEdgeNumber( uiPartIdx ); |
---|
| 966 | Bool bLeft = pcCU->getEdgeLeftFirst( uiPartIdx ); |
---|
| 967 | UChar ucStart = pcCU->getEdgeStartPos( uiPartIdx ); |
---|
| 968 | UInt uiSymbol; |
---|
| 969 | |
---|
| 970 | // 1. Top(0) or Left(1) |
---|
| 971 | uiSymbol = (bLeft == false) ? 0 : 1; |
---|
| 972 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
| 973 | |
---|
| 974 | // 2. Start position (lowest bit first) |
---|
| 975 | uiSymbol = ucStart; |
---|
| 976 | for( UInt ui = 6; ui > uiDepth; ui-- ) // 64(0)->6, 32(1)->5, 16(2)->4, 8(3)->3, 4(4)->2 |
---|
| 977 | { |
---|
| 978 | m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); |
---|
| 979 | uiSymbol >>= 1; |
---|
| 980 | } |
---|
| 981 | |
---|
| 982 | // 3. Number of edges |
---|
| 983 | uiSymbol = ucEdgeNumber > 0 ? ucEdgeNumber - 1 : 0; |
---|
| 984 | for( UInt ui = 7; ui > uiDepth; ui-- ) // 64(0)->7, 32(1)->6, 16(2)->5, 8(3)->4, 4(4)->3 |
---|
| 985 | { |
---|
| 986 | m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); |
---|
| 987 | uiSymbol >>= 1; |
---|
| 988 | } |
---|
| 989 | |
---|
| 990 | if(uiSymbol != 0) |
---|
| 991 | { |
---|
| 992 | printf(" ucEdgeNumber %d at depth %d\n",ucEdgeNumber, uiDepth); |
---|
| 993 | assert(false); |
---|
| 994 | } |
---|
| 995 | |
---|
| 996 | // 4. Edges |
---|
| 997 | for( Int iPtr2 = 0; iPtr2 < ucEdgeNumber; iPtr2++ ) |
---|
| 998 | { |
---|
| 999 | UInt uiReorderSymbol = pucSymbolList[iPtr2]; |
---|
| 1000 | |
---|
| 1001 | //printf ("Ptr = %d, Symbol = %d\n", iPtr2, uiSymbol); |
---|
| 1002 | |
---|
| 1003 | // Left-friendly direction (Top start) |
---|
| 1004 | // 0 ( 0deg) => 0 |
---|
| 1005 | // 1 ( 45deg) => 10 |
---|
| 1006 | // 2 ( -45deg) => 110 |
---|
| 1007 | // 3 ( 90deg) => 1110 |
---|
| 1008 | // 4 ( -90deg) => 11110 |
---|
| 1009 | // 5 ( 135deg) => 111110 |
---|
| 1010 | // 6 (-135deg) => 111111 |
---|
| 1011 | // Right-friendly direction (Left start) |
---|
| 1012 | // 0 ( 0deg) => 0 |
---|
| 1013 | // 2 ( -45deg) => 10 |
---|
| 1014 | // 1 ( 45deg) => 110 |
---|
| 1015 | // 4 ( -90deg) => 1110 |
---|
| 1016 | // 3 ( 90deg) => 11110 |
---|
| 1017 | // 6 (-135deg) => 111110 |
---|
| 1018 | // 5 ( 135deg) => 111111 |
---|
| 1019 | |
---|
| 1020 | // refer to a paper "An efficient chain code with Huffman coding" |
---|
| 1021 | |
---|
| 1022 | for( UInt ui = 0; ui < uiReorderSymbol; ui++ ) |
---|
| 1023 | { |
---|
| 1024 | m_pcBinIf->encodeBin( 1, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) ); |
---|
| 1025 | } |
---|
| 1026 | |
---|
| 1027 | if( uiReorderSymbol != 6 ) |
---|
| 1028 | m_pcBinIf->encodeBin( 0, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) ); |
---|
| 1029 | } |
---|
| 1030 | } |
---|
| 1031 | #endif |
---|
| 1032 | |
---|
[2] | 1033 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1034 | { |
---|
[56] | 1035 | UInt uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
[2] | 1036 | |
---|
[5] | 1037 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[56] | 1038 | if( pcCU->getSlice()->getSPS()->getUseDMM() && pcCU->getWidth( uiAbsPartIdx ) <= DMM_WEDGEMODEL_MAX_SIZE ) |
---|
[2] | 1039 | { |
---|
[189] | 1040 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 1041 | m_pcBinIf->encodeBin( uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX, m_cDmmFlagSCModel.get(0, 0, 0) ); |
---|
| 1042 | #else |
---|
[56] | 1043 | m_pcBinIf->encodeBin( uiDir >= NUM_INTRA_MODE, m_cDmmFlagSCModel.get(0, 0, 0) ); |
---|
[100] | 1044 | #endif |
---|
[2] | 1045 | } |
---|
[189] | 1046 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 1047 | if( uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX ) |
---|
| 1048 | #else |
---|
[56] | 1049 | if( uiDir >= NUM_INTRA_MODE ) |
---|
[100] | 1050 | #endif |
---|
[2] | 1051 | { |
---|
[56] | 1052 | assert( pcCU->getWidth( uiAbsPartIdx ) <= DMM_WEDGEMODEL_MAX_SIZE ); |
---|
| 1053 | UInt uiDMMode = uiDir - NUM_INTRA_MODE; |
---|
[2] | 1054 | |
---|
[5] | 1055 | #if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX |
---|
[56] | 1056 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
| 1057 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
[5] | 1058 | |
---|
[56] | 1059 | if( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
| 1060 | { |
---|
| 1061 | m_pcBinIf->encodeBin( (uiDMMode & 0x04) >> 2, m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
| 1062 | } |
---|
[5] | 1063 | #else |
---|
[56] | 1064 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
[2] | 1065 | |
---|
[56] | 1066 | if( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
[2] | 1067 | { |
---|
[56] | 1068 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
[2] | 1069 | } |
---|
[5] | 1070 | #endif |
---|
| 1071 | #if HHI_DMM_WEDGE_INTRA |
---|
[2] | 1072 | if( uiDir == DMM_WEDGE_FULL_IDX ) { xCodeWedgeFullInfo ( pcCU, uiAbsPartIdx ); } |
---|
| 1073 | if( uiDir == DMM_WEDGE_FULL_D_IDX ) { xCodeWedgeFullDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
| 1074 | if( uiDir == DMM_WEDGE_PREDDIR_IDX ) { xCodeWedgePredDirInfo ( pcCU, uiAbsPartIdx ); } |
---|
| 1075 | if( uiDir == DMM_WEDGE_PREDDIR_D_IDX ) { xCodeWedgePredDirDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
[5] | 1076 | #endif |
---|
| 1077 | #if HHI_DMM_PRED_TEX |
---|
[210] | 1078 | |
---|
| 1079 | #if FLEX_CODING_ORDER_M23723 |
---|
| 1080 | if ( !pcCU->getSlice()->getSPS()->getUseDMM34() ) |
---|
| 1081 | { |
---|
| 1082 | assert( uiDir != DMM_WEDGE_PREDTEX_D_IDX ); |
---|
| 1083 | assert( uiDir != DMM_CONTOUR_PREDTEX_D_IDX ); |
---|
| 1084 | } |
---|
| 1085 | #endif |
---|
| 1086 | |
---|
[2] | 1087 | if( uiDir == DMM_WEDGE_PREDTEX_D_IDX ) { xCodeWedgePredTexDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
| 1088 | if( uiDir == DMM_CONTOUR_PREDTEX_D_IDX ) { xCodeContourPredTexDeltaInfo( pcCU, uiAbsPartIdx ); } |
---|
[5] | 1089 | #endif |
---|
[2] | 1090 | } |
---|
| 1091 | else |
---|
[189] | 1092 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 1093 | if ( uiDir >= EDGE_INTRA_IDX) |
---|
| 1094 | { |
---|
| 1095 | m_pcBinIf->encodeBin( 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
| 1096 | m_pcBinIf->encodeBinsEP( 63, 6 ); |
---|
| 1097 | xCodeEdgeIntraInfo( pcCU, uiAbsPartIdx ); |
---|
| 1098 | #if LGE_EDGE_INTRA_DELTA_DC |
---|
| 1099 | m_pcBinIf->encodeBin( (uiDir == EDGE_INTRA_DELTA_IDX), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) ); |
---|
| 1100 | if( uiDir == EDGE_INTRA_DELTA_IDX ) |
---|
| 1101 | { |
---|
| 1102 | Int iDeltaDC0 = pcCU->getEdgeDeltaDC0( uiAbsPartIdx ); |
---|
| 1103 | Int iDeltaDC1 = pcCU->getEdgeDeltaDC1( uiAbsPartIdx ); |
---|
| 1104 | |
---|
| 1105 | xWriteExGolombLevel( UInt( abs( iDeltaDC0 ) ), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) ); |
---|
| 1106 | if ( iDeltaDC0 != 0 ) |
---|
| 1107 | { |
---|
| 1108 | UInt uiSign = iDeltaDC0 > 0 ? 0 : 1; |
---|
| 1109 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 1110 | } |
---|
| 1111 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) ); |
---|
| 1112 | if ( iDeltaDC1 != 0 ) |
---|
| 1113 | { |
---|
| 1114 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
| 1115 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 1116 | } |
---|
| 1117 | } |
---|
| 1118 | #endif |
---|
| 1119 | } |
---|
| 1120 | else |
---|
| 1121 | #endif // LGE_EDGE_INTRA |
---|
[56] | 1122 | { |
---|
[2] | 1123 | #endif |
---|
[56] | 1124 | #if !LOGI_INTRA_NAME_3MPM |
---|
[2] | 1125 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
| 1126 | #endif |
---|
[189] | 1127 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 1128 | Bool bCodeEdgeIntra = false; |
---|
| 1129 | if( pcCU->getSlice()->getSPS()->isDepth() ) |
---|
| 1130 | { |
---|
| 1131 | UInt uiPUWidth = pcCU->getWidth( uiAbsPartIdx ) >> (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 1 : 0); |
---|
| 1132 | if( uiPUWidth <= LGE_EDGE_INTRA_MAX_SIZE && uiPUWidth >= LGE_EDGE_INTRA_MIN_SIZE ) |
---|
| 1133 | bCodeEdgeIntra = true; |
---|
| 1134 | } |
---|
| 1135 | #endif |
---|
[2] | 1136 | |
---|
[56] | 1137 | #if LOGI_INTRA_NAME_3MPM |
---|
| 1138 | Int uiPreds[3] = {-1, -1, -1}; |
---|
| 1139 | #else |
---|
[2] | 1140 | Int uiPreds[2] = {-1, -1}; |
---|
[56] | 1141 | #endif |
---|
[2] | 1142 | Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); |
---|
| 1143 | |
---|
| 1144 | Int uiPredIdx = -1; |
---|
| 1145 | |
---|
| 1146 | for(UInt i = 0; i < uiPredNum; i++) |
---|
| 1147 | { |
---|
| 1148 | if(uiDir == uiPreds[i]) |
---|
| 1149 | { |
---|
| 1150 | uiPredIdx = i; |
---|
| 1151 | } |
---|
| 1152 | } |
---|
| 1153 | |
---|
| 1154 | if(uiPredIdx != -1) |
---|
| 1155 | { |
---|
| 1156 | m_pcBinIf->encodeBin( 1, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
[56] | 1157 | #if LOGI_INTRA_NAME_3MPM |
---|
| 1158 | m_pcBinIf->encodeBinEP( uiPredIdx ? 1 : 0 ); |
---|
| 1159 | if (uiPredIdx) |
---|
[2] | 1160 | { |
---|
[56] | 1161 | m_pcBinIf->encodeBinEP( uiPredIdx-1 ); |
---|
[2] | 1162 | } |
---|
[56] | 1163 | #else |
---|
| 1164 | m_pcBinIf->encodeBinEP( uiPredIdx ); |
---|
| 1165 | #endif |
---|
[2] | 1166 | } |
---|
| 1167 | else |
---|
| 1168 | { |
---|
| 1169 | m_pcBinIf->encodeBin( 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
| 1170 | |
---|
[56] | 1171 | #if LOGI_INTRA_NAME_3MPM |
---|
| 1172 | if (uiPreds[0] > uiPreds[1]) |
---|
| 1173 | { |
---|
| 1174 | std::swap(uiPreds[0], uiPreds[1]); |
---|
| 1175 | } |
---|
| 1176 | if (uiPreds[0] > uiPreds[2]) |
---|
[2] | 1177 | { |
---|
[56] | 1178 | std::swap(uiPreds[0], uiPreds[2]); |
---|
[2] | 1179 | } |
---|
[56] | 1180 | if (uiPreds[1] > uiPreds[2]) |
---|
[2] | 1181 | { |
---|
[56] | 1182 | std::swap(uiPreds[1], uiPreds[2]); |
---|
[2] | 1183 | } |
---|
| 1184 | #endif |
---|
| 1185 | |
---|
[56] | 1186 | for(Int i = (uiPredNum - 1); i >= 0; i--) |
---|
| 1187 | { |
---|
| 1188 | uiDir = uiDir > uiPreds[i] ? uiDir - 1 : uiDir; |
---|
| 1189 | } |
---|
[5] | 1190 | |
---|
[56] | 1191 | #if LOGI_INTRA_NAME_3MPM |
---|
| 1192 | m_pcBinIf->encodeBinsEP( uiDir, 5 ); |
---|
[189] | 1193 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 1194 | if (bCodeEdgeIntra) |
---|
| 1195 | if (uiDir == 31) m_pcBinIf->encodeBinsEP(0,1); |
---|
| 1196 | #endif |
---|
[5] | 1197 | #else |
---|
[56] | 1198 | if ( uiDir < 31 ) |
---|
[2] | 1199 | { |
---|
[56] | 1200 | m_pcBinIf->encodeBinsEP( uiDir, g_aucIntraModeBitsAng[ iIntraIdx ] - 1 ); |
---|
[2] | 1201 | } |
---|
| 1202 | else |
---|
| 1203 | { |
---|
[56] | 1204 | m_pcBinIf->encodeBinsEP( 31, 5 ); |
---|
| 1205 | m_pcBinIf->encodeBinEP( uiDir - 31 ); |
---|
[2] | 1206 | } |
---|
[56] | 1207 | #endif |
---|
| 1208 | } |
---|
| 1209 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[2] | 1210 | } |
---|
| 1211 | #endif |
---|
| 1212 | return; |
---|
| 1213 | } |
---|
[56] | 1214 | |
---|
[2] | 1215 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1216 | { |
---|
[56] | 1217 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx ); |
---|
[2] | 1218 | |
---|
[56] | 1219 | if( uiIntraDirChroma == DM_CHROMA_IDX ) |
---|
[2] | 1220 | { |
---|
[56] | 1221 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 1222 | } |
---|
[56] | 1223 | else if( uiIntraDirChroma == LM_CHROMA_IDX ) |
---|
[2] | 1224 | { |
---|
[56] | 1225 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
| 1226 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 1 ) ); |
---|
[2] | 1227 | } |
---|
| 1228 | else |
---|
[56] | 1229 | { |
---|
| 1230 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
| 1231 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
[2] | 1232 | |
---|
[56] | 1233 | for( Int i = 0; i < NUM_CHROMA_MODE - 2; i++ ) |
---|
| 1234 | { |
---|
| 1235 | if( uiIntraDirChroma == uiAllowedChromaDir[i] ) |
---|
| 1236 | { |
---|
| 1237 | uiIntraDirChroma = i; |
---|
| 1238 | break; |
---|
| 1239 | } |
---|
| 1240 | } |
---|
| 1241 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 1242 | |
---|
[56] | 1243 | if (pcCU->getSlice()->getSPS()->getUseLMChroma()) |
---|
| 1244 | { |
---|
| 1245 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 1 )); |
---|
[2] | 1246 | } |
---|
[56] | 1247 | #if CHROMA_MODE_CODING |
---|
| 1248 | m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); |
---|
[2] | 1249 | #else |
---|
[56] | 1250 | xWriteUnaryMaxSymbol( uiIntraDirChroma, m_cCUChromaPredSCModel.get( 0, 0 ) + 1, 0, 3 ); |
---|
[2] | 1251 | #endif |
---|
| 1252 | } |
---|
| 1253 | return; |
---|
| 1254 | } |
---|
| 1255 | |
---|
| 1256 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1257 | { |
---|
[56] | 1258 | const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1; |
---|
| 1259 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
| 1260 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
| 1261 | m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); |
---|
| 1262 | |
---|
[2] | 1263 | return; |
---|
| 1264 | } |
---|
| 1265 | |
---|
| 1266 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1267 | { |
---|
| 1268 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getInterDir( uiAbsPartIdx ) != 3) |
---|
| 1269 | { |
---|
| 1270 | Int iRefFrame = pcCU->getSlice()->getRefIdxOfLC(eRefList, pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx )); |
---|
| 1271 | |
---|
[56] | 1272 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
| 1273 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
[2] | 1274 | |
---|
[56] | 1275 | if( iRefFrame > 0 ) |
---|
[2] | 1276 | { |
---|
[56] | 1277 | xWriteUnaryMaxSymbol( iRefFrame - 1, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C )-2 ); |
---|
[2] | 1278 | } |
---|
| 1279 | } |
---|
| 1280 | else |
---|
| 1281 | { |
---|
[56] | 1282 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
| 1283 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
| 1284 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
| 1285 | |
---|
| 1286 | if( iRefFrame > 0 ) |
---|
| 1287 | { |
---|
| 1288 | xWriteUnaryMaxSymbol( iRefFrame - 1, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
| 1289 | } |
---|
[2] | 1290 | } |
---|
| 1291 | return; |
---|
| 1292 | } |
---|
| 1293 | |
---|
| 1294 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1295 | { |
---|
[56] | 1296 | #if H0111_MVD_L1_ZERO |
---|
| 1297 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
| 1298 | { |
---|
| 1299 | return; |
---|
| 1300 | } |
---|
[2] | 1301 | #endif |
---|
| 1302 | |
---|
[56] | 1303 | const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
| 1304 | const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
| 1305 | const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
| 1306 | ContextModel* pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
[2] | 1307 | |
---|
[56] | 1308 | m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx ); |
---|
| 1309 | m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx ); |
---|
[2] | 1310 | |
---|
[56] | 1311 | const Bool bHorAbsGr0 = iHor != 0; |
---|
| 1312 | const Bool bVerAbsGr0 = iVer != 0; |
---|
| 1313 | const UInt uiHorAbs = 0 > iHor ? -iHor : iHor; |
---|
| 1314 | const UInt uiVerAbs = 0 > iVer ? -iVer : iVer; |
---|
| 1315 | pCtx++; |
---|
[2] | 1316 | |
---|
[56] | 1317 | if( bHorAbsGr0 ) |
---|
| 1318 | { |
---|
| 1319 | m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx ); |
---|
| 1320 | } |
---|
| 1321 | |
---|
| 1322 | if( bVerAbsGr0 ) |
---|
| 1323 | { |
---|
| 1324 | m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx ); |
---|
| 1325 | } |
---|
| 1326 | |
---|
| 1327 | if( bHorAbsGr0 ) |
---|
| 1328 | { |
---|
| 1329 | if( uiHorAbs > 1 ) |
---|
| 1330 | { |
---|
| 1331 | xWriteEpExGolomb( uiHorAbs-2, 1 ); |
---|
| 1332 | } |
---|
| 1333 | |
---|
| 1334 | m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 ); |
---|
| 1335 | } |
---|
| 1336 | |
---|
| 1337 | if( bVerAbsGr0 ) |
---|
| 1338 | { |
---|
| 1339 | if( uiVerAbs > 1 ) |
---|
| 1340 | { |
---|
| 1341 | xWriteEpExGolomb( uiVerAbs-2, 1 ); |
---|
| 1342 | } |
---|
| 1343 | |
---|
| 1344 | m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); |
---|
| 1345 | } |
---|
[2] | 1346 | |
---|
| 1347 | return; |
---|
| 1348 | } |
---|
| 1349 | |
---|
| 1350 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1351 | { |
---|
[56] | 1352 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
[2] | 1353 | |
---|
[56] | 1354 | #if H0736_AVC_STYLE_QP_RANGE |
---|
| 1355 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
| 1356 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
| 1357 | #else |
---|
| 1358 | #if LOSSLESS_CODING |
---|
| 1359 | if(pcCU->getSlice()->getSPS()->getUseLossless()) |
---|
| 1360 | { |
---|
| 1361 | if(iDQp > 25) |
---|
| 1362 | { |
---|
| 1363 | iDQp = iDQp - 52; |
---|
| 1364 | } |
---|
| 1365 | if(iDQp < -26) |
---|
| 1366 | { |
---|
| 1367 | iDQp = iDQp + 52; |
---|
| 1368 | } |
---|
| 1369 | } |
---|
| 1370 | #endif |
---|
| 1371 | #endif |
---|
| 1372 | |
---|
[2] | 1373 | if ( iDQp == 0 ) |
---|
| 1374 | { |
---|
| 1375 | m_pcBinIf->encodeBin( 0, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) ); |
---|
| 1376 | } |
---|
| 1377 | else |
---|
| 1378 | { |
---|
| 1379 | m_pcBinIf->encodeBin( 1, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) ); |
---|
[56] | 1380 | |
---|
| 1381 | UInt uiSign = (iDQp > 0 ? 0 : 1); |
---|
| 1382 | #if !H0736_AVC_STYLE_QP_RANGE |
---|
| 1383 | UInt uiQpBdOffsetY = 6*(g_uiBitIncrement + g_uiBitDepth - 8); |
---|
| 1384 | #endif |
---|
| 1385 | |
---|
| 1386 | m_pcBinIf->encodeBinEP(uiSign); |
---|
| 1387 | |
---|
| 1388 | #if H0736_AVC_STYLE_QP_RANGE |
---|
| 1389 | assert(iDQp >= -(26+(qpBdOffsetY/2))); |
---|
| 1390 | assert(iDQp <= (25+(qpBdOffsetY/2))); |
---|
| 1391 | |
---|
| 1392 | UInt uiMaxAbsDQpMinus1 = 24 + (qpBdOffsetY/2) + (uiSign); |
---|
| 1393 | #else |
---|
| 1394 | assert(iDQp >= -(26+(Int)(uiQpBdOffsetY/2))); |
---|
| 1395 | assert(iDQp <= (25+(Int)(uiQpBdOffsetY/2))); |
---|
| 1396 | |
---|
| 1397 | UInt uiMaxAbsDQpMinus1 = 24 + (uiQpBdOffsetY/2) + (uiSign); |
---|
| 1398 | #endif |
---|
| 1399 | UInt uiAbsDQpMinus1 = (UInt)((iDQp > 0)? iDQp : (-iDQp)) - 1; |
---|
| 1400 | xWriteUnaryMaxSymbol( uiAbsDQpMinus1, &m_cCUDeltaQpSCModel.get( 0, 0, 1 ), 1, uiMaxAbsDQpMinus1); |
---|
[2] | 1401 | } |
---|
| 1402 | |
---|
| 1403 | return; |
---|
| 1404 | } |
---|
| 1405 | |
---|
| 1406 | Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
| 1407 | { |
---|
| 1408 | UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
| 1409 | UInt uiCtx = pcCU->getCtxQtCbf( uiAbsPartIdx, eType, uiTrDepth ); |
---|
[56] | 1410 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
| 1411 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1412 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
| 1413 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1414 | DTRACE_CABAC_V( uiCbf ) |
---|
| 1415 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 1416 | DTRACE_CABAC_V( uiCtx ) |
---|
| 1417 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 1418 | DTRACE_CABAC_V( eType ) |
---|
| 1419 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 1420 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1421 | DTRACE_CABAC_T( "\n" ) |
---|
| 1422 | } |
---|
| 1423 | |
---|
[56] | 1424 | #if BURST_IPCM |
---|
| 1425 | /** Code I_PCM information. |
---|
| 1426 | * \param pcCU pointer to CU |
---|
| 1427 | * \param uiAbsPartIdx CU index |
---|
| 1428 | * \param numIPCM the number of succesive IPCM blocks with the same size |
---|
| 1429 | * \param firstIPCMFlag |
---|
| 1430 | * \returns Void |
---|
| 1431 | */ |
---|
| 1432 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Int numIPCM, Bool firstIPCMFlag) |
---|
| 1433 | #else |
---|
| 1434 | /** Code I_PCM information. |
---|
| 1435 | * \param pcCU pointer to CU |
---|
| 1436 | * \param uiAbsPartIdx CU index |
---|
| 1437 | * \returns Void |
---|
| 1438 | * |
---|
| 1439 | * If I_PCM flag indicates that the CU is I_PCM, code its PCM alignment bits and codes. |
---|
| 1440 | */ |
---|
| 1441 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx) |
---|
| 1442 | #endif |
---|
[2] | 1443 | { |
---|
[56] | 1444 | UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0; |
---|
| 1445 | |
---|
| 1446 | #if BURST_IPCM |
---|
| 1447 | Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx); |
---|
| 1448 | |
---|
| 1449 | if( uiIPCM == 0 || firstIPCMFlag) |
---|
[2] | 1450 | { |
---|
[56] | 1451 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
| 1452 | |
---|
| 1453 | if ( firstIPCMFlag ) |
---|
[2] | 1454 | { |
---|
[56] | 1455 | m_pcBinIf->encodeNumSubseqIPCM( numIPCM - 1 ); |
---|
| 1456 | m_pcBinIf->encodePCMAlignBits(); |
---|
| 1457 | } |
---|
| 1458 | } |
---|
| 1459 | #else |
---|
| 1460 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
| 1461 | #endif |
---|
| 1462 | |
---|
| 1463 | #if BURST_IPCM |
---|
| 1464 | if (writePCMSampleFlag) |
---|
| 1465 | #else |
---|
| 1466 | if (uiIPCM) |
---|
| 1467 | #endif |
---|
| 1468 | { |
---|
| 1469 | #if !BURST_IPCM |
---|
| 1470 | m_pcBinIf->encodePCMAlignBits(); |
---|
| 1471 | #endif |
---|
| 1472 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
| 1473 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
| 1474 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
| 1475 | Pel* piPCMSample; |
---|
| 1476 | UInt uiWidth; |
---|
| 1477 | UInt uiHeight; |
---|
| 1478 | UInt uiSampleBits; |
---|
| 1479 | UInt uiX, uiY; |
---|
| 1480 | |
---|
| 1481 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
| 1482 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
| 1483 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
| 1484 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
| 1485 | |
---|
| 1486 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 1487 | { |
---|
| 1488 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
[2] | 1489 | { |
---|
[56] | 1490 | UInt uiSample = piPCMSample[uiX]; |
---|
| 1491 | |
---|
| 1492 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
[2] | 1493 | } |
---|
[56] | 1494 | piPCMSample += uiWidth; |
---|
[2] | 1495 | } |
---|
[56] | 1496 | |
---|
| 1497 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
| 1498 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
| 1499 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
| 1500 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
| 1501 | |
---|
| 1502 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 1503 | { |
---|
| 1504 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 1505 | { |
---|
| 1506 | UInt uiSample = piPCMSample[uiX]; |
---|
| 1507 | |
---|
| 1508 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
| 1509 | } |
---|
| 1510 | piPCMSample += uiWidth; |
---|
| 1511 | } |
---|
| 1512 | |
---|
| 1513 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
| 1514 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
| 1515 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
| 1516 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
| 1517 | |
---|
| 1518 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 1519 | { |
---|
| 1520 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 1521 | { |
---|
| 1522 | UInt uiSample = piPCMSample[uiX]; |
---|
| 1523 | |
---|
| 1524 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
| 1525 | } |
---|
| 1526 | piPCMSample += uiWidth; |
---|
| 1527 | } |
---|
| 1528 | #if BURST_IPCM |
---|
| 1529 | numIPCM--; |
---|
| 1530 | if(numIPCM == 0) |
---|
| 1531 | { |
---|
| 1532 | m_pcBinIf->resetBac(); |
---|
| 1533 | } |
---|
| 1534 | #else |
---|
| 1535 | m_pcBinIf->resetBac(); |
---|
| 1536 | #endif |
---|
[2] | 1537 | } |
---|
| 1538 | } |
---|
| 1539 | |
---|
| 1540 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1541 | { |
---|
| 1542 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
[56] | 1543 | UInt uiCtx = 0; |
---|
[2] | 1544 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
[56] | 1545 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1546 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
| 1547 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1548 | DTRACE_CABAC_V( uiCbf ) |
---|
| 1549 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 1550 | DTRACE_CABAC_V( uiCtx ) |
---|
| 1551 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 1552 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1553 | DTRACE_CABAC_T( "\n" ) |
---|
| 1554 | } |
---|
| 1555 | |
---|
| 1556 | /** Encode (X,Y) position of the last significant coefficient |
---|
| 1557 | * \param uiPosX X component of last coefficient |
---|
| 1558 | * \param uiPosY Y component of last coefficient |
---|
[56] | 1559 | * \param width Block width |
---|
| 1560 | * \param height Block height |
---|
[2] | 1561 | * \param eTType plane type / luminance or chrominance |
---|
| 1562 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
| 1563 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
| 1564 | */ |
---|
[56] | 1565 | Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
[2] | 1566 | { |
---|
[56] | 1567 | // swap |
---|
[2] | 1568 | if( uiScanIdx == SCAN_VER ) |
---|
| 1569 | { |
---|
| 1570 | swap( uiPosX, uiPosY ); |
---|
| 1571 | } |
---|
| 1572 | |
---|
[56] | 1573 | UInt uiCtxLast; |
---|
| 1574 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
| 1575 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
| 1576 | UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; |
---|
| 1577 | UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; |
---|
| 1578 | |
---|
| 1579 | // posX |
---|
| 1580 | #if LAST_CTX_REDUCTION |
---|
| 1581 | Int widthCtx = eTType? 4: width; |
---|
| 1582 | const UInt *puiCtxIdxX = g_uiLastCtx + ( g_aucConvertToBit[ widthCtx ] * ( g_aucConvertToBit[ widthCtx ] + 3 ) ); |
---|
| 1583 | #else |
---|
| 1584 | const UInt *puiCtxIdxX = g_uiLastCtx + ( g_aucConvertToBit[ width ] * ( g_aucConvertToBit[ width ] + 3 ) ); |
---|
| 1585 | #endif |
---|
| 1586 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) |
---|
[2] | 1587 | { |
---|
[56] | 1588 | #if LAST_CTX_REDUCTION |
---|
| 1589 | if (eTType) |
---|
| 1590 | { |
---|
| 1591 | m_pcBinIf->encodeBin( 1, *( pCtxX + (uiCtxLast>>g_aucConvertToBit[ width ]) ) ); |
---|
| 1592 | } |
---|
| 1593 | else |
---|
| 1594 | { |
---|
| 1595 | #endif |
---|
| 1596 | m_pcBinIf->encodeBin( 1, *( pCtxX + puiCtxIdxX[ uiCtxLast ] ) ); |
---|
| 1597 | #if LAST_CTX_REDUCTION |
---|
| 1598 | } |
---|
| 1599 | #endif |
---|
[2] | 1600 | } |
---|
[56] | 1601 | if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) |
---|
[2] | 1602 | { |
---|
[56] | 1603 | #if LAST_CTX_REDUCTION |
---|
| 1604 | if ( eTType ) |
---|
| 1605 | { |
---|
| 1606 | m_pcBinIf->encodeBin( 0, *( pCtxX + (uiCtxLast>>g_aucConvertToBit[ width ]) ) ); |
---|
| 1607 | } |
---|
| 1608 | else |
---|
| 1609 | { |
---|
| 1610 | #endif |
---|
| 1611 | m_pcBinIf->encodeBin( 0, *( pCtxX + puiCtxIdxX[ uiCtxLast ] ) ); |
---|
| 1612 | #if LAST_CTX_REDUCTION |
---|
| 1613 | } |
---|
| 1614 | #endif |
---|
[2] | 1615 | } |
---|
| 1616 | |
---|
[56] | 1617 | // posY |
---|
| 1618 | #if LAST_CTX_REDUCTION |
---|
| 1619 | Int heightCtx = eTType? 4: height; |
---|
| 1620 | const UInt *puiCtxIdxY = g_uiLastCtx + ( g_aucConvertToBit[ heightCtx ] * ( g_aucConvertToBit[ heightCtx ] + 3 ) ); |
---|
| 1621 | #else |
---|
| 1622 | const UInt *puiCtxIdxY = g_uiLastCtx + ( g_aucConvertToBit[ height ] * ( g_aucConvertToBit[ height ] + 3 ) ); |
---|
| 1623 | #endif |
---|
| 1624 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) |
---|
[2] | 1625 | { |
---|
[56] | 1626 | #if LAST_CTX_REDUCTION |
---|
| 1627 | if (eTType) |
---|
| 1628 | { |
---|
| 1629 | m_pcBinIf->encodeBin( 1, *( pCtxY + (uiCtxLast>>g_aucConvertToBit[ height ]))); |
---|
| 1630 | } |
---|
| 1631 | else |
---|
| 1632 | { |
---|
| 1633 | #endif |
---|
| 1634 | m_pcBinIf->encodeBin( 1, *( pCtxY + puiCtxIdxY[ uiCtxLast ] ) ); |
---|
| 1635 | #if LAST_CTX_REDUCTION |
---|
| 1636 | } |
---|
| 1637 | #endif |
---|
[2] | 1638 | } |
---|
[56] | 1639 | if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ]) |
---|
[2] | 1640 | { |
---|
[56] | 1641 | #if LAST_CTX_REDUCTION |
---|
| 1642 | if (eTType) |
---|
| 1643 | { |
---|
| 1644 | m_pcBinIf->encodeBin( 0, *( pCtxY + (uiCtxLast>>g_aucConvertToBit[ height ]) ) ); |
---|
| 1645 | } |
---|
| 1646 | else |
---|
| 1647 | { |
---|
| 1648 | #endif |
---|
| 1649 | m_pcBinIf->encodeBin( 0, *( pCtxY + puiCtxIdxY[ uiCtxLast ] ) ); |
---|
| 1650 | #if LAST_CTX_REDUCTION |
---|
| 1651 | } |
---|
| 1652 | #endif |
---|
| 1653 | } |
---|
| 1654 | if ( uiGroupIdxX > 3 ) |
---|
| 1655 | { |
---|
| 1656 | UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; |
---|
| 1657 | uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; |
---|
| 1658 | for (Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
| 1659 | { |
---|
| 1660 | m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 ); |
---|
| 1661 | } |
---|
[2] | 1662 | } |
---|
[56] | 1663 | if ( uiGroupIdxY > 3 ) |
---|
| 1664 | { |
---|
| 1665 | UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; |
---|
| 1666 | uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; |
---|
| 1667 | for ( Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
| 1668 | { |
---|
| 1669 | m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 ); |
---|
| 1670 | } |
---|
| 1671 | } |
---|
[2] | 1672 | } |
---|
| 1673 | |
---|
[56] | 1674 | Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
[2] | 1675 | { |
---|
[56] | 1676 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1677 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
| 1678 | DTRACE_CABAC_V( eTType ) |
---|
| 1679 | DTRACE_CABAC_T( "\twidth=" ) |
---|
| 1680 | DTRACE_CABAC_V( uiWidth ) |
---|
| 1681 | DTRACE_CABAC_T( "\theight=" ) |
---|
| 1682 | DTRACE_CABAC_V( uiHeight ) |
---|
| 1683 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
| 1684 | DTRACE_CABAC_V( uiDepth ) |
---|
| 1685 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
| 1686 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1687 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
| 1688 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
| 1689 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
| 1690 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
| 1691 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
| 1692 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
| 1693 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
| 1694 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1695 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
| 1696 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1697 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
| 1698 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
| 1699 | DTRACE_CABAC_T( "\n" ) |
---|
[56] | 1700 | |
---|
[2] | 1701 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
| 1702 | { |
---|
| 1703 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
| 1704 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
| 1705 | } |
---|
| 1706 | |
---|
| 1707 | UInt uiNumSig = 0; |
---|
| 1708 | |
---|
| 1709 | // compute number of significant coefficients |
---|
[56] | 1710 | uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); |
---|
[2] | 1711 | |
---|
| 1712 | if ( uiNumSig == 0 ) |
---|
| 1713 | return; |
---|
| 1714 | |
---|
| 1715 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
| 1716 | |
---|
| 1717 | //----- encode significance map ----- |
---|
| 1718 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
[56] | 1719 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
| 1720 | if (uiScanIdx == SCAN_ZIGZAG) |
---|
| 1721 | { |
---|
| 1722 | // Map zigzag to diagonal scan |
---|
| 1723 | uiScanIdx = SCAN_DIAG; |
---|
| 1724 | } |
---|
| 1725 | Int blockType = uiLog2BlockSize; |
---|
| 1726 | if (uiWidth != uiHeight) |
---|
| 1727 | { |
---|
| 1728 | uiScanIdx = SCAN_DIAG; |
---|
| 1729 | blockType = 4; |
---|
| 1730 | } |
---|
[2] | 1731 | |
---|
[56] | 1732 | const UInt * scan; |
---|
| 1733 | if (uiWidth == uiHeight) |
---|
| 1734 | { |
---|
| 1735 | scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize - 1 ]; |
---|
| 1736 | } |
---|
| 1737 | else |
---|
| 1738 | { |
---|
| 1739 | scan = g_sigScanNSQT[ uiLog2BlockSize - 2 ]; |
---|
| 1740 | } |
---|
| 1741 | |
---|
| 1742 | #if MULTIBITS_DATA_HIDING |
---|
| 1743 | UInt const tsig = pcCU->getSlice()->getPPS()->getTSIG(); |
---|
| 1744 | #if LOSSLESS_CODING |
---|
| 1745 | Bool beValid; |
---|
| 1746 | if (pcCU->isLosslessCoded(uiAbsPartIdx)) |
---|
| 1747 | { |
---|
| 1748 | beValid = false; |
---|
| 1749 | } |
---|
| 1750 | else |
---|
| 1751 | { |
---|
| 1752 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
| 1753 | } |
---|
[2] | 1754 | #else |
---|
[56] | 1755 | Bool beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
| 1756 | #endif |
---|
| 1757 | #endif |
---|
[2] | 1758 | |
---|
[56] | 1759 | // Find position of last coefficient |
---|
| 1760 | Int scanPosLast = -1; |
---|
| 1761 | Int posLast; |
---|
| 1762 | |
---|
| 1763 | const UInt * scanCG; |
---|
| 1764 | if (uiWidth == uiHeight) |
---|
| 1765 | { |
---|
| 1766 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
| 1767 | #if MULTILEVEL_SIGMAP_EXT |
---|
| 1768 | if( uiLog2BlockSize == 3 ) |
---|
| 1769 | { |
---|
| 1770 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
[2] | 1771 | } |
---|
[56] | 1772 | else if( uiLog2BlockSize == 5 ) |
---|
| 1773 | { |
---|
| 1774 | scanCG = g_sigLastScanCG32x32; |
---|
| 1775 | } |
---|
| 1776 | #endif |
---|
| 1777 | } |
---|
| 1778 | else |
---|
| 1779 | { |
---|
| 1780 | scanCG = g_sigCGScanNSQT[ uiLog2BlockSize - 2 ]; |
---|
| 1781 | } |
---|
| 1782 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
| 1783 | static const UInt uiShift = MLS_CG_SIZE >> 1; |
---|
| 1784 | const UInt uiNumBlkSide = uiWidth >> uiShift; |
---|
[2] | 1785 | |
---|
[56] | 1786 | #if !MULTILEVEL_SIGMAP_EXT |
---|
| 1787 | if( blockType > 3 ) |
---|
| 1788 | { |
---|
| 1789 | #endif |
---|
| 1790 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
| 1791 | |
---|
| 1792 | do |
---|
[2] | 1793 | { |
---|
[56] | 1794 | posLast = scan[ ++scanPosLast ]; |
---|
| 1795 | |
---|
| 1796 | // get L1 sig map |
---|
| 1797 | UInt uiPosY = posLast >> uiLog2BlockSize; |
---|
| 1798 | UInt uiPosX = posLast - ( uiPosY << uiLog2BlockSize ); |
---|
| 1799 | UInt uiBlkIdx = uiNumBlkSide * (uiPosY >> uiShift) + (uiPosX >> uiShift); |
---|
| 1800 | #if MULTILEVEL_SIGMAP_EXT |
---|
| 1801 | if( uiWidth == 8 && uiHeight == 8 && (uiScanIdx == SCAN_HOR || uiScanIdx == SCAN_VER) ) |
---|
[2] | 1802 | { |
---|
[56] | 1803 | if( uiScanIdx == SCAN_HOR ) |
---|
[2] | 1804 | { |
---|
[56] | 1805 | uiBlkIdx = uiPosY >> 1; |
---|
[2] | 1806 | } |
---|
[56] | 1807 | else if( uiScanIdx == SCAN_VER ) |
---|
[2] | 1808 | { |
---|
[56] | 1809 | uiBlkIdx = uiPosX >> 1; |
---|
[2] | 1810 | } |
---|
| 1811 | } |
---|
| 1812 | #endif |
---|
[56] | 1813 | if( pcCoef[ posLast ] ) |
---|
[2] | 1814 | { |
---|
[56] | 1815 | uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; |
---|
[2] | 1816 | } |
---|
[56] | 1817 | |
---|
| 1818 | uiNumSig -= ( pcCoef[ posLast ] != 0 ); |
---|
[2] | 1819 | } |
---|
[56] | 1820 | while ( uiNumSig > 0 ); |
---|
| 1821 | #if !MULTILEVEL_SIGMAP_EXT |
---|
[2] | 1822 | } |
---|
[56] | 1823 | else |
---|
| 1824 | { |
---|
| 1825 | |
---|
| 1826 | do |
---|
| 1827 | { |
---|
| 1828 | posLast = scan[ ++scanPosLast ]; |
---|
| 1829 | uiNumSig -= ( pcCoef[ posLast ] != 0 ); |
---|
| 1830 | } |
---|
| 1831 | while ( uiNumSig > 0 ); |
---|
| 1832 | |
---|
| 1833 | } |
---|
[2] | 1834 | #endif |
---|
| 1835 | |
---|
[56] | 1836 | // Code position of last coefficient |
---|
| 1837 | Int posLastY = posLast >> uiLog2BlockSize; |
---|
| 1838 | Int posLastX = posLast - ( posLastY << uiLog2BlockSize ); |
---|
| 1839 | codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, eTType, uiScanIdx); |
---|
| 1840 | |
---|
| 1841 | //===== code significance flag ===== |
---|
| 1842 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
| 1843 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
| 1844 | |
---|
| 1845 | |
---|
| 1846 | const Int iLastScanSet = scanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
| 1847 | UInt uiNumOne = 0; |
---|
| 1848 | UInt uiGoRiceParam = 0; |
---|
| 1849 | Int iScanPosSig = scanPosLast; |
---|
| 1850 | |
---|
| 1851 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
[2] | 1852 | { |
---|
[56] | 1853 | Int numNonZero = 0; |
---|
| 1854 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
| 1855 | uiGoRiceParam = 0; |
---|
| 1856 | Int absCoeff[16]; |
---|
| 1857 | UInt coeffSigns = 0; |
---|
| 1858 | |
---|
| 1859 | #if MULTIBITS_DATA_HIDING |
---|
| 1860 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
| 1861 | #endif |
---|
| 1862 | |
---|
| 1863 | if( iScanPosSig == scanPosLast ) |
---|
[2] | 1864 | { |
---|
[56] | 1865 | absCoeff[ 0 ] = abs( pcCoef[ posLast ] ); |
---|
| 1866 | coeffSigns = ( pcCoef[ posLast ] < 0 ); |
---|
| 1867 | numNonZero = 1; |
---|
| 1868 | #if MULTIBITS_DATA_HIDING |
---|
| 1869 | lastNZPosInCG = iScanPosSig; |
---|
| 1870 | firstNZPosInCG = iScanPosSig; |
---|
[2] | 1871 | #endif |
---|
[56] | 1872 | iScanPosSig--; |
---|
| 1873 | } |
---|
[2] | 1874 | |
---|
[56] | 1875 | #if !MULTILEVEL_SIGMAP_EXT |
---|
| 1876 | if( blockType > 3 ) |
---|
| 1877 | { |
---|
| 1878 | #endif |
---|
| 1879 | // encode significant_coeffgroup_flag |
---|
| 1880 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
| 1881 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
| 1882 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
| 1883 | #if MULTILEVEL_SIGMAP_EXT |
---|
| 1884 | if( uiWidth == 8 && uiHeight == 8 && (uiScanIdx == SCAN_HOR || uiScanIdx == SCAN_VER) ) |
---|
[2] | 1885 | { |
---|
[56] | 1886 | iCGPosY = (uiScanIdx == SCAN_HOR ? iCGBlkPos : 0); |
---|
| 1887 | iCGPosX = (uiScanIdx == SCAN_VER ? iCGBlkPos : 0); |
---|
[2] | 1888 | } |
---|
[56] | 1889 | #endif |
---|
| 1890 | #if !REMOVE_INFER_SIGGRP |
---|
| 1891 | Bool bInferredCGFlag = false; |
---|
| 1892 | #endif |
---|
| 1893 | #if REMOVE_INFER_SIGGRP |
---|
| 1894 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
| 1895 | #else |
---|
| 1896 | if( iSubSet == iLastScanSet ) |
---|
| 1897 | #endif |
---|
[2] | 1898 | { |
---|
[56] | 1899 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
| 1900 | } |
---|
| 1901 | else |
---|
| 1902 | { |
---|
| 1903 | #if !REMOVE_INFER_SIGGRP |
---|
| 1904 | #if MULTILEVEL_SIGMAP_EXT |
---|
| 1905 | if( !TComTrQuant::bothCGNeighboursOne( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiScanIdx, uiWidth, uiHeight ) && ( iSubSet ) ) |
---|
| 1906 | #else |
---|
| 1907 | if( !TComTrQuant::bothCGNeighboursOne( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ) && ( iSubSet ) ) |
---|
| 1908 | #endif |
---|
[2] | 1909 | { |
---|
[56] | 1910 | #endif |
---|
| 1911 | UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); |
---|
| 1912 | #if MULTILEVEL_SIGMAP_EXT |
---|
| 1913 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiScanIdx, uiWidth, uiHeight ); |
---|
| 1914 | #else |
---|
| 1915 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
| 1916 | #endif |
---|
| 1917 | m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
| 1918 | #if !REMOVE_INFER_SIGGRP |
---|
[2] | 1919 | } |
---|
| 1920 | else |
---|
| 1921 | { |
---|
[56] | 1922 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
| 1923 | bInferredCGFlag = true; |
---|
[2] | 1924 | } |
---|
[56] | 1925 | #endif |
---|
| 1926 | } |
---|
| 1927 | |
---|
| 1928 | // encode significant_coeff_flag |
---|
| 1929 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
| 1930 | { |
---|
| 1931 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
| 1932 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
[2] | 1933 | { |
---|
[56] | 1934 | uiBlkPos = scan[ iScanPosSig ]; |
---|
| 1935 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
| 1936 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
| 1937 | uiSig = (pcCoef[ uiBlkPos ] != 0); |
---|
| 1938 | #if REMOVE_INFER_SIGGRP |
---|
| 1939 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
| 1940 | #else |
---|
| 1941 | if( iScanPosSig > iSubPos || bInferredCGFlag || numNonZero ) |
---|
| 1942 | #endif |
---|
[2] | 1943 | { |
---|
[56] | 1944 | uiCtxSig = TComTrQuant::getSigCtxInc( pcCoef, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType ); |
---|
| 1945 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
| 1946 | } |
---|
| 1947 | if( uiSig ) |
---|
| 1948 | { |
---|
| 1949 | absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); |
---|
| 1950 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
| 1951 | numNonZero++; |
---|
| 1952 | #if MULTIBITS_DATA_HIDING |
---|
| 1953 | if( lastNZPosInCG == -1 ) |
---|
[2] | 1954 | { |
---|
[56] | 1955 | lastNZPosInCG = iScanPosSig; |
---|
[2] | 1956 | } |
---|
[56] | 1957 | firstNZPosInCG = iScanPosSig; |
---|
| 1958 | #endif |
---|
[2] | 1959 | } |
---|
| 1960 | } |
---|
[56] | 1961 | } |
---|
| 1962 | else |
---|
| 1963 | { |
---|
| 1964 | iScanPosSig = iSubPos - 1; |
---|
| 1965 | } |
---|
| 1966 | #if !MULTILEVEL_SIGMAP_EXT |
---|
| 1967 | } |
---|
| 1968 | else |
---|
| 1969 | { |
---|
| 1970 | |
---|
| 1971 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
| 1972 | { |
---|
| 1973 | UInt uiBlkPos = scan[ iScanPosSig ]; |
---|
| 1974 | UInt uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
| 1975 | UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
| 1976 | UInt uiSig = 0; |
---|
| 1977 | if( pcCoef[ uiBlkPos ] != 0 ) |
---|
| 1978 | { |
---|
| 1979 | uiSig = 1; |
---|
| 1980 | absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); |
---|
| 1981 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
| 1982 | numNonZero++; |
---|
| 1983 | #if MULTIBITS_DATA_HIDING |
---|
| 1984 | if( lastNZPosInCG == -1 ) |
---|
[2] | 1985 | { |
---|
[56] | 1986 | lastNZPosInCG = iScanPosSig; |
---|
| 1987 | } |
---|
| 1988 | firstNZPosInCG = iScanPosSig; |
---|
| 1989 | #endif |
---|
| 1990 | } |
---|
| 1991 | UInt uiCtxSig = TComTrQuant::getSigCtxInc( pcCoef, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType ); |
---|
| 1992 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
| 1993 | } |
---|
[2] | 1994 | |
---|
[56] | 1995 | } |
---|
| 1996 | #endif |
---|
[2] | 1997 | |
---|
[56] | 1998 | if( numNonZero > 0 ) |
---|
| 1999 | { |
---|
| 2000 | #if MULTIBITS_DATA_HIDING |
---|
| 2001 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= (Int)tsig ); |
---|
| 2002 | #endif // MULTIBITS_DATA_HIDING |
---|
| 2003 | |
---|
| 2004 | UInt c1 = 1; |
---|
| 2005 | #if !RESTRICT_GR1GR2FLAG_NUMBER |
---|
| 2006 | UInt c2 = 0; |
---|
| 2007 | #endif |
---|
| 2008 | #if LEVEL_CTX_LUMA_RED |
---|
| 2009 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
[2] | 2010 | #else |
---|
[56] | 2011 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 3 : 0; |
---|
[2] | 2012 | #endif |
---|
[56] | 2013 | |
---|
| 2014 | if( uiNumOne > 0 ) |
---|
| 2015 | { |
---|
| 2016 | uiCtxSet++; |
---|
| 2017 | #if !LEVEL_CTX_LUMA_RED |
---|
| 2018 | if( uiNumOne > 3 && eTType==TEXT_LUMA) |
---|
[2] | 2019 | { |
---|
[56] | 2020 | uiCtxSet++; |
---|
[2] | 2021 | } |
---|
[56] | 2022 | #endif |
---|
[2] | 2023 | } |
---|
| 2024 | |
---|
[56] | 2025 | uiNumOne >>= 1; |
---|
| 2026 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
| 2027 | |
---|
| 2028 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
| 2029 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
| 2030 | Int firstC2FlagIdx = -1; |
---|
| 2031 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
| 2032 | #else |
---|
| 2033 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 2034 | #endif |
---|
[2] | 2035 | { |
---|
[56] | 2036 | UInt uiSymbol = absCoeff[ idx ] > 1; |
---|
| 2037 | m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] ); |
---|
[2] | 2038 | if( uiSymbol ) |
---|
| 2039 | { |
---|
| 2040 | c1 = 0; |
---|
[56] | 2041 | |
---|
| 2042 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
| 2043 | if (firstC2FlagIdx == -1) |
---|
| 2044 | { |
---|
| 2045 | firstC2FlagIdx = idx; |
---|
| 2046 | } |
---|
| 2047 | #endif |
---|
[2] | 2048 | } |
---|
[56] | 2049 | else if( (c1 < 3) && (c1 > 0) ) |
---|
[2] | 2050 | { |
---|
| 2051 | c1++; |
---|
| 2052 | } |
---|
| 2053 | } |
---|
| 2054 | |
---|
[56] | 2055 | if (c1 == 0) |
---|
[2] | 2056 | { |
---|
[56] | 2057 | |
---|
| 2058 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
| 2059 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
| 2060 | if ( firstC2FlagIdx != -1) |
---|
[2] | 2061 | { |
---|
[56] | 2062 | UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; |
---|
| 2063 | m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); |
---|
| 2064 | } |
---|
| 2065 | #else |
---|
| 2066 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + 3 * uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + 3 * uiCtxSet; |
---|
| 2067 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 2068 | { |
---|
| 2069 | if( absCoeff[ idx ] > 1 ) |
---|
[2] | 2070 | { |
---|
[56] | 2071 | UInt symbol = absCoeff[ idx ] > 2; |
---|
| 2072 | m_pcBinIf->encodeBin( symbol, baseCtxMod[c2] ); |
---|
| 2073 | c2 += (c2 < 2); |
---|
| 2074 | uiNumOne++; |
---|
[2] | 2075 | } |
---|
[56] | 2076 | } |
---|
[2] | 2077 | #endif |
---|
| 2078 | } |
---|
| 2079 | |
---|
[56] | 2080 | #if MULTIBITS_DATA_HIDING |
---|
| 2081 | if( beValid && signHidden ) |
---|
[2] | 2082 | { |
---|
[56] | 2083 | m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 ); |
---|
[2] | 2084 | } |
---|
[56] | 2085 | else |
---|
| 2086 | { |
---|
| 2087 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
| 2088 | } |
---|
[2] | 2089 | #else |
---|
[56] | 2090 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
[2] | 2091 | #endif |
---|
[56] | 2092 | |
---|
| 2093 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
| 2094 | Int iFirstCoeff2 = 1; |
---|
| 2095 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
[2] | 2096 | #else |
---|
[56] | 2097 | if (c1 == 0) |
---|
[2] | 2098 | #endif |
---|
[56] | 2099 | { |
---|
| 2100 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 2101 | { |
---|
| 2102 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
| 2103 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1; |
---|
[2] | 2104 | |
---|
[56] | 2105 | if( absCoeff[ idx ] >= baseLevel) |
---|
| 2106 | { |
---|
| 2107 | xWriteGoRiceExGolomb( absCoeff[ idx ] - baseLevel, uiGoRiceParam ); |
---|
| 2108 | } |
---|
| 2109 | if(absCoeff[ idx ] >= 2) |
---|
| 2110 | { |
---|
| 2111 | iFirstCoeff2 = 0; |
---|
| 2112 | uiNumOne++; |
---|
| 2113 | } |
---|
| 2114 | #else |
---|
| 2115 | if ( absCoeff[ idx ] > 2 ) |
---|
| 2116 | { |
---|
| 2117 | xWriteGoRiceExGolomb( absCoeff[ idx ] - 3, uiGoRiceParam ); |
---|
| 2118 | } |
---|
| 2119 | #endif |
---|
| 2120 | } |
---|
| 2121 | } |
---|
[2] | 2122 | } |
---|
[56] | 2123 | else |
---|
[2] | 2124 | { |
---|
[56] | 2125 | uiNumOne >>= 1; |
---|
[2] | 2126 | } |
---|
| 2127 | } |
---|
[56] | 2128 | |
---|
[2] | 2129 | return; |
---|
| 2130 | } |
---|
| 2131 | |
---|
| 2132 | Void TEncSbac::codeAlfFlag ( UInt uiCode ) |
---|
| 2133 | { |
---|
| 2134 | UInt uiSymbol = ( ( uiCode == 0 ) ? 0 : 1 ); |
---|
| 2135 | m_pcBinIf->encodeBin( uiSymbol, m_cALFFlagSCModel.get( 0, 0, 0 ) ); |
---|
| 2136 | } |
---|
| 2137 | |
---|
| 2138 | Void TEncSbac::codeAlfCtrlFlag( UInt uiSymbol ) |
---|
| 2139 | { |
---|
| 2140 | m_pcBinIf->encodeBin( uiSymbol, m_cCUAlfCtrlFlagSCModel.get( 0, 0, 0) ); |
---|
| 2141 | } |
---|
| 2142 | |
---|
| 2143 | Void TEncSbac::codeAlfUvlc ( UInt uiCode ) |
---|
| 2144 | { |
---|
| 2145 | Int i; |
---|
| 2146 | |
---|
| 2147 | if ( uiCode == 0 ) |
---|
| 2148 | { |
---|
| 2149 | m_pcBinIf->encodeBin( 0, m_cALFUvlcSCModel.get( 0, 0, 0 ) ); |
---|
| 2150 | } |
---|
| 2151 | else |
---|
| 2152 | { |
---|
| 2153 | m_pcBinIf->encodeBin( 1, m_cALFUvlcSCModel.get( 0, 0, 0 ) ); |
---|
| 2154 | for ( i=0; i<uiCode-1; i++ ) |
---|
| 2155 | { |
---|
| 2156 | m_pcBinIf->encodeBin( 1, m_cALFUvlcSCModel.get( 0, 0, 1 ) ); |
---|
| 2157 | } |
---|
| 2158 | m_pcBinIf->encodeBin( 0, m_cALFUvlcSCModel.get( 0, 0, 1 ) ); |
---|
| 2159 | } |
---|
| 2160 | } |
---|
| 2161 | |
---|
| 2162 | Void TEncSbac::codeAlfSvlc ( Int iCode ) |
---|
| 2163 | { |
---|
| 2164 | Int i; |
---|
| 2165 | |
---|
| 2166 | if ( iCode == 0 ) |
---|
| 2167 | { |
---|
| 2168 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 0 ) ); |
---|
| 2169 | } |
---|
| 2170 | else |
---|
| 2171 | { |
---|
| 2172 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 0 ) ); |
---|
| 2173 | |
---|
| 2174 | // write sign |
---|
| 2175 | if ( iCode > 0 ) |
---|
| 2176 | { |
---|
| 2177 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 1 ) ); |
---|
| 2178 | } |
---|
| 2179 | else |
---|
| 2180 | { |
---|
| 2181 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 1 ) ); |
---|
| 2182 | iCode = -iCode; |
---|
| 2183 | } |
---|
| 2184 | |
---|
| 2185 | // write magnitude |
---|
| 2186 | for ( i=0; i<iCode-1; i++ ) |
---|
| 2187 | { |
---|
| 2188 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 2 ) ); |
---|
| 2189 | } |
---|
| 2190 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 2 ) ); |
---|
| 2191 | } |
---|
| 2192 | } |
---|
| 2193 | |
---|
[56] | 2194 | Void TEncSbac::codeSaoFlag ( UInt uiCode ) |
---|
[2] | 2195 | { |
---|
| 2196 | UInt uiSymbol = ( ( uiCode == 0 ) ? 0 : 1 ); |
---|
[56] | 2197 | m_pcBinIf->encodeBin( uiSymbol, m_cSaoFlagSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 2198 | } |
---|
[56] | 2199 | |
---|
| 2200 | Void TEncSbac::codeSaoUvlc ( UInt uiCode ) |
---|
[2] | 2201 | { |
---|
| 2202 | Int i; |
---|
| 2203 | |
---|
| 2204 | if ( uiCode == 0 ) |
---|
| 2205 | { |
---|
[56] | 2206 | m_pcBinIf->encodeBin( 0, m_cSaoUvlcSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 2207 | } |
---|
| 2208 | else |
---|
| 2209 | { |
---|
[56] | 2210 | m_pcBinIf->encodeBin( 1, m_cSaoUvlcSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 2211 | for ( i=0; i<uiCode-1; i++ ) |
---|
| 2212 | { |
---|
[56] | 2213 | m_pcBinIf->encodeBin( 1, m_cSaoUvlcSCModel.get( 0, 0, 1 ) ); |
---|
[2] | 2214 | } |
---|
[56] | 2215 | m_pcBinIf->encodeBin( 0, m_cSaoUvlcSCModel.get( 0, 0, 1 ) ); |
---|
[2] | 2216 | } |
---|
| 2217 | } |
---|
[56] | 2218 | |
---|
| 2219 | Void TEncSbac::codeSaoSvlc ( Int iCode ) |
---|
[2] | 2220 | { |
---|
| 2221 | Int i; |
---|
| 2222 | |
---|
| 2223 | if ( iCode == 0 ) |
---|
| 2224 | { |
---|
[56] | 2225 | m_pcBinIf->encodeBin( 0, m_cSaoSvlcSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 2226 | } |
---|
| 2227 | else |
---|
| 2228 | { |
---|
[56] | 2229 | m_pcBinIf->encodeBin( 1, m_cSaoSvlcSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 2230 | |
---|
| 2231 | // write sign |
---|
| 2232 | if ( iCode > 0 ) |
---|
| 2233 | { |
---|
[56] | 2234 | m_pcBinIf->encodeBin( 0, m_cSaoSvlcSCModel.get( 0, 0, 1 ) ); |
---|
[2] | 2235 | } |
---|
| 2236 | else |
---|
| 2237 | { |
---|
[56] | 2238 | m_pcBinIf->encodeBin( 1, m_cSaoSvlcSCModel.get( 0, 0, 1 ) ); |
---|
[2] | 2239 | iCode = -iCode; |
---|
| 2240 | } |
---|
| 2241 | |
---|
| 2242 | // write magnitude |
---|
| 2243 | for ( i=0; i<iCode-1; i++ ) |
---|
| 2244 | { |
---|
[56] | 2245 | m_pcBinIf->encodeBin( 1, m_cSaoSvlcSCModel.get( 0, 0, 2 ) ); |
---|
[2] | 2246 | } |
---|
[56] | 2247 | m_pcBinIf->encodeBin( 0, m_cSaoSvlcSCModel.get( 0, 0, 2 ) ); |
---|
[2] | 2248 | } |
---|
| 2249 | } |
---|
[56] | 2250 | #if SAO_UNIT_INTERLEAVING |
---|
| 2251 | /** Code SAO band position |
---|
| 2252 | * \param uiCode |
---|
| 2253 | */ |
---|
| 2254 | Void TEncSbac::codeSaoUflc ( UInt uiCode ) |
---|
| 2255 | { |
---|
| 2256 | for (Int i=0;i<5;i++) |
---|
| 2257 | { |
---|
| 2258 | m_pcBinIf->encodeBinEP ( (uiCode>>i) &0x01 ); |
---|
| 2259 | } |
---|
| 2260 | } |
---|
| 2261 | /** Code SAO merge left flag |
---|
| 2262 | * \param uiCode |
---|
| 2263 | * \param uiCompIdx |
---|
| 2264 | */ |
---|
| 2265 | Void TEncSbac::codeSaoMergeLeft ( UInt uiCode, UInt uiCompIdx ) |
---|
| 2266 | { |
---|
| 2267 | if (uiCode == 0) |
---|
| 2268 | { |
---|
| 2269 | m_pcBinIf->encodeBin(0, m_cSaoMergeLeftSCModel.get( 0, 0, uiCompIdx )); |
---|
| 2270 | } |
---|
| 2271 | else |
---|
| 2272 | { |
---|
| 2273 | m_pcBinIf->encodeBin(1, m_cSaoMergeLeftSCModel.get( 0, 0, uiCompIdx )); |
---|
| 2274 | } |
---|
| 2275 | } |
---|
| 2276 | /** Code SAO merge up flag |
---|
| 2277 | * \param uiCode |
---|
| 2278 | */ |
---|
| 2279 | Void TEncSbac::codeSaoMergeUp ( UInt uiCode) |
---|
| 2280 | { |
---|
| 2281 | if (uiCode == 0) |
---|
| 2282 | { |
---|
| 2283 | m_pcBinIf->encodeBin(0, m_cSaoMergeUpSCModel.get( 0, 0, 0 )); |
---|
| 2284 | } |
---|
| 2285 | else |
---|
| 2286 | { |
---|
| 2287 | m_pcBinIf->encodeBin(1, m_cSaoMergeUpSCModel.get( 0, 0, 0 )); |
---|
| 2288 | } |
---|
| 2289 | } |
---|
| 2290 | /** Code SAO type index |
---|
| 2291 | * \param uiCode |
---|
| 2292 | */ |
---|
| 2293 | Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) |
---|
| 2294 | { |
---|
| 2295 | Int i; |
---|
| 2296 | if ( uiCode == 0 ) |
---|
| 2297 | { |
---|
| 2298 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
| 2299 | } |
---|
| 2300 | else |
---|
| 2301 | { |
---|
| 2302 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
| 2303 | for ( i=0; i<uiCode-1; i++ ) |
---|
| 2304 | { |
---|
| 2305 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 1 ) ); |
---|
| 2306 | } |
---|
| 2307 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 1 ) ); |
---|
| 2308 | } |
---|
| 2309 | } |
---|
[2] | 2310 | #endif |
---|
| 2311 | /*! |
---|
| 2312 | **************************************************************************** |
---|
| 2313 | * \brief |
---|
| 2314 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
| 2315 | **************************************************************************** |
---|
| 2316 | */ |
---|
[56] | 2317 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
[2] | 2318 | { |
---|
| 2319 | estCBFBit( pcEstBitsSbac, 0, eTType ); |
---|
[56] | 2320 | |
---|
| 2321 | estSignificantCoeffGroupMapBit( pcEstBitsSbac, 0, eTType ); |
---|
[2] | 2322 | |
---|
| 2323 | // encode significance map |
---|
[56] | 2324 | estSignificantMapBit( pcEstBitsSbac, width, height, eTType ); |
---|
[2] | 2325 | |
---|
| 2326 | // encode significant coefficients |
---|
[56] | 2327 | estSignificantCoefficientsBit( pcEstBitsSbac, 0, eTType ); |
---|
[2] | 2328 | } |
---|
| 2329 | |
---|
| 2330 | /*! |
---|
| 2331 | **************************************************************************** |
---|
| 2332 | * \brief |
---|
| 2333 | * estimate bit cost for each CBP bit |
---|
| 2334 | **************************************************************************** |
---|
| 2335 | */ |
---|
| 2336 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
| 2337 | { |
---|
| 2338 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
| 2339 | |
---|
[56] | 2340 | for( UInt uiCtxInc = 0; uiCtxInc < 3*NUM_QT_CBF_CTX; uiCtxInc++ ) |
---|
[2] | 2341 | { |
---|
[56] | 2342 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
| 2343 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
[2] | 2344 | } |
---|
| 2345 | |
---|
[56] | 2346 | pCtx = m_cCUQtRootCbfSCModel.get( 0 ); |
---|
| 2347 | |
---|
[2] | 2348 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
| 2349 | { |
---|
[56] | 2350 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
| 2351 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
[2] | 2352 | } |
---|
| 2353 | } |
---|
| 2354 | |
---|
| 2355 | |
---|
| 2356 | /*! |
---|
| 2357 | **************************************************************************** |
---|
| 2358 | * \brief |
---|
[56] | 2359 | * estimate SAMBAC bit cost for significant coefficient group map |
---|
[2] | 2360 | **************************************************************************** |
---|
| 2361 | */ |
---|
[56] | 2362 | Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
[2] | 2363 | { |
---|
[56] | 2364 | Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; |
---|
| 2365 | |
---|
| 2366 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
[2] | 2367 | { |
---|
| 2368 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
| 2369 | { |
---|
[56] | 2370 | pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, eTType, ctxIdx ).getEntropyBits( uiBin ); |
---|
| 2371 | } |
---|
| 2372 | } |
---|
| 2373 | } |
---|
| 2374 | |
---|
| 2375 | |
---|
| 2376 | /*! |
---|
| 2377 | **************************************************************************** |
---|
| 2378 | * \brief |
---|
| 2379 | * estimate SAMBAC bit cost for significant coefficient map |
---|
| 2380 | **************************************************************************** |
---|
| 2381 | */ |
---|
| 2382 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
| 2383 | { |
---|
| 2384 | Int firstCtx = 0, numCtx = (eTType == TEXT_LUMA) ? 9 : 6; |
---|
| 2385 | if (std::max(width, height) >= 16) |
---|
| 2386 | { |
---|
| 2387 | firstCtx = (eTType == TEXT_LUMA) ? 20 : 17; |
---|
| 2388 | numCtx = (eTType == TEXT_LUMA) ? 7 : 4; |
---|
| 2389 | } |
---|
| 2390 | else if (width == 8) |
---|
| 2391 | { |
---|
| 2392 | firstCtx = (eTType == TEXT_LUMA) ? 9 : 6; |
---|
| 2393 | numCtx = 11; |
---|
| 2394 | } |
---|
| 2395 | |
---|
| 2396 | if (eTType == TEXT_LUMA ) |
---|
| 2397 | { |
---|
| 2398 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
| 2399 | { |
---|
| 2400 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
[2] | 2401 | { |
---|
[56] | 2402 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, ctxIdx ).getEntropyBits( uiBin ); |
---|
[2] | 2403 | } |
---|
[56] | 2404 | } |
---|
| 2405 | } |
---|
| 2406 | else |
---|
| 2407 | { |
---|
| 2408 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
| 2409 | { |
---|
| 2410 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
[2] | 2411 | { |
---|
[56] | 2412 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx ).getEntropyBits( uiBin ); |
---|
[2] | 2413 | } |
---|
[56] | 2414 | } |
---|
| 2415 | } |
---|
| 2416 | Int iBitsX = 0, iBitsY = 0; |
---|
| 2417 | const UInt *puiCtxIdx; |
---|
| 2418 | Int ctx; |
---|
| 2419 | #if LAST_CTX_REDUCTION |
---|
| 2420 | Int widthCtx = eTType? 4 : width; |
---|
| 2421 | puiCtxIdx = g_uiLastCtx + (g_aucConvertToBit[ widthCtx ]*(g_aucConvertToBit[ widthCtx ]+3)); |
---|
| 2422 | #else |
---|
| 2423 | puiCtxIdx = g_uiLastCtx + (g_aucConvertToBit[ width ]*(g_aucConvertToBit[ width ]+3)); |
---|
[2] | 2424 | #endif |
---|
[56] | 2425 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
| 2426 | for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) |
---|
| 2427 | { |
---|
| 2428 | Int ctxOffset = puiCtxIdx[ ctx ]; |
---|
| 2429 | #if LAST_CTX_REDUCTION |
---|
| 2430 | if (eTType) |
---|
| 2431 | { |
---|
| 2432 | Int ctxOffsetC = ctx>>g_aucConvertToBit[ width ]; |
---|
| 2433 | pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffsetC ].getEntropyBits( 0 ); |
---|
| 2434 | iBitsX += pCtxX[ ctxOffsetC].getEntropyBits( 1 ); |
---|
| 2435 | } |
---|
| 2436 | else |
---|
| 2437 | { |
---|
[2] | 2438 | #endif |
---|
[56] | 2439 | pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); |
---|
| 2440 | iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); |
---|
| 2441 | #if LAST_CTX_REDUCTION |
---|
[2] | 2442 | } |
---|
[56] | 2443 | #endif |
---|
| 2444 | } |
---|
| 2445 | pcEstBitsSbac->lastXBits[ctx] = iBitsX; |
---|
[2] | 2446 | |
---|
[56] | 2447 | #if LAST_CTX_REDUCTION |
---|
| 2448 | Int heightCtx = eTType? 4 : height; |
---|
| 2449 | puiCtxIdx = g_uiLastCtx + (g_aucConvertToBit[ heightCtx ]*(g_aucConvertToBit[ heightCtx ]+3)); |
---|
| 2450 | #else |
---|
| 2451 | puiCtxIdx = g_uiLastCtx + (g_aucConvertToBit[ height ]*(g_aucConvertToBit[ height ]+3)); |
---|
| 2452 | #endif |
---|
| 2453 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
| 2454 | for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) |
---|
[2] | 2455 | { |
---|
[56] | 2456 | Int ctxOffset = puiCtxIdx[ ctx ]; |
---|
| 2457 | #if LAST_CTX_REDUCTION |
---|
| 2458 | if (eTType) |
---|
| 2459 | { |
---|
| 2460 | Int ctxOffsetC = ctx>>g_aucConvertToBit[ height ]; |
---|
| 2461 | pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffsetC ].getEntropyBits( 0 ); |
---|
| 2462 | iBitsY += pCtxY[ctxOffsetC].getEntropyBits( 1 ); |
---|
| 2463 | } |
---|
| 2464 | else |
---|
| 2465 | { |
---|
[2] | 2466 | #endif |
---|
[56] | 2467 | pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); |
---|
| 2468 | iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); |
---|
| 2469 | #if LAST_CTX_REDUCTION |
---|
| 2470 | } |
---|
| 2471 | #endif |
---|
| 2472 | } |
---|
| 2473 | pcEstBitsSbac->lastYBits[ctx] = iBitsY; |
---|
[2] | 2474 | } |
---|
| 2475 | |
---|
| 2476 | /*! |
---|
| 2477 | **************************************************************************** |
---|
| 2478 | * \brief |
---|
| 2479 | * estimate bit cost of significant coefficient |
---|
| 2480 | **************************************************************************** |
---|
| 2481 | */ |
---|
| 2482 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
| 2483 | { |
---|
[56] | 2484 | if (eTType==TEXT_LUMA) |
---|
[2] | 2485 | { |
---|
[56] | 2486 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); |
---|
| 2487 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); |
---|
| 2488 | |
---|
| 2489 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++) |
---|
[2] | 2490 | { |
---|
[56] | 2491 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2492 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
[2] | 2493 | } |
---|
[56] | 2494 | |
---|
| 2495 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_LUMA; ctxIdx++) |
---|
| 2496 | { |
---|
| 2497 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2498 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 2499 | } |
---|
[2] | 2500 | } |
---|
[56] | 2501 | else |
---|
| 2502 | { |
---|
| 2503 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA; |
---|
| 2504 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA; |
---|
| 2505 | |
---|
| 2506 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++) |
---|
| 2507 | { |
---|
| 2508 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2509 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 2510 | } |
---|
| 2511 | |
---|
| 2512 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_CHROMA; ctxIdx++) |
---|
| 2513 | { |
---|
| 2514 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2515 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 2516 | } |
---|
| 2517 | } |
---|
[2] | 2518 | } |
---|
| 2519 | |
---|
[56] | 2520 | /** |
---|
| 2521 | - Initialize our context information from the nominated source. |
---|
| 2522 | . |
---|
| 2523 | \param pSrc From where to copy context information. |
---|
| 2524 | */ |
---|
| 2525 | Void TEncSbac::xCopyContextsFrom( TEncSbac* pSrc ) |
---|
| 2526 | { |
---|
| 2527 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
| 2528 | } |
---|
| 2529 | |
---|
| 2530 | Void TEncSbac::loadContexts ( TEncSbac* pScr) |
---|
[2] | 2531 | { |
---|
[56] | 2532 | this->xCopyContextsFrom(pScr); |
---|
[2] | 2533 | } |
---|
[56] | 2534 | |
---|
[189] | 2535 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX || (LGE_EDGE_INTRA_A0070 && LGE_EDGE_INTRA_DELTA_DC) |
---|
[56] | 2536 | Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel ) |
---|
| 2537 | { |
---|
| 2538 | if( uiSymbol ) |
---|
| 2539 | { |
---|
| 2540 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
| 2541 | UInt uiCount = 0; |
---|
| 2542 | Bool bNoExGo = (uiSymbol < 13); |
---|
| 2543 | |
---|
| 2544 | while( --uiSymbol && ++uiCount < 13 ) |
---|
| 2545 | { |
---|
| 2546 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
| 2547 | } |
---|
| 2548 | if( bNoExGo ) |
---|
| 2549 | { |
---|
| 2550 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
| 2551 | } |
---|
| 2552 | else |
---|
| 2553 | { |
---|
| 2554 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
| 2555 | } |
---|
| 2556 | } |
---|
| 2557 | else |
---|
| 2558 | { |
---|
| 2559 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
| 2560 | } |
---|
| 2561 | |
---|
| 2562 | return; |
---|
| 2563 | } |
---|
| 2564 | #endif |
---|
| 2565 | #if HHI_DMM_WEDGE_INTRA |
---|
| 2566 | Void TEncSbac::xCodeWedgeFullInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2567 | { |
---|
| 2568 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
| 2569 | Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx]; |
---|
| 2570 | |
---|
| 2571 | UInt uiTabIdx = pcCU->getWedgeFullTabIdx( uiAbsPartIdx ); |
---|
| 2572 | |
---|
| 2573 | for ( Int i = 0; i < iBits; i++ ) |
---|
| 2574 | { |
---|
| 2575 | m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cDmmDataSCModel.get(0, 0, 0) ); |
---|
| 2576 | } |
---|
| 2577 | } |
---|
| 2578 | |
---|
| 2579 | Void TEncSbac::xCodeWedgeFullDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2580 | { |
---|
| 2581 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
| 2582 | Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx]; |
---|
| 2583 | |
---|
| 2584 | UInt uiTabIdx = pcCU->getWedgeFullTabIdx( uiAbsPartIdx ); |
---|
| 2585 | |
---|
| 2586 | for ( Int i = 0; i < iBits; i++ ) |
---|
| 2587 | { |
---|
| 2588 | m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cDmmDataSCModel.get(0, 0, 0) ); |
---|
| 2589 | } |
---|
| 2590 | |
---|
| 2591 | Int iDeltaDC1 = pcCU->getWedgeFullDeltaDC1( uiAbsPartIdx ); |
---|
| 2592 | Int iDeltaDC2 = pcCU->getWedgeFullDeltaDC2( uiAbsPartIdx ); |
---|
| 2593 | |
---|
| 2594 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2595 | if ( iDeltaDC1 != 0 ) |
---|
| 2596 | { |
---|
| 2597 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
| 2598 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2599 | } |
---|
| 2600 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2601 | if ( iDeltaDC2 != 0 ) |
---|
| 2602 | { |
---|
| 2603 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
| 2604 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2605 | } |
---|
| 2606 | } |
---|
| 2607 | |
---|
| 2608 | Void TEncSbac::xCodeWedgePredDirInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2609 | { |
---|
| 2610 | if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 ) |
---|
| 2611 | { |
---|
| 2612 | Int iDeltaEnd = pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ); |
---|
| 2613 | m_pcBinIf->encodeBin( (iDeltaEnd!=0), m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
| 2614 | |
---|
| 2615 | if( iDeltaEnd != 0 ) |
---|
| 2616 | { |
---|
| 2617 | UInt uiAbsValMinus1 = abs(iDeltaEnd)-1; |
---|
| 2618 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
| 2619 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
| 2620 | |
---|
| 2621 | UInt uiSign = iDeltaEnd > 0 ? 0 : 1; |
---|
| 2622 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2623 | } |
---|
| 2624 | } |
---|
| 2625 | } |
---|
| 2626 | |
---|
| 2627 | Void TEncSbac::xCodeWedgePredDirDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2628 | { |
---|
| 2629 | if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 ) |
---|
| 2630 | { |
---|
| 2631 | Int iDeltaEnd = pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ); |
---|
| 2632 | m_pcBinIf->encodeBin( (iDeltaEnd!=0), m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
| 2633 | |
---|
| 2634 | if( iDeltaEnd != 0 ) |
---|
| 2635 | { |
---|
| 2636 | UInt uiAbsValMinus1 = abs(iDeltaEnd)-1; |
---|
| 2637 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
| 2638 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
| 2639 | |
---|
| 2640 | UInt uiSign = iDeltaEnd > 0 ? 0 : 1; |
---|
| 2641 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2642 | } |
---|
| 2643 | } |
---|
| 2644 | |
---|
| 2645 | Int iDeltaDC1 = pcCU->getWedgePredDirDeltaDC1( uiAbsPartIdx ); |
---|
| 2646 | Int iDeltaDC2 = pcCU->getWedgePredDirDeltaDC2( uiAbsPartIdx ); |
---|
| 2647 | |
---|
| 2648 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2649 | if ( iDeltaDC1 != 0 ) |
---|
| 2650 | { |
---|
| 2651 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
| 2652 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2653 | } |
---|
| 2654 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2655 | if ( iDeltaDC2 != 0 ) |
---|
| 2656 | { |
---|
| 2657 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
| 2658 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2659 | } |
---|
| 2660 | } |
---|
| 2661 | #endif |
---|
| 2662 | #if HHI_DMM_PRED_TEX |
---|
| 2663 | Void TEncSbac::xCodeWedgePredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2664 | { |
---|
| 2665 | Int iDeltaDC1 = pcCU->getWedgePredTexDeltaDC1( uiAbsPartIdx ); |
---|
| 2666 | Int iDeltaDC2 = pcCU->getWedgePredTexDeltaDC2( uiAbsPartIdx ); |
---|
| 2667 | |
---|
| 2668 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2669 | if ( iDeltaDC1 != 0 ) |
---|
| 2670 | { |
---|
| 2671 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
| 2672 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2673 | } |
---|
| 2674 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2675 | if ( iDeltaDC2 != 0 ) |
---|
| 2676 | { |
---|
| 2677 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
| 2678 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2679 | } |
---|
| 2680 | } |
---|
| 2681 | |
---|
| 2682 | Void TEncSbac::xCodeContourPredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2683 | { |
---|
| 2684 | Int iDeltaDC1 = pcCU->getContourPredTexDeltaDC1( uiAbsPartIdx ); |
---|
| 2685 | Int iDeltaDC2 = pcCU->getContourPredTexDeltaDC2( uiAbsPartIdx ); |
---|
| 2686 | |
---|
| 2687 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2688 | if ( iDeltaDC1 != 0 ) |
---|
| 2689 | { |
---|
| 2690 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
| 2691 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2692 | } |
---|
| 2693 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2694 | if ( iDeltaDC2 != 0 ) |
---|
| 2695 | { |
---|
| 2696 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
| 2697 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2698 | } |
---|
| 2699 | } |
---|
| 2700 | #endif |
---|
[189] | 2701 | |
---|
| 2702 | #if RWTH_SDC_DLT_B0036 |
---|
| 2703 | Void TEncSbac::codeSDCPredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2704 | { |
---|
| 2705 | assert( pcCU->getSlice()->getSPS()->isDepth() ); |
---|
| 2706 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
| 2707 | assert( pcCU->getSDCFlag(uiAbsPartIdx) ); |
---|
| 2708 | |
---|
| 2709 | UInt uiPredMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
| 2710 | UInt uiCtx = 0; |
---|
| 2711 | |
---|
| 2712 | UInt uiMPModeIdx = 0; |
---|
| 2713 | |
---|
| 2714 | for(Int i=0; i<RWTH_SDC_NUM_PRED_MODES-1; i++) |
---|
| 2715 | { |
---|
| 2716 | UInt uiBit = (uiPredMode == g_auiSDCPredModes[uiMPModeIdx]) ? 1 : 0; |
---|
| 2717 | m_pcBinIf->encodeBin( uiBit, m_cSDCPredModeSCModel.get( 0, i, uiCtx ) ); |
---|
| 2718 | |
---|
| 2719 | // if mode is most probable mode, we are done here |
---|
| 2720 | if ( uiBit == 1 ) |
---|
| 2721 | break; |
---|
| 2722 | |
---|
| 2723 | // else: get next most probable pred mode |
---|
| 2724 | uiMPModeIdx = (uiMPModeIdx+1)%RWTH_SDC_NUM_PRED_MODES; |
---|
| 2725 | } |
---|
| 2726 | |
---|
| 2727 | #if HHI_DMM_WEDGE_INTRA |
---|
| 2728 | if( uiPredMode == DMM_WEDGE_FULL_IDX ) { xCodeWedgeFullInfo ( pcCU, uiAbsPartIdx ); } |
---|
| 2729 | if( uiPredMode == DMM_WEDGE_PREDDIR_IDX ) { xCodeWedgePredDirInfo ( pcCU, uiAbsPartIdx ); } |
---|
| 2730 | #endif |
---|
| 2731 | |
---|
| 2732 | AOF(uiPredMode == g_auiSDCPredModes[uiMPModeIdx]); |
---|
| 2733 | } |
---|
| 2734 | |
---|
| 2735 | Void TEncSbac::codeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2736 | { |
---|
| 2737 | // get context function is here |
---|
| 2738 | UInt uiSymbol = pcCU->getSDCFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 2739 | UInt uiCtxSDCFlag = pcCU->getCtxSDCFlag( uiAbsPartIdx ); |
---|
| 2740 | m_pcBinIf->encodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, uiCtxSDCFlag ) ); |
---|
| 2741 | |
---|
| 2742 | } |
---|
| 2743 | |
---|
| 2744 | Void TEncSbac::codeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ) |
---|
| 2745 | { |
---|
| 2746 | assert( pcCU->getSlice()->getSPS()->isDepth() ); |
---|
| 2747 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
| 2748 | assert( pcCU->getSDCFlag(uiAbsPartIdx) ); |
---|
| 2749 | assert( uiSegment < 2 ); |
---|
| 2750 | |
---|
| 2751 | Pel segmentDCOffset = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx); |
---|
| 2752 | |
---|
| 2753 | UInt uiResidual = segmentDCOffset == 0 ? 0 : 1; |
---|
| 2754 | UInt uiSign = segmentDCOffset < 0 ? 1 : 0; |
---|
| 2755 | UInt uiAbsIdx = abs(segmentDCOffset); |
---|
| 2756 | UInt uiBit = 0; |
---|
| 2757 | |
---|
| 2758 | UInt uiMaxResidualBits = GetBitsPerDepthValue(); |
---|
| 2759 | assert( uiMaxResidualBits <= g_uiBitDepth ); |
---|
| 2760 | |
---|
| 2761 | // residual flag |
---|
| 2762 | m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, uiSegment, 0 ) ); //TODO depthmap: more sophisticated context selection |
---|
| 2763 | |
---|
| 2764 | if (uiResidual) |
---|
| 2765 | { |
---|
| 2766 | // encode sign bit of residual |
---|
| 2767 | m_pcBinIf->encodeBin( uiSign, m_cSDCResidualSignFlagSCModel.get( 0, uiSegment, 0 ) ); //TODO depthmap: more sophisticated context selection |
---|
| 2768 | |
---|
| 2769 | assert(uiAbsIdx < GetNumDepthValues()); |
---|
| 2770 | |
---|
| 2771 | // encode residual magnitude |
---|
| 2772 | uiAbsIdx -= 1; |
---|
| 2773 | for (Int i=0; i<uiMaxResidualBits; i++) |
---|
| 2774 | { |
---|
| 2775 | uiBit = (uiAbsIdx & (1<<i))>>i; |
---|
| 2776 | |
---|
| 2777 | m_pcBinIf->encodeBin( uiBit, m_cSDCResidualSCModel.get( 0, uiSegment, i ) ); //TODO depthmap: more sophisticated context selection |
---|
| 2778 | } |
---|
| 2779 | |
---|
| 2780 | } |
---|
| 2781 | } |
---|
| 2782 | #endif |
---|
[56] | 2783 | //! \} |
---|