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