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