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