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