[324] | 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) |
---|
[504] | 62 | #if H_3D_ARP |
---|
| 63 | , m_cCUPUARPWSCModel ( 1, 1, NUM_ARPW_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 64 | #endif |
---|
| 65 | #if H_3D_IC |
---|
| 66 | , m_cCUICFlagSCModel ( 1, 1, NUM_IC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 67 | #endif |
---|
[324] | 68 | , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 69 | , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 70 | , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 71 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 72 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 73 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 74 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 75 | , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 76 | , m_cCUQtCbfSCModel ( 1, 2, NUM_QT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 77 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 78 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 79 | , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 80 | , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 81 | , m_cCuCtxLastX ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 82 | , m_cCuCtxLastY ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 83 | , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 84 | , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 85 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 86 | , m_cCUAMPSCModel ( 1, 1, NUM_CU_AMP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 87 | , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 88 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 89 | , m_cTransformSkipSCModel ( 1, 2, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 90 | , m_CUTransquantBypassFlagSCModel( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels) |
---|
[531] | 91 | #if H_3D_DIM |
---|
| 92 | , m_cDepthIntraModeSCModel ( 1, 1, NUM_DEPTH_INTRA_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 93 | , m_cDdcFlagSCModel ( 1, 1, NUM_DDC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 94 | , m_cDdcDataSCModel ( 1, 1, NUM_DDC_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 95 | #if H_3D_DIM_DMM |
---|
| 96 | , m_cDmm1DataSCModel ( 1, 1, NUM_DMM1_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 97 | , m_cDmm2DataSCModel ( 1, 1, NUM_DMM2_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 98 | , m_cDmm3DataSCModel ( 1, 1, NUM_DMM3_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 99 | #endif |
---|
| 100 | #if H_3D_DIM_RBC |
---|
| 101 | , m_cRbcDataSCModel ( 1, 1, NUM_RBC_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 102 | #endif |
---|
| 103 | #if H_3D_DIM_SDC |
---|
| 104 | , m_cSDCResidualFlagSCModel ( 1, 1, SDC_NUM_RESIDUAL_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 105 | , m_cSDCResidualSCModel ( 1, 1, SDC_NUM_RESIDUAL_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
| 106 | #endif |
---|
| 107 | #endif |
---|
[324] | 108 | { |
---|
| 109 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | TEncSbac::~TEncSbac() |
---|
| 113 | { |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | // ==================================================================================================================== |
---|
| 117 | // Public member functions |
---|
| 118 | // ==================================================================================================================== |
---|
| 119 | |
---|
| 120 | Void TEncSbac::resetEntropy () |
---|
| 121 | { |
---|
| 122 | Int iQp = m_pcSlice->getSliceQp(); |
---|
| 123 | SliceType eSliceType = m_pcSlice->getSliceType(); |
---|
| 124 | |
---|
| 125 | Int encCABACTableIdx = m_pcSlice->getPPS()->getEncCABACTableIdx(); |
---|
| 126 | if (!m_pcSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && m_pcSlice->getPPS()->getCabacInitPresentFlag()) |
---|
| 127 | { |
---|
| 128 | eSliceType = (SliceType) encCABACTableIdx; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
| 132 | |
---|
| 133 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
| 134 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
| 135 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
[504] | 136 | #if H_3D_ARP |
---|
| 137 | m_cCUPUARPWSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ARPW ); |
---|
| 138 | #endif |
---|
| 139 | #if H_3D_IC |
---|
| 140 | m_cCUICFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_IC_FLAG ); |
---|
| 141 | #endif |
---|
[324] | 142 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
| 143 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
| 144 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
| 145 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
| 146 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
| 147 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
| 148 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
| 149 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
| 150 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
| 151 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
| 152 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
| 153 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
| 154 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
| 155 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 156 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 157 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
| 158 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
| 159 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
| 160 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
| 161 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
| 162 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
| 163 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
| 164 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
[531] | 165 | |
---|
| 166 | #if H_3D_DIM |
---|
| 167 | m_cDepthIntraModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE ); |
---|
| 168 | m_cDdcFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG ); |
---|
| 169 | m_cDdcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_DATA ); |
---|
| 170 | #if H_3D_DIM_DMM |
---|
| 171 | m_cDmm1DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA ); |
---|
| 172 | m_cDmm2DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA ); |
---|
| 173 | m_cDmm3DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA ); |
---|
| 174 | #endif |
---|
| 175 | #if H_3D_DIM_RBC |
---|
| 176 | m_cRbcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RBC_DATA ); |
---|
| 177 | #endif |
---|
| 178 | #if H_3D_DIM_SDC |
---|
| 179 | m_cSDCResidualFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG ); |
---|
| 180 | m_cSDCResidualSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL ); |
---|
| 181 | #endif |
---|
| 182 | #endif |
---|
[324] | 183 | // new structure |
---|
| 184 | m_uiLastQp = iQp; |
---|
| 185 | |
---|
| 186 | m_pcBinIf->start(); |
---|
| 187 | |
---|
| 188 | return; |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | /** The function does the following: |
---|
| 192 | * If current slice type is P/B then it determines the distance of initialisation type 1 and 2 from the current CABAC states and |
---|
| 193 | * stores the index of the closest table. This index is used for the next P/B slice when cabac_init_present_flag is true. |
---|
| 194 | */ |
---|
| 195 | Void TEncSbac::determineCabacInitIdx() |
---|
| 196 | { |
---|
| 197 | Int qp = m_pcSlice->getSliceQp(); |
---|
| 198 | |
---|
| 199 | if (!m_pcSlice->isIntra()) |
---|
| 200 | { |
---|
| 201 | SliceType aSliceTypeChoices[] = {B_SLICE, P_SLICE}; |
---|
| 202 | |
---|
| 203 | UInt bestCost = MAX_UINT; |
---|
| 204 | SliceType bestSliceType = aSliceTypeChoices[0]; |
---|
| 205 | for (UInt idx=0; idx<2; idx++) |
---|
| 206 | { |
---|
| 207 | UInt curCost = 0; |
---|
| 208 | SliceType curSliceType = aSliceTypeChoices[idx]; |
---|
| 209 | |
---|
| 210 | curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
| 211 | curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
| 212 | curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
| 213 | curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
[504] | 214 | #if H_3D_ARP |
---|
| 215 | curCost += m_cCUPUARPWSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ARPW ); |
---|
| 216 | #endif |
---|
| 217 | #if H_3D_IC |
---|
| 218 | curCost += m_cCUICFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_IC_FLAG ); |
---|
| 219 | #endif |
---|
[324] | 220 | curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); |
---|
| 221 | curCost += m_cCUAMPSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_AMP_POS ); |
---|
| 222 | curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); |
---|
| 223 | curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
| 224 | curCost += m_cCUChromaPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
| 225 | curCost += m_cCUInterDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTER_DIR ); |
---|
| 226 | curCost += m_cCUMvdSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVD ); |
---|
| 227 | curCost += m_cCURefPicSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_REF_PIC ); |
---|
| 228 | curCost += m_cCUDeltaQpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DQP ); |
---|
| 229 | curCost += m_cCUQtCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_CBF ); |
---|
| 230 | curCost += m_cCUQtRootCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
| 231 | curCost += m_cCUSigCoeffGroupSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
| 232 | curCost += m_cCUSigSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_FLAG ); |
---|
| 233 | curCost += m_cCuCtxLastX.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
| 234 | curCost += m_cCuCtxLastY.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
| 235 | curCost += m_cCUOneSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ONE_FLAG ); |
---|
| 236 | curCost += m_cCUAbsSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ABS_FLAG ); |
---|
| 237 | curCost += m_cMVPIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVP_IDX ); |
---|
| 238 | curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
| 239 | curCost += m_cSaoMergeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
| 240 | curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
| 241 | curCost += m_cTransformSkipSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
| 242 | curCost += m_CUTransquantBypassFlagSCModel.calcCost( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
[531] | 243 | #if H_3D_DIM |
---|
| 244 | if( m_pcSlice->getVpsDepthModesFlag() ) |
---|
| 245 | { |
---|
| 246 | curCost += m_cDepthIntraModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DEPTH_INTRA_MODE ); |
---|
| 247 | curCost += m_cDdcFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DDC_FLAG ); |
---|
| 248 | curCost += m_cDdcDataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DDC_DATA ); |
---|
| 249 | #if H_3D_DIM_DMM |
---|
| 250 | curCost += m_cDmm1DataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM1_DATA ); |
---|
| 251 | curCost += m_cDmm2DataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM2_DATA ); |
---|
| 252 | curCost += m_cDmm3DataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM3_DATA ); |
---|
| 253 | #endif |
---|
| 254 | #if H_3D_DIM_RBC |
---|
| 255 | curCost += m_cRbcDataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_RBC_DATA ); |
---|
| 256 | #endif |
---|
| 257 | } |
---|
| 258 | #endif |
---|
[324] | 259 | if (curCost < bestCost) |
---|
| 260 | { |
---|
| 261 | bestSliceType = curSliceType; |
---|
| 262 | bestCost = curCost; |
---|
| 263 | } |
---|
| 264 | } |
---|
| 265 | m_pcSlice->getPPS()->setEncCABACTableIdx( bestSliceType ); |
---|
| 266 | } |
---|
| 267 | else |
---|
| 268 | { |
---|
| 269 | m_pcSlice->getPPS()->setEncCABACTableIdx( I_SLICE ); |
---|
| 270 | } |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | |
---|
| 274 | /** The function does the followng: Write out terminate bit. Flush CABAC. Intialize CABAC states. Start CABAC. |
---|
| 275 | */ |
---|
| 276 | Void TEncSbac::updateContextTables( SliceType eSliceType, Int iQp, Bool bExecuteFinish ) |
---|
| 277 | { |
---|
| 278 | m_pcBinIf->encodeBinTrm(1); |
---|
| 279 | if (bExecuteFinish) m_pcBinIf->finish(); |
---|
| 280 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
| 281 | |
---|
| 282 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
| 283 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
| 284 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
[504] | 285 | #if H_3D_ARP |
---|
| 286 | m_cCUPUARPWSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ARPW ); |
---|
| 287 | #endif |
---|
| 288 | #if H_3D_IC |
---|
| 289 | m_cCUICFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_IC_FLAG ); |
---|
| 290 | #endif |
---|
[324] | 291 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
| 292 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
| 293 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
| 294 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
| 295 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
| 296 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
| 297 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
| 298 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
| 299 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
| 300 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
| 301 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
| 302 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
| 303 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
| 304 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 305 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
| 306 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
| 307 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
| 308 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
| 309 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
| 310 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
| 311 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
| 312 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
| 313 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
[531] | 314 | |
---|
| 315 | #if H_3D_DIM |
---|
| 316 | m_cDepthIntraModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE ); |
---|
| 317 | m_cDdcFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG ); |
---|
| 318 | m_cDdcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_DATA ); |
---|
| 319 | #if H_3D_DIM_DMM |
---|
| 320 | m_cDmm1DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA ); |
---|
| 321 | m_cDmm2DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA ); |
---|
| 322 | m_cDmm3DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA ); |
---|
| 323 | #endif |
---|
| 324 | #if H_3D_DIM_RBC |
---|
| 325 | m_cRbcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RBC_DATA ); |
---|
| 326 | #endif |
---|
| 327 | #if H_3D_DIM_SDC |
---|
| 328 | m_cSDCResidualFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG ); |
---|
| 329 | m_cSDCResidualSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL ); |
---|
| 330 | #endif |
---|
| 331 | #endif |
---|
[324] | 332 | m_pcBinIf->start(); |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | Void TEncSbac::codeVPS( TComVPS* pcVPS ) |
---|
| 336 | { |
---|
| 337 | assert (0); |
---|
| 338 | return; |
---|
| 339 | } |
---|
| 340 | |
---|
[446] | 341 | #if H_3D |
---|
| 342 | Void TEncSbac::codeSPS( TComSPS* pcSPS, Int viewIndex, Bool depthFlag ) |
---|
| 343 | #else |
---|
[324] | 344 | Void TEncSbac::codeSPS( TComSPS* pcSPS ) |
---|
[446] | 345 | #endif |
---|
[324] | 346 | { |
---|
| 347 | assert (0); |
---|
| 348 | return; |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | Void TEncSbac::codePPS( TComPPS* pcPPS ) |
---|
| 352 | { |
---|
| 353 | assert (0); |
---|
| 354 | return; |
---|
| 355 | } |
---|
| 356 | |
---|
| 357 | Void TEncSbac::codeSliceHeader( TComSlice* pcSlice ) |
---|
| 358 | { |
---|
| 359 | assert (0); |
---|
| 360 | return; |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | Void TEncSbac::codeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
| 364 | { |
---|
| 365 | assert (0); |
---|
| 366 | return; |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | Void TEncSbac::codeTerminatingBit( UInt uilsLast ) |
---|
| 370 | { |
---|
| 371 | m_pcBinIf->encodeBinTrm( uilsLast ); |
---|
| 372 | } |
---|
| 373 | |
---|
| 374 | Void TEncSbac::codeSliceFinish() |
---|
| 375 | { |
---|
| 376 | m_pcBinIf->finish(); |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
| 380 | { |
---|
| 381 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] ); |
---|
| 382 | |
---|
| 383 | if( 0 == uiSymbol) |
---|
| 384 | { |
---|
| 385 | return; |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | while( uiSymbol-- ) |
---|
| 389 | { |
---|
| 390 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] ); |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | return; |
---|
| 394 | } |
---|
| 395 | |
---|
| 396 | Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
| 397 | { |
---|
| 398 | if (uiMaxSymbol == 0) |
---|
| 399 | { |
---|
| 400 | return; |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] ); |
---|
| 404 | |
---|
| 405 | if ( uiSymbol == 0 ) |
---|
| 406 | { |
---|
| 407 | return; |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
| 411 | |
---|
| 412 | while( --uiSymbol ) |
---|
| 413 | { |
---|
| 414 | m_pcBinIf->encodeBin( 1, pcSCModel[ iOffset ] ); |
---|
| 415 | } |
---|
| 416 | if( bCodeLast ) |
---|
| 417 | { |
---|
| 418 | m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] ); |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | return; |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | Void TEncSbac::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
| 425 | { |
---|
| 426 | UInt bins = 0; |
---|
| 427 | Int numBins = 0; |
---|
| 428 | |
---|
| 429 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
| 430 | { |
---|
| 431 | bins = 2 * bins + 1; |
---|
| 432 | numBins++; |
---|
| 433 | uiSymbol -= 1 << uiCount; |
---|
| 434 | uiCount ++; |
---|
| 435 | } |
---|
| 436 | bins = 2 * bins + 0; |
---|
| 437 | numBins++; |
---|
| 438 | |
---|
| 439 | bins = (bins << uiCount) | uiSymbol; |
---|
| 440 | numBins += uiCount; |
---|
| 441 | |
---|
| 442 | assert( numBins <= 32 ); |
---|
| 443 | m_pcBinIf->encodeBinsEP( bins, numBins ); |
---|
| 444 | } |
---|
| 445 | |
---|
| 446 | /** Coding of coeff_abs_level_minus3 |
---|
| 447 | * \param uiSymbol value of coeff_abs_level_minus3 |
---|
| 448 | * \param ruiGoRiceParam reference to Rice parameter |
---|
| 449 | * \returns Void |
---|
| 450 | */ |
---|
| 451 | Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam ) |
---|
| 452 | { |
---|
| 453 | Int codeNumber = (Int)symbol; |
---|
| 454 | UInt length; |
---|
| 455 | if (codeNumber < (COEF_REMAIN_BIN_REDUCTION << rParam)) |
---|
| 456 | { |
---|
| 457 | length = codeNumber>>rParam; |
---|
| 458 | m_pcBinIf->encodeBinsEP( (1<<(length+1))-2 , length+1); |
---|
| 459 | m_pcBinIf->encodeBinsEP((codeNumber%(1<<rParam)),rParam); |
---|
| 460 | } |
---|
| 461 | else |
---|
| 462 | { |
---|
| 463 | length = rParam; |
---|
| 464 | codeNumber = codeNumber - ( COEF_REMAIN_BIN_REDUCTION << rParam); |
---|
| 465 | while (codeNumber >= (1<<length)) |
---|
| 466 | { |
---|
| 467 | codeNumber -= (1<<(length++)); |
---|
| 468 | } |
---|
| 469 | m_pcBinIf->encodeBinsEP((1<<(COEF_REMAIN_BIN_REDUCTION+length+1-rParam))-2,COEF_REMAIN_BIN_REDUCTION+length+1-rParam); |
---|
| 470 | m_pcBinIf->encodeBinsEP(codeNumber,length); |
---|
| 471 | } |
---|
| 472 | } |
---|
| 473 | |
---|
[531] | 474 | #if H_3D_DIM |
---|
| 475 | Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel ) |
---|
| 476 | { |
---|
| 477 | if( uiSymbol ) |
---|
| 478 | { |
---|
| 479 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
| 480 | UInt uiCount = 0; |
---|
| 481 | Bool bNoExGo = (uiSymbol < 13); |
---|
| 482 | |
---|
| 483 | while( --uiSymbol && ++uiCount < 13 ) |
---|
| 484 | { |
---|
| 485 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
| 486 | } |
---|
| 487 | if( bNoExGo ) |
---|
| 488 | { |
---|
| 489 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
| 490 | } |
---|
| 491 | else |
---|
| 492 | { |
---|
| 493 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
| 494 | } |
---|
| 495 | } |
---|
| 496 | else |
---|
| 497 | { |
---|
| 498 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | return; |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | Void TEncSbac::xCodeDimDeltaDC( Pel valDeltaDC, UInt dimType ) |
---|
| 505 | { |
---|
| 506 | xWriteExGolombLevel( UInt( abs( valDeltaDC ) ), m_cDdcDataSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) ); |
---|
| 507 | if( valDeltaDC != 0 ) |
---|
| 508 | { |
---|
| 509 | UInt uiSign = valDeltaDC > 0 ? 0 : 1; |
---|
| 510 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 511 | } |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | #if H_3D_DIM_DMM |
---|
| 515 | Void TEncSbac::xCodeDmm1WedgeIdx( UInt uiTabIdx, Int iNumBit ) |
---|
| 516 | { |
---|
| 517 | for ( Int i = 0; i < iNumBit; i++ ) |
---|
| 518 | { |
---|
| 519 | m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cDmm1DataSCModel.get(0, 0, 0) ); |
---|
| 520 | } |
---|
| 521 | } |
---|
| 522 | |
---|
| 523 | Void TEncSbac::xCodeDmm2Offset( Int iOffset ) |
---|
| 524 | { |
---|
| 525 | if( DMM2_DELTAEND_MAX > 0 ) |
---|
| 526 | { |
---|
| 527 | m_pcBinIf->encodeBin( (iOffset != 0) , m_cDmm2DataSCModel.get(0, 0, 0) ); |
---|
| 528 | if( iOffset != 0 ) |
---|
| 529 | { |
---|
| 530 | UInt uiAbsValMinus1 = abs(iOffset)-1; |
---|
| 531 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cDmm2DataSCModel.get(0, 0, 0) ); |
---|
| 532 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cDmm2DataSCModel.get(0, 0, 0) ); |
---|
| 533 | |
---|
| 534 | UInt uiSign = (iOffset > 0) ? 0 : 1; |
---|
| 535 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 536 | } |
---|
| 537 | } |
---|
| 538 | } |
---|
| 539 | |
---|
| 540 | Void TEncSbac::xCodeDmm3WedgeIdx( UInt uiIntraIdx, Int iNumBit ) |
---|
| 541 | { |
---|
| 542 | for( Int i = 0; i < iNumBit; i++ ) |
---|
| 543 | { |
---|
| 544 | m_pcBinIf->encodeBin( ( uiIntraIdx >> i ) & 1, m_cDmm3DataSCModel.get(0, 0, 0) ); |
---|
| 545 | } |
---|
| 546 | } |
---|
| 547 | #endif |
---|
| 548 | #if H_3D_DIM_RBC |
---|
| 549 | Void TEncSbac::xCodeRbcEdge( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 550 | { |
---|
| 551 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ) + (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 1 : 0); |
---|
| 552 | UChar* pucSymbolList = pcCU->getEdgeCode ( uiAbsPartIdx ); |
---|
| 553 | UChar ucEdgeNumber = pcCU->getEdgeNumber ( uiAbsPartIdx ); |
---|
| 554 | Bool bLeft = pcCU->getEdgeLeftFirst( uiAbsPartIdx ); |
---|
| 555 | UChar ucStart = pcCU->getEdgeStartPos ( uiAbsPartIdx ); |
---|
| 556 | UInt uiSymbol; |
---|
| 557 | |
---|
| 558 | // 1. Top(0) or Left(1) |
---|
| 559 | uiSymbol = (bLeft == false) ? 0 : 1; |
---|
| 560 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
| 561 | |
---|
| 562 | // 2. Start position (lowest bit first) |
---|
| 563 | uiSymbol = ucStart; |
---|
| 564 | for( UInt ui = 6; ui > uiDepth; ui-- ) // 64(0)->6, 32(1)->5, 16(2)->4, 8(3)->3, 4(4)->2 |
---|
| 565 | { |
---|
| 566 | m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); |
---|
| 567 | uiSymbol >>= 1; |
---|
| 568 | } |
---|
| 569 | |
---|
| 570 | // 3. Number of edges |
---|
| 571 | uiSymbol = ucEdgeNumber > 0 ? ucEdgeNumber - 1 : 0; |
---|
| 572 | for( UInt ui = 7; ui > uiDepth; ui-- ) // 64(0)->7, 32(1)->6, 16(2)->5, 8(3)->4, 4(4)->3 |
---|
| 573 | { |
---|
| 574 | m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); |
---|
| 575 | uiSymbol >>= 1; |
---|
| 576 | } |
---|
| 577 | |
---|
| 578 | if(uiSymbol != 0) |
---|
| 579 | { |
---|
| 580 | printf(" ucEdgeNumber %d at depth %d\n",ucEdgeNumber, uiDepth); |
---|
| 581 | assert(false); |
---|
| 582 | } |
---|
| 583 | |
---|
| 584 | // 4. Edges |
---|
| 585 | for( Int iPtr2 = 0; iPtr2 < ucEdgeNumber; iPtr2++ ) |
---|
| 586 | { |
---|
| 587 | UInt uiReorderSymbol = pucSymbolList[iPtr2]; |
---|
| 588 | for( UInt ui = 0; ui < uiReorderSymbol; ui++ ) |
---|
| 589 | { |
---|
| 590 | m_pcBinIf->encodeBin( 1, m_cRbcDataSCModel.get( 0, 0, 0 ) ); |
---|
| 591 | } |
---|
| 592 | |
---|
| 593 | if( uiReorderSymbol != 6 ) |
---|
| 594 | m_pcBinIf->encodeBin( 0, m_cRbcDataSCModel.get( 0, 0, 0 ) ); |
---|
| 595 | } |
---|
| 596 | } |
---|
| 597 | #endif |
---|
| 598 | #if H_3D_DIM_SDC |
---|
| 599 | Void TEncSbac::xCodeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ) |
---|
| 600 | { |
---|
| 601 | assert( pcCU->getSlice()->getIsDepth() ); |
---|
| 602 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
| 603 | assert( pcCU->getSDCFlag(uiAbsPartIdx) ); |
---|
| 604 | assert( uiSegment < 2 ); |
---|
| 605 | |
---|
| 606 | Pel segmentDCOffset = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx); |
---|
| 607 | |
---|
| 608 | UInt uiResidual = segmentDCOffset == 0 ? 0 : 1; |
---|
| 609 | UInt uiSign = segmentDCOffset < 0 ? 1 : 0; |
---|
| 610 | UInt uiAbsIdx = abs(segmentDCOffset); |
---|
| 611 | |
---|
| 612 | #if H_3D_DIM_DLT |
---|
| 613 | UInt uiMaxResidualBits = pcCU->getSlice()->getVPS()->getBitsPerDepthValue( pcCU->getSlice()->getLayerIdInVps() ); |
---|
| 614 | #else |
---|
| 615 | UInt uiMaxResidualBits = g_bitDepthY; |
---|
| 616 | #endif |
---|
| 617 | assert( uiMaxResidualBits <= g_bitDepthY ); |
---|
| 618 | |
---|
| 619 | // residual flag |
---|
| 620 | m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) ); |
---|
| 621 | |
---|
| 622 | if (uiResidual) |
---|
| 623 | { |
---|
| 624 | // encode sign bit of residual |
---|
| 625 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
| 626 | |
---|
| 627 | #if H_3D_DIM_DLT |
---|
| 628 | UInt uiNumDepthValues = pcCU->getSlice()->getVPS()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() ); |
---|
| 629 | #else |
---|
| 630 | UInt uiNumDepthValues = ((1 << g_bitDepthY)-1); |
---|
| 631 | #endif |
---|
| 632 | assert(uiAbsIdx <= uiNumDepthValues); |
---|
| 633 | |
---|
| 634 | // encode residual magnitude |
---|
| 635 | uiAbsIdx -= 1; |
---|
| 636 | // prefix part |
---|
| 637 | if ( uiAbsIdx == 0 ) |
---|
| 638 | m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) ); |
---|
| 639 | else |
---|
| 640 | { |
---|
| 641 | UInt l = uiAbsIdx; |
---|
| 642 | UInt k = 0; |
---|
| 643 | UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2); |
---|
| 644 | while ( l > 0 && k < uiPrefixThreshold ) |
---|
| 645 | { |
---|
| 646 | m_pcBinIf->encodeBin( 1, m_cSDCResidualSCModel.get(0, 0, 0) ); |
---|
| 647 | l--; |
---|
| 648 | k++; |
---|
| 649 | } |
---|
| 650 | if ( uiAbsIdx < uiPrefixThreshold ) |
---|
| 651 | m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) ); |
---|
| 652 | // suffix part |
---|
| 653 | else |
---|
| 654 | { |
---|
| 655 | uiAbsIdx -= uiPrefixThreshold; |
---|
| 656 | UInt uiSuffixLength = numBitsForValue(uiNumDepthValues - uiPrefixThreshold); |
---|
| 657 | UInt uiBitInfo = 0; |
---|
| 658 | for ( Int i = 0; i < uiSuffixLength; i++) |
---|
| 659 | { |
---|
| 660 | uiBitInfo = ( uiAbsIdx & ( 1 << i ) ) >> i; |
---|
| 661 | m_pcBinIf->encodeBinEP( uiBitInfo); |
---|
| 662 | } |
---|
| 663 | } |
---|
| 664 | } |
---|
| 665 | |
---|
| 666 | } |
---|
| 667 | } |
---|
| 668 | #endif |
---|
| 669 | #endif |
---|
| 670 | |
---|
[324] | 671 | // SBAC RD |
---|
| 672 | Void TEncSbac::load ( TEncSbac* pSrc) |
---|
| 673 | { |
---|
| 674 | this->xCopyFrom(pSrc); |
---|
| 675 | } |
---|
| 676 | |
---|
| 677 | Void TEncSbac::loadIntraDirModeLuma( TEncSbac* pSrc) |
---|
| 678 | { |
---|
| 679 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
| 680 | |
---|
| 681 | this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); |
---|
| 682 | } |
---|
[531] | 683 | #if H_3D_DIM |
---|
| 684 | Void TEncSbac::loadIntraDepthMode( TEncSbac* pSrc) |
---|
| 685 | { |
---|
| 686 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
[324] | 687 | |
---|
[531] | 688 | this->m_cDepthIntraModeSCModel .copyFrom( &pSrc->m_cDepthIntraModeSCModel ); |
---|
| 689 | this->m_cDdcFlagSCModel .copyFrom( &pSrc->m_cDdcFlagSCModel ); |
---|
| 690 | } |
---|
| 691 | #endif |
---|
[324] | 692 | |
---|
| 693 | Void TEncSbac::store( TEncSbac* pDest) |
---|
| 694 | { |
---|
| 695 | pDest->xCopyFrom( this ); |
---|
| 696 | } |
---|
| 697 | |
---|
| 698 | |
---|
| 699 | Void TEncSbac::xCopyFrom( TEncSbac* pSrc ) |
---|
| 700 | { |
---|
| 701 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
| 702 | |
---|
| 703 | this->m_uiCoeffCost = pSrc->m_uiCoeffCost; |
---|
| 704 | this->m_uiLastQp = pSrc->m_uiLastQp; |
---|
| 705 | |
---|
| 706 | memcpy( m_contextModels, pSrc->m_contextModels, m_numContextModels * sizeof( ContextModel ) ); |
---|
| 707 | } |
---|
| 708 | |
---|
| 709 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 710 | { |
---|
| 711 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
| 712 | Int iNum = AMVP_MAX_NUM_CANDS; |
---|
| 713 | |
---|
| 714 | xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1); |
---|
[521] | 715 | #if H_MV_ENC_DEC_TRAC |
---|
| 716 | #if ENC_DEC_TRACE |
---|
| 717 | if ( eRefList == REF_PIC_LIST_0 ) |
---|
| 718 | { |
---|
| 719 | DTRACE_PU("mvp_l0_flag", iSymbol) |
---|
| 720 | } |
---|
| 721 | else |
---|
| 722 | { |
---|
| 723 | DTRACE_PU("mvp_l1_flag", iSymbol) |
---|
| 724 | } |
---|
| 725 | #endif |
---|
| 726 | #endif |
---|
[324] | 727 | } |
---|
| 728 | |
---|
| 729 | Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 730 | { |
---|
| 731 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
[539] | 732 | #if H_3D_QTLPC |
---|
| 733 | TComSPS *sps = pcCU->getPic()->getSlice(0)->getSPS(); |
---|
| 734 | TComPic *pcTexture = pcCU->getSlice()->getTexturePic(); |
---|
| 735 | Bool bDepthMapDetect = (pcTexture != NULL); |
---|
| 736 | Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE); |
---|
| 737 | |
---|
| 738 | Bool rapPic = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA); |
---|
| 739 | |
---|
| 740 | if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && pcCU->getPic()->getReduceBitsFlag() && sps->getUseQTL() && sps->getUsePC() ) |
---|
| 741 | { |
---|
| 742 | TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr()); |
---|
| 743 | UInt uiCUIdx = (pcCU->getZorderIdxInCU() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU(); |
---|
| 744 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); |
---|
| 745 | if (pcTextureCU->getDepth(uiCUIdx) == uiDepth && pcTextureCU->getPartitionSize( uiCUIdx ) != SIZE_NxN) |
---|
| 746 | { |
---|
| 747 | assert( eSize == SIZE_2Nx2N ); |
---|
| 748 | return; |
---|
| 749 | } |
---|
| 750 | } |
---|
| 751 | #endif |
---|
[324] | 752 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 753 | { |
---|
| 754 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 755 | { |
---|
| 756 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
[521] | 757 | #if H_MV_ENC_DEC_TRAC |
---|
| 758 | DTRACE_CU("part_mode", eSize == SIZE_2Nx2N? 1 : 0) |
---|
| 759 | #endif |
---|
[324] | 760 | } |
---|
| 761 | return; |
---|
| 762 | } |
---|
| 763 | |
---|
[521] | 764 | #if H_MV_ENC_DEC_TRAC |
---|
| 765 | DTRACE_CU("part_mode", eSize ) |
---|
| 766 | #endif |
---|
[324] | 767 | switch(eSize) |
---|
| 768 | { |
---|
| 769 | case SIZE_2Nx2N: |
---|
| 770 | { |
---|
| 771 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 772 | break; |
---|
| 773 | } |
---|
| 774 | case SIZE_2NxN: |
---|
| 775 | case SIZE_2NxnU: |
---|
| 776 | case SIZE_2NxnD: |
---|
| 777 | { |
---|
| 778 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 779 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
| 780 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
| 781 | { |
---|
| 782 | if (eSize == SIZE_2NxN) |
---|
| 783 | { |
---|
| 784 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 785 | } |
---|
| 786 | else |
---|
| 787 | { |
---|
| 788 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 789 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
| 790 | } |
---|
| 791 | } |
---|
| 792 | break; |
---|
| 793 | } |
---|
| 794 | case SIZE_Nx2N: |
---|
| 795 | case SIZE_nLx2N: |
---|
| 796 | case SIZE_nRx2N: |
---|
| 797 | { |
---|
| 798 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 799 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
| 800 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
| 801 | { |
---|
| 802 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
| 803 | } |
---|
| 804 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
| 805 | { |
---|
| 806 | if (eSize == SIZE_Nx2N) |
---|
| 807 | { |
---|
| 808 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 809 | } |
---|
| 810 | else |
---|
| 811 | { |
---|
| 812 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 813 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
| 814 | } |
---|
| 815 | } |
---|
| 816 | break; |
---|
| 817 | } |
---|
| 818 | case SIZE_NxN: |
---|
| 819 | { |
---|
| 820 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
| 821 | { |
---|
| 822 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 823 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
| 824 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
| 825 | } |
---|
| 826 | break; |
---|
| 827 | } |
---|
| 828 | default: |
---|
| 829 | { |
---|
| 830 | assert(0); |
---|
| 831 | } |
---|
| 832 | } |
---|
| 833 | } |
---|
| 834 | |
---|
| 835 | /** code prediction mode |
---|
| 836 | * \param pcCU |
---|
| 837 | * \param uiAbsPartIdx |
---|
| 838 | * \returns Void |
---|
| 839 | */ |
---|
| 840 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 841 | { |
---|
[531] | 842 | #if H_3D_DIM_SDC |
---|
| 843 | if ( pcCU->getSlice()->isIntra() ) |
---|
| 844 | { |
---|
| 845 | assert( pcCU->isIntra(uiAbsPartIdx) ); |
---|
| 846 | return; |
---|
| 847 | } |
---|
| 848 | #endif |
---|
| 849 | |
---|
[324] | 850 | // get context function is here |
---|
| 851 | Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); |
---|
| 852 | m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
[521] | 853 | #if H_MV_ENC_DEC_TRAC |
---|
| 854 | DTRACE_CU("pred_mode_flag", iPredMode == MODE_INTER ? 0 : 1); |
---|
| 855 | #endif |
---|
[324] | 856 | } |
---|
| 857 | |
---|
| 858 | Void TEncSbac::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 859 | { |
---|
| 860 | UInt uiSymbol = pcCU->getCUTransquantBypass(uiAbsPartIdx); |
---|
| 861 | m_pcBinIf->encodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
[521] | 862 | #if H_MV_ENC_DEC_TRAC |
---|
| 863 | DTRACE_CU("cu_transquant_bypass_flag", uiSymbol); |
---|
| 864 | #endif |
---|
[324] | 865 | } |
---|
| 866 | |
---|
| 867 | /** code skip flag |
---|
| 868 | * \param pcCU |
---|
| 869 | * \param uiAbsPartIdx |
---|
| 870 | * \returns Void |
---|
| 871 | */ |
---|
| 872 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 873 | { |
---|
| 874 | // get context function is here |
---|
| 875 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
| 876 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
| 877 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
[521] | 878 | #if !H_MV_ENC_DEC_TRAC |
---|
[324] | 879 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 880 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
| 881 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
| 882 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
| 883 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 884 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 885 | DTRACE_CABAC_T( "\n"); |
---|
[521] | 886 | #else |
---|
| 887 | DTRACE_CU("cu_skip_flag", uiSymbol); |
---|
| 888 | #endif |
---|
[324] | 889 | } |
---|
| 890 | |
---|
| 891 | /** code merge flag |
---|
| 892 | * \param pcCU |
---|
| 893 | * \param uiAbsPartIdx |
---|
| 894 | * \returns Void |
---|
| 895 | */ |
---|
| 896 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 897 | { |
---|
| 898 | const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 899 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
| 900 | |
---|
[521] | 901 | #if H_MV_ENC_DEC_TRAC |
---|
| 902 | DTRACE_PU("merge_flag", uiSymbol); |
---|
| 903 | #else |
---|
[324] | 904 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 905 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
| 906 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 907 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
| 908 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
| 909 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
| 910 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 911 | DTRACE_CABAC_T( "\n" ); |
---|
[521] | 912 | #endif |
---|
[324] | 913 | } |
---|
| 914 | |
---|
| 915 | /** code merge index |
---|
| 916 | * \param pcCU |
---|
| 917 | * \param uiAbsPartIdx |
---|
| 918 | * \returns Void |
---|
| 919 | */ |
---|
| 920 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 921 | { |
---|
| 922 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
| 923 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
| 924 | if ( uiNumCand > 1 ) |
---|
| 925 | { |
---|
| 926 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
| 927 | { |
---|
| 928 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
| 929 | if ( ui==0 ) |
---|
| 930 | { |
---|
| 931 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
| 932 | } |
---|
| 933 | else |
---|
| 934 | { |
---|
| 935 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
| 936 | } |
---|
| 937 | if( uiSymbol == 0 ) |
---|
| 938 | { |
---|
| 939 | break; |
---|
| 940 | } |
---|
| 941 | } |
---|
[521] | 942 | #if H_MV_ENC_DEC_TRAC |
---|
| 943 | DTRACE_PU("merge_idx", uiUnaryIdx); |
---|
| 944 | #endif |
---|
[324] | 945 | } |
---|
[521] | 946 | #if !H_MV_ENC_DEC_TRAC |
---|
[324] | 947 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 948 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
| 949 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
| 950 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
| 951 | DTRACE_CABAC_T( "\n" ); |
---|
[521] | 952 | #endif |
---|
[324] | 953 | } |
---|
| 954 | |
---|
[504] | 955 | #if H_3D_ARP |
---|
| 956 | Void TEncSbac::codeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 957 | { |
---|
| 958 | Int iW = (Int)pcCU->getARPW( uiAbsPartIdx ); |
---|
| 959 | Int iMaxW = pcCU->getSlice()->getARPStepNum() - 1; |
---|
| 960 | assert( iMaxW > 0); |
---|
| 961 | |
---|
| 962 | Int nOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx); |
---|
| 963 | Int nBinNum = iW + ( iW != iMaxW ); |
---|
| 964 | m_pcBinIf->encodeBin( iW ? 1 : 0 , m_cCUPUARPWSCModel.get( 0, 0, 0 + nOffset ) ); |
---|
| 965 | if( nBinNum > 1 ) |
---|
| 966 | { |
---|
| 967 | m_pcBinIf->encodeBin( ( iW == iMaxW ) ? 1 : 0, m_cCUPUARPWSCModel.get( 0, 0, 3 ) ); |
---|
| 968 | } |
---|
[521] | 969 | #if H_MV_ENC_DEC_TRAC |
---|
| 970 | DTRACE_CU("iv_res_pred_weight_idx", iW); |
---|
| 971 | #endif |
---|
[504] | 972 | } |
---|
| 973 | #endif |
---|
| 974 | |
---|
| 975 | #if H_3D_IC |
---|
| 976 | /** code Illumination Compensation flag |
---|
| 977 | * \param pcCU |
---|
| 978 | * \param uiAbsPartIdx |
---|
| 979 | * \returns Void |
---|
| 980 | */ |
---|
| 981 | Void TEncSbac::codeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 982 | { |
---|
| 983 | // get context function is here |
---|
| 984 | UInt uiSymbol = pcCU->getICFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 985 | UInt uiCtxIC = pcCU->getCtxICFlag( uiAbsPartIdx ) ; |
---|
| 986 | m_pcBinIf->encodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, uiCtxIC ) ); |
---|
[521] | 987 | #if !H_MV_ENC_DEC_TRAC |
---|
[504] | 988 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 989 | DTRACE_CABAC_T( "\tICFlag" ); |
---|
| 990 | DTRACE_CABAC_T( "\tuiCtxIC: "); |
---|
| 991 | DTRACE_CABAC_V( uiCtxIC ); |
---|
| 992 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 993 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 994 | DTRACE_CABAC_T( "\n"); |
---|
[521] | 995 | #else |
---|
| 996 | DTRACE_CU("ic_flag", uiSymbol ); |
---|
| 997 | #endif |
---|
[504] | 998 | } |
---|
| 999 | #endif |
---|
| 1000 | |
---|
| 1001 | |
---|
[324] | 1002 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1003 | { |
---|
| 1004 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 1005 | return; |
---|
| 1006 | |
---|
| 1007 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
| 1008 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
| 1009 | |
---|
| 1010 | assert( uiCtx < 3 ); |
---|
[539] | 1011 | #if H_3D_QTLPC |
---|
| 1012 | Bool bCodeSplitFlag = true; |
---|
| 1013 | |
---|
| 1014 | TComSPS *sps = pcCU->getPic()->getSlice(0)->getSPS(); |
---|
| 1015 | TComPic *pcTexture = pcCU->getSlice()->getTexturePic(); |
---|
| 1016 | Bool bDepthMapDetect = (pcTexture != NULL); |
---|
| 1017 | Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE); |
---|
| 1018 | |
---|
| 1019 | Bool rapPic = (pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || pcCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA); |
---|
| 1020 | |
---|
| 1021 | if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && pcCU->getPic()->getReduceBitsFlag() && sps->getUseQTL() && sps->getUsePC()) |
---|
| 1022 | { |
---|
| 1023 | TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr()); |
---|
| 1024 | UInt uiCUIdx = (pcCU->getZorderIdxInCU() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU(); |
---|
| 1025 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); |
---|
| 1026 | bCodeSplitFlag = (pcTextureCU->getDepth(uiCUIdx) > uiDepth); |
---|
| 1027 | } |
---|
| 1028 | |
---|
| 1029 | if(!bCodeSplitFlag) |
---|
| 1030 | { |
---|
| 1031 | assert(uiCurrSplitFlag == 0); |
---|
| 1032 | return; |
---|
| 1033 | } |
---|
| 1034 | #endif |
---|
[324] | 1035 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
[521] | 1036 | #if !H_MV_ENC_DEC_TRAC |
---|
[324] | 1037 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1038 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
[521] | 1039 | #else |
---|
| 1040 | DTRACE_CU("split_cu_flag", uiCurrSplitFlag ); |
---|
| 1041 | #endif |
---|
[324] | 1042 | return; |
---|
| 1043 | } |
---|
| 1044 | |
---|
| 1045 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
| 1046 | { |
---|
| 1047 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
[521] | 1048 | #if !H_MV_ENC_DEC_TRAC |
---|
[324] | 1049 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1050 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
| 1051 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1052 | DTRACE_CABAC_V( uiSymbol ) |
---|
| 1053 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 1054 | DTRACE_CABAC_V( uiCtx ) |
---|
| 1055 | DTRACE_CABAC_T( "\n" ) |
---|
[521] | 1056 | #endif |
---|
[324] | 1057 | } |
---|
| 1058 | |
---|
| 1059 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple) |
---|
| 1060 | { |
---|
| 1061 | UInt dir[4],j; |
---|
| 1062 | Int preds[4][3] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}}; |
---|
| 1063 | Int predNum[4], predIdx[4] ={ -1,-1,-1,-1}; |
---|
| 1064 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
| 1065 | UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1; |
---|
| 1066 | UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
| 1067 | for (j=0;j<partNum;j++) |
---|
| 1068 | { |
---|
| 1069 | dir[j] = pcCU->getLumaIntraDir( absPartIdx+partOffset*j ); |
---|
[531] | 1070 | #if H_3D_DIM |
---|
| 1071 | if( pcCU->getSlice()->getVpsDepthModesFlag() ) |
---|
| 1072 | { |
---|
| 1073 | codeIntraDepth( pcCU, absPartIdx+partOffset*j ); |
---|
| 1074 | } |
---|
| 1075 | if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) |
---|
| 1076 | #if H_3D_DIM_SDC |
---|
| 1077 | if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) ) |
---|
| 1078 | #endif |
---|
| 1079 | { |
---|
| 1080 | #endif |
---|
[324] | 1081 | predNum[j] = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds[j]); |
---|
| 1082 | for(UInt i = 0; i < predNum[j]; i++) |
---|
| 1083 | { |
---|
| 1084 | if(dir[j] == preds[j][i]) |
---|
| 1085 | { |
---|
| 1086 | predIdx[j] = i; |
---|
| 1087 | } |
---|
| 1088 | } |
---|
| 1089 | m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
[521] | 1090 | #if H_MV_ENC_DEC_TRAC |
---|
| 1091 | DTRACE_CU("prev_intra_luma_pred_flag", (predIdx[j] != -1)? 1 : 0); |
---|
| 1092 | #endif |
---|
[531] | 1093 | #if H_3D_DIM |
---|
| 1094 | } |
---|
| 1095 | #endif |
---|
| 1096 | |
---|
[324] | 1097 | } |
---|
| 1098 | for (j=0;j<partNum;j++) |
---|
| 1099 | { |
---|
[531] | 1100 | #if H_3D_DIM |
---|
| 1101 | if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) |
---|
| 1102 | #if H_3D_DIM_SDC |
---|
| 1103 | if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) ) |
---|
| 1104 | #endif |
---|
| 1105 | { |
---|
| 1106 | #endif |
---|
[324] | 1107 | if(predIdx[j] != -1) |
---|
| 1108 | { |
---|
| 1109 | m_pcBinIf->encodeBinEP( predIdx[j] ? 1 : 0 ); |
---|
| 1110 | if (predIdx[j]) |
---|
| 1111 | { |
---|
| 1112 | m_pcBinIf->encodeBinEP( predIdx[j]-1 ); |
---|
| 1113 | } |
---|
[521] | 1114 | #if H_MV_ENC_DEC_TRAC |
---|
| 1115 | DTRACE_CU("mpm_idx", predIdx[j] ); |
---|
| 1116 | #endif |
---|
[324] | 1117 | } |
---|
| 1118 | else |
---|
| 1119 | { |
---|
| 1120 | if (preds[j][0] > preds[j][1]) |
---|
| 1121 | { |
---|
| 1122 | std::swap(preds[j][0], preds[j][1]); |
---|
| 1123 | } |
---|
| 1124 | if (preds[j][0] > preds[j][2]) |
---|
| 1125 | { |
---|
| 1126 | std::swap(preds[j][0], preds[j][2]); |
---|
| 1127 | } |
---|
| 1128 | if (preds[j][1] > preds[j][2]) |
---|
| 1129 | { |
---|
| 1130 | std::swap(preds[j][1], preds[j][2]); |
---|
| 1131 | } |
---|
| 1132 | for(Int i = (predNum[j] - 1); i >= 0; i--) |
---|
| 1133 | { |
---|
| 1134 | dir[j] = dir[j] > preds[j][i] ? dir[j] - 1 : dir[j]; |
---|
| 1135 | } |
---|
| 1136 | m_pcBinIf->encodeBinsEP( dir[j], 5 ); |
---|
[521] | 1137 | #if H_MV_ENC_DEC_TRAC |
---|
| 1138 | DTRACE_CU("rem_intra_luma_pred_mode", dir[j] ); |
---|
| 1139 | #endif |
---|
[324] | 1140 | } |
---|
[531] | 1141 | #if H_3D_DIM |
---|
| 1142 | } |
---|
| 1143 | #endif |
---|
[324] | 1144 | } |
---|
| 1145 | return; |
---|
| 1146 | } |
---|
| 1147 | |
---|
| 1148 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1149 | { |
---|
| 1150 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx ); |
---|
| 1151 | |
---|
| 1152 | if( uiIntraDirChroma == DM_CHROMA_IDX ) |
---|
| 1153 | { |
---|
| 1154 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
[521] | 1155 | #if H_MV_ENC_DEC_TRAC |
---|
| 1156 | DTRACE_CU("intra_chroma_pred_mode", 0 ); |
---|
| 1157 | #endif |
---|
[324] | 1158 | } |
---|
| 1159 | else |
---|
| 1160 | { |
---|
| 1161 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
| 1162 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
| 1163 | |
---|
| 1164 | for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ ) |
---|
| 1165 | { |
---|
| 1166 | if( uiIntraDirChroma == uiAllowedChromaDir[i] ) |
---|
| 1167 | { |
---|
| 1168 | uiIntraDirChroma = i; |
---|
| 1169 | break; |
---|
| 1170 | } |
---|
| 1171 | } |
---|
| 1172 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
| 1173 | |
---|
| 1174 | m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); |
---|
[521] | 1175 | #if H_MV_ENC_DEC_TRAC |
---|
| 1176 | DTRACE_CU("intra_chroma_pred_mode", uiIntraDirChroma ); |
---|
| 1177 | #endif |
---|
| 1178 | |
---|
[324] | 1179 | } |
---|
| 1180 | return; |
---|
| 1181 | } |
---|
| 1182 | |
---|
[531] | 1183 | #if H_3D_DIM |
---|
| 1184 | Void TEncSbac::codeIntraDepth( TComDataCU* pcCU, UInt absPartIdx ) |
---|
| 1185 | { |
---|
| 1186 | codeIntraDepthMode( pcCU, absPartIdx ); |
---|
| 1187 | |
---|
| 1188 | UInt dir = pcCU->getLumaIntraDir( absPartIdx ); |
---|
| 1189 | UInt dimType = getDimType( dir ); |
---|
| 1190 | |
---|
| 1191 | switch( dimType ) |
---|
| 1192 | { |
---|
| 1193 | #if H_3D_DIM_DMM |
---|
| 1194 | case( DMM1_IDX ): |
---|
| 1195 | { |
---|
| 1196 | xCodeDmm1WedgeIdx( pcCU->getDmmWedgeTabIdx( dimType, absPartIdx ), g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] ); |
---|
| 1197 | } break; |
---|
| 1198 | case( DMM2_IDX ): |
---|
| 1199 | { |
---|
| 1200 | xCodeDmm2Offset( pcCU->getDmm2DeltaEnd( absPartIdx ) ); |
---|
| 1201 | } break; |
---|
| 1202 | case( DMM3_IDX ): |
---|
| 1203 | { |
---|
| 1204 | xCodeDmm3WedgeIdx( pcCU->getDmm3IntraTabIdx( absPartIdx ), g_dmm3IntraTabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] ); |
---|
| 1205 | } break; |
---|
| 1206 | case( DMM4_IDX ): break; |
---|
| 1207 | #endif |
---|
| 1208 | #if H_3D_DIM_RBC |
---|
| 1209 | case( RBC_IDX ): |
---|
| 1210 | { |
---|
| 1211 | assert( pcCU->getWidth( absPartIdx ) < 64 ); |
---|
| 1212 | xCodeRbcEdge( pcCU, absPartIdx ); |
---|
| 1213 | } break; |
---|
| 1214 | #endif |
---|
| 1215 | default: break; |
---|
| 1216 | } |
---|
| 1217 | |
---|
| 1218 | #if H_3D_DIM_SDC |
---|
| 1219 | if( pcCU->getSDCFlag( absPartIdx ) ) |
---|
| 1220 | { |
---|
| 1221 | assert(pcCU->getPartitionSize(absPartIdx)==SIZE_2Nx2N); |
---|
| 1222 | UInt uiNumSegments = ( dir == DC_IDX || dir == PLANAR_IDX )? 1 : 2; |
---|
| 1223 | for(UInt uiSeg=0; uiSeg<uiNumSegments; uiSeg++) |
---|
| 1224 | { |
---|
| 1225 | xCodeSDCResidualData(pcCU, absPartIdx, uiSeg); |
---|
| 1226 | } |
---|
| 1227 | } |
---|
| 1228 | else |
---|
| 1229 | { |
---|
| 1230 | #endif |
---|
| 1231 | if( dimType < DIM_NUM_TYPE ) |
---|
| 1232 | { |
---|
| 1233 | UInt dimDeltaDC = isDimDeltaDC( dir ); |
---|
| 1234 | m_pcBinIf->encodeBin( dimDeltaDC, m_cDdcFlagSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) ); |
---|
| 1235 | if( dimDeltaDC ) |
---|
| 1236 | { |
---|
| 1237 | for( UInt segment = 0; segment < 2; segment++ ) |
---|
| 1238 | { |
---|
| 1239 | xCodeDimDeltaDC( pcCU->getDimDeltaDC( dimType, segment, absPartIdx ), dimType ); |
---|
| 1240 | } |
---|
| 1241 | } |
---|
| 1242 | } |
---|
| 1243 | #if H_3D_DIM_SDC |
---|
| 1244 | } |
---|
| 1245 | #endif |
---|
| 1246 | } |
---|
| 1247 | |
---|
| 1248 | Void TEncSbac::codeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx ) |
---|
| 1249 | { |
---|
| 1250 | UInt codeWordTable[3][9] = {{0, 0, 0, 2, 0,6, 0, 0, 7},{0, 2, 3, 4, 5, 6, 14, 31, 30},{0, 2, 0, 0, 0, 0, 3, 0, 0}}; |
---|
| 1251 | UInt codeWordLenTable[3][9] = {{0, 1, 0, 2, 0,3, 0, 0, 3},{2, 3, 3, 3, 3, 3, 4, 5, 5},{1, 2, 0, 0, 0, 0, 2, 0, 0}}; |
---|
| 1252 | UInt dir = pcCU->getLumaIntraDir( absPartIdx ); |
---|
| 1253 | UInt puIdx = (pcCU->getWidth(absPartIdx) == 64) ? 2 : ( (pcCU->getPartitionSize(absPartIdx) == SIZE_NxN && pcCU->getWidth(absPartIdx) == 8) ? 0 : 1 ); |
---|
| 1254 | UInt codeIdx = 0; |
---|
| 1255 | |
---|
| 1256 | if( dir < NUM_INTRA_MODE ) |
---|
| 1257 | { |
---|
| 1258 | codeIdx = 1; |
---|
| 1259 | } |
---|
| 1260 | if( isDimMode( dir ) ) |
---|
| 1261 | { |
---|
| 1262 | switch( getDimType( dir ) ) |
---|
| 1263 | { |
---|
| 1264 | case DMM1_IDX: codeIdx = 3; break; |
---|
| 1265 | case DMM4_IDX: codeIdx = 4; break; |
---|
| 1266 | case DMM3_IDX: codeIdx = 5; break; |
---|
| 1267 | case DMM2_IDX: codeIdx = 7; break; |
---|
| 1268 | case RBC_IDX: codeIdx = 8; break; |
---|
| 1269 | default: break; |
---|
| 1270 | } |
---|
| 1271 | } |
---|
| 1272 | |
---|
| 1273 | #if H_3D_DIM_SDC |
---|
| 1274 | if( pcCU->getSDCFlag( absPartIdx ) ) |
---|
| 1275 | { |
---|
| 1276 | switch( dir ) |
---|
| 1277 | { |
---|
| 1278 | case PLANAR_IDX: codeIdx = 0; break; |
---|
| 1279 | case DC_IDX: codeIdx = 6; break; |
---|
| 1280 | default: codeIdx = 2; break; |
---|
| 1281 | } |
---|
| 1282 | } |
---|
| 1283 | #endif |
---|
| 1284 | //mode coding |
---|
| 1285 | for( UInt i = 0; i < codeWordLenTable[puIdx][codeIdx]; i++ ) |
---|
| 1286 | { |
---|
| 1287 | UInt bit = codeWordTable[puIdx][codeIdx] & ( 1<<(codeWordLenTable[puIdx][codeIdx] - i - 1) ); |
---|
| 1288 | UInt ctxDepthMode = puIdx*3 + ( (i >= 2) ? 2 : i ); |
---|
| 1289 | m_pcBinIf->encodeBin( bit!=0 , m_cDepthIntraModeSCModel.get(0, 0, ctxDepthMode) ); |
---|
| 1290 | } |
---|
| 1291 | } |
---|
| 1292 | #endif |
---|
| 1293 | |
---|
| 1294 | |
---|
[324] | 1295 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1296 | { |
---|
| 1297 | const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1; |
---|
| 1298 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
| 1299 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
| 1300 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
| 1301 | { |
---|
| 1302 | m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); |
---|
| 1303 | } |
---|
| 1304 | if (uiInterDir < 2) |
---|
| 1305 | { |
---|
| 1306 | m_pcBinIf->encodeBin( uiInterDir, *( pCtx + 4 ) ); |
---|
| 1307 | } |
---|
[521] | 1308 | #if H_MV_ENC_DEC_TRAC |
---|
| 1309 | DTRACE_PU("inter_pred_idc", uiInterDir ); |
---|
| 1310 | #endif |
---|
| 1311 | |
---|
[324] | 1312 | return; |
---|
| 1313 | } |
---|
| 1314 | |
---|
| 1315 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1316 | { |
---|
| 1317 | { |
---|
| 1318 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
| 1319 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
| 1320 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
| 1321 | |
---|
| 1322 | if( iRefFrame > 0 ) |
---|
| 1323 | { |
---|
| 1324 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
| 1325 | pCtx++; |
---|
| 1326 | iRefFrame--; |
---|
| 1327 | for( UInt ui = 0; ui < uiRefNum; ++ui ) |
---|
| 1328 | { |
---|
| 1329 | const UInt uiSymbol = ui == iRefFrame ? 0 : 1; |
---|
| 1330 | if( ui == 0 ) |
---|
| 1331 | { |
---|
| 1332 | m_pcBinIf->encodeBin( uiSymbol, *pCtx ); |
---|
| 1333 | } |
---|
| 1334 | else |
---|
| 1335 | { |
---|
| 1336 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
| 1337 | } |
---|
| 1338 | if( uiSymbol == 0 ) |
---|
| 1339 | { |
---|
| 1340 | break; |
---|
| 1341 | } |
---|
| 1342 | } |
---|
| 1343 | } |
---|
[521] | 1344 | #if H_MV_ENC_DEC_TRAC |
---|
| 1345 | #if ENC_DEC_TRACE |
---|
| 1346 | iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
| 1347 | if ( eRefList == REF_PIC_LIST_0 ) |
---|
| 1348 | { |
---|
| 1349 | DTRACE_PU("ref_idx_l0", iRefFrame) |
---|
| 1350 | } |
---|
| 1351 | else |
---|
| 1352 | { |
---|
| 1353 | DTRACE_PU("ref_idx_l1", iRefFrame) |
---|
| 1354 | } |
---|
| 1355 | #endif |
---|
| 1356 | #endif |
---|
[324] | 1357 | } |
---|
| 1358 | return; |
---|
| 1359 | } |
---|
| 1360 | |
---|
| 1361 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1362 | { |
---|
| 1363 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
| 1364 | { |
---|
| 1365 | return; |
---|
| 1366 | } |
---|
| 1367 | |
---|
| 1368 | const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
| 1369 | const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
| 1370 | const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
| 1371 | ContextModel* pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
| 1372 | |
---|
| 1373 | m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx ); |
---|
| 1374 | m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx ); |
---|
| 1375 | |
---|
| 1376 | const Bool bHorAbsGr0 = iHor != 0; |
---|
| 1377 | const Bool bVerAbsGr0 = iVer != 0; |
---|
| 1378 | const UInt uiHorAbs = 0 > iHor ? -iHor : iHor; |
---|
| 1379 | const UInt uiVerAbs = 0 > iVer ? -iVer : iVer; |
---|
| 1380 | pCtx++; |
---|
| 1381 | |
---|
| 1382 | if( bHorAbsGr0 ) |
---|
| 1383 | { |
---|
| 1384 | m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx ); |
---|
| 1385 | } |
---|
| 1386 | |
---|
| 1387 | if( bVerAbsGr0 ) |
---|
| 1388 | { |
---|
| 1389 | m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx ); |
---|
| 1390 | } |
---|
| 1391 | |
---|
| 1392 | if( bHorAbsGr0 ) |
---|
| 1393 | { |
---|
| 1394 | if( uiHorAbs > 1 ) |
---|
| 1395 | { |
---|
| 1396 | xWriteEpExGolomb( uiHorAbs-2, 1 ); |
---|
| 1397 | } |
---|
| 1398 | |
---|
| 1399 | m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 ); |
---|
| 1400 | } |
---|
| 1401 | |
---|
| 1402 | if( bVerAbsGr0 ) |
---|
| 1403 | { |
---|
| 1404 | if( uiVerAbs > 1 ) |
---|
| 1405 | { |
---|
| 1406 | xWriteEpExGolomb( uiVerAbs-2, 1 ); |
---|
| 1407 | } |
---|
| 1408 | |
---|
| 1409 | m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); |
---|
| 1410 | } |
---|
| 1411 | |
---|
| 1412 | return; |
---|
| 1413 | } |
---|
| 1414 | |
---|
| 1415 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1416 | { |
---|
| 1417 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
| 1418 | |
---|
| 1419 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
| 1420 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
| 1421 | |
---|
| 1422 | UInt uiAbsDQp = (UInt)((iDQp > 0)? iDQp : (-iDQp)); |
---|
| 1423 | UInt TUValue = min((Int)uiAbsDQp, CU_DQP_TU_CMAX); |
---|
| 1424 | xWriteUnaryMaxSymbol( TUValue, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
| 1425 | if( uiAbsDQp >= CU_DQP_TU_CMAX ) |
---|
| 1426 | { |
---|
| 1427 | xWriteEpExGolomb( uiAbsDQp - CU_DQP_TU_CMAX, CU_DQP_EG_k ); |
---|
| 1428 | } |
---|
| 1429 | |
---|
| 1430 | if ( uiAbsDQp > 0) |
---|
| 1431 | { |
---|
| 1432 | UInt uiSign = (iDQp > 0 ? 0 : 1); |
---|
| 1433 | m_pcBinIf->encodeBinEP(uiSign); |
---|
| 1434 | } |
---|
| 1435 | |
---|
| 1436 | return; |
---|
| 1437 | } |
---|
| 1438 | |
---|
| 1439 | Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
| 1440 | { |
---|
| 1441 | UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
| 1442 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
| 1443 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
[521] | 1444 | #if !H_MV_ENC_DEC_TRAC |
---|
[324] | 1445 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1446 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
| 1447 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1448 | DTRACE_CABAC_V( uiCbf ) |
---|
| 1449 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 1450 | DTRACE_CABAC_V( uiCtx ) |
---|
| 1451 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 1452 | DTRACE_CABAC_V( eType ) |
---|
| 1453 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 1454 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1455 | DTRACE_CABAC_T( "\n" ) |
---|
[521] | 1456 | #endif |
---|
[324] | 1457 | } |
---|
| 1458 | |
---|
| 1459 | void TEncSbac::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) |
---|
| 1460 | { |
---|
| 1461 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
| 1462 | { |
---|
| 1463 | return; |
---|
| 1464 | } |
---|
| 1465 | if(width != 4 || height != 4) |
---|
| 1466 | { |
---|
| 1467 | return; |
---|
| 1468 | } |
---|
| 1469 | |
---|
| 1470 | UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,eTType); |
---|
| 1471 | m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) ); |
---|
[521] | 1472 | #if !H_MV_ENC_DEC_TRAC |
---|
[324] | 1473 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1474 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
| 1475 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1476 | DTRACE_CABAC_V( useTransformSkip ) |
---|
| 1477 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
| 1478 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
| 1479 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 1480 | DTRACE_CABAC_V( eTType ) |
---|
| 1481 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 1482 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1483 | DTRACE_CABAC_T( "\n" ) |
---|
[521] | 1484 | #endif |
---|
[324] | 1485 | } |
---|
| 1486 | |
---|
| 1487 | /** Code I_PCM information. |
---|
| 1488 | * \param pcCU pointer to CU |
---|
| 1489 | * \param uiAbsPartIdx CU index |
---|
| 1490 | * \returns Void |
---|
| 1491 | */ |
---|
| 1492 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1493 | { |
---|
| 1494 | UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0; |
---|
| 1495 | |
---|
| 1496 | Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx); |
---|
| 1497 | |
---|
| 1498 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
[521] | 1499 | #if H_MV_ENC_DEC_TRAC |
---|
| 1500 | DTRACE_CU("pcm_flag", uiIPCM) |
---|
| 1501 | #endif |
---|
[324] | 1502 | if (writePCMSampleFlag) |
---|
| 1503 | { |
---|
| 1504 | m_pcBinIf->encodePCMAlignBits(); |
---|
| 1505 | |
---|
| 1506 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
| 1507 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
| 1508 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
| 1509 | Pel* piPCMSample; |
---|
| 1510 | UInt uiWidth; |
---|
| 1511 | UInt uiHeight; |
---|
| 1512 | UInt uiSampleBits; |
---|
| 1513 | UInt uiX, uiY; |
---|
| 1514 | |
---|
| 1515 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
| 1516 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
| 1517 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
| 1518 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
| 1519 | |
---|
| 1520 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 1521 | { |
---|
| 1522 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 1523 | { |
---|
| 1524 | UInt uiSample = piPCMSample[uiX]; |
---|
| 1525 | |
---|
| 1526 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
| 1527 | } |
---|
| 1528 | piPCMSample += uiWidth; |
---|
| 1529 | } |
---|
| 1530 | |
---|
| 1531 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
| 1532 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
| 1533 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
| 1534 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
| 1535 | |
---|
| 1536 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 1537 | { |
---|
| 1538 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 1539 | { |
---|
| 1540 | UInt uiSample = piPCMSample[uiX]; |
---|
| 1541 | |
---|
| 1542 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
| 1543 | } |
---|
| 1544 | piPCMSample += uiWidth; |
---|
| 1545 | } |
---|
| 1546 | |
---|
| 1547 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
| 1548 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
| 1549 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
| 1550 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
| 1551 | |
---|
| 1552 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 1553 | { |
---|
| 1554 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 1555 | { |
---|
| 1556 | UInt uiSample = piPCMSample[uiX]; |
---|
| 1557 | |
---|
| 1558 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
| 1559 | } |
---|
| 1560 | piPCMSample += uiWidth; |
---|
| 1561 | } |
---|
| 1562 | m_pcBinIf->resetBac(); |
---|
| 1563 | } |
---|
| 1564 | } |
---|
| 1565 | |
---|
| 1566 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1567 | { |
---|
| 1568 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
| 1569 | UInt uiCtx = 0; |
---|
| 1570 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
[521] | 1571 | #if !H_MV_ENC_DEC_TRAC |
---|
[324] | 1572 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1573 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
| 1574 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1575 | DTRACE_CABAC_V( uiCbf ) |
---|
| 1576 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 1577 | DTRACE_CABAC_V( uiCtx ) |
---|
| 1578 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 1579 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1580 | DTRACE_CABAC_T( "\n" ) |
---|
[521] | 1581 | #else |
---|
| 1582 | DTRACE_CU( "rqt_root_cbf", uiCbf ) |
---|
| 1583 | #endif |
---|
[324] | 1584 | } |
---|
| 1585 | |
---|
| 1586 | Void TEncSbac::codeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
---|
| 1587 | { |
---|
| 1588 | // this function is only used to estimate the bits when cbf is 0 |
---|
| 1589 | // and will never be called when writing the bistream. do not need to write log |
---|
| 1590 | UInt uiCbf = 0; |
---|
| 1591 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
| 1592 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
| 1593 | } |
---|
| 1594 | |
---|
| 1595 | Void TEncSbac::codeQtRootCbfZero( TComDataCU* pcCU ) |
---|
| 1596 | { |
---|
| 1597 | // this function is only used to estimate the bits when cbf is 0 |
---|
| 1598 | // and will never be called when writing the bistream. do not need to write log |
---|
| 1599 | UInt uiCbf = 0; |
---|
| 1600 | UInt uiCtx = 0; |
---|
| 1601 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
| 1602 | } |
---|
| 1603 | |
---|
| 1604 | /** Encode (X,Y) position of the last significant coefficient |
---|
| 1605 | * \param uiPosX X component of last coefficient |
---|
| 1606 | * \param uiPosY Y component of last coefficient |
---|
| 1607 | * \param width Block width |
---|
| 1608 | * \param height Block height |
---|
| 1609 | * \param eTType plane type / luminance or chrominance |
---|
| 1610 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
| 1611 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
| 1612 | */ |
---|
| 1613 | Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
| 1614 | { |
---|
| 1615 | // swap |
---|
| 1616 | if( uiScanIdx == SCAN_VER ) |
---|
| 1617 | { |
---|
| 1618 | swap( uiPosX, uiPosY ); |
---|
| 1619 | } |
---|
| 1620 | |
---|
| 1621 | UInt uiCtxLast; |
---|
| 1622 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
| 1623 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
| 1624 | UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; |
---|
| 1625 | UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; |
---|
| 1626 | |
---|
| 1627 | |
---|
| 1628 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
| 1629 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
| 1630 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
| 1631 | shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
| 1632 | shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
| 1633 | // posX |
---|
| 1634 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) |
---|
| 1635 | { |
---|
| 1636 | m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
| 1637 | } |
---|
| 1638 | if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) |
---|
| 1639 | { |
---|
| 1640 | m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
| 1641 | } |
---|
| 1642 | |
---|
| 1643 | // posY |
---|
| 1644 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) |
---|
| 1645 | { |
---|
| 1646 | m_pcBinIf->encodeBin( 1, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
| 1647 | } |
---|
| 1648 | if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ]) |
---|
| 1649 | { |
---|
| 1650 | m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
| 1651 | } |
---|
| 1652 | if ( uiGroupIdxX > 3 ) |
---|
| 1653 | { |
---|
| 1654 | UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; |
---|
| 1655 | uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; |
---|
| 1656 | for (Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
| 1657 | { |
---|
| 1658 | m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 ); |
---|
| 1659 | } |
---|
| 1660 | } |
---|
| 1661 | if ( uiGroupIdxY > 3 ) |
---|
| 1662 | { |
---|
| 1663 | UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; |
---|
| 1664 | uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; |
---|
| 1665 | for ( Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
| 1666 | { |
---|
| 1667 | m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 ); |
---|
| 1668 | } |
---|
| 1669 | } |
---|
| 1670 | } |
---|
| 1671 | |
---|
| 1672 | Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
| 1673 | { |
---|
[521] | 1674 | #if !H_MV_ENC_DEC_TRAC |
---|
[324] | 1675 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1676 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
| 1677 | DTRACE_CABAC_V( eTType ) |
---|
| 1678 | DTRACE_CABAC_T( "\twidth=" ) |
---|
| 1679 | DTRACE_CABAC_V( uiWidth ) |
---|
| 1680 | DTRACE_CABAC_T( "\theight=" ) |
---|
| 1681 | DTRACE_CABAC_V( uiHeight ) |
---|
| 1682 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
| 1683 | DTRACE_CABAC_V( uiDepth ) |
---|
| 1684 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
| 1685 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1686 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
| 1687 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
| 1688 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
| 1689 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
| 1690 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
| 1691 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
| 1692 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
| 1693 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1694 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
| 1695 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1696 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
| 1697 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
| 1698 | DTRACE_CABAC_T( "\n" ) |
---|
[521] | 1699 | #endif |
---|
[324] | 1700 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
| 1701 | { |
---|
| 1702 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
| 1703 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
| 1704 | } |
---|
| 1705 | |
---|
| 1706 | UInt uiNumSig = 0; |
---|
| 1707 | |
---|
| 1708 | // compute number of significant coefficients |
---|
| 1709 | uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); |
---|
| 1710 | |
---|
| 1711 | if ( uiNumSig == 0 ) |
---|
| 1712 | return; |
---|
| 1713 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
| 1714 | { |
---|
| 1715 | codeTransformSkipFlags( pcCU,uiAbsPartIdx, uiWidth, uiHeight, eTType ); |
---|
| 1716 | } |
---|
| 1717 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
| 1718 | |
---|
| 1719 | //----- encode significance map ----- |
---|
| 1720 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
| 1721 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
| 1722 | const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize - 1 ]; |
---|
| 1723 | |
---|
| 1724 | Bool beValid; |
---|
| 1725 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
| 1726 | { |
---|
| 1727 | beValid = false; |
---|
| 1728 | } |
---|
| 1729 | else |
---|
| 1730 | { |
---|
| 1731 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
| 1732 | } |
---|
| 1733 | |
---|
| 1734 | // Find position of last coefficient |
---|
| 1735 | Int scanPosLast = -1; |
---|
| 1736 | Int posLast; |
---|
| 1737 | |
---|
| 1738 | const UInt * scanCG; |
---|
| 1739 | { |
---|
| 1740 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
| 1741 | if( uiLog2BlockSize == 3 ) |
---|
| 1742 | { |
---|
| 1743 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
| 1744 | } |
---|
| 1745 | else if( uiLog2BlockSize == 5 ) |
---|
| 1746 | { |
---|
| 1747 | scanCG = g_sigLastScanCG32x32; |
---|
| 1748 | } |
---|
| 1749 | } |
---|
| 1750 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
| 1751 | static const UInt uiShift = MLS_CG_SIZE >> 1; |
---|
| 1752 | const UInt uiNumBlkSide = uiWidth >> uiShift; |
---|
| 1753 | |
---|
| 1754 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
| 1755 | |
---|
| 1756 | do |
---|
| 1757 | { |
---|
| 1758 | posLast = scan[ ++scanPosLast ]; |
---|
| 1759 | |
---|
| 1760 | // get L1 sig map |
---|
| 1761 | UInt uiPosY = posLast >> uiLog2BlockSize; |
---|
| 1762 | UInt uiPosX = posLast - ( uiPosY << uiLog2BlockSize ); |
---|
| 1763 | UInt uiBlkIdx = uiNumBlkSide * (uiPosY >> uiShift) + (uiPosX >> uiShift); |
---|
| 1764 | if( pcCoef[ posLast ] ) |
---|
| 1765 | { |
---|
| 1766 | uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; |
---|
| 1767 | } |
---|
| 1768 | |
---|
| 1769 | uiNumSig -= ( pcCoef[ posLast ] != 0 ); |
---|
| 1770 | } |
---|
| 1771 | while ( uiNumSig > 0 ); |
---|
| 1772 | |
---|
| 1773 | // Code position of last coefficient |
---|
| 1774 | Int posLastY = posLast >> uiLog2BlockSize; |
---|
| 1775 | Int posLastX = posLast - ( posLastY << uiLog2BlockSize ); |
---|
| 1776 | codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, eTType, uiScanIdx); |
---|
| 1777 | |
---|
| 1778 | //===== code significance flag ===== |
---|
| 1779 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
| 1780 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
| 1781 | |
---|
| 1782 | |
---|
| 1783 | const Int iLastScanSet = scanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
| 1784 | UInt c1 = 1; |
---|
| 1785 | UInt uiGoRiceParam = 0; |
---|
| 1786 | Int iScanPosSig = scanPosLast; |
---|
| 1787 | |
---|
| 1788 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
| 1789 | { |
---|
| 1790 | Int numNonZero = 0; |
---|
| 1791 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
| 1792 | uiGoRiceParam = 0; |
---|
| 1793 | Int absCoeff[16]; |
---|
| 1794 | UInt coeffSigns = 0; |
---|
| 1795 | |
---|
| 1796 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
| 1797 | |
---|
| 1798 | if( iScanPosSig == scanPosLast ) |
---|
| 1799 | { |
---|
| 1800 | absCoeff[ 0 ] = abs( pcCoef[ posLast ] ); |
---|
| 1801 | coeffSigns = ( pcCoef[ posLast ] < 0 ); |
---|
| 1802 | numNonZero = 1; |
---|
| 1803 | lastNZPosInCG = iScanPosSig; |
---|
| 1804 | firstNZPosInCG = iScanPosSig; |
---|
| 1805 | iScanPosSig--; |
---|
| 1806 | } |
---|
| 1807 | |
---|
| 1808 | // encode significant_coeffgroup_flag |
---|
| 1809 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
| 1810 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
| 1811 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
| 1812 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
| 1813 | { |
---|
| 1814 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
| 1815 | } |
---|
| 1816 | else |
---|
| 1817 | { |
---|
| 1818 | UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); |
---|
| 1819 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
| 1820 | m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
| 1821 | } |
---|
| 1822 | |
---|
| 1823 | // encode significant_coeff_flag |
---|
| 1824 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
| 1825 | { |
---|
| 1826 | Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
| 1827 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
| 1828 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
| 1829 | { |
---|
| 1830 | uiBlkPos = scan[ iScanPosSig ]; |
---|
| 1831 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
| 1832 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
| 1833 | uiSig = (pcCoef[ uiBlkPos ] != 0); |
---|
| 1834 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
| 1835 | { |
---|
| 1836 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType ); |
---|
| 1837 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
| 1838 | } |
---|
| 1839 | if( uiSig ) |
---|
| 1840 | { |
---|
| 1841 | absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); |
---|
| 1842 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
| 1843 | numNonZero++; |
---|
| 1844 | if( lastNZPosInCG == -1 ) |
---|
| 1845 | { |
---|
| 1846 | lastNZPosInCG = iScanPosSig; |
---|
| 1847 | } |
---|
| 1848 | firstNZPosInCG = iScanPosSig; |
---|
| 1849 | } |
---|
| 1850 | } |
---|
| 1851 | } |
---|
| 1852 | else |
---|
| 1853 | { |
---|
| 1854 | iScanPosSig = iSubPos - 1; |
---|
| 1855 | } |
---|
| 1856 | |
---|
| 1857 | if( numNonZero > 0 ) |
---|
| 1858 | { |
---|
| 1859 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
| 1860 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
| 1861 | |
---|
| 1862 | if( c1 == 0 ) |
---|
| 1863 | { |
---|
| 1864 | uiCtxSet++; |
---|
| 1865 | } |
---|
| 1866 | c1 = 1; |
---|
| 1867 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
| 1868 | |
---|
| 1869 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
| 1870 | Int firstC2FlagIdx = -1; |
---|
| 1871 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
| 1872 | { |
---|
| 1873 | UInt uiSymbol = absCoeff[ idx ] > 1; |
---|
| 1874 | m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] ); |
---|
| 1875 | if( uiSymbol ) |
---|
| 1876 | { |
---|
| 1877 | c1 = 0; |
---|
| 1878 | |
---|
| 1879 | if (firstC2FlagIdx == -1) |
---|
| 1880 | { |
---|
| 1881 | firstC2FlagIdx = idx; |
---|
| 1882 | } |
---|
| 1883 | } |
---|
| 1884 | else if( (c1 < 3) && (c1 > 0) ) |
---|
| 1885 | { |
---|
| 1886 | c1++; |
---|
| 1887 | } |
---|
| 1888 | } |
---|
| 1889 | |
---|
| 1890 | if (c1 == 0) |
---|
| 1891 | { |
---|
| 1892 | |
---|
| 1893 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
| 1894 | if ( firstC2FlagIdx != -1) |
---|
| 1895 | { |
---|
| 1896 | UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; |
---|
| 1897 | m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); |
---|
| 1898 | } |
---|
| 1899 | } |
---|
| 1900 | |
---|
| 1901 | if( beValid && signHidden ) |
---|
| 1902 | { |
---|
| 1903 | m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 ); |
---|
| 1904 | } |
---|
| 1905 | else |
---|
| 1906 | { |
---|
| 1907 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
| 1908 | } |
---|
| 1909 | |
---|
| 1910 | Int iFirstCoeff2 = 1; |
---|
| 1911 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
| 1912 | { |
---|
| 1913 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 1914 | { |
---|
| 1915 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1; |
---|
| 1916 | |
---|
| 1917 | if( absCoeff[ idx ] >= baseLevel) |
---|
| 1918 | { |
---|
| 1919 | xWriteCoefRemainExGolomb( absCoeff[ idx ] - baseLevel, uiGoRiceParam ); |
---|
| 1920 | if(absCoeff[idx] > 3*(1<<uiGoRiceParam)) |
---|
| 1921 | { |
---|
| 1922 | uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4); |
---|
| 1923 | } |
---|
| 1924 | } |
---|
| 1925 | if(absCoeff[ idx ] >= 2) |
---|
| 1926 | { |
---|
| 1927 | iFirstCoeff2 = 0; |
---|
| 1928 | } |
---|
| 1929 | } |
---|
| 1930 | } |
---|
| 1931 | } |
---|
| 1932 | } |
---|
| 1933 | |
---|
| 1934 | return; |
---|
| 1935 | } |
---|
| 1936 | |
---|
| 1937 | /** code SAO offset sign |
---|
| 1938 | * \param code sign value |
---|
| 1939 | */ |
---|
| 1940 | Void TEncSbac::codeSAOSign( UInt code ) |
---|
| 1941 | { |
---|
| 1942 | m_pcBinIf->encodeBinEP( code ); |
---|
| 1943 | } |
---|
| 1944 | |
---|
| 1945 | Void TEncSbac::codeSaoMaxUvlc ( UInt code, UInt maxSymbol ) |
---|
| 1946 | { |
---|
| 1947 | if (maxSymbol == 0) |
---|
| 1948 | { |
---|
| 1949 | return; |
---|
| 1950 | } |
---|
| 1951 | |
---|
| 1952 | Int i; |
---|
| 1953 | Bool bCodeLast = ( maxSymbol > code ); |
---|
| 1954 | |
---|
| 1955 | if ( code == 0 ) |
---|
| 1956 | { |
---|
| 1957 | m_pcBinIf->encodeBinEP( 0 ); |
---|
| 1958 | } |
---|
| 1959 | else |
---|
| 1960 | { |
---|
| 1961 | m_pcBinIf->encodeBinEP( 1 ); |
---|
| 1962 | for ( i=0; i<code-1; i++ ) |
---|
| 1963 | { |
---|
| 1964 | m_pcBinIf->encodeBinEP( 1 ); |
---|
| 1965 | } |
---|
| 1966 | if( bCodeLast ) |
---|
| 1967 | { |
---|
| 1968 | m_pcBinIf->encodeBinEP( 0 ); |
---|
| 1969 | } |
---|
| 1970 | } |
---|
| 1971 | } |
---|
| 1972 | |
---|
| 1973 | |
---|
| 1974 | /** Code SAO EO class or BO band position |
---|
| 1975 | * \param uiLength |
---|
| 1976 | * \param uiCode |
---|
| 1977 | */ |
---|
| 1978 | Void TEncSbac::codeSaoUflc ( UInt uiLength, UInt uiCode ) |
---|
| 1979 | { |
---|
| 1980 | m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); |
---|
| 1981 | } |
---|
| 1982 | /** Code SAO merge flags |
---|
| 1983 | * \param uiCode |
---|
| 1984 | * \param uiCompIdx |
---|
| 1985 | */ |
---|
| 1986 | Void TEncSbac::codeSaoMerge ( UInt uiCode ) |
---|
| 1987 | { |
---|
| 1988 | if (uiCode == 0) |
---|
| 1989 | { |
---|
| 1990 | m_pcBinIf->encodeBin(0, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
| 1991 | } |
---|
| 1992 | else |
---|
| 1993 | { |
---|
| 1994 | m_pcBinIf->encodeBin(1, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
| 1995 | } |
---|
| 1996 | } |
---|
| 1997 | /** Code SAO type index |
---|
| 1998 | * \param uiCode |
---|
| 1999 | */ |
---|
| 2000 | Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) |
---|
| 2001 | { |
---|
| 2002 | if (uiCode == 0) |
---|
| 2003 | { |
---|
| 2004 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
| 2005 | } |
---|
| 2006 | else |
---|
| 2007 | { |
---|
| 2008 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
| 2009 | m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 ); |
---|
| 2010 | } |
---|
| 2011 | } |
---|
| 2012 | /*! |
---|
| 2013 | **************************************************************************** |
---|
| 2014 | * \brief |
---|
| 2015 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
| 2016 | **************************************************************************** |
---|
| 2017 | */ |
---|
| 2018 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
| 2019 | { |
---|
| 2020 | estCBFBit( pcEstBitsSbac ); |
---|
| 2021 | |
---|
| 2022 | estSignificantCoeffGroupMapBit( pcEstBitsSbac, eTType ); |
---|
| 2023 | |
---|
| 2024 | // encode significance map |
---|
| 2025 | estSignificantMapBit( pcEstBitsSbac, width, height, eTType ); |
---|
| 2026 | |
---|
| 2027 | // encode significant coefficients |
---|
| 2028 | estSignificantCoefficientsBit( pcEstBitsSbac, eTType ); |
---|
| 2029 | } |
---|
| 2030 | |
---|
| 2031 | /*! |
---|
| 2032 | **************************************************************************** |
---|
| 2033 | * \brief |
---|
| 2034 | * estimate bit cost for each CBP bit |
---|
| 2035 | **************************************************************************** |
---|
| 2036 | */ |
---|
| 2037 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac ) |
---|
| 2038 | { |
---|
| 2039 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
| 2040 | |
---|
| 2041 | for( UInt uiCtxInc = 0; uiCtxInc < 3*NUM_QT_CBF_CTX; uiCtxInc++ ) |
---|
| 2042 | { |
---|
| 2043 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
| 2044 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
| 2045 | } |
---|
| 2046 | |
---|
| 2047 | pCtx = m_cCUQtRootCbfSCModel.get( 0 ); |
---|
| 2048 | |
---|
| 2049 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
| 2050 | { |
---|
| 2051 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
| 2052 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
| 2053 | } |
---|
| 2054 | } |
---|
| 2055 | |
---|
| 2056 | |
---|
| 2057 | /*! |
---|
| 2058 | **************************************************************************** |
---|
| 2059 | * \brief |
---|
| 2060 | * estimate SAMBAC bit cost for significant coefficient group map |
---|
| 2061 | **************************************************************************** |
---|
| 2062 | */ |
---|
| 2063 | Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
| 2064 | { |
---|
| 2065 | Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; |
---|
| 2066 | |
---|
| 2067 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
| 2068 | { |
---|
| 2069 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
| 2070 | { |
---|
| 2071 | pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, eTType, ctxIdx ).getEntropyBits( uiBin ); |
---|
| 2072 | } |
---|
| 2073 | } |
---|
| 2074 | } |
---|
| 2075 | |
---|
| 2076 | |
---|
| 2077 | /*! |
---|
| 2078 | **************************************************************************** |
---|
| 2079 | * \brief |
---|
| 2080 | * estimate SAMBAC bit cost for significant coefficient map |
---|
| 2081 | **************************************************************************** |
---|
| 2082 | */ |
---|
| 2083 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
| 2084 | { |
---|
| 2085 | Int firstCtx = 1, numCtx = 8; |
---|
| 2086 | if (max(width, height) >= 16) |
---|
| 2087 | { |
---|
| 2088 | firstCtx = (eTType == TEXT_LUMA) ? 21 : 12; |
---|
| 2089 | numCtx = (eTType == TEXT_LUMA) ? 6 : 3; |
---|
| 2090 | } |
---|
| 2091 | else if (width == 8) |
---|
| 2092 | { |
---|
| 2093 | firstCtx = 9; |
---|
| 2094 | numCtx = (eTType == TEXT_LUMA) ? 12 : 3; |
---|
| 2095 | } |
---|
| 2096 | |
---|
| 2097 | if (eTType == TEXT_LUMA ) |
---|
| 2098 | { |
---|
| 2099 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
| 2100 | { |
---|
| 2101 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, 0 ).getEntropyBits( bin ); |
---|
| 2102 | } |
---|
| 2103 | |
---|
| 2104 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
| 2105 | { |
---|
| 2106 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
| 2107 | { |
---|
| 2108 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, ctxIdx ).getEntropyBits( uiBin ); |
---|
| 2109 | } |
---|
| 2110 | } |
---|
| 2111 | } |
---|
| 2112 | else |
---|
| 2113 | { |
---|
| 2114 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
| 2115 | { |
---|
| 2116 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + 0 ).getEntropyBits( bin ); |
---|
| 2117 | } |
---|
| 2118 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
| 2119 | { |
---|
| 2120 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
| 2121 | { |
---|
| 2122 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx ).getEntropyBits( uiBin ); |
---|
| 2123 | } |
---|
| 2124 | } |
---|
| 2125 | } |
---|
| 2126 | Int iBitsX = 0, iBitsY = 0; |
---|
| 2127 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
| 2128 | |
---|
| 2129 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
| 2130 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
| 2131 | shiftX = eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
| 2132 | shiftY = eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
| 2133 | |
---|
| 2134 | Int ctx; |
---|
| 2135 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
| 2136 | for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) |
---|
| 2137 | { |
---|
| 2138 | Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX); |
---|
| 2139 | pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); |
---|
| 2140 | iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); |
---|
| 2141 | } |
---|
| 2142 | pcEstBitsSbac->lastXBits[ctx] = iBitsX; |
---|
| 2143 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
| 2144 | for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) |
---|
| 2145 | { |
---|
| 2146 | Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY); |
---|
| 2147 | pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); |
---|
| 2148 | iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); |
---|
| 2149 | } |
---|
| 2150 | pcEstBitsSbac->lastYBits[ctx] = iBitsY; |
---|
| 2151 | } |
---|
| 2152 | |
---|
| 2153 | /*! |
---|
| 2154 | **************************************************************************** |
---|
| 2155 | * \brief |
---|
| 2156 | * estimate bit cost of significant coefficient |
---|
| 2157 | **************************************************************************** |
---|
| 2158 | */ |
---|
| 2159 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
| 2160 | { |
---|
| 2161 | if (eTType==TEXT_LUMA) |
---|
| 2162 | { |
---|
| 2163 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); |
---|
| 2164 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); |
---|
| 2165 | |
---|
| 2166 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++) |
---|
| 2167 | { |
---|
| 2168 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2169 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 2170 | } |
---|
| 2171 | |
---|
| 2172 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_LUMA; ctxIdx++) |
---|
| 2173 | { |
---|
| 2174 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2175 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 2176 | } |
---|
| 2177 | } |
---|
| 2178 | else |
---|
| 2179 | { |
---|
| 2180 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA; |
---|
| 2181 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA; |
---|
| 2182 | |
---|
| 2183 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++) |
---|
| 2184 | { |
---|
| 2185 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2186 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 2187 | } |
---|
| 2188 | |
---|
| 2189 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_CHROMA; ctxIdx++) |
---|
| 2190 | { |
---|
| 2191 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2192 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 2193 | } |
---|
| 2194 | } |
---|
| 2195 | } |
---|
| 2196 | |
---|
| 2197 | /** |
---|
| 2198 | - Initialize our context information from the nominated source. |
---|
| 2199 | . |
---|
| 2200 | \param pSrc From where to copy context information. |
---|
| 2201 | */ |
---|
| 2202 | Void TEncSbac::xCopyContextsFrom( TEncSbac* pSrc ) |
---|
| 2203 | { |
---|
| 2204 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
| 2205 | } |
---|
| 2206 | |
---|
| 2207 | Void TEncSbac::loadContexts ( TEncSbac* pScr) |
---|
| 2208 | { |
---|
| 2209 | this->xCopyContextsFrom(pScr); |
---|
| 2210 | } |
---|
| 2211 | //! \} |
---|