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-2012, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TEncSbac.cpp |
---|
35 | \brief SBAC encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TEncTop.h" |
---|
39 | #include "TEncSbac.h" |
---|
40 | |
---|
41 | #include <map> |
---|
42 | #include <algorithm> |
---|
43 | |
---|
44 | //! \ingroup TLibEncoder |
---|
45 | //! \{ |
---|
46 | |
---|
47 | // ==================================================================================================================== |
---|
48 | // Constructor / destructor / create / destroy |
---|
49 | // ==================================================================================================================== |
---|
50 | |
---|
51 | TEncSbac::TEncSbac() |
---|
52 | // new structure here |
---|
53 | : m_pcBitIf ( NULL ) |
---|
54 | , m_pcSlice ( NULL ) |
---|
55 | , m_pcBinIf ( NULL ) |
---|
56 | , m_bAlfCtrl ( false ) |
---|
57 | , m_uiCoeffCost ( 0 ) |
---|
58 | , m_uiMaxAlfCtrlDepth ( 0 ) |
---|
59 | , m_numContextModels ( 0 ) |
---|
60 | , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels ) |
---|
61 | , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
62 | , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
63 | , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
64 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
65 | , m_cResPredFlagSCModel ( 1, 1, NUM_RES_PRED_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
66 | #endif |
---|
67 | , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
68 | , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
69 | , m_cCUAlfCtrlFlagSCModel ( 1, 1, NUM_ALF_CTRL_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
70 | , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
71 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
72 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
73 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
74 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
75 | , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
76 | , m_cCUQtCbfSCModel ( 1, 2, NUM_QT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
77 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
78 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
79 | , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
80 | , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
81 | , m_cCuCtxLastX ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
82 | , m_cCuCtxLastY ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
83 | , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
84 | , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
85 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
86 | , m_cALFFlagSCModel ( 1, 1, NUM_ALF_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
87 | , m_cALFUvlcSCModel ( 1, 1, NUM_ALF_UVLC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
88 | , m_cALFSvlcSCModel ( 1, 1, NUM_ALF_SVLC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
89 | #if AMP_CTX |
---|
90 | , m_cCUAMPSCModel ( 1, 1, NUM_CU_AMP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
91 | #else |
---|
92 | , m_cCUXPosiSCModel ( 1, 1, NUM_CU_X_POS_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
93 | , m_cCUYPosiSCModel ( 1, 1, NUM_CU_Y_POS_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
94 | #endif |
---|
95 | , m_cSaoFlagSCModel ( 1, 1, NUM_SAO_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
96 | , m_cSaoUvlcSCModel ( 1, 1, NUM_SAO_UVLC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
97 | , m_cSaoSvlcSCModel ( 1, 1, NUM_SAO_SVLC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
98 | #if SAO_UNIT_INTERLEAVING |
---|
99 | , m_cSaoMergeLeftSCModel ( 1, 1, NUM_SAO_MERGE_LEFT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
100 | , m_cSaoMergeUpSCModel ( 1, 1, NUM_SAO_MERGE_UP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
101 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
102 | #endif |
---|
103 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
104 | , m_cDmmFlagSCModel ( 1, 1, NUM_DMM_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
105 | , m_cDmmModeSCModel ( 1, 1, NUM_DMM_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
106 | , m_cDmmDataSCModel ( 1, 1, NUM_DMM_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
107 | #endif |
---|
108 | #if LGE_EDGE_INTRA |
---|
109 | , m_cEdgeIntraSCModel ( 1, 1, NUM_EDGE_INTRA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
110 | #if LGE_EDGE_INTRA_DELTA_DC |
---|
111 | , m_cEdgeIntraDeltaDCSCModel ( 1, 1, NUM_EDGE_INTRA_DELTA_DC_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
112 | #endif |
---|
113 | #endif |
---|
114 | { |
---|
115 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
116 | m_iSliceGranularity = 0; |
---|
117 | } |
---|
118 | |
---|
119 | TEncSbac::~TEncSbac() |
---|
120 | { |
---|
121 | } |
---|
122 | |
---|
123 | // ==================================================================================================================== |
---|
124 | // Public member functions |
---|
125 | // ==================================================================================================================== |
---|
126 | |
---|
127 | Void TEncSbac::resetEntropy () |
---|
128 | { |
---|
129 | Int iQp = m_pcSlice->getSliceQp(); |
---|
130 | SliceType eSliceType = m_pcSlice->getSliceType(); |
---|
131 | |
---|
132 | #if CABAC_INIT_FLAG |
---|
133 | Int encCABACTableIdx = m_pcSlice->getPPS()->getEncCABACTableIdx(); |
---|
134 | if (!m_pcSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && m_pcSlice->getPPS()->getCabacInitPresentFlag()) |
---|
135 | { |
---|
136 | eSliceType = (SliceType) encCABACTableIdx; |
---|
137 | } |
---|
138 | #endif |
---|
139 | |
---|
140 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
141 | |
---|
142 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
143 | m_cCUAlfCtrlFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_CTRL_FLAG ); |
---|
144 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
145 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
146 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
147 | m_cResPredFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RES_PRED_FLAG ); |
---|
148 | #endif |
---|
149 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
150 | #if AMP_CTX |
---|
151 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
152 | #else |
---|
153 | m_cCUXPosiSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_X_POS ); |
---|
154 | m_cCUYPosiSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_Y_POS ); |
---|
155 | #endif |
---|
156 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
157 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
158 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
159 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
160 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
161 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
162 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
163 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
164 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
165 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
166 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
167 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
168 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
169 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
170 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
171 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
172 | m_cALFFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_FLAG ); |
---|
173 | m_cALFUvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_UVLC ); |
---|
174 | m_cALFSvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_SVLC ); |
---|
175 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
176 | m_cSaoFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_FLAG ); |
---|
177 | m_cSaoUvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_UVLC ); |
---|
178 | m_cSaoSvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_SVLC ); |
---|
179 | #if SAO_UNIT_INTERLEAVING |
---|
180 | m_cSaoMergeLeftSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG ); |
---|
181 | m_cSaoMergeUpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_UP_FLAG ); |
---|
182 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
183 | #endif |
---|
184 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
185 | m_cDmmFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM_FLAG ); |
---|
186 | m_cDmmModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM_MODE ); |
---|
187 | m_cDmmDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM_DATA ); |
---|
188 | #endif |
---|
189 | #if LGE_EDGE_INTRA |
---|
190 | m_cEdgeIntraSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_EDGE_INTRA ); |
---|
191 | #if LGE_EDGE_INTRA_DELTA_DC |
---|
192 | m_cEdgeIntraDeltaDCSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_EDGE_INTRA_DELTA_DC ); |
---|
193 | #endif |
---|
194 | #endif |
---|
195 | |
---|
196 | // new structure |
---|
197 | m_uiLastQp = iQp; |
---|
198 | |
---|
199 | m_pcBinIf->start(); |
---|
200 | |
---|
201 | return; |
---|
202 | } |
---|
203 | |
---|
204 | #if CABAC_INIT_FLAG |
---|
205 | /** The function does the following: |
---|
206 | * If current slice type is P/B then it determines the distance of initialisation type 1 and 2 from the current CABAC states and |
---|
207 | * stores the index of the closest table. This index is used for the next P/B slice when cabac_init_present_flag is true. |
---|
208 | */ |
---|
209 | Void TEncSbac::determineCabacInitIdx() |
---|
210 | { |
---|
211 | Int qp = m_pcSlice->getSliceQp(); |
---|
212 | |
---|
213 | if (!m_pcSlice->isIntra()) |
---|
214 | { |
---|
215 | SliceType aSliceTypeChoices[] = {B_SLICE, P_SLICE}; |
---|
216 | |
---|
217 | UInt bestCost = MAX_UINT; |
---|
218 | SliceType bestSliceType = aSliceTypeChoices[0]; |
---|
219 | for (UInt idx=0; idx<2; idx++) |
---|
220 | { |
---|
221 | UInt curCost = 0; |
---|
222 | SliceType curSliceType = aSliceTypeChoices[idx]; |
---|
223 | |
---|
224 | curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
225 | curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
226 | curCost += m_cCUAlfCtrlFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ALF_CTRL_FLAG ); |
---|
227 | curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
228 | curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
229 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
230 | curCost += m_cResPredFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_RES_PRED_FLAG); |
---|
231 | #endif |
---|
232 | curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); |
---|
233 | #if AMP_CTX |
---|
234 | curCost += m_cCUAMPSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_AMP_POS ); |
---|
235 | #else |
---|
236 | curCost += m_cCUXPosiSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_X_POS ); |
---|
237 | curCost += m_cCUYPosiSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_Y_POS ); |
---|
238 | #endif |
---|
239 | curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); |
---|
240 | curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
241 | curCost += m_cCUChromaPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
242 | curCost += m_cCUInterDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTER_DIR ); |
---|
243 | curCost += m_cCUMvdSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVD ); |
---|
244 | curCost += m_cCURefPicSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_REF_PIC ); |
---|
245 | curCost += m_cCUDeltaQpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DQP ); |
---|
246 | curCost += m_cCUQtCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_CBF ); |
---|
247 | curCost += m_cCUQtRootCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
248 | curCost += m_cCUSigCoeffGroupSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
249 | curCost += m_cCUSigSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_FLAG ); |
---|
250 | curCost += m_cCuCtxLastX.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
251 | curCost += m_cCuCtxLastY.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
252 | curCost += m_cCUOneSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ONE_FLAG ); |
---|
253 | curCost += m_cCUAbsSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ABS_FLAG ); |
---|
254 | curCost += m_cMVPIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVP_IDX ); |
---|
255 | curCost += m_cALFFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ALF_FLAG ); |
---|
256 | curCost += m_cALFUvlcSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ALF_UVLC ); |
---|
257 | curCost += m_cALFSvlcSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ALF_SVLC ); |
---|
258 | curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
259 | curCost += m_cSaoFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_FLAG ); |
---|
260 | curCost += m_cSaoUvlcSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_UVLC ); |
---|
261 | curCost += m_cSaoSvlcSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_SVLC ); |
---|
262 | #if SAO_UNIT_INTERLEAVING |
---|
263 | curCost += m_cSaoMergeLeftSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG ); |
---|
264 | curCost += m_cSaoMergeUpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_UP_FLAG ); |
---|
265 | curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
266 | #endif |
---|
267 | |
---|
268 | if (curCost < bestCost) |
---|
269 | { |
---|
270 | bestSliceType = curSliceType; |
---|
271 | bestCost = curCost; |
---|
272 | } |
---|
273 | } |
---|
274 | m_pcSlice->getPPS()->setEncCABACTableIdx( bestSliceType ); |
---|
275 | } |
---|
276 | else |
---|
277 | { |
---|
278 | m_pcSlice->getPPS()->setEncCABACTableIdx( I_SLICE ); |
---|
279 | } |
---|
280 | |
---|
281 | #if CABAC_INIT_FLAG && POZNAN_CABAC_INIT_FLAG_FIX |
---|
282 | m_pcSlice->getPPS()->setEncPrevPOC( m_pcSlice->getPOC() ); |
---|
283 | #endif |
---|
284 | } |
---|
285 | #endif |
---|
286 | |
---|
287 | |
---|
288 | /** The function does the followng: Write out terminate bit. Flush CABAC. Intialize CABAC states. Start CABAC. |
---|
289 | */ |
---|
290 | Void TEncSbac::updateContextTables( SliceType eSliceType, Int iQp, Bool bExecuteFinish ) |
---|
291 | { |
---|
292 | m_pcBinIf->encodeBinTrm(1); |
---|
293 | if (bExecuteFinish) m_pcBinIf->finish(); |
---|
294 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
295 | |
---|
296 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
297 | m_cCUAlfCtrlFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_CTRL_FLAG ); |
---|
298 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
299 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
300 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
301 | m_cResPredFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RES_PRED_FLAG ); |
---|
302 | #endif |
---|
303 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
304 | #if AMP_CTX |
---|
305 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
306 | #else |
---|
307 | m_cCUXPosiSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_X_POS ); |
---|
308 | m_cCUYPosiSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_Y_POS ); |
---|
309 | #endif |
---|
310 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
311 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
312 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
313 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
314 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
315 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
316 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
317 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
318 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
319 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
320 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
321 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
322 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
323 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
324 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
325 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
326 | m_cALFFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_FLAG ); |
---|
327 | m_cALFUvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_UVLC ); |
---|
328 | m_cALFSvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ALF_SVLC ); |
---|
329 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
330 | m_cSaoFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_FLAG ); |
---|
331 | m_cSaoUvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_UVLC ); |
---|
332 | m_cSaoSvlcSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_SVLC ); |
---|
333 | #if SAO_UNIT_INTERLEAVING |
---|
334 | m_cSaoMergeLeftSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG ); |
---|
335 | m_cSaoMergeUpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_UP_FLAG ); |
---|
336 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
337 | #endif |
---|
338 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
339 | m_cDmmFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM_FLAG ); |
---|
340 | m_cDmmModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM_MODE ); |
---|
341 | m_cDmmDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM_DATA ); |
---|
342 | #endif |
---|
343 | |
---|
344 | m_pcBinIf->start(); |
---|
345 | } |
---|
346 | |
---|
347 | Void TEncSbac::writeTileMarker( UInt uiTileIdx, UInt uiBitsUsed ) |
---|
348 | { |
---|
349 | for (Int iShift=uiBitsUsed-1; iShift>=0; iShift--) |
---|
350 | { |
---|
351 | m_pcBinIf->encodeBinEP ( (uiTileIdx & (1 << iShift)) >> iShift ); |
---|
352 | } |
---|
353 | } |
---|
354 | |
---|
355 | void TEncSbac::codeSEI(const SEI&) |
---|
356 | { |
---|
357 | assert(0); |
---|
358 | } |
---|
359 | |
---|
360 | #if VIDYO_VPS_INTEGRATION |
---|
361 | Void TEncSbac::codeVPS( TComVPS* pcVPS ) |
---|
362 | { |
---|
363 | assert (0); |
---|
364 | return; |
---|
365 | } |
---|
366 | #endif |
---|
367 | |
---|
368 | #if HHI_MPI |
---|
369 | Void TEncSbac::codeSPS( TComSPS* pcSPS, Bool bIsDepth ) |
---|
370 | #else |
---|
371 | Void TEncSbac::codeSPS( TComSPS* pcSPS ) |
---|
372 | #endif |
---|
373 | { |
---|
374 | assert (0); |
---|
375 | return; |
---|
376 | } |
---|
377 | |
---|
378 | Void TEncSbac::codePPS( TComPPS* pcPPS ) |
---|
379 | { |
---|
380 | assert (0); |
---|
381 | return; |
---|
382 | } |
---|
383 | |
---|
384 | Void TEncSbac::codeSliceHeader( TComSlice* pcSlice ) |
---|
385 | { |
---|
386 | assert (0); |
---|
387 | return; |
---|
388 | } |
---|
389 | |
---|
390 | #if TILES_WPP_ENTRY_POINT_SIGNALLING |
---|
391 | Void TEncSbac::codeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
392 | { |
---|
393 | assert (0); |
---|
394 | return; |
---|
395 | } |
---|
396 | #else |
---|
397 | Void TEncSbac::codeSliceHeaderSubstreamTable( TComSlice* pcSlice ) |
---|
398 | { |
---|
399 | assert (0); |
---|
400 | } |
---|
401 | #endif |
---|
402 | |
---|
403 | Void TEncSbac::codeTerminatingBit( UInt uilsLast ) |
---|
404 | { |
---|
405 | m_pcBinIf->encodeBinTrm( uilsLast ); |
---|
406 | } |
---|
407 | |
---|
408 | Void TEncSbac::codeSliceFinish() |
---|
409 | { |
---|
410 | m_pcBinIf->finish(); |
---|
411 | } |
---|
412 | |
---|
413 | #if OL_FLUSH |
---|
414 | Void TEncSbac::codeFlush() |
---|
415 | { |
---|
416 | m_pcBinIf->flush(); |
---|
417 | } |
---|
418 | |
---|
419 | Void TEncSbac::encodeStart() |
---|
420 | { |
---|
421 | m_pcBinIf->start(); |
---|
422 | } |
---|
423 | #endif |
---|
424 | |
---|
425 | Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
426 | { |
---|
427 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] ); |
---|
428 | |
---|
429 | if( 0 == uiSymbol) |
---|
430 | { |
---|
431 | return; |
---|
432 | } |
---|
433 | |
---|
434 | while( uiSymbol-- ) |
---|
435 | { |
---|
436 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] ); |
---|
437 | } |
---|
438 | |
---|
439 | return; |
---|
440 | } |
---|
441 | |
---|
442 | Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
443 | { |
---|
444 | if (uiMaxSymbol == 0) |
---|
445 | { |
---|
446 | return; |
---|
447 | } |
---|
448 | |
---|
449 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] ); |
---|
450 | |
---|
451 | if ( uiSymbol == 0 ) |
---|
452 | { |
---|
453 | return; |
---|
454 | } |
---|
455 | |
---|
456 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
457 | |
---|
458 | while( --uiSymbol ) |
---|
459 | { |
---|
460 | m_pcBinIf->encodeBin( 1, pcSCModel[ iOffset ] ); |
---|
461 | } |
---|
462 | if( bCodeLast ) |
---|
463 | { |
---|
464 | m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] ); |
---|
465 | } |
---|
466 | |
---|
467 | return; |
---|
468 | } |
---|
469 | |
---|
470 | Void TEncSbac::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
471 | { |
---|
472 | UInt bins = 0; |
---|
473 | Int numBins = 0; |
---|
474 | |
---|
475 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
476 | { |
---|
477 | bins = 2 * bins + 1; |
---|
478 | numBins++; |
---|
479 | uiSymbol -= 1 << uiCount; |
---|
480 | uiCount ++; |
---|
481 | } |
---|
482 | bins = 2 * bins + 0; |
---|
483 | numBins++; |
---|
484 | |
---|
485 | bins = (bins << uiCount) | uiSymbol; |
---|
486 | numBins += uiCount; |
---|
487 | |
---|
488 | assert( numBins <= 32 ); |
---|
489 | m_pcBinIf->encodeBinsEP( bins, numBins ); |
---|
490 | } |
---|
491 | |
---|
492 | /** Coding of coeff_abs_level_minus3 |
---|
493 | * \param uiSymbol value of coeff_abs_level_minus3 |
---|
494 | * \param ruiGoRiceParam reference to Rice parameter |
---|
495 | * \returns Void |
---|
496 | */ |
---|
497 | Void TEncSbac::xWriteGoRiceExGolomb( UInt uiSymbol, UInt &ruiGoRiceParam ) |
---|
498 | { |
---|
499 | UInt uiMaxVlc = g_auiGoRiceRange[ ruiGoRiceParam ]; |
---|
500 | Bool bExGolomb = ( uiSymbol > uiMaxVlc ); |
---|
501 | UInt uiCodeWord = min<UInt>( uiSymbol, ( uiMaxVlc + 1 ) ); |
---|
502 | UInt uiQuotient = uiCodeWord >> ruiGoRiceParam; |
---|
503 | UInt uiMaxPreLen = g_auiGoRicePrefixLen[ ruiGoRiceParam ]; |
---|
504 | |
---|
505 | UInt binValues; |
---|
506 | Int numBins; |
---|
507 | |
---|
508 | if ( uiQuotient >= uiMaxPreLen ) |
---|
509 | { |
---|
510 | numBins = uiMaxPreLen; |
---|
511 | binValues = ( 1 << numBins ) - 1; |
---|
512 | } |
---|
513 | else |
---|
514 | { |
---|
515 | numBins = uiQuotient + 1; |
---|
516 | binValues = ( 1 << numBins ) - 2; |
---|
517 | } |
---|
518 | |
---|
519 | m_pcBinIf->encodeBinsEP( ( binValues << ruiGoRiceParam ) + uiCodeWord - ( uiQuotient << ruiGoRiceParam ), numBins + ruiGoRiceParam ); |
---|
520 | |
---|
521 | #if EIGHT_BITS_RICE_CODE |
---|
522 | ruiGoRiceParam = g_aauiGoRiceUpdate[ ruiGoRiceParam ][ min<UInt>( uiSymbol, 23 ) ]; |
---|
523 | #else |
---|
524 | ruiGoRiceParam = g_aauiGoRiceUpdate[ ruiGoRiceParam ][ min<UInt>( uiSymbol, 15 ) ]; |
---|
525 | #endif |
---|
526 | |
---|
527 | if( bExGolomb ) |
---|
528 | { |
---|
529 | uiSymbol -= uiMaxVlc + 1; |
---|
530 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
531 | } |
---|
532 | } |
---|
533 | |
---|
534 | // SBAC RD |
---|
535 | Void TEncSbac::load ( TEncSbac* pSrc) |
---|
536 | { |
---|
537 | this->xCopyFrom(pSrc); |
---|
538 | } |
---|
539 | |
---|
540 | Void TEncSbac::loadIntraDirModeLuma( TEncSbac* pSrc) |
---|
541 | { |
---|
542 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
543 | |
---|
544 | this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); |
---|
545 | } |
---|
546 | |
---|
547 | |
---|
548 | Void TEncSbac::store( TEncSbac* pDest) |
---|
549 | { |
---|
550 | pDest->xCopyFrom( this ); |
---|
551 | } |
---|
552 | |
---|
553 | |
---|
554 | Void TEncSbac::xCopyFrom( TEncSbac* pSrc ) |
---|
555 | { |
---|
556 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
557 | |
---|
558 | this->m_uiCoeffCost = pSrc->m_uiCoeffCost; |
---|
559 | this->m_uiLastQp = pSrc->m_uiLastQp; |
---|
560 | |
---|
561 | memcpy( m_contextModels, pSrc->m_contextModels, m_numContextModels * sizeof( ContextModel ) ); |
---|
562 | } |
---|
563 | |
---|
564 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
565 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Int iNum ) |
---|
566 | #else |
---|
567 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
568 | #endif |
---|
569 | { |
---|
570 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
571 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
572 | #else |
---|
573 | Int iNum = AMVP_MAX_NUM_CANDS; |
---|
574 | #endif |
---|
575 | |
---|
576 | xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1); |
---|
577 | } |
---|
578 | |
---|
579 | Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
580 | { |
---|
581 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
582 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
583 | { |
---|
584 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
585 | { |
---|
586 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
587 | } |
---|
588 | return; |
---|
589 | } |
---|
590 | |
---|
591 | switch(eSize) |
---|
592 | { |
---|
593 | case SIZE_2Nx2N: |
---|
594 | { |
---|
595 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
596 | break; |
---|
597 | } |
---|
598 | case SIZE_2NxN: |
---|
599 | case SIZE_2NxnU: |
---|
600 | case SIZE_2NxnD: |
---|
601 | { |
---|
602 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
603 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
604 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
605 | { |
---|
606 | if (eSize == SIZE_2NxN) |
---|
607 | { |
---|
608 | #if AMP_CTX |
---|
609 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
610 | #else |
---|
611 | m_pcBinIf->encodeBin(1, m_cCUYPosiSCModel.get( 0, 0, 0 )); |
---|
612 | #endif |
---|
613 | } |
---|
614 | else |
---|
615 | { |
---|
616 | #if AMP_CTX |
---|
617 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
618 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
619 | #else |
---|
620 | m_pcBinIf->encodeBin(0, m_cCUYPosiSCModel.get( 0, 0, 0 )); |
---|
621 | m_pcBinIf->encodeBin((eSize == SIZE_2NxnU? 0: 1), m_cCUYPosiSCModel.get( 0, 0, 1 )); |
---|
622 | #endif |
---|
623 | } |
---|
624 | } |
---|
625 | break; |
---|
626 | } |
---|
627 | case SIZE_Nx2N: |
---|
628 | case SIZE_nLx2N: |
---|
629 | case SIZE_nRx2N: |
---|
630 | { |
---|
631 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
632 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
633 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getSlice()->getSPS()->getDisInter4x4() && pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
634 | { |
---|
635 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
636 | } |
---|
637 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
638 | { |
---|
639 | if (eSize == SIZE_Nx2N) |
---|
640 | { |
---|
641 | #if AMP_CTX |
---|
642 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
643 | #else |
---|
644 | m_pcBinIf->encodeBin(1, m_cCUXPosiSCModel.get( 0, 0, 0 )); |
---|
645 | #endif |
---|
646 | } |
---|
647 | else |
---|
648 | { |
---|
649 | #if AMP_CTX |
---|
650 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
651 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
652 | #else |
---|
653 | m_pcBinIf->encodeBin(0, m_cCUXPosiSCModel.get( 0, 0, 0 )); |
---|
654 | m_pcBinIf->encodeBin((eSize == SIZE_nLx2N? 0: 1), m_cCUXPosiSCModel.get( 0, 0, 1 )); |
---|
655 | #endif |
---|
656 | } |
---|
657 | } |
---|
658 | break; |
---|
659 | } |
---|
660 | case SIZE_NxN: |
---|
661 | { |
---|
662 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getSlice()->getSPS()->getDisInter4x4() && pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
663 | { |
---|
664 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
665 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
666 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
667 | } |
---|
668 | break; |
---|
669 | } |
---|
670 | default: |
---|
671 | { |
---|
672 | assert(0); |
---|
673 | } |
---|
674 | } |
---|
675 | } |
---|
676 | |
---|
677 | /** code prediction mode |
---|
678 | * \param pcCU |
---|
679 | * \param uiAbsPartIdx |
---|
680 | * \returns Void |
---|
681 | */ |
---|
682 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
683 | { |
---|
684 | // get context function is here |
---|
685 | Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); |
---|
686 | m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
687 | } |
---|
688 | |
---|
689 | Void TEncSbac::codeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
690 | { |
---|
691 | if (!m_bAlfCtrl) |
---|
692 | return; |
---|
693 | |
---|
694 | if( pcCU->getDepth(uiAbsPartIdx) > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth)) |
---|
695 | { |
---|
696 | return; |
---|
697 | } |
---|
698 | |
---|
699 | const UInt uiSymbol = pcCU->getAlfCtrlFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
700 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUAlfCtrlFlagSCModel.get( 0 ) ); |
---|
701 | } |
---|
702 | |
---|
703 | Void TEncSbac::codeAlfCtrlDepth() |
---|
704 | { |
---|
705 | if (!m_bAlfCtrl) |
---|
706 | return; |
---|
707 | |
---|
708 | UInt uiDepth = m_uiMaxAlfCtrlDepth; |
---|
709 | xWriteUnaryMaxSymbol(uiDepth, m_cALFUvlcSCModel.get(0), 1, g_uiMaxCUDepth-1); |
---|
710 | } |
---|
711 | |
---|
712 | /** code skip flag |
---|
713 | * \param pcCU |
---|
714 | * \param uiAbsPartIdx |
---|
715 | * \returns Void |
---|
716 | */ |
---|
717 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
718 | { |
---|
719 | // get context function is here |
---|
720 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
721 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
722 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
723 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
724 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
725 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
726 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
727 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
728 | DTRACE_CABAC_V( uiSymbol ); |
---|
729 | DTRACE_CABAC_T( "\n"); |
---|
730 | } |
---|
731 | |
---|
732 | /** code merge flag |
---|
733 | * \param pcCU |
---|
734 | * \param uiAbsPartIdx |
---|
735 | * \returns Void |
---|
736 | */ |
---|
737 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
738 | { |
---|
739 | const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
740 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
741 | |
---|
742 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
743 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
744 | DTRACE_CABAC_V( uiSymbol ); |
---|
745 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
746 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
747 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
748 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
749 | DTRACE_CABAC_T( "\n" ); |
---|
750 | } |
---|
751 | |
---|
752 | /** code merge index |
---|
753 | * \param pcCU |
---|
754 | * \param uiAbsPartIdx |
---|
755 | * \returns Void |
---|
756 | */ |
---|
757 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
758 | { |
---|
759 | UInt uiNumCand = MRG_MAX_NUM_CANDS; |
---|
760 | #if !MRG_IDX_CTX_RED |
---|
761 | UInt auiCtx[4] = { 0, 1, 2, 3 }; |
---|
762 | #endif |
---|
763 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
764 | uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
765 | #if HHI_MPI |
---|
766 | const Bool bMVIAvailable = pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE; |
---|
767 | if( bMVIAvailable ) |
---|
768 | { |
---|
769 | const Bool bUseMVI = pcCU->getTextureModeDepth( uiAbsPartIdx ) != -1; |
---|
770 | if( bUseMVI ) |
---|
771 | { |
---|
772 | uiUnaryIdx = (UInt)HHI_MPI_MERGE_POS; |
---|
773 | } |
---|
774 | else if( (Int)uiUnaryIdx >= (Int)HHI_MPI_MERGE_POS ) |
---|
775 | { |
---|
776 | uiUnaryIdx++; |
---|
777 | } |
---|
778 | } |
---|
779 | #endif |
---|
780 | if ( uiNumCand > 1 ) |
---|
781 | { |
---|
782 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
783 | { |
---|
784 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
785 | #if MRG_IDX_CTX_RED |
---|
786 | if ( ui==0 ) |
---|
787 | { |
---|
788 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
789 | } |
---|
790 | else |
---|
791 | { |
---|
792 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
793 | } |
---|
794 | #else |
---|
795 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, auiCtx[ui] ) ); |
---|
796 | #endif |
---|
797 | if( uiSymbol == 0 ) |
---|
798 | { |
---|
799 | break; |
---|
800 | } |
---|
801 | } |
---|
802 | } |
---|
803 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
804 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
805 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
806 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
807 | DTRACE_CABAC_T( "\n" ); |
---|
808 | } |
---|
809 | |
---|
810 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
811 | Void |
---|
812 | TEncSbac::codeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
813 | { |
---|
814 | UInt uiCtx = pcCU->getCtxResPredFlag( uiAbsPartIdx ); |
---|
815 | UInt uiSymbol = ( pcCU->getResPredFlag( uiAbsPartIdx ) ? 1 : 0 ); |
---|
816 | m_pcBinIf->encodeBin( uiSymbol, m_cResPredFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
817 | } |
---|
818 | #endif |
---|
819 | |
---|
820 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
821 | { |
---|
822 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
823 | return; |
---|
824 | |
---|
825 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
826 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
827 | |
---|
828 | assert( uiCtx < 3 ); |
---|
829 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
830 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
831 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
832 | return; |
---|
833 | } |
---|
834 | |
---|
835 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
836 | { |
---|
837 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
838 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
839 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
840 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
841 | DTRACE_CABAC_V( uiSymbol ) |
---|
842 | DTRACE_CABAC_T( "\tctx=" ) |
---|
843 | DTRACE_CABAC_V( uiCtx ) |
---|
844 | DTRACE_CABAC_T( "\n" ) |
---|
845 | } |
---|
846 | |
---|
847 | #if LGE_EDGE_INTRA |
---|
848 | Void TEncSbac::xCodeEdgeIntraInfo( TComDataCU* pcCU, UInt uiPartIdx ) |
---|
849 | { |
---|
850 | UInt uiDepth = pcCU->getDepth( uiPartIdx ) + (pcCU->getPartitionSize( uiPartIdx ) == SIZE_NxN ? 1 : 0); |
---|
851 | UInt uiCtxEdgeIntra = pcCU->getCtxEdgeIntra( uiPartIdx ); |
---|
852 | UChar* pucSymbolList = pcCU->getEdgeCode( uiPartIdx ); |
---|
853 | UChar ucEdgeNumber = pcCU->getEdgeNumber( uiPartIdx ); |
---|
854 | Bool bLeft = pcCU->getEdgeLeftFirst( uiPartIdx ); |
---|
855 | UChar ucStart = pcCU->getEdgeStartPos( uiPartIdx ); |
---|
856 | UInt uiSymbol; |
---|
857 | |
---|
858 | // 1. Top(0) or Left(1) |
---|
859 | uiSymbol = (bLeft == false) ? 0 : 1; |
---|
860 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
861 | |
---|
862 | // 2. Start position (lowest bit first) |
---|
863 | uiSymbol = ucStart; |
---|
864 | for( UInt ui = 6; ui > uiDepth; ui-- ) // 64(0)->6, 32(1)->5, 16(2)->4, 8(3)->3, 4(4)->2 |
---|
865 | { |
---|
866 | m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); |
---|
867 | uiSymbol >>= 1; |
---|
868 | } |
---|
869 | |
---|
870 | // 3. Number of edges |
---|
871 | uiSymbol = ucEdgeNumber > 0 ? ucEdgeNumber - 1 : 0; |
---|
872 | for( UInt ui = 7; ui > uiDepth; ui-- ) // 64(0)->7, 32(1)->6, 16(2)->5, 8(3)->4, 4(4)->3 |
---|
873 | { |
---|
874 | m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); |
---|
875 | uiSymbol >>= 1; |
---|
876 | } |
---|
877 | |
---|
878 | if(uiSymbol != 0) |
---|
879 | { |
---|
880 | printf(" ucEdgeNumber %d at depth %d\n",ucEdgeNumber, uiDepth); |
---|
881 | assert(false); |
---|
882 | } |
---|
883 | |
---|
884 | // 4. Edges |
---|
885 | for( Int iPtr2 = 0; iPtr2 < ucEdgeNumber; iPtr2++ ) |
---|
886 | { |
---|
887 | UInt uiReorderSymbol = pucSymbolList[iPtr2]; |
---|
888 | |
---|
889 | //printf ("Ptr = %d, Symbol = %d\n", iPtr2, uiSymbol); |
---|
890 | |
---|
891 | // Left-friendly direction (Top start) |
---|
892 | // 0 ( 0deg) => 0 |
---|
893 | // 1 ( 45deg) => 10 |
---|
894 | // 2 ( -45deg) => 110 |
---|
895 | // 3 ( 90deg) => 1110 |
---|
896 | // 4 ( -90deg) => 11110 |
---|
897 | // 5 ( 135deg) => 111110 |
---|
898 | // 6 (-135deg) => 111111 |
---|
899 | // Right-friendly direction (Left start) |
---|
900 | // 0 ( 0deg) => 0 |
---|
901 | // 2 ( -45deg) => 10 |
---|
902 | // 1 ( 45deg) => 110 |
---|
903 | // 4 ( -90deg) => 1110 |
---|
904 | // 3 ( 90deg) => 11110 |
---|
905 | // 6 (-135deg) => 111110 |
---|
906 | // 5 ( 135deg) => 111111 |
---|
907 | |
---|
908 | // refer to a paper "An efficient chain code with Huffman coding" |
---|
909 | |
---|
910 | for( UInt ui = 0; ui < uiReorderSymbol; ui++ ) |
---|
911 | { |
---|
912 | m_pcBinIf->encodeBin( 1, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) ); |
---|
913 | } |
---|
914 | |
---|
915 | if( uiReorderSymbol != 6 ) |
---|
916 | m_pcBinIf->encodeBin( 0, m_cEdgeIntraSCModel.get( 0, 0, uiCtxEdgeIntra ) ); |
---|
917 | } |
---|
918 | } |
---|
919 | #endif |
---|
920 | |
---|
921 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
922 | { |
---|
923 | UInt uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx ); |
---|
924 | |
---|
925 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
926 | if( pcCU->getSlice()->getSPS()->getUseDMM() && pcCU->getWidth( uiAbsPartIdx ) <= DMM_WEDGEMODEL_MAX_SIZE ) |
---|
927 | { |
---|
928 | #if LGE_EDGE_INTRA |
---|
929 | m_pcBinIf->encodeBin( uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX, m_cDmmFlagSCModel.get(0, 0, 0) ); |
---|
930 | #else |
---|
931 | m_pcBinIf->encodeBin( uiDir >= NUM_INTRA_MODE, m_cDmmFlagSCModel.get(0, 0, 0) ); |
---|
932 | #endif |
---|
933 | } |
---|
934 | #if LGE_EDGE_INTRA |
---|
935 | if( uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX ) |
---|
936 | #else |
---|
937 | if( uiDir >= NUM_INTRA_MODE ) |
---|
938 | #endif |
---|
939 | { |
---|
940 | assert( pcCU->getWidth( uiAbsPartIdx ) <= DMM_WEDGEMODEL_MAX_SIZE ); |
---|
941 | UInt uiDMMode = uiDir - NUM_INTRA_MODE; |
---|
942 | |
---|
943 | #if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX |
---|
944 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
945 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
946 | |
---|
947 | if( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
948 | { |
---|
949 | m_pcBinIf->encodeBin( (uiDMMode & 0x04) >> 2, m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
950 | } |
---|
951 | #else |
---|
952 | m_pcBinIf->encodeBin( (uiDMMode & 0x01), m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
953 | |
---|
954 | if( pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_NxN && pcCU->getWidth( uiAbsPartIdx ) > 4 ) |
---|
955 | { |
---|
956 | m_pcBinIf->encodeBin( (uiDMMode & 0x02) >> 1, m_cDmmModeSCModel.get(0, 0, 0) ); |
---|
957 | } |
---|
958 | #endif |
---|
959 | #if HHI_DMM_WEDGE_INTRA |
---|
960 | if( uiDir == DMM_WEDGE_FULL_IDX ) { xCodeWedgeFullInfo ( pcCU, uiAbsPartIdx ); } |
---|
961 | if( uiDir == DMM_WEDGE_FULL_D_IDX ) { xCodeWedgeFullDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
962 | if( uiDir == DMM_WEDGE_PREDDIR_IDX ) { xCodeWedgePredDirInfo ( pcCU, uiAbsPartIdx ); } |
---|
963 | if( uiDir == DMM_WEDGE_PREDDIR_D_IDX ) { xCodeWedgePredDirDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
964 | #endif |
---|
965 | #if HHI_DMM_PRED_TEX |
---|
966 | if( uiDir == DMM_WEDGE_PREDTEX_D_IDX ) { xCodeWedgePredTexDeltaInfo ( pcCU, uiAbsPartIdx ); } |
---|
967 | if( uiDir == DMM_CONTOUR_PREDTEX_D_IDX ) { xCodeContourPredTexDeltaInfo( pcCU, uiAbsPartIdx ); } |
---|
968 | #endif |
---|
969 | } |
---|
970 | else |
---|
971 | #if LGE_EDGE_INTRA |
---|
972 | if ( uiDir >= EDGE_INTRA_IDX) |
---|
973 | { |
---|
974 | m_pcBinIf->encodeBin( 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
975 | m_pcBinIf->encodeBinsEP( 63, 6 ); |
---|
976 | xCodeEdgeIntraInfo( pcCU, uiAbsPartIdx ); |
---|
977 | #if LGE_EDGE_INTRA_DELTA_DC |
---|
978 | m_pcBinIf->encodeBin( (uiDir == EDGE_INTRA_DELTA_IDX), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) ); |
---|
979 | if( uiDir == EDGE_INTRA_DELTA_IDX ) |
---|
980 | { |
---|
981 | Int iDeltaDC0 = pcCU->getEdgeDeltaDC0( uiAbsPartIdx ); |
---|
982 | Int iDeltaDC1 = pcCU->getEdgeDeltaDC1( uiAbsPartIdx ); |
---|
983 | |
---|
984 | xWriteExGolombLevel( UInt( abs( iDeltaDC0 ) ), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) ); |
---|
985 | if ( iDeltaDC0 != 0 ) |
---|
986 | { |
---|
987 | UInt uiSign = iDeltaDC0 > 0 ? 0 : 1; |
---|
988 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
989 | } |
---|
990 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) ); |
---|
991 | if ( iDeltaDC1 != 0 ) |
---|
992 | { |
---|
993 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
994 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
995 | } |
---|
996 | } |
---|
997 | #endif |
---|
998 | } |
---|
999 | else |
---|
1000 | #endif // LGE_EDGE_INTRA |
---|
1001 | { |
---|
1002 | #endif |
---|
1003 | #if !LOGI_INTRA_NAME_3MPM |
---|
1004 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
1005 | #endif |
---|
1006 | #if LGE_EDGE_INTRA |
---|
1007 | Bool bCodeEdgeIntra = false; |
---|
1008 | if( pcCU->getSlice()->getSPS()->isDepth() ) |
---|
1009 | { |
---|
1010 | UInt uiPUWidth = pcCU->getWidth( uiAbsPartIdx ) >> (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 1 : 0); |
---|
1011 | if( uiPUWidth <= LGE_EDGE_INTRA_MAX_SIZE && uiPUWidth >= LGE_EDGE_INTRA_MIN_SIZE ) |
---|
1012 | bCodeEdgeIntra = true; |
---|
1013 | } |
---|
1014 | #endif |
---|
1015 | |
---|
1016 | #if LOGI_INTRA_NAME_3MPM |
---|
1017 | Int uiPreds[3] = {-1, -1, -1}; |
---|
1018 | #else |
---|
1019 | Int uiPreds[2] = {-1, -1}; |
---|
1020 | #endif |
---|
1021 | Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); |
---|
1022 | |
---|
1023 | Int uiPredIdx = -1; |
---|
1024 | |
---|
1025 | for(UInt i = 0; i < uiPredNum; i++) |
---|
1026 | { |
---|
1027 | if(uiDir == uiPreds[i]) |
---|
1028 | { |
---|
1029 | uiPredIdx = i; |
---|
1030 | } |
---|
1031 | } |
---|
1032 | |
---|
1033 | if(uiPredIdx != -1) |
---|
1034 | { |
---|
1035 | m_pcBinIf->encodeBin( 1, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
1036 | #if LOGI_INTRA_NAME_3MPM |
---|
1037 | m_pcBinIf->encodeBinEP( uiPredIdx ? 1 : 0 ); |
---|
1038 | if (uiPredIdx) |
---|
1039 | { |
---|
1040 | m_pcBinIf->encodeBinEP( uiPredIdx-1 ); |
---|
1041 | } |
---|
1042 | #else |
---|
1043 | m_pcBinIf->encodeBinEP( uiPredIdx ); |
---|
1044 | #endif |
---|
1045 | } |
---|
1046 | else |
---|
1047 | { |
---|
1048 | m_pcBinIf->encodeBin( 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
1049 | |
---|
1050 | #if LOGI_INTRA_NAME_3MPM |
---|
1051 | if (uiPreds[0] > uiPreds[1]) |
---|
1052 | { |
---|
1053 | std::swap(uiPreds[0], uiPreds[1]); |
---|
1054 | } |
---|
1055 | if (uiPreds[0] > uiPreds[2]) |
---|
1056 | { |
---|
1057 | std::swap(uiPreds[0], uiPreds[2]); |
---|
1058 | } |
---|
1059 | if (uiPreds[1] > uiPreds[2]) |
---|
1060 | { |
---|
1061 | std::swap(uiPreds[1], uiPreds[2]); |
---|
1062 | } |
---|
1063 | #endif |
---|
1064 | |
---|
1065 | for(Int i = (uiPredNum - 1); i >= 0; i--) |
---|
1066 | { |
---|
1067 | uiDir = uiDir > uiPreds[i] ? uiDir - 1 : uiDir; |
---|
1068 | } |
---|
1069 | |
---|
1070 | #if LOGI_INTRA_NAME_3MPM |
---|
1071 | m_pcBinIf->encodeBinsEP( uiDir, 5 ); |
---|
1072 | #if LGE_EDGE_INTRA |
---|
1073 | if (bCodeEdgeIntra) |
---|
1074 | if (uiDir == 31) m_pcBinIf->encodeBinsEP(0,1); |
---|
1075 | #endif |
---|
1076 | #else |
---|
1077 | if ( uiDir < 31 ) |
---|
1078 | { |
---|
1079 | m_pcBinIf->encodeBinsEP( uiDir, g_aucIntraModeBitsAng[ iIntraIdx ] - 1 ); |
---|
1080 | } |
---|
1081 | else |
---|
1082 | { |
---|
1083 | m_pcBinIf->encodeBinsEP( 31, 5 ); |
---|
1084 | m_pcBinIf->encodeBinEP( uiDir - 31 ); |
---|
1085 | } |
---|
1086 | #endif |
---|
1087 | } |
---|
1088 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
1089 | } |
---|
1090 | #endif |
---|
1091 | return; |
---|
1092 | } |
---|
1093 | |
---|
1094 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1095 | { |
---|
1096 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx ); |
---|
1097 | |
---|
1098 | if( uiIntraDirChroma == DM_CHROMA_IDX ) |
---|
1099 | { |
---|
1100 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
1101 | } |
---|
1102 | else if( uiIntraDirChroma == LM_CHROMA_IDX ) |
---|
1103 | { |
---|
1104 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
1105 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 1 ) ); |
---|
1106 | } |
---|
1107 | else |
---|
1108 | { |
---|
1109 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
1110 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
1111 | |
---|
1112 | for( Int i = 0; i < NUM_CHROMA_MODE - 2; i++ ) |
---|
1113 | { |
---|
1114 | if( uiIntraDirChroma == uiAllowedChromaDir[i] ) |
---|
1115 | { |
---|
1116 | uiIntraDirChroma = i; |
---|
1117 | break; |
---|
1118 | } |
---|
1119 | } |
---|
1120 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
1121 | |
---|
1122 | if (pcCU->getSlice()->getSPS()->getUseLMChroma()) |
---|
1123 | { |
---|
1124 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 1 )); |
---|
1125 | } |
---|
1126 | #if CHROMA_MODE_CODING |
---|
1127 | m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); |
---|
1128 | #else |
---|
1129 | xWriteUnaryMaxSymbol( uiIntraDirChroma, m_cCUChromaPredSCModel.get( 0, 0 ) + 1, 0, 3 ); |
---|
1130 | #endif |
---|
1131 | } |
---|
1132 | return; |
---|
1133 | } |
---|
1134 | |
---|
1135 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1136 | { |
---|
1137 | const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1; |
---|
1138 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
1139 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
1140 | m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); |
---|
1141 | |
---|
1142 | return; |
---|
1143 | } |
---|
1144 | |
---|
1145 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1146 | { |
---|
1147 | if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getInterDir( uiAbsPartIdx ) != 3) |
---|
1148 | { |
---|
1149 | Int iRefFrame = pcCU->getSlice()->getRefIdxOfLC(eRefList, pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx )); |
---|
1150 | |
---|
1151 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
1152 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
1153 | |
---|
1154 | if( iRefFrame > 0 ) |
---|
1155 | { |
---|
1156 | xWriteUnaryMaxSymbol( iRefFrame - 1, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C )-2 ); |
---|
1157 | } |
---|
1158 | } |
---|
1159 | else |
---|
1160 | { |
---|
1161 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1162 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
1163 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
1164 | |
---|
1165 | if( iRefFrame > 0 ) |
---|
1166 | { |
---|
1167 | xWriteUnaryMaxSymbol( iRefFrame - 1, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 ); |
---|
1168 | } |
---|
1169 | } |
---|
1170 | return; |
---|
1171 | } |
---|
1172 | |
---|
1173 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1174 | { |
---|
1175 | #if H0111_MVD_L1_ZERO |
---|
1176 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
1177 | { |
---|
1178 | return; |
---|
1179 | } |
---|
1180 | #endif |
---|
1181 | |
---|
1182 | const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
1183 | const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
1184 | const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
1185 | ContextModel* pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
1186 | |
---|
1187 | m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx ); |
---|
1188 | m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx ); |
---|
1189 | |
---|
1190 | const Bool bHorAbsGr0 = iHor != 0; |
---|
1191 | const Bool bVerAbsGr0 = iVer != 0; |
---|
1192 | const UInt uiHorAbs = 0 > iHor ? -iHor : iHor; |
---|
1193 | const UInt uiVerAbs = 0 > iVer ? -iVer : iVer; |
---|
1194 | pCtx++; |
---|
1195 | |
---|
1196 | if( bHorAbsGr0 ) |
---|
1197 | { |
---|
1198 | m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx ); |
---|
1199 | } |
---|
1200 | |
---|
1201 | if( bVerAbsGr0 ) |
---|
1202 | { |
---|
1203 | m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx ); |
---|
1204 | } |
---|
1205 | |
---|
1206 | if( bHorAbsGr0 ) |
---|
1207 | { |
---|
1208 | if( uiHorAbs > 1 ) |
---|
1209 | { |
---|
1210 | xWriteEpExGolomb( uiHorAbs-2, 1 ); |
---|
1211 | } |
---|
1212 | |
---|
1213 | m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 ); |
---|
1214 | } |
---|
1215 | |
---|
1216 | if( bVerAbsGr0 ) |
---|
1217 | { |
---|
1218 | if( uiVerAbs > 1 ) |
---|
1219 | { |
---|
1220 | xWriteEpExGolomb( uiVerAbs-2, 1 ); |
---|
1221 | } |
---|
1222 | |
---|
1223 | m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); |
---|
1224 | } |
---|
1225 | |
---|
1226 | return; |
---|
1227 | } |
---|
1228 | |
---|
1229 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1230 | { |
---|
1231 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
1232 | |
---|
1233 | #if H0736_AVC_STYLE_QP_RANGE |
---|
1234 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
1235 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
1236 | #else |
---|
1237 | #if LOSSLESS_CODING |
---|
1238 | if(pcCU->getSlice()->getSPS()->getUseLossless()) |
---|
1239 | { |
---|
1240 | if(iDQp > 25) |
---|
1241 | { |
---|
1242 | iDQp = iDQp - 52; |
---|
1243 | } |
---|
1244 | if(iDQp < -26) |
---|
1245 | { |
---|
1246 | iDQp = iDQp + 52; |
---|
1247 | } |
---|
1248 | } |
---|
1249 | #endif |
---|
1250 | #endif |
---|
1251 | |
---|
1252 | if ( iDQp == 0 ) |
---|
1253 | { |
---|
1254 | m_pcBinIf->encodeBin( 0, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) ); |
---|
1255 | } |
---|
1256 | else |
---|
1257 | { |
---|
1258 | m_pcBinIf->encodeBin( 1, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) ); |
---|
1259 | |
---|
1260 | UInt uiSign = (iDQp > 0 ? 0 : 1); |
---|
1261 | #if !H0736_AVC_STYLE_QP_RANGE |
---|
1262 | UInt uiQpBdOffsetY = 6*(g_uiBitIncrement + g_uiBitDepth - 8); |
---|
1263 | #endif |
---|
1264 | |
---|
1265 | m_pcBinIf->encodeBinEP(uiSign); |
---|
1266 | |
---|
1267 | #if H0736_AVC_STYLE_QP_RANGE |
---|
1268 | assert(iDQp >= -(26+(qpBdOffsetY/2))); |
---|
1269 | assert(iDQp <= (25+(qpBdOffsetY/2))); |
---|
1270 | |
---|
1271 | UInt uiMaxAbsDQpMinus1 = 24 + (qpBdOffsetY/2) + (uiSign); |
---|
1272 | #else |
---|
1273 | assert(iDQp >= -(26+(Int)(uiQpBdOffsetY/2))); |
---|
1274 | assert(iDQp <= (25+(Int)(uiQpBdOffsetY/2))); |
---|
1275 | |
---|
1276 | UInt uiMaxAbsDQpMinus1 = 24 + (uiQpBdOffsetY/2) + (uiSign); |
---|
1277 | #endif |
---|
1278 | UInt uiAbsDQpMinus1 = (UInt)((iDQp > 0)? iDQp : (-iDQp)) - 1; |
---|
1279 | xWriteUnaryMaxSymbol( uiAbsDQpMinus1, &m_cCUDeltaQpSCModel.get( 0, 0, 1 ), 1, uiMaxAbsDQpMinus1); |
---|
1280 | } |
---|
1281 | |
---|
1282 | return; |
---|
1283 | } |
---|
1284 | |
---|
1285 | Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
1286 | { |
---|
1287 | UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
1288 | UInt uiCtx = pcCU->getCtxQtCbf( uiAbsPartIdx, eType, uiTrDepth ); |
---|
1289 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
1290 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1291 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
1292 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1293 | DTRACE_CABAC_V( uiCbf ) |
---|
1294 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1295 | DTRACE_CABAC_V( uiCtx ) |
---|
1296 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1297 | DTRACE_CABAC_V( eType ) |
---|
1298 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1299 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1300 | DTRACE_CABAC_T( "\n" ) |
---|
1301 | } |
---|
1302 | |
---|
1303 | #if BURST_IPCM |
---|
1304 | /** Code I_PCM information. |
---|
1305 | * \param pcCU pointer to CU |
---|
1306 | * \param uiAbsPartIdx CU index |
---|
1307 | * \param numIPCM the number of succesive IPCM blocks with the same size |
---|
1308 | * \param firstIPCMFlag |
---|
1309 | * \returns Void |
---|
1310 | */ |
---|
1311 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Int numIPCM, Bool firstIPCMFlag) |
---|
1312 | #else |
---|
1313 | /** Code I_PCM information. |
---|
1314 | * \param pcCU pointer to CU |
---|
1315 | * \param uiAbsPartIdx CU index |
---|
1316 | * \returns Void |
---|
1317 | * |
---|
1318 | * If I_PCM flag indicates that the CU is I_PCM, code its PCM alignment bits and codes. |
---|
1319 | */ |
---|
1320 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx) |
---|
1321 | #endif |
---|
1322 | { |
---|
1323 | UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0; |
---|
1324 | |
---|
1325 | #if BURST_IPCM |
---|
1326 | Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx); |
---|
1327 | |
---|
1328 | if( uiIPCM == 0 || firstIPCMFlag) |
---|
1329 | { |
---|
1330 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
1331 | |
---|
1332 | if ( firstIPCMFlag ) |
---|
1333 | { |
---|
1334 | m_pcBinIf->encodeNumSubseqIPCM( numIPCM - 1 ); |
---|
1335 | m_pcBinIf->encodePCMAlignBits(); |
---|
1336 | } |
---|
1337 | } |
---|
1338 | #else |
---|
1339 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
1340 | #endif |
---|
1341 | |
---|
1342 | #if BURST_IPCM |
---|
1343 | if (writePCMSampleFlag) |
---|
1344 | #else |
---|
1345 | if (uiIPCM) |
---|
1346 | #endif |
---|
1347 | { |
---|
1348 | #if !BURST_IPCM |
---|
1349 | m_pcBinIf->encodePCMAlignBits(); |
---|
1350 | #endif |
---|
1351 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
1352 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
1353 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
1354 | Pel* piPCMSample; |
---|
1355 | UInt uiWidth; |
---|
1356 | UInt uiHeight; |
---|
1357 | UInt uiSampleBits; |
---|
1358 | UInt uiX, uiY; |
---|
1359 | |
---|
1360 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
1361 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
1362 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
1363 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
1364 | |
---|
1365 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
1366 | { |
---|
1367 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
1368 | { |
---|
1369 | UInt uiSample = piPCMSample[uiX]; |
---|
1370 | |
---|
1371 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
1372 | } |
---|
1373 | piPCMSample += uiWidth; |
---|
1374 | } |
---|
1375 | |
---|
1376 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
1377 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
1378 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
1379 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
1380 | |
---|
1381 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
1382 | { |
---|
1383 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
1384 | { |
---|
1385 | UInt uiSample = piPCMSample[uiX]; |
---|
1386 | |
---|
1387 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
1388 | } |
---|
1389 | piPCMSample += uiWidth; |
---|
1390 | } |
---|
1391 | |
---|
1392 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
1393 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
1394 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
1395 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
1396 | |
---|
1397 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
1398 | { |
---|
1399 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
1400 | { |
---|
1401 | UInt uiSample = piPCMSample[uiX]; |
---|
1402 | |
---|
1403 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
1404 | } |
---|
1405 | piPCMSample += uiWidth; |
---|
1406 | } |
---|
1407 | #if BURST_IPCM |
---|
1408 | numIPCM--; |
---|
1409 | if(numIPCM == 0) |
---|
1410 | { |
---|
1411 | m_pcBinIf->resetBac(); |
---|
1412 | } |
---|
1413 | #else |
---|
1414 | m_pcBinIf->resetBac(); |
---|
1415 | #endif |
---|
1416 | } |
---|
1417 | } |
---|
1418 | |
---|
1419 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1420 | { |
---|
1421 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
1422 | UInt uiCtx = 0; |
---|
1423 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
1424 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1425 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
1426 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1427 | DTRACE_CABAC_V( uiCbf ) |
---|
1428 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1429 | DTRACE_CABAC_V( uiCtx ) |
---|
1430 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1431 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1432 | DTRACE_CABAC_T( "\n" ) |
---|
1433 | } |
---|
1434 | |
---|
1435 | /** Encode (X,Y) position of the last significant coefficient |
---|
1436 | * \param uiPosX X component of last coefficient |
---|
1437 | * \param uiPosY Y component of last coefficient |
---|
1438 | * \param width Block width |
---|
1439 | * \param height Block height |
---|
1440 | * \param eTType plane type / luminance or chrominance |
---|
1441 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
1442 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
1443 | */ |
---|
1444 | Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
1445 | { |
---|
1446 | // swap |
---|
1447 | if( uiScanIdx == SCAN_VER ) |
---|
1448 | { |
---|
1449 | swap( uiPosX, uiPosY ); |
---|
1450 | } |
---|
1451 | |
---|
1452 | UInt uiCtxLast; |
---|
1453 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
1454 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
1455 | UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; |
---|
1456 | UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; |
---|
1457 | |
---|
1458 | // posX |
---|
1459 | #if LAST_CTX_REDUCTION |
---|
1460 | Int widthCtx = eTType? 4: width; |
---|
1461 | const UInt *puiCtxIdxX = g_uiLastCtx + ( g_aucConvertToBit[ widthCtx ] * ( g_aucConvertToBit[ widthCtx ] + 3 ) ); |
---|
1462 | #else |
---|
1463 | const UInt *puiCtxIdxX = g_uiLastCtx + ( g_aucConvertToBit[ width ] * ( g_aucConvertToBit[ width ] + 3 ) ); |
---|
1464 | #endif |
---|
1465 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) |
---|
1466 | { |
---|
1467 | #if LAST_CTX_REDUCTION |
---|
1468 | if (eTType) |
---|
1469 | { |
---|
1470 | m_pcBinIf->encodeBin( 1, *( pCtxX + (uiCtxLast>>g_aucConvertToBit[ width ]) ) ); |
---|
1471 | } |
---|
1472 | else |
---|
1473 | { |
---|
1474 | #endif |
---|
1475 | m_pcBinIf->encodeBin( 1, *( pCtxX + puiCtxIdxX[ uiCtxLast ] ) ); |
---|
1476 | #if LAST_CTX_REDUCTION |
---|
1477 | } |
---|
1478 | #endif |
---|
1479 | } |
---|
1480 | if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) |
---|
1481 | { |
---|
1482 | #if LAST_CTX_REDUCTION |
---|
1483 | if ( eTType ) |
---|
1484 | { |
---|
1485 | m_pcBinIf->encodeBin( 0, *( pCtxX + (uiCtxLast>>g_aucConvertToBit[ width ]) ) ); |
---|
1486 | } |
---|
1487 | else |
---|
1488 | { |
---|
1489 | #endif |
---|
1490 | m_pcBinIf->encodeBin( 0, *( pCtxX + puiCtxIdxX[ uiCtxLast ] ) ); |
---|
1491 | #if LAST_CTX_REDUCTION |
---|
1492 | } |
---|
1493 | #endif |
---|
1494 | } |
---|
1495 | |
---|
1496 | // posY |
---|
1497 | #if LAST_CTX_REDUCTION |
---|
1498 | Int heightCtx = eTType? 4: height; |
---|
1499 | const UInt *puiCtxIdxY = g_uiLastCtx + ( g_aucConvertToBit[ heightCtx ] * ( g_aucConvertToBit[ heightCtx ] + 3 ) ); |
---|
1500 | #else |
---|
1501 | const UInt *puiCtxIdxY = g_uiLastCtx + ( g_aucConvertToBit[ height ] * ( g_aucConvertToBit[ height ] + 3 ) ); |
---|
1502 | #endif |
---|
1503 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) |
---|
1504 | { |
---|
1505 | #if LAST_CTX_REDUCTION |
---|
1506 | if (eTType) |
---|
1507 | { |
---|
1508 | m_pcBinIf->encodeBin( 1, *( pCtxY + (uiCtxLast>>g_aucConvertToBit[ height ]))); |
---|
1509 | } |
---|
1510 | else |
---|
1511 | { |
---|
1512 | #endif |
---|
1513 | m_pcBinIf->encodeBin( 1, *( pCtxY + puiCtxIdxY[ uiCtxLast ] ) ); |
---|
1514 | #if LAST_CTX_REDUCTION |
---|
1515 | } |
---|
1516 | #endif |
---|
1517 | } |
---|
1518 | if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ]) |
---|
1519 | { |
---|
1520 | #if LAST_CTX_REDUCTION |
---|
1521 | if (eTType) |
---|
1522 | { |
---|
1523 | m_pcBinIf->encodeBin( 0, *( pCtxY + (uiCtxLast>>g_aucConvertToBit[ height ]) ) ); |
---|
1524 | } |
---|
1525 | else |
---|
1526 | { |
---|
1527 | #endif |
---|
1528 | m_pcBinIf->encodeBin( 0, *( pCtxY + puiCtxIdxY[ uiCtxLast ] ) ); |
---|
1529 | #if LAST_CTX_REDUCTION |
---|
1530 | } |
---|
1531 | #endif |
---|
1532 | } |
---|
1533 | if ( uiGroupIdxX > 3 ) |
---|
1534 | { |
---|
1535 | UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; |
---|
1536 | uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; |
---|
1537 | for (Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1538 | { |
---|
1539 | m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 ); |
---|
1540 | } |
---|
1541 | } |
---|
1542 | if ( uiGroupIdxY > 3 ) |
---|
1543 | { |
---|
1544 | UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; |
---|
1545 | uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; |
---|
1546 | for ( Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1547 | { |
---|
1548 | m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 ); |
---|
1549 | } |
---|
1550 | } |
---|
1551 | } |
---|
1552 | |
---|
1553 | Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
1554 | { |
---|
1555 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1556 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
1557 | DTRACE_CABAC_V( eTType ) |
---|
1558 | DTRACE_CABAC_T( "\twidth=" ) |
---|
1559 | DTRACE_CABAC_V( uiWidth ) |
---|
1560 | DTRACE_CABAC_T( "\theight=" ) |
---|
1561 | DTRACE_CABAC_V( uiHeight ) |
---|
1562 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
1563 | DTRACE_CABAC_V( uiDepth ) |
---|
1564 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
1565 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1566 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
1567 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
1568 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
1569 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
1570 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
1571 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
1572 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
1573 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1574 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
1575 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1576 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
1577 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
1578 | DTRACE_CABAC_T( "\n" ) |
---|
1579 | |
---|
1580 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
1581 | { |
---|
1582 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1583 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1584 | } |
---|
1585 | |
---|
1586 | UInt uiNumSig = 0; |
---|
1587 | |
---|
1588 | // compute number of significant coefficients |
---|
1589 | uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); |
---|
1590 | |
---|
1591 | if ( uiNumSig == 0 ) |
---|
1592 | return; |
---|
1593 | |
---|
1594 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
1595 | |
---|
1596 | //----- encode significance map ----- |
---|
1597 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
1598 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
1599 | if (uiScanIdx == SCAN_ZIGZAG) |
---|
1600 | { |
---|
1601 | // Map zigzag to diagonal scan |
---|
1602 | uiScanIdx = SCAN_DIAG; |
---|
1603 | } |
---|
1604 | Int blockType = uiLog2BlockSize; |
---|
1605 | if (uiWidth != uiHeight) |
---|
1606 | { |
---|
1607 | uiScanIdx = SCAN_DIAG; |
---|
1608 | blockType = 4; |
---|
1609 | } |
---|
1610 | |
---|
1611 | const UInt * scan; |
---|
1612 | if (uiWidth == uiHeight) |
---|
1613 | { |
---|
1614 | scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize - 1 ]; |
---|
1615 | } |
---|
1616 | else |
---|
1617 | { |
---|
1618 | scan = g_sigScanNSQT[ uiLog2BlockSize - 2 ]; |
---|
1619 | } |
---|
1620 | |
---|
1621 | #if MULTIBITS_DATA_HIDING |
---|
1622 | UInt const tsig = pcCU->getSlice()->getPPS()->getTSIG(); |
---|
1623 | #if LOSSLESS_CODING |
---|
1624 | Bool beValid; |
---|
1625 | if (pcCU->isLosslessCoded(uiAbsPartIdx)) |
---|
1626 | { |
---|
1627 | beValid = false; |
---|
1628 | } |
---|
1629 | else |
---|
1630 | { |
---|
1631 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
1632 | } |
---|
1633 | #else |
---|
1634 | Bool beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
1635 | #endif |
---|
1636 | #endif |
---|
1637 | |
---|
1638 | // Find position of last coefficient |
---|
1639 | Int scanPosLast = -1; |
---|
1640 | Int posLast; |
---|
1641 | |
---|
1642 | const UInt * scanCG; |
---|
1643 | if (uiWidth == uiHeight) |
---|
1644 | { |
---|
1645 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
1646 | #if MULTILEVEL_SIGMAP_EXT |
---|
1647 | if( uiLog2BlockSize == 3 ) |
---|
1648 | { |
---|
1649 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
1650 | } |
---|
1651 | else if( uiLog2BlockSize == 5 ) |
---|
1652 | { |
---|
1653 | scanCG = g_sigLastScanCG32x32; |
---|
1654 | } |
---|
1655 | #endif |
---|
1656 | } |
---|
1657 | else |
---|
1658 | { |
---|
1659 | scanCG = g_sigCGScanNSQT[ uiLog2BlockSize - 2 ]; |
---|
1660 | } |
---|
1661 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
1662 | static const UInt uiShift = MLS_CG_SIZE >> 1; |
---|
1663 | const UInt uiNumBlkSide = uiWidth >> uiShift; |
---|
1664 | |
---|
1665 | #if !MULTILEVEL_SIGMAP_EXT |
---|
1666 | if( blockType > 3 ) |
---|
1667 | { |
---|
1668 | #endif |
---|
1669 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
1670 | |
---|
1671 | do |
---|
1672 | { |
---|
1673 | posLast = scan[ ++scanPosLast ]; |
---|
1674 | |
---|
1675 | // get L1 sig map |
---|
1676 | UInt uiPosY = posLast >> uiLog2BlockSize; |
---|
1677 | UInt uiPosX = posLast - ( uiPosY << uiLog2BlockSize ); |
---|
1678 | UInt uiBlkIdx = uiNumBlkSide * (uiPosY >> uiShift) + (uiPosX >> uiShift); |
---|
1679 | #if MULTILEVEL_SIGMAP_EXT |
---|
1680 | if( uiWidth == 8 && uiHeight == 8 && (uiScanIdx == SCAN_HOR || uiScanIdx == SCAN_VER) ) |
---|
1681 | { |
---|
1682 | if( uiScanIdx == SCAN_HOR ) |
---|
1683 | { |
---|
1684 | uiBlkIdx = uiPosY >> 1; |
---|
1685 | } |
---|
1686 | else if( uiScanIdx == SCAN_VER ) |
---|
1687 | { |
---|
1688 | uiBlkIdx = uiPosX >> 1; |
---|
1689 | } |
---|
1690 | } |
---|
1691 | #endif |
---|
1692 | if( pcCoef[ posLast ] ) |
---|
1693 | { |
---|
1694 | uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; |
---|
1695 | } |
---|
1696 | |
---|
1697 | uiNumSig -= ( pcCoef[ posLast ] != 0 ); |
---|
1698 | } |
---|
1699 | while ( uiNumSig > 0 ); |
---|
1700 | #if !MULTILEVEL_SIGMAP_EXT |
---|
1701 | } |
---|
1702 | else |
---|
1703 | { |
---|
1704 | |
---|
1705 | do |
---|
1706 | { |
---|
1707 | posLast = scan[ ++scanPosLast ]; |
---|
1708 | uiNumSig -= ( pcCoef[ posLast ] != 0 ); |
---|
1709 | } |
---|
1710 | while ( uiNumSig > 0 ); |
---|
1711 | |
---|
1712 | } |
---|
1713 | #endif |
---|
1714 | |
---|
1715 | // Code position of last coefficient |
---|
1716 | Int posLastY = posLast >> uiLog2BlockSize; |
---|
1717 | Int posLastX = posLast - ( posLastY << uiLog2BlockSize ); |
---|
1718 | codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, eTType, uiScanIdx); |
---|
1719 | |
---|
1720 | //===== code significance flag ===== |
---|
1721 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
1722 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
1723 | |
---|
1724 | |
---|
1725 | const Int iLastScanSet = scanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
1726 | UInt uiNumOne = 0; |
---|
1727 | UInt uiGoRiceParam = 0; |
---|
1728 | Int iScanPosSig = scanPosLast; |
---|
1729 | |
---|
1730 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
1731 | { |
---|
1732 | Int numNonZero = 0; |
---|
1733 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
1734 | uiGoRiceParam = 0; |
---|
1735 | Int absCoeff[16]; |
---|
1736 | UInt coeffSigns = 0; |
---|
1737 | |
---|
1738 | #if MULTIBITS_DATA_HIDING |
---|
1739 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
1740 | #endif |
---|
1741 | |
---|
1742 | if( iScanPosSig == scanPosLast ) |
---|
1743 | { |
---|
1744 | absCoeff[ 0 ] = abs( pcCoef[ posLast ] ); |
---|
1745 | coeffSigns = ( pcCoef[ posLast ] < 0 ); |
---|
1746 | numNonZero = 1; |
---|
1747 | #if MULTIBITS_DATA_HIDING |
---|
1748 | lastNZPosInCG = iScanPosSig; |
---|
1749 | firstNZPosInCG = iScanPosSig; |
---|
1750 | #endif |
---|
1751 | iScanPosSig--; |
---|
1752 | } |
---|
1753 | |
---|
1754 | #if !MULTILEVEL_SIGMAP_EXT |
---|
1755 | if( blockType > 3 ) |
---|
1756 | { |
---|
1757 | #endif |
---|
1758 | // encode significant_coeffgroup_flag |
---|
1759 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
1760 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
1761 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
1762 | #if MULTILEVEL_SIGMAP_EXT |
---|
1763 | if( uiWidth == 8 && uiHeight == 8 && (uiScanIdx == SCAN_HOR || uiScanIdx == SCAN_VER) ) |
---|
1764 | { |
---|
1765 | iCGPosY = (uiScanIdx == SCAN_HOR ? iCGBlkPos : 0); |
---|
1766 | iCGPosX = (uiScanIdx == SCAN_VER ? iCGBlkPos : 0); |
---|
1767 | } |
---|
1768 | #endif |
---|
1769 | #if !REMOVE_INFER_SIGGRP |
---|
1770 | Bool bInferredCGFlag = false; |
---|
1771 | #endif |
---|
1772 | #if REMOVE_INFER_SIGGRP |
---|
1773 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
1774 | #else |
---|
1775 | if( iSubSet == iLastScanSet ) |
---|
1776 | #endif |
---|
1777 | { |
---|
1778 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
1779 | } |
---|
1780 | else |
---|
1781 | { |
---|
1782 | #if !REMOVE_INFER_SIGGRP |
---|
1783 | #if MULTILEVEL_SIGMAP_EXT |
---|
1784 | if( !TComTrQuant::bothCGNeighboursOne( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiScanIdx, uiWidth, uiHeight ) && ( iSubSet ) ) |
---|
1785 | #else |
---|
1786 | if( !TComTrQuant::bothCGNeighboursOne( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ) && ( iSubSet ) ) |
---|
1787 | #endif |
---|
1788 | { |
---|
1789 | #endif |
---|
1790 | UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); |
---|
1791 | #if MULTILEVEL_SIGMAP_EXT |
---|
1792 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiScanIdx, uiWidth, uiHeight ); |
---|
1793 | #else |
---|
1794 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
1795 | #endif |
---|
1796 | m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
1797 | #if !REMOVE_INFER_SIGGRP |
---|
1798 | } |
---|
1799 | else |
---|
1800 | { |
---|
1801 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
1802 | bInferredCGFlag = true; |
---|
1803 | } |
---|
1804 | #endif |
---|
1805 | } |
---|
1806 | |
---|
1807 | // encode significant_coeff_flag |
---|
1808 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
1809 | { |
---|
1810 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
1811 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
1812 | { |
---|
1813 | uiBlkPos = scan[ iScanPosSig ]; |
---|
1814 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
1815 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
1816 | uiSig = (pcCoef[ uiBlkPos ] != 0); |
---|
1817 | #if REMOVE_INFER_SIGGRP |
---|
1818 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
1819 | #else |
---|
1820 | if( iScanPosSig > iSubPos || bInferredCGFlag || numNonZero ) |
---|
1821 | #endif |
---|
1822 | { |
---|
1823 | uiCtxSig = TComTrQuant::getSigCtxInc( pcCoef, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType ); |
---|
1824 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
1825 | } |
---|
1826 | if( uiSig ) |
---|
1827 | { |
---|
1828 | absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); |
---|
1829 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
1830 | numNonZero++; |
---|
1831 | #if MULTIBITS_DATA_HIDING |
---|
1832 | if( lastNZPosInCG == -1 ) |
---|
1833 | { |
---|
1834 | lastNZPosInCG = iScanPosSig; |
---|
1835 | } |
---|
1836 | firstNZPosInCG = iScanPosSig; |
---|
1837 | #endif |
---|
1838 | } |
---|
1839 | } |
---|
1840 | } |
---|
1841 | else |
---|
1842 | { |
---|
1843 | iScanPosSig = iSubPos - 1; |
---|
1844 | } |
---|
1845 | #if !MULTILEVEL_SIGMAP_EXT |
---|
1846 | } |
---|
1847 | else |
---|
1848 | { |
---|
1849 | |
---|
1850 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
1851 | { |
---|
1852 | UInt uiBlkPos = scan[ iScanPosSig ]; |
---|
1853 | UInt uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
1854 | UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
1855 | UInt uiSig = 0; |
---|
1856 | if( pcCoef[ uiBlkPos ] != 0 ) |
---|
1857 | { |
---|
1858 | uiSig = 1; |
---|
1859 | absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); |
---|
1860 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
1861 | numNonZero++; |
---|
1862 | #if MULTIBITS_DATA_HIDING |
---|
1863 | if( lastNZPosInCG == -1 ) |
---|
1864 | { |
---|
1865 | lastNZPosInCG = iScanPosSig; |
---|
1866 | } |
---|
1867 | firstNZPosInCG = iScanPosSig; |
---|
1868 | #endif |
---|
1869 | } |
---|
1870 | UInt uiCtxSig = TComTrQuant::getSigCtxInc( pcCoef, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType ); |
---|
1871 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
1872 | } |
---|
1873 | |
---|
1874 | } |
---|
1875 | #endif |
---|
1876 | |
---|
1877 | if( numNonZero > 0 ) |
---|
1878 | { |
---|
1879 | #if MULTIBITS_DATA_HIDING |
---|
1880 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= (Int)tsig ); |
---|
1881 | #endif // MULTIBITS_DATA_HIDING |
---|
1882 | |
---|
1883 | UInt c1 = 1; |
---|
1884 | #if !RESTRICT_GR1GR2FLAG_NUMBER |
---|
1885 | UInt c2 = 0; |
---|
1886 | #endif |
---|
1887 | #if LEVEL_CTX_LUMA_RED |
---|
1888 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
1889 | #else |
---|
1890 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 3 : 0; |
---|
1891 | #endif |
---|
1892 | |
---|
1893 | if( uiNumOne > 0 ) |
---|
1894 | { |
---|
1895 | uiCtxSet++; |
---|
1896 | #if !LEVEL_CTX_LUMA_RED |
---|
1897 | if( uiNumOne > 3 && eTType==TEXT_LUMA) |
---|
1898 | { |
---|
1899 | uiCtxSet++; |
---|
1900 | } |
---|
1901 | #endif |
---|
1902 | } |
---|
1903 | |
---|
1904 | uiNumOne >>= 1; |
---|
1905 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
1906 | |
---|
1907 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
1908 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
1909 | Int firstC2FlagIdx = -1; |
---|
1910 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
1911 | #else |
---|
1912 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1913 | #endif |
---|
1914 | { |
---|
1915 | UInt uiSymbol = absCoeff[ idx ] > 1; |
---|
1916 | m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] ); |
---|
1917 | if( uiSymbol ) |
---|
1918 | { |
---|
1919 | c1 = 0; |
---|
1920 | |
---|
1921 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
1922 | if (firstC2FlagIdx == -1) |
---|
1923 | { |
---|
1924 | firstC2FlagIdx = idx; |
---|
1925 | } |
---|
1926 | #endif |
---|
1927 | } |
---|
1928 | else if( (c1 < 3) && (c1 > 0) ) |
---|
1929 | { |
---|
1930 | c1++; |
---|
1931 | } |
---|
1932 | } |
---|
1933 | |
---|
1934 | if (c1 == 0) |
---|
1935 | { |
---|
1936 | |
---|
1937 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
1938 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
1939 | if ( firstC2FlagIdx != -1) |
---|
1940 | { |
---|
1941 | UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; |
---|
1942 | m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); |
---|
1943 | } |
---|
1944 | #else |
---|
1945 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + 3 * uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + 3 * uiCtxSet; |
---|
1946 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1947 | { |
---|
1948 | if( absCoeff[ idx ] > 1 ) |
---|
1949 | { |
---|
1950 | UInt symbol = absCoeff[ idx ] > 2; |
---|
1951 | m_pcBinIf->encodeBin( symbol, baseCtxMod[c2] ); |
---|
1952 | c2 += (c2 < 2); |
---|
1953 | uiNumOne++; |
---|
1954 | } |
---|
1955 | } |
---|
1956 | #endif |
---|
1957 | } |
---|
1958 | |
---|
1959 | #if MULTIBITS_DATA_HIDING |
---|
1960 | if( beValid && signHidden ) |
---|
1961 | { |
---|
1962 | m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 ); |
---|
1963 | } |
---|
1964 | else |
---|
1965 | { |
---|
1966 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
1967 | } |
---|
1968 | #else |
---|
1969 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
1970 | #endif |
---|
1971 | |
---|
1972 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
1973 | Int iFirstCoeff2 = 1; |
---|
1974 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
1975 | #else |
---|
1976 | if (c1 == 0) |
---|
1977 | #endif |
---|
1978 | { |
---|
1979 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1980 | { |
---|
1981 | #if RESTRICT_GR1GR2FLAG_NUMBER |
---|
1982 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1; |
---|
1983 | |
---|
1984 | if( absCoeff[ idx ] >= baseLevel) |
---|
1985 | { |
---|
1986 | xWriteGoRiceExGolomb( absCoeff[ idx ] - baseLevel, uiGoRiceParam ); |
---|
1987 | } |
---|
1988 | if(absCoeff[ idx ] >= 2) |
---|
1989 | { |
---|
1990 | iFirstCoeff2 = 0; |
---|
1991 | uiNumOne++; |
---|
1992 | } |
---|
1993 | #else |
---|
1994 | if ( absCoeff[ idx ] > 2 ) |
---|
1995 | { |
---|
1996 | xWriteGoRiceExGolomb( absCoeff[ idx ] - 3, uiGoRiceParam ); |
---|
1997 | } |
---|
1998 | #endif |
---|
1999 | } |
---|
2000 | } |
---|
2001 | } |
---|
2002 | else |
---|
2003 | { |
---|
2004 | uiNumOne >>= 1; |
---|
2005 | } |
---|
2006 | } |
---|
2007 | |
---|
2008 | return; |
---|
2009 | } |
---|
2010 | |
---|
2011 | Void TEncSbac::codeAlfFlag ( UInt uiCode ) |
---|
2012 | { |
---|
2013 | UInt uiSymbol = ( ( uiCode == 0 ) ? 0 : 1 ); |
---|
2014 | m_pcBinIf->encodeBin( uiSymbol, m_cALFFlagSCModel.get( 0, 0, 0 ) ); |
---|
2015 | } |
---|
2016 | |
---|
2017 | Void TEncSbac::codeAlfCtrlFlag( UInt uiSymbol ) |
---|
2018 | { |
---|
2019 | m_pcBinIf->encodeBin( uiSymbol, m_cCUAlfCtrlFlagSCModel.get( 0, 0, 0) ); |
---|
2020 | } |
---|
2021 | |
---|
2022 | Void TEncSbac::codeAlfUvlc ( UInt uiCode ) |
---|
2023 | { |
---|
2024 | Int i; |
---|
2025 | |
---|
2026 | if ( uiCode == 0 ) |
---|
2027 | { |
---|
2028 | m_pcBinIf->encodeBin( 0, m_cALFUvlcSCModel.get( 0, 0, 0 ) ); |
---|
2029 | } |
---|
2030 | else |
---|
2031 | { |
---|
2032 | m_pcBinIf->encodeBin( 1, m_cALFUvlcSCModel.get( 0, 0, 0 ) ); |
---|
2033 | for ( i=0; i<uiCode-1; i++ ) |
---|
2034 | { |
---|
2035 | m_pcBinIf->encodeBin( 1, m_cALFUvlcSCModel.get( 0, 0, 1 ) ); |
---|
2036 | } |
---|
2037 | m_pcBinIf->encodeBin( 0, m_cALFUvlcSCModel.get( 0, 0, 1 ) ); |
---|
2038 | } |
---|
2039 | } |
---|
2040 | |
---|
2041 | Void TEncSbac::codeAlfSvlc ( Int iCode ) |
---|
2042 | { |
---|
2043 | Int i; |
---|
2044 | |
---|
2045 | if ( iCode == 0 ) |
---|
2046 | { |
---|
2047 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 0 ) ); |
---|
2048 | } |
---|
2049 | else |
---|
2050 | { |
---|
2051 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 0 ) ); |
---|
2052 | |
---|
2053 | // write sign |
---|
2054 | if ( iCode > 0 ) |
---|
2055 | { |
---|
2056 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 1 ) ); |
---|
2057 | } |
---|
2058 | else |
---|
2059 | { |
---|
2060 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 1 ) ); |
---|
2061 | iCode = -iCode; |
---|
2062 | } |
---|
2063 | |
---|
2064 | // write magnitude |
---|
2065 | for ( i=0; i<iCode-1; i++ ) |
---|
2066 | { |
---|
2067 | m_pcBinIf->encodeBin( 1, m_cALFSvlcSCModel.get( 0, 0, 2 ) ); |
---|
2068 | } |
---|
2069 | m_pcBinIf->encodeBin( 0, m_cALFSvlcSCModel.get( 0, 0, 2 ) ); |
---|
2070 | } |
---|
2071 | } |
---|
2072 | |
---|
2073 | Void TEncSbac::codeSaoFlag ( UInt uiCode ) |
---|
2074 | { |
---|
2075 | UInt uiSymbol = ( ( uiCode == 0 ) ? 0 : 1 ); |
---|
2076 | m_pcBinIf->encodeBin( uiSymbol, m_cSaoFlagSCModel.get( 0, 0, 0 ) ); |
---|
2077 | } |
---|
2078 | |
---|
2079 | Void TEncSbac::codeSaoUvlc ( UInt uiCode ) |
---|
2080 | { |
---|
2081 | Int i; |
---|
2082 | |
---|
2083 | if ( uiCode == 0 ) |
---|
2084 | { |
---|
2085 | m_pcBinIf->encodeBin( 0, m_cSaoUvlcSCModel.get( 0, 0, 0 ) ); |
---|
2086 | } |
---|
2087 | else |
---|
2088 | { |
---|
2089 | m_pcBinIf->encodeBin( 1, m_cSaoUvlcSCModel.get( 0, 0, 0 ) ); |
---|
2090 | for ( i=0; i<uiCode-1; i++ ) |
---|
2091 | { |
---|
2092 | m_pcBinIf->encodeBin( 1, m_cSaoUvlcSCModel.get( 0, 0, 1 ) ); |
---|
2093 | } |
---|
2094 | m_pcBinIf->encodeBin( 0, m_cSaoUvlcSCModel.get( 0, 0, 1 ) ); |
---|
2095 | } |
---|
2096 | } |
---|
2097 | |
---|
2098 | Void TEncSbac::codeSaoSvlc ( Int iCode ) |
---|
2099 | { |
---|
2100 | Int i; |
---|
2101 | |
---|
2102 | if ( iCode == 0 ) |
---|
2103 | { |
---|
2104 | m_pcBinIf->encodeBin( 0, m_cSaoSvlcSCModel.get( 0, 0, 0 ) ); |
---|
2105 | } |
---|
2106 | else |
---|
2107 | { |
---|
2108 | m_pcBinIf->encodeBin( 1, m_cSaoSvlcSCModel.get( 0, 0, 0 ) ); |
---|
2109 | |
---|
2110 | // write sign |
---|
2111 | if ( iCode > 0 ) |
---|
2112 | { |
---|
2113 | m_pcBinIf->encodeBin( 0, m_cSaoSvlcSCModel.get( 0, 0, 1 ) ); |
---|
2114 | } |
---|
2115 | else |
---|
2116 | { |
---|
2117 | m_pcBinIf->encodeBin( 1, m_cSaoSvlcSCModel.get( 0, 0, 1 ) ); |
---|
2118 | iCode = -iCode; |
---|
2119 | } |
---|
2120 | |
---|
2121 | // write magnitude |
---|
2122 | for ( i=0; i<iCode-1; i++ ) |
---|
2123 | { |
---|
2124 | m_pcBinIf->encodeBin( 1, m_cSaoSvlcSCModel.get( 0, 0, 2 ) ); |
---|
2125 | } |
---|
2126 | m_pcBinIf->encodeBin( 0, m_cSaoSvlcSCModel.get( 0, 0, 2 ) ); |
---|
2127 | } |
---|
2128 | } |
---|
2129 | #if SAO_UNIT_INTERLEAVING |
---|
2130 | /** Code SAO band position |
---|
2131 | * \param uiCode |
---|
2132 | */ |
---|
2133 | Void TEncSbac::codeSaoUflc ( UInt uiCode ) |
---|
2134 | { |
---|
2135 | for (Int i=0;i<5;i++) |
---|
2136 | { |
---|
2137 | m_pcBinIf->encodeBinEP ( (uiCode>>i) &0x01 ); |
---|
2138 | } |
---|
2139 | } |
---|
2140 | /** Code SAO merge left flag |
---|
2141 | * \param uiCode |
---|
2142 | * \param uiCompIdx |
---|
2143 | */ |
---|
2144 | Void TEncSbac::codeSaoMergeLeft ( UInt uiCode, UInt uiCompIdx ) |
---|
2145 | { |
---|
2146 | if (uiCode == 0) |
---|
2147 | { |
---|
2148 | m_pcBinIf->encodeBin(0, m_cSaoMergeLeftSCModel.get( 0, 0, uiCompIdx )); |
---|
2149 | } |
---|
2150 | else |
---|
2151 | { |
---|
2152 | m_pcBinIf->encodeBin(1, m_cSaoMergeLeftSCModel.get( 0, 0, uiCompIdx )); |
---|
2153 | } |
---|
2154 | } |
---|
2155 | /** Code SAO merge up flag |
---|
2156 | * \param uiCode |
---|
2157 | */ |
---|
2158 | Void TEncSbac::codeSaoMergeUp ( UInt uiCode) |
---|
2159 | { |
---|
2160 | if (uiCode == 0) |
---|
2161 | { |
---|
2162 | m_pcBinIf->encodeBin(0, m_cSaoMergeUpSCModel.get( 0, 0, 0 )); |
---|
2163 | } |
---|
2164 | else |
---|
2165 | { |
---|
2166 | m_pcBinIf->encodeBin(1, m_cSaoMergeUpSCModel.get( 0, 0, 0 )); |
---|
2167 | } |
---|
2168 | } |
---|
2169 | /** Code SAO type index |
---|
2170 | * \param uiCode |
---|
2171 | */ |
---|
2172 | Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) |
---|
2173 | { |
---|
2174 | Int i; |
---|
2175 | if ( uiCode == 0 ) |
---|
2176 | { |
---|
2177 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
2178 | } |
---|
2179 | else |
---|
2180 | { |
---|
2181 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
2182 | for ( i=0; i<uiCode-1; i++ ) |
---|
2183 | { |
---|
2184 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 1 ) ); |
---|
2185 | } |
---|
2186 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 1 ) ); |
---|
2187 | } |
---|
2188 | } |
---|
2189 | #endif |
---|
2190 | /*! |
---|
2191 | **************************************************************************** |
---|
2192 | * \brief |
---|
2193 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
2194 | **************************************************************************** |
---|
2195 | */ |
---|
2196 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
2197 | { |
---|
2198 | estCBFBit( pcEstBitsSbac, 0, eTType ); |
---|
2199 | |
---|
2200 | estSignificantCoeffGroupMapBit( pcEstBitsSbac, 0, eTType ); |
---|
2201 | |
---|
2202 | // encode significance map |
---|
2203 | estSignificantMapBit( pcEstBitsSbac, width, height, eTType ); |
---|
2204 | |
---|
2205 | // encode significant coefficients |
---|
2206 | estSignificantCoefficientsBit( pcEstBitsSbac, 0, eTType ); |
---|
2207 | } |
---|
2208 | |
---|
2209 | /*! |
---|
2210 | **************************************************************************** |
---|
2211 | * \brief |
---|
2212 | * estimate bit cost for each CBP bit |
---|
2213 | **************************************************************************** |
---|
2214 | */ |
---|
2215 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
2216 | { |
---|
2217 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
2218 | |
---|
2219 | for( UInt uiCtxInc = 0; uiCtxInc < 3*NUM_QT_CBF_CTX; uiCtxInc++ ) |
---|
2220 | { |
---|
2221 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
2222 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
2223 | } |
---|
2224 | |
---|
2225 | pCtx = m_cCUQtRootCbfSCModel.get( 0 ); |
---|
2226 | |
---|
2227 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
2228 | { |
---|
2229 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
2230 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
2231 | } |
---|
2232 | } |
---|
2233 | |
---|
2234 | |
---|
2235 | /*! |
---|
2236 | **************************************************************************** |
---|
2237 | * \brief |
---|
2238 | * estimate SAMBAC bit cost for significant coefficient group map |
---|
2239 | **************************************************************************** |
---|
2240 | */ |
---|
2241 | Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
2242 | { |
---|
2243 | Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; |
---|
2244 | |
---|
2245 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
2246 | { |
---|
2247 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
2248 | { |
---|
2249 | pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, eTType, ctxIdx ).getEntropyBits( uiBin ); |
---|
2250 | } |
---|
2251 | } |
---|
2252 | } |
---|
2253 | |
---|
2254 | |
---|
2255 | /*! |
---|
2256 | **************************************************************************** |
---|
2257 | * \brief |
---|
2258 | * estimate SAMBAC bit cost for significant coefficient map |
---|
2259 | **************************************************************************** |
---|
2260 | */ |
---|
2261 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
2262 | { |
---|
2263 | Int firstCtx = 0, numCtx = (eTType == TEXT_LUMA) ? 9 : 6; |
---|
2264 | if (std::max(width, height) >= 16) |
---|
2265 | { |
---|
2266 | firstCtx = (eTType == TEXT_LUMA) ? 20 : 17; |
---|
2267 | numCtx = (eTType == TEXT_LUMA) ? 7 : 4; |
---|
2268 | } |
---|
2269 | else if (width == 8) |
---|
2270 | { |
---|
2271 | firstCtx = (eTType == TEXT_LUMA) ? 9 : 6; |
---|
2272 | numCtx = 11; |
---|
2273 | } |
---|
2274 | |
---|
2275 | if (eTType == TEXT_LUMA ) |
---|
2276 | { |
---|
2277 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
2278 | { |
---|
2279 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
2280 | { |
---|
2281 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, ctxIdx ).getEntropyBits( uiBin ); |
---|
2282 | } |
---|
2283 | } |
---|
2284 | } |
---|
2285 | else |
---|
2286 | { |
---|
2287 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
2288 | { |
---|
2289 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
2290 | { |
---|
2291 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx ).getEntropyBits( uiBin ); |
---|
2292 | } |
---|
2293 | } |
---|
2294 | } |
---|
2295 | Int iBitsX = 0, iBitsY = 0; |
---|
2296 | const UInt *puiCtxIdx; |
---|
2297 | Int ctx; |
---|
2298 | #if LAST_CTX_REDUCTION |
---|
2299 | Int widthCtx = eTType? 4 : width; |
---|
2300 | puiCtxIdx = g_uiLastCtx + (g_aucConvertToBit[ widthCtx ]*(g_aucConvertToBit[ widthCtx ]+3)); |
---|
2301 | #else |
---|
2302 | puiCtxIdx = g_uiLastCtx + (g_aucConvertToBit[ width ]*(g_aucConvertToBit[ width ]+3)); |
---|
2303 | #endif |
---|
2304 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
2305 | for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) |
---|
2306 | { |
---|
2307 | Int ctxOffset = puiCtxIdx[ ctx ]; |
---|
2308 | #if LAST_CTX_REDUCTION |
---|
2309 | if (eTType) |
---|
2310 | { |
---|
2311 | Int ctxOffsetC = ctx>>g_aucConvertToBit[ width ]; |
---|
2312 | pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffsetC ].getEntropyBits( 0 ); |
---|
2313 | iBitsX += pCtxX[ ctxOffsetC].getEntropyBits( 1 ); |
---|
2314 | } |
---|
2315 | else |
---|
2316 | { |
---|
2317 | #endif |
---|
2318 | pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); |
---|
2319 | iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); |
---|
2320 | #if LAST_CTX_REDUCTION |
---|
2321 | } |
---|
2322 | #endif |
---|
2323 | } |
---|
2324 | pcEstBitsSbac->lastXBits[ctx] = iBitsX; |
---|
2325 | |
---|
2326 | #if LAST_CTX_REDUCTION |
---|
2327 | Int heightCtx = eTType? 4 : height; |
---|
2328 | puiCtxIdx = g_uiLastCtx + (g_aucConvertToBit[ heightCtx ]*(g_aucConvertToBit[ heightCtx ]+3)); |
---|
2329 | #else |
---|
2330 | puiCtxIdx = g_uiLastCtx + (g_aucConvertToBit[ height ]*(g_aucConvertToBit[ height ]+3)); |
---|
2331 | #endif |
---|
2332 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
2333 | for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) |
---|
2334 | { |
---|
2335 | Int ctxOffset = puiCtxIdx[ ctx ]; |
---|
2336 | #if LAST_CTX_REDUCTION |
---|
2337 | if (eTType) |
---|
2338 | { |
---|
2339 | Int ctxOffsetC = ctx>>g_aucConvertToBit[ height ]; |
---|
2340 | pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffsetC ].getEntropyBits( 0 ); |
---|
2341 | iBitsY += pCtxY[ctxOffsetC].getEntropyBits( 1 ); |
---|
2342 | } |
---|
2343 | else |
---|
2344 | { |
---|
2345 | #endif |
---|
2346 | pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); |
---|
2347 | iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); |
---|
2348 | #if LAST_CTX_REDUCTION |
---|
2349 | } |
---|
2350 | #endif |
---|
2351 | } |
---|
2352 | pcEstBitsSbac->lastYBits[ctx] = iBitsY; |
---|
2353 | } |
---|
2354 | |
---|
2355 | /*! |
---|
2356 | **************************************************************************** |
---|
2357 | * \brief |
---|
2358 | * estimate bit cost of significant coefficient |
---|
2359 | **************************************************************************** |
---|
2360 | */ |
---|
2361 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType ) |
---|
2362 | { |
---|
2363 | if (eTType==TEXT_LUMA) |
---|
2364 | { |
---|
2365 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); |
---|
2366 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); |
---|
2367 | |
---|
2368 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++) |
---|
2369 | { |
---|
2370 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
2371 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
2372 | } |
---|
2373 | |
---|
2374 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_LUMA; ctxIdx++) |
---|
2375 | { |
---|
2376 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
2377 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
2378 | } |
---|
2379 | } |
---|
2380 | else |
---|
2381 | { |
---|
2382 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA; |
---|
2383 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA; |
---|
2384 | |
---|
2385 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++) |
---|
2386 | { |
---|
2387 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
2388 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
2389 | } |
---|
2390 | |
---|
2391 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_CHROMA; ctxIdx++) |
---|
2392 | { |
---|
2393 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
2394 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
2395 | } |
---|
2396 | } |
---|
2397 | } |
---|
2398 | |
---|
2399 | /** |
---|
2400 | - Initialize our context information from the nominated source. |
---|
2401 | . |
---|
2402 | \param pSrc From where to copy context information. |
---|
2403 | */ |
---|
2404 | Void TEncSbac::xCopyContextsFrom( TEncSbac* pSrc ) |
---|
2405 | { |
---|
2406 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
2407 | } |
---|
2408 | |
---|
2409 | Void TEncSbac::loadContexts ( TEncSbac* pScr) |
---|
2410 | { |
---|
2411 | this->xCopyContextsFrom(pScr); |
---|
2412 | } |
---|
2413 | |
---|
2414 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX || (LGE_EDGE_INTRA && LGE_EDGE_INTRA_DELTA_DC) |
---|
2415 | Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel ) |
---|
2416 | { |
---|
2417 | if( uiSymbol ) |
---|
2418 | { |
---|
2419 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
2420 | UInt uiCount = 0; |
---|
2421 | Bool bNoExGo = (uiSymbol < 13); |
---|
2422 | |
---|
2423 | while( --uiSymbol && ++uiCount < 13 ) |
---|
2424 | { |
---|
2425 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
2426 | } |
---|
2427 | if( bNoExGo ) |
---|
2428 | { |
---|
2429 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
2430 | } |
---|
2431 | else |
---|
2432 | { |
---|
2433 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
2434 | } |
---|
2435 | } |
---|
2436 | else |
---|
2437 | { |
---|
2438 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
2439 | } |
---|
2440 | |
---|
2441 | return; |
---|
2442 | } |
---|
2443 | #endif |
---|
2444 | #if HHI_DMM_WEDGE_INTRA |
---|
2445 | Void TEncSbac::xCodeWedgeFullInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
2446 | { |
---|
2447 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
2448 | Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx]; |
---|
2449 | |
---|
2450 | UInt uiTabIdx = pcCU->getWedgeFullTabIdx( uiAbsPartIdx ); |
---|
2451 | |
---|
2452 | for ( Int i = 0; i < iBits; i++ ) |
---|
2453 | { |
---|
2454 | m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cDmmDataSCModel.get(0, 0, 0) ); |
---|
2455 | } |
---|
2456 | } |
---|
2457 | |
---|
2458 | Void TEncSbac::xCodeWedgeFullDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
2459 | { |
---|
2460 | Int iIntraIdx = pcCU->getIntraSizeIdx(uiAbsPartIdx); |
---|
2461 | Int iBits = g_aucWedgeFullBitsListIdx[iIntraIdx]; |
---|
2462 | |
---|
2463 | UInt uiTabIdx = pcCU->getWedgeFullTabIdx( uiAbsPartIdx ); |
---|
2464 | |
---|
2465 | for ( Int i = 0; i < iBits; i++ ) |
---|
2466 | { |
---|
2467 | m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cDmmDataSCModel.get(0, 0, 0) ); |
---|
2468 | } |
---|
2469 | |
---|
2470 | Int iDeltaDC1 = pcCU->getWedgeFullDeltaDC1( uiAbsPartIdx ); |
---|
2471 | Int iDeltaDC2 = pcCU->getWedgeFullDeltaDC2( uiAbsPartIdx ); |
---|
2472 | |
---|
2473 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
2474 | if ( iDeltaDC1 != 0 ) |
---|
2475 | { |
---|
2476 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
2477 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2478 | } |
---|
2479 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
2480 | if ( iDeltaDC2 != 0 ) |
---|
2481 | { |
---|
2482 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
2483 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2484 | } |
---|
2485 | } |
---|
2486 | |
---|
2487 | Void TEncSbac::xCodeWedgePredDirInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
2488 | { |
---|
2489 | if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 ) |
---|
2490 | { |
---|
2491 | Int iDeltaEnd = pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ); |
---|
2492 | m_pcBinIf->encodeBin( (iDeltaEnd!=0), m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
2493 | |
---|
2494 | if( iDeltaEnd != 0 ) |
---|
2495 | { |
---|
2496 | UInt uiAbsValMinus1 = abs(iDeltaEnd)-1; |
---|
2497 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
2498 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
2499 | |
---|
2500 | UInt uiSign = iDeltaEnd > 0 ? 0 : 1; |
---|
2501 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2502 | } |
---|
2503 | } |
---|
2504 | } |
---|
2505 | |
---|
2506 | Void TEncSbac::xCodeWedgePredDirDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
2507 | { |
---|
2508 | if( DMM_WEDGE_PREDDIR_DELTAEND_MAX > 0 ) |
---|
2509 | { |
---|
2510 | Int iDeltaEnd = pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ); |
---|
2511 | m_pcBinIf->encodeBin( (iDeltaEnd!=0), m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
2512 | |
---|
2513 | if( iDeltaEnd != 0 ) |
---|
2514 | { |
---|
2515 | UInt uiAbsValMinus1 = abs(iDeltaEnd)-1; |
---|
2516 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
2517 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cDmmDataSCModel.get(0, 0, 2) ); |
---|
2518 | |
---|
2519 | UInt uiSign = iDeltaEnd > 0 ? 0 : 1; |
---|
2520 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2521 | } |
---|
2522 | } |
---|
2523 | |
---|
2524 | Int iDeltaDC1 = pcCU->getWedgePredDirDeltaDC1( uiAbsPartIdx ); |
---|
2525 | Int iDeltaDC2 = pcCU->getWedgePredDirDeltaDC2( uiAbsPartIdx ); |
---|
2526 | |
---|
2527 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
2528 | if ( iDeltaDC1 != 0 ) |
---|
2529 | { |
---|
2530 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
2531 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2532 | } |
---|
2533 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
2534 | if ( iDeltaDC2 != 0 ) |
---|
2535 | { |
---|
2536 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
2537 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2538 | } |
---|
2539 | } |
---|
2540 | #endif |
---|
2541 | #if HHI_DMM_PRED_TEX |
---|
2542 | Void TEncSbac::xCodeWedgePredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
2543 | { |
---|
2544 | Int iDeltaDC1 = pcCU->getWedgePredTexDeltaDC1( uiAbsPartIdx ); |
---|
2545 | Int iDeltaDC2 = pcCU->getWedgePredTexDeltaDC2( uiAbsPartIdx ); |
---|
2546 | |
---|
2547 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
2548 | if ( iDeltaDC1 != 0 ) |
---|
2549 | { |
---|
2550 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
2551 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2552 | } |
---|
2553 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
2554 | if ( iDeltaDC2 != 0 ) |
---|
2555 | { |
---|
2556 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
2557 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2558 | } |
---|
2559 | } |
---|
2560 | |
---|
2561 | Void TEncSbac::xCodeContourPredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
2562 | { |
---|
2563 | Int iDeltaDC1 = pcCU->getContourPredTexDeltaDC1( uiAbsPartIdx ); |
---|
2564 | Int iDeltaDC2 = pcCU->getContourPredTexDeltaDC2( uiAbsPartIdx ); |
---|
2565 | |
---|
2566 | xWriteExGolombLevel( UInt( abs( iDeltaDC1 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
2567 | if ( iDeltaDC1 != 0 ) |
---|
2568 | { |
---|
2569 | UInt uiSign = iDeltaDC1 > 0 ? 0 : 1; |
---|
2570 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2571 | } |
---|
2572 | xWriteExGolombLevel( UInt( abs( iDeltaDC2 ) ), m_cDmmDataSCModel.get(0, 0, 1) ); |
---|
2573 | if ( iDeltaDC2 != 0 ) |
---|
2574 | { |
---|
2575 | UInt uiSign = iDeltaDC2 > 0 ? 0 : 1; |
---|
2576 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
2577 | } |
---|
2578 | } |
---|
2579 | #endif |
---|
2580 | //! \} |
---|