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