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-2013, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TEncSbac.cpp |
---|
35 | \brief SBAC encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TEncTop.h" |
---|
39 | #include "TEncSbac.h" |
---|
40 | |
---|
41 | #include <map> |
---|
42 | #include <algorithm> |
---|
43 | |
---|
44 | //! \ingroup TLibEncoder |
---|
45 | //! \{ |
---|
46 | |
---|
47 | // ==================================================================================================================== |
---|
48 | // Constructor / destructor / create / destroy |
---|
49 | // ==================================================================================================================== |
---|
50 | |
---|
51 | TEncSbac::TEncSbac() |
---|
52 | // new structure here |
---|
53 | : m_pcBitIf ( NULL ) |
---|
54 | , m_pcSlice ( NULL ) |
---|
55 | , m_pcBinIf ( NULL ) |
---|
56 | , m_uiCoeffCost ( 0 ) |
---|
57 | , m_numContextModels ( 0 ) |
---|
58 | , m_cCUSplitFlagSCModel ( 1, 1, NUM_SPLIT_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels ) |
---|
59 | , m_cCUSkipFlagSCModel ( 1, 1, NUM_SKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
60 | , m_cCUMergeFlagExtSCModel ( 1, 1, NUM_MERGE_FLAG_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
61 | , m_cCUMergeIdxExtSCModel ( 1, 1, NUM_MERGE_IDX_EXT_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
62 | , m_cCUPartSizeSCModel ( 1, 1, NUM_PART_SIZE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
63 | , m_cCUPredModeSCModel ( 1, 1, NUM_PRED_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
64 | , m_cCUIntraPredSCModel ( 1, 1, NUM_ADI_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
65 | , m_cCUChromaPredSCModel ( 1, 1, NUM_CHROMA_PRED_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
66 | , m_cCUDeltaQpSCModel ( 1, 1, NUM_DELTA_QP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
67 | , m_cCUInterDirSCModel ( 1, 1, NUM_INTER_DIR_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
68 | , m_cCURefPicSCModel ( 1, 1, NUM_REF_NO_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
69 | , m_cCUMvdSCModel ( 1, 1, NUM_MV_RES_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
70 | , m_cCUQtCbfSCModel ( 1, 2, NUM_QT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
71 | , m_cCUTransSubdivFlagSCModel ( 1, 1, NUM_TRANS_SUBDIV_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
72 | , m_cCUQtRootCbfSCModel ( 1, 1, NUM_QT_ROOT_CBF_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
73 | , m_cCUSigCoeffGroupSCModel ( 1, 2, NUM_SIG_CG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
74 | , m_cCUSigSCModel ( 1, 1, NUM_SIG_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
75 | , m_cCuCtxLastX ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
76 | , m_cCuCtxLastY ( 1, 2, NUM_CTX_LAST_FLAG_XY , m_contextModels + m_numContextModels, m_numContextModels) |
---|
77 | , m_cCUOneSCModel ( 1, 1, NUM_ONE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
78 | , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
79 | , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
80 | , m_cCUAMPSCModel ( 1, 1, NUM_CU_AMP_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
81 | , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
82 | , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
83 | , m_cTransformSkipSCModel ( 1, 2, NUM_TRANSFORMSKIP_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
84 | , m_CUTransquantBypassFlagSCModel( 1, 1, NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels) |
---|
85 | #if H_3D_DIM |
---|
86 | , m_cDepthIntraModeSCModel ( 1, 1, NUM_DEPTH_INTRA_MODE_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
87 | , m_cDdcFlagSCModel ( 1, 1, NUM_DDC_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
88 | , m_cDdcDataSCModel ( 1, 1, NUM_DDC_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
89 | #if H_3D_DIM_DMM |
---|
90 | , m_cDmm1DataSCModel ( 1, 1, NUM_DMM1_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
91 | , m_cDmm2DataSCModel ( 1, 1, NUM_DMM2_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
92 | , m_cDmm3DataSCModel ( 1, 1, NUM_DMM3_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
93 | #endif |
---|
94 | #if H_3D_DIM_RBC |
---|
95 | , m_cRbcDataSCModel ( 1, 1, NUM_RBC_DATA_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
96 | #endif |
---|
97 | #if H_3D_DIM_SDC |
---|
98 | , m_cSDCResidualFlagSCModel ( 1, 1, SDC_NUM_RESIDUAL_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
99 | , m_cSDCResidualSCModel ( 1, 1, SDC_NUM_RESIDUAL_CTX , m_contextModels + m_numContextModels, m_numContextModels) |
---|
100 | #endif |
---|
101 | #endif |
---|
102 | { |
---|
103 | assert( m_numContextModels <= MAX_NUM_CTX_MOD ); |
---|
104 | } |
---|
105 | |
---|
106 | TEncSbac::~TEncSbac() |
---|
107 | { |
---|
108 | } |
---|
109 | |
---|
110 | // ==================================================================================================================== |
---|
111 | // Public member functions |
---|
112 | // ==================================================================================================================== |
---|
113 | |
---|
114 | Void TEncSbac::resetEntropy () |
---|
115 | { |
---|
116 | Int iQp = m_pcSlice->getSliceQp(); |
---|
117 | SliceType eSliceType = m_pcSlice->getSliceType(); |
---|
118 | |
---|
119 | Int encCABACTableIdx = m_pcSlice->getPPS()->getEncCABACTableIdx(); |
---|
120 | if (!m_pcSlice->isIntra() && (encCABACTableIdx==B_SLICE || encCABACTableIdx==P_SLICE) && m_pcSlice->getPPS()->getCabacInitPresentFlag()) |
---|
121 | { |
---|
122 | eSliceType = (SliceType) encCABACTableIdx; |
---|
123 | } |
---|
124 | |
---|
125 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
126 | |
---|
127 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
128 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
129 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
130 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
131 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
132 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
133 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
134 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
135 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
136 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
137 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
138 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
139 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
140 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
141 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
142 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
143 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
144 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
145 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
146 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
147 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
148 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
149 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
150 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
151 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
152 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
153 | |
---|
154 | #if H_3D_DIM |
---|
155 | m_cDepthIntraModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE ); |
---|
156 | m_cDdcFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG ); |
---|
157 | m_cDdcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_DATA ); |
---|
158 | #if H_3D_DIM_DMM |
---|
159 | m_cDmm1DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA ); |
---|
160 | m_cDmm2DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA ); |
---|
161 | m_cDmm3DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA ); |
---|
162 | #endif |
---|
163 | #if H_3D_DIM_RBC |
---|
164 | m_cRbcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RBC_DATA ); |
---|
165 | #endif |
---|
166 | #if H_3D_DIM_SDC |
---|
167 | m_cSDCResidualFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG ); |
---|
168 | m_cSDCResidualSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL ); |
---|
169 | #endif |
---|
170 | #endif |
---|
171 | // new structure |
---|
172 | m_uiLastQp = iQp; |
---|
173 | |
---|
174 | m_pcBinIf->start(); |
---|
175 | |
---|
176 | return; |
---|
177 | } |
---|
178 | |
---|
179 | /** The function does the following: |
---|
180 | * If current slice type is P/B then it determines the distance of initialisation type 1 and 2 from the current CABAC states and |
---|
181 | * stores the index of the closest table. This index is used for the next P/B slice when cabac_init_present_flag is true. |
---|
182 | */ |
---|
183 | Void TEncSbac::determineCabacInitIdx() |
---|
184 | { |
---|
185 | Int qp = m_pcSlice->getSliceQp(); |
---|
186 | |
---|
187 | if (!m_pcSlice->isIntra()) |
---|
188 | { |
---|
189 | SliceType aSliceTypeChoices[] = {B_SLICE, P_SLICE}; |
---|
190 | |
---|
191 | UInt bestCost = MAX_UINT; |
---|
192 | SliceType bestSliceType = aSliceTypeChoices[0]; |
---|
193 | for (UInt idx=0; idx<2; idx++) |
---|
194 | { |
---|
195 | UInt curCost = 0; |
---|
196 | SliceType curSliceType = aSliceTypeChoices[idx]; |
---|
197 | |
---|
198 | curCost = m_cCUSplitFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG ); |
---|
199 | curCost += m_cCUSkipFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG ); |
---|
200 | curCost += m_cCUMergeFlagExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
201 | curCost += m_cCUMergeIdxExtSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
202 | curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); |
---|
203 | curCost += m_cCUAMPSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_AMP_POS ); |
---|
204 | curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); |
---|
205 | curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
206 | curCost += m_cCUChromaPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
207 | curCost += m_cCUInterDirSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTER_DIR ); |
---|
208 | curCost += m_cCUMvdSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVD ); |
---|
209 | curCost += m_cCURefPicSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_REF_PIC ); |
---|
210 | curCost += m_cCUDeltaQpSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DQP ); |
---|
211 | curCost += m_cCUQtCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_CBF ); |
---|
212 | curCost += m_cCUQtRootCbfSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
213 | curCost += m_cCUSigCoeffGroupSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
214 | curCost += m_cCUSigSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SIG_FLAG ); |
---|
215 | curCost += m_cCuCtxLastX.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
216 | curCost += m_cCuCtxLastY.calcCost ( curSliceType, qp, (UChar*)INIT_LAST ); |
---|
217 | curCost += m_cCUOneSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ONE_FLAG ); |
---|
218 | curCost += m_cCUAbsSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_ABS_FLAG ); |
---|
219 | curCost += m_cMVPIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_MVP_IDX ); |
---|
220 | curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
221 | curCost += m_cSaoMergeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
222 | curCost += m_cSaoTypeIdxSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
223 | curCost += m_cTransformSkipSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
224 | curCost += m_CUTransquantBypassFlagSCModel.calcCost( curSliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
225 | #if H_3D_DIM |
---|
226 | if( m_pcSlice->getVpsDepthModesFlag() ) |
---|
227 | { |
---|
228 | curCost += m_cDepthIntraModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DEPTH_INTRA_MODE ); |
---|
229 | curCost += m_cDdcFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DDC_FLAG ); |
---|
230 | curCost += m_cDdcDataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DDC_DATA ); |
---|
231 | #if H_3D_DIM_DMM |
---|
232 | curCost += m_cDmm1DataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM1_DATA ); |
---|
233 | curCost += m_cDmm2DataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM2_DATA ); |
---|
234 | curCost += m_cDmm3DataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_DMM3_DATA ); |
---|
235 | #endif |
---|
236 | #if H_3D_DIM_RBC |
---|
237 | curCost += m_cRbcDataSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_RBC_DATA ); |
---|
238 | #endif |
---|
239 | } |
---|
240 | #endif |
---|
241 | if (curCost < bestCost) |
---|
242 | { |
---|
243 | bestSliceType = curSliceType; |
---|
244 | bestCost = curCost; |
---|
245 | } |
---|
246 | } |
---|
247 | m_pcSlice->getPPS()->setEncCABACTableIdx( bestSliceType ); |
---|
248 | } |
---|
249 | else |
---|
250 | { |
---|
251 | m_pcSlice->getPPS()->setEncCABACTableIdx( I_SLICE ); |
---|
252 | } |
---|
253 | } |
---|
254 | |
---|
255 | |
---|
256 | /** The function does the followng: Write out terminate bit. Flush CABAC. Intialize CABAC states. Start CABAC. |
---|
257 | */ |
---|
258 | Void TEncSbac::updateContextTables( SliceType eSliceType, Int iQp, Bool bExecuteFinish ) |
---|
259 | { |
---|
260 | m_pcBinIf->encodeBinTrm(1); |
---|
261 | if (bExecuteFinish) m_pcBinIf->finish(); |
---|
262 | m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); |
---|
263 | |
---|
264 | m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); |
---|
265 | m_cCUMergeFlagExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT); |
---|
266 | m_cCUMergeIdxExtSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT); |
---|
267 | m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); |
---|
268 | m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS ); |
---|
269 | m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); |
---|
270 | m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); |
---|
271 | m_cCUChromaPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CHROMA_PRED_MODE ); |
---|
272 | m_cCUInterDirSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTER_DIR ); |
---|
273 | m_cCUMvdSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVD ); |
---|
274 | m_cCURefPicSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_REF_PIC ); |
---|
275 | m_cCUDeltaQpSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DQP ); |
---|
276 | m_cCUQtCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_CBF ); |
---|
277 | m_cCUQtRootCbfSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_QT_ROOT_CBF ); |
---|
278 | m_cCUSigCoeffGroupSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_CG_FLAG ); |
---|
279 | m_cCUSigSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SIG_FLAG ); |
---|
280 | m_cCuCtxLastX.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
281 | m_cCuCtxLastY.initBuffer ( eSliceType, iQp, (UChar*)INIT_LAST ); |
---|
282 | m_cCUOneSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ONE_FLAG ); |
---|
283 | m_cCUAbsSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG ); |
---|
284 | m_cMVPIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_MVP_IDX ); |
---|
285 | m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG ); |
---|
286 | m_cSaoMergeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG ); |
---|
287 | m_cSaoTypeIdxSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX ); |
---|
288 | m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); |
---|
289 | m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); |
---|
290 | |
---|
291 | #if H_3D_DIM |
---|
292 | m_cDepthIntraModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE ); |
---|
293 | m_cDdcFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_FLAG ); |
---|
294 | m_cDdcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DDC_DATA ); |
---|
295 | #if H_3D_DIM_DMM |
---|
296 | m_cDmm1DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA ); |
---|
297 | m_cDmm2DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA ); |
---|
298 | m_cDmm3DataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA ); |
---|
299 | #endif |
---|
300 | #if H_3D_DIM_RBC |
---|
301 | m_cRbcDataSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_RBC_DATA ); |
---|
302 | #endif |
---|
303 | #if H_3D_DIM_SDC |
---|
304 | m_cSDCResidualFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG ); |
---|
305 | m_cSDCResidualSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL ); |
---|
306 | #endif |
---|
307 | #endif |
---|
308 | m_pcBinIf->start(); |
---|
309 | } |
---|
310 | |
---|
311 | Void TEncSbac::codeVPS( TComVPS* pcVPS ) |
---|
312 | { |
---|
313 | assert (0); |
---|
314 | return; |
---|
315 | } |
---|
316 | |
---|
317 | #if H_3D |
---|
318 | Void TEncSbac::codeSPS( TComSPS* pcSPS, Int viewIndex, Bool depthFlag ) |
---|
319 | #else |
---|
320 | Void TEncSbac::codeSPS( TComSPS* pcSPS ) |
---|
321 | #endif |
---|
322 | { |
---|
323 | assert (0); |
---|
324 | return; |
---|
325 | } |
---|
326 | |
---|
327 | Void TEncSbac::codePPS( TComPPS* pcPPS ) |
---|
328 | { |
---|
329 | assert (0); |
---|
330 | return; |
---|
331 | } |
---|
332 | |
---|
333 | Void TEncSbac::codeSliceHeader( TComSlice* pcSlice ) |
---|
334 | { |
---|
335 | assert (0); |
---|
336 | return; |
---|
337 | } |
---|
338 | |
---|
339 | Void TEncSbac::codeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
340 | { |
---|
341 | assert (0); |
---|
342 | return; |
---|
343 | } |
---|
344 | |
---|
345 | Void TEncSbac::codeTerminatingBit( UInt uilsLast ) |
---|
346 | { |
---|
347 | m_pcBinIf->encodeBinTrm( uilsLast ); |
---|
348 | } |
---|
349 | |
---|
350 | Void TEncSbac::codeSliceFinish() |
---|
351 | { |
---|
352 | m_pcBinIf->finish(); |
---|
353 | } |
---|
354 | |
---|
355 | Void TEncSbac::xWriteUnarySymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ) |
---|
356 | { |
---|
357 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[0] ); |
---|
358 | |
---|
359 | if( 0 == uiSymbol) |
---|
360 | { |
---|
361 | return; |
---|
362 | } |
---|
363 | |
---|
364 | while( uiSymbol-- ) |
---|
365 | { |
---|
366 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ iOffset ] ); |
---|
367 | } |
---|
368 | |
---|
369 | return; |
---|
370 | } |
---|
371 | |
---|
372 | Void TEncSbac::xWriteUnaryMaxSymbol( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ) |
---|
373 | { |
---|
374 | if (uiMaxSymbol == 0) |
---|
375 | { |
---|
376 | return; |
---|
377 | } |
---|
378 | |
---|
379 | m_pcBinIf->encodeBin( uiSymbol ? 1 : 0, pcSCModel[ 0 ] ); |
---|
380 | |
---|
381 | if ( uiSymbol == 0 ) |
---|
382 | { |
---|
383 | return; |
---|
384 | } |
---|
385 | |
---|
386 | Bool bCodeLast = ( uiMaxSymbol > uiSymbol ); |
---|
387 | |
---|
388 | while( --uiSymbol ) |
---|
389 | { |
---|
390 | m_pcBinIf->encodeBin( 1, pcSCModel[ iOffset ] ); |
---|
391 | } |
---|
392 | if( bCodeLast ) |
---|
393 | { |
---|
394 | m_pcBinIf->encodeBin( 0, pcSCModel[ iOffset ] ); |
---|
395 | } |
---|
396 | |
---|
397 | return; |
---|
398 | } |
---|
399 | |
---|
400 | Void TEncSbac::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount ) |
---|
401 | { |
---|
402 | UInt bins = 0; |
---|
403 | Int numBins = 0; |
---|
404 | |
---|
405 | while( uiSymbol >= (UInt)(1<<uiCount) ) |
---|
406 | { |
---|
407 | bins = 2 * bins + 1; |
---|
408 | numBins++; |
---|
409 | uiSymbol -= 1 << uiCount; |
---|
410 | uiCount ++; |
---|
411 | } |
---|
412 | bins = 2 * bins + 0; |
---|
413 | numBins++; |
---|
414 | |
---|
415 | bins = (bins << uiCount) | uiSymbol; |
---|
416 | numBins += uiCount; |
---|
417 | |
---|
418 | assert( numBins <= 32 ); |
---|
419 | m_pcBinIf->encodeBinsEP( bins, numBins ); |
---|
420 | } |
---|
421 | |
---|
422 | /** Coding of coeff_abs_level_minus3 |
---|
423 | * \param uiSymbol value of coeff_abs_level_minus3 |
---|
424 | * \param ruiGoRiceParam reference to Rice parameter |
---|
425 | * \returns Void |
---|
426 | */ |
---|
427 | Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam ) |
---|
428 | { |
---|
429 | Int codeNumber = (Int)symbol; |
---|
430 | UInt length; |
---|
431 | if (codeNumber < (COEF_REMAIN_BIN_REDUCTION << rParam)) |
---|
432 | { |
---|
433 | length = codeNumber>>rParam; |
---|
434 | m_pcBinIf->encodeBinsEP( (1<<(length+1))-2 , length+1); |
---|
435 | m_pcBinIf->encodeBinsEP((codeNumber%(1<<rParam)),rParam); |
---|
436 | } |
---|
437 | else |
---|
438 | { |
---|
439 | length = rParam; |
---|
440 | codeNumber = codeNumber - ( COEF_REMAIN_BIN_REDUCTION << rParam); |
---|
441 | while (codeNumber >= (1<<length)) |
---|
442 | { |
---|
443 | codeNumber -= (1<<(length++)); |
---|
444 | } |
---|
445 | m_pcBinIf->encodeBinsEP((1<<(COEF_REMAIN_BIN_REDUCTION+length+1-rParam))-2,COEF_REMAIN_BIN_REDUCTION+length+1-rParam); |
---|
446 | m_pcBinIf->encodeBinsEP(codeNumber,length); |
---|
447 | } |
---|
448 | } |
---|
449 | |
---|
450 | #if H_3D_DIM |
---|
451 | Void TEncSbac::xWriteExGolombLevel( UInt uiSymbol, ContextModel& rcSCModel ) |
---|
452 | { |
---|
453 | if( uiSymbol ) |
---|
454 | { |
---|
455 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
456 | UInt uiCount = 0; |
---|
457 | Bool bNoExGo = (uiSymbol < 13); |
---|
458 | |
---|
459 | while( --uiSymbol && ++uiCount < 13 ) |
---|
460 | { |
---|
461 | m_pcBinIf->encodeBin( 1, rcSCModel ); |
---|
462 | } |
---|
463 | if( bNoExGo ) |
---|
464 | { |
---|
465 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
466 | } |
---|
467 | else |
---|
468 | { |
---|
469 | xWriteEpExGolomb( uiSymbol, 0 ); |
---|
470 | } |
---|
471 | } |
---|
472 | else |
---|
473 | { |
---|
474 | m_pcBinIf->encodeBin( 0, rcSCModel ); |
---|
475 | } |
---|
476 | |
---|
477 | return; |
---|
478 | } |
---|
479 | |
---|
480 | Void TEncSbac::xCodeDimDeltaDC( Pel valDeltaDC, UInt dimType ) |
---|
481 | { |
---|
482 | xWriteExGolombLevel( UInt( abs( valDeltaDC ) ), m_cDdcDataSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) ); |
---|
483 | if( valDeltaDC != 0 ) |
---|
484 | { |
---|
485 | UInt uiSign = valDeltaDC > 0 ? 0 : 1; |
---|
486 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
487 | } |
---|
488 | } |
---|
489 | |
---|
490 | #if H_3D_DIM_DMM |
---|
491 | Void TEncSbac::xCodeDmm1WedgeIdx( UInt uiTabIdx, Int iNumBit ) |
---|
492 | { |
---|
493 | for ( Int i = 0; i < iNumBit; i++ ) |
---|
494 | { |
---|
495 | m_pcBinIf->encodeBin( ( uiTabIdx >> i ) & 1, m_cDmm1DataSCModel.get(0, 0, 0) ); |
---|
496 | } |
---|
497 | } |
---|
498 | |
---|
499 | Void TEncSbac::xCodeDmm2Offset( Int iOffset ) |
---|
500 | { |
---|
501 | if( DMM2_DELTAEND_MAX > 0 ) |
---|
502 | { |
---|
503 | m_pcBinIf->encodeBin( (iOffset != 0) , m_cDmm2DataSCModel.get(0, 0, 0) ); |
---|
504 | if( iOffset != 0 ) |
---|
505 | { |
---|
506 | UInt uiAbsValMinus1 = abs(iOffset)-1; |
---|
507 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01), m_cDmm2DataSCModel.get(0, 0, 0) ); |
---|
508 | m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cDmm2DataSCModel.get(0, 0, 0) ); |
---|
509 | |
---|
510 | UInt uiSign = (iOffset > 0) ? 0 : 1; |
---|
511 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
512 | } |
---|
513 | } |
---|
514 | } |
---|
515 | |
---|
516 | Void TEncSbac::xCodeDmm3WedgeIdx( UInt uiIntraIdx, Int iNumBit ) |
---|
517 | { |
---|
518 | for( Int i = 0; i < iNumBit; i++ ) |
---|
519 | { |
---|
520 | m_pcBinIf->encodeBin( ( uiIntraIdx >> i ) & 1, m_cDmm3DataSCModel.get(0, 0, 0) ); |
---|
521 | } |
---|
522 | } |
---|
523 | #endif |
---|
524 | #if H_3D_DIM_RBC |
---|
525 | Void TEncSbac::xCodeRbcEdge( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
526 | { |
---|
527 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ) + (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 1 : 0); |
---|
528 | UChar* pucSymbolList = pcCU->getEdgeCode ( uiAbsPartIdx ); |
---|
529 | UChar ucEdgeNumber = pcCU->getEdgeNumber ( uiAbsPartIdx ); |
---|
530 | Bool bLeft = pcCU->getEdgeLeftFirst( uiAbsPartIdx ); |
---|
531 | UChar ucStart = pcCU->getEdgeStartPos ( uiAbsPartIdx ); |
---|
532 | UInt uiSymbol; |
---|
533 | |
---|
534 | // 1. Top(0) or Left(1) |
---|
535 | uiSymbol = (bLeft == false) ? 0 : 1; |
---|
536 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
537 | |
---|
538 | // 2. Start position (lowest bit first) |
---|
539 | uiSymbol = ucStart; |
---|
540 | for( UInt ui = 6; ui > uiDepth; ui-- ) // 64(0)->6, 32(1)->5, 16(2)->4, 8(3)->3, 4(4)->2 |
---|
541 | { |
---|
542 | m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); |
---|
543 | uiSymbol >>= 1; |
---|
544 | } |
---|
545 | |
---|
546 | // 3. Number of edges |
---|
547 | uiSymbol = ucEdgeNumber > 0 ? ucEdgeNumber - 1 : 0; |
---|
548 | for( UInt ui = 7; ui > uiDepth; ui-- ) // 64(0)->7, 32(1)->6, 16(2)->5, 8(3)->4, 4(4)->3 |
---|
549 | { |
---|
550 | m_pcBinIf->encodeBinEP( uiSymbol & 0x1 ); |
---|
551 | uiSymbol >>= 1; |
---|
552 | } |
---|
553 | |
---|
554 | if(uiSymbol != 0) |
---|
555 | { |
---|
556 | printf(" ucEdgeNumber %d at depth %d\n",ucEdgeNumber, uiDepth); |
---|
557 | assert(false); |
---|
558 | } |
---|
559 | |
---|
560 | // 4. Edges |
---|
561 | for( Int iPtr2 = 0; iPtr2 < ucEdgeNumber; iPtr2++ ) |
---|
562 | { |
---|
563 | UInt uiReorderSymbol = pucSymbolList[iPtr2]; |
---|
564 | for( UInt ui = 0; ui < uiReorderSymbol; ui++ ) |
---|
565 | { |
---|
566 | m_pcBinIf->encodeBin( 1, m_cRbcDataSCModel.get( 0, 0, 0 ) ); |
---|
567 | } |
---|
568 | |
---|
569 | if( uiReorderSymbol != 6 ) |
---|
570 | m_pcBinIf->encodeBin( 0, m_cRbcDataSCModel.get( 0, 0, 0 ) ); |
---|
571 | } |
---|
572 | } |
---|
573 | #endif |
---|
574 | #if H_3D_DIM_SDC |
---|
575 | Void TEncSbac::xCodeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ) |
---|
576 | { |
---|
577 | assert( pcCU->getSlice()->getIsDepth() ); |
---|
578 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
579 | assert( pcCU->getSDCFlag(uiAbsPartIdx) ); |
---|
580 | assert( uiSegment < 2 ); |
---|
581 | |
---|
582 | Pel segmentDCOffset = pcCU->getSDCSegmentDCOffset(uiSegment, uiAbsPartIdx); |
---|
583 | |
---|
584 | UInt uiResidual = segmentDCOffset == 0 ? 0 : 1; |
---|
585 | UInt uiSign = segmentDCOffset < 0 ? 1 : 0; |
---|
586 | UInt uiAbsIdx = abs(segmentDCOffset); |
---|
587 | |
---|
588 | #if H_3D_DIM_DLT |
---|
589 | UInt uiMaxResidualBits = pcCU->getSlice()->getVPS()->getBitsPerDepthValue( pcCU->getSlice()->getLayerIdInVps() ); |
---|
590 | #else |
---|
591 | UInt uiMaxResidualBits = g_bitDepthY; |
---|
592 | #endif |
---|
593 | assert( uiMaxResidualBits <= g_bitDepthY ); |
---|
594 | |
---|
595 | // residual flag |
---|
596 | m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) ); |
---|
597 | |
---|
598 | if (uiResidual) |
---|
599 | { |
---|
600 | // encode sign bit of residual |
---|
601 | m_pcBinIf->encodeBinEP( uiSign ); |
---|
602 | |
---|
603 | #if H_3D_DIM_DLT |
---|
604 | UInt uiNumDepthValues = pcCU->getSlice()->getVPS()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() ); |
---|
605 | #else |
---|
606 | UInt uiNumDepthValues = ((1 << g_bitDepthY)-1); |
---|
607 | #endif |
---|
608 | assert(uiAbsIdx <= uiNumDepthValues); |
---|
609 | |
---|
610 | // encode residual magnitude |
---|
611 | uiAbsIdx -= 1; |
---|
612 | // prefix part |
---|
613 | if ( uiAbsIdx == 0 ) |
---|
614 | m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) ); |
---|
615 | else |
---|
616 | { |
---|
617 | UInt l = uiAbsIdx; |
---|
618 | UInt k = 0; |
---|
619 | UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2); |
---|
620 | while ( l > 0 && k < uiPrefixThreshold ) |
---|
621 | { |
---|
622 | m_pcBinIf->encodeBin( 1, m_cSDCResidualSCModel.get(0, 0, 0) ); |
---|
623 | l--; |
---|
624 | k++; |
---|
625 | } |
---|
626 | if ( uiAbsIdx < uiPrefixThreshold ) |
---|
627 | m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) ); |
---|
628 | // suffix part |
---|
629 | else |
---|
630 | { |
---|
631 | uiAbsIdx -= uiPrefixThreshold; |
---|
632 | UInt uiSuffixLength = ( (UInt)ceil( Log2(uiNumDepthValues - uiPrefixThreshold) ) ); |
---|
633 | UInt uiBitInfo = 0; |
---|
634 | for ( Int i = 0; i < uiSuffixLength; i++) |
---|
635 | { |
---|
636 | uiBitInfo = ( uiAbsIdx & ( 1 << i ) ) >> i; |
---|
637 | m_pcBinIf->encodeBinEP( uiBitInfo); |
---|
638 | } |
---|
639 | } |
---|
640 | } |
---|
641 | |
---|
642 | } |
---|
643 | } |
---|
644 | #endif |
---|
645 | #endif |
---|
646 | |
---|
647 | // SBAC RD |
---|
648 | Void TEncSbac::load ( TEncSbac* pSrc) |
---|
649 | { |
---|
650 | this->xCopyFrom(pSrc); |
---|
651 | } |
---|
652 | |
---|
653 | Void TEncSbac::loadIntraDirModeLuma( TEncSbac* pSrc) |
---|
654 | { |
---|
655 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
656 | |
---|
657 | this->m_cCUIntraPredSCModel .copyFrom( &pSrc->m_cCUIntraPredSCModel ); |
---|
658 | } |
---|
659 | #if H_3D_DIM |
---|
660 | Void TEncSbac::loadIntraDepthMode( TEncSbac* pSrc) |
---|
661 | { |
---|
662 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
663 | |
---|
664 | this->m_cDepthIntraModeSCModel .copyFrom( &pSrc->m_cDepthIntraModeSCModel ); |
---|
665 | this->m_cDdcFlagSCModel .copyFrom( &pSrc->m_cDdcFlagSCModel ); |
---|
666 | } |
---|
667 | #endif |
---|
668 | |
---|
669 | Void TEncSbac::store( TEncSbac* pDest) |
---|
670 | { |
---|
671 | pDest->xCopyFrom( this ); |
---|
672 | } |
---|
673 | |
---|
674 | |
---|
675 | Void TEncSbac::xCopyFrom( TEncSbac* pSrc ) |
---|
676 | { |
---|
677 | m_pcBinIf->copyState( pSrc->m_pcBinIf ); |
---|
678 | |
---|
679 | this->m_uiCoeffCost = pSrc->m_uiCoeffCost; |
---|
680 | this->m_uiLastQp = pSrc->m_uiLastQp; |
---|
681 | |
---|
682 | memcpy( m_contextModels, pSrc->m_contextModels, m_numContextModels * sizeof( ContextModel ) ); |
---|
683 | } |
---|
684 | |
---|
685 | Void TEncSbac::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
686 | { |
---|
687 | Int iSymbol = pcCU->getMVPIdx(eRefList, uiAbsPartIdx); |
---|
688 | Int iNum = AMVP_MAX_NUM_CANDS; |
---|
689 | |
---|
690 | xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum-1); |
---|
691 | } |
---|
692 | |
---|
693 | Void TEncSbac::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
694 | { |
---|
695 | PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
696 | if ( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
697 | { |
---|
698 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
699 | { |
---|
700 | m_pcBinIf->encodeBin( eSize == SIZE_2Nx2N? 1 : 0, m_cCUPartSizeSCModel.get( 0, 0, 0 ) ); |
---|
701 | } |
---|
702 | return; |
---|
703 | } |
---|
704 | |
---|
705 | switch(eSize) |
---|
706 | { |
---|
707 | case SIZE_2Nx2N: |
---|
708 | { |
---|
709 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
710 | break; |
---|
711 | } |
---|
712 | case SIZE_2NxN: |
---|
713 | case SIZE_2NxnU: |
---|
714 | case SIZE_2NxnD: |
---|
715 | { |
---|
716 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
717 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
718 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
719 | { |
---|
720 | if (eSize == SIZE_2NxN) |
---|
721 | { |
---|
722 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
723 | } |
---|
724 | else |
---|
725 | { |
---|
726 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
727 | m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); |
---|
728 | } |
---|
729 | } |
---|
730 | break; |
---|
731 | } |
---|
732 | case SIZE_Nx2N: |
---|
733 | case SIZE_nLx2N: |
---|
734 | case SIZE_nRx2N: |
---|
735 | { |
---|
736 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
737 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
738 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
739 | { |
---|
740 | m_pcBinIf->encodeBin( 1, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
741 | } |
---|
742 | if ( pcCU->getSlice()->getSPS()->getAMPAcc( uiDepth ) ) |
---|
743 | { |
---|
744 | if (eSize == SIZE_Nx2N) |
---|
745 | { |
---|
746 | m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
747 | } |
---|
748 | else |
---|
749 | { |
---|
750 | m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 )); |
---|
751 | m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); |
---|
752 | } |
---|
753 | } |
---|
754 | break; |
---|
755 | } |
---|
756 | case SIZE_NxN: |
---|
757 | { |
---|
758 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && !( pcCU->getWidth(uiAbsPartIdx) == 8 && pcCU->getHeight(uiAbsPartIdx) == 8 ) ) |
---|
759 | { |
---|
760 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 0) ); |
---|
761 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 1) ); |
---|
762 | m_pcBinIf->encodeBin( 0, m_cCUPartSizeSCModel.get( 0, 0, 2) ); |
---|
763 | } |
---|
764 | break; |
---|
765 | } |
---|
766 | default: |
---|
767 | { |
---|
768 | assert(0); |
---|
769 | } |
---|
770 | } |
---|
771 | } |
---|
772 | |
---|
773 | /** code prediction mode |
---|
774 | * \param pcCU |
---|
775 | * \param uiAbsPartIdx |
---|
776 | * \returns Void |
---|
777 | */ |
---|
778 | Void TEncSbac::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
779 | { |
---|
780 | #if H_3D_DIM_SDC |
---|
781 | if ( pcCU->getSlice()->isIntra() ) |
---|
782 | { |
---|
783 | assert( pcCU->isIntra(uiAbsPartIdx) ); |
---|
784 | return; |
---|
785 | } |
---|
786 | #endif |
---|
787 | |
---|
788 | // get context function is here |
---|
789 | Int iPredMode = pcCU->getPredictionMode( uiAbsPartIdx ); |
---|
790 | m_pcBinIf->encodeBin( iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get( 0, 0, 0 ) ); |
---|
791 | } |
---|
792 | |
---|
793 | Void TEncSbac::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
794 | { |
---|
795 | UInt uiSymbol = pcCU->getCUTransquantBypass(uiAbsPartIdx); |
---|
796 | m_pcBinIf->encodeBin( uiSymbol, m_CUTransquantBypassFlagSCModel.get( 0, 0, 0 ) ); |
---|
797 | } |
---|
798 | |
---|
799 | /** code skip flag |
---|
800 | * \param pcCU |
---|
801 | * \param uiAbsPartIdx |
---|
802 | * \returns Void |
---|
803 | */ |
---|
804 | Void TEncSbac::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
805 | { |
---|
806 | // get context function is here |
---|
807 | UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0; |
---|
808 | UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ; |
---|
809 | m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) ); |
---|
810 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
811 | DTRACE_CABAC_T( "\tSkipFlag" ); |
---|
812 | DTRACE_CABAC_T( "\tuiCtxSkip: "); |
---|
813 | DTRACE_CABAC_V( uiCtxSkip ); |
---|
814 | DTRACE_CABAC_T( "\tuiSymbol: "); |
---|
815 | DTRACE_CABAC_V( uiSymbol ); |
---|
816 | DTRACE_CABAC_T( "\n"); |
---|
817 | } |
---|
818 | |
---|
819 | /** code merge flag |
---|
820 | * \param pcCU |
---|
821 | * \param uiAbsPartIdx |
---|
822 | * \returns Void |
---|
823 | */ |
---|
824 | Void TEncSbac::codeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
825 | { |
---|
826 | const UInt uiSymbol = pcCU->getMergeFlag( uiAbsPartIdx ) ? 1 : 0; |
---|
827 | m_pcBinIf->encodeBin( uiSymbol, *m_cCUMergeFlagExtSCModel.get( 0 ) ); |
---|
828 | |
---|
829 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
830 | DTRACE_CABAC_T( "\tMergeFlag: " ); |
---|
831 | DTRACE_CABAC_V( uiSymbol ); |
---|
832 | DTRACE_CABAC_T( "\tAddress: " ); |
---|
833 | DTRACE_CABAC_V( pcCU->getAddr() ); |
---|
834 | DTRACE_CABAC_T( "\tuiAbsPartIdx: " ); |
---|
835 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
836 | DTRACE_CABAC_T( "\n" ); |
---|
837 | } |
---|
838 | |
---|
839 | /** code merge index |
---|
840 | * \param pcCU |
---|
841 | * \param uiAbsPartIdx |
---|
842 | * \returns Void |
---|
843 | */ |
---|
844 | Void TEncSbac::codeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
845 | { |
---|
846 | UInt uiUnaryIdx = pcCU->getMergeIndex( uiAbsPartIdx ); |
---|
847 | UInt uiNumCand = pcCU->getSlice()->getMaxNumMergeCand(); |
---|
848 | if ( uiNumCand > 1 ) |
---|
849 | { |
---|
850 | for( UInt ui = 0; ui < uiNumCand - 1; ++ui ) |
---|
851 | { |
---|
852 | const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1; |
---|
853 | if ( ui==0 ) |
---|
854 | { |
---|
855 | m_pcBinIf->encodeBin( uiSymbol, m_cCUMergeIdxExtSCModel.get( 0, 0, 0 ) ); |
---|
856 | } |
---|
857 | else |
---|
858 | { |
---|
859 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
860 | } |
---|
861 | if( uiSymbol == 0 ) |
---|
862 | { |
---|
863 | break; |
---|
864 | } |
---|
865 | } |
---|
866 | } |
---|
867 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
868 | DTRACE_CABAC_T( "\tparseMergeIndex()" ); |
---|
869 | DTRACE_CABAC_T( "\tuiMRGIdx= " ); |
---|
870 | DTRACE_CABAC_V( pcCU->getMergeIndex( uiAbsPartIdx ) ); |
---|
871 | DTRACE_CABAC_T( "\n" ); |
---|
872 | } |
---|
873 | |
---|
874 | Void TEncSbac::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
875 | { |
---|
876 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
877 | return; |
---|
878 | |
---|
879 | UInt uiCtx = pcCU->getCtxSplitFlag( uiAbsPartIdx, uiDepth ); |
---|
880 | UInt uiCurrSplitFlag = ( pcCU->getDepth( uiAbsPartIdx ) > uiDepth ) ? 1 : 0; |
---|
881 | |
---|
882 | assert( uiCtx < 3 ); |
---|
883 | m_pcBinIf->encodeBin( uiCurrSplitFlag, m_cCUSplitFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
884 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
885 | DTRACE_CABAC_T( "\tSplitFlag\n" ) |
---|
886 | return; |
---|
887 | } |
---|
888 | |
---|
889 | Void TEncSbac::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
890 | { |
---|
891 | m_pcBinIf->encodeBin( uiSymbol, m_cCUTransSubdivFlagSCModel.get( 0, 0, uiCtx ) ); |
---|
892 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
893 | DTRACE_CABAC_T( "\tparseTransformSubdivFlag()" ) |
---|
894 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
895 | DTRACE_CABAC_V( uiSymbol ) |
---|
896 | DTRACE_CABAC_T( "\tctx=" ) |
---|
897 | DTRACE_CABAC_V( uiCtx ) |
---|
898 | DTRACE_CABAC_T( "\n" ) |
---|
899 | } |
---|
900 | |
---|
901 | Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple) |
---|
902 | { |
---|
903 | UInt dir[4],j; |
---|
904 | Int preds[4][3] = {{-1, -1, -1},{-1, -1, -1},{-1, -1, -1},{-1, -1, -1}}; |
---|
905 | Int predNum[4], predIdx[4] ={ -1,-1,-1,-1}; |
---|
906 | PartSize mode = pcCU->getPartitionSize( absPartIdx ); |
---|
907 | UInt partNum = isMultiple?(mode==SIZE_NxN?4:1):1; |
---|
908 | UInt partOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(absPartIdx) << 1 ) ) >> 2; |
---|
909 | for (j=0;j<partNum;j++) |
---|
910 | { |
---|
911 | dir[j] = pcCU->getLumaIntraDir( absPartIdx+partOffset*j ); |
---|
912 | #if H_3D_DIM |
---|
913 | if( pcCU->getSlice()->getVpsDepthModesFlag() ) |
---|
914 | { |
---|
915 | codeIntraDepth( pcCU, absPartIdx+partOffset*j ); |
---|
916 | } |
---|
917 | if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) |
---|
918 | #if H_3D_DIM_SDC |
---|
919 | if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) ) |
---|
920 | #endif |
---|
921 | { |
---|
922 | #endif |
---|
923 | predNum[j] = pcCU->getIntraDirLumaPredictor(absPartIdx+partOffset*j, preds[j]); |
---|
924 | for(UInt i = 0; i < predNum[j]; i++) |
---|
925 | { |
---|
926 | if(dir[j] == preds[j][i]) |
---|
927 | { |
---|
928 | predIdx[j] = i; |
---|
929 | } |
---|
930 | } |
---|
931 | m_pcBinIf->encodeBin((predIdx[j] != -1)? 1 : 0, m_cCUIntraPredSCModel.get( 0, 0, 0 ) ); |
---|
932 | #if H_3D_DIM |
---|
933 | } |
---|
934 | #endif |
---|
935 | } |
---|
936 | for (j=0;j<partNum;j++) |
---|
937 | { |
---|
938 | #if H_3D_DIM |
---|
939 | if( pcCU->getLumaIntraDir( absPartIdx+partOffset*j ) < NUM_INTRA_MODE ) |
---|
940 | #if H_3D_DIM_SDC |
---|
941 | if( !pcCU->getSDCFlag( absPartIdx+partOffset*j ) ) |
---|
942 | #endif |
---|
943 | { |
---|
944 | #endif |
---|
945 | if(predIdx[j] != -1) |
---|
946 | { |
---|
947 | m_pcBinIf->encodeBinEP( predIdx[j] ? 1 : 0 ); |
---|
948 | if (predIdx[j]) |
---|
949 | { |
---|
950 | m_pcBinIf->encodeBinEP( predIdx[j]-1 ); |
---|
951 | } |
---|
952 | } |
---|
953 | else |
---|
954 | { |
---|
955 | if (preds[j][0] > preds[j][1]) |
---|
956 | { |
---|
957 | std::swap(preds[j][0], preds[j][1]); |
---|
958 | } |
---|
959 | if (preds[j][0] > preds[j][2]) |
---|
960 | { |
---|
961 | std::swap(preds[j][0], preds[j][2]); |
---|
962 | } |
---|
963 | if (preds[j][1] > preds[j][2]) |
---|
964 | { |
---|
965 | std::swap(preds[j][1], preds[j][2]); |
---|
966 | } |
---|
967 | for(Int i = (predNum[j] - 1); i >= 0; i--) |
---|
968 | { |
---|
969 | dir[j] = dir[j] > preds[j][i] ? dir[j] - 1 : dir[j]; |
---|
970 | } |
---|
971 | m_pcBinIf->encodeBinsEP( dir[j], 5 ); |
---|
972 | } |
---|
973 | #if H_3D_DIM |
---|
974 | } |
---|
975 | #endif |
---|
976 | } |
---|
977 | return; |
---|
978 | } |
---|
979 | |
---|
980 | Void TEncSbac::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
981 | { |
---|
982 | UInt uiIntraDirChroma = pcCU->getChromaIntraDir( uiAbsPartIdx ); |
---|
983 | |
---|
984 | if( uiIntraDirChroma == DM_CHROMA_IDX ) |
---|
985 | { |
---|
986 | m_pcBinIf->encodeBin( 0, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
987 | } |
---|
988 | else |
---|
989 | { |
---|
990 | UInt uiAllowedChromaDir[ NUM_CHROMA_MODE ]; |
---|
991 | pcCU->getAllowedChromaDir( uiAbsPartIdx, uiAllowedChromaDir ); |
---|
992 | |
---|
993 | for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ ) |
---|
994 | { |
---|
995 | if( uiIntraDirChroma == uiAllowedChromaDir[i] ) |
---|
996 | { |
---|
997 | uiIntraDirChroma = i; |
---|
998 | break; |
---|
999 | } |
---|
1000 | } |
---|
1001 | m_pcBinIf->encodeBin( 1, m_cCUChromaPredSCModel.get( 0, 0, 0 ) ); |
---|
1002 | |
---|
1003 | m_pcBinIf->encodeBinsEP( uiIntraDirChroma, 2 ); |
---|
1004 | } |
---|
1005 | return; |
---|
1006 | } |
---|
1007 | |
---|
1008 | #if H_3D_DIM |
---|
1009 | Void TEncSbac::codeIntraDepth( TComDataCU* pcCU, UInt absPartIdx ) |
---|
1010 | { |
---|
1011 | codeIntraDepthMode( pcCU, absPartIdx ); |
---|
1012 | |
---|
1013 | UInt dir = pcCU->getLumaIntraDir( absPartIdx ); |
---|
1014 | UInt dimType = getDimType( dir ); |
---|
1015 | |
---|
1016 | switch( dimType ) |
---|
1017 | { |
---|
1018 | #if H_3D_DIM_DMM |
---|
1019 | case( DMM1_IDX ): |
---|
1020 | { |
---|
1021 | xCodeDmm1WedgeIdx( pcCU->getDmmWedgeTabIdx( dimType, absPartIdx ), g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] ); |
---|
1022 | } break; |
---|
1023 | case( DMM2_IDX ): |
---|
1024 | { |
---|
1025 | xCodeDmm2Offset( pcCU->getDmm2DeltaEnd( absPartIdx ) ); |
---|
1026 | } break; |
---|
1027 | case( DMM3_IDX ): |
---|
1028 | { |
---|
1029 | xCodeDmm3WedgeIdx( pcCU->getDmm3IntraTabIdx( absPartIdx ), g_dmm3IntraTabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] ); |
---|
1030 | } break; |
---|
1031 | case( DMM4_IDX ): break; |
---|
1032 | #endif |
---|
1033 | #if H_3D_DIM_RBC |
---|
1034 | case( RBC_IDX ): |
---|
1035 | { |
---|
1036 | assert( pcCU->getWidth( absPartIdx ) < 64 ); |
---|
1037 | xCodeRbcEdge( pcCU, absPartIdx ); |
---|
1038 | } break; |
---|
1039 | #endif |
---|
1040 | default: break; |
---|
1041 | } |
---|
1042 | |
---|
1043 | #if H_3D_DIM_SDC |
---|
1044 | if( pcCU->getSDCFlag( absPartIdx ) ) |
---|
1045 | { |
---|
1046 | assert(pcCU->getPartitionSize(absPartIdx)==SIZE_2Nx2N); |
---|
1047 | UInt uiNumSegments = ( dir == DC_IDX || dir == PLANAR_IDX )? 1 : 2; |
---|
1048 | for(UInt uiSeg=0; uiSeg<uiNumSegments; uiSeg++) |
---|
1049 | { |
---|
1050 | xCodeSDCResidualData(pcCU, absPartIdx, uiSeg); |
---|
1051 | } |
---|
1052 | } |
---|
1053 | else |
---|
1054 | { |
---|
1055 | #endif |
---|
1056 | if( dimType < DIM_NUM_TYPE ) |
---|
1057 | { |
---|
1058 | UInt dimDeltaDC = isDimDeltaDC( dir ); |
---|
1059 | m_pcBinIf->encodeBin( dimDeltaDC, m_cDdcFlagSCModel.get(0, 0, (RBC_IDX == dimType) ? 1 : 0) ); |
---|
1060 | if( dimDeltaDC ) |
---|
1061 | { |
---|
1062 | for( UInt segment = 0; segment < 2; segment++ ) |
---|
1063 | { |
---|
1064 | xCodeDimDeltaDC( pcCU->getDimDeltaDC( dimType, segment, absPartIdx ), dimType ); |
---|
1065 | } |
---|
1066 | } |
---|
1067 | } |
---|
1068 | #if H_3D_DIM_SDC |
---|
1069 | } |
---|
1070 | #endif |
---|
1071 | } |
---|
1072 | |
---|
1073 | Void TEncSbac::codeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx ) |
---|
1074 | { |
---|
1075 | UInt codeWordTable[3][9] = {{0, 0, 0, 2, 0,6, 0, 0, 7},{0, 2, 3, 4, 5, 6, 14, 31, 30},{0, 2, 0, 0, 0, 0, 3, 0, 0}}; |
---|
1076 | UInt codeWordLenTable[3][9] = {{0, 1, 0, 2, 0,3, 0, 0, 3},{2, 3, 3, 3, 3, 3, 4, 5, 5},{1, 2, 0, 0, 0, 0, 2, 0, 0}}; |
---|
1077 | UInt dir = pcCU->getLumaIntraDir( absPartIdx ); |
---|
1078 | UInt puIdx = (pcCU->getWidth(absPartIdx) == 64) ? 2 : ( (pcCU->getPartitionSize(absPartIdx) == SIZE_NxN && pcCU->getWidth(absPartIdx) == 8) ? 0 : 1 ); |
---|
1079 | UInt codeIdx = 0; |
---|
1080 | |
---|
1081 | if( dir < NUM_INTRA_MODE ) |
---|
1082 | { |
---|
1083 | codeIdx = 1; |
---|
1084 | } |
---|
1085 | if( isDimMode( dir ) ) |
---|
1086 | { |
---|
1087 | switch( getDimType( dir ) ) |
---|
1088 | { |
---|
1089 | case DMM1_IDX: codeIdx = 3; break; |
---|
1090 | case DMM4_IDX: codeIdx = 4; break; |
---|
1091 | case DMM3_IDX: codeIdx = 5; break; |
---|
1092 | case DMM2_IDX: codeIdx = 7; break; |
---|
1093 | case RBC_IDX: codeIdx = 8; break; |
---|
1094 | default: break; |
---|
1095 | } |
---|
1096 | } |
---|
1097 | |
---|
1098 | #if H_3D_DIM_SDC |
---|
1099 | if( pcCU->getSDCFlag( absPartIdx ) ) |
---|
1100 | { |
---|
1101 | switch( dir ) |
---|
1102 | { |
---|
1103 | case PLANAR_IDX: codeIdx = 0; break; |
---|
1104 | case DC_IDX: codeIdx = 6; break; |
---|
1105 | default: codeIdx = 2; break; |
---|
1106 | } |
---|
1107 | } |
---|
1108 | #endif |
---|
1109 | //mode coding |
---|
1110 | for( UInt i = 0; i < codeWordLenTable[puIdx][codeIdx]; i++ ) |
---|
1111 | { |
---|
1112 | UInt bit = codeWordTable[puIdx][codeIdx] & ( 1<<(codeWordLenTable[puIdx][codeIdx] - i - 1) ); |
---|
1113 | UInt ctxDepthMode = puIdx*3 + ( (i >= 2) ? 2 : i ); |
---|
1114 | m_pcBinIf->encodeBin( bit!=0 , m_cDepthIntraModeSCModel.get(0, 0, ctxDepthMode) ); |
---|
1115 | } |
---|
1116 | } |
---|
1117 | #endif |
---|
1118 | |
---|
1119 | Void TEncSbac::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1120 | { |
---|
1121 | const UInt uiInterDir = pcCU->getInterDir( uiAbsPartIdx ) - 1; |
---|
1122 | const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx ); |
---|
1123 | ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 ); |
---|
1124 | if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 ) |
---|
1125 | { |
---|
1126 | m_pcBinIf->encodeBin( uiInterDir == 2 ? 1 : 0, *( pCtx + uiCtx ) ); |
---|
1127 | } |
---|
1128 | if (uiInterDir < 2) |
---|
1129 | { |
---|
1130 | m_pcBinIf->encodeBin( uiInterDir, *( pCtx + 4 ) ); |
---|
1131 | } |
---|
1132 | return; |
---|
1133 | } |
---|
1134 | |
---|
1135 | Void TEncSbac::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1136 | { |
---|
1137 | { |
---|
1138 | Int iRefFrame = pcCU->getCUMvField( eRefList )->getRefIdx( uiAbsPartIdx ); |
---|
1139 | ContextModel *pCtx = m_cCURefPicSCModel.get( 0 ); |
---|
1140 | m_pcBinIf->encodeBin( ( iRefFrame == 0 ? 0 : 1 ), *pCtx ); |
---|
1141 | |
---|
1142 | if( iRefFrame > 0 ) |
---|
1143 | { |
---|
1144 | UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2; |
---|
1145 | pCtx++; |
---|
1146 | iRefFrame--; |
---|
1147 | for( UInt ui = 0; ui < uiRefNum; ++ui ) |
---|
1148 | { |
---|
1149 | const UInt uiSymbol = ui == iRefFrame ? 0 : 1; |
---|
1150 | if( ui == 0 ) |
---|
1151 | { |
---|
1152 | m_pcBinIf->encodeBin( uiSymbol, *pCtx ); |
---|
1153 | } |
---|
1154 | else |
---|
1155 | { |
---|
1156 | m_pcBinIf->encodeBinEP( uiSymbol ); |
---|
1157 | } |
---|
1158 | if( uiSymbol == 0 ) |
---|
1159 | { |
---|
1160 | break; |
---|
1161 | } |
---|
1162 | } |
---|
1163 | } |
---|
1164 | } |
---|
1165 | return; |
---|
1166 | } |
---|
1167 | |
---|
1168 | Void TEncSbac::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
1169 | { |
---|
1170 | if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefList == REF_PIC_LIST_1 && pcCU->getInterDir(uiAbsPartIdx)==3) |
---|
1171 | { |
---|
1172 | return; |
---|
1173 | } |
---|
1174 | |
---|
1175 | const TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefList ); |
---|
1176 | const Int iHor = pcCUMvField->getMvd( uiAbsPartIdx ).getHor(); |
---|
1177 | const Int iVer = pcCUMvField->getMvd( uiAbsPartIdx ).getVer(); |
---|
1178 | ContextModel* pCtx = m_cCUMvdSCModel.get( 0 ); |
---|
1179 | |
---|
1180 | m_pcBinIf->encodeBin( iHor != 0 ? 1 : 0, *pCtx ); |
---|
1181 | m_pcBinIf->encodeBin( iVer != 0 ? 1 : 0, *pCtx ); |
---|
1182 | |
---|
1183 | const Bool bHorAbsGr0 = iHor != 0; |
---|
1184 | const Bool bVerAbsGr0 = iVer != 0; |
---|
1185 | const UInt uiHorAbs = 0 > iHor ? -iHor : iHor; |
---|
1186 | const UInt uiVerAbs = 0 > iVer ? -iVer : iVer; |
---|
1187 | pCtx++; |
---|
1188 | |
---|
1189 | if( bHorAbsGr0 ) |
---|
1190 | { |
---|
1191 | m_pcBinIf->encodeBin( uiHorAbs > 1 ? 1 : 0, *pCtx ); |
---|
1192 | } |
---|
1193 | |
---|
1194 | if( bVerAbsGr0 ) |
---|
1195 | { |
---|
1196 | m_pcBinIf->encodeBin( uiVerAbs > 1 ? 1 : 0, *pCtx ); |
---|
1197 | } |
---|
1198 | |
---|
1199 | if( bHorAbsGr0 ) |
---|
1200 | { |
---|
1201 | if( uiHorAbs > 1 ) |
---|
1202 | { |
---|
1203 | xWriteEpExGolomb( uiHorAbs-2, 1 ); |
---|
1204 | } |
---|
1205 | |
---|
1206 | m_pcBinIf->encodeBinEP( 0 > iHor ? 1 : 0 ); |
---|
1207 | } |
---|
1208 | |
---|
1209 | if( bVerAbsGr0 ) |
---|
1210 | { |
---|
1211 | if( uiVerAbs > 1 ) |
---|
1212 | { |
---|
1213 | xWriteEpExGolomb( uiVerAbs-2, 1 ); |
---|
1214 | } |
---|
1215 | |
---|
1216 | m_pcBinIf->encodeBinEP( 0 > iVer ? 1 : 0 ); |
---|
1217 | } |
---|
1218 | |
---|
1219 | return; |
---|
1220 | } |
---|
1221 | |
---|
1222 | Void TEncSbac::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1223 | { |
---|
1224 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
1225 | |
---|
1226 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
1227 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
1228 | |
---|
1229 | UInt uiAbsDQp = (UInt)((iDQp > 0)? iDQp : (-iDQp)); |
---|
1230 | UInt TUValue = min((Int)uiAbsDQp, CU_DQP_TU_CMAX); |
---|
1231 | xWriteUnaryMaxSymbol( TUValue, &m_cCUDeltaQpSCModel.get( 0, 0, 0 ), 1, CU_DQP_TU_CMAX); |
---|
1232 | if( uiAbsDQp >= CU_DQP_TU_CMAX ) |
---|
1233 | { |
---|
1234 | xWriteEpExGolomb( uiAbsDQp - CU_DQP_TU_CMAX, CU_DQP_EG_k ); |
---|
1235 | } |
---|
1236 | |
---|
1237 | if ( uiAbsDQp > 0) |
---|
1238 | { |
---|
1239 | UInt uiSign = (iDQp > 0 ? 0 : 1); |
---|
1240 | m_pcBinIf->encodeBinEP(uiSign); |
---|
1241 | } |
---|
1242 | |
---|
1243 | return; |
---|
1244 | } |
---|
1245 | |
---|
1246 | Void TEncSbac::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
1247 | { |
---|
1248 | UInt uiCbf = pcCU->getCbf ( uiAbsPartIdx, eType, uiTrDepth ); |
---|
1249 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
1250 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
1251 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1252 | DTRACE_CABAC_T( "\tparseQtCbf()" ) |
---|
1253 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1254 | DTRACE_CABAC_V( uiCbf ) |
---|
1255 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1256 | DTRACE_CABAC_V( uiCtx ) |
---|
1257 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1258 | DTRACE_CABAC_V( eType ) |
---|
1259 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1260 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1261 | DTRACE_CABAC_T( "\n" ) |
---|
1262 | } |
---|
1263 | |
---|
1264 | void TEncSbac::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) |
---|
1265 | { |
---|
1266 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1267 | { |
---|
1268 | return; |
---|
1269 | } |
---|
1270 | if(width != 4 || height != 4) |
---|
1271 | { |
---|
1272 | return; |
---|
1273 | } |
---|
1274 | |
---|
1275 | UInt useTransformSkip = pcCU->getTransformSkip( uiAbsPartIdx,eTType); |
---|
1276 | m_pcBinIf->encodeBin( useTransformSkip, m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) ); |
---|
1277 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1278 | DTRACE_CABAC_T("\tparseTransformSkip()"); |
---|
1279 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1280 | DTRACE_CABAC_V( useTransformSkip ) |
---|
1281 | DTRACE_CABAC_T( "\tAddr=" ) |
---|
1282 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
1283 | DTRACE_CABAC_T( "\tetype=" ) |
---|
1284 | DTRACE_CABAC_V( eTType ) |
---|
1285 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1286 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1287 | DTRACE_CABAC_T( "\n" ) |
---|
1288 | } |
---|
1289 | |
---|
1290 | /** Code I_PCM information. |
---|
1291 | * \param pcCU pointer to CU |
---|
1292 | * \param uiAbsPartIdx CU index |
---|
1293 | * \returns Void |
---|
1294 | */ |
---|
1295 | Void TEncSbac::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1296 | { |
---|
1297 | UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0; |
---|
1298 | |
---|
1299 | Bool writePCMSampleFlag = pcCU->getIPCMFlag(uiAbsPartIdx); |
---|
1300 | |
---|
1301 | m_pcBinIf->encodeBinTrm (uiIPCM); |
---|
1302 | |
---|
1303 | if (writePCMSampleFlag) |
---|
1304 | { |
---|
1305 | m_pcBinIf->encodePCMAlignBits(); |
---|
1306 | |
---|
1307 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
1308 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
1309 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
1310 | Pel* piPCMSample; |
---|
1311 | UInt uiWidth; |
---|
1312 | UInt uiHeight; |
---|
1313 | UInt uiSampleBits; |
---|
1314 | UInt uiX, uiY; |
---|
1315 | |
---|
1316 | piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset; |
---|
1317 | uiWidth = pcCU->getWidth(uiAbsPartIdx); |
---|
1318 | uiHeight = pcCU->getHeight(uiAbsPartIdx); |
---|
1319 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma(); |
---|
1320 | |
---|
1321 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
1322 | { |
---|
1323 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
1324 | { |
---|
1325 | UInt uiSample = piPCMSample[uiX]; |
---|
1326 | |
---|
1327 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
1328 | } |
---|
1329 | piPCMSample += uiWidth; |
---|
1330 | } |
---|
1331 | |
---|
1332 | piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset; |
---|
1333 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
1334 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
1335 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
1336 | |
---|
1337 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
1338 | { |
---|
1339 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
1340 | { |
---|
1341 | UInt uiSample = piPCMSample[uiX]; |
---|
1342 | |
---|
1343 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
1344 | } |
---|
1345 | piPCMSample += uiWidth; |
---|
1346 | } |
---|
1347 | |
---|
1348 | piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset; |
---|
1349 | uiWidth = pcCU->getWidth(uiAbsPartIdx)/2; |
---|
1350 | uiHeight = pcCU->getHeight(uiAbsPartIdx)/2; |
---|
1351 | uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma(); |
---|
1352 | |
---|
1353 | for(uiY = 0; uiY < uiHeight; uiY++) |
---|
1354 | { |
---|
1355 | for(uiX = 0; uiX < uiWidth; uiX++) |
---|
1356 | { |
---|
1357 | UInt uiSample = piPCMSample[uiX]; |
---|
1358 | |
---|
1359 | m_pcBinIf->xWritePCMCode(uiSample, uiSampleBits); |
---|
1360 | } |
---|
1361 | piPCMSample += uiWidth; |
---|
1362 | } |
---|
1363 | m_pcBinIf->resetBac(); |
---|
1364 | } |
---|
1365 | } |
---|
1366 | |
---|
1367 | Void TEncSbac::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
1368 | { |
---|
1369 | UInt uiCbf = pcCU->getQtRootCbf( uiAbsPartIdx ); |
---|
1370 | UInt uiCtx = 0; |
---|
1371 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
1372 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1373 | DTRACE_CABAC_T( "\tparseQtRootCbf()" ) |
---|
1374 | DTRACE_CABAC_T( "\tsymbol=" ) |
---|
1375 | DTRACE_CABAC_V( uiCbf ) |
---|
1376 | DTRACE_CABAC_T( "\tctx=" ) |
---|
1377 | DTRACE_CABAC_V( uiCtx ) |
---|
1378 | DTRACE_CABAC_T( "\tuiAbsPartIdx=" ) |
---|
1379 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1380 | DTRACE_CABAC_T( "\n" ) |
---|
1381 | } |
---|
1382 | |
---|
1383 | Void TEncSbac::codeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
---|
1384 | { |
---|
1385 | // this function is only used to estimate the bits when cbf is 0 |
---|
1386 | // and will never be called when writing the bistream. do not need to write log |
---|
1387 | UInt uiCbf = 0; |
---|
1388 | UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth ); |
---|
1389 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA : eType, uiCtx ) ); |
---|
1390 | } |
---|
1391 | |
---|
1392 | Void TEncSbac::codeQtRootCbfZero( TComDataCU* pcCU ) |
---|
1393 | { |
---|
1394 | // this function is only used to estimate the bits when cbf is 0 |
---|
1395 | // and will never be called when writing the bistream. do not need to write log |
---|
1396 | UInt uiCbf = 0; |
---|
1397 | UInt uiCtx = 0; |
---|
1398 | m_pcBinIf->encodeBin( uiCbf , m_cCUQtRootCbfSCModel.get( 0, 0, uiCtx ) ); |
---|
1399 | } |
---|
1400 | |
---|
1401 | /** Encode (X,Y) position of the last significant coefficient |
---|
1402 | * \param uiPosX X component of last coefficient |
---|
1403 | * \param uiPosY Y component of last coefficient |
---|
1404 | * \param width Block width |
---|
1405 | * \param height Block height |
---|
1406 | * \param eTType plane type / luminance or chrominance |
---|
1407 | * \param uiScanIdx scan type (zig-zag, hor, ver) |
---|
1408 | * This method encodes the X and Y component within a block of the last significant coefficient. |
---|
1409 | */ |
---|
1410 | Void TEncSbac::codeLastSignificantXY( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx ) |
---|
1411 | { |
---|
1412 | // swap |
---|
1413 | if( uiScanIdx == SCAN_VER ) |
---|
1414 | { |
---|
1415 | swap( uiPosX, uiPosY ); |
---|
1416 | } |
---|
1417 | |
---|
1418 | UInt uiCtxLast; |
---|
1419 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
1420 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
1421 | UInt uiGroupIdxX = g_uiGroupIdx[ uiPosX ]; |
---|
1422 | UInt uiGroupIdxY = g_uiGroupIdx[ uiPosY ]; |
---|
1423 | |
---|
1424 | |
---|
1425 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1426 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
1427 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
1428 | shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
1429 | shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
1430 | // posX |
---|
1431 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxX; uiCtxLast++ ) |
---|
1432 | { |
---|
1433 | m_pcBinIf->encodeBin( 1, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
1434 | } |
---|
1435 | if( uiGroupIdxX < g_uiGroupIdx[ width - 1 ]) |
---|
1436 | { |
---|
1437 | m_pcBinIf->encodeBin( 0, *( pCtxX + blkSizeOffsetX + (uiCtxLast >>shiftX) ) ); |
---|
1438 | } |
---|
1439 | |
---|
1440 | // posY |
---|
1441 | for( uiCtxLast = 0; uiCtxLast < uiGroupIdxY; uiCtxLast++ ) |
---|
1442 | { |
---|
1443 | m_pcBinIf->encodeBin( 1, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
1444 | } |
---|
1445 | if( uiGroupIdxY < g_uiGroupIdx[ height - 1 ]) |
---|
1446 | { |
---|
1447 | m_pcBinIf->encodeBin( 0, *( pCtxY + blkSizeOffsetY + (uiCtxLast >>shiftY) ) ); |
---|
1448 | } |
---|
1449 | if ( uiGroupIdxX > 3 ) |
---|
1450 | { |
---|
1451 | UInt uiCount = ( uiGroupIdxX - 2 ) >> 1; |
---|
1452 | uiPosX = uiPosX - g_uiMinInGroup[ uiGroupIdxX ]; |
---|
1453 | for (Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1454 | { |
---|
1455 | m_pcBinIf->encodeBinEP( ( uiPosX >> i ) & 1 ); |
---|
1456 | } |
---|
1457 | } |
---|
1458 | if ( uiGroupIdxY > 3 ) |
---|
1459 | { |
---|
1460 | UInt uiCount = ( uiGroupIdxY - 2 ) >> 1; |
---|
1461 | uiPosY = uiPosY - g_uiMinInGroup[ uiGroupIdxY ]; |
---|
1462 | for ( Int i = uiCount - 1 ; i >= 0; i-- ) |
---|
1463 | { |
---|
1464 | m_pcBinIf->encodeBinEP( ( uiPosY >> i ) & 1 ); |
---|
1465 | } |
---|
1466 | } |
---|
1467 | } |
---|
1468 | |
---|
1469 | Void TEncSbac::codeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
1470 | { |
---|
1471 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
1472 | DTRACE_CABAC_T( "\tparseCoeffNxN()\teType=" ) |
---|
1473 | DTRACE_CABAC_V( eTType ) |
---|
1474 | DTRACE_CABAC_T( "\twidth=" ) |
---|
1475 | DTRACE_CABAC_V( uiWidth ) |
---|
1476 | DTRACE_CABAC_T( "\theight=" ) |
---|
1477 | DTRACE_CABAC_V( uiHeight ) |
---|
1478 | DTRACE_CABAC_T( "\tdepth=" ) |
---|
1479 | DTRACE_CABAC_V( uiDepth ) |
---|
1480 | DTRACE_CABAC_T( "\tabspartidx=" ) |
---|
1481 | DTRACE_CABAC_V( uiAbsPartIdx ) |
---|
1482 | DTRACE_CABAC_T( "\ttoCU-X=" ) |
---|
1483 | DTRACE_CABAC_V( pcCU->getCUPelX() ) |
---|
1484 | DTRACE_CABAC_T( "\ttoCU-Y=" ) |
---|
1485 | DTRACE_CABAC_V( pcCU->getCUPelY() ) |
---|
1486 | DTRACE_CABAC_T( "\tCU-addr=" ) |
---|
1487 | DTRACE_CABAC_V( pcCU->getAddr() ) |
---|
1488 | DTRACE_CABAC_T( "\tinCU-X=" ) |
---|
1489 | DTRACE_CABAC_V( g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1490 | DTRACE_CABAC_T( "\tinCU-Y=" ) |
---|
1491 | DTRACE_CABAC_V( g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ] ) |
---|
1492 | DTRACE_CABAC_T( "\tpredmode=" ) |
---|
1493 | DTRACE_CABAC_V( pcCU->getPredictionMode( uiAbsPartIdx ) ) |
---|
1494 | DTRACE_CABAC_T( "\n" ) |
---|
1495 | |
---|
1496 | if( uiWidth > m_pcSlice->getSPS()->getMaxTrSize() ) |
---|
1497 | { |
---|
1498 | uiWidth = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1499 | uiHeight = m_pcSlice->getSPS()->getMaxTrSize(); |
---|
1500 | } |
---|
1501 | |
---|
1502 | UInt uiNumSig = 0; |
---|
1503 | |
---|
1504 | // compute number of significant coefficients |
---|
1505 | uiNumSig = TEncEntropy::countNonZeroCoeffs(pcCoef, uiWidth * uiHeight); |
---|
1506 | |
---|
1507 | if ( uiNumSig == 0 ) |
---|
1508 | return; |
---|
1509 | if(pcCU->getSlice()->getPPS()->getUseTransformSkip()) |
---|
1510 | { |
---|
1511 | codeTransformSkipFlags( pcCU,uiAbsPartIdx, uiWidth, uiHeight, eTType ); |
---|
1512 | } |
---|
1513 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : ( eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA ); |
---|
1514 | |
---|
1515 | //----- encode significance map ----- |
---|
1516 | const UInt uiLog2BlockSize = g_aucConvertToBit[ uiWidth ] + 2; |
---|
1517 | UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx)); |
---|
1518 | const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize - 1 ]; |
---|
1519 | |
---|
1520 | Bool beValid; |
---|
1521 | if (pcCU->getCUTransquantBypass(uiAbsPartIdx)) |
---|
1522 | { |
---|
1523 | beValid = false; |
---|
1524 | } |
---|
1525 | else |
---|
1526 | { |
---|
1527 | beValid = pcCU->getSlice()->getPPS()->getSignHideFlag() > 0; |
---|
1528 | } |
---|
1529 | |
---|
1530 | // Find position of last coefficient |
---|
1531 | Int scanPosLast = -1; |
---|
1532 | Int posLast; |
---|
1533 | |
---|
1534 | const UInt * scanCG; |
---|
1535 | { |
---|
1536 | scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0 ]; |
---|
1537 | if( uiLog2BlockSize == 3 ) |
---|
1538 | { |
---|
1539 | scanCG = g_sigLastScan8x8[ uiScanIdx ]; |
---|
1540 | } |
---|
1541 | else if( uiLog2BlockSize == 5 ) |
---|
1542 | { |
---|
1543 | scanCG = g_sigLastScanCG32x32; |
---|
1544 | } |
---|
1545 | } |
---|
1546 | UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ]; |
---|
1547 | static const UInt uiShift = MLS_CG_SIZE >> 1; |
---|
1548 | const UInt uiNumBlkSide = uiWidth >> uiShift; |
---|
1549 | |
---|
1550 | ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); |
---|
1551 | |
---|
1552 | do |
---|
1553 | { |
---|
1554 | posLast = scan[ ++scanPosLast ]; |
---|
1555 | |
---|
1556 | // get L1 sig map |
---|
1557 | UInt uiPosY = posLast >> uiLog2BlockSize; |
---|
1558 | UInt uiPosX = posLast - ( uiPosY << uiLog2BlockSize ); |
---|
1559 | UInt uiBlkIdx = uiNumBlkSide * (uiPosY >> uiShift) + (uiPosX >> uiShift); |
---|
1560 | if( pcCoef[ posLast ] ) |
---|
1561 | { |
---|
1562 | uiSigCoeffGroupFlag[ uiBlkIdx ] = 1; |
---|
1563 | } |
---|
1564 | |
---|
1565 | uiNumSig -= ( pcCoef[ posLast ] != 0 ); |
---|
1566 | } |
---|
1567 | while ( uiNumSig > 0 ); |
---|
1568 | |
---|
1569 | // Code position of last coefficient |
---|
1570 | Int posLastY = posLast >> uiLog2BlockSize; |
---|
1571 | Int posLastX = posLast - ( posLastY << uiLog2BlockSize ); |
---|
1572 | codeLastSignificantXY(posLastX, posLastY, uiWidth, uiHeight, eTType, uiScanIdx); |
---|
1573 | |
---|
1574 | //===== code significance flag ===== |
---|
1575 | ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get( 0, eTType ); |
---|
1576 | ContextModel * const baseCtx = (eTType==TEXT_LUMA) ? m_cCUSigSCModel.get( 0, 0 ) : m_cCUSigSCModel.get( 0, 0 ) + NUM_SIG_FLAG_CTX_LUMA; |
---|
1577 | |
---|
1578 | |
---|
1579 | const Int iLastScanSet = scanPosLast >> LOG2_SCAN_SET_SIZE; |
---|
1580 | UInt c1 = 1; |
---|
1581 | UInt uiGoRiceParam = 0; |
---|
1582 | Int iScanPosSig = scanPosLast; |
---|
1583 | |
---|
1584 | for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- ) |
---|
1585 | { |
---|
1586 | Int numNonZero = 0; |
---|
1587 | Int iSubPos = iSubSet << LOG2_SCAN_SET_SIZE; |
---|
1588 | uiGoRiceParam = 0; |
---|
1589 | Int absCoeff[16]; |
---|
1590 | UInt coeffSigns = 0; |
---|
1591 | |
---|
1592 | Int lastNZPosInCG = -1, firstNZPosInCG = SCAN_SET_SIZE; |
---|
1593 | |
---|
1594 | if( iScanPosSig == scanPosLast ) |
---|
1595 | { |
---|
1596 | absCoeff[ 0 ] = abs( pcCoef[ posLast ] ); |
---|
1597 | coeffSigns = ( pcCoef[ posLast ] < 0 ); |
---|
1598 | numNonZero = 1; |
---|
1599 | lastNZPosInCG = iScanPosSig; |
---|
1600 | firstNZPosInCG = iScanPosSig; |
---|
1601 | iScanPosSig--; |
---|
1602 | } |
---|
1603 | |
---|
1604 | // encode significant_coeffgroup_flag |
---|
1605 | Int iCGBlkPos = scanCG[ iSubSet ]; |
---|
1606 | Int iCGPosY = iCGBlkPos / uiNumBlkSide; |
---|
1607 | Int iCGPosX = iCGBlkPos - (iCGPosY * uiNumBlkSide); |
---|
1608 | if( iSubSet == iLastScanSet || iSubSet == 0) |
---|
1609 | { |
---|
1610 | uiSigCoeffGroupFlag[ iCGBlkPos ] = 1; |
---|
1611 | } |
---|
1612 | else |
---|
1613 | { |
---|
1614 | UInt uiSigCoeffGroup = (uiSigCoeffGroupFlag[ iCGBlkPos ] != 0); |
---|
1615 | UInt uiCtxSig = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
1616 | m_pcBinIf->encodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] ); |
---|
1617 | } |
---|
1618 | |
---|
1619 | // encode significant_coeff_flag |
---|
1620 | if( uiSigCoeffGroupFlag[ iCGBlkPos ] ) |
---|
1621 | { |
---|
1622 | Int patternSigCtx = TComTrQuant::calcPatternSigCtx( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight ); |
---|
1623 | UInt uiBlkPos, uiPosY, uiPosX, uiSig, uiCtxSig; |
---|
1624 | for( ; iScanPosSig >= iSubPos; iScanPosSig-- ) |
---|
1625 | { |
---|
1626 | uiBlkPos = scan[ iScanPosSig ]; |
---|
1627 | uiPosY = uiBlkPos >> uiLog2BlockSize; |
---|
1628 | uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockSize ); |
---|
1629 | uiSig = (pcCoef[ uiBlkPos ] != 0); |
---|
1630 | if( iScanPosSig > iSubPos || iSubSet == 0 || numNonZero ) |
---|
1631 | { |
---|
1632 | uiCtxSig = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType ); |
---|
1633 | m_pcBinIf->encodeBin( uiSig, baseCtx[ uiCtxSig ] ); |
---|
1634 | } |
---|
1635 | if( uiSig ) |
---|
1636 | { |
---|
1637 | absCoeff[ numNonZero ] = abs( pcCoef[ uiBlkPos ] ); |
---|
1638 | coeffSigns = 2 * coeffSigns + ( pcCoef[ uiBlkPos ] < 0 ); |
---|
1639 | numNonZero++; |
---|
1640 | if( lastNZPosInCG == -1 ) |
---|
1641 | { |
---|
1642 | lastNZPosInCG = iScanPosSig; |
---|
1643 | } |
---|
1644 | firstNZPosInCG = iScanPosSig; |
---|
1645 | } |
---|
1646 | } |
---|
1647 | } |
---|
1648 | else |
---|
1649 | { |
---|
1650 | iScanPosSig = iSubPos - 1; |
---|
1651 | } |
---|
1652 | |
---|
1653 | if( numNonZero > 0 ) |
---|
1654 | { |
---|
1655 | Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD ); |
---|
1656 | UInt uiCtxSet = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0; |
---|
1657 | |
---|
1658 | if( c1 == 0 ) |
---|
1659 | { |
---|
1660 | uiCtxSet++; |
---|
1661 | } |
---|
1662 | c1 = 1; |
---|
1663 | ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet; |
---|
1664 | |
---|
1665 | Int numC1Flag = min(numNonZero, C1FLAG_NUMBER); |
---|
1666 | Int firstC2FlagIdx = -1; |
---|
1667 | for( Int idx = 0; idx < numC1Flag; idx++ ) |
---|
1668 | { |
---|
1669 | UInt uiSymbol = absCoeff[ idx ] > 1; |
---|
1670 | m_pcBinIf->encodeBin( uiSymbol, baseCtxMod[c1] ); |
---|
1671 | if( uiSymbol ) |
---|
1672 | { |
---|
1673 | c1 = 0; |
---|
1674 | |
---|
1675 | if (firstC2FlagIdx == -1) |
---|
1676 | { |
---|
1677 | firstC2FlagIdx = idx; |
---|
1678 | } |
---|
1679 | } |
---|
1680 | else if( (c1 < 3) && (c1 > 0) ) |
---|
1681 | { |
---|
1682 | c1++; |
---|
1683 | } |
---|
1684 | } |
---|
1685 | |
---|
1686 | if (c1 == 0) |
---|
1687 | { |
---|
1688 | |
---|
1689 | baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUAbsSCModel.get( 0, 0 ) + uiCtxSet : m_cCUAbsSCModel.get( 0, 0 ) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet; |
---|
1690 | if ( firstC2FlagIdx != -1) |
---|
1691 | { |
---|
1692 | UInt symbol = absCoeff[ firstC2FlagIdx ] > 2; |
---|
1693 | m_pcBinIf->encodeBin( symbol, baseCtxMod[0] ); |
---|
1694 | } |
---|
1695 | } |
---|
1696 | |
---|
1697 | if( beValid && signHidden ) |
---|
1698 | { |
---|
1699 | m_pcBinIf->encodeBinsEP( (coeffSigns >> 1), numNonZero-1 ); |
---|
1700 | } |
---|
1701 | else |
---|
1702 | { |
---|
1703 | m_pcBinIf->encodeBinsEP( coeffSigns, numNonZero ); |
---|
1704 | } |
---|
1705 | |
---|
1706 | Int iFirstCoeff2 = 1; |
---|
1707 | if (c1 == 0 || numNonZero > C1FLAG_NUMBER) |
---|
1708 | { |
---|
1709 | for ( Int idx = 0; idx < numNonZero; idx++ ) |
---|
1710 | { |
---|
1711 | UInt baseLevel = (idx < C1FLAG_NUMBER)? (2 + iFirstCoeff2 ) : 1; |
---|
1712 | |
---|
1713 | if( absCoeff[ idx ] >= baseLevel) |
---|
1714 | { |
---|
1715 | xWriteCoefRemainExGolomb( absCoeff[ idx ] - baseLevel, uiGoRiceParam ); |
---|
1716 | if(absCoeff[idx] > 3*(1<<uiGoRiceParam)) |
---|
1717 | { |
---|
1718 | uiGoRiceParam = min<UInt>(uiGoRiceParam+ 1, 4); |
---|
1719 | } |
---|
1720 | } |
---|
1721 | if(absCoeff[ idx ] >= 2) |
---|
1722 | { |
---|
1723 | iFirstCoeff2 = 0; |
---|
1724 | } |
---|
1725 | } |
---|
1726 | } |
---|
1727 | } |
---|
1728 | } |
---|
1729 | |
---|
1730 | return; |
---|
1731 | } |
---|
1732 | |
---|
1733 | /** code SAO offset sign |
---|
1734 | * \param code sign value |
---|
1735 | */ |
---|
1736 | Void TEncSbac::codeSAOSign( UInt code ) |
---|
1737 | { |
---|
1738 | m_pcBinIf->encodeBinEP( code ); |
---|
1739 | } |
---|
1740 | |
---|
1741 | Void TEncSbac::codeSaoMaxUvlc ( UInt code, UInt maxSymbol ) |
---|
1742 | { |
---|
1743 | if (maxSymbol == 0) |
---|
1744 | { |
---|
1745 | return; |
---|
1746 | } |
---|
1747 | |
---|
1748 | Int i; |
---|
1749 | Bool bCodeLast = ( maxSymbol > code ); |
---|
1750 | |
---|
1751 | if ( code == 0 ) |
---|
1752 | { |
---|
1753 | m_pcBinIf->encodeBinEP( 0 ); |
---|
1754 | } |
---|
1755 | else |
---|
1756 | { |
---|
1757 | m_pcBinIf->encodeBinEP( 1 ); |
---|
1758 | for ( i=0; i<code-1; i++ ) |
---|
1759 | { |
---|
1760 | m_pcBinIf->encodeBinEP( 1 ); |
---|
1761 | } |
---|
1762 | if( bCodeLast ) |
---|
1763 | { |
---|
1764 | m_pcBinIf->encodeBinEP( 0 ); |
---|
1765 | } |
---|
1766 | } |
---|
1767 | } |
---|
1768 | |
---|
1769 | |
---|
1770 | /** Code SAO EO class or BO band position |
---|
1771 | * \param uiLength |
---|
1772 | * \param uiCode |
---|
1773 | */ |
---|
1774 | Void TEncSbac::codeSaoUflc ( UInt uiLength, UInt uiCode ) |
---|
1775 | { |
---|
1776 | m_pcBinIf->encodeBinsEP ( uiCode, uiLength ); |
---|
1777 | } |
---|
1778 | /** Code SAO merge flags |
---|
1779 | * \param uiCode |
---|
1780 | * \param uiCompIdx |
---|
1781 | */ |
---|
1782 | Void TEncSbac::codeSaoMerge ( UInt uiCode ) |
---|
1783 | { |
---|
1784 | if (uiCode == 0) |
---|
1785 | { |
---|
1786 | m_pcBinIf->encodeBin(0, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
1787 | } |
---|
1788 | else |
---|
1789 | { |
---|
1790 | m_pcBinIf->encodeBin(1, m_cSaoMergeSCModel.get( 0, 0, 0 )); |
---|
1791 | } |
---|
1792 | } |
---|
1793 | /** Code SAO type index |
---|
1794 | * \param uiCode |
---|
1795 | */ |
---|
1796 | Void TEncSbac::codeSaoTypeIdx ( UInt uiCode) |
---|
1797 | { |
---|
1798 | if (uiCode == 0) |
---|
1799 | { |
---|
1800 | m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1801 | } |
---|
1802 | else |
---|
1803 | { |
---|
1804 | m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); |
---|
1805 | m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 ); |
---|
1806 | } |
---|
1807 | } |
---|
1808 | /*! |
---|
1809 | **************************************************************************** |
---|
1810 | * \brief |
---|
1811 | * estimate bit cost for CBP, significant map and significant coefficients |
---|
1812 | **************************************************************************** |
---|
1813 | */ |
---|
1814 | Void TEncSbac::estBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
1815 | { |
---|
1816 | estCBFBit( pcEstBitsSbac ); |
---|
1817 | |
---|
1818 | estSignificantCoeffGroupMapBit( pcEstBitsSbac, eTType ); |
---|
1819 | |
---|
1820 | // encode significance map |
---|
1821 | estSignificantMapBit( pcEstBitsSbac, width, height, eTType ); |
---|
1822 | |
---|
1823 | // encode significant coefficients |
---|
1824 | estSignificantCoefficientsBit( pcEstBitsSbac, eTType ); |
---|
1825 | } |
---|
1826 | |
---|
1827 | /*! |
---|
1828 | **************************************************************************** |
---|
1829 | * \brief |
---|
1830 | * estimate bit cost for each CBP bit |
---|
1831 | **************************************************************************** |
---|
1832 | */ |
---|
1833 | Void TEncSbac::estCBFBit( estBitsSbacStruct* pcEstBitsSbac ) |
---|
1834 | { |
---|
1835 | ContextModel *pCtx = m_cCUQtCbfSCModel.get( 0 ); |
---|
1836 | |
---|
1837 | for( UInt uiCtxInc = 0; uiCtxInc < 3*NUM_QT_CBF_CTX; uiCtxInc++ ) |
---|
1838 | { |
---|
1839 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
1840 | pcEstBitsSbac->blockCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
1841 | } |
---|
1842 | |
---|
1843 | pCtx = m_cCUQtRootCbfSCModel.get( 0 ); |
---|
1844 | |
---|
1845 | for( UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++ ) |
---|
1846 | { |
---|
1847 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 0 ] = pCtx[ uiCtxInc ].getEntropyBits( 0 ); |
---|
1848 | pcEstBitsSbac->blockRootCbpBits[ uiCtxInc ][ 1 ] = pCtx[ uiCtxInc ].getEntropyBits( 1 ); |
---|
1849 | } |
---|
1850 | } |
---|
1851 | |
---|
1852 | |
---|
1853 | /*! |
---|
1854 | **************************************************************************** |
---|
1855 | * \brief |
---|
1856 | * estimate SAMBAC bit cost for significant coefficient group map |
---|
1857 | **************************************************************************** |
---|
1858 | */ |
---|
1859 | Void TEncSbac::estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
1860 | { |
---|
1861 | Int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX; |
---|
1862 | |
---|
1863 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1864 | { |
---|
1865 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1866 | { |
---|
1867 | pcEstBitsSbac->significantCoeffGroupBits[ ctxIdx ][ uiBin ] = m_cCUSigCoeffGroupSCModel.get( 0, eTType, ctxIdx ).getEntropyBits( uiBin ); |
---|
1868 | } |
---|
1869 | } |
---|
1870 | } |
---|
1871 | |
---|
1872 | |
---|
1873 | /*! |
---|
1874 | **************************************************************************** |
---|
1875 | * \brief |
---|
1876 | * estimate SAMBAC bit cost for significant coefficient map |
---|
1877 | **************************************************************************** |
---|
1878 | */ |
---|
1879 | Void TEncSbac::estSignificantMapBit( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ) |
---|
1880 | { |
---|
1881 | Int firstCtx = 1, numCtx = 8; |
---|
1882 | if (max(width, height) >= 16) |
---|
1883 | { |
---|
1884 | firstCtx = (eTType == TEXT_LUMA) ? 21 : 12; |
---|
1885 | numCtx = (eTType == TEXT_LUMA) ? 6 : 3; |
---|
1886 | } |
---|
1887 | else if (width == 8) |
---|
1888 | { |
---|
1889 | firstCtx = 9; |
---|
1890 | numCtx = (eTType == TEXT_LUMA) ? 12 : 3; |
---|
1891 | } |
---|
1892 | |
---|
1893 | if (eTType == TEXT_LUMA ) |
---|
1894 | { |
---|
1895 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
1896 | { |
---|
1897 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, 0 ).getEntropyBits( bin ); |
---|
1898 | } |
---|
1899 | |
---|
1900 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1901 | { |
---|
1902 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1903 | { |
---|
1904 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, ctxIdx ).getEntropyBits( uiBin ); |
---|
1905 | } |
---|
1906 | } |
---|
1907 | } |
---|
1908 | else |
---|
1909 | { |
---|
1910 | for( UInt bin = 0; bin < 2; bin++ ) |
---|
1911 | { |
---|
1912 | pcEstBitsSbac->significantBits[ 0 ][ bin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + 0 ).getEntropyBits( bin ); |
---|
1913 | } |
---|
1914 | for ( Int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++ ) |
---|
1915 | { |
---|
1916 | for( UInt uiBin = 0; uiBin < 2; uiBin++ ) |
---|
1917 | { |
---|
1918 | pcEstBitsSbac->significantBits[ ctxIdx ][ uiBin ] = m_cCUSigSCModel.get( 0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx ).getEntropyBits( uiBin ); |
---|
1919 | } |
---|
1920 | } |
---|
1921 | } |
---|
1922 | Int iBitsX = 0, iBitsY = 0; |
---|
1923 | Int blkSizeOffsetX, blkSizeOffsetY, shiftX, shiftY; |
---|
1924 | |
---|
1925 | blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2)); |
---|
1926 | blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2)); |
---|
1927 | shiftX = eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2); |
---|
1928 | shiftY = eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2); |
---|
1929 | |
---|
1930 | Int ctx; |
---|
1931 | ContextModel *pCtxX = m_cCuCtxLastX.get( 0, eTType ); |
---|
1932 | for (ctx = 0; ctx < g_uiGroupIdx[ width - 1 ]; ctx++) |
---|
1933 | { |
---|
1934 | Int ctxOffset = blkSizeOffsetX + (ctx >>shiftX); |
---|
1935 | pcEstBitsSbac->lastXBits[ ctx ] = iBitsX + pCtxX[ ctxOffset ].getEntropyBits( 0 ); |
---|
1936 | iBitsX += pCtxX[ ctxOffset ].getEntropyBits( 1 ); |
---|
1937 | } |
---|
1938 | pcEstBitsSbac->lastXBits[ctx] = iBitsX; |
---|
1939 | ContextModel *pCtxY = m_cCuCtxLastY.get( 0, eTType ); |
---|
1940 | for (ctx = 0; ctx < g_uiGroupIdx[ height - 1 ]; ctx++) |
---|
1941 | { |
---|
1942 | Int ctxOffset = blkSizeOffsetY + (ctx >>shiftY); |
---|
1943 | pcEstBitsSbac->lastYBits[ ctx ] = iBitsY + pCtxY[ ctxOffset ].getEntropyBits( 0 ); |
---|
1944 | iBitsY += pCtxY[ ctxOffset ].getEntropyBits( 1 ); |
---|
1945 | } |
---|
1946 | pcEstBitsSbac->lastYBits[ctx] = iBitsY; |
---|
1947 | } |
---|
1948 | |
---|
1949 | /*! |
---|
1950 | **************************************************************************** |
---|
1951 | * \brief |
---|
1952 | * estimate bit cost of significant coefficient |
---|
1953 | **************************************************************************** |
---|
1954 | */ |
---|
1955 | Void TEncSbac::estSignificantCoefficientsBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ) |
---|
1956 | { |
---|
1957 | if (eTType==TEXT_LUMA) |
---|
1958 | { |
---|
1959 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0); |
---|
1960 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0); |
---|
1961 | |
---|
1962 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++) |
---|
1963 | { |
---|
1964 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
1965 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
1966 | } |
---|
1967 | |
---|
1968 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_LUMA; ctxIdx++) |
---|
1969 | { |
---|
1970 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
1971 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
1972 | } |
---|
1973 | } |
---|
1974 | else |
---|
1975 | { |
---|
1976 | ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA; |
---|
1977 | ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA; |
---|
1978 | |
---|
1979 | for (Int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++) |
---|
1980 | { |
---|
1981 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 0 ] = ctxOne[ ctxIdx ].getEntropyBits( 0 ); |
---|
1982 | pcEstBitsSbac->m_greaterOneBits[ ctxIdx ][ 1 ] = ctxOne[ ctxIdx ].getEntropyBits( 1 ); |
---|
1983 | } |
---|
1984 | |
---|
1985 | for (Int ctxIdx = 0; ctxIdx < NUM_ABS_FLAG_CTX_CHROMA; ctxIdx++) |
---|
1986 | { |
---|
1987 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 0 ] = ctxAbs[ ctxIdx ].getEntropyBits( 0 ); |
---|
1988 | pcEstBitsSbac->m_levelAbsBits[ ctxIdx ][ 1 ] = ctxAbs[ ctxIdx ].getEntropyBits( 1 ); |
---|
1989 | } |
---|
1990 | } |
---|
1991 | } |
---|
1992 | |
---|
1993 | /** |
---|
1994 | - Initialize our context information from the nominated source. |
---|
1995 | . |
---|
1996 | \param pSrc From where to copy context information. |
---|
1997 | */ |
---|
1998 | Void TEncSbac::xCopyContextsFrom( TEncSbac* pSrc ) |
---|
1999 | { |
---|
2000 | memcpy(m_contextModels, pSrc->m_contextModels, m_numContextModels*sizeof(m_contextModels[0])); |
---|
2001 | } |
---|
2002 | |
---|
2003 | Void TEncSbac::loadContexts ( TEncSbac* pScr) |
---|
2004 | { |
---|
2005 | this->xCopyContextsFrom(pScr); |
---|
2006 | } |
---|
2007 | //! \} |
---|