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