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