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