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