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