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