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