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