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