[5] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[56] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[608] | 6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
[5] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
[2] | 33 | |
---|
| 34 | /** \file TEncSbac.cpp |
---|
| 35 | \brief SBAC encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TEncTop.h" |
---|
| 39 | #include "TEncSbac.h" |
---|
| 40 | |
---|
| 41 | #include <map> |
---|
[56] | 42 | #include <algorithm> |
---|
[2] | 43 | |
---|
[56] | 44 | //! \ingroup TLibEncoder |
---|
| 45 | //! \{ |
---|
[2] | 46 | |
---|
| 47 | // ==================================================================================================================== |
---|
| 48 | // Constructor / destructor / create / destroy |
---|
| 49 | // ==================================================================================================================== |
---|
| 50 | |
---|
| 51 | TEncSbac::TEncSbac() |
---|
| 52 | // new structure here |
---|
| 53 | : m_pcBitIf ( NULL ) |
---|
| 54 | , m_pcSlice ( NULL ) |
---|
| 55 | , m_pcBinIf ( NULL ) |
---|
| 56 | , m_uiCoeffCost ( 0 ) |
---|
[56] | 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) |
---|
[608] | 62 | #if H_3D_ARP |
---|
| 63 | , m_cCUPUARPWSCModel ( 1, 1, NUM_ARPW_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[2] | 64 | #endif |
---|
[608] | 65 | #if H_3D_IC |
---|
| 66 | , m_cCUICFlagSCModel ( 1, 1, NUM_IC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[443] | 67 | #endif |
---|
[56] | 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) |
---|
[608] | 87 | , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[443] | 88 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[608] | 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) |
---|
| 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) |
---|
[622] | 97 | #if !SEC_DMM2_E0146_HHIFIX |
---|
[608] | 98 | , m_cDmm2DataSCModel ( 1, 1, NUM_DMM2_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[443] | 99 | #endif |
---|
[608] | 100 | , m_cDmm3DataSCModel ( 1, 1, NUM_DMM3_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[443] | 101 | #endif |
---|
[608] | 102 | #if H_3D_DIM_RBC |
---|
| 103 | , m_cRbcDataSCModel ( 1, 1, NUM_RBC_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
[2] | 104 | #endif |
---|
[608] | 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) |
---|
[100] | 108 | #endif |
---|
| 109 | #endif |
---|
[608] | 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) |
---|
[443] | 114 | #endif |
---|
[2] | 115 | { |
---|
[56] | 116 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
[2] | 117 | } |
---|
| 118 | |
---|
| 119 | TEncSbac::~TEncSbac() |
---|
| 120 | { |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | // ==================================================================================================================== |
---|
| 124 | // Public member functions |
---|
| 125 | // ==================================================================================================================== |
---|
| 126 | |
---|
| 127 | Void TEncSbac::resetEntropy () |
---|
| 128 | { |
---|
| 129 | Int iQp = m_pcSlice->getSliceQp(); |
---|
| 130 | SliceType eSliceType = m_pcSlice->getSliceType(); |
---|
| 131 | |
---|
[56] | 132 | 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 ); |
---|
[2] | 139 | |
---|
[56] | 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); |
---|
[608] | 143 | #if H_3D_ARP |
---|
| 144 | m_cCUPUARPWSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ARPW ); |
---|
[2] | 145 | #endif |
---|
[608] | 146 | #if H_3D_IC |
---|
| 147 | m_cCUICFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_IC_FLAG ); |
---|
[443] | 148 | #endif |
---|
[56] | 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 ); |
---|
[608] | 168 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
[443] | 169 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
[608] | 170 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
| 171 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
| 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 ); |
---|
[622] | 179 | #if !SEC_DMM2_E0146_HHIFIX |
---|
[608] | 180 | m_cDmm2DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA ); |
---|
[443] | 181 | #endif |
---|
[608] | 182 | m_cDmm3DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA ); |
---|
[443] | 183 | #endif |
---|
[608] | 184 | #if H_3D_DIM_RBC |
---|
| 185 | m_cRbcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RBC_DATA ); |
---|
[2] | 186 | #endif |
---|
[608] | 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 ); |
---|
[100] | 190 | #endif |
---|
| 191 | #endif |
---|
[608] | 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 ); |
---|
[443] | 196 | #endif |
---|
[2] | 197 | // new structure |
---|
| 198 | m_uiLastQp = iQp; |
---|
| 199 | |
---|
| 200 | m_pcBinIf->start(); |
---|
| 201 | |
---|
| 202 | return; |
---|
| 203 | } |
---|
| 204 | |
---|
[56] | 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); |
---|
[608] | 228 | #if H_3D_ARP |
---|
| 229 | curCost += m_cCUPUARPWSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ARPW ); |
---|
[56] | 230 | #endif |
---|
[608] | 231 | #if H_3D_IC |
---|
| 232 | curCost += m_cCUICFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_IC_FLAG ); |
---|
| 233 | #endif |
---|
| 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 |
---|
[56] | 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 ); |
---|
[608] | 258 | curCost += m_cSaoMergeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
[443] | 259 | curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
[608] | 260 | curCost += m_cTransformSkipSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
| 261 | curCost += m_CUTransquantBypassFlagSCModel.calcCost( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
| 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 ); |
---|
[622] | 270 | #if !SEC_DMM2_E0146_HHIFIX |
---|
[608] | 271 | curCost += m_cDmm2DataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM2_DATA ); |
---|
[443] | 272 | #endif |
---|
[608] | 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 |
---|
[56] | 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 ) |
---|
[2] | 298 | { |
---|
[56] | 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); |
---|
[608] | 306 | #if H_3D_ARP |
---|
| 307 | m_cCUPUARPWSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ARPW ); |
---|
[56] | 308 | #endif |
---|
[608] | 309 | #if H_3D_IC |
---|
| 310 | m_cCUICFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_IC_FLAG ); |
---|
[443] | 311 | #endif |
---|
[56] | 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 ); |
---|
[608] | 331 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
[443] | 332 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
[608] | 333 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
| 334 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
| 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 ); |
---|
[622] | 342 | #if !SEC_DMM2_E0146_HHIFIX |
---|
[608] | 343 | m_cDmm2DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA ); |
---|
[443] | 344 | #endif |
---|
[608] | 345 | m_cDmm3DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA ); |
---|
[443] | 346 | #endif |
---|
[608] | 347 | #if H_3D_DIM_RBC |
---|
| 348 | m_cRbcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RBC_DATA ); |
---|
[56] | 349 | #endif |
---|
[608] | 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 ); |
---|
[443] | 353 | #endif |
---|
| 354 | #endif |
---|
[608] | 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 ); |
---|
[189] | 359 | #endif |
---|
[56] | 360 | m_pcBinIf->start(); |
---|
[2] | 361 | } |
---|
| 362 | |
---|
[77] | 363 | Void TEncSbac::codeVPS( TComVPS* pcVPS ) |
---|
| 364 | { |
---|
[100] | 365 | assert (0); |
---|
[77] | 366 | return; |
---|
| 367 | } |
---|
| 368 | |
---|
[608] | 369 | #if H_3D |
---|
| 370 | Void TEncSbac::codeSPS( TComSPS* pcSPS, Int viewIndex, Bool depthFlag ) |
---|
[56] | 371 | #else |
---|
[2] | 372 | Void TEncSbac::codeSPS( TComSPS* pcSPS ) |
---|
[56] | 373 | #endif |
---|
[2] | 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 | |
---|
[56] | 391 | Void TEncSbac::codeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
| 392 | { |
---|
| 393 | assert (0); |
---|
| 394 | return; |
---|
| 395 | } |
---|
| 396 | |
---|
[2] | 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 | { |
---|
[56] | 454 | UInt bins = 0; |
---|
| 455 | Int numBins = 0; |
---|
| 456 | |
---|
[2] | 457 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
| 458 | { |
---|
[56] | 459 | bins = 2 * bins + 1; |
---|
| 460 | numBins++; |
---|
| 461 | uiSymbol -= 1 << uiCount; |
---|
[2] | 462 | uiCount ++; |
---|
| 463 | } |
---|
[56] | 464 | bins = 2 * bins + 0; |
---|
| 465 | numBins++; |
---|
[2] | 466 | |
---|
[56] | 467 | bins = (bins << uiCount) | uiSymbol; |
---|
| 468 | numBins += uiCount; |
---|
| 469 | |
---|
| 470 | assert( numBins <= 32 ); |
---|
| 471 | m_pcBinIf->encodeBinsEP( bins, numBins ); |
---|
[2] | 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 | */ |
---|
[608] | 479 | Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam ) |
---|
[2] | 480 | { |
---|
[608] | 481 | Int codeNumber = (Int)symbol; |
---|
| 482 | UInt length; |
---|
| 483 | if (codeNumber < (COEF_REMAIN_BIN_REDUCTION << rParam)) |
---|
[2] | 484 | { |
---|
[608] | 485 | length = codeNumber>>rParam; |
---|
| 486 | m_pcBinIf->encodeBinsEP( (1<<(length+1))-2 , length+1); |
---|
| 487 | m_pcBinIf->encodeBinsEP((codeNumber%(1<<rParam)),rParam); |
---|
[2] | 488 | } |
---|
| 489 | else |
---|
| 490 | { |
---|
[608] | 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); |
---|
[2] | 499 | } |
---|
[608] | 500 | } |
---|
| 501 | |
---|
| 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 | |
---|
[622] | 551 | #if !SEC_DMM2_E0146_HHIFIX |
---|
[608] | 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 | } |
---|
| 568 | #endif |
---|
| 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 ); |
---|
[56] | 635 | |
---|
[608] | 636 | Pel segmentDCOffset = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx); |
---|
[56] | 637 | |
---|
[608] | 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 ); |
---|
[56] | 648 | |
---|
[608] | 649 | // residual flag |
---|
| 650 | m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) ); |
---|
[622] | 651 | #if H_MV_ENC_DEC_TRAC |
---|
| 652 | DTRACE_CU("sdc_residual_flag[i]", uiResidual) |
---|
| 653 | #endif |
---|
[608] | 654 | |
---|
| 655 | if (uiResidual) |
---|
[2] | 656 | { |
---|
[608] | 657 | // encode sign bit of residual |
---|
| 658 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
[622] | 659 | #if H_MV_ENC_DEC_TRAC |
---|
| 660 | DTRACE_CU("sdc_residual_sign_flag[i]", uiSign) |
---|
| 661 | #endif |
---|
[608] | 662 | |
---|
| 663 | #if H_3D_DIM_DLT |
---|
| 664 | UInt uiNumDepthValues = pcCU->getSlice()->getVPS()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() ); |
---|
| 665 | #else |
---|
| 666 | UInt uiNumDepthValues = ((1 << g_bitDepthY)-1); |
---|
| 667 | #endif |
---|
| 668 | assert(uiAbsIdx <= uiNumDepthValues); |
---|
| 669 | |
---|
| 670 | // encode residual magnitude |
---|
| 671 | uiAbsIdx -= 1; |
---|
[622] | 672 | |
---|
| 673 | #if H_MV_ENC_DEC_TRAC |
---|
| 674 | DTRACE_CU("sdc_residual_abs_minus1[i]", uiAbsIdx) |
---|
| 675 | #endif |
---|
| 676 | |
---|
[608] | 677 | // prefix part |
---|
| 678 | if ( uiAbsIdx == 0 ) |
---|
[622] | 679 | { |
---|
[608] | 680 | m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) ); |
---|
[622] | 681 | } |
---|
[608] | 682 | else |
---|
| 683 | { |
---|
| 684 | UInt l = uiAbsIdx; |
---|
| 685 | UInt k = 0; |
---|
| 686 | UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2); |
---|
| 687 | while ( l > 0 && k < uiPrefixThreshold ) |
---|
| 688 | { |
---|
| 689 | m_pcBinIf->encodeBin( 1, m_cSDCResidualSCModel.get(0, 0, 0) ); |
---|
| 690 | l--; |
---|
| 691 | k++; |
---|
| 692 | } |
---|
| 693 | if ( uiAbsIdx < uiPrefixThreshold ) |
---|
[622] | 694 | { |
---|
[608] | 695 | m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) ); |
---|
[622] | 696 | } |
---|
[608] | 697 | else |
---|
[622] | 698 | { // suffix part |
---|
[608] | 699 | uiAbsIdx -= uiPrefixThreshold; |
---|
| 700 | UInt uiSuffixLength = numBitsForValue(uiNumDepthValues - uiPrefixThreshold); |
---|
| 701 | UInt uiBitInfo = 0; |
---|
| 702 | for ( Int i = 0; i < uiSuffixLength; i++) |
---|
| 703 | { |
---|
| 704 | uiBitInfo = ( uiAbsIdx & ( 1 << i ) ) >> i; |
---|
| 705 | m_pcBinIf->encodeBinEP( uiBitInfo); |
---|
| 706 | } |
---|
| 707 | } |
---|
| 708 | } |
---|
| 709 | |
---|
[2] | 710 | } |
---|
| 711 | } |
---|
[608] | 712 | #endif |
---|
| 713 | #endif |
---|
[2] | 714 | |
---|
[56] | 715 | // SBAC RD |
---|
| 716 | Void TEncSbac::load ( TEncSbac* pSrc) |
---|
[2] | 717 | { |
---|
[56] | 718 | this->xCopyFrom(pSrc); |
---|
[2] | 719 | } |
---|
| 720 | |
---|
[56] | 721 | Void TEncSbac::loadIntraDirModeLuma( TEncSbac* pSrc) |
---|
[2] | 722 | { |
---|
[56] | 723 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
| 724 | |
---|
| 725 | this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); |
---|
[2] | 726 | } |
---|
[608] | 727 | #if H_3D_DIM |
---|
| 728 | Void TEncSbac::loadIntraDepthMode( TEncSbac* pSrc) |
---|
[443] | 729 | { |
---|
| 730 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
[56] | 731 | |
---|
[608] | 732 | this->m_cDepthIntraModeSCModel .copyFrom( &pSrc->m_cDepthIntraModeSCModel ); |
---|
| 733 | this->m_cDdcFlagSCModel .copyFrom( &pSrc->m_cDdcFlagSCModel ); |
---|
[443] | 734 | } |
---|
| 735 | #endif |
---|
[608] | 736 | |
---|
[2] | 737 | Void TEncSbac::store( TEncSbac* pDest) |
---|
| 738 | { |
---|
| 739 | pDest->xCopyFrom( this ); |
---|
| 740 | } |
---|
| 741 | |
---|
| 742 | |
---|
| 743 | Void TEncSbac::xCopyFrom( TEncSbac* pSrc ) |
---|
| 744 | { |
---|
| 745 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
| 746 | |
---|
| 747 | this->m_uiCoeffCost = pSrc->m_uiCoeffCost; |
---|
| 748 | this->m_uiLastQp = pSrc->m_uiLastQp; |
---|
| 749 | |
---|
[56] | 750 | memcpy( m_contextModels, pSrc->m_contextModels, m_numContextModels * sizeof( ContextModel ) ); |
---|
[2] | 751 | } |
---|
| 752 | |
---|
| 753 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 754 | { |
---|
| 755 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
[56] | 756 | Int iNum = AMVP_MAX_NUM_CANDS; |
---|
[2] | 757 | |
---|
| 758 | xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1); |
---|
[608] | 759 | #if H_MV_ENC_DEC_TRAC |
---|
| 760 | #if ENC_DEC_TRACE |
---|
| 761 | if ( eRefList == REF_PIC_LIST_0 ) |
---|
| 762 | { |
---|
| 763 | DTRACE_PU("mvp_l0_flag", iSymbol) |
---|
| 764 | } |
---|
| 765 | else |
---|
| 766 | { |
---|
| 767 | DTRACE_PU("mvp_l1_flag", iSymbol) |
---|
| 768 | } |
---|
| 769 | #endif |
---|
| 770 | #endif |
---|
[2] | 771 | } |
---|
| 772 | |
---|
| 773 | Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 774 | { |
---|
| 775 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
[608] | 776 | #if H_3D_QTLPC |
---|
[189] | 777 | TComSPS *sps = pcCU->getPic()->getSlice(0)->getSPS(); |
---|
| 778 | TComPic *pcTexture = pcCU->getSlice()->getTexturePic(); |
---|
| 779 | Bool bDepthMapDetect = (pcTexture != NULL); |
---|
| 780 | Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE); |
---|
| 781 | |
---|
[608] | 782 | 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); |
---|
| 783 | |
---|
| 784 | if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && pcCU->getPic()->getReduceBitsFlag() && sps->getUseQTL() && sps->getUsePC() ) |
---|
[189] | 785 | { |
---|
| 786 | TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr()); |
---|
| 787 | UInt uiCUIdx = (pcCU->getZorderIdxInCU() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU(); |
---|
| 788 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); |
---|
| 789 | if (pcTextureCU->getDepth(uiCUIdx) == uiDepth && pcTextureCU->getPartitionSize( uiCUIdx ) != SIZE_NxN) |
---|
| 790 | { |
---|
| 791 | assert( eSize == SIZE_2Nx2N ); |
---|
| 792 | return; |
---|
| 793 | } |
---|
| 794 | } |
---|
[115] | 795 | #endif |
---|
[2] | 796 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
| 797 | { |
---|
| 798 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 799 | { |
---|
| 800 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
[608] | 801 | #if H_MV_ENC_DEC_TRAC |
---|
| 802 | DTRACE_CU("part_mode", eSize == SIZE_2Nx2N? 1 : 0) |
---|
| 803 | #endif |
---|
[2] | 804 | } |
---|
| 805 | return; |
---|
| 806 | } |
---|
| 807 | |
---|
[608] | 808 | #if H_MV_ENC_DEC_TRAC |
---|
| 809 | DTRACE_CU("part_mode", eSize ) |
---|
| 810 | #endif |
---|
[2] | 811 | switch(eSize) |
---|
| 812 | { |
---|
[608] | 813 | case SIZE_2Nx2N: |
---|
[2] | 814 | { |
---|
| 815 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 816 | break; |
---|
| 817 | } |
---|
[608] | 818 | case SIZE_2NxN: |
---|
| 819 | case SIZE_2NxnU: |
---|
| 820 | case SIZE_2NxnD: |
---|
[2] | 821 | { |
---|
| 822 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 823 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
[56] | 824 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
| 825 | { |
---|
| 826 | if (eSize == SIZE_2NxN) |
---|
| 827 | { |
---|
| 828 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 829 | } |
---|
| 830 | else |
---|
| 831 | { |
---|
| 832 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 833 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
| 834 | } |
---|
| 835 | } |
---|
[2] | 836 | break; |
---|
| 837 | } |
---|
[608] | 838 | case SIZE_Nx2N: |
---|
| 839 | case SIZE_nLx2N: |
---|
| 840 | case SIZE_nRx2N: |
---|
[2] | 841 | { |
---|
| 842 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
| 843 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
[608] | 844 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
[56] | 845 | { |
---|
| 846 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
| 847 | } |
---|
| 848 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
| 849 | { |
---|
| 850 | if (eSize == SIZE_Nx2N) |
---|
| 851 | { |
---|
| 852 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 853 | } |
---|
| 854 | else |
---|
| 855 | { |
---|
| 856 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
| 857 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
| 858 | } |
---|
| 859 | } |
---|
[2] | 860 | break; |
---|
| 861 | } |
---|
[608] | 862 | case SIZE_NxN: |
---|
[2] | 863 | { |
---|
[608] | 864 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
[2] | 865 | { |
---|
| 866 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
[56] | 867 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
| 868 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
[2] | 869 | } |
---|
| 870 | break; |
---|
| 871 | } |
---|
[608] | 872 | default: |
---|
[2] | 873 | { |
---|
| 874 | assert(0); |
---|
| 875 | } |
---|
| 876 | } |
---|
| 877 | } |
---|
| 878 | |
---|
| 879 | /** code prediction mode |
---|
| 880 | * \param pcCU |
---|
| 881 | * \param uiAbsPartIdx |
---|
| 882 | * \returns Void |
---|
| 883 | */ |
---|
| 884 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 885 | { |
---|
[608] | 886 | #if H_3D_DIM_SDC |
---|
[189] | 887 | if ( pcCU->getSlice()->isIntra() ) |
---|
| 888 | { |
---|
| 889 | assert( pcCU->isIntra(uiAbsPartIdx) ); |
---|
| 890 | return; |
---|
| 891 | } |
---|
| 892 | #endif |
---|
| 893 | |
---|
[2] | 894 | // get context function is here |
---|
| 895 | Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); |
---|
[56] | 896 | m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
[608] | 897 | #if H_MV_ENC_DEC_TRAC |
---|
| 898 | DTRACE_CU("pred_mode_flag", iPredMode == MODE_INTER ? 0 : 1); |
---|
| 899 | #endif |
---|
[2] | 900 | } |
---|
| 901 | |
---|
[608] | 902 | Void TEncSbac::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
[2] | 903 | { |
---|
[608] | 904 | UInt uiSymbol = pcCU->getCUTransquantBypass(uiAbsPartIdx); |
---|
| 905 | m_pcBinIf->encodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
| 906 | #if H_MV_ENC_DEC_TRAC |
---|
| 907 | DTRACE_CU("cu_transquant_bypass_flag", uiSymbol); |
---|
| 908 | #endif |
---|
[2] | 909 | } |
---|
| 910 | |
---|
| 911 | /** code skip flag |
---|
| 912 | * \param pcCU |
---|
| 913 | * \param uiAbsPartIdx |
---|
| 914 | * \returns Void |
---|
| 915 | */ |
---|
| 916 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 917 | { |
---|
| 918 | // get context function is here |
---|
| 919 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
| 920 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
| 921 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
[608] | 922 | #if !H_MV_ENC_DEC_TRAC |
---|
[56] | 923 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 924 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
| 925 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
| 926 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
| 927 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 928 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 929 | DTRACE_CABAC_T( "\n"); |
---|
[608] | 930 | #else |
---|
| 931 | DTRACE_CU("cu_skip_flag", uiSymbol); |
---|
| 932 | #endif |
---|
[2] | 933 | } |
---|
| 934 | |
---|
| 935 | /** code merge flag |
---|
| 936 | * \param pcCU |
---|
| 937 | * \param uiAbsPartIdx |
---|
| 938 | * \returns Void |
---|
| 939 | */ |
---|
| 940 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 941 | { |
---|
[56] | 942 | const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 943 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
[2] | 944 | |
---|
[608] | 945 | #if H_MV_ENC_DEC_TRAC |
---|
| 946 | DTRACE_PU("merge_flag", uiSymbol); |
---|
| 947 | #else |
---|
[56] | 948 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 949 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
| 950 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 951 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
| 952 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
| 953 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
| 954 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
| 955 | DTRACE_CABAC_T( "\n" ); |
---|
[608] | 956 | #endif |
---|
[2] | 957 | } |
---|
| 958 | |
---|
[56] | 959 | /** code merge index |
---|
| 960 | * \param pcCU |
---|
| 961 | * \param uiAbsPartIdx |
---|
| 962 | * \returns Void |
---|
| 963 | */ |
---|
| 964 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
[2] | 965 | { |
---|
[56] | 966 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
[608] | 967 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
[56] | 968 | if ( uiNumCand > 1 ) |
---|
[2] | 969 | { |
---|
[56] | 970 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
[2] | 971 | { |
---|
[56] | 972 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
| 973 | if ( ui==0 ) |
---|
[2] | 974 | { |
---|
[56] | 975 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
[2] | 976 | } |
---|
[56] | 977 | else |
---|
[2] | 978 | { |
---|
[56] | 979 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
[2] | 980 | } |
---|
[56] | 981 | if( uiSymbol == 0 ) |
---|
[2] | 982 | { |
---|
[56] | 983 | break; |
---|
[2] | 984 | } |
---|
| 985 | } |
---|
[608] | 986 | #if H_MV_ENC_DEC_TRAC |
---|
| 987 | DTRACE_PU("merge_idx", uiUnaryIdx); |
---|
| 988 | #endif |
---|
[2] | 989 | } |
---|
[608] | 990 | #if !H_MV_ENC_DEC_TRAC |
---|
[56] | 991 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[2] | 992 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
| 993 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
| 994 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
| 995 | DTRACE_CABAC_T( "\n" ); |
---|
[608] | 996 | #endif |
---|
[2] | 997 | } |
---|
| 998 | |
---|
[608] | 999 | #if H_3D_ARP |
---|
[443] | 1000 | Void TEncSbac::codeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1001 | { |
---|
[608] | 1002 | Int iW = (Int)pcCU->getARPW( uiAbsPartIdx ); |
---|
| 1003 | Int iMaxW = pcCU->getSlice()->getARPStepNum() - 1; |
---|
| 1004 | assert( iMaxW > 0); |
---|
| 1005 | |
---|
| 1006 | Int nOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx); |
---|
| 1007 | Int nBinNum = iW + ( iW != iMaxW ); |
---|
| 1008 | m_pcBinIf->encodeBin( iW ? 1 : 0 , m_cCUPUARPWSCModel.get( 0, 0, 0 + nOffset ) ); |
---|
| 1009 | if( nBinNum > 1 ) |
---|
[443] | 1010 | { |
---|
[608] | 1011 | m_pcBinIf->encodeBin( ( iW == iMaxW ) ? 1 : 0, m_cCUPUARPWSCModel.get( 0, 0, 3 ) ); |
---|
[443] | 1012 | } |
---|
[608] | 1013 | #if H_MV_ENC_DEC_TRAC |
---|
| 1014 | DTRACE_CU("iv_res_pred_weight_idx", iW); |
---|
| 1015 | #endif |
---|
[443] | 1016 | } |
---|
| 1017 | #endif |
---|
[608] | 1018 | |
---|
| 1019 | #if H_3D_IC |
---|
| 1020 | /** code Illumination Compensation flag |
---|
| 1021 | * \param pcCU |
---|
| 1022 | * \param uiAbsPartIdx |
---|
| 1023 | * \returns Void |
---|
| 1024 | */ |
---|
| 1025 | Void TEncSbac::codeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1026 | { |
---|
| 1027 | // get context function is here |
---|
| 1028 | UInt uiSymbol = pcCU->getICFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 1029 | UInt uiCtxIC = pcCU->getCtxICFlag( uiAbsPartIdx ) ; |
---|
| 1030 | m_pcBinIf->encodeBin( uiSymbol, m_cCUICFlagSCModel.get( 0, 0, uiCtxIC ) ); |
---|
| 1031 | #if !H_MV_ENC_DEC_TRAC |
---|
| 1032 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 1033 | DTRACE_CABAC_T( "\tICFlag" ); |
---|
| 1034 | DTRACE_CABAC_T( "\tuiCtxIC: "); |
---|
| 1035 | DTRACE_CABAC_V( uiCtxIC ); |
---|
| 1036 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
| 1037 | DTRACE_CABAC_V( uiSymbol ); |
---|
| 1038 | DTRACE_CABAC_T( "\n"); |
---|
| 1039 | #else |
---|
| 1040 | DTRACE_CU("ic_flag", uiSymbol ); |
---|
| 1041 | #endif |
---|
| 1042 | } |
---|
| 1043 | #endif |
---|
| 1044 | |
---|
| 1045 | |
---|
[2] | 1046 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1047 | { |
---|
| 1048 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 1049 | return; |
---|
| 1050 | |
---|
| 1051 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
| 1052 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
| 1053 | |
---|
| 1054 | assert( uiCtx < 3 ); |
---|
[608] | 1055 | #if H_3D_QTLPC |
---|
[189] | 1056 | Bool bCodeSplitFlag = true; |
---|
| 1057 | |
---|
| 1058 | TComSPS *sps = pcCU->getPic()->getSlice(0)->getSPS(); |
---|
| 1059 | TComPic *pcTexture = pcCU->getSlice()->getTexturePic(); |
---|
| 1060 | Bool bDepthMapDetect = (pcTexture != NULL); |
---|
| 1061 | Bool bIntraSliceDetect = (pcCU->getSlice()->getSliceType() == I_SLICE); |
---|
| 1062 | |
---|
[608] | 1063 | 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); |
---|
| 1064 | |
---|
| 1065 | if(bDepthMapDetect && !bIntraSliceDetect && !rapPic && pcCU->getPic()->getReduceBitsFlag() && sps->getUseQTL() && sps->getUsePC()) |
---|
[115] | 1066 | { |
---|
[189] | 1067 | TComDataCU *pcTextureCU = pcTexture->getCU(pcCU->getAddr()); |
---|
| 1068 | UInt uiCUIdx = (pcCU->getZorderIdxInCU() == 0) ? uiAbsPartIdx : pcCU->getZorderIdxInCU(); |
---|
| 1069 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); |
---|
| 1070 | bCodeSplitFlag = (pcTextureCU->getDepth(uiCUIdx) > uiDepth); |
---|
[115] | 1071 | } |
---|
[189] | 1072 | |
---|
| 1073 | if(!bCodeSplitFlag) |
---|
| 1074 | { |
---|
| 1075 | assert(uiCurrSplitFlag == 0); |
---|
| 1076 | return; |
---|
| 1077 | } |
---|
[115] | 1078 | #endif |
---|
[189] | 1079 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
[608] | 1080 | #if !H_MV_ENC_DEC_TRAC |
---|
[56] | 1081 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1082 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
[608] | 1083 | #else |
---|
| 1084 | DTRACE_CU("split_cu_flag", uiCurrSplitFlag ); |
---|
| 1085 | #endif |
---|
[2] | 1086 | return; |
---|
| 1087 | } |
---|
| 1088 | |
---|
| 1089 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
| 1090 | { |
---|
| 1091 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
[608] | 1092 | #if !H_MV_ENC_DEC_TRAC |
---|
[56] | 1093 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1094 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
| 1095 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1096 | DTRACE_CABAC_V( uiSymbol ) |
---|
| 1097 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 1098 | DTRACE_CABAC_V( uiCtx ) |
---|
| 1099 | DTRACE_CABAC_T( "\n" ) |
---|
[608] | 1100 | #endif |
---|
[2] | 1101 | } |
---|
[100] | 1102 | |
---|
[608] | 1103 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple) |
---|
[100] | 1104 | { |
---|
[608] | 1105 | UInt dir[4],j; |
---|
| 1106 | Int preds[4][3] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}}; |
---|
| 1107 | Int predNum[4], predIdx[4] ={ -1,-1,-1,-1}; |
---|
| 1108 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
| 1109 | UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1; |
---|
| 1110 | UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
| 1111 | for (j=0;j<partNum;j++) |
---|
[100] | 1112 | { |
---|
[608] | 1113 | dir[j] = pcCU->getLumaIntraDir( absPartIdx+partOffset*j ); |
---|
| 1114 | #if H_3D_DIM |
---|
| 1115 | if( pcCU->getSlice()->getVpsDepthModesFlag() ) |
---|
[100] | 1116 | { |
---|
[608] | 1117 | codeIntraDepth( pcCU, absPartIdx+partOffset*j ); |
---|
[100] | 1118 | } |
---|
[608] | 1119 | if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) |
---|
| 1120 | #if H_3D_DIM_SDC |
---|
| 1121 | if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) ) |
---|
[100] | 1122 | #endif |
---|
[443] | 1123 | { |
---|
[608] | 1124 | #endif |
---|
| 1125 | predNum[j] = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds[j]); |
---|
| 1126 | for(UInt i = 0; i < predNum[j]; i++) |
---|
| 1127 | { |
---|
| 1128 | if(dir[j] == preds[j][i]) |
---|
| 1129 | { |
---|
| 1130 | predIdx[j] = i; |
---|
| 1131 | } |
---|
[443] | 1132 | } |
---|
[608] | 1133 | m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
| 1134 | #if H_MV_ENC_DEC_TRAC |
---|
| 1135 | DTRACE_CU("prev_intra_luma_pred_flag", (predIdx[j] != -1)? 1 : 0); |
---|
| 1136 | #endif |
---|
| 1137 | #if H_3D_DIM |
---|
| 1138 | } |
---|
| 1139 | #endif |
---|
[100] | 1140 | |
---|
[608] | 1141 | } |
---|
| 1142 | for (j=0;j<partNum;j++) |
---|
[443] | 1143 | { |
---|
[608] | 1144 | #if H_3D_DIM |
---|
| 1145 | if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) |
---|
| 1146 | #if H_3D_DIM_SDC |
---|
| 1147 | if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) ) |
---|
| 1148 | #endif |
---|
[443] | 1149 | { |
---|
[608] | 1150 | #endif |
---|
| 1151 | if(predIdx[j] != -1) |
---|
| 1152 | { |
---|
| 1153 | m_pcBinIf->encodeBinEP( predIdx[j] ? 1 : 0 ); |
---|
| 1154 | if (predIdx[j]) |
---|
[443] | 1155 | { |
---|
[608] | 1156 | m_pcBinIf->encodeBinEP( predIdx[j]-1 ); |
---|
[443] | 1157 | } |
---|
[608] | 1158 | #if H_MV_ENC_DEC_TRAC |
---|
| 1159 | DTRACE_CU("mpm_idx", predIdx[j] ); |
---|
| 1160 | #endif |
---|
| 1161 | } |
---|
| 1162 | else |
---|
| 1163 | { |
---|
| 1164 | if (preds[j][0] > preds[j][1]) |
---|
| 1165 | { |
---|
| 1166 | std::swap(preds[j][0], preds[j][1]); |
---|
[443] | 1167 | } |
---|
[608] | 1168 | if (preds[j][0] > preds[j][2]) |
---|
[443] | 1169 | { |
---|
[608] | 1170 | std::swap(preds[j][0], preds[j][2]); |
---|
[443] | 1171 | } |
---|
[608] | 1172 | if (preds[j][1] > preds[j][2]) |
---|
[443] | 1173 | { |
---|
[608] | 1174 | std::swap(preds[j][1], preds[j][2]); |
---|
[443] | 1175 | } |
---|
[608] | 1176 | for(Int i = (predNum[j] - 1); i >= 0; i--) |
---|
[443] | 1177 | { |
---|
[608] | 1178 | dir[j] = dir[j] > preds[j][i] ? dir[j] - 1 : dir[j]; |
---|
[443] | 1179 | } |
---|
[608] | 1180 | m_pcBinIf->encodeBinsEP( dir[j], 5 ); |
---|
| 1181 | #if H_MV_ENC_DEC_TRAC |
---|
| 1182 | DTRACE_CU("rem_intra_luma_pred_mode", dir[j] ); |
---|
| 1183 | #endif |
---|
[443] | 1184 | } |
---|
[608] | 1185 | #if H_3D_DIM |
---|
| 1186 | } |
---|
| 1187 | #endif |
---|
[443] | 1188 | } |
---|
[608] | 1189 | return; |
---|
| 1190 | } |
---|
| 1191 | |
---|
| 1192 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1193 | { |
---|
| 1194 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx ); |
---|
| 1195 | |
---|
| 1196 | if( uiIntraDirChroma == DM_CHROMA_IDX ) |
---|
[443] | 1197 | { |
---|
[608] | 1198 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
| 1199 | #if H_MV_ENC_DEC_TRAC |
---|
| 1200 | DTRACE_CU("intra_chroma_pred_mode", 0 ); |
---|
| 1201 | #endif |
---|
| 1202 | } |
---|
| 1203 | else |
---|
| 1204 | { |
---|
| 1205 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
| 1206 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
[443] | 1207 | |
---|
[608] | 1208 | for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ ) |
---|
[443] | 1209 | { |
---|
[608] | 1210 | if( uiIntraDirChroma == uiAllowedChromaDir[i] ) |
---|
[443] | 1211 | { |
---|
[608] | 1212 | uiIntraDirChroma = i; |
---|
| 1213 | break; |
---|
[443] | 1214 | } |
---|
| 1215 | } |
---|
[608] | 1216 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
| 1217 | |
---|
| 1218 | m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); |
---|
| 1219 | #if H_MV_ENC_DEC_TRAC |
---|
| 1220 | DTRACE_CU("intra_chroma_pred_mode", uiIntraDirChroma ); |
---|
| 1221 | #endif |
---|
| 1222 | |
---|
[443] | 1223 | } |
---|
[608] | 1224 | return; |
---|
[443] | 1225 | } |
---|
[608] | 1226 | |
---|
| 1227 | #if H_3D_DIM |
---|
| 1228 | Void TEncSbac::codeIntraDepth( TComDataCU* pcCU, UInt absPartIdx ) |
---|
[2] | 1229 | { |
---|
[608] | 1230 | codeIntraDepthMode( pcCU, absPartIdx ); |
---|
[2] | 1231 | |
---|
[608] | 1232 | UInt dir = pcCU->getLumaIntraDir( absPartIdx ); |
---|
| 1233 | UInt dimType = getDimType( dir ); |
---|
| 1234 | |
---|
| 1235 | switch( dimType ) |
---|
[2] | 1236 | { |
---|
[608] | 1237 | #if H_3D_DIM_DMM |
---|
| 1238 | case( DMM1_IDX ): |
---|
| 1239 | { |
---|
| 1240 | xCodeDmm1WedgeIdx( pcCU->getDmmWedgeTabIdx( dimType, absPartIdx ), g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] ); |
---|
| 1241 | } break; |
---|
[622] | 1242 | #if !SEC_DMM2_E0146_HHIFIX |
---|
[608] | 1243 | case( DMM2_IDX ): |
---|
| 1244 | { |
---|
| 1245 | xCodeDmm2Offset( pcCU->getDmm2DeltaEnd( absPartIdx ) ); |
---|
| 1246 | } break; |
---|
[100] | 1247 | #endif |
---|
[608] | 1248 | case( DMM3_IDX ): |
---|
| 1249 | { |
---|
| 1250 | xCodeDmm3WedgeIdx( pcCU->getDmm3IntraTabIdx( absPartIdx ), g_dmm3IntraTabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] ); |
---|
| 1251 | } break; |
---|
| 1252 | case( DMM4_IDX ): break; |
---|
[100] | 1253 | #endif |
---|
[608] | 1254 | #if H_3D_DIM_RBC |
---|
| 1255 | case( RBC_IDX ): |
---|
[56] | 1256 | { |
---|
[608] | 1257 | assert( pcCU->getWidth( absPartIdx ) < 64 ); |
---|
| 1258 | xCodeRbcEdge( pcCU, absPartIdx ); |
---|
| 1259 | } break; |
---|
[5] | 1260 | #endif |
---|
[608] | 1261 | default: break; |
---|
| 1262 | } |
---|
[210] | 1263 | |
---|
[608] | 1264 | #if H_3D_DIM_SDC |
---|
| 1265 | if( pcCU->getSDCFlag( absPartIdx ) ) |
---|
| 1266 | { |
---|
| 1267 | assert(pcCU->getPartitionSize(absPartIdx)==SIZE_2Nx2N); |
---|
| 1268 | UInt uiNumSegments = ( dir == DC_IDX || dir == PLANAR_IDX )? 1 : 2; |
---|
| 1269 | for(UInt uiSeg=0; uiSeg<uiNumSegments; uiSeg++) |
---|
[210] | 1270 | { |
---|
[608] | 1271 | xCodeSDCResidualData(pcCU, absPartIdx, uiSeg); |
---|
[210] | 1272 | } |
---|
[2] | 1273 | } |
---|
| 1274 | else |
---|
[608] | 1275 | { |
---|
| 1276 | #endif |
---|
| 1277 | if( dimType < DIM_NUM_TYPE ) |
---|
[100] | 1278 | { |
---|
[608] | 1279 | UInt dimDeltaDC = isDimDeltaDC( dir ); |
---|
| 1280 | m_pcBinIf->encodeBin( dimDeltaDC, m_cDdcFlagSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) ); |
---|
| 1281 | if( dimDeltaDC ) |
---|
[100] | 1282 | { |
---|
[608] | 1283 | for( UInt segment = 0; segment < 2; segment++ ) |
---|
[100] | 1284 | { |
---|
[608] | 1285 | xCodeDimDeltaDC( pcCU->getDimDeltaDC( dimType, segment, absPartIdx ), dimType ); |
---|
[100] | 1286 | } |
---|
| 1287 | } |
---|
| 1288 | } |
---|
[608] | 1289 | #if H_3D_DIM_SDC |
---|
[100] | 1290 | } |
---|
| 1291 | #endif |
---|
[608] | 1292 | } |
---|
| 1293 | |
---|
| 1294 | Void TEncSbac::codeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx ) |
---|
| 1295 | { |
---|
| 1296 | #if ZJU_DEPTH_INTRA_MODE_E0204 |
---|
| 1297 | 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}}; |
---|
| 1298 | 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}}; |
---|
[443] | 1299 | #else |
---|
[608] | 1300 | #if LGE_SDC_REMOVE_DC_E0158 |
---|
[622] | 1301 | #if SEC_DMM2_E0146_HHIFIX |
---|
[608] | 1302 | 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}}; |
---|
| 1303 | 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}}; |
---|
| 1304 | #else |
---|
| 1305 | 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 } }; |
---|
| 1306 | 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 } }; |
---|
[443] | 1307 | #endif |
---|
[608] | 1308 | #else |
---|
[622] | 1309 | #if SEC_DMM2_E0146_HHIFIX |
---|
[608] | 1310 | 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}}; |
---|
| 1311 | 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}}; |
---|
| 1312 | #else |
---|
| 1313 | 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}}; |
---|
| 1314 | 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}}; |
---|
| 1315 | #endif |
---|
| 1316 | #endif |
---|
| 1317 | #endif |
---|
| 1318 | UInt dir = pcCU->getLumaIntraDir( absPartIdx ); |
---|
| 1319 | UInt puIdx = (pcCU->getWidth(absPartIdx) == 64) ? 2 : ( (pcCU->getPartitionSize(absPartIdx) == SIZE_NxN && pcCU->getWidth(absPartIdx) == 8) ? 0 : 1 ); |
---|
| 1320 | UInt codeIdx = 0; |
---|
[2] | 1321 | |
---|
[608] | 1322 | if( dir < NUM_INTRA_MODE ) |
---|
| 1323 | { |
---|
| 1324 | codeIdx = 1; |
---|
[2] | 1325 | } |
---|
[608] | 1326 | if( isDimMode( dir ) ) |
---|
[2] | 1327 | { |
---|
[608] | 1328 | switch( getDimType( dir ) ) |
---|
[2] | 1329 | { |
---|
[608] | 1330 | case DMM1_IDX: codeIdx = 3; break; |
---|
| 1331 | case DMM4_IDX: codeIdx = 4; break; |
---|
| 1332 | case DMM3_IDX: codeIdx = 5; break; |
---|
| 1333 | #if LGE_SDC_REMOVE_DC_E0158 |
---|
[622] | 1334 | #if SEC_DMM2_E0146_HHIFIX |
---|
[608] | 1335 | case RBC_IDX: codeIdx = 6; break; |
---|
| 1336 | #else |
---|
| 1337 | case DMM2_IDX: codeIdx = 6; break; |
---|
| 1338 | case RBC_IDX: codeIdx = 7; break; |
---|
| 1339 | #endif |
---|
| 1340 | #else |
---|
[622] | 1341 | #if SEC_DMM2_E0146_HHIFIX |
---|
[608] | 1342 | case RBC_IDX: codeIdx = 7; break; |
---|
| 1343 | #else |
---|
| 1344 | case DMM2_IDX: codeIdx = 7; break; |
---|
| 1345 | case RBC_IDX: codeIdx = 8; break; |
---|
| 1346 | #endif |
---|
| 1347 | #endif |
---|
| 1348 | default: break; |
---|
[2] | 1349 | } |
---|
| 1350 | } |
---|
[608] | 1351 | |
---|
| 1352 | #if H_3D_DIM_SDC |
---|
| 1353 | if( pcCU->getSDCFlag( absPartIdx ) ) |
---|
[2] | 1354 | { |
---|
[608] | 1355 | switch( dir ) |
---|
[2] | 1356 | { |
---|
[608] | 1357 | case PLANAR_IDX: codeIdx = 0; break; |
---|
| 1358 | #if !LGE_SDC_REMOVE_DC_E0158 |
---|
| 1359 | case DC_IDX: codeIdx = 6; break; |
---|
| 1360 | #endif |
---|
| 1361 | default: codeIdx = 2; break; |
---|
[2] | 1362 | } |
---|
| 1363 | } |
---|
| 1364 | #endif |
---|
[608] | 1365 | #if ZJU_DEPTH_INTRA_MODE_E0204 |
---|
| 1366 | if( puIdx==1 ) |
---|
[2] | 1367 | { |
---|
[608] | 1368 | if( codeIdx==1 || codeIdx==2 || codeIdx==4 ) |
---|
[56] | 1369 | { |
---|
[608] | 1370 | m_pcBinIf->encodeBinEP( 0 ); |
---|
[56] | 1371 | } |
---|
[608] | 1372 | else |
---|
| 1373 | { |
---|
| 1374 | m_pcBinIf->encodeBinEP( 1 ); |
---|
| 1375 | } |
---|
[2] | 1376 | } |
---|
[608] | 1377 | #endif |
---|
| 1378 | //mode coding |
---|
| 1379 | for( UInt i = 0; i < codeWordLenTable[puIdx][codeIdx]; i++ ) |
---|
| 1380 | { |
---|
| 1381 | UInt bit = codeWordTable[puIdx][codeIdx] & ( 1<<(codeWordLenTable[puIdx][codeIdx] - i - 1) ); |
---|
| 1382 | UInt ctxDepthMode = puIdx*3 + ( (i >= 2) ? 2 : i ); |
---|
| 1383 | m_pcBinIf->encodeBin( bit!=0 , m_cDepthIntraModeSCModel.get(0, 0, ctxDepthMode) ); |
---|
| 1384 | } |
---|
[2] | 1385 | } |
---|
[608] | 1386 | #endif |
---|
[2] | 1387 | |
---|
[608] | 1388 | |
---|
[2] | 1389 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1390 | { |
---|
[56] | 1391 | const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1; |
---|
| 1392 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
| 1393 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
[608] | 1394 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
| 1395 | { |
---|
| 1396 | m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); |
---|
| 1397 | } |
---|
| 1398 | if (uiInterDir < 2) |
---|
| 1399 | { |
---|
| 1400 | m_pcBinIf->encodeBin( uiInterDir, *( pCtx + 4 ) ); |
---|
| 1401 | } |
---|
| 1402 | #if H_MV_ENC_DEC_TRAC |
---|
| 1403 | DTRACE_PU("inter_pred_idc", uiInterDir ); |
---|
| 1404 | #endif |
---|
[56] | 1405 | |
---|
[2] | 1406 | return; |
---|
| 1407 | } |
---|
| 1408 | |
---|
| 1409 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1410 | { |
---|
| 1411 | { |
---|
[608] | 1412 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
[56] | 1413 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
| 1414 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
[608] | 1415 | |
---|
[56] | 1416 | if( iRefFrame > 0 ) |
---|
[2] | 1417 | { |
---|
[608] | 1418 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
| 1419 | pCtx++; |
---|
| 1420 | iRefFrame--; |
---|
| 1421 | for( UInt ui = 0; ui < uiRefNum; ++ui ) |
---|
| 1422 | { |
---|
| 1423 | const UInt uiSymbol = ui == iRefFrame ? 0 : 1; |
---|
| 1424 | if( ui == 0 ) |
---|
| 1425 | { |
---|
| 1426 | m_pcBinIf->encodeBin( uiSymbol, *pCtx ); |
---|
| 1427 | } |
---|
| 1428 | else |
---|
| 1429 | { |
---|
| 1430 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
| 1431 | } |
---|
| 1432 | if( uiSymbol == 0 ) |
---|
| 1433 | { |
---|
| 1434 | break; |
---|
| 1435 | } |
---|
| 1436 | } |
---|
[2] | 1437 | } |
---|
[608] | 1438 | #if H_MV_ENC_DEC_TRAC |
---|
| 1439 | #if ENC_DEC_TRACE |
---|
| 1440 | iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
| 1441 | if ( eRefList == REF_PIC_LIST_0 ) |
---|
[296] | 1442 | { |
---|
[608] | 1443 | DTRACE_PU("ref_idx_l0", iRefFrame) |
---|
[296] | 1444 | } |
---|
[608] | 1445 | else |
---|
[56] | 1446 | { |
---|
[608] | 1447 | DTRACE_PU("ref_idx_l1", iRefFrame) |
---|
[56] | 1448 | } |
---|
[296] | 1449 | #endif |
---|
[608] | 1450 | #endif |
---|
[2] | 1451 | } |
---|
| 1452 | return; |
---|
| 1453 | } |
---|
| 1454 | |
---|
| 1455 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1456 | { |
---|
[56] | 1457 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
| 1458 | { |
---|
| 1459 | return; |
---|
| 1460 | } |
---|
[2] | 1461 | |
---|
[56] | 1462 | const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
| 1463 | const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
| 1464 | const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
| 1465 | ContextModel* pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
[2] | 1466 | |
---|
[56] | 1467 | m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx ); |
---|
| 1468 | m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx ); |
---|
[2] | 1469 | |
---|
[56] | 1470 | const Bool bHorAbsGr0 = iHor != 0; |
---|
| 1471 | const Bool bVerAbsGr0 = iVer != 0; |
---|
| 1472 | const UInt uiHorAbs = 0 > iHor ? -iHor : iHor; |
---|
| 1473 | const UInt uiVerAbs = 0 > iVer ? -iVer : iVer; |
---|
| 1474 | pCtx++; |
---|
[2] | 1475 | |
---|
[56] | 1476 | if( bHorAbsGr0 ) |
---|
| 1477 | { |
---|
| 1478 | m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx ); |
---|
| 1479 | } |
---|
| 1480 | |
---|
| 1481 | if( bVerAbsGr0 ) |
---|
| 1482 | { |
---|
| 1483 | m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx ); |
---|
| 1484 | } |
---|
| 1485 | |
---|
| 1486 | if( bHorAbsGr0 ) |
---|
| 1487 | { |
---|
| 1488 | if( uiHorAbs > 1 ) |
---|
| 1489 | { |
---|
| 1490 | xWriteEpExGolomb( uiHorAbs-2, 1 ); |
---|
| 1491 | } |
---|
| 1492 | |
---|
| 1493 | m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 ); |
---|
| 1494 | } |
---|
| 1495 | |
---|
| 1496 | if( bVerAbsGr0 ) |
---|
| 1497 | { |
---|
| 1498 | if( uiVerAbs > 1 ) |
---|
| 1499 | { |
---|
| 1500 | xWriteEpExGolomb( uiVerAbs-2, 1 ); |
---|
| 1501 | } |
---|
| 1502 | |
---|
| 1503 | m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); |
---|
| 1504 | } |
---|
[2] | 1505 | |
---|
| 1506 | return; |
---|
| 1507 | } |
---|
| 1508 | |
---|
| 1509 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1510 | { |
---|
[56] | 1511 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
[2] | 1512 | |
---|
[56] | 1513 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
| 1514 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
| 1515 | |
---|
[608] | 1516 | UInt uiAbsDQp = (UInt)((iDQp > 0)? iDQp : (-iDQp)); |
---|
| 1517 | UInt TUValue = min((Int)uiAbsDQp, CU_DQP_TU_CMAX); |
---|
| 1518 | xWriteUnaryMaxSymbol( TUValue, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
| 1519 | if( uiAbsDQp >= CU_DQP_TU_CMAX ) |
---|
[2] | 1520 | { |
---|
[608] | 1521 | xWriteEpExGolomb( uiAbsDQp - CU_DQP_TU_CMAX, CU_DQP_EG_k ); |
---|
[2] | 1522 | } |
---|
[608] | 1523 | |
---|
| 1524 | if ( uiAbsDQp > 0) |
---|
[2] | 1525 | { |
---|
[56] | 1526 | UInt uiSign = (iDQp > 0 ? 0 : 1); |
---|
| 1527 | m_pcBinIf->encodeBinEP(uiSign); |
---|
[608] | 1528 | } |
---|
[56] | 1529 | |
---|
[2] | 1530 | return; |
---|
| 1531 | } |
---|
| 1532 | |
---|
| 1533 | Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
| 1534 | { |
---|
| 1535 | UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
[608] | 1536 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
[56] | 1537 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
[608] | 1538 | #if !H_MV_ENC_DEC_TRAC |
---|
[56] | 1539 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1540 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
| 1541 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1542 | DTRACE_CABAC_V( uiCbf ) |
---|
| 1543 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 1544 | DTRACE_CABAC_V( uiCtx ) |
---|
| 1545 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 1546 | DTRACE_CABAC_V( eType ) |
---|
| 1547 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 1548 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1549 | DTRACE_CABAC_T( "\n" ) |
---|
[608] | 1550 | #endif |
---|
[2] | 1551 | } |
---|
| 1552 | |
---|
[608] | 1553 | void TEncSbac::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) |
---|
| 1554 | { |
---|
| 1555 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
| 1556 | { |
---|
| 1557 | return; |
---|
| 1558 | } |
---|
| 1559 | if(width != 4 || height != 4) |
---|
| 1560 | { |
---|
| 1561 | return; |
---|
| 1562 | } |
---|
| 1563 | |
---|
| 1564 | UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,eTType); |
---|
| 1565 | m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) ); |
---|
| 1566 | #if !H_MV_ENC_DEC_TRAC |
---|
| 1567 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
| 1568 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
| 1569 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1570 | DTRACE_CABAC_V( useTransformSkip ) |
---|
| 1571 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
| 1572 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
| 1573 | DTRACE_CABAC_T( "\tetype=" ) |
---|
| 1574 | DTRACE_CABAC_V( eTType ) |
---|
| 1575 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 1576 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1577 | DTRACE_CABAC_T( "\n" ) |
---|
| 1578 | #endif |
---|
| 1579 | } |
---|
| 1580 | |
---|
| 1581 | /** Code I_PCM information. |
---|
[56] | 1582 | * \param pcCU pointer to CU |
---|
| 1583 | * \param uiAbsPartIdx CU index |
---|
| 1584 | * \returns Void |
---|
| 1585 | */ |
---|
[608] | 1586 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
[2] | 1587 | { |
---|
[56] | 1588 | UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0; |
---|
| 1589 | |
---|
| 1590 | Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx); |
---|
| 1591 | |
---|
[608] | 1592 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
| 1593 | #if H_MV_ENC_DEC_TRAC |
---|
| 1594 | DTRACE_CU("pcm_flag", uiIPCM) |
---|
| 1595 | #endif |
---|
| 1596 | if (writePCMSampleFlag) |
---|
[2] | 1597 | { |
---|
[608] | 1598 | m_pcBinIf->encodePCMAlignBits(); |
---|
[56] | 1599 | |
---|
| 1600 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
| 1601 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
| 1602 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
| 1603 | Pel* piPCMSample; |
---|
| 1604 | UInt uiWidth; |
---|
| 1605 | UInt uiHeight; |
---|
| 1606 | UInt uiSampleBits; |
---|
| 1607 | UInt uiX, uiY; |
---|
| 1608 | |
---|
| 1609 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
| 1610 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
| 1611 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
| 1612 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
| 1613 | |
---|
| 1614 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 1615 | { |
---|
| 1616 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
[2] | 1617 | { |
---|
[56] | 1618 | UInt uiSample = piPCMSample[uiX]; |
---|
| 1619 | |
---|
| 1620 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
[2] | 1621 | } |
---|
[56] | 1622 | piPCMSample += uiWidth; |
---|
[2] | 1623 | } |
---|
[56] | 1624 | |
---|
| 1625 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
| 1626 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
| 1627 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
| 1628 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
| 1629 | |
---|
| 1630 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 1631 | { |
---|
| 1632 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 1633 | { |
---|
| 1634 | UInt uiSample = piPCMSample[uiX]; |
---|
| 1635 | |
---|
| 1636 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
| 1637 | } |
---|
| 1638 | piPCMSample += uiWidth; |
---|
| 1639 | } |
---|
| 1640 | |
---|
| 1641 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
| 1642 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
| 1643 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
| 1644 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
| 1645 | |
---|
| 1646 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
| 1647 | { |
---|
| 1648 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
| 1649 | { |
---|
| 1650 | UInt uiSample = piPCMSample[uiX]; |
---|
| 1651 | |
---|
| 1652 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
| 1653 | } |
---|
| 1654 | piPCMSample += uiWidth; |
---|
| 1655 | } |
---|
[608] | 1656 | m_pcBinIf->resetBac(); |
---|
[2] | 1657 | } |
---|
| 1658 | } |
---|
| 1659 | |
---|
| 1660 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 1661 | { |
---|
| 1662 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
[56] | 1663 | UInt uiCtx = 0; |
---|
[2] | 1664 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
[608] | 1665 | #if !H_MV_ENC_DEC_TRAC |
---|
[56] | 1666 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1667 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
| 1668 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
| 1669 | DTRACE_CABAC_V( uiCbf ) |
---|
| 1670 | DTRACE_CABAC_T( "\tctx=" ) |
---|
| 1671 | DTRACE_CABAC_V( uiCtx ) |
---|
| 1672 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
| 1673 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1674 | DTRACE_CABAC_T( "\n" ) |
---|
[608] | 1675 | #else |
---|
| 1676 | DTRACE_CU( "rqt_root_cbf", uiCbf ) |
---|
| 1677 | #endif |
---|
[2] | 1678 | } |
---|
| 1679 | |
---|
[608] | 1680 | Void TEncSbac::codeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
---|
| 1681 | { |
---|
| 1682 | // this function is only used to estimate the bits when cbf is 0 |
---|
| 1683 | // and will never be called when writing the bistream. do not need to write log |
---|
| 1684 | UInt uiCbf = 0; |
---|
| 1685 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
| 1686 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
| 1687 | } |
---|
| 1688 | |
---|
| 1689 | Void TEncSbac::codeQtRootCbfZero( TComDataCU* pcCU ) |
---|
| 1690 | { |
---|
| 1691 | // this function is only used to estimate the bits when cbf is 0 |
---|
| 1692 | // and will never be called when writing the bistream. do not need to write log |
---|
| 1693 | UInt uiCbf = 0; |
---|
| 1694 | UInt uiCtx = 0; |
---|
| 1695 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
| 1696 | } |
---|
| 1697 | |
---|
[2] | 1698 | /** Encode (X,Y) position of the last significant coefficient |
---|
| 1699 | * \param uiPosX X component of last coefficient |
---|
| 1700 | * \param uiPosY Y component of last coefficient |
---|
[56] | 1701 | * \param width Block width |
---|
| 1702 | * \param height Block height |
---|
[2] | 1703 | * \param eTType plane type / luminance or chrominance |
---|
| 1704 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
| 1705 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
| 1706 | */ |
---|
[56] | 1707 | Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
[2] | 1708 | { |
---|
[56] | 1709 | // swap |
---|
[2] | 1710 | if( uiScanIdx == SCAN_VER ) |
---|
| 1711 | { |
---|
| 1712 | swap( uiPosX, uiPosY ); |
---|
| 1713 | } |
---|
| 1714 | |
---|
[56] | 1715 | UInt uiCtxLast; |
---|
| 1716 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
| 1717 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
| 1718 | UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; |
---|
| 1719 | UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; |
---|
| 1720 | |
---|
[608] | 1721 | |
---|
| 1722 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
| 1723 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
| 1724 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
| 1725 | shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
| 1726 | shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
[56] | 1727 | // posX |
---|
| 1728 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) |
---|
[2] | 1729 | { |
---|
[608] | 1730 | m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
[2] | 1731 | } |
---|
[56] | 1732 | if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) |
---|
[2] | 1733 | { |
---|
[608] | 1734 | m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
[2] | 1735 | } |
---|
| 1736 | |
---|
[56] | 1737 | // posY |
---|
| 1738 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) |
---|
[2] | 1739 | { |
---|
[608] | 1740 | m_pcBinIf->encodeBin( 1, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
[2] | 1741 | } |
---|
[56] | 1742 | if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ]) |
---|
[2] | 1743 | { |
---|
[608] | 1744 | m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
| 1745 | } |
---|
[56] | 1746 | if ( uiGroupIdxX > 3 ) |
---|
| 1747 | { |
---|
| 1748 | UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; |
---|
| 1749 | uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; |
---|
| 1750 | for (Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
| 1751 | { |
---|
| 1752 | m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 ); |
---|
| 1753 | } |
---|
[2] | 1754 | } |
---|
[56] | 1755 | if ( uiGroupIdxY > 3 ) |
---|
| 1756 | { |
---|
| 1757 | UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; |
---|
| 1758 | uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; |
---|
| 1759 | for ( Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
| 1760 | { |
---|
| 1761 | m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 ); |
---|
| 1762 | } |
---|
| 1763 | } |
---|
[2] | 1764 | } |
---|
| 1765 | |
---|
[56] | 1766 | Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
[2] | 1767 | { |
---|
[608] | 1768 | #if !H_MV_ENC_DEC_TRAC |
---|
[56] | 1769 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
[2] | 1770 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
| 1771 | DTRACE_CABAC_V( eTType ) |
---|
| 1772 | DTRACE_CABAC_T( "\twidth=" ) |
---|
| 1773 | DTRACE_CABAC_V( uiWidth ) |
---|
| 1774 | DTRACE_CABAC_T( "\theight=" ) |
---|
| 1775 | DTRACE_CABAC_V( uiHeight ) |
---|
| 1776 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
| 1777 | DTRACE_CABAC_V( uiDepth ) |
---|
| 1778 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
| 1779 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
| 1780 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
| 1781 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
| 1782 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
| 1783 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
| 1784 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
| 1785 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
| 1786 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
| 1787 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1788 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
| 1789 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
| 1790 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
| 1791 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
| 1792 | DTRACE_CABAC_T( "\n" ) |
---|
[608] | 1793 | #endif |
---|
[2] | 1794 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
| 1795 | { |
---|
| 1796 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
| 1797 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
| 1798 | } |
---|
| 1799 | |
---|
| 1800 | UInt uiNumSig = 0; |
---|
| 1801 | |
---|
| 1802 | // compute number of significant coefficients |
---|
[56] | 1803 | uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); |
---|
[2] | 1804 | |
---|
| 1805 | if ( uiNumSig == 0 ) |
---|
| 1806 | return; |
---|
[608] | 1807 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
| 1808 | { |
---|
| 1809 | codeTransformSkipFlags( pcCU,uiAbsPartIdx, uiWidth, uiHeight, eTType ); |
---|
| 1810 | } |
---|
[2] | 1811 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
| 1812 | |
---|
| 1813 | //----- encode significance map ----- |
---|
[608] | 1814 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
[56] | 1815 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
[608] | 1816 | const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize - 1 ]; |
---|
[2] | 1817 | |
---|
[608] | 1818 | Bool beValid; |
---|
| 1819 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
[56] | 1820 | { |
---|
| 1821 | beValid = false; |
---|
| 1822 | } |
---|
| 1823 | else |
---|
| 1824 | { |
---|
| 1825 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
| 1826 | } |
---|
[2] | 1827 | |
---|
[56] | 1828 | // Find position of last coefficient |
---|
| 1829 | Int scanPosLast = -1; |
---|
| 1830 | Int posLast; |
---|
| 1831 | |
---|
| 1832 | const UInt * scanCG; |
---|
| 1833 | { |
---|
| 1834 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
| 1835 | if( uiLog2BlockSize == 3 ) |
---|
| 1836 | { |
---|
| 1837 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
[2] | 1838 | } |
---|
[56] | 1839 | else if( uiLog2BlockSize == 5 ) |
---|
| 1840 | { |
---|
| 1841 | scanCG = g_sigLastScanCG32x32; |
---|
| 1842 | } |
---|
| 1843 | } |
---|
| 1844 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
| 1845 | static const UInt uiShift = MLS_CG_SIZE >> 1; |
---|
| 1846 | const UInt uiNumBlkSide = uiWidth >> uiShift; |
---|
[2] | 1847 | |
---|
[56] | 1848 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
| 1849 | |
---|
| 1850 | do |
---|
[2] | 1851 | { |
---|
[56] | 1852 | posLast = scan[ ++scanPosLast ]; |
---|
| 1853 | |
---|
| 1854 | // get L1 sig map |
---|
| 1855 | UInt uiPosY = posLast >> uiLog2BlockSize; |
---|
| 1856 | UInt uiPosX = posLast - ( uiPosY << uiLog2BlockSize ); |
---|
| 1857 | UInt uiBlkIdx = uiNumBlkSide * (uiPosY >> uiShift) + (uiPosX >> uiShift); |
---|
| 1858 | if( pcCoef[ posLast ] ) |
---|
[2] | 1859 | { |
---|
[56] | 1860 | uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; |
---|
[2] | 1861 | } |
---|
[56] | 1862 | |
---|
| 1863 | uiNumSig -= ( pcCoef[ posLast ] != 0 ); |
---|
[2] | 1864 | } |
---|
[56] | 1865 | while ( uiNumSig > 0 ); |
---|
| 1866 | |
---|
| 1867 | // Code position of last coefficient |
---|
| 1868 | Int posLastY = posLast >> uiLog2BlockSize; |
---|
| 1869 | Int posLastX = posLast - ( posLastY << uiLog2BlockSize ); |
---|
| 1870 | codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, eTType, uiScanIdx); |
---|
| 1871 | |
---|
| 1872 | //===== code significance flag ===== |
---|
| 1873 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
| 1874 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
| 1875 | |
---|
| 1876 | |
---|
| 1877 | const Int iLastScanSet = scanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
[608] | 1878 | UInt c1 = 1; |
---|
[56] | 1879 | UInt uiGoRiceParam = 0; |
---|
| 1880 | Int iScanPosSig = scanPosLast; |
---|
| 1881 | |
---|
| 1882 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
[2] | 1883 | { |
---|
[56] | 1884 | Int numNonZero = 0; |
---|
| 1885 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
| 1886 | uiGoRiceParam = 0; |
---|
| 1887 | Int absCoeff[16]; |
---|
| 1888 | UInt coeffSigns = 0; |
---|
| 1889 | |
---|
| 1890 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
| 1891 | |
---|
| 1892 | if( iScanPosSig == scanPosLast ) |
---|
[2] | 1893 | { |
---|
[56] | 1894 | absCoeff[ 0 ] = abs( pcCoef[ posLast ] ); |
---|
| 1895 | coeffSigns = ( pcCoef[ posLast ] < 0 ); |
---|
| 1896 | numNonZero = 1; |
---|
| 1897 | lastNZPosInCG = iScanPosSig; |
---|
| 1898 | firstNZPosInCG = iScanPosSig; |
---|
| 1899 | iScanPosSig--; |
---|
| 1900 | } |
---|
[2] | 1901 | |
---|
[56] | 1902 | // encode significant_coeffgroup_flag |
---|
| 1903 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
| 1904 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
| 1905 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
| 1906 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
[2] | 1907 | { |
---|
[56] | 1908 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
| 1909 | } |
---|
| 1910 | else |
---|
| 1911 | { |
---|
| 1912 | UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); |
---|
[608] | 1913 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
[56] | 1914 | m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
| 1915 | } |
---|
| 1916 | |
---|
| 1917 | // encode significant_coeff_flag |
---|
| 1918 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
| 1919 | { |
---|
[608] | 1920 | Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
[56] | 1921 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
| 1922 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
[2] | 1923 | { |
---|
[56] | 1924 | uiBlkPos = scan[ iScanPosSig ]; |
---|
| 1925 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
| 1926 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
| 1927 | uiSig = (pcCoef[ uiBlkPos ] != 0); |
---|
| 1928 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
[2] | 1929 | { |
---|
[608] | 1930 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType ); |
---|
[56] | 1931 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
| 1932 | } |
---|
| 1933 | if( uiSig ) |
---|
| 1934 | { |
---|
| 1935 | absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); |
---|
| 1936 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
| 1937 | numNonZero++; |
---|
| 1938 | if( lastNZPosInCG == -1 ) |
---|
[2] | 1939 | { |
---|
[56] | 1940 | lastNZPosInCG = iScanPosSig; |
---|
[2] | 1941 | } |
---|
[56] | 1942 | firstNZPosInCG = iScanPosSig; |
---|
[2] | 1943 | } |
---|
| 1944 | } |
---|
[56] | 1945 | } |
---|
| 1946 | else |
---|
| 1947 | { |
---|
| 1948 | iScanPosSig = iSubPos - 1; |
---|
| 1949 | } |
---|
| 1950 | |
---|
| 1951 | if( numNonZero > 0 ) |
---|
| 1952 | { |
---|
[608] | 1953 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
[56] | 1954 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
| 1955 | |
---|
[608] | 1956 | if( c1 == 0 ) |
---|
[56] | 1957 | { |
---|
| 1958 | uiCtxSet++; |
---|
[2] | 1959 | } |
---|
[608] | 1960 | c1 = 1; |
---|
[56] | 1961 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
| 1962 | |
---|
| 1963 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
| 1964 | Int firstC2FlagIdx = -1; |
---|
| 1965 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
[2] | 1966 | { |
---|
[56] | 1967 | UInt uiSymbol = absCoeff[ idx ] > 1; |
---|
| 1968 | m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] ); |
---|
[2] | 1969 | if( uiSymbol ) |
---|
| 1970 | { |
---|
| 1971 | c1 = 0; |
---|
[56] | 1972 | |
---|
| 1973 | if (firstC2FlagIdx == -1) |
---|
| 1974 | { |
---|
| 1975 | firstC2FlagIdx = idx; |
---|
| 1976 | } |
---|
[2] | 1977 | } |
---|
[56] | 1978 | else if( (c1 < 3) && (c1 > 0) ) |
---|
[2] | 1979 | { |
---|
| 1980 | c1++; |
---|
| 1981 | } |
---|
| 1982 | } |
---|
| 1983 | |
---|
[56] | 1984 | if (c1 == 0) |
---|
[2] | 1985 | { |
---|
[56] | 1986 | |
---|
| 1987 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
| 1988 | if ( firstC2FlagIdx != -1) |
---|
[2] | 1989 | { |
---|
[56] | 1990 | UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; |
---|
| 1991 | m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); |
---|
| 1992 | } |
---|
[2] | 1993 | } |
---|
| 1994 | |
---|
[56] | 1995 | if( beValid && signHidden ) |
---|
[2] | 1996 | { |
---|
[56] | 1997 | m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 ); |
---|
[2] | 1998 | } |
---|
[56] | 1999 | else |
---|
| 2000 | { |
---|
| 2001 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
| 2002 | } |
---|
| 2003 | |
---|
| 2004 | Int iFirstCoeff2 = 1; |
---|
| 2005 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
| 2006 | { |
---|
| 2007 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
| 2008 | { |
---|
| 2009 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1; |
---|
[2] | 2010 | |
---|
[56] | 2011 | if( absCoeff[ idx ] >= baseLevel) |
---|
| 2012 | { |
---|
[608] | 2013 | xWriteCoefRemainExGolomb( absCoeff[ idx ] - baseLevel, uiGoRiceParam ); |
---|
| 2014 | if(absCoeff[idx] > 3*(1<<uiGoRiceParam)) |
---|
| 2015 | { |
---|
| 2016 | uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4); |
---|
| 2017 | } |
---|
[56] | 2018 | } |
---|
| 2019 | if(absCoeff[ idx ] >= 2) |
---|
| 2020 | { |
---|
| 2021 | iFirstCoeff2 = 0; |
---|
| 2022 | } |
---|
| 2023 | } |
---|
| 2024 | } |
---|
[2] | 2025 | } |
---|
| 2026 | } |
---|
[56] | 2027 | |
---|
[2] | 2028 | return; |
---|
| 2029 | } |
---|
| 2030 | |
---|
[608] | 2031 | /** code SAO offset sign |
---|
| 2032 | * \param code sign value |
---|
| 2033 | */ |
---|
[443] | 2034 | Void TEncSbac::codeSAOSign( UInt code ) |
---|
| 2035 | { |
---|
| 2036 | m_pcBinIf->encodeBinEP( code ); |
---|
| 2037 | } |
---|
[2] | 2038 | |
---|
[443] | 2039 | Void TEncSbac::codeSaoMaxUvlc ( UInt code, UInt maxSymbol ) |
---|
| 2040 | { |
---|
| 2041 | if (maxSymbol == 0) |
---|
| 2042 | { |
---|
| 2043 | return; |
---|
| 2044 | } |
---|
| 2045 | |
---|
| 2046 | Int i; |
---|
| 2047 | Bool bCodeLast = ( maxSymbol > code ); |
---|
| 2048 | |
---|
| 2049 | if ( code == 0 ) |
---|
| 2050 | { |
---|
| 2051 | m_pcBinIf->encodeBinEP( 0 ); |
---|
| 2052 | } |
---|
| 2053 | else |
---|
| 2054 | { |
---|
| 2055 | m_pcBinIf->encodeBinEP( 1 ); |
---|
| 2056 | for ( i=0; i<code-1; i++ ) |
---|
| 2057 | { |
---|
| 2058 | m_pcBinIf->encodeBinEP( 1 ); |
---|
| 2059 | } |
---|
| 2060 | if( bCodeLast ) |
---|
| 2061 | { |
---|
| 2062 | m_pcBinIf->encodeBinEP( 0 ); |
---|
| 2063 | } |
---|
| 2064 | } |
---|
| 2065 | } |
---|
| 2066 | |
---|
[608] | 2067 | |
---|
[443] | 2068 | /** Code SAO EO class or BO band position |
---|
| 2069 | * \param uiLength |
---|
| 2070 | * \param uiCode |
---|
| 2071 | */ |
---|
| 2072 | Void TEncSbac::codeSaoUflc ( UInt uiLength, UInt uiCode ) |
---|
| 2073 | { |
---|
| 2074 | m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); |
---|
| 2075 | } |
---|
| 2076 | /** Code SAO merge flags |
---|
| 2077 | * \param uiCode |
---|
| 2078 | * \param uiCompIdx |
---|
| 2079 | */ |
---|
| 2080 | Void TEncSbac::codeSaoMerge ( UInt uiCode ) |
---|
| 2081 | { |
---|
| 2082 | if (uiCode == 0) |
---|
| 2083 | { |
---|
| 2084 | m_pcBinIf->encodeBin(0, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
| 2085 | } |
---|
| 2086 | else |
---|
| 2087 | { |
---|
| 2088 | m_pcBinIf->encodeBin(1, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
| 2089 | } |
---|
| 2090 | } |
---|
| 2091 | /** Code SAO type index |
---|
| 2092 | * \param uiCode |
---|
| 2093 | */ |
---|
| 2094 | Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) |
---|
| 2095 | { |
---|
| 2096 | if (uiCode == 0) |
---|
| 2097 | { |
---|
| 2098 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
| 2099 | } |
---|
| 2100 | else |
---|
| 2101 | { |
---|
| 2102 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
[608] | 2103 | m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 ); |
---|
[443] | 2104 | } |
---|
| 2105 | } |
---|
[2] | 2106 | /*! |
---|
| 2107 | **************************************************************************** |
---|
| 2108 | * \brief |
---|
| 2109 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
| 2110 | **************************************************************************** |
---|
| 2111 | */ |
---|
[56] | 2112 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
[2] | 2113 | { |
---|
[608] | 2114 | estCBFBit( pcEstBitsSbac ); |
---|
[56] | 2115 | |
---|
[608] | 2116 | estSignificantCoeffGroupMapBit( pcEstBitsSbac, eTType ); |
---|
[2] | 2117 | |
---|
| 2118 | // encode significance map |
---|
[56] | 2119 | estSignificantMapBit( pcEstBitsSbac, width, height, eTType ); |
---|
[2] | 2120 | |
---|
| 2121 | // encode significant coefficients |
---|
[608] | 2122 | estSignificantCoefficientsBit( pcEstBitsSbac, eTType ); |
---|
[2] | 2123 | } |
---|
| 2124 | |
---|
| 2125 | /*! |
---|
| 2126 | **************************************************************************** |
---|
| 2127 | * \brief |
---|
| 2128 | * estimate bit cost for each CBP bit |
---|
| 2129 | **************************************************************************** |
---|
| 2130 | */ |
---|
[608] | 2131 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac ) |
---|
[2] | 2132 | { |
---|
| 2133 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
| 2134 | |
---|
[56] | 2135 | for( UInt uiCtxInc = 0; uiCtxInc < 3*NUM_QT_CBF_CTX; uiCtxInc++ ) |
---|
[2] | 2136 | { |
---|
[56] | 2137 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
| 2138 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
[2] | 2139 | } |
---|
| 2140 | |
---|
[56] | 2141 | pCtx = m_cCUQtRootCbfSCModel.get( 0 ); |
---|
| 2142 | |
---|
[2] | 2143 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
| 2144 | { |
---|
[56] | 2145 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
| 2146 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
[2] | 2147 | } |
---|
| 2148 | } |
---|
| 2149 | |
---|
| 2150 | |
---|
| 2151 | /*! |
---|
| 2152 | **************************************************************************** |
---|
| 2153 | * \brief |
---|
[56] | 2154 | * estimate SAMBAC bit cost for significant coefficient group map |
---|
[2] | 2155 | **************************************************************************** |
---|
| 2156 | */ |
---|
[608] | 2157 | Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
[2] | 2158 | { |
---|
[56] | 2159 | Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; |
---|
| 2160 | |
---|
| 2161 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
[2] | 2162 | { |
---|
| 2163 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
| 2164 | { |
---|
[56] | 2165 | pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, eTType, ctxIdx ).getEntropyBits( uiBin ); |
---|
| 2166 | } |
---|
| 2167 | } |
---|
| 2168 | } |
---|
| 2169 | |
---|
| 2170 | |
---|
| 2171 | /*! |
---|
| 2172 | **************************************************************************** |
---|
| 2173 | * \brief |
---|
| 2174 | * estimate SAMBAC bit cost for significant coefficient map |
---|
| 2175 | **************************************************************************** |
---|
| 2176 | */ |
---|
| 2177 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
| 2178 | { |
---|
[608] | 2179 | Int firstCtx = 1, numCtx = 8; |
---|
| 2180 | if (max(width, height) >= 16) |
---|
[56] | 2181 | { |
---|
[608] | 2182 | firstCtx = (eTType == TEXT_LUMA) ? 21 : 12; |
---|
| 2183 | numCtx = (eTType == TEXT_LUMA) ? 6 : 3; |
---|
[56] | 2184 | } |
---|
| 2185 | else if (width == 8) |
---|
| 2186 | { |
---|
[608] | 2187 | firstCtx = 9; |
---|
| 2188 | numCtx = (eTType == TEXT_LUMA) ? 12 : 3; |
---|
[56] | 2189 | } |
---|
| 2190 | |
---|
| 2191 | if (eTType == TEXT_LUMA ) |
---|
| 2192 | { |
---|
[608] | 2193 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
| 2194 | { |
---|
| 2195 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, 0 ).getEntropyBits( bin ); |
---|
| 2196 | } |
---|
| 2197 | |
---|
[56] | 2198 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
| 2199 | { |
---|
| 2200 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
[2] | 2201 | { |
---|
[56] | 2202 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, ctxIdx ).getEntropyBits( uiBin ); |
---|
[2] | 2203 | } |
---|
[56] | 2204 | } |
---|
| 2205 | } |
---|
| 2206 | else |
---|
| 2207 | { |
---|
[608] | 2208 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
| 2209 | { |
---|
| 2210 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + 0 ).getEntropyBits( bin ); |
---|
| 2211 | } |
---|
[56] | 2212 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
| 2213 | { |
---|
| 2214 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
[2] | 2215 | { |
---|
[56] | 2216 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx ).getEntropyBits( uiBin ); |
---|
[2] | 2217 | } |
---|
[56] | 2218 | } |
---|
| 2219 | } |
---|
| 2220 | Int iBitsX = 0, iBitsY = 0; |
---|
[608] | 2221 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
| 2222 | |
---|
| 2223 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
| 2224 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
| 2225 | shiftX = eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
| 2226 | shiftY = eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
| 2227 | |
---|
[56] | 2228 | Int ctx; |
---|
| 2229 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
| 2230 | for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) |
---|
| 2231 | { |
---|
[608] | 2232 | Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX); |
---|
| 2233 | pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); |
---|
| 2234 | iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); |
---|
| 2235 | } |
---|
[56] | 2236 | pcEstBitsSbac->lastXBits[ctx] = iBitsX; |
---|
| 2237 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
| 2238 | for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) |
---|
[2] | 2239 | { |
---|
[608] | 2240 | Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY); |
---|
| 2241 | pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); |
---|
| 2242 | iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); |
---|
| 2243 | } |
---|
[56] | 2244 | pcEstBitsSbac->lastYBits[ctx] = iBitsY; |
---|
[2] | 2245 | } |
---|
| 2246 | |
---|
| 2247 | /*! |
---|
| 2248 | **************************************************************************** |
---|
| 2249 | * \brief |
---|
| 2250 | * estimate bit cost of significant coefficient |
---|
| 2251 | **************************************************************************** |
---|
| 2252 | */ |
---|
[608] | 2253 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
[2] | 2254 | { |
---|
[56] | 2255 | if (eTType==TEXT_LUMA) |
---|
[2] | 2256 | { |
---|
[56] | 2257 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); |
---|
| 2258 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); |
---|
| 2259 | |
---|
| 2260 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++) |
---|
[2] | 2261 | { |
---|
[56] | 2262 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2263 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
[2] | 2264 | } |
---|
[56] | 2265 | |
---|
| 2266 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_LUMA; ctxIdx++) |
---|
| 2267 | { |
---|
| 2268 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2269 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 2270 | } |
---|
[2] | 2271 | } |
---|
[56] | 2272 | else |
---|
| 2273 | { |
---|
| 2274 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA; |
---|
| 2275 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA; |
---|
| 2276 | |
---|
| 2277 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++) |
---|
| 2278 | { |
---|
| 2279 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2280 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 2281 | } |
---|
| 2282 | |
---|
| 2283 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_CHROMA; ctxIdx++) |
---|
| 2284 | { |
---|
| 2285 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
| 2286 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
| 2287 | } |
---|
| 2288 | } |
---|
[2] | 2289 | } |
---|
| 2290 | |
---|
[56] | 2291 | /** |
---|
| 2292 | - Initialize our context information from the nominated source. |
---|
| 2293 | . |
---|
| 2294 | \param pSrc From where to copy context information. |
---|
| 2295 | */ |
---|
| 2296 | Void TEncSbac::xCopyContextsFrom( TEncSbac* pSrc ) |
---|
| 2297 | { |
---|
| 2298 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
| 2299 | } |
---|
| 2300 | |
---|
| 2301 | Void TEncSbac::loadContexts ( TEncSbac* pScr) |
---|
[2] | 2302 | { |
---|
[56] | 2303 | this->xCopyContextsFrom(pScr); |
---|
[2] | 2304 | } |
---|
[56] | 2305 | |
---|
[608] | 2306 | #if LGE_INTER_SDC_E0156 |
---|
| 2307 | Void TEncSbac::codeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
[56] | 2308 | { |
---|
[608] | 2309 | UInt uiSymbol = pcCU->getInterSDCFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
| 2310 | UInt uiCtxInterSDCFlag = pcCU->getCtxInterSDCFlag( uiAbsPartIdx ); |
---|
[56] | 2311 | |
---|
[608] | 2312 | m_pcBinIf->encodeBin( uiSymbol, m_cInterSDCFlagSCModel.get( 0, 0, uiCtxInterSDCFlag ) ); |
---|
[56] | 2313 | } |
---|
| 2314 | |
---|
[608] | 2315 | Void TEncSbac::codeInterSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ) |
---|
[56] | 2316 | { |
---|
[608] | 2317 | Pel segmentDCOffset = pcCU->getInterSDCSegmentDCOffset( uiSegment, uiAbsPartIdx ); |
---|
[56] | 2318 | |
---|
[608] | 2319 | UInt uiSign = segmentDCOffset < 0 ? 1 : 0; |
---|
| 2320 | UInt uiAbsIdx = abs( segmentDCOffset ); |
---|
[56] | 2321 | |
---|
[608] | 2322 | assert( uiAbsIdx > 0 ); |
---|
| 2323 | uiAbsIdx--; |
---|
| 2324 | xWriteExGolombLevel( uiAbsIdx, m_cInterSDCResidualSCModel.get( 0, 0, 0 ) ); |
---|
| 2325 | m_pcBinIf->encodeBin( uiSign, m_cInterSDCResidualSignFlagSCModel.get( 0, 0, 0 ) ); |
---|
[56] | 2326 | } |
---|
| 2327 | #endif |
---|
| 2328 | //! \} |
---|