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