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