[313] | 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 |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
| 6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
| 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. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 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 | */ |
---|
| 33 | |
---|
| 34 | /** \file TEncSbac.cpp |
---|
| 35 | \brief SBAC encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TEncTop.h" |
---|
| 39 | #include "TEncSbac.h" |
---|
| 40 | |
---|
| 41 | #include <map> |
---|
| 42 | #include <algorithm> |
---|
| 43 | |
---|
| 44 | //! \ingroup TLibEncoder |
---|
| 45 | //! \{ |
---|
| 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_uiCoeffCost ( 0 ) |
---|
| 57 | , m_numContextModels ( 0 ) |
---|
| 58 | , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels ) |
---|
| 59 | , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 60 | , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 61 | , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 62 | , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 63 | , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 64 | , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 65 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 66 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 67 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 68 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 69 | , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 70 | , m_cCUQtCbfSCModel ( 1, 2, NUM_QT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 71 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 72 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 73 | , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 74 | , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 75 | , m_cCuCtxLastX ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 76 | , m_cCuCtxLastY ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 77 | , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 78 | , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 79 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 80 | , m_cCUAMPSCModel ( 1, 1, NUM_CU_AMP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 81 | , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 82 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 83 | , m_cTransformSkipSCModel ( 1, 2, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 84 | , m_CUTransquantBypassFlagSCModel( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 85 | { |
---|
| 86 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | TEncSbac::~TEncSbac() |
---|
| 90 | { |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | // ==================================================================================================================== |
---|
| 94 | // Public member functions |
---|
| 95 | // ==================================================================================================================== |
---|
| 96 | |
---|
| 97 | Void TEncSbac::resetEntropy () |
---|
| 98 | { |
---|
| 99 | Int iQp = m_pcSlice->getSliceQp(); |
---|
| 100 | SliceType eSliceType = m_pcSlice->getSliceType(); |
---|
| 101 | |
---|
| 102 | Int encCABACTableIdx = m_pcSlice->getPPS()->getEncCABACTableIdx(); |
---|
| 103 | if (!m_pcSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && m_pcSlice->getPPS()->getCabacInitPresentFlag()) |
---|
| 104 | { |
---|
| 105 | eSliceType = (SliceType) encCABACTableIdx; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
| 109 | |
---|
| 110 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
| 111 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
| 112 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
| 113 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
| 114 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
| 115 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
| 116 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
| 117 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
| 118 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
| 119 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
| 120 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
| 121 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
| 122 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
| 123 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
| 124 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
| 125 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
| 126 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 127 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 128 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
| 129 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
| 130 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
| 131 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
| 132 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
| 133 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
| 134 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
| 135 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
| 136 | // new structure |
---|
| 137 | m_uiLastQp = iQp; |
---|
| 138 | |
---|
| 139 | m_pcBinIf->start(); |
---|
| 140 | |
---|
| 141 | return; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | /** The function does the following: |
---|
| 145 | * If current slice type is P/B then it determines the distance of initialisation type 1 and 2 from the current CABAC states and |
---|
| 146 | * stores the index of the closest table. This index is used for the next P/B slice when cabac_init_present_flag is true. |
---|
| 147 | */ |
---|
| 148 | Void TEncSbac::determineCabacInitIdx() |
---|
| 149 | { |
---|
| 150 | Int qp = m_pcSlice->getSliceQp(); |
---|
| 151 | |
---|
| 152 | if (!m_pcSlice->isIntra()) |
---|
| 153 | { |
---|
| 154 | SliceType aSliceTypeChoices[] = {B_SLICE, P_SLICE}; |
---|
| 155 | |
---|
| 156 | UInt bestCost = MAX_UINT; |
---|
| 157 | SliceType bestSliceType = aSliceTypeChoices[0]; |
---|
| 158 | for (UInt idx=0; idx<2; idx++) |
---|
| 159 | { |
---|
| 160 | UInt curCost = 0; |
---|
| 161 | SliceType curSliceType = aSliceTypeChoices[idx]; |
---|
| 162 | |
---|
| 163 | curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
| 164 | curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
| 165 | curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
| 166 | curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
| 167 | curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); |
---|
| 168 | curCost += m_cCUAMPSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_AMP_POS ); |
---|
| 169 | curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); |
---|
| 170 | curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
| 171 | curCost += m_cCUChromaPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
| 172 | curCost += m_cCUInterDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTER_DIR ); |
---|
| 173 | curCost += m_cCUMvdSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVD ); |
---|
| 174 | curCost += m_cCURefPicSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_REF_PIC ); |
---|
| 175 | curCost += m_cCUDeltaQpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DQP ); |
---|
| 176 | curCost += m_cCUQtCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_CBF ); |
---|
| 177 | curCost += m_cCUQtRootCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
| 178 | curCost += m_cCUSigCoeffGroupSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
| 179 | curCost += m_cCUSigSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_FLAG ); |
---|
| 180 | curCost += m_cCuCtxLastX.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
| 181 | curCost += m_cCuCtxLastY.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
| 182 | curCost += m_cCUOneSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ONE_FLAG ); |
---|
| 183 | curCost += m_cCUAbsSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ABS_FLAG ); |
---|
| 184 | curCost += m_cMVPIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVP_IDX ); |
---|
| 185 | curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
| 186 | curCost += m_cSaoMergeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
| 187 | curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
| 188 | curCost += m_cTransformSkipSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
| 189 | curCost += m_CUTransquantBypassFlagSCModel.calcCost( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
| 190 | if (curCost < bestCost) |
---|
| 191 | { |
---|
| 192 | bestSliceType = curSliceType; |
---|
| 193 | bestCost = curCost; |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | m_pcSlice->getPPS()->setEncCABACTableIdx( bestSliceType ); |
---|
| 197 | } |
---|
| 198 | else |
---|
| 199 | { |
---|
| 200 | m_pcSlice->getPPS()->setEncCABACTableIdx( I_SLICE ); |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | /** The function does the followng: Write out terminate bit. Flush CABAC. Intialize CABAC states. Start CABAC. |
---|
| 206 | */ |
---|
| 207 | Void TEncSbac::updateContextTables( SliceType eSliceType, Int iQp, Bool bExecuteFinish ) |
---|
| 208 | { |
---|
| 209 | m_pcBinIf->encodeBinTrm(1); |
---|
| 210 | if (bExecuteFinish) m_pcBinIf->finish(); |
---|
| 211 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
| 212 | |
---|
| 213 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
| 214 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
| 215 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
| 216 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
| 217 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
| 218 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
| 219 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
| 220 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
| 221 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
| 222 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
| 223 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
| 224 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
| 225 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
| 226 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
| 227 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
| 228 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
| 229 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 230 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 231 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
| 232 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
| 233 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
| 234 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
| 235 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
| 236 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
| 237 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
| 238 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
| 239 | m_pcBinIf->start(); |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | Void TEncSbac::codeVPS( TComVPS* pcVPS ) |
---|
| 243 | { |
---|
| 244 | assert (0); |
---|
| 245 | return; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | Void TEncSbac::codeSPS( TComSPS* pcSPS ) |
---|
| 249 | { |
---|
| 250 | assert (0); |
---|
| 251 | return; |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | Void TEncSbac::codePPS( TComPPS* pcPPS ) |
---|
| 255 | { |
---|
| 256 | assert (0); |
---|
| 257 | return; |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | Void TEncSbac::codeSliceHeader( TComSlice* pcSlice ) |
---|
| 261 | { |
---|
| 262 | assert (0); |
---|
| 263 | return; |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | Void TEncSbac::codeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
| 267 | { |
---|
| 268 | assert (0); |
---|
| 269 | return; |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | Void TEncSbac::codeTerminatingBit( UInt uilsLast ) |
---|
| 273 | { |
---|
| 274 | m_pcBinIf->encodeBinTrm( uilsLast ); |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | Void TEncSbac::codeSliceFinish() |
---|
| 278 | { |
---|
| 279 | m_pcBinIf->finish(); |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
| 283 | { |
---|
| 284 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] ); |
---|
| 285 | |
---|
| 286 | if( 0 == uiSymbol) |
---|
| 287 | { |
---|
| 288 | return; |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | while( uiSymbol-- ) |
---|
| 292 | { |
---|
| 293 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] ); |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | return; |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
| 300 | { |
---|
| 301 | if (uiMaxSymbol == 0) |
---|
| 302 | { |
---|
| 303 | return; |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] ); |
---|
| 307 | |
---|
| 308 | if ( uiSymbol == 0 ) |
---|
| 309 | { |
---|
| 310 | return; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
| 314 | |
---|
| 315 | while( --uiSymbol ) |
---|
| 316 | { |
---|
| 317 | m_pcBinIf->encodeBin( 1, pcSCModel[ iOffset ] ); |
---|
| 318 | } |
---|
| 319 | if( bCodeLast ) |
---|
| 320 | { |
---|
| 321 | m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] ); |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | return; |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | Void TEncSbac::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
| 328 | { |
---|
| 329 | UInt bins = 0; |
---|
| 330 | Int numBins = 0; |
---|
| 331 | |
---|
| 332 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
| 333 | { |
---|
| 334 | bins = 2 * bins + 1; |
---|
| 335 | numBins++; |
---|
| 336 | uiSymbol -= 1 << uiCount; |
---|
| 337 | uiCount ++; |
---|
| 338 | } |
---|
| 339 | bins = 2 * bins + 0; |
---|
| 340 | numBins++; |
---|
| 341 | |
---|
| 342 | bins = (bins << uiCount) | uiSymbol; |
---|
| 343 | numBins += uiCount; |
---|
| 344 | |
---|
| 345 | assert( numBins <= 32 ); |
---|
| 346 | m_pcBinIf->encodeBinsEP( bins, numBins ); |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | /** Coding of coeff_abs_level_minus3 |
---|
| 350 | * \param uiSymbol value of coeff_abs_level_minus3 |
---|
| 351 | * \param ruiGoRiceParam reference to Rice parameter |
---|
| 352 | * \returns Void |
---|
| 353 | */ |
---|
| 354 | Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam ) |
---|
| 355 | { |
---|
| 356 | Int codeNumber = (Int)symbol; |
---|
| 357 | UInt length; |
---|
| 358 | if (codeNumber < (COEF_REMAIN_BIN_REDUCTION << rParam)) |
---|
| 359 | { |
---|
| 360 | length = codeNumber>>rParam; |
---|
| 361 | m_pcBinIf->encodeBinsEP( (1<<(length+1))-2 , length+1); |
---|
| 362 | m_pcBinIf->encodeBinsEP((codeNumber%(1<<rParam)),rParam); |
---|
| 363 | } |
---|
| 364 | else |
---|
| 365 | { |
---|
| 366 | length = rParam; |
---|
| 367 | codeNumber = codeNumber - ( COEF_REMAIN_BIN_REDUCTION << rParam); |
---|
| 368 | while (codeNumber >= (1<<length)) |
---|
| 369 | { |
---|
| 370 | codeNumber -= (1<<(length++)); |
---|
| 371 | } |
---|
| 372 | m_pcBinIf->encodeBinsEP((1<<(COEF_REMAIN_BIN_REDUCTION+length+1-rParam))-2,COEF_REMAIN_BIN_REDUCTION+length+1-rParam); |
---|
| 373 | m_pcBinIf->encodeBinsEP(codeNumber,length); |
---|
| 374 | } |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | // SBAC RD |
---|
| 378 | Void TEncSbac::load ( TEncSbac* pSrc) |
---|
| 379 | { |
---|
| 380 | this->xCopyFrom(pSrc); |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | Void TEncSbac::loadIntraDirModeLuma( TEncSbac* pSrc) |
---|
| 384 | { |
---|
| 385 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
| 386 | |
---|
| 387 | this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | |
---|
| 391 | Void TEncSbac::store( TEncSbac* pDest) |
---|
| 392 | { |
---|
| 393 | pDest->xCopyFrom( this ); |
---|
| 394 | } |
---|
| 395 | |
---|
| 396 | |
---|
| 397 | Void TEncSbac::xCopyFrom( TEncSbac* pSrc ) |
---|
| 398 | { |
---|
| 399 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
| 400 | |
---|
| 401 | this->m_uiCoeffCost = pSrc->m_uiCoeffCost; |
---|
| 402 | this->m_uiLastQp = pSrc->m_uiLastQp; |
---|
| 403 | |
---|
| 404 | memcpy( m_contextModels, pSrc->m_contextModels, m_numContextModels * sizeof( ContextModel ) ); |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 408 | { |
---|
| 409 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
| 410 | Int iNum = AMVP_MAX_NUM_CANDS; |
---|
| 411 | |
---|
| 412 | xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1); |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 416 | { |
---|
| 417 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
[321] | 418 | |
---|
[313] | 419 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 420 | { |
---|
| 421 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 422 | { |
---|
| 423 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
| 424 | } |
---|
| 425 | return; |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | switch(eSize) |
---|
| 429 | { |
---|
| 430 | case SIZE_2Nx2N: |
---|
| 431 | { |
---|
| 432 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 433 | break; |
---|
| 434 | } |
---|
| 435 | case SIZE_2NxN: |
---|
| 436 | case SIZE_2NxnU: |
---|
| 437 | case SIZE_2NxnD: |
---|
| 438 | { |
---|
| 439 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 440 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
| 441 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
| 442 | { |
---|
| 443 | if (eSize == SIZE_2NxN) |
---|
| 444 | { |
---|
| 445 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 446 | } |
---|
| 447 | else |
---|
| 448 | { |
---|
| 449 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 450 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | break; |
---|
| 454 | } |
---|
| 455 | case SIZE_Nx2N: |
---|
| 456 | case SIZE_nLx2N: |
---|
| 457 | case SIZE_nRx2N: |
---|
| 458 | { |
---|
| 459 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 460 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
| 461 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
| 462 | { |
---|
| 463 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
| 464 | } |
---|
| 465 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
| 466 | { |
---|
| 467 | if (eSize == SIZE_Nx2N) |
---|
| 468 | { |
---|
| 469 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 470 | } |
---|
| 471 | else |
---|
| 472 | { |
---|
| 473 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 474 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
| 475 | } |
---|
| 476 | } |
---|
| 477 | break; |
---|
| 478 | } |
---|
| 479 | case SIZE_NxN: |
---|
| 480 | { |
---|
| 481 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
| 482 | { |
---|
| 483 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 484 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
| 485 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
| 486 | } |
---|
| 487 | break; |
---|
| 488 | } |
---|
| 489 | default: |
---|
| 490 | { |
---|
| 491 | assert(0); |
---|
| 492 | } |
---|
| 493 | } |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | /** code prediction mode |
---|
| 497 | * \param pcCU |
---|
| 498 | * \param uiAbsPartIdx |
---|
| 499 | * \returns Void |
---|
| 500 | */ |
---|
| 501 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 502 | { |
---|
| 503 | // get context function is here |
---|
| 504 | Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); |
---|
| 505 | m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
| 506 | } |
---|
| 507 | |
---|
| 508 | Void TEncSbac::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 509 | { |
---|
| 510 | UInt uiSymbol = pcCU->getCUTransquantBypass(uiAbsPartIdx); |
---|
| 511 | m_pcBinIf->encodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | /** code skip flag |
---|
| 515 | * \param pcCU |
---|
| 516 | * \param uiAbsPartIdx |
---|
| 517 | * \returns Void |
---|
| 518 | */ |
---|
| 519 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 520 | { |
---|
| 521 | // get context function is here |
---|
| 522 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
| 523 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
| 524 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
| 525 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 526 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
| 527 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
| 528 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
| 529 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 530 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 531 | DTRACE_CABAC_T( "\n"); |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | /** code merge flag |
---|
| 535 | * \param pcCU |
---|
| 536 | * \param uiAbsPartIdx |
---|
| 537 | * \returns Void |
---|
| 538 | */ |
---|
| 539 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 540 | { |
---|
| 541 | const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 542 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
| 543 | |
---|
| 544 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 545 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
| 546 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 547 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
| 548 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
| 549 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
| 550 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 551 | DTRACE_CABAC_T( "\n" ); |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | /** code merge index |
---|
| 555 | * \param pcCU |
---|
| 556 | * \param uiAbsPartIdx |
---|
| 557 | * \returns Void |
---|
| 558 | */ |
---|
| 559 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 560 | { |
---|
| 561 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
| 562 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
| 563 | if ( uiNumCand > 1 ) |
---|
| 564 | { |
---|
| 565 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
| 566 | { |
---|
| 567 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
| 568 | if ( ui==0 ) |
---|
| 569 | { |
---|
| 570 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
| 571 | } |
---|
| 572 | else |
---|
| 573 | { |
---|
| 574 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
| 575 | } |
---|
| 576 | if( uiSymbol == 0 ) |
---|
| 577 | { |
---|
| 578 | break; |
---|
| 579 | } |
---|
| 580 | } |
---|
| 581 | } |
---|
| 582 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 583 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
| 584 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
| 585 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
| 586 | DTRACE_CABAC_T( "\n" ); |
---|
| 587 | } |
---|
| 588 | |
---|
| 589 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 590 | { |
---|
| 591 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 592 | return; |
---|
| 593 | |
---|
| 594 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
| 595 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
| 596 | |
---|
| 597 | assert( uiCtx < 3 ); |
---|
| 598 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
| 599 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 600 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
| 601 | return; |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
| 605 | { |
---|
| 606 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
| 607 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 608 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
| 609 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 610 | DTRACE_CABAC_V( uiSymbol ) |
---|
| 611 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 612 | DTRACE_CABAC_V( uiCtx ) |
---|
| 613 | DTRACE_CABAC_T( "\n" ) |
---|
| 614 | } |
---|
| 615 | |
---|
| 616 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple) |
---|
| 617 | { |
---|
| 618 | UInt dir[4],j; |
---|
| 619 | Int preds[4][3] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}}; |
---|
| 620 | Int predNum[4], predIdx[4] ={ -1,-1,-1,-1}; |
---|
| 621 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
| 622 | UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1; |
---|
| 623 | UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
| 624 | for (j=0;j<partNum;j++) |
---|
| 625 | { |
---|
| 626 | dir[j] = pcCU->getLumaIntraDir( absPartIdx+partOffset*j ); |
---|
| 627 | predNum[j] = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds[j]); |
---|
| 628 | for(UInt i = 0; i < predNum[j]; i++) |
---|
| 629 | { |
---|
| 630 | if(dir[j] == preds[j][i]) |
---|
| 631 | { |
---|
| 632 | predIdx[j] = i; |
---|
| 633 | } |
---|
| 634 | } |
---|
| 635 | m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
| 636 | } |
---|
| 637 | for (j=0;j<partNum;j++) |
---|
| 638 | { |
---|
| 639 | if(predIdx[j] != -1) |
---|
| 640 | { |
---|
| 641 | m_pcBinIf->encodeBinEP( predIdx[j] ? 1 : 0 ); |
---|
| 642 | if (predIdx[j]) |
---|
| 643 | { |
---|
| 644 | m_pcBinIf->encodeBinEP( predIdx[j]-1 ); |
---|
| 645 | } |
---|
| 646 | } |
---|
| 647 | else |
---|
| 648 | { |
---|
| 649 | if (preds[j][0] > preds[j][1]) |
---|
| 650 | { |
---|
| 651 | std::swap(preds[j][0], preds[j][1]); |
---|
| 652 | } |
---|
| 653 | if (preds[j][0] > preds[j][2]) |
---|
| 654 | { |
---|
| 655 | std::swap(preds[j][0], preds[j][2]); |
---|
| 656 | } |
---|
| 657 | if (preds[j][1] > preds[j][2]) |
---|
| 658 | { |
---|
| 659 | std::swap(preds[j][1], preds[j][2]); |
---|
| 660 | } |
---|
| 661 | for(Int i = (predNum[j] - 1); i >= 0; i--) |
---|
| 662 | { |
---|
| 663 | dir[j] = dir[j] > preds[j][i] ? dir[j] - 1 : dir[j]; |
---|
| 664 | } |
---|
| 665 | m_pcBinIf->encodeBinsEP( dir[j], 5 ); |
---|
| 666 | } |
---|
| 667 | } |
---|
| 668 | return; |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 672 | { |
---|
| 673 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx ); |
---|
| 674 | |
---|
| 675 | if( uiIntraDirChroma == DM_CHROMA_IDX ) |
---|
| 676 | { |
---|
| 677 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
| 678 | } |
---|
| 679 | else |
---|
| 680 | { |
---|
| 681 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
| 682 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
| 683 | |
---|
| 684 | for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ ) |
---|
| 685 | { |
---|
| 686 | if( uiIntraDirChroma == uiAllowedChromaDir[i] ) |
---|
| 687 | { |
---|
| 688 | uiIntraDirChroma = i; |
---|
| 689 | break; |
---|
| 690 | } |
---|
| 691 | } |
---|
| 692 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
| 693 | |
---|
| 694 | m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); |
---|
| 695 | } |
---|
| 696 | return; |
---|
| 697 | } |
---|
| 698 | |
---|
| 699 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 700 | { |
---|
| 701 | const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1; |
---|
| 702 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
| 703 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
| 704 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
| 705 | { |
---|
| 706 | m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); |
---|
| 707 | } |
---|
| 708 | if (uiInterDir < 2) |
---|
| 709 | { |
---|
| 710 | m_pcBinIf->encodeBin( uiInterDir, *( pCtx + 4 ) ); |
---|
| 711 | } |
---|
| 712 | return; |
---|
| 713 | } |
---|
| 714 | |
---|
| 715 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 716 | { |
---|
| 717 | { |
---|
| 718 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
| 719 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
| 720 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
| 721 | |
---|
| 722 | if( iRefFrame > 0 ) |
---|
| 723 | { |
---|
| 724 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
| 725 | pCtx++; |
---|
| 726 | iRefFrame--; |
---|
| 727 | for( UInt ui = 0; ui < uiRefNum; ++ui ) |
---|
| 728 | { |
---|
| 729 | const UInt uiSymbol = ui == iRefFrame ? 0 : 1; |
---|
| 730 | if( ui == 0 ) |
---|
| 731 | { |
---|
| 732 | m_pcBinIf->encodeBin( uiSymbol, *pCtx ); |
---|
| 733 | } |
---|
| 734 | else |
---|
| 735 | { |
---|
| 736 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
| 737 | } |
---|
| 738 | if( uiSymbol == 0 ) |
---|
| 739 | { |
---|
| 740 | break; |
---|
| 741 | } |
---|
| 742 | } |
---|
| 743 | } |
---|
| 744 | } |
---|
| 745 | return; |
---|
| 746 | } |
---|
| 747 | |
---|
| 748 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 749 | { |
---|
| 750 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
| 751 | { |
---|
| 752 | return; |
---|
| 753 | } |
---|
| 754 | |
---|
| 755 | const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
| 756 | const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
| 757 | const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
| 758 | ContextModel* pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
| 759 | |
---|
| 760 | m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx ); |
---|
| 761 | m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx ); |
---|
| 762 | |
---|
| 763 | const Bool bHorAbsGr0 = iHor != 0; |
---|
| 764 | const Bool bVerAbsGr0 = iVer != 0; |
---|
| 765 | const UInt uiHorAbs = 0 > iHor ? -iHor : iHor; |
---|
| 766 | const UInt uiVerAbs = 0 > iVer ? -iVer : iVer; |
---|
| 767 | pCtx++; |
---|
| 768 | |
---|
| 769 | if( bHorAbsGr0 ) |
---|
| 770 | { |
---|
| 771 | m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx ); |
---|
| 772 | } |
---|
| 773 | |
---|
| 774 | if( bVerAbsGr0 ) |
---|
| 775 | { |
---|
| 776 | m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx ); |
---|
| 777 | } |
---|
| 778 | |
---|
| 779 | if( bHorAbsGr0 ) |
---|
| 780 | { |
---|
| 781 | if( uiHorAbs > 1 ) |
---|
| 782 | { |
---|
| 783 | xWriteEpExGolomb( uiHorAbs-2, 1 ); |
---|
| 784 | } |
---|
| 785 | |
---|
| 786 | m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 ); |
---|
| 787 | } |
---|
| 788 | |
---|
| 789 | if( bVerAbsGr0 ) |
---|
| 790 | { |
---|
| 791 | if( uiVerAbs > 1 ) |
---|
| 792 | { |
---|
| 793 | xWriteEpExGolomb( uiVerAbs-2, 1 ); |
---|
| 794 | } |
---|
| 795 | |
---|
| 796 | m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); |
---|
| 797 | } |
---|
| 798 | |
---|
| 799 | return; |
---|
| 800 | } |
---|
| 801 | |
---|
| 802 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 803 | { |
---|
| 804 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
| 805 | |
---|
| 806 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
| 807 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
| 808 | |
---|
| 809 | UInt uiAbsDQp = (UInt)((iDQp > 0)? iDQp : (-iDQp)); |
---|
| 810 | UInt TUValue = min((Int)uiAbsDQp, CU_DQP_TU_CMAX); |
---|
| 811 | xWriteUnaryMaxSymbol( TUValue, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
| 812 | if( uiAbsDQp >= CU_DQP_TU_CMAX ) |
---|
| 813 | { |
---|
| 814 | xWriteEpExGolomb( uiAbsDQp - CU_DQP_TU_CMAX, CU_DQP_EG_k ); |
---|
| 815 | } |
---|
| 816 | |
---|
| 817 | if ( uiAbsDQp > 0) |
---|
| 818 | { |
---|
| 819 | UInt uiSign = (iDQp > 0 ? 0 : 1); |
---|
| 820 | m_pcBinIf->encodeBinEP(uiSign); |
---|
| 821 | } |
---|
| 822 | |
---|
| 823 | return; |
---|
| 824 | } |
---|
| 825 | |
---|
| 826 | Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
| 827 | { |
---|
| 828 | UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
| 829 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
| 830 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
| 831 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 832 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
| 833 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 834 | DTRACE_CABAC_V( uiCbf ) |
---|
| 835 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 836 | DTRACE_CABAC_V( uiCtx ) |
---|
| 837 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 838 | DTRACE_CABAC_V( eType ) |
---|
| 839 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 840 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 841 | DTRACE_CABAC_T( "\n" ) |
---|
| 842 | } |
---|
| 843 | |
---|
| 844 | void TEncSbac::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) |
---|
| 845 | { |
---|
| 846 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
| 847 | { |
---|
| 848 | return; |
---|
| 849 | } |
---|
| 850 | if(width != 4 || height != 4) |
---|
| 851 | { |
---|
| 852 | return; |
---|
| 853 | } |
---|
| 854 | |
---|
| 855 | UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,eTType); |
---|
| 856 | m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) ); |
---|
| 857 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 858 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
| 859 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 860 | DTRACE_CABAC_V( useTransformSkip ) |
---|
| 861 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
| 862 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
| 863 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 864 | DTRACE_CABAC_V( eTType ) |
---|
| 865 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 866 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 867 | DTRACE_CABAC_T( "\n" ) |
---|
| 868 | } |
---|
| 869 | |
---|
| 870 | /** Code I_PCM information. |
---|
| 871 | * \param pcCU pointer to CU |
---|
| 872 | * \param uiAbsPartIdx CU index |
---|
| 873 | * \returns Void |
---|
| 874 | */ |
---|
| 875 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 876 | { |
---|
| 877 | UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0; |
---|
| 878 | |
---|
| 879 | Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx); |
---|
| 880 | |
---|
| 881 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
| 882 | |
---|
| 883 | if (writePCMSampleFlag) |
---|
| 884 | { |
---|
| 885 | m_pcBinIf->encodePCMAlignBits(); |
---|
| 886 | |
---|
| 887 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
| 888 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
| 889 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
| 890 | Pel* piPCMSample; |
---|
| 891 | UInt uiWidth; |
---|
| 892 | UInt uiHeight; |
---|
| 893 | UInt uiSampleBits; |
---|
| 894 | UInt uiX, uiY; |
---|
| 895 | |
---|
| 896 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
| 897 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
| 898 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
| 899 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
| 900 | |
---|
| 901 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 902 | { |
---|
| 903 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 904 | { |
---|
| 905 | UInt uiSample = piPCMSample[uiX]; |
---|
| 906 | |
---|
| 907 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
| 908 | } |
---|
| 909 | piPCMSample += uiWidth; |
---|
| 910 | } |
---|
| 911 | |
---|
| 912 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
| 913 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
| 914 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
| 915 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
| 916 | |
---|
| 917 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 918 | { |
---|
| 919 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 920 | { |
---|
| 921 | UInt uiSample = piPCMSample[uiX]; |
---|
| 922 | |
---|
| 923 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
| 924 | } |
---|
| 925 | piPCMSample += uiWidth; |
---|
| 926 | } |
---|
| 927 | |
---|
| 928 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
| 929 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
| 930 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
| 931 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
| 932 | |
---|
| 933 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 934 | { |
---|
| 935 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 936 | { |
---|
| 937 | UInt uiSample = piPCMSample[uiX]; |
---|
| 938 | |
---|
| 939 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
| 940 | } |
---|
| 941 | piPCMSample += uiWidth; |
---|
| 942 | } |
---|
| 943 | m_pcBinIf->resetBac(); |
---|
| 944 | } |
---|
| 945 | } |
---|
| 946 | |
---|
| 947 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 948 | { |
---|
| 949 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
| 950 | UInt uiCtx = 0; |
---|
| 951 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
| 952 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 953 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
| 954 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 955 | DTRACE_CABAC_V( uiCbf ) |
---|
| 956 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 957 | DTRACE_CABAC_V( uiCtx ) |
---|
| 958 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 959 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 960 | DTRACE_CABAC_T( "\n" ) |
---|
| 961 | } |
---|
| 962 | |
---|
| 963 | Void TEncSbac::codeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
---|
| 964 | { |
---|
| 965 | // this function is only used to estimate the bits when cbf is 0 |
---|
| 966 | // and will never be called when writing the bistream. do not need to write log |
---|
| 967 | UInt uiCbf = 0; |
---|
| 968 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
| 969 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
| 970 | } |
---|
| 971 | |
---|
| 972 | Void TEncSbac::codeQtRootCbfZero( TComDataCU* pcCU ) |
---|
| 973 | { |
---|
| 974 | // this function is only used to estimate the bits when cbf is 0 |
---|
| 975 | // and will never be called when writing the bistream. do not need to write log |
---|
| 976 | UInt uiCbf = 0; |
---|
| 977 | UInt uiCtx = 0; |
---|
| 978 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
| 979 | } |
---|
| 980 | |
---|
| 981 | /** Encode (X,Y) position of the last significant coefficient |
---|
| 982 | * \param uiPosX X component of last coefficient |
---|
| 983 | * \param uiPosY Y component of last coefficient |
---|
| 984 | * \param width Block width |
---|
| 985 | * \param height Block height |
---|
| 986 | * \param eTType plane type / luminance or chrominance |
---|
| 987 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
| 988 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
| 989 | */ |
---|
| 990 | Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
| 991 | { |
---|
| 992 | // swap |
---|
| 993 | if( uiScanIdx == SCAN_VER ) |
---|
| 994 | { |
---|
| 995 | swap( uiPosX, uiPosY ); |
---|
| 996 | } |
---|
| 997 | |
---|
| 998 | UInt uiCtxLast; |
---|
| 999 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
| 1000 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
| 1001 | UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; |
---|
| 1002 | UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; |
---|
| 1003 | |
---|
| 1004 | |
---|
| 1005 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
| 1006 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
| 1007 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
| 1008 | shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
| 1009 | shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
| 1010 | // posX |
---|
| 1011 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) |
---|
| 1012 | { |
---|
| 1013 | m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
| 1014 | } |
---|
| 1015 | if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) |
---|
| 1016 | { |
---|
| 1017 | m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
| 1018 | } |
---|
| 1019 | |
---|
| 1020 | // posY |
---|
| 1021 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) |
---|
| 1022 | { |
---|
| 1023 | m_pcBinIf->encodeBin( 1, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
| 1024 | } |
---|
| 1025 | if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ]) |
---|
| 1026 | { |
---|
| 1027 | m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
| 1028 | } |
---|
| 1029 | if ( uiGroupIdxX > 3 ) |
---|
| 1030 | { |
---|
| 1031 | UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; |
---|
| 1032 | uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; |
---|
| 1033 | for (Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
| 1034 | { |
---|
| 1035 | m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 ); |
---|
| 1036 | } |
---|
| 1037 | } |
---|
| 1038 | if ( uiGroupIdxY > 3 ) |
---|
| 1039 | { |
---|
| 1040 | UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; |
---|
| 1041 | uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; |
---|
| 1042 | for ( Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
| 1043 | { |
---|
| 1044 | m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 ); |
---|
| 1045 | } |
---|
| 1046 | } |
---|
| 1047 | } |
---|
| 1048 | |
---|
| 1049 | Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
| 1050 | { |
---|
| 1051 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1052 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
| 1053 | DTRACE_CABAC_V( eTType ) |
---|
| 1054 | DTRACE_CABAC_T( "\twidth=" ) |
---|
| 1055 | DTRACE_CABAC_V( uiWidth ) |
---|
| 1056 | DTRACE_CABAC_T( "\theight=" ) |
---|
| 1057 | DTRACE_CABAC_V( uiHeight ) |
---|
| 1058 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
| 1059 | DTRACE_CABAC_V( uiDepth ) |
---|
| 1060 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
| 1061 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1062 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
| 1063 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
| 1064 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
| 1065 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
| 1066 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
| 1067 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
| 1068 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
| 1069 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1070 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
| 1071 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1072 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
| 1073 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
| 1074 | DTRACE_CABAC_T( "\n" ) |
---|
| 1075 | |
---|
| 1076 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
| 1077 | { |
---|
| 1078 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
| 1079 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
| 1080 | } |
---|
| 1081 | |
---|
| 1082 | UInt uiNumSig = 0; |
---|
| 1083 | |
---|
| 1084 | // compute number of significant coefficients |
---|
| 1085 | uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); |
---|
| 1086 | |
---|
| 1087 | if ( uiNumSig == 0 ) |
---|
| 1088 | return; |
---|
| 1089 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
| 1090 | { |
---|
| 1091 | codeTransformSkipFlags( pcCU,uiAbsPartIdx, uiWidth, uiHeight, eTType ); |
---|
| 1092 | } |
---|
| 1093 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
| 1094 | |
---|
| 1095 | //----- encode significance map ----- |
---|
| 1096 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
| 1097 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
| 1098 | const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize - 1 ]; |
---|
| 1099 | |
---|
| 1100 | Bool beValid; |
---|
| 1101 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
| 1102 | { |
---|
| 1103 | beValid = false; |
---|
| 1104 | } |
---|
| 1105 | else |
---|
| 1106 | { |
---|
| 1107 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
| 1108 | } |
---|
| 1109 | |
---|
| 1110 | // Find position of last coefficient |
---|
| 1111 | Int scanPosLast = -1; |
---|
| 1112 | Int posLast; |
---|
| 1113 | |
---|
| 1114 | const UInt * scanCG; |
---|
| 1115 | { |
---|
| 1116 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
| 1117 | if( uiLog2BlockSize == 3 ) |
---|
| 1118 | { |
---|
| 1119 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
| 1120 | } |
---|
| 1121 | else if( uiLog2BlockSize == 5 ) |
---|
| 1122 | { |
---|
| 1123 | scanCG = g_sigLastScanCG32x32; |
---|
| 1124 | } |
---|
| 1125 | } |
---|
| 1126 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
| 1127 | static const UInt uiShift = MLS_CG_SIZE >> 1; |
---|
| 1128 | const UInt uiNumBlkSide = uiWidth >> uiShift; |
---|
| 1129 | |
---|
| 1130 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
| 1131 | |
---|
| 1132 | do |
---|
| 1133 | { |
---|
| 1134 | posLast = scan[ ++scanPosLast ]; |
---|
| 1135 | |
---|
| 1136 | // get L1 sig map |
---|
| 1137 | UInt uiPosY = posLast >> uiLog2BlockSize; |
---|
| 1138 | UInt uiPosX = posLast - ( uiPosY << uiLog2BlockSize ); |
---|
| 1139 | UInt uiBlkIdx = uiNumBlkSide * (uiPosY >> uiShift) + (uiPosX >> uiShift); |
---|
| 1140 | if( pcCoef[ posLast ] ) |
---|
| 1141 | { |
---|
| 1142 | uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; |
---|
| 1143 | } |
---|
| 1144 | |
---|
| 1145 | uiNumSig -= ( pcCoef[ posLast ] != 0 ); |
---|
| 1146 | } |
---|
| 1147 | while ( uiNumSig > 0 ); |
---|
| 1148 | |
---|
| 1149 | // Code position of last coefficient |
---|
| 1150 | Int posLastY = posLast >> uiLog2BlockSize; |
---|
| 1151 | Int posLastX = posLast - ( posLastY << uiLog2BlockSize ); |
---|
| 1152 | codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, eTType, uiScanIdx); |
---|
| 1153 | |
---|
| 1154 | //===== code significance flag ===== |
---|
| 1155 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
| 1156 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
| 1157 | |
---|
| 1158 | |
---|
| 1159 | const Int iLastScanSet = scanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
| 1160 | UInt c1 = 1; |
---|
| 1161 | UInt uiGoRiceParam = 0; |
---|
| 1162 | Int iScanPosSig = scanPosLast; |
---|
| 1163 | |
---|
| 1164 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
| 1165 | { |
---|
| 1166 | Int numNonZero = 0; |
---|
| 1167 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
| 1168 | uiGoRiceParam = 0; |
---|
| 1169 | Int absCoeff[16]; |
---|
| 1170 | UInt coeffSigns = 0; |
---|
| 1171 | |
---|
| 1172 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
| 1173 | |
---|
| 1174 | if( iScanPosSig == scanPosLast ) |
---|
| 1175 | { |
---|
| 1176 | absCoeff[ 0 ] = abs( pcCoef[ posLast ] ); |
---|
| 1177 | coeffSigns = ( pcCoef[ posLast ] < 0 ); |
---|
| 1178 | numNonZero = 1; |
---|
| 1179 | lastNZPosInCG = iScanPosSig; |
---|
| 1180 | firstNZPosInCG = iScanPosSig; |
---|
| 1181 | iScanPosSig--; |
---|
| 1182 | } |
---|
| 1183 | |
---|
| 1184 | // encode significant_coeffgroup_flag |
---|
| 1185 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
| 1186 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
| 1187 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
| 1188 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
| 1189 | { |
---|
| 1190 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
| 1191 | } |
---|
| 1192 | else |
---|
| 1193 | { |
---|
| 1194 | UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); |
---|
| 1195 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
| 1196 | m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
| 1197 | } |
---|
| 1198 | |
---|
| 1199 | // encode significant_coeff_flag |
---|
| 1200 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
| 1201 | { |
---|
| 1202 | Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
| 1203 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
| 1204 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
| 1205 | { |
---|
| 1206 | uiBlkPos = scan[ iScanPosSig ]; |
---|
| 1207 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
| 1208 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
| 1209 | uiSig = (pcCoef[ uiBlkPos ] != 0); |
---|
| 1210 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
| 1211 | { |
---|
| 1212 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType ); |
---|
| 1213 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
| 1214 | } |
---|
| 1215 | if( uiSig ) |
---|
| 1216 | { |
---|
| 1217 | absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); |
---|
| 1218 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
| 1219 | numNonZero++; |
---|
| 1220 | if( lastNZPosInCG == -1 ) |
---|
| 1221 | { |
---|
| 1222 | lastNZPosInCG = iScanPosSig; |
---|
| 1223 | } |
---|
| 1224 | firstNZPosInCG = iScanPosSig; |
---|
| 1225 | } |
---|
| 1226 | } |
---|
| 1227 | } |
---|
| 1228 | else |
---|
| 1229 | { |
---|
| 1230 | iScanPosSig = iSubPos - 1; |
---|
| 1231 | } |
---|
| 1232 | |
---|
| 1233 | if( numNonZero > 0 ) |
---|
| 1234 | { |
---|
| 1235 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
| 1236 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
| 1237 | |
---|
| 1238 | if( c1 == 0 ) |
---|
| 1239 | { |
---|
| 1240 | uiCtxSet++; |
---|
| 1241 | } |
---|
| 1242 | c1 = 1; |
---|
| 1243 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
| 1244 | |
---|
| 1245 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
| 1246 | Int firstC2FlagIdx = -1; |
---|
| 1247 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
| 1248 | { |
---|
| 1249 | UInt uiSymbol = absCoeff[ idx ] > 1; |
---|
| 1250 | m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] ); |
---|
| 1251 | if( uiSymbol ) |
---|
| 1252 | { |
---|
| 1253 | c1 = 0; |
---|
| 1254 | |
---|
| 1255 | if (firstC2FlagIdx == -1) |
---|
| 1256 | { |
---|
| 1257 | firstC2FlagIdx = idx; |
---|
| 1258 | } |
---|
| 1259 | } |
---|
| 1260 | else if( (c1 < 3) && (c1 > 0) ) |
---|
| 1261 | { |
---|
| 1262 | c1++; |
---|
| 1263 | } |
---|
| 1264 | } |
---|
| 1265 | |
---|
| 1266 | if (c1 == 0) |
---|
| 1267 | { |
---|
| 1268 | |
---|
| 1269 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
| 1270 | if ( firstC2FlagIdx != -1) |
---|
| 1271 | { |
---|
| 1272 | UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; |
---|
| 1273 | m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); |
---|
| 1274 | } |
---|
| 1275 | } |
---|
| 1276 | |
---|
| 1277 | if( beValid && signHidden ) |
---|
| 1278 | { |
---|
| 1279 | m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 ); |
---|
| 1280 | } |
---|
| 1281 | else |
---|
| 1282 | { |
---|
| 1283 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
| 1284 | } |
---|
| 1285 | |
---|
| 1286 | Int iFirstCoeff2 = 1; |
---|
| 1287 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
| 1288 | { |
---|
| 1289 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 1290 | { |
---|
| 1291 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1; |
---|
| 1292 | |
---|
| 1293 | if( absCoeff[ idx ] >= baseLevel) |
---|
| 1294 | { |
---|
| 1295 | xWriteCoefRemainExGolomb( absCoeff[ idx ] - baseLevel, uiGoRiceParam ); |
---|
| 1296 | if(absCoeff[idx] > 3*(1<<uiGoRiceParam)) |
---|
| 1297 | { |
---|
| 1298 | uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4); |
---|
| 1299 | } |
---|
| 1300 | } |
---|
| 1301 | if(absCoeff[ idx ] >= 2) |
---|
| 1302 | { |
---|
| 1303 | iFirstCoeff2 = 0; |
---|
| 1304 | } |
---|
| 1305 | } |
---|
| 1306 | } |
---|
| 1307 | } |
---|
| 1308 | } |
---|
| 1309 | |
---|
| 1310 | return; |
---|
| 1311 | } |
---|
| 1312 | |
---|
| 1313 | /** code SAO offset sign |
---|
| 1314 | * \param code sign value |
---|
| 1315 | */ |
---|
| 1316 | Void TEncSbac::codeSAOSign( UInt code ) |
---|
| 1317 | { |
---|
| 1318 | m_pcBinIf->encodeBinEP( code ); |
---|
| 1319 | } |
---|
| 1320 | |
---|
| 1321 | Void TEncSbac::codeSaoMaxUvlc ( UInt code, UInt maxSymbol ) |
---|
| 1322 | { |
---|
| 1323 | if (maxSymbol == 0) |
---|
| 1324 | { |
---|
| 1325 | return; |
---|
| 1326 | } |
---|
| 1327 | |
---|
| 1328 | Int i; |
---|
| 1329 | Bool bCodeLast = ( maxSymbol > code ); |
---|
| 1330 | |
---|
| 1331 | if ( code == 0 ) |
---|
| 1332 | { |
---|
| 1333 | m_pcBinIf->encodeBinEP( 0 ); |
---|
| 1334 | } |
---|
| 1335 | else |
---|
| 1336 | { |
---|
| 1337 | m_pcBinIf->encodeBinEP( 1 ); |
---|
| 1338 | for ( i=0; i<code-1; i++ ) |
---|
| 1339 | { |
---|
| 1340 | m_pcBinIf->encodeBinEP( 1 ); |
---|
| 1341 | } |
---|
| 1342 | if( bCodeLast ) |
---|
| 1343 | { |
---|
| 1344 | m_pcBinIf->encodeBinEP( 0 ); |
---|
| 1345 | } |
---|
| 1346 | } |
---|
| 1347 | } |
---|
| 1348 | |
---|
| 1349 | |
---|
| 1350 | /** Code SAO EO class or BO band position |
---|
| 1351 | * \param uiLength |
---|
| 1352 | * \param uiCode |
---|
| 1353 | */ |
---|
| 1354 | Void TEncSbac::codeSaoUflc ( UInt uiLength, UInt uiCode ) |
---|
| 1355 | { |
---|
| 1356 | m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); |
---|
| 1357 | } |
---|
| 1358 | /** Code SAO merge flags |
---|
| 1359 | * \param uiCode |
---|
| 1360 | * \param uiCompIdx |
---|
| 1361 | */ |
---|
| 1362 | Void TEncSbac::codeSaoMerge ( UInt uiCode ) |
---|
| 1363 | { |
---|
| 1364 | if (uiCode == 0) |
---|
| 1365 | { |
---|
| 1366 | m_pcBinIf->encodeBin(0, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
| 1367 | } |
---|
| 1368 | else |
---|
| 1369 | { |
---|
| 1370 | m_pcBinIf->encodeBin(1, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
| 1371 | } |
---|
| 1372 | } |
---|
| 1373 | /** Code SAO type index |
---|
| 1374 | * \param uiCode |
---|
| 1375 | */ |
---|
| 1376 | Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) |
---|
| 1377 | { |
---|
| 1378 | if (uiCode == 0) |
---|
| 1379 | { |
---|
| 1380 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
| 1381 | } |
---|
| 1382 | else |
---|
| 1383 | { |
---|
| 1384 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
| 1385 | m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 ); |
---|
| 1386 | } |
---|
| 1387 | } |
---|
| 1388 | /*! |
---|
| 1389 | **************************************************************************** |
---|
| 1390 | * \brief |
---|
| 1391 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
| 1392 | **************************************************************************** |
---|
| 1393 | */ |
---|
| 1394 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
| 1395 | { |
---|
| 1396 | estCBFBit( pcEstBitsSbac ); |
---|
| 1397 | |
---|
| 1398 | estSignificantCoeffGroupMapBit( pcEstBitsSbac, eTType ); |
---|
| 1399 | |
---|
| 1400 | // encode significance map |
---|
| 1401 | estSignificantMapBit( pcEstBitsSbac, width, height, eTType ); |
---|
| 1402 | |
---|
| 1403 | // encode significant coefficients |
---|
| 1404 | estSignificantCoefficientsBit( pcEstBitsSbac, eTType ); |
---|
| 1405 | } |
---|
| 1406 | |
---|
| 1407 | /*! |
---|
| 1408 | **************************************************************************** |
---|
| 1409 | * \brief |
---|
| 1410 | * estimate bit cost for each CBP bit |
---|
| 1411 | **************************************************************************** |
---|
| 1412 | */ |
---|
| 1413 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac ) |
---|
| 1414 | { |
---|
| 1415 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
| 1416 | |
---|
| 1417 | for( UInt uiCtxInc = 0; uiCtxInc < 3*NUM_QT_CBF_CTX; uiCtxInc++ ) |
---|
| 1418 | { |
---|
| 1419 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
| 1420 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
| 1421 | } |
---|
| 1422 | |
---|
| 1423 | pCtx = m_cCUQtRootCbfSCModel.get( 0 ); |
---|
| 1424 | |
---|
| 1425 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
| 1426 | { |
---|
| 1427 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
| 1428 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
| 1429 | } |
---|
| 1430 | } |
---|
| 1431 | |
---|
| 1432 | |
---|
| 1433 | /*! |
---|
| 1434 | **************************************************************************** |
---|
| 1435 | * \brief |
---|
| 1436 | * estimate SAMBAC bit cost for significant coefficient group map |
---|
| 1437 | **************************************************************************** |
---|
| 1438 | */ |
---|
| 1439 | Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
| 1440 | { |
---|
| 1441 | Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; |
---|
| 1442 | |
---|
| 1443 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
| 1444 | { |
---|
| 1445 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
| 1446 | { |
---|
| 1447 | pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, eTType, ctxIdx ).getEntropyBits( uiBin ); |
---|
| 1448 | } |
---|
| 1449 | } |
---|
| 1450 | } |
---|
| 1451 | |
---|
| 1452 | |
---|
| 1453 | /*! |
---|
| 1454 | **************************************************************************** |
---|
| 1455 | * \brief |
---|
| 1456 | * estimate SAMBAC bit cost for significant coefficient map |
---|
| 1457 | **************************************************************************** |
---|
| 1458 | */ |
---|
| 1459 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
| 1460 | { |
---|
| 1461 | Int firstCtx = 1, numCtx = 8; |
---|
| 1462 | if (max(width, height) >= 16) |
---|
| 1463 | { |
---|
| 1464 | firstCtx = (eTType == TEXT_LUMA) ? 21 : 12; |
---|
| 1465 | numCtx = (eTType == TEXT_LUMA) ? 6 : 3; |
---|
| 1466 | } |
---|
| 1467 | else if (width == 8) |
---|
| 1468 | { |
---|
| 1469 | firstCtx = 9; |
---|
| 1470 | numCtx = (eTType == TEXT_LUMA) ? 12 : 3; |
---|
| 1471 | } |
---|
| 1472 | |
---|
| 1473 | if (eTType == TEXT_LUMA ) |
---|
| 1474 | { |
---|
| 1475 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
| 1476 | { |
---|
| 1477 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, 0 ).getEntropyBits( bin ); |
---|
| 1478 | } |
---|
| 1479 | |
---|
| 1480 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
| 1481 | { |
---|
| 1482 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
| 1483 | { |
---|
| 1484 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, ctxIdx ).getEntropyBits( uiBin ); |
---|
| 1485 | } |
---|
| 1486 | } |
---|
| 1487 | } |
---|
| 1488 | else |
---|
| 1489 | { |
---|
| 1490 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
| 1491 | { |
---|
| 1492 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + 0 ).getEntropyBits( bin ); |
---|
| 1493 | } |
---|
| 1494 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
| 1495 | { |
---|
| 1496 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
| 1497 | { |
---|
| 1498 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx ).getEntropyBits( uiBin ); |
---|
| 1499 | } |
---|
| 1500 | } |
---|
| 1501 | } |
---|
| 1502 | Int iBitsX = 0, iBitsY = 0; |
---|
| 1503 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
| 1504 | |
---|
| 1505 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
| 1506 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
| 1507 | shiftX = eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
| 1508 | shiftY = eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
| 1509 | |
---|
| 1510 | Int ctx; |
---|
| 1511 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
| 1512 | for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) |
---|
| 1513 | { |
---|
| 1514 | Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX); |
---|
| 1515 | pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); |
---|
| 1516 | iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); |
---|
| 1517 | } |
---|
| 1518 | pcEstBitsSbac->lastXBits[ctx] = iBitsX; |
---|
| 1519 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
| 1520 | for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) |
---|
| 1521 | { |
---|
| 1522 | Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY); |
---|
| 1523 | pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); |
---|
| 1524 | iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); |
---|
| 1525 | } |
---|
| 1526 | pcEstBitsSbac->lastYBits[ctx] = iBitsY; |
---|
| 1527 | } |
---|
| 1528 | |
---|
| 1529 | /*! |
---|
| 1530 | **************************************************************************** |
---|
| 1531 | * \brief |
---|
| 1532 | * estimate bit cost of significant coefficient |
---|
| 1533 | **************************************************************************** |
---|
| 1534 | */ |
---|
| 1535 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
| 1536 | { |
---|
| 1537 | if (eTType==TEXT_LUMA) |
---|
| 1538 | { |
---|
| 1539 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); |
---|
| 1540 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); |
---|
| 1541 | |
---|
| 1542 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++) |
---|
| 1543 | { |
---|
| 1544 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 1545 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 1546 | } |
---|
| 1547 | |
---|
| 1548 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_LUMA; ctxIdx++) |
---|
| 1549 | { |
---|
| 1550 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 1551 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 1552 | } |
---|
| 1553 | } |
---|
| 1554 | else |
---|
| 1555 | { |
---|
| 1556 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA; |
---|
| 1557 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA; |
---|
| 1558 | |
---|
| 1559 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++) |
---|
| 1560 | { |
---|
| 1561 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 1562 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 1563 | } |
---|
| 1564 | |
---|
| 1565 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_CHROMA; ctxIdx++) |
---|
| 1566 | { |
---|
| 1567 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 1568 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 1569 | } |
---|
| 1570 | } |
---|
| 1571 | } |
---|
| 1572 | |
---|
| 1573 | /** |
---|
| 1574 | - Initialize our context information from the nominated source. |
---|
| 1575 | . |
---|
| 1576 | \param pSrc From where to copy context information. |
---|
| 1577 | */ |
---|
| 1578 | Void TEncSbac::xCopyContextsFrom( TEncSbac* pSrc ) |
---|
| 1579 | { |
---|
| 1580 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
| 1581 | } |
---|
| 1582 | |
---|
| 1583 | Void TEncSbac::loadContexts ( TEncSbac* pScr) |
---|
| 1584 | { |
---|
| 1585 | this->xCopyContextsFrom(pScr); |
---|
| 1586 | } |
---|
| 1587 | |
---|
| 1588 | //! \} |
---|