[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 | |
---|
[228] | 627 | #if HHI_QTLPC_RAU_OFF_C0160 |
---|
[229] | 628 | Bool rapPic = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA); |
---|
[228] | 629 | if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTLPC() && pcCU->getPic()->getReduceBitsFlag()) |
---|
| 630 | #else |
---|
[189] | 631 | if(bDepthMapDetect && !bIntraSliceDetect && sps->getUseQTLPC() && pcCU->getPic()->getReduceBitsFlag()) |
---|
[228] | 632 | #endif |
---|
[189] | 633 | { |
---|
| 634 | TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr()); |
---|
| 635 | UInt uiCUIdx = (pcCU->getZorderIdxInCU() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU(); |
---|
| 636 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); |
---|
| 637 | if (pcTextureCU->getDepth(uiCUIdx) == uiDepth && pcTextureCU->getPartitionSize( uiCUIdx ) != SIZE_NxN) |
---|
| 638 | { |
---|
| 639 | assert( eSize == SIZE_2Nx2N ); |
---|
| 640 | return; |
---|
| 641 | } |
---|
| 642 | } |
---|
[115] | 643 | #endif |
---|
[189] | 644 | |
---|
[2] | 645 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 646 | { |
---|
| 647 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 648 | { |
---|
| 649 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
| 650 | } |
---|
| 651 | return; |
---|
| 652 | } |
---|
| 653 | |
---|
| 654 | switch(eSize) |
---|
| 655 | { |
---|
[116] | 656 | case SIZE_2Nx2N: |
---|
[2] | 657 | { |
---|
| 658 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 659 | break; |
---|
| 660 | } |
---|
[116] | 661 | case SIZE_2NxN: |
---|
| 662 | case SIZE_2NxnU: |
---|
| 663 | case SIZE_2NxnD: |
---|
[2] | 664 | { |
---|
| 665 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 666 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
[56] | 667 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
| 668 | { |
---|
| 669 | if (eSize == SIZE_2NxN) |
---|
| 670 | { |
---|
| 671 | #if AMP_CTX |
---|
| 672 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 673 | #else |
---|
| 674 | m_pcBinIf->encodeBin(1, m_cCUYPosiSCModel.get( 0, 0, 0 )); |
---|
| 675 | #endif |
---|
| 676 | } |
---|
| 677 | else |
---|
| 678 | { |
---|
| 679 | #if AMP_CTX |
---|
| 680 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 681 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
| 682 | #else |
---|
| 683 | m_pcBinIf->encodeBin(0, m_cCUYPosiSCModel.get( 0, 0, 0 )); |
---|
| 684 | m_pcBinIf->encodeBin((eSize == SIZE_2NxnU? 0: 1), m_cCUYPosiSCModel.get( 0, 0, 1 )); |
---|
| 685 | #endif |
---|
| 686 | } |
---|
| 687 | } |
---|
[2] | 688 | break; |
---|
| 689 | } |
---|
[116] | 690 | case SIZE_Nx2N: |
---|
| 691 | case SIZE_nLx2N: |
---|
| 692 | case SIZE_nRx2N: |
---|
[2] | 693 | { |
---|
| 694 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 695 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
[56] | 696 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getSlice()->getSPS()->getDisInter4x4() && pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
| 697 | { |
---|
| 698 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
| 699 | } |
---|
| 700 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
| 701 | { |
---|
| 702 | if (eSize == SIZE_Nx2N) |
---|
| 703 | { |
---|
| 704 | #if AMP_CTX |
---|
| 705 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 706 | #else |
---|
| 707 | m_pcBinIf->encodeBin(1, m_cCUXPosiSCModel.get( 0, 0, 0 )); |
---|
| 708 | #endif |
---|
| 709 | } |
---|
| 710 | else |
---|
| 711 | { |
---|
| 712 | #if AMP_CTX |
---|
| 713 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 714 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
| 715 | #else |
---|
| 716 | m_pcBinIf->encodeBin(0, m_cCUXPosiSCModel.get( 0, 0, 0 )); |
---|
| 717 | m_pcBinIf->encodeBin((eSize == SIZE_nLx2N? 0: 1), m_cCUXPosiSCModel.get( 0, 0, 1 )); |
---|
| 718 | #endif |
---|
| 719 | } |
---|
| 720 | } |
---|
[2] | 721 | break; |
---|
| 722 | } |
---|
[116] | 723 | case SIZE_NxN: |
---|
[2] | 724 | { |
---|
[56] | 725 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getSlice()->getSPS()->getDisInter4x4() && pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
[2] | 726 | { |
---|
| 727 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
[56] | 728 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
| 729 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
[2] | 730 | } |
---|
| 731 | break; |
---|
| 732 | } |
---|
[116] | 733 | default: |
---|
[2] | 734 | { |
---|
| 735 | assert(0); |
---|
| 736 | } |
---|
| 737 | } |
---|
| 738 | } |
---|
| 739 | |
---|
| 740 | /** code prediction mode |
---|
| 741 | * \param pcCU |
---|
| 742 | * \param uiAbsPartIdx |
---|
| 743 | * \returns Void |
---|
| 744 | */ |
---|
| 745 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 746 | { |
---|
[189] | 747 | #if RWTH_SDC_DLT_B0036 |
---|
| 748 | if ( pcCU->getSlice()->isIntra() ) |
---|
| 749 | { |
---|
| 750 | assert( pcCU->isIntra(uiAbsPartIdx) ); |
---|
| 751 | return; |
---|
| 752 | } |
---|
| 753 | #endif |
---|
| 754 | |
---|
[2] | 755 | // get context function is here |
---|
| 756 | Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); |
---|
[56] | 757 | m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 758 | } |
---|
| 759 | |
---|
| 760 | Void TEncSbac::codeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 761 | { |
---|
| 762 | if (!m_bAlfCtrl) |
---|
| 763 | return; |
---|
| 764 | |
---|
| 765 | if( pcCU->getDepth(uiAbsPartIdx) > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth)) |
---|
| 766 | { |
---|
| 767 | return; |
---|
| 768 | } |
---|
| 769 | |
---|
[56] | 770 | const UInt uiSymbol = pcCU->getAlfCtrlFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 771 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUAlfCtrlFlagSCModel.get( 0 ) ); |
---|
[2] | 772 | } |
---|
| 773 | |
---|
| 774 | Void TEncSbac::codeAlfCtrlDepth() |
---|
| 775 | { |
---|
| 776 | if (!m_bAlfCtrl) |
---|
| 777 | return; |
---|
| 778 | |
---|
| 779 | UInt uiDepth = m_uiMaxAlfCtrlDepth; |
---|
| 780 | xWriteUnaryMaxSymbol(uiDepth, m_cALFUvlcSCModel.get(0), 1, g_uiMaxCUDepth-1); |
---|
| 781 | } |
---|
| 782 | |
---|
| 783 | /** code skip flag |
---|
| 784 | * \param pcCU |
---|
| 785 | * \param uiAbsPartIdx |
---|
| 786 | * \returns Void |
---|
| 787 | */ |
---|
| 788 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 789 | { |
---|
| 790 | // get context function is here |
---|
| 791 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
| 792 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
| 793 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
[56] | 794 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 795 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
| 796 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
| 797 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
| 798 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 799 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 800 | DTRACE_CABAC_T( "\n"); |
---|
| 801 | } |
---|
| 802 | |
---|
[189] | 803 | #if LGE_ILLUCOMP_B0045 |
---|
| 804 | /** code Illumination Compensation flag |
---|
| 805 | * \param pcCU |
---|
| 806 | * \param uiAbsPartIdx |
---|
| 807 | * \returns Void |
---|
| 808 | */ |
---|
| 809 | Void TEncSbac::codeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 810 | { |
---|
| 811 | // get context function is here |
---|
| 812 | UInt uiSymbol = pcCU->getICFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 813 | UInt uiCtxIC = pcCU->getCtxICFlag( uiAbsPartIdx ) ; |
---|
| 814 | m_pcBinIf->encodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, uiCtxIC ) ); |
---|
| 815 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 816 | DTRACE_CABAC_T( "\tICFlag" ); |
---|
| 817 | DTRACE_CABAC_T( "\tuiCtxIC: "); |
---|
| 818 | DTRACE_CABAC_V( uiCtxIC ); |
---|
| 819 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 820 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 821 | DTRACE_CABAC_T( "\n"); |
---|
| 822 | } |
---|
| 823 | #endif |
---|
| 824 | |
---|
[2] | 825 | /** code merge flag |
---|
| 826 | * \param pcCU |
---|
| 827 | * \param uiAbsPartIdx |
---|
| 828 | * \returns Void |
---|
| 829 | */ |
---|
| 830 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 831 | { |
---|
[56] | 832 | const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 833 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
[2] | 834 | |
---|
[56] | 835 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 836 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
| 837 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 838 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
| 839 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
| 840 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
| 841 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 842 | DTRACE_CABAC_T( "\n" ); |
---|
| 843 | } |
---|
| 844 | |
---|
[56] | 845 | /** code merge index |
---|
| 846 | * \param pcCU |
---|
| 847 | * \param uiAbsPartIdx |
---|
| 848 | * \returns Void |
---|
| 849 | */ |
---|
| 850 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
[2] | 851 | { |
---|
[56] | 852 | UInt uiNumCand = MRG_MAX_NUM_CANDS; |
---|
| 853 | #if !MRG_IDX_CTX_RED |
---|
| 854 | UInt auiCtx[4] = { 0, 1, 2, 3 }; |
---|
| 855 | #endif |
---|
| 856 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
| 857 | uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
[5] | 858 | #if HHI_MPI |
---|
[2] | 859 | const Bool bMVIAvailable = pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE; |
---|
| 860 | if( bMVIAvailable ) |
---|
| 861 | { |
---|
| 862 | const Bool bUseMVI = pcCU->getTextureModeDepth( uiAbsPartIdx ) != -1; |
---|
| 863 | if( bUseMVI ) |
---|
| 864 | { |
---|
[58] | 865 | uiUnaryIdx = (UInt)HHI_MPI_MERGE_POS; |
---|
[2] | 866 | } |
---|
[58] | 867 | else if( (Int)uiUnaryIdx >= (Int)HHI_MPI_MERGE_POS ) |
---|
[2] | 868 | { |
---|
[56] | 869 | uiUnaryIdx++; |
---|
[2] | 870 | } |
---|
| 871 | } |
---|
| 872 | #endif |
---|
[56] | 873 | if ( uiNumCand > 1 ) |
---|
[2] | 874 | { |
---|
[56] | 875 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
[2] | 876 | { |
---|
[56] | 877 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
| 878 | #if MRG_IDX_CTX_RED |
---|
| 879 | if ( ui==0 ) |
---|
[2] | 880 | { |
---|
[56] | 881 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 882 | } |
---|
[56] | 883 | else |
---|
[2] | 884 | { |
---|
[56] | 885 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
[2] | 886 | } |
---|
[56] | 887 | #else |
---|
| 888 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, auiCtx[ui] ) ); |
---|
| 889 | #endif |
---|
| 890 | if( uiSymbol == 0 ) |
---|
[2] | 891 | { |
---|
[56] | 892 | break; |
---|
[2] | 893 | } |
---|
| 894 | } |
---|
| 895 | } |
---|
[56] | 896 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 897 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
| 898 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
| 899 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
| 900 | DTRACE_CABAC_T( "\n" ); |
---|
| 901 | } |
---|
| 902 | |
---|
[5] | 903 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
[56] | 904 | Void |
---|
[2] | 905 | TEncSbac::codeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 906 | { |
---|
[56] | 907 | UInt uiCtx = pcCU->getCtxResPredFlag( uiAbsPartIdx ); |
---|
[2] | 908 | UInt uiSymbol = ( pcCU->getResPredFlag( uiAbsPartIdx ) ? 1 : 0 ); |
---|
| 909 | m_pcBinIf->encodeBin( uiSymbol, m_cResPredFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
| 910 | } |
---|
[5] | 911 | #endif |
---|
[2] | 912 | |
---|
| 913 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 914 | { |
---|
| 915 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 916 | return; |
---|
| 917 | |
---|
| 918 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
| 919 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
| 920 | |
---|
| 921 | assert( uiCtx < 3 ); |
---|
[189] | 922 | |
---|
| 923 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
| 924 | Bool bCodeSplitFlag = true; |
---|
| 925 | |
---|
| 926 | TComSPS *sps = pcCU->getPic()->getSlice(0)->getSPS(); |
---|
| 927 | TComPic *pcTexture = pcCU->getSlice()->getTexturePic(); |
---|
| 928 | Bool bDepthMapDetect = (pcTexture != NULL); |
---|
| 929 | Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE); |
---|
| 930 | |
---|
[228] | 931 | #if HHI_QTLPC_RAU_OFF_C0160 |
---|
[229] | 932 | Bool rapPic = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA); |
---|
[228] | 933 | if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTLPC() && pcCU->getPic()->getReduceBitsFlag()) |
---|
| 934 | #else |
---|
[189] | 935 | if(bDepthMapDetect && !bIntraSliceDetect && sps->getUseQTLPC() && pcCU->getPic()->getReduceBitsFlag()) |
---|
[228] | 936 | #endif |
---|
[115] | 937 | { |
---|
[189] | 938 | TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr()); |
---|
| 939 | UInt uiCUIdx = (pcCU->getZorderIdxInCU() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU(); |
---|
| 940 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); |
---|
| 941 | bCodeSplitFlag = (pcTextureCU->getDepth(uiCUIdx) > uiDepth); |
---|
[115] | 942 | } |
---|
[189] | 943 | |
---|
| 944 | if(!bCodeSplitFlag) |
---|
| 945 | { |
---|
| 946 | assert(uiCurrSplitFlag == 0); |
---|
| 947 | return; |
---|
| 948 | } |
---|
[115] | 949 | #endif |
---|
[189] | 950 | |
---|
| 951 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
[56] | 952 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 953 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
| 954 | return; |
---|
| 955 | } |
---|
| 956 | |
---|
| 957 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
| 958 | { |
---|
| 959 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
[56] | 960 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 961 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
| 962 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 963 | DTRACE_CABAC_V( uiSymbol ) |
---|
| 964 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 965 | DTRACE_CABAC_V( uiCtx ) |
---|
| 966 | DTRACE_CABAC_T( "\n" ) |
---|
| 967 | } |
---|
[100] | 968 | |
---|
[189] | 969 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 970 | Void TEncSbac::xCodeEdgeIntraInfo( TComDataCU* pcCU, UInt uiPartIdx ) |
---|
| 971 | { |
---|
| 972 | UInt uiDepth = pcCU->getDepth( uiPartIdx ) + (pcCU->getPartitionSize( uiPartIdx ) == SIZE_NxN ? 1 : 0); |
---|
| 973 | UInt uiCtxEdgeIntra = pcCU->getCtxEdgeIntra( uiPartIdx ); |
---|
| 974 | UChar* pucSymbolList = pcCU->getEdgeCode( uiPartIdx ); |
---|
| 975 | UChar ucEdgeNumber = pcCU->getEdgeNumber( uiPartIdx ); |
---|
| 976 | Bool bLeft = pcCU->getEdgeLeftFirst( uiPartIdx ); |
---|
| 977 | UChar ucStart = pcCU->getEdgeStartPos( uiPartIdx ); |
---|
| 978 | UInt uiSymbol; |
---|
| 979 | |
---|
| 980 | // 1. Top(0) or Left(1) |
---|
| 981 | uiSymbol = (bLeft == false) ? 0 : 1; |
---|
| 982 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
| 983 | |
---|
| 984 | // 2. Start position (lowest bit first) |
---|
| 985 | uiSymbol = ucStart; |
---|
| 986 | for( UInt ui = 6; ui > uiDepth; ui-- ) // 64(0)->6, 32(1)->5, 16(2)->4, 8(3)->3, 4(4)->2 |
---|
| 987 | { |
---|
| 988 | m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); |
---|
| 989 | uiSymbol >>= 1; |
---|
| 990 | } |
---|
| 991 | |
---|
| 992 | // 3. Number of edges |
---|
| 993 | uiSymbol = ucEdgeNumber > 0 ? ucEdgeNumber - 1 : 0; |
---|
| 994 | for( UInt ui = 7; ui > uiDepth; ui-- ) // 64(0)->7, 32(1)->6, 16(2)->5, 8(3)->4, 4(4)->3 |
---|
| 995 | { |
---|
| 996 | m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); |
---|
| 997 | uiSymbol >>= 1; |
---|
| 998 | } |
---|
| 999 | |
---|
| 1000 | if(uiSymbol != 0) |
---|
| 1001 | { |
---|
| 1002 | printf(" ucEdgeNumber %d at depth %d\n",ucEdgeNumber, uiDepth); |
---|
| 1003 | assert(false); |
---|
| 1004 | } |
---|
| 1005 | |
---|
| 1006 | // 4. Edges |
---|
| 1007 | for( Int iPtr2 = 0; iPtr2 < ucEdgeNumber; iPtr2++ ) |
---|
| 1008 | { |
---|
| 1009 | UInt uiReorderSymbol = pucSymbolList[iPtr2]; |
---|
| 1010 | |
---|
| 1011 | //printf ("Ptr = %d, Symbol = %d\n", iPtr2, uiSymbol); |
---|
| 1012 | |
---|
| 1013 | // Left-friendly direction (Top start) |
---|
| 1014 | // 0 ( 0deg) => 0 |
---|
| 1015 | // 1 ( 45deg) => 10 |
---|
| 1016 | // 2 ( -45deg) => 110 |
---|
| 1017 | // 3 ( 90deg) => 1110 |
---|
| 1018 | // 4 ( -90deg) => 11110 |
---|
| 1019 | // 5 ( 135deg) => 111110 |
---|
| 1020 | // 6 (-135deg) => 111111 |
---|
| 1021 | // Right-friendly direction (Left start) |
---|
| 1022 | // 0 ( 0deg) => 0 |
---|
| 1023 | // 2 ( -45deg) => 10 |
---|
| 1024 | // 1 ( 45deg) => 110 |
---|
| 1025 | // 4 ( -90deg) => 1110 |
---|
| 1026 | // 3 ( 90deg) => 11110 |
---|
| 1027 | // 6 (-135deg) => 111110 |
---|
| 1028 | // 5 ( 135deg) => 111111 |
---|
| 1029 | |
---|
| 1030 | // refer to a paper "An efficient chain code with Huffman coding" |
---|
| 1031 | |
---|
| 1032 | for( UInt ui = 0; ui < uiReorderSymbol; ui++ ) |
---|
| 1033 | { |
---|
| 1034 | m_pcBinIf->encodeBin( 1, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) ); |
---|
| 1035 | } |
---|
| 1036 | |
---|
| 1037 | if( uiReorderSymbol != 6 ) |
---|
| 1038 | m_pcBinIf->encodeBin( 0, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) ); |
---|
| 1039 | } |
---|
| 1040 | } |
---|
| 1041 | #endif |
---|
| 1042 | |
---|
[2] | 1043 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1044 | { |
---|
[56] | 1045 | UInt uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
[2] | 1046 | |
---|
[5] | 1047 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[56] | 1048 | if( pcCU->getSlice()->getSPS()->getUseDMM() && pcCU->getWidth( uiAbsPartIdx ) <= DMM_WEDGEMODEL_MAX_SIZE ) |
---|
[2] | 1049 | { |
---|
[189] | 1050 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 1051 | m_pcBinIf->encodeBin( uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX, m_cDmmFlagSCModel.get(0, 0, 0) ); |
---|
| 1052 | #else |
---|
[56] | 1053 | m_pcBinIf->encodeBin( uiDir >= NUM_INTRA_MODE, m_cDmmFlagSCModel.get(0, 0, 0) ); |
---|
[100] | 1054 | #endif |
---|
[2] | 1055 | } |
---|
[189] | 1056 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 1057 | if( uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX ) |
---|
| 1058 | #else |
---|
[56] | 1059 | if( uiDir >= NUM_INTRA_MODE ) |
---|
[100] | 1060 | #endif |
---|
[2] | 1061 | { |
---|
[56] | 1062 | assert( pcCU->getWidth( uiAbsPartIdx ) <= DMM_WEDGEMODEL_MAX_SIZE ); |
---|
| 1063 | UInt uiDMMode = uiDir - NUM_INTRA_MODE; |
---|
[2] | 1064 | |
---|
[5] | 1065 | #if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX |
---|
[56] | 1066 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
| 1067 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
[5] | 1068 | |
---|
[56] | 1069 | if( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
| 1070 | { |
---|
| 1071 | m_pcBinIf->encodeBin( (uiDMMode & 0x04) >> 2, m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
| 1072 | } |
---|
[5] | 1073 | #else |
---|
[56] | 1074 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
[2] | 1075 | |
---|
[56] | 1076 | if( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
[2] | 1077 | { |
---|
[56] | 1078 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
[2] | 1079 | } |
---|
[5] | 1080 | #endif |
---|
| 1081 | #if HHI_DMM_WEDGE_INTRA |
---|
[2] | 1082 | if( uiDir == DMM_WEDGE_FULL_IDX ) { xCodeWedgeFullInfo ( pcCU, uiAbsPartIdx ); } |
---|
| 1083 | if( uiDir == DMM_WEDGE_FULL_D_IDX ) { xCodeWedgeFullDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
| 1084 | if( uiDir == DMM_WEDGE_PREDDIR_IDX ) { xCodeWedgePredDirInfo ( pcCU, uiAbsPartIdx ); } |
---|
| 1085 | if( uiDir == DMM_WEDGE_PREDDIR_D_IDX ) { xCodeWedgePredDirDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
[5] | 1086 | #endif |
---|
| 1087 | #if HHI_DMM_PRED_TEX |
---|
[210] | 1088 | |
---|
| 1089 | #if FLEX_CODING_ORDER_M23723 |
---|
| 1090 | if ( !pcCU->getSlice()->getSPS()->getUseDMM34() ) |
---|
| 1091 | { |
---|
| 1092 | assert( uiDir != DMM_WEDGE_PREDTEX_D_IDX ); |
---|
| 1093 | assert( uiDir != DMM_CONTOUR_PREDTEX_D_IDX ); |
---|
| 1094 | } |
---|
| 1095 | #endif |
---|
| 1096 | |
---|
[2] | 1097 | if( uiDir == DMM_WEDGE_PREDTEX_D_IDX ) { xCodeWedgePredTexDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
| 1098 | if( uiDir == DMM_CONTOUR_PREDTEX_D_IDX ) { xCodeContourPredTexDeltaInfo( pcCU, uiAbsPartIdx ); } |
---|
[5] | 1099 | #endif |
---|
[2] | 1100 | } |
---|
| 1101 | else |
---|
[189] | 1102 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 1103 | if ( uiDir >= EDGE_INTRA_IDX) |
---|
| 1104 | { |
---|
| 1105 | m_pcBinIf->encodeBin( 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
| 1106 | m_pcBinIf->encodeBinsEP( 63, 6 ); |
---|
| 1107 | xCodeEdgeIntraInfo( pcCU, uiAbsPartIdx ); |
---|
| 1108 | #if LGE_EDGE_INTRA_DELTA_DC |
---|
| 1109 | m_pcBinIf->encodeBin( (uiDir == EDGE_INTRA_DELTA_IDX), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) ); |
---|
| 1110 | if( uiDir == EDGE_INTRA_DELTA_IDX ) |
---|
| 1111 | { |
---|
| 1112 | Int iDeltaDC0 = pcCU->getEdgeDeltaDC0( uiAbsPartIdx ); |
---|
| 1113 | Int iDeltaDC1 = pcCU->getEdgeDeltaDC1( uiAbsPartIdx ); |
---|
| 1114 | |
---|
| 1115 | xWriteExGolombLevel( UInt( abs( iDeltaDC0 ) ), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) ); |
---|
| 1116 | if ( iDeltaDC0 != 0 ) |
---|
| 1117 | { |
---|
| 1118 | UInt uiSign = iDeltaDC0 > 0 ? 0 : 1; |
---|
| 1119 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 1120 | } |
---|
| 1121 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) ); |
---|
| 1122 | if ( iDeltaDC1 != 0 ) |
---|
| 1123 | { |
---|
| 1124 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
| 1125 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 1126 | } |
---|
| 1127 | } |
---|
| 1128 | #endif |
---|
| 1129 | } |
---|
| 1130 | else |
---|
| 1131 | #endif // LGE_EDGE_INTRA |
---|
[56] | 1132 | { |
---|
[2] | 1133 | #endif |
---|
[56] | 1134 | #if !LOGI_INTRA_NAME_3MPM |
---|
[2] | 1135 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
| 1136 | #endif |
---|
[189] | 1137 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 1138 | Bool bCodeEdgeIntra = false; |
---|
| 1139 | if( pcCU->getSlice()->getSPS()->isDepth() ) |
---|
| 1140 | { |
---|
| 1141 | UInt uiPUWidth = pcCU->getWidth( uiAbsPartIdx ) >> (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 1 : 0); |
---|
| 1142 | if( uiPUWidth <= LGE_EDGE_INTRA_MAX_SIZE && uiPUWidth >= LGE_EDGE_INTRA_MIN_SIZE ) |
---|
| 1143 | bCodeEdgeIntra = true; |
---|
| 1144 | } |
---|
| 1145 | #endif |
---|
[2] | 1146 | |
---|
[56] | 1147 | #if LOGI_INTRA_NAME_3MPM |
---|
| 1148 | Int uiPreds[3] = {-1, -1, -1}; |
---|
| 1149 | #else |
---|
[2] | 1150 | Int uiPreds[2] = {-1, -1}; |
---|
[56] | 1151 | #endif |
---|
[2] | 1152 | Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); |
---|
| 1153 | |
---|
| 1154 | Int uiPredIdx = -1; |
---|
| 1155 | |
---|
| 1156 | for(UInt i = 0; i < uiPredNum; i++) |
---|
| 1157 | { |
---|
| 1158 | if(uiDir == uiPreds[i]) |
---|
| 1159 | { |
---|
| 1160 | uiPredIdx = i; |
---|
| 1161 | } |
---|
| 1162 | } |
---|
| 1163 | |
---|
| 1164 | if(uiPredIdx != -1) |
---|
| 1165 | { |
---|
| 1166 | m_pcBinIf->encodeBin( 1, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
[56] | 1167 | #if LOGI_INTRA_NAME_3MPM |
---|
| 1168 | m_pcBinIf->encodeBinEP( uiPredIdx ? 1 : 0 ); |
---|
| 1169 | if (uiPredIdx) |
---|
[2] | 1170 | { |
---|
[56] | 1171 | m_pcBinIf->encodeBinEP( uiPredIdx-1 ); |
---|
[2] | 1172 | } |
---|
[56] | 1173 | #else |
---|
| 1174 | m_pcBinIf->encodeBinEP( uiPredIdx ); |
---|
| 1175 | #endif |
---|
[2] | 1176 | } |
---|
| 1177 | else |
---|
| 1178 | { |
---|
| 1179 | m_pcBinIf->encodeBin( 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
| 1180 | |
---|
[56] | 1181 | #if LOGI_INTRA_NAME_3MPM |
---|
| 1182 | if (uiPreds[0] > uiPreds[1]) |
---|
| 1183 | { |
---|
| 1184 | std::swap(uiPreds[0], uiPreds[1]); |
---|
| 1185 | } |
---|
| 1186 | if (uiPreds[0] > uiPreds[2]) |
---|
[2] | 1187 | { |
---|
[56] | 1188 | std::swap(uiPreds[0], uiPreds[2]); |
---|
[2] | 1189 | } |
---|
[56] | 1190 | if (uiPreds[1] > uiPreds[2]) |
---|
[2] | 1191 | { |
---|
[56] | 1192 | std::swap(uiPreds[1], uiPreds[2]); |
---|
[2] | 1193 | } |
---|
| 1194 | #endif |
---|
| 1195 | |
---|
[56] | 1196 | for(Int i = (uiPredNum - 1); i >= 0; i--) |
---|
| 1197 | { |
---|
| 1198 | uiDir = uiDir > uiPreds[i] ? uiDir - 1 : uiDir; |
---|
| 1199 | } |
---|
[5] | 1200 | |
---|
[56] | 1201 | #if LOGI_INTRA_NAME_3MPM |
---|
| 1202 | m_pcBinIf->encodeBinsEP( uiDir, 5 ); |
---|
[189] | 1203 | #if LGE_EDGE_INTRA_A0070 |
---|
[100] | 1204 | if (bCodeEdgeIntra) |
---|
| 1205 | if (uiDir == 31) m_pcBinIf->encodeBinsEP(0,1); |
---|
| 1206 | #endif |
---|
[5] | 1207 | #else |
---|
[56] | 1208 | if ( uiDir < 31 ) |
---|
[2] | 1209 | { |
---|
[56] | 1210 | m_pcBinIf->encodeBinsEP( uiDir, g_aucIntraModeBitsAng[ iIntraIdx ] - 1 ); |
---|
[2] | 1211 | } |
---|
| 1212 | else |
---|
| 1213 | { |
---|
[56] | 1214 | m_pcBinIf->encodeBinsEP( 31, 5 ); |
---|
| 1215 | m_pcBinIf->encodeBinEP( uiDir - 31 ); |
---|
[2] | 1216 | } |
---|
[56] | 1217 | #endif |
---|
| 1218 | } |
---|
| 1219 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[2] | 1220 | } |
---|
| 1221 | #endif |
---|
| 1222 | return; |
---|
| 1223 | } |
---|
[56] | 1224 | |
---|
[2] | 1225 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1226 | { |
---|
[56] | 1227 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx ); |
---|
[2] | 1228 | |
---|
[56] | 1229 | if( uiIntraDirChroma == DM_CHROMA_IDX ) |
---|
[2] | 1230 | { |
---|
[56] | 1231 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 1232 | } |
---|
[56] | 1233 | else if( uiIntraDirChroma == LM_CHROMA_IDX ) |
---|
[2] | 1234 | { |
---|
[56] | 1235 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
| 1236 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 1 ) ); |
---|
[2] | 1237 | } |
---|
| 1238 | else |
---|
[56] | 1239 | { |
---|
| 1240 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
| 1241 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
[2] | 1242 | |
---|
[56] | 1243 | for( Int i = 0; i < NUM_CHROMA_MODE - 2; i++ ) |
---|
| 1244 | { |
---|
| 1245 | if( uiIntraDirChroma == uiAllowedChromaDir[i] ) |
---|
| 1246 | { |
---|
| 1247 | uiIntraDirChroma = i; |
---|
| 1248 | break; |
---|
| 1249 | } |
---|
| 1250 | } |
---|
| 1251 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 1252 | |
---|
[56] | 1253 | if (pcCU->getSlice()->getSPS()->getUseLMChroma()) |
---|
| 1254 | { |
---|
| 1255 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 1 )); |
---|
[2] | 1256 | } |
---|
[56] | 1257 | #if CHROMA_MODE_CODING |
---|
| 1258 | m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); |
---|
[2] | 1259 | #else |
---|
[56] | 1260 | xWriteUnaryMaxSymbol( uiIntraDirChroma, m_cCUChromaPredSCModel.get( 0, 0 ) + 1, 0, 3 ); |
---|
[2] | 1261 | #endif |
---|
| 1262 | } |
---|
| 1263 | return; |
---|
| 1264 | } |
---|
| 1265 | |
---|
| 1266 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1267 | { |
---|
[56] | 1268 | const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1; |
---|
| 1269 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
| 1270 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
| 1271 | m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); |
---|
| 1272 | |
---|
[2] | 1273 | return; |
---|
| 1274 | } |
---|
| 1275 | |
---|
| 1276 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1277 | { |
---|
| 1278 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getInterDir( uiAbsPartIdx ) != 3) |
---|
| 1279 | { |
---|
| 1280 | Int iRefFrame = pcCU->getSlice()->getRefIdxOfLC(eRefList, pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx )); |
---|
| 1281 | |
---|
[56] | 1282 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
| 1283 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
[2] | 1284 | |
---|
[56] | 1285 | if( iRefFrame > 0 ) |
---|
[2] | 1286 | { |
---|
[56] | 1287 | xWriteUnaryMaxSymbol( iRefFrame - 1, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C )-2 ); |
---|
[2] | 1288 | } |
---|
| 1289 | } |
---|
| 1290 | else |
---|
| 1291 | { |
---|
[56] | 1292 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
| 1293 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
| 1294 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
| 1295 | |
---|
| 1296 | if( iRefFrame > 0 ) |
---|
| 1297 | { |
---|
| 1298 | xWriteUnaryMaxSymbol( iRefFrame - 1, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
| 1299 | } |
---|
[2] | 1300 | } |
---|
| 1301 | return; |
---|
| 1302 | } |
---|
| 1303 | |
---|
| 1304 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1305 | { |
---|
[56] | 1306 | #if H0111_MVD_L1_ZERO |
---|
| 1307 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
| 1308 | { |
---|
| 1309 | return; |
---|
| 1310 | } |
---|
[2] | 1311 | #endif |
---|
| 1312 | |
---|
[56] | 1313 | const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
| 1314 | const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
| 1315 | const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
| 1316 | ContextModel* pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
[2] | 1317 | |
---|
[56] | 1318 | m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx ); |
---|
| 1319 | m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx ); |
---|
[2] | 1320 | |
---|
[56] | 1321 | const Bool bHorAbsGr0 = iHor != 0; |
---|
| 1322 | const Bool bVerAbsGr0 = iVer != 0; |
---|
| 1323 | const UInt uiHorAbs = 0 > iHor ? -iHor : iHor; |
---|
| 1324 | const UInt uiVerAbs = 0 > iVer ? -iVer : iVer; |
---|
| 1325 | pCtx++; |
---|
[2] | 1326 | |
---|
[56] | 1327 | if( bHorAbsGr0 ) |
---|
| 1328 | { |
---|
| 1329 | m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx ); |
---|
| 1330 | } |
---|
| 1331 | |
---|
| 1332 | if( bVerAbsGr0 ) |
---|
| 1333 | { |
---|
| 1334 | m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx ); |
---|
| 1335 | } |
---|
| 1336 | |
---|
| 1337 | if( bHorAbsGr0 ) |
---|
| 1338 | { |
---|
| 1339 | if( uiHorAbs > 1 ) |
---|
| 1340 | { |
---|
| 1341 | xWriteEpExGolomb( uiHorAbs-2, 1 ); |
---|
| 1342 | } |
---|
| 1343 | |
---|
| 1344 | m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 ); |
---|
| 1345 | } |
---|
| 1346 | |
---|
| 1347 | if( bVerAbsGr0 ) |
---|
| 1348 | { |
---|
| 1349 | if( uiVerAbs > 1 ) |
---|
| 1350 | { |
---|
| 1351 | xWriteEpExGolomb( uiVerAbs-2, 1 ); |
---|
| 1352 | } |
---|
| 1353 | |
---|
| 1354 | m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); |
---|
| 1355 | } |
---|
[2] | 1356 | |
---|
| 1357 | return; |
---|
| 1358 | } |
---|
| 1359 | |
---|
| 1360 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1361 | { |
---|
[56] | 1362 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
[2] | 1363 | |
---|
[56] | 1364 | #if H0736_AVC_STYLE_QP_RANGE |
---|
| 1365 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
| 1366 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
| 1367 | #else |
---|
| 1368 | #if LOSSLESS_CODING |
---|
| 1369 | if(pcCU->getSlice()->getSPS()->getUseLossless()) |
---|
| 1370 | { |
---|
| 1371 | if(iDQp > 25) |
---|
| 1372 | { |
---|
| 1373 | iDQp = iDQp - 52; |
---|
| 1374 | } |
---|
| 1375 | if(iDQp < -26) |
---|
| 1376 | { |
---|
| 1377 | iDQp = iDQp + 52; |
---|
| 1378 | } |
---|
| 1379 | } |
---|
| 1380 | #endif |
---|
| 1381 | #endif |
---|
| 1382 | |
---|
[2] | 1383 | if ( iDQp == 0 ) |
---|
| 1384 | { |
---|
| 1385 | m_pcBinIf->encodeBin( 0, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) ); |
---|
| 1386 | } |
---|
| 1387 | else |
---|
| 1388 | { |
---|
| 1389 | m_pcBinIf->encodeBin( 1, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) ); |
---|
[56] | 1390 | |
---|
| 1391 | UInt uiSign = (iDQp > 0 ? 0 : 1); |
---|
| 1392 | #if !H0736_AVC_STYLE_QP_RANGE |
---|
| 1393 | UInt uiQpBdOffsetY = 6*(g_uiBitIncrement + g_uiBitDepth - 8); |
---|
| 1394 | #endif |
---|
| 1395 | |
---|
| 1396 | m_pcBinIf->encodeBinEP(uiSign); |
---|
| 1397 | |
---|
| 1398 | #if H0736_AVC_STYLE_QP_RANGE |
---|
| 1399 | assert(iDQp >= -(26+(qpBdOffsetY/2))); |
---|
| 1400 | assert(iDQp <= (25+(qpBdOffsetY/2))); |
---|
| 1401 | |
---|
| 1402 | UInt uiMaxAbsDQpMinus1 = 24 + (qpBdOffsetY/2) + (uiSign); |
---|
| 1403 | #else |
---|
| 1404 | assert(iDQp >= -(26+(Int)(uiQpBdOffsetY/2))); |
---|
| 1405 | assert(iDQp <= (25+(Int)(uiQpBdOffsetY/2))); |
---|
| 1406 | |
---|
| 1407 | UInt uiMaxAbsDQpMinus1 = 24 + (uiQpBdOffsetY/2) + (uiSign); |
---|
| 1408 | #endif |
---|
| 1409 | UInt uiAbsDQpMinus1 = (UInt)((iDQp > 0)? iDQp : (-iDQp)) - 1; |
---|
| 1410 | xWriteUnaryMaxSymbol( uiAbsDQpMinus1, &m_cCUDeltaQpSCModel.get( 0, 0, 1 ), 1, uiMaxAbsDQpMinus1); |
---|
[2] | 1411 | } |
---|
| 1412 | |
---|
| 1413 | return; |
---|
| 1414 | } |
---|
| 1415 | |
---|
| 1416 | Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
| 1417 | { |
---|
| 1418 | UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
| 1419 | UInt uiCtx = pcCU->getCtxQtCbf( uiAbsPartIdx, eType, uiTrDepth ); |
---|
[56] | 1420 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
| 1421 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1422 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
| 1423 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1424 | DTRACE_CABAC_V( uiCbf ) |
---|
| 1425 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 1426 | DTRACE_CABAC_V( uiCtx ) |
---|
| 1427 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 1428 | DTRACE_CABAC_V( eType ) |
---|
| 1429 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 1430 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1431 | DTRACE_CABAC_T( "\n" ) |
---|
| 1432 | } |
---|
| 1433 | |
---|
[56] | 1434 | #if BURST_IPCM |
---|
| 1435 | /** Code I_PCM information. |
---|
| 1436 | * \param pcCU pointer to CU |
---|
| 1437 | * \param uiAbsPartIdx CU index |
---|
| 1438 | * \param numIPCM the number of succesive IPCM blocks with the same size |
---|
| 1439 | * \param firstIPCMFlag |
---|
| 1440 | * \returns Void |
---|
| 1441 | */ |
---|
| 1442 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Int numIPCM, Bool firstIPCMFlag) |
---|
| 1443 | #else |
---|
| 1444 | /** Code I_PCM information. |
---|
| 1445 | * \param pcCU pointer to CU |
---|
| 1446 | * \param uiAbsPartIdx CU index |
---|
| 1447 | * \returns Void |
---|
| 1448 | * |
---|
| 1449 | * If I_PCM flag indicates that the CU is I_PCM, code its PCM alignment bits and codes. |
---|
| 1450 | */ |
---|
| 1451 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx) |
---|
| 1452 | #endif |
---|
[2] | 1453 | { |
---|
[56] | 1454 | UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0; |
---|
| 1455 | |
---|
| 1456 | #if BURST_IPCM |
---|
| 1457 | Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx); |
---|
| 1458 | |
---|
| 1459 | if( uiIPCM == 0 || firstIPCMFlag) |
---|
[2] | 1460 | { |
---|
[56] | 1461 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
| 1462 | |
---|
| 1463 | if ( firstIPCMFlag ) |
---|
[2] | 1464 | { |
---|
[56] | 1465 | m_pcBinIf->encodeNumSubseqIPCM( numIPCM - 1 ); |
---|
| 1466 | m_pcBinIf->encodePCMAlignBits(); |
---|
| 1467 | } |
---|
| 1468 | } |
---|
| 1469 | #else |
---|
| 1470 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
| 1471 | #endif |
---|
| 1472 | |
---|
| 1473 | #if BURST_IPCM |
---|
| 1474 | if (writePCMSampleFlag) |
---|
| 1475 | #else |
---|
| 1476 | if (uiIPCM) |
---|
| 1477 | #endif |
---|
| 1478 | { |
---|
| 1479 | #if !BURST_IPCM |
---|
| 1480 | m_pcBinIf->encodePCMAlignBits(); |
---|
| 1481 | #endif |
---|
| 1482 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
| 1483 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
| 1484 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
| 1485 | Pel* piPCMSample; |
---|
| 1486 | UInt uiWidth; |
---|
| 1487 | UInt uiHeight; |
---|
| 1488 | UInt uiSampleBits; |
---|
| 1489 | UInt uiX, uiY; |
---|
| 1490 | |
---|
| 1491 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
| 1492 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
| 1493 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
| 1494 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
| 1495 | |
---|
| 1496 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 1497 | { |
---|
| 1498 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
[2] | 1499 | { |
---|
[56] | 1500 | UInt uiSample = piPCMSample[uiX]; |
---|
| 1501 | |
---|
| 1502 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
[2] | 1503 | } |
---|
[56] | 1504 | piPCMSample += uiWidth; |
---|
[2] | 1505 | } |
---|
[56] | 1506 | |
---|
| 1507 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
| 1508 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
| 1509 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
| 1510 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
| 1511 | |
---|
| 1512 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 1513 | { |
---|
| 1514 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 1515 | { |
---|
| 1516 | UInt uiSample = piPCMSample[uiX]; |
---|
| 1517 | |
---|
| 1518 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
| 1519 | } |
---|
| 1520 | piPCMSample += uiWidth; |
---|
| 1521 | } |
---|
| 1522 | |
---|
| 1523 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
| 1524 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
| 1525 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
| 1526 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
| 1527 | |
---|
| 1528 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 1529 | { |
---|
| 1530 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 1531 | { |
---|
| 1532 | UInt uiSample = piPCMSample[uiX]; |
---|
| 1533 | |
---|
| 1534 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
| 1535 | } |
---|
| 1536 | piPCMSample += uiWidth; |
---|
| 1537 | } |
---|
| 1538 | #if BURST_IPCM |
---|
| 1539 | numIPCM--; |
---|
| 1540 | if(numIPCM == 0) |
---|
| 1541 | { |
---|
| 1542 | m_pcBinIf->resetBac(); |
---|
| 1543 | } |
---|
| 1544 | #else |
---|
| 1545 | m_pcBinIf->resetBac(); |
---|
| 1546 | #endif |
---|
[2] | 1547 | } |
---|
| 1548 | } |
---|
| 1549 | |
---|
| 1550 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1551 | { |
---|
| 1552 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
[56] | 1553 | UInt uiCtx = 0; |
---|
[2] | 1554 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
[56] | 1555 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1556 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
| 1557 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1558 | DTRACE_CABAC_V( uiCbf ) |
---|
| 1559 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 1560 | DTRACE_CABAC_V( uiCtx ) |
---|
| 1561 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 1562 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1563 | DTRACE_CABAC_T( "\n" ) |
---|
| 1564 | } |
---|
| 1565 | |
---|
| 1566 | /** Encode (X,Y) position of the last significant coefficient |
---|
| 1567 | * \param uiPosX X component of last coefficient |
---|
| 1568 | * \param uiPosY Y component of last coefficient |
---|
[56] | 1569 | * \param width Block width |
---|
| 1570 | * \param height Block height |
---|
[2] | 1571 | * \param eTType plane type / luminance or chrominance |
---|
| 1572 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
| 1573 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
| 1574 | */ |
---|
[56] | 1575 | Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
[2] | 1576 | { |
---|
[56] | 1577 | // swap |
---|
[2] | 1578 | if( uiScanIdx == SCAN_VER ) |
---|
| 1579 | { |
---|
| 1580 | swap( uiPosX, uiPosY ); |
---|
| 1581 | } |
---|
| 1582 | |
---|
[56] | 1583 | UInt uiCtxLast; |
---|
| 1584 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
| 1585 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
| 1586 | UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; |
---|
| 1587 | UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; |
---|
| 1588 | |
---|
| 1589 | // posX |
---|
| 1590 | #if LAST_CTX_REDUCTION |
---|
| 1591 | Int widthCtx = eTType? 4: width; |
---|
| 1592 | const UInt *puiCtxIdxX = g_uiLastCtx + ( g_aucConvertToBit[ widthCtx ] * ( g_aucConvertToBit[ widthCtx ] + 3 ) ); |
---|
| 1593 | #else |
---|
| 1594 | const UInt *puiCtxIdxX = g_uiLastCtx + ( g_aucConvertToBit[ width ] * ( g_aucConvertToBit[ width ] + 3 ) ); |
---|
| 1595 | #endif |
---|
| 1596 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) |
---|
[2] | 1597 | { |
---|
[56] | 1598 | #if LAST_CTX_REDUCTION |
---|
| 1599 | if (eTType) |
---|
| 1600 | { |
---|
| 1601 | m_pcBinIf->encodeBin( 1, *( pCtxX + (uiCtxLast>>g_aucConvertToBit[ width ]) ) ); |
---|
| 1602 | } |
---|
| 1603 | else |
---|
| 1604 | { |
---|
| 1605 | #endif |
---|
| 1606 | m_pcBinIf->encodeBin( 1, *( pCtxX + puiCtxIdxX[ uiCtxLast ] ) ); |
---|
| 1607 | #if LAST_CTX_REDUCTION |
---|
| 1608 | } |
---|
| 1609 | #endif |
---|
[2] | 1610 | } |
---|
[56] | 1611 | if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) |
---|
[2] | 1612 | { |
---|
[56] | 1613 | #if LAST_CTX_REDUCTION |
---|
| 1614 | if ( eTType ) |
---|
| 1615 | { |
---|
| 1616 | m_pcBinIf->encodeBin( 0, *( pCtxX + (uiCtxLast>>g_aucConvertToBit[ width ]) ) ); |
---|
| 1617 | } |
---|
| 1618 | else |
---|
| 1619 | { |
---|
| 1620 | #endif |
---|
| 1621 | m_pcBinIf->encodeBin( 0, *( pCtxX + puiCtxIdxX[ uiCtxLast ] ) ); |
---|
| 1622 | #if LAST_CTX_REDUCTION |
---|
| 1623 | } |
---|
| 1624 | #endif |
---|
[2] | 1625 | } |
---|
| 1626 | |
---|
[56] | 1627 | // posY |
---|
| 1628 | #if LAST_CTX_REDUCTION |
---|
| 1629 | Int heightCtx = eTType? 4: height; |
---|
| 1630 | const UInt *puiCtxIdxY = g_uiLastCtx + ( g_aucConvertToBit[ heightCtx ] * ( g_aucConvertToBit[ heightCtx ] + 3 ) ); |
---|
| 1631 | #else |
---|
| 1632 | const UInt *puiCtxIdxY = g_uiLastCtx + ( g_aucConvertToBit[ height ] * ( g_aucConvertToBit[ height ] + 3 ) ); |
---|
| 1633 | #endif |
---|
| 1634 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) |
---|
[2] | 1635 | { |
---|
[56] | 1636 | #if LAST_CTX_REDUCTION |
---|
| 1637 | if (eTType) |
---|
| 1638 | { |
---|
| 1639 | m_pcBinIf->encodeBin( 1, *( pCtxY + (uiCtxLast>>g_aucConvertToBit[ height ]))); |
---|
| 1640 | } |
---|
| 1641 | else |
---|
| 1642 | { |
---|
| 1643 | #endif |
---|
| 1644 | m_pcBinIf->encodeBin( 1, *( pCtxY + puiCtxIdxY[ uiCtxLast ] ) ); |
---|
| 1645 | #if LAST_CTX_REDUCTION |
---|
| 1646 | } |
---|
| 1647 | #endif |
---|
[2] | 1648 | } |
---|
[56] | 1649 | if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ]) |
---|
[2] | 1650 | { |
---|
[56] | 1651 | #if LAST_CTX_REDUCTION |
---|
| 1652 | if (eTType) |
---|
| 1653 | { |
---|
| 1654 | m_pcBinIf->encodeBin( 0, *( pCtxY + (uiCtxLast>>g_aucConvertToBit[ height ]) ) ); |
---|
| 1655 | } |
---|
| 1656 | else |
---|
| 1657 | { |
---|
| 1658 | #endif |
---|
| 1659 | m_pcBinIf->encodeBin( 0, *( pCtxY + puiCtxIdxY[ uiCtxLast ] ) ); |
---|
| 1660 | #if LAST_CTX_REDUCTION |
---|
| 1661 | } |
---|
| 1662 | #endif |
---|
| 1663 | } |
---|
| 1664 | if ( uiGroupIdxX > 3 ) |
---|
| 1665 | { |
---|
| 1666 | UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; |
---|
| 1667 | uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; |
---|
| 1668 | for (Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
| 1669 | { |
---|
| 1670 | m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 ); |
---|
| 1671 | } |
---|
[2] | 1672 | } |
---|
[56] | 1673 | if ( uiGroupIdxY > 3 ) |
---|
| 1674 | { |
---|
| 1675 | UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; |
---|
| 1676 | uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; |
---|
| 1677 | for ( Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
| 1678 | { |
---|
| 1679 | m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 ); |
---|
| 1680 | } |
---|
| 1681 | } |
---|
[2] | 1682 | } |
---|
| 1683 | |
---|
[56] | 1684 | Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
[2] | 1685 | { |
---|
[56] | 1686 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1687 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
| 1688 | DTRACE_CABAC_V( eTType ) |
---|
| 1689 | DTRACE_CABAC_T( "\twidth=" ) |
---|
| 1690 | DTRACE_CABAC_V( uiWidth ) |
---|
| 1691 | DTRACE_CABAC_T( "\theight=" ) |
---|
| 1692 | DTRACE_CABAC_V( uiHeight ) |
---|
| 1693 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
| 1694 | DTRACE_CABAC_V( uiDepth ) |
---|
| 1695 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
| 1696 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1697 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
| 1698 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
| 1699 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
| 1700 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
| 1701 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
| 1702 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
| 1703 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
| 1704 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1705 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
| 1706 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1707 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
| 1708 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
| 1709 | DTRACE_CABAC_T( "\n" ) |
---|
[56] | 1710 | |
---|
[2] | 1711 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
| 1712 | { |
---|
| 1713 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
| 1714 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
| 1715 | } |
---|
| 1716 | |
---|
| 1717 | UInt uiNumSig = 0; |
---|
| 1718 | |
---|
| 1719 | // compute number of significant coefficients |
---|
[56] | 1720 | uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); |
---|
[2] | 1721 | |
---|
| 1722 | if ( uiNumSig == 0 ) |
---|
| 1723 | return; |
---|
| 1724 | |
---|
| 1725 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
| 1726 | |
---|
| 1727 | //----- encode significance map ----- |
---|
| 1728 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
[56] | 1729 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
| 1730 | if (uiScanIdx == SCAN_ZIGZAG) |
---|
| 1731 | { |
---|
| 1732 | // Map zigzag to diagonal scan |
---|
| 1733 | uiScanIdx = SCAN_DIAG; |
---|
| 1734 | } |
---|
| 1735 | Int blockType = uiLog2BlockSize; |
---|
| 1736 | if (uiWidth != uiHeight) |
---|
| 1737 | { |
---|
| 1738 | uiScanIdx = SCAN_DIAG; |
---|
| 1739 | blockType = 4; |
---|
| 1740 | } |
---|
[2] | 1741 | |
---|
[56] | 1742 | const UInt * scan; |
---|
| 1743 | if (uiWidth == uiHeight) |
---|
| 1744 | { |
---|
| 1745 | scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize - 1 ]; |
---|
| 1746 | } |
---|
| 1747 | else |
---|
| 1748 | { |
---|
| 1749 | scan = g_sigScanNSQT[ uiLog2BlockSize - 2 ]; |
---|
| 1750 | } |
---|
| 1751 | |
---|
| 1752 | #if MULTIBITS_DATA_HIDING |
---|
| 1753 | UInt const tsig = pcCU->getSlice()->getPPS()->getTSIG(); |
---|
| 1754 | #if LOSSLESS_CODING |
---|
| 1755 | Bool beValid; |
---|
| 1756 | if (pcCU->isLosslessCoded(uiAbsPartIdx)) |
---|
| 1757 | { |
---|
| 1758 | beValid = false; |
---|
| 1759 | } |
---|
| 1760 | else |
---|
| 1761 | { |
---|
| 1762 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
| 1763 | } |
---|
[2] | 1764 | #else |
---|
[56] | 1765 | Bool beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
| 1766 | #endif |
---|
| 1767 | #endif |
---|
[2] | 1768 | |
---|
[56] | 1769 | // Find position of last coefficient |
---|
| 1770 | Int scanPosLast = -1; |
---|
| 1771 | Int posLast; |
---|
| 1772 | |
---|
| 1773 | const UInt * scanCG; |
---|
| 1774 | if (uiWidth == uiHeight) |
---|
| 1775 | { |
---|
| 1776 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
| 1777 | #if MULTILEVEL_SIGMAP_EXT |
---|
| 1778 | if( uiLog2BlockSize == 3 ) |
---|
| 1779 | { |
---|
| 1780 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
[2] | 1781 | } |
---|
[56] | 1782 | else if( uiLog2BlockSize == 5 ) |
---|
| 1783 | { |
---|
| 1784 | scanCG = g_sigLastScanCG32x32; |
---|
| 1785 | } |
---|
| 1786 | #endif |
---|
| 1787 | } |
---|
| 1788 | else |
---|
| 1789 | { |
---|
| 1790 | scanCG = g_sigCGScanNSQT[ uiLog2BlockSize - 2 ]; |
---|
| 1791 | } |
---|
| 1792 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
| 1793 | static const UInt uiShift = MLS_CG_SIZE >> 1; |
---|
| 1794 | const UInt uiNumBlkSide = uiWidth >> uiShift; |
---|
[2] | 1795 | |
---|
[56] | 1796 | #if !MULTILEVEL_SIGMAP_EXT |
---|
| 1797 | if( blockType > 3 ) |
---|
| 1798 | { |
---|
| 1799 | #endif |
---|
| 1800 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
| 1801 | |
---|
| 1802 | do |
---|
[2] | 1803 | { |
---|
[56] | 1804 | posLast = scan[ ++scanPosLast ]; |
---|
| 1805 | |
---|
| 1806 | // get L1 sig map |
---|
| 1807 | UInt uiPosY = posLast >> uiLog2BlockSize; |
---|
| 1808 | UInt uiPosX = posLast - ( uiPosY << uiLog2BlockSize ); |
---|
| 1809 | UInt uiBlkIdx = uiNumBlkSide * (uiPosY >> uiShift) + (uiPosX >> uiShift); |
---|
| 1810 | #if MULTILEVEL_SIGMAP_EXT |
---|
| 1811 | if( uiWidth == 8 && uiHeight == 8 && (uiScanIdx == SCAN_HOR || uiScanIdx == SCAN_VER) ) |
---|
[2] | 1812 | { |
---|
[56] | 1813 | if( uiScanIdx == SCAN_HOR ) |
---|
[2] | 1814 | { |
---|
[56] | 1815 | uiBlkIdx = uiPosY >> 1; |
---|
[2] | 1816 | } |
---|
[56] | 1817 | else if( uiScanIdx == SCAN_VER ) |
---|
[2] | 1818 | { |
---|
[56] | 1819 | uiBlkIdx = uiPosX >> 1; |
---|
[2] | 1820 | } |
---|
| 1821 | } |
---|
| 1822 | #endif |
---|
[56] | 1823 | if( pcCoef[ posLast ] ) |
---|
[2] | 1824 | { |
---|
[56] | 1825 | uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; |
---|
[2] | 1826 | } |
---|
[56] | 1827 | |
---|
| 1828 | uiNumSig -= ( pcCoef[ posLast ] != 0 ); |
---|
[2] | 1829 | } |
---|
[56] | 1830 | while ( uiNumSig > 0 ); |
---|
| 1831 | #if !MULTILEVEL_SIGMAP_EXT |
---|
[2] | 1832 | } |
---|
[56] | 1833 | else |
---|
| 1834 | { |
---|
| 1835 | |
---|
| 1836 | do |
---|
| 1837 | { |
---|
| 1838 | posLast = scan[ ++scanPosLast ]; |
---|
| 1839 | uiNumSig -= ( pcCoef[ posLast ] != 0 ); |
---|
| 1840 | } |
---|
| 1841 | while ( uiNumSig > 0 ); |
---|
| 1842 | |
---|
| 1843 | } |
---|
[2] | 1844 | #endif |
---|
| 1845 | |
---|
[56] | 1846 | // Code position of last coefficient |
---|
| 1847 | Int posLastY = posLast >> uiLog2BlockSize; |
---|
| 1848 | Int posLastX = posLast - ( posLastY << uiLog2BlockSize ); |
---|
| 1849 | codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, eTType, uiScanIdx); |
---|
| 1850 | |
---|
| 1851 | //===== code significance flag ===== |
---|
| 1852 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
| 1853 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
| 1854 | |
---|
| 1855 | |
---|
| 1856 | const Int iLastScanSet = scanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
| 1857 | UInt uiNumOne = 0; |
---|
| 1858 | UInt uiGoRiceParam = 0; |
---|
| 1859 | Int iScanPosSig = scanPosLast; |
---|
| 1860 | |
---|
| 1861 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
[2] | 1862 | { |
---|
[56] | 1863 | Int numNonZero = 0; |
---|
| 1864 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
| 1865 | uiGoRiceParam = 0; |
---|
| 1866 | Int absCoeff[16]; |
---|
| 1867 | UInt coeffSigns = 0; |
---|
| 1868 | |
---|
| 1869 | #if MULTIBITS_DATA_HIDING |
---|
| 1870 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
| 1871 | #endif |
---|
| 1872 | |
---|
| 1873 | if( iScanPosSig == scanPosLast ) |
---|
[2] | 1874 | { |
---|
[56] | 1875 | absCoeff[ 0 ] = abs( pcCoef[ posLast ] ); |
---|
| 1876 | coeffSigns = ( pcCoef[ posLast ] < 0 ); |
---|
| 1877 | numNonZero = 1; |
---|
| 1878 | #if MULTIBITS_DATA_HIDING |
---|
| 1879 | lastNZPosInCG = iScanPosSig; |
---|
| 1880 | firstNZPosInCG = iScanPosSig; |
---|
[2] | 1881 | #endif |
---|
[56] | 1882 | iScanPosSig--; |
---|
| 1883 | } |
---|
[2] | 1884 | |
---|
[56] | 1885 | #if !MULTILEVEL_SIGMAP_EXT |
---|
| 1886 | if( blockType > 3 ) |
---|
| 1887 | { |
---|
| 1888 | #endif |
---|
| 1889 | // encode significant_coeffgroup_flag |
---|
| 1890 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
| 1891 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
| 1892 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
| 1893 | #if MULTILEVEL_SIGMAP_EXT |
---|
| 1894 | if( uiWidth == 8 && uiHeight == 8 && (uiScanIdx == SCAN_HOR || uiScanIdx == SCAN_VER) ) |
---|
[2] | 1895 | { |
---|
[56] | 1896 | iCGPosY = (uiScanIdx == SCAN_HOR ? iCGBlkPos : 0); |
---|
| 1897 | iCGPosX = (uiScanIdx == SCAN_VER ? iCGBlkPos : 0); |
---|
[2] | 1898 | } |
---|
[56] | 1899 | #endif |
---|
| 1900 | #if !REMOVE_INFER_SIGGRP |
---|
| 1901 | Bool bInferredCGFlag = false; |
---|
| 1902 | #endif |
---|
| 1903 | #if REMOVE_INFER_SIGGRP |
---|
| 1904 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
| 1905 | #else |
---|
| 1906 | if( iSubSet == iLastScanSet ) |
---|
| 1907 | #endif |
---|
[2] | 1908 | { |
---|
[56] | 1909 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
| 1910 | } |
---|
| 1911 | else |
---|
| 1912 | { |
---|
| 1913 | #if !REMOVE_INFER_SIGGRP |
---|
| 1914 | #if MULTILEVEL_SIGMAP_EXT |
---|
| 1915 | if( !TComTrQuant::bothCGNeighboursOne( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiScanIdx, uiWidth, uiHeight ) && ( iSubSet ) ) |
---|
| 1916 | #else |
---|
| 1917 | if( !TComTrQuant::bothCGNeighboursOne( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ) && ( iSubSet ) ) |
---|
| 1918 | #endif |
---|
[2] | 1919 | { |
---|
[56] | 1920 | #endif |
---|
| 1921 | UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); |
---|
| 1922 | #if MULTILEVEL_SIGMAP_EXT |
---|
| 1923 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiScanIdx, uiWidth, uiHeight ); |
---|
| 1924 | #else |
---|
| 1925 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
| 1926 | #endif |
---|
| 1927 | m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
| 1928 | #if !REMOVE_INFER_SIGGRP |
---|
[2] | 1929 | } |
---|
| 1930 | else |
---|
| 1931 | { |
---|
[56] | 1932 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
| 1933 | bInferredCGFlag = true; |
---|
[2] | 1934 | } |
---|
[56] | 1935 | #endif |
---|
| 1936 | } |
---|
| 1937 | |
---|
| 1938 | // encode significant_coeff_flag |
---|
| 1939 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
| 1940 | { |
---|
| 1941 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
| 1942 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
[2] | 1943 | { |
---|
[56] | 1944 | uiBlkPos = scan[ iScanPosSig ]; |
---|
| 1945 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
| 1946 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
| 1947 | uiSig = (pcCoef[ uiBlkPos ] != 0); |
---|
| 1948 | #if REMOVE_INFER_SIGGRP |
---|
| 1949 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
| 1950 | #else |
---|
| 1951 | if( iScanPosSig > iSubPos || bInferredCGFlag || numNonZero ) |
---|
| 1952 | #endif |
---|
[2] | 1953 | { |
---|
[56] | 1954 | uiCtxSig = TComTrQuant::getSigCtxInc( pcCoef, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType ); |
---|
| 1955 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
| 1956 | } |
---|
| 1957 | if( uiSig ) |
---|
| 1958 | { |
---|
| 1959 | absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); |
---|
| 1960 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
| 1961 | numNonZero++; |
---|
| 1962 | #if MULTIBITS_DATA_HIDING |
---|
| 1963 | if( lastNZPosInCG == -1 ) |
---|
[2] | 1964 | { |
---|
[56] | 1965 | lastNZPosInCG = iScanPosSig; |
---|
[2] | 1966 | } |
---|
[56] | 1967 | firstNZPosInCG = iScanPosSig; |
---|
| 1968 | #endif |
---|
[2] | 1969 | } |
---|
| 1970 | } |
---|
[56] | 1971 | } |
---|
| 1972 | else |
---|
| 1973 | { |
---|
| 1974 | iScanPosSig = iSubPos - 1; |
---|
| 1975 | } |
---|
| 1976 | #if !MULTILEVEL_SIGMAP_EXT |
---|
| 1977 | } |
---|
| 1978 | else |
---|
| 1979 | { |
---|
| 1980 | |
---|
| 1981 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
| 1982 | { |
---|
| 1983 | UInt uiBlkPos = scan[ iScanPosSig ]; |
---|
| 1984 | UInt uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
| 1985 | UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
| 1986 | UInt uiSig = 0; |
---|
| 1987 | if( pcCoef[ uiBlkPos ] != 0 ) |
---|
| 1988 | { |
---|
| 1989 | uiSig = 1; |
---|
| 1990 | absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); |
---|
| 1991 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
| 1992 | numNonZero++; |
---|
| 1993 | #if MULTIBITS_DATA_HIDING |
---|
| 1994 | if( lastNZPosInCG == -1 ) |
---|
[2] | 1995 | { |
---|
[56] | 1996 | lastNZPosInCG = iScanPosSig; |
---|
| 1997 | } |
---|
| 1998 | firstNZPosInCG = iScanPosSig; |
---|
| 1999 | #endif |
---|
| 2000 | } |
---|
| 2001 | UInt uiCtxSig = TComTrQuant::getSigCtxInc( pcCoef, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType ); |
---|
| 2002 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
| 2003 | } |
---|
[2] | 2004 | |
---|
[56] | 2005 | } |
---|
| 2006 | #endif |
---|
[2] | 2007 | |
---|
[56] | 2008 | if( numNonZero > 0 ) |
---|
| 2009 | { |
---|
| 2010 | #if MULTIBITS_DATA_HIDING |
---|
| 2011 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= (Int)tsig ); |
---|
| 2012 | #endif // MULTIBITS_DATA_HIDING |
---|
| 2013 | |
---|
| 2014 | UInt c1 = 1; |
---|
| 2015 | #if !RESTRICT_GR1GR2FLAG_NUMBER |
---|
| 2016 | UInt c2 = 0; |
---|
| 2017 | #endif |
---|
| 2018 | #if LEVEL_CTX_LUMA_RED |
---|
| 2019 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
[2] | 2020 | #else |
---|
[56] | 2021 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 3 : 0; |
---|
[2] | 2022 | #endif |
---|
[56] | 2023 | |
---|
| 2024 | if( uiNumOne > 0 ) |
---|
| 2025 | { |
---|
| 2026 | uiCtxSet++; |
---|
| 2027 | #if !LEVEL_CTX_LUMA_RED |
---|
| 2028 | if( uiNumOne > 3 && eTType==TEXT_LUMA) |
---|
[2] | 2029 | { |
---|
[56] | 2030 | uiCtxSet++; |
---|
[2] | 2031 | } |
---|
[56] | 2032 | #endif |
---|
[2] | 2033 | } |
---|
| 2034 | |
---|
[56] | 2035 | uiNumOne >>= 1; |
---|
| 2036 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
| 2037 | |
---|
| 2038 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
| 2039 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
| 2040 | Int firstC2FlagIdx = -1; |
---|
| 2041 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
| 2042 | #else |
---|
| 2043 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 2044 | #endif |
---|
[2] | 2045 | { |
---|
[56] | 2046 | UInt uiSymbol = absCoeff[ idx ] > 1; |
---|
| 2047 | m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] ); |
---|
[2] | 2048 | if( uiSymbol ) |
---|
| 2049 | { |
---|
| 2050 | c1 = 0; |
---|
[56] | 2051 | |
---|
| 2052 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
| 2053 | if (firstC2FlagIdx == -1) |
---|
| 2054 | { |
---|
| 2055 | firstC2FlagIdx = idx; |
---|
| 2056 | } |
---|
| 2057 | #endif |
---|
[2] | 2058 | } |
---|
[56] | 2059 | else if( (c1 < 3) && (c1 > 0) ) |
---|
[2] | 2060 | { |
---|
| 2061 | c1++; |
---|
| 2062 | } |
---|
| 2063 | } |
---|
| 2064 | |
---|
[56] | 2065 | if (c1 == 0) |
---|
[2] | 2066 | { |
---|
[56] | 2067 | |
---|
| 2068 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
| 2069 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
| 2070 | if ( firstC2FlagIdx != -1) |
---|
[2] | 2071 | { |
---|
[56] | 2072 | UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; |
---|
| 2073 | m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); |
---|
| 2074 | } |
---|
| 2075 | #else |
---|
| 2076 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + 3 * uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + 3 * uiCtxSet; |
---|
| 2077 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 2078 | { |
---|
| 2079 | if( absCoeff[ idx ] > 1 ) |
---|
[2] | 2080 | { |
---|
[56] | 2081 | UInt symbol = absCoeff[ idx ] > 2; |
---|
| 2082 | m_pcBinIf->encodeBin( symbol, baseCtxMod[c2] ); |
---|
| 2083 | c2 += (c2 < 2); |
---|
| 2084 | uiNumOne++; |
---|
[2] | 2085 | } |
---|
[56] | 2086 | } |
---|
[2] | 2087 | #endif |
---|
| 2088 | } |
---|
| 2089 | |
---|
[56] | 2090 | #if MULTIBITS_DATA_HIDING |
---|
| 2091 | if( beValid && signHidden ) |
---|
[2] | 2092 | { |
---|
[56] | 2093 | m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 ); |
---|
[2] | 2094 | } |
---|
[56] | 2095 | else |
---|
| 2096 | { |
---|
| 2097 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
| 2098 | } |
---|
[2] | 2099 | #else |
---|
[56] | 2100 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
[2] | 2101 | #endif |
---|
[56] | 2102 | |
---|
| 2103 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
| 2104 | Int iFirstCoeff2 = 1; |
---|
| 2105 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
[2] | 2106 | #else |
---|
[56] | 2107 | if (c1 == 0) |
---|
[2] | 2108 | #endif |
---|
[56] | 2109 | { |
---|
| 2110 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 2111 | { |
---|
| 2112 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
| 2113 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1; |
---|
[2] | 2114 | |
---|
[56] | 2115 | if( absCoeff[ idx ] >= baseLevel) |
---|
| 2116 | { |
---|
| 2117 | xWriteGoRiceExGolomb( absCoeff[ idx ] - baseLevel, uiGoRiceParam ); |
---|
| 2118 | } |
---|
| 2119 | if(absCoeff[ idx ] >= 2) |
---|
| 2120 | { |
---|
| 2121 | iFirstCoeff2 = 0; |
---|
| 2122 | uiNumOne++; |
---|
| 2123 | } |
---|
| 2124 | #else |
---|
| 2125 | if ( absCoeff[ idx ] > 2 ) |
---|
| 2126 | { |
---|
| 2127 | xWriteGoRiceExGolomb( absCoeff[ idx ] - 3, uiGoRiceParam ); |
---|
| 2128 | } |
---|
| 2129 | #endif |
---|
| 2130 | } |
---|
| 2131 | } |
---|
[2] | 2132 | } |
---|
[56] | 2133 | else |
---|
[2] | 2134 | { |
---|
[56] | 2135 | uiNumOne >>= 1; |
---|
[2] | 2136 | } |
---|
| 2137 | } |
---|
[56] | 2138 | |
---|
[2] | 2139 | return; |
---|
| 2140 | } |
---|
| 2141 | |
---|
| 2142 | Void TEncSbac::codeAlfFlag ( UInt uiCode ) |
---|
| 2143 | { |
---|
| 2144 | UInt uiSymbol = ( ( uiCode == 0 ) ? 0 : 1 ); |
---|
| 2145 | m_pcBinIf->encodeBin( uiSymbol, m_cALFFlagSCModel.get( 0, 0, 0 ) ); |
---|
| 2146 | } |
---|
| 2147 | |
---|
| 2148 | Void TEncSbac::codeAlfCtrlFlag( UInt uiSymbol ) |
---|
| 2149 | { |
---|
| 2150 | m_pcBinIf->encodeBin( uiSymbol, m_cCUAlfCtrlFlagSCModel.get( 0, 0, 0) ); |
---|
| 2151 | } |
---|
| 2152 | |
---|
| 2153 | Void TEncSbac::codeAlfUvlc ( UInt uiCode ) |
---|
| 2154 | { |
---|
| 2155 | Int i; |
---|
| 2156 | |
---|
| 2157 | if ( uiCode == 0 ) |
---|
| 2158 | { |
---|
| 2159 | m_pcBinIf->encodeBin( 0, m_cALFUvlcSCModel.get( 0, 0, 0 ) ); |
---|
| 2160 | } |
---|
| 2161 | else |
---|
| 2162 | { |
---|
| 2163 | m_pcBinIf->encodeBin( 1, m_cALFUvlcSCModel.get( 0, 0, 0 ) ); |
---|
| 2164 | for ( i=0; i<uiCode-1; i++ ) |
---|
| 2165 | { |
---|
| 2166 | m_pcBinIf->encodeBin( 1, m_cALFUvlcSCModel.get( 0, 0, 1 ) ); |
---|
| 2167 | } |
---|
| 2168 | m_pcBinIf->encodeBin( 0, m_cALFUvlcSCModel.get( 0, 0, 1 ) ); |
---|
| 2169 | } |
---|
| 2170 | } |
---|
| 2171 | |
---|
| 2172 | Void TEncSbac::codeAlfSvlc ( Int iCode ) |
---|
| 2173 | { |
---|
| 2174 | Int i; |
---|
| 2175 | |
---|
| 2176 | if ( iCode == 0 ) |
---|
| 2177 | { |
---|
| 2178 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 0 ) ); |
---|
| 2179 | } |
---|
| 2180 | else |
---|
| 2181 | { |
---|
| 2182 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 0 ) ); |
---|
| 2183 | |
---|
| 2184 | // write sign |
---|
| 2185 | if ( iCode > 0 ) |
---|
| 2186 | { |
---|
| 2187 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 1 ) ); |
---|
| 2188 | } |
---|
| 2189 | else |
---|
| 2190 | { |
---|
| 2191 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 1 ) ); |
---|
| 2192 | iCode = -iCode; |
---|
| 2193 | } |
---|
| 2194 | |
---|
| 2195 | // write magnitude |
---|
| 2196 | for ( i=0; i<iCode-1; i++ ) |
---|
| 2197 | { |
---|
| 2198 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 2 ) ); |
---|
| 2199 | } |
---|
| 2200 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 2 ) ); |
---|
| 2201 | } |
---|
| 2202 | } |
---|
| 2203 | |
---|
[56] | 2204 | Void TEncSbac::codeSaoFlag ( UInt uiCode ) |
---|
[2] | 2205 | { |
---|
| 2206 | UInt uiSymbol = ( ( uiCode == 0 ) ? 0 : 1 ); |
---|
[56] | 2207 | m_pcBinIf->encodeBin( uiSymbol, m_cSaoFlagSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 2208 | } |
---|
[56] | 2209 | |
---|
| 2210 | Void TEncSbac::codeSaoUvlc ( UInt uiCode ) |
---|
[2] | 2211 | { |
---|
| 2212 | Int i; |
---|
| 2213 | |
---|
| 2214 | if ( uiCode == 0 ) |
---|
| 2215 | { |
---|
[56] | 2216 | m_pcBinIf->encodeBin( 0, m_cSaoUvlcSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 2217 | } |
---|
| 2218 | else |
---|
| 2219 | { |
---|
[56] | 2220 | m_pcBinIf->encodeBin( 1, m_cSaoUvlcSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 2221 | for ( i=0; i<uiCode-1; i++ ) |
---|
| 2222 | { |
---|
[56] | 2223 | m_pcBinIf->encodeBin( 1, m_cSaoUvlcSCModel.get( 0, 0, 1 ) ); |
---|
[2] | 2224 | } |
---|
[56] | 2225 | m_pcBinIf->encodeBin( 0, m_cSaoUvlcSCModel.get( 0, 0, 1 ) ); |
---|
[2] | 2226 | } |
---|
| 2227 | } |
---|
[56] | 2228 | |
---|
| 2229 | Void TEncSbac::codeSaoSvlc ( Int iCode ) |
---|
[2] | 2230 | { |
---|
| 2231 | Int i; |
---|
| 2232 | |
---|
| 2233 | if ( iCode == 0 ) |
---|
| 2234 | { |
---|
[56] | 2235 | m_pcBinIf->encodeBin( 0, m_cSaoSvlcSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 2236 | } |
---|
| 2237 | else |
---|
| 2238 | { |
---|
[56] | 2239 | m_pcBinIf->encodeBin( 1, m_cSaoSvlcSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 2240 | |
---|
| 2241 | // write sign |
---|
| 2242 | if ( iCode > 0 ) |
---|
| 2243 | { |
---|
[56] | 2244 | m_pcBinIf->encodeBin( 0, m_cSaoSvlcSCModel.get( 0, 0, 1 ) ); |
---|
[2] | 2245 | } |
---|
| 2246 | else |
---|
| 2247 | { |
---|
[56] | 2248 | m_pcBinIf->encodeBin( 1, m_cSaoSvlcSCModel.get( 0, 0, 1 ) ); |
---|
[2] | 2249 | iCode = -iCode; |
---|
| 2250 | } |
---|
| 2251 | |
---|
| 2252 | // write magnitude |
---|
| 2253 | for ( i=0; i<iCode-1; i++ ) |
---|
| 2254 | { |
---|
[56] | 2255 | m_pcBinIf->encodeBin( 1, m_cSaoSvlcSCModel.get( 0, 0, 2 ) ); |
---|
[2] | 2256 | } |
---|
[56] | 2257 | m_pcBinIf->encodeBin( 0, m_cSaoSvlcSCModel.get( 0, 0, 2 ) ); |
---|
[2] | 2258 | } |
---|
| 2259 | } |
---|
[56] | 2260 | #if SAO_UNIT_INTERLEAVING |
---|
| 2261 | /** Code SAO band position |
---|
| 2262 | * \param uiCode |
---|
| 2263 | */ |
---|
| 2264 | Void TEncSbac::codeSaoUflc ( UInt uiCode ) |
---|
| 2265 | { |
---|
| 2266 | for (Int i=0;i<5;i++) |
---|
| 2267 | { |
---|
| 2268 | m_pcBinIf->encodeBinEP ( (uiCode>>i) &0x01 ); |
---|
| 2269 | } |
---|
| 2270 | } |
---|
| 2271 | /** Code SAO merge left flag |
---|
| 2272 | * \param uiCode |
---|
| 2273 | * \param uiCompIdx |
---|
| 2274 | */ |
---|
| 2275 | Void TEncSbac::codeSaoMergeLeft ( UInt uiCode, UInt uiCompIdx ) |
---|
| 2276 | { |
---|
| 2277 | if (uiCode == 0) |
---|
| 2278 | { |
---|
| 2279 | m_pcBinIf->encodeBin(0, m_cSaoMergeLeftSCModel.get( 0, 0, uiCompIdx )); |
---|
| 2280 | } |
---|
| 2281 | else |
---|
| 2282 | { |
---|
| 2283 | m_pcBinIf->encodeBin(1, m_cSaoMergeLeftSCModel.get( 0, 0, uiCompIdx )); |
---|
| 2284 | } |
---|
| 2285 | } |
---|
| 2286 | /** Code SAO merge up flag |
---|
| 2287 | * \param uiCode |
---|
| 2288 | */ |
---|
| 2289 | Void TEncSbac::codeSaoMergeUp ( UInt uiCode) |
---|
| 2290 | { |
---|
| 2291 | if (uiCode == 0) |
---|
| 2292 | { |
---|
| 2293 | m_pcBinIf->encodeBin(0, m_cSaoMergeUpSCModel.get( 0, 0, 0 )); |
---|
| 2294 | } |
---|
| 2295 | else |
---|
| 2296 | { |
---|
| 2297 | m_pcBinIf->encodeBin(1, m_cSaoMergeUpSCModel.get( 0, 0, 0 )); |
---|
| 2298 | } |
---|
| 2299 | } |
---|
| 2300 | /** Code SAO type index |
---|
| 2301 | * \param uiCode |
---|
| 2302 | */ |
---|
| 2303 | Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) |
---|
| 2304 | { |
---|
| 2305 | Int i; |
---|
| 2306 | if ( uiCode == 0 ) |
---|
| 2307 | { |
---|
| 2308 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
| 2309 | } |
---|
| 2310 | else |
---|
| 2311 | { |
---|
| 2312 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
| 2313 | for ( i=0; i<uiCode-1; i++ ) |
---|
| 2314 | { |
---|
| 2315 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 1 ) ); |
---|
| 2316 | } |
---|
| 2317 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 1 ) ); |
---|
| 2318 | } |
---|
| 2319 | } |
---|
[2] | 2320 | #endif |
---|
| 2321 | /*! |
---|
| 2322 | **************************************************************************** |
---|
| 2323 | * \brief |
---|
| 2324 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
| 2325 | **************************************************************************** |
---|
| 2326 | */ |
---|
[56] | 2327 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
[2] | 2328 | { |
---|
| 2329 | estCBFBit( pcEstBitsSbac, 0, eTType ); |
---|
[56] | 2330 | |
---|
| 2331 | estSignificantCoeffGroupMapBit( pcEstBitsSbac, 0, eTType ); |
---|
[2] | 2332 | |
---|
| 2333 | // encode significance map |
---|
[56] | 2334 | estSignificantMapBit( pcEstBitsSbac, width, height, eTType ); |
---|
[2] | 2335 | |
---|
| 2336 | // encode significant coefficients |
---|
[56] | 2337 | estSignificantCoefficientsBit( pcEstBitsSbac, 0, eTType ); |
---|
[2] | 2338 | } |
---|
| 2339 | |
---|
| 2340 | /*! |
---|
| 2341 | **************************************************************************** |
---|
| 2342 | * \brief |
---|
| 2343 | * estimate bit cost for each CBP bit |
---|
| 2344 | **************************************************************************** |
---|
| 2345 | */ |
---|
| 2346 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
| 2347 | { |
---|
| 2348 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
| 2349 | |
---|
[56] | 2350 | for( UInt uiCtxInc = 0; uiCtxInc < 3*NUM_QT_CBF_CTX; uiCtxInc++ ) |
---|
[2] | 2351 | { |
---|
[56] | 2352 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
| 2353 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
[2] | 2354 | } |
---|
| 2355 | |
---|
[56] | 2356 | pCtx = m_cCUQtRootCbfSCModel.get( 0 ); |
---|
| 2357 | |
---|
[2] | 2358 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
| 2359 | { |
---|
[56] | 2360 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
| 2361 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
[2] | 2362 | } |
---|
| 2363 | } |
---|
| 2364 | |
---|
| 2365 | |
---|
| 2366 | /*! |
---|
| 2367 | **************************************************************************** |
---|
| 2368 | * \brief |
---|
[56] | 2369 | * estimate SAMBAC bit cost for significant coefficient group map |
---|
[2] | 2370 | **************************************************************************** |
---|
| 2371 | */ |
---|
[56] | 2372 | Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
[2] | 2373 | { |
---|
[56] | 2374 | Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; |
---|
| 2375 | |
---|
| 2376 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
[2] | 2377 | { |
---|
| 2378 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
| 2379 | { |
---|
[56] | 2380 | pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, eTType, ctxIdx ).getEntropyBits( uiBin ); |
---|
| 2381 | } |
---|
| 2382 | } |
---|
| 2383 | } |
---|
| 2384 | |
---|
| 2385 | |
---|
| 2386 | /*! |
---|
| 2387 | **************************************************************************** |
---|
| 2388 | * \brief |
---|
| 2389 | * estimate SAMBAC bit cost for significant coefficient map |
---|
| 2390 | **************************************************************************** |
---|
| 2391 | */ |
---|
| 2392 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
| 2393 | { |
---|
| 2394 | Int firstCtx = 0, numCtx = (eTType == TEXT_LUMA) ? 9 : 6; |
---|
| 2395 | if (std::max(width, height) >= 16) |
---|
| 2396 | { |
---|
| 2397 | firstCtx = (eTType == TEXT_LUMA) ? 20 : 17; |
---|
| 2398 | numCtx = (eTType == TEXT_LUMA) ? 7 : 4; |
---|
| 2399 | } |
---|
| 2400 | else if (width == 8) |
---|
| 2401 | { |
---|
| 2402 | firstCtx = (eTType == TEXT_LUMA) ? 9 : 6; |
---|
| 2403 | numCtx = 11; |
---|
| 2404 | } |
---|
| 2405 | |
---|
| 2406 | if (eTType == TEXT_LUMA ) |
---|
| 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, ctxIdx ).getEntropyBits( uiBin ); |
---|
[2] | 2413 | } |
---|
[56] | 2414 | } |
---|
| 2415 | } |
---|
| 2416 | else |
---|
| 2417 | { |
---|
| 2418 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
| 2419 | { |
---|
| 2420 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
[2] | 2421 | { |
---|
[56] | 2422 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx ).getEntropyBits( uiBin ); |
---|
[2] | 2423 | } |
---|
[56] | 2424 | } |
---|
| 2425 | } |
---|
| 2426 | Int iBitsX = 0, iBitsY = 0; |
---|
| 2427 | const UInt *puiCtxIdx; |
---|
| 2428 | Int ctx; |
---|
| 2429 | #if LAST_CTX_REDUCTION |
---|
| 2430 | Int widthCtx = eTType? 4 : width; |
---|
| 2431 | puiCtxIdx = g_uiLastCtx + (g_aucConvertToBit[ widthCtx ]*(g_aucConvertToBit[ widthCtx ]+3)); |
---|
| 2432 | #else |
---|
| 2433 | puiCtxIdx = g_uiLastCtx + (g_aucConvertToBit[ width ]*(g_aucConvertToBit[ width ]+3)); |
---|
[2] | 2434 | #endif |
---|
[56] | 2435 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
| 2436 | for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) |
---|
| 2437 | { |
---|
| 2438 | Int ctxOffset = puiCtxIdx[ ctx ]; |
---|
| 2439 | #if LAST_CTX_REDUCTION |
---|
| 2440 | if (eTType) |
---|
| 2441 | { |
---|
| 2442 | Int ctxOffsetC = ctx>>g_aucConvertToBit[ width ]; |
---|
| 2443 | pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffsetC ].getEntropyBits( 0 ); |
---|
| 2444 | iBitsX += pCtxX[ ctxOffsetC].getEntropyBits( 1 ); |
---|
| 2445 | } |
---|
| 2446 | else |
---|
| 2447 | { |
---|
[2] | 2448 | #endif |
---|
[56] | 2449 | pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); |
---|
| 2450 | iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); |
---|
| 2451 | #if LAST_CTX_REDUCTION |
---|
[2] | 2452 | } |
---|
[56] | 2453 | #endif |
---|
| 2454 | } |
---|
| 2455 | pcEstBitsSbac->lastXBits[ctx] = iBitsX; |
---|
[2] | 2456 | |
---|
[56] | 2457 | #if LAST_CTX_REDUCTION |
---|
| 2458 | Int heightCtx = eTType? 4 : height; |
---|
| 2459 | puiCtxIdx = g_uiLastCtx + (g_aucConvertToBit[ heightCtx ]*(g_aucConvertToBit[ heightCtx ]+3)); |
---|
| 2460 | #else |
---|
| 2461 | puiCtxIdx = g_uiLastCtx + (g_aucConvertToBit[ height ]*(g_aucConvertToBit[ height ]+3)); |
---|
| 2462 | #endif |
---|
| 2463 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
| 2464 | for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) |
---|
[2] | 2465 | { |
---|
[56] | 2466 | Int ctxOffset = puiCtxIdx[ ctx ]; |
---|
| 2467 | #if LAST_CTX_REDUCTION |
---|
| 2468 | if (eTType) |
---|
| 2469 | { |
---|
| 2470 | Int ctxOffsetC = ctx>>g_aucConvertToBit[ height ]; |
---|
| 2471 | pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffsetC ].getEntropyBits( 0 ); |
---|
| 2472 | iBitsY += pCtxY[ctxOffsetC].getEntropyBits( 1 ); |
---|
| 2473 | } |
---|
| 2474 | else |
---|
| 2475 | { |
---|
[2] | 2476 | #endif |
---|
[56] | 2477 | pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); |
---|
| 2478 | iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); |
---|
| 2479 | #if LAST_CTX_REDUCTION |
---|
| 2480 | } |
---|
| 2481 | #endif |
---|
| 2482 | } |
---|
| 2483 | pcEstBitsSbac->lastYBits[ctx] = iBitsY; |
---|
[2] | 2484 | } |
---|
| 2485 | |
---|
| 2486 | /*! |
---|
| 2487 | **************************************************************************** |
---|
| 2488 | * \brief |
---|
| 2489 | * estimate bit cost of significant coefficient |
---|
| 2490 | **************************************************************************** |
---|
| 2491 | */ |
---|
| 2492 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
| 2493 | { |
---|
[56] | 2494 | if (eTType==TEXT_LUMA) |
---|
[2] | 2495 | { |
---|
[56] | 2496 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); |
---|
| 2497 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); |
---|
| 2498 | |
---|
| 2499 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++) |
---|
[2] | 2500 | { |
---|
[56] | 2501 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2502 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
[2] | 2503 | } |
---|
[56] | 2504 | |
---|
| 2505 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_LUMA; ctxIdx++) |
---|
| 2506 | { |
---|
| 2507 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2508 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 2509 | } |
---|
[2] | 2510 | } |
---|
[56] | 2511 | else |
---|
| 2512 | { |
---|
| 2513 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA; |
---|
| 2514 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA; |
---|
| 2515 | |
---|
| 2516 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++) |
---|
| 2517 | { |
---|
| 2518 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2519 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 2520 | } |
---|
| 2521 | |
---|
| 2522 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_CHROMA; ctxIdx++) |
---|
| 2523 | { |
---|
| 2524 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2525 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 2526 | } |
---|
| 2527 | } |
---|
[2] | 2528 | } |
---|
| 2529 | |
---|
[56] | 2530 | /** |
---|
| 2531 | - Initialize our context information from the nominated source. |
---|
| 2532 | . |
---|
| 2533 | \param pSrc From where to copy context information. |
---|
| 2534 | */ |
---|
| 2535 | Void TEncSbac::xCopyContextsFrom( TEncSbac* pSrc ) |
---|
| 2536 | { |
---|
| 2537 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
| 2538 | } |
---|
| 2539 | |
---|
| 2540 | Void TEncSbac::loadContexts ( TEncSbac* pScr) |
---|
[2] | 2541 | { |
---|
[56] | 2542 | this->xCopyContextsFrom(pScr); |
---|
[2] | 2543 | } |
---|
[56] | 2544 | |
---|
[189] | 2545 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX || (LGE_EDGE_INTRA_A0070 && LGE_EDGE_INTRA_DELTA_DC) |
---|
[56] | 2546 | Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel ) |
---|
| 2547 | { |
---|
| 2548 | if( uiSymbol ) |
---|
| 2549 | { |
---|
| 2550 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
| 2551 | UInt uiCount = 0; |
---|
| 2552 | Bool bNoExGo = (uiSymbol < 13); |
---|
| 2553 | |
---|
| 2554 | while( --uiSymbol && ++uiCount < 13 ) |
---|
| 2555 | { |
---|
| 2556 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
| 2557 | } |
---|
| 2558 | if( bNoExGo ) |
---|
| 2559 | { |
---|
| 2560 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
| 2561 | } |
---|
| 2562 | else |
---|
| 2563 | { |
---|
| 2564 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
| 2565 | } |
---|
| 2566 | } |
---|
| 2567 | else |
---|
| 2568 | { |
---|
| 2569 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
| 2570 | } |
---|
| 2571 | |
---|
| 2572 | return; |
---|
| 2573 | } |
---|
| 2574 | #endif |
---|
| 2575 | #if HHI_DMM_WEDGE_INTRA |
---|
| 2576 | Void TEncSbac::xCodeWedgeFullInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2577 | { |
---|
| 2578 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
| 2579 | Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx]; |
---|
| 2580 | |
---|
| 2581 | UInt uiTabIdx = pcCU->getWedgeFullTabIdx( uiAbsPartIdx ); |
---|
| 2582 | |
---|
| 2583 | for ( Int i = 0; i < iBits; i++ ) |
---|
| 2584 | { |
---|
| 2585 | m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cDmmDataSCModel.get(0, 0, 0) ); |
---|
| 2586 | } |
---|
| 2587 | } |
---|
| 2588 | |
---|
| 2589 | Void TEncSbac::xCodeWedgeFullDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2590 | { |
---|
| 2591 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
| 2592 | Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx]; |
---|
| 2593 | |
---|
| 2594 | UInt uiTabIdx = pcCU->getWedgeFullTabIdx( uiAbsPartIdx ); |
---|
| 2595 | |
---|
| 2596 | for ( Int i = 0; i < iBits; i++ ) |
---|
| 2597 | { |
---|
| 2598 | m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cDmmDataSCModel.get(0, 0, 0) ); |
---|
| 2599 | } |
---|
| 2600 | |
---|
| 2601 | Int iDeltaDC1 = pcCU->getWedgeFullDeltaDC1( uiAbsPartIdx ); |
---|
| 2602 | Int iDeltaDC2 = pcCU->getWedgeFullDeltaDC2( uiAbsPartIdx ); |
---|
| 2603 | |
---|
| 2604 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2605 | if ( iDeltaDC1 != 0 ) |
---|
| 2606 | { |
---|
| 2607 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
| 2608 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2609 | } |
---|
| 2610 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2611 | if ( iDeltaDC2 != 0 ) |
---|
| 2612 | { |
---|
| 2613 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
| 2614 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2615 | } |
---|
| 2616 | } |
---|
| 2617 | |
---|
| 2618 | Void TEncSbac::xCodeWedgePredDirInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2619 | { |
---|
| 2620 | if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 ) |
---|
| 2621 | { |
---|
| 2622 | Int iDeltaEnd = pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ); |
---|
| 2623 | m_pcBinIf->encodeBin( (iDeltaEnd!=0), m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
| 2624 | |
---|
| 2625 | if( iDeltaEnd != 0 ) |
---|
| 2626 | { |
---|
| 2627 | UInt uiAbsValMinus1 = abs(iDeltaEnd)-1; |
---|
| 2628 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
| 2629 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
| 2630 | |
---|
| 2631 | UInt uiSign = iDeltaEnd > 0 ? 0 : 1; |
---|
| 2632 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2633 | } |
---|
| 2634 | } |
---|
| 2635 | } |
---|
| 2636 | |
---|
| 2637 | Void TEncSbac::xCodeWedgePredDirDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2638 | { |
---|
| 2639 | if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 ) |
---|
| 2640 | { |
---|
| 2641 | Int iDeltaEnd = pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ); |
---|
| 2642 | m_pcBinIf->encodeBin( (iDeltaEnd!=0), m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
| 2643 | |
---|
| 2644 | if( iDeltaEnd != 0 ) |
---|
| 2645 | { |
---|
| 2646 | UInt uiAbsValMinus1 = abs(iDeltaEnd)-1; |
---|
| 2647 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
| 2648 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
| 2649 | |
---|
| 2650 | UInt uiSign = iDeltaEnd > 0 ? 0 : 1; |
---|
| 2651 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2652 | } |
---|
| 2653 | } |
---|
| 2654 | |
---|
| 2655 | Int iDeltaDC1 = pcCU->getWedgePredDirDeltaDC1( uiAbsPartIdx ); |
---|
| 2656 | Int iDeltaDC2 = pcCU->getWedgePredDirDeltaDC2( uiAbsPartIdx ); |
---|
| 2657 | |
---|
| 2658 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2659 | if ( iDeltaDC1 != 0 ) |
---|
| 2660 | { |
---|
| 2661 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
| 2662 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2663 | } |
---|
| 2664 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2665 | if ( iDeltaDC2 != 0 ) |
---|
| 2666 | { |
---|
| 2667 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
| 2668 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2669 | } |
---|
| 2670 | } |
---|
| 2671 | #endif |
---|
| 2672 | #if HHI_DMM_PRED_TEX |
---|
| 2673 | Void TEncSbac::xCodeWedgePredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2674 | { |
---|
| 2675 | Int iDeltaDC1 = pcCU->getWedgePredTexDeltaDC1( uiAbsPartIdx ); |
---|
| 2676 | Int iDeltaDC2 = pcCU->getWedgePredTexDeltaDC2( uiAbsPartIdx ); |
---|
| 2677 | |
---|
| 2678 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2679 | if ( iDeltaDC1 != 0 ) |
---|
| 2680 | { |
---|
| 2681 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
| 2682 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2683 | } |
---|
| 2684 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2685 | if ( iDeltaDC2 != 0 ) |
---|
| 2686 | { |
---|
| 2687 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
| 2688 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2689 | } |
---|
| 2690 | } |
---|
| 2691 | |
---|
| 2692 | Void TEncSbac::xCodeContourPredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2693 | { |
---|
| 2694 | Int iDeltaDC1 = pcCU->getContourPredTexDeltaDC1( uiAbsPartIdx ); |
---|
| 2695 | Int iDeltaDC2 = pcCU->getContourPredTexDeltaDC2( uiAbsPartIdx ); |
---|
| 2696 | |
---|
| 2697 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2698 | if ( iDeltaDC1 != 0 ) |
---|
| 2699 | { |
---|
| 2700 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
| 2701 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2702 | } |
---|
| 2703 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
| 2704 | if ( iDeltaDC2 != 0 ) |
---|
| 2705 | { |
---|
| 2706 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
| 2707 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 2708 | } |
---|
| 2709 | } |
---|
| 2710 | #endif |
---|
[189] | 2711 | |
---|
| 2712 | #if RWTH_SDC_DLT_B0036 |
---|
| 2713 | Void TEncSbac::codeSDCPredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2714 | { |
---|
| 2715 | assert( pcCU->getSlice()->getSPS()->isDepth() ); |
---|
| 2716 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
| 2717 | assert( pcCU->getSDCFlag(uiAbsPartIdx) ); |
---|
| 2718 | |
---|
| 2719 | UInt uiPredMode = pcCU->getLumaIntraDir(uiAbsPartIdx); |
---|
| 2720 | UInt uiCtx = 0; |
---|
| 2721 | |
---|
| 2722 | UInt uiMPModeIdx = 0; |
---|
| 2723 | |
---|
| 2724 | for(Int i=0; i<RWTH_SDC_NUM_PRED_MODES-1; i++) |
---|
| 2725 | { |
---|
| 2726 | UInt uiBit = (uiPredMode == g_auiSDCPredModes[uiMPModeIdx]) ? 1 : 0; |
---|
| 2727 | m_pcBinIf->encodeBin( uiBit, m_cSDCPredModeSCModel.get( 0, i, uiCtx ) ); |
---|
| 2728 | |
---|
| 2729 | // if mode is most probable mode, we are done here |
---|
| 2730 | if ( uiBit == 1 ) |
---|
| 2731 | break; |
---|
| 2732 | |
---|
| 2733 | // else: get next most probable pred mode |
---|
| 2734 | uiMPModeIdx = (uiMPModeIdx+1)%RWTH_SDC_NUM_PRED_MODES; |
---|
| 2735 | } |
---|
| 2736 | |
---|
| 2737 | #if HHI_DMM_WEDGE_INTRA |
---|
| 2738 | if( uiPredMode == DMM_WEDGE_FULL_IDX ) { xCodeWedgeFullInfo ( pcCU, uiAbsPartIdx ); } |
---|
| 2739 | if( uiPredMode == DMM_WEDGE_PREDDIR_IDX ) { xCodeWedgePredDirInfo ( pcCU, uiAbsPartIdx ); } |
---|
| 2740 | #endif |
---|
| 2741 | |
---|
| 2742 | AOF(uiPredMode == g_auiSDCPredModes[uiMPModeIdx]); |
---|
| 2743 | } |
---|
| 2744 | |
---|
| 2745 | Void TEncSbac::codeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2746 | { |
---|
| 2747 | // get context function is here |
---|
| 2748 | UInt uiSymbol = pcCU->getSDCFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 2749 | UInt uiCtxSDCFlag = pcCU->getCtxSDCFlag( uiAbsPartIdx ); |
---|
| 2750 | m_pcBinIf->encodeBin( uiSymbol, m_cSDCFlagSCModel.get( 0, 0, uiCtxSDCFlag ) ); |
---|
| 2751 | |
---|
| 2752 | } |
---|
| 2753 | |
---|
| 2754 | Void TEncSbac::codeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ) |
---|
| 2755 | { |
---|
| 2756 | assert( pcCU->getSlice()->getSPS()->isDepth() ); |
---|
| 2757 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
| 2758 | assert( pcCU->getSDCFlag(uiAbsPartIdx) ); |
---|
| 2759 | assert( uiSegment < 2 ); |
---|
| 2760 | |
---|
| 2761 | Pel segmentDCOffset = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx); |
---|
| 2762 | |
---|
| 2763 | UInt uiResidual = segmentDCOffset == 0 ? 0 : 1; |
---|
| 2764 | UInt uiSign = segmentDCOffset < 0 ? 1 : 0; |
---|
| 2765 | UInt uiAbsIdx = abs(segmentDCOffset); |
---|
| 2766 | UInt uiBit = 0; |
---|
| 2767 | |
---|
| 2768 | UInt uiMaxResidualBits = GetBitsPerDepthValue(); |
---|
| 2769 | assert( uiMaxResidualBits <= g_uiBitDepth ); |
---|
| 2770 | |
---|
| 2771 | // residual flag |
---|
| 2772 | m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, uiSegment, 0 ) ); //TODO depthmap: more sophisticated context selection |
---|
| 2773 | |
---|
| 2774 | if (uiResidual) |
---|
| 2775 | { |
---|
| 2776 | // encode sign bit of residual |
---|
| 2777 | m_pcBinIf->encodeBin( uiSign, m_cSDCResidualSignFlagSCModel.get( 0, uiSegment, 0 ) ); //TODO depthmap: more sophisticated context selection |
---|
| 2778 | |
---|
| 2779 | assert(uiAbsIdx < GetNumDepthValues()); |
---|
| 2780 | |
---|
| 2781 | // encode residual magnitude |
---|
| 2782 | uiAbsIdx -= 1; |
---|
| 2783 | for (Int i=0; i<uiMaxResidualBits; i++) |
---|
| 2784 | { |
---|
| 2785 | uiBit = (uiAbsIdx & (1<<i))>>i; |
---|
| 2786 | |
---|
| 2787 | m_pcBinIf->encodeBin( uiBit, m_cSDCResidualSCModel.get( 0, uiSegment, i ) ); //TODO depthmap: more sophisticated context selection |
---|
| 2788 | } |
---|
| 2789 | |
---|
| 2790 | } |
---|
| 2791 | } |
---|
| 2792 | #endif |
---|
[56] | 2793 | //! \} |
---|