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