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