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