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