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