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