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