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