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