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