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 TDecEntropy.cpp |
---|
35 | \brief entropy decoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TDecEntropy.h" |
---|
39 | |
---|
40 | //! \ingroup TLibDecoder |
---|
41 | //! \{ |
---|
42 | |
---|
43 | Void TDecEntropy::setEntropyDecoder ( TDecEntropyIf* p ) |
---|
44 | { |
---|
45 | m_pcEntropyDecoderIf = p; |
---|
46 | } |
---|
47 | |
---|
48 | #include "TLibCommon/TComSampleAdaptiveOffset.h" |
---|
49 | |
---|
50 | Void TDecEntropy::decodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
51 | { |
---|
52 | m_pcEntropyDecoderIf->parseSkipFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
53 | } |
---|
54 | |
---|
55 | Void TDecEntropy::decodeCUTransquantBypassFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
56 | { |
---|
57 | m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
58 | } |
---|
59 | |
---|
60 | /** decode merge flag |
---|
61 | * \param pcSubCU |
---|
62 | * \param uiAbsPartIdx |
---|
63 | * \param uiDepth |
---|
64 | * \param uiPUIdx |
---|
65 | * \returns Void |
---|
66 | */ |
---|
67 | Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
68 | { |
---|
69 | // at least one merge candidate exists |
---|
70 | m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx ); |
---|
71 | } |
---|
72 | |
---|
73 | /** decode merge index |
---|
74 | * \param pcCU |
---|
75 | * \param uiPartIdx |
---|
76 | * \param uiAbsPartIdx |
---|
77 | * \param puhInterDirNeighbours pointer to list of inter direction from the casual neighbours |
---|
78 | * \param pcMvFieldNeighbours pointer to list of motion vector field from the casual neighbours |
---|
79 | * \param uiDepth |
---|
80 | * \returns Void |
---|
81 | */ |
---|
82 | Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
83 | { |
---|
84 | UInt uiMergeIndex = 0; |
---|
85 | m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex ); |
---|
86 | pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
87 | } |
---|
88 | |
---|
89 | #if H_3D_ARP |
---|
90 | Void TDecEntropy::decodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
91 | { |
---|
92 | if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) ) |
---|
93 | { |
---|
94 | return; |
---|
95 | } |
---|
96 | |
---|
97 | if( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) |
---|
98 | { |
---|
99 | pcCU->setARPWSubParts( 0 , uiAbsPartIdx, uiDepth ); |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | m_pcEntropyDecoderIf->parseARPW( pcCU , uiAbsPartIdx , uiDepth ); |
---|
104 | } |
---|
105 | } |
---|
106 | #endif |
---|
107 | |
---|
108 | #if H_3D_IC |
---|
109 | Void TDecEntropy::decodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
110 | { |
---|
111 | pcCU->setICFlagSubParts( false , uiAbsPartIdx, 0, uiDepth ); |
---|
112 | |
---|
113 | #if SEC_ONLY_TEXTURE_IC_F0151 |
---|
114 | if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() ) |
---|
115 | #else |
---|
116 | if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) ) |
---|
117 | #endif |
---|
118 | { |
---|
119 | return; |
---|
120 | } |
---|
121 | |
---|
122 | if( !pcCU->getSlice()->getApplyIC() ) |
---|
123 | return; |
---|
124 | |
---|
125 | if( pcCU->isICFlagRequired( uiAbsPartIdx ) ) |
---|
126 | m_pcEntropyDecoderIf->parseICFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
127 | } |
---|
128 | #endif |
---|
129 | |
---|
130 | Void TDecEntropy::decodeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
131 | { |
---|
132 | m_pcEntropyDecoderIf->parseSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
133 | } |
---|
134 | |
---|
135 | Void TDecEntropy::decodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
136 | { |
---|
137 | m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth ); |
---|
138 | } |
---|
139 | |
---|
140 | Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
141 | { |
---|
142 | m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
143 | } |
---|
144 | |
---|
145 | Void TDecEntropy::decodePredInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU ) |
---|
146 | { |
---|
147 | if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode. |
---|
148 | { |
---|
149 | decodeIntraDirModeLuma ( pcCU, uiAbsPartIdx, uiDepth ); |
---|
150 | #if H_3D_DIM_SDC |
---|
151 | if(!pcCU->getSDCFlag(uiAbsPartIdx)) |
---|
152 | #endif |
---|
153 | decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth ); |
---|
154 | } |
---|
155 | else // if it is Inter mode, encode motion vector and reference index |
---|
156 | { |
---|
157 | decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU ); |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | /** Parse I_PCM information. |
---|
162 | * \param pcCU pointer to CUpointer to CU |
---|
163 | * \param uiAbsPartIdx CU index |
---|
164 | * \param uiDepth CU depth |
---|
165 | * \returns Void |
---|
166 | */ |
---|
167 | Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
168 | { |
---|
169 | if(!pcCU->getSlice()->getSPS()->getUsePCM() |
---|
170 | || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize()) |
---|
171 | || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) ) |
---|
172 | { |
---|
173 | return; |
---|
174 | } |
---|
175 | #if H_3D_DIM_SDC |
---|
176 | if( pcCU->getSDCFlag(uiAbsPartIdx) ) |
---|
177 | { |
---|
178 | return; |
---|
179 | } |
---|
180 | #endif |
---|
181 | |
---|
182 | m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth ); |
---|
183 | } |
---|
184 | |
---|
185 | Void TDecEntropy::decodeIntraDirModeLuma ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
186 | { |
---|
187 | m_pcEntropyDecoderIf->parseIntraDirLumaAng( pcCU, uiAbsPartIdx, uiDepth ); |
---|
188 | } |
---|
189 | |
---|
190 | Void TDecEntropy::decodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
191 | { |
---|
192 | m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth ); |
---|
193 | } |
---|
194 | |
---|
195 | /** decode motion information for every PU block. |
---|
196 | * \param pcCU |
---|
197 | * \param uiAbsPartIdx |
---|
198 | * \param uiDepth |
---|
199 | * \param pcSubCU |
---|
200 | * \returns Void |
---|
201 | */ |
---|
202 | Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU ) |
---|
203 | { |
---|
204 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
205 | UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) ); |
---|
206 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4; |
---|
207 | |
---|
208 | #if H_3D_IV_MERGE |
---|
209 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists |
---|
210 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM]; |
---|
211 | #else |
---|
212 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
213 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
214 | #endif |
---|
215 | |
---|
216 | for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ ) |
---|
217 | { |
---|
218 | uhInterDirNeighbours[ui] = 0; |
---|
219 | } |
---|
220 | Int numValidMergeCand = 0; |
---|
221 | Bool isMerged = false; |
---|
222 | |
---|
223 | pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 ); |
---|
224 | pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 ); |
---|
225 | #if H_3D_IV_MERGE |
---|
226 | pcSubCU->copyDVInfoFrom( pcCU, uiAbsPartIdx); |
---|
227 | #endif |
---|
228 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
229 | { |
---|
230 | #if H_MV_ENC_DEC_TRAC |
---|
231 | DTRACE_PU_S("=========== prediction_unit ===========\n") |
---|
232 | // ToDo: |
---|
233 | //DTRACE_PU("x0", uiLPelX) |
---|
234 | //DTRACE_PU("x1", uiTPelY) |
---|
235 | #endif |
---|
236 | decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
237 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
238 | { |
---|
239 | decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth ); |
---|
240 | UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx); |
---|
241 | if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) |
---|
242 | { |
---|
243 | pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
244 | if ( !isMerged ) |
---|
245 | { |
---|
246 | #if H_3D_VSP |
---|
247 | Int vspFlag[MRG_MAX_NUM_CANDS_MEM]; |
---|
248 | memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM); |
---|
249 | InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM]; |
---|
250 | pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, numValidMergeCand ); |
---|
251 | pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); |
---|
252 | |
---|
253 | if(vspFlag[uiMergeIndex]) |
---|
254 | { |
---|
255 | pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth); |
---|
256 | } |
---|
257 | #else |
---|
258 | pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
259 | #endif |
---|
260 | isMerged = true; |
---|
261 | } |
---|
262 | pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth ); |
---|
263 | } |
---|
264 | else |
---|
265 | { |
---|
266 | uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx); |
---|
267 | #if H_3D_VSP |
---|
268 | Int vspFlag[MRG_MAX_NUM_CANDS_MEM]; |
---|
269 | memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM); |
---|
270 | InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM]; |
---|
271 | pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo,numValidMergeCand, uiMergeIndex ); |
---|
272 | pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); |
---|
273 | if(vspFlag[uiMergeIndex]) |
---|
274 | { |
---|
275 | pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth); |
---|
276 | } |
---|
277 | #else |
---|
278 | pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex ); |
---|
279 | #endif |
---|
280 | } |
---|
281 | pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); |
---|
282 | |
---|
283 | TComMv cTmpMv( 0, 0 ); |
---|
284 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
285 | { |
---|
286 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
287 | { |
---|
288 | pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth); |
---|
289 | pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth); |
---|
290 | pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
291 | pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
292 | } |
---|
293 | } |
---|
294 | } |
---|
295 | else |
---|
296 | { |
---|
297 | decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
298 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
299 | { |
---|
300 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
301 | { |
---|
302 | decodeRefFrmIdxPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
303 | decodeMvdPU ( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
304 | decodeMVPIdxPU ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
305 | } |
---|
306 | } |
---|
307 | } |
---|
308 | #if H_3D_VSP |
---|
309 | if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) && (pcCU->getVSPFlag(uiSubPartIdx) == false)) |
---|
310 | #else |
---|
311 | if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) ) |
---|
312 | #endif |
---|
313 | { |
---|
314 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx); |
---|
315 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx); |
---|
316 | pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth); |
---|
317 | } |
---|
318 | } |
---|
319 | return; |
---|
320 | } |
---|
321 | |
---|
322 | /** decode inter direction for a PU block |
---|
323 | * \param pcCU |
---|
324 | * \param uiAbsPartIdx |
---|
325 | * \param uiDepth |
---|
326 | * \param uiPartIdx |
---|
327 | * \returns Void |
---|
328 | */ |
---|
329 | Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx ) |
---|
330 | { |
---|
331 | UInt uiInterDir; |
---|
332 | |
---|
333 | if ( pcCU->getSlice()->isInterP() ) |
---|
334 | { |
---|
335 | uiInterDir = 1; |
---|
336 | } |
---|
337 | else |
---|
338 | { |
---|
339 | m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx ); |
---|
340 | } |
---|
341 | |
---|
342 | pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
343 | } |
---|
344 | |
---|
345 | Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
346 | { |
---|
347 | Int iRefFrmIdx = 0; |
---|
348 | Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ); |
---|
349 | |
---|
350 | if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx ) |
---|
351 | { |
---|
352 | m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList ); |
---|
353 | } |
---|
354 | else if ( !iParseRefFrmIdx ) |
---|
355 | { |
---|
356 | iRefFrmIdx = NOT_VALID; |
---|
357 | } |
---|
358 | else |
---|
359 | { |
---|
360 | iRefFrmIdx = 0; |
---|
361 | } |
---|
362 | |
---|
363 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
364 | pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx ); |
---|
365 | } |
---|
366 | |
---|
367 | /** decode motion vector difference for a PU block |
---|
368 | * \param pcCU |
---|
369 | * \param uiAbsPartIdx |
---|
370 | * \param uiDepth |
---|
371 | * \param uiPartIdx |
---|
372 | * \param eRefList |
---|
373 | * \returns Void |
---|
374 | */ |
---|
375 | Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
376 | { |
---|
377 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
378 | { |
---|
379 | m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList ); |
---|
380 | } |
---|
381 | } |
---|
382 | |
---|
383 | Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
384 | { |
---|
385 | Int iMVPIdx = -1; |
---|
386 | |
---|
387 | TComMv cZeroMv( 0, 0 ); |
---|
388 | TComMv cMv = cZeroMv; |
---|
389 | Int iRefIdx = -1; |
---|
390 | |
---|
391 | TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList ); |
---|
392 | AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo(); |
---|
393 | |
---|
394 | iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr); |
---|
395 | cMv = cZeroMv; |
---|
396 | |
---|
397 | if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) ) |
---|
398 | { |
---|
399 | m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx ); |
---|
400 | #if H_MV_ENC_DEC_TRAC |
---|
401 | #if ENC_DEC_TRACE |
---|
402 | if ( eRefList == REF_PIC_LIST_0 ) |
---|
403 | { |
---|
404 | DTRACE_PU("mvp_l0_flag", iMVPIdx) |
---|
405 | } |
---|
406 | else |
---|
407 | { |
---|
408 | DTRACE_PU("mvp_l1_flag", iMVPIdx) |
---|
409 | } |
---|
410 | #endif |
---|
411 | #endif |
---|
412 | } |
---|
413 | pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo); |
---|
414 | pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth); |
---|
415 | pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth ); |
---|
416 | if ( iRefIdx >= 0 ) |
---|
417 | { |
---|
418 | m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv); |
---|
419 | cMv += pcSubCUMvField->getMvd( uiPartAddr ); |
---|
420 | } |
---|
421 | |
---|
422 | PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr ); |
---|
423 | pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx); |
---|
424 | } |
---|
425 | |
---|
426 | Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP) |
---|
427 | { |
---|
428 | UInt uiSubdiv; |
---|
429 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
430 | |
---|
431 | if(uiTrIdx==0) |
---|
432 | { |
---|
433 | m_bakAbsPartIdxCU = uiAbsPartIdx; |
---|
434 | } |
---|
435 | if( uiLog2TrafoSize == 2 ) |
---|
436 | { |
---|
437 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
438 | if( ( uiAbsPartIdx % partNum ) == 0 ) |
---|
439 | { |
---|
440 | m_uiBakAbsPartIdx = uiAbsPartIdx; |
---|
441 | m_uiBakChromaOffset = offsetChroma; |
---|
442 | } |
---|
443 | } |
---|
444 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
445 | { |
---|
446 | uiSubdiv = 1; |
---|
447 | } |
---|
448 | else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) ) |
---|
449 | { |
---|
450 | uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx)); |
---|
451 | } |
---|
452 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
453 | { |
---|
454 | uiSubdiv = 1; |
---|
455 | } |
---|
456 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
457 | { |
---|
458 | uiSubdiv = 0; |
---|
459 | } |
---|
460 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
461 | { |
---|
462 | uiSubdiv = 0; |
---|
463 | } |
---|
464 | else |
---|
465 | { |
---|
466 | assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
467 | m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); |
---|
468 | } |
---|
469 | |
---|
470 | const UInt uiTrDepth = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
471 | { |
---|
472 | const Bool bFirstCbfOfCU = uiTrDepth == 0; |
---|
473 | if( bFirstCbfOfCU ) |
---|
474 | { |
---|
475 | pcCU->setCbfSubParts( 0, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth ); |
---|
476 | pcCU->setCbfSubParts( 0, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth ); |
---|
477 | } |
---|
478 | if( bFirstCbfOfCU || uiLog2TrafoSize > 2 ) |
---|
479 | { |
---|
480 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) ) |
---|
481 | { |
---|
482 | m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth, uiDepth ); |
---|
483 | } |
---|
484 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) ) |
---|
485 | { |
---|
486 | m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth, uiDepth ); |
---|
487 | } |
---|
488 | } |
---|
489 | else |
---|
490 | { |
---|
491 | pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_U, uiAbsPartIdx, uiDepth ); |
---|
492 | pcCU->setCbfSubParts( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth - 1 ) << uiTrDepth, TEXT_CHROMA_V, uiAbsPartIdx, uiDepth ); |
---|
493 | } |
---|
494 | } |
---|
495 | |
---|
496 | if( uiSubdiv ) |
---|
497 | { |
---|
498 | UInt size; |
---|
499 | width >>= 1; |
---|
500 | height >>= 1; |
---|
501 | size = width*height; |
---|
502 | uiTrIdx++; |
---|
503 | ++uiDepth; |
---|
504 | const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
505 | const UInt uiStartAbsPartIdx = uiAbsPartIdx; |
---|
506 | UInt uiYCbf = 0; |
---|
507 | UInt uiUCbf = 0; |
---|
508 | UInt uiVCbf = 0; |
---|
509 | |
---|
510 | for( Int i = 0; i < 4; i++ ) |
---|
511 | { |
---|
512 | xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
513 | uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 ); |
---|
514 | uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 ); |
---|
515 | uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth+1 ); |
---|
516 | uiAbsPartIdx += uiQPartNum; |
---|
517 | offsetLuma += size; offsetChroma += (size>>2); |
---|
518 | } |
---|
519 | |
---|
520 | for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui ) |
---|
521 | { |
---|
522 | pcCU->getCbf( TEXT_LUMA )[uiStartAbsPartIdx + ui] |= uiYCbf << uiTrDepth; |
---|
523 | pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiTrDepth; |
---|
524 | pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiTrDepth; |
---|
525 | } |
---|
526 | } |
---|
527 | else |
---|
528 | { |
---|
529 | assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) ); |
---|
530 | pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth ); |
---|
531 | |
---|
532 | #if !H_MV_ENC_DEC_TRAC |
---|
533 | { |
---|
534 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
535 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
---|
536 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
537 | DTRACE_CABAC_T( "\tdepth=" ); |
---|
538 | DTRACE_CABAC_V( uiDepth ); |
---|
539 | DTRACE_CABAC_T( "\ttrdepth=" ); |
---|
540 | DTRACE_CABAC_V( uiTrDepth ); |
---|
541 | DTRACE_CABAC_T( "\n" ); |
---|
542 | } |
---|
543 | #endif |
---|
544 | |
---|
545 | pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
546 | if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
547 | { |
---|
548 | pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth ); |
---|
549 | } |
---|
550 | else |
---|
551 | { |
---|
552 | m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiDepth ); |
---|
553 | } |
---|
554 | |
---|
555 | |
---|
556 | // transform_unit begin |
---|
557 | UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA , uiTrIdx ); |
---|
558 | UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
559 | UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
560 | if( uiLog2TrafoSize == 2 ) |
---|
561 | { |
---|
562 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
563 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
564 | { |
---|
565 | cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
566 | cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
567 | } |
---|
568 | } |
---|
569 | if ( cbfY || cbfU || cbfV ) |
---|
570 | { |
---|
571 | // dQP: only for LCU |
---|
572 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
573 | { |
---|
574 | if ( bCodeDQP ) |
---|
575 | { |
---|
576 | decodeQP( pcCU, m_bakAbsPartIdxCU); |
---|
577 | bCodeDQP = false; |
---|
578 | } |
---|
579 | } |
---|
580 | } |
---|
581 | if( cbfY ) |
---|
582 | { |
---|
583 | Int trWidth = width; |
---|
584 | Int trHeight = height; |
---|
585 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
586 | } |
---|
587 | if( uiLog2TrafoSize > 2 ) |
---|
588 | { |
---|
589 | Int trWidth = width >> 1; |
---|
590 | Int trHeight = height >> 1; |
---|
591 | if( cbfU ) |
---|
592 | { |
---|
593 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
594 | } |
---|
595 | if( cbfV ) |
---|
596 | { |
---|
597 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
598 | } |
---|
599 | } |
---|
600 | else |
---|
601 | { |
---|
602 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
603 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
604 | { |
---|
605 | Int trWidth = width; |
---|
606 | Int trHeight = height; |
---|
607 | if( cbfU ) |
---|
608 | { |
---|
609 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
610 | } |
---|
611 | if( cbfV ) |
---|
612 | { |
---|
613 | m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
614 | } |
---|
615 | } |
---|
616 | } |
---|
617 | // transform_unit end |
---|
618 | } |
---|
619 | } |
---|
620 | |
---|
621 | Void TDecEntropy::decodeQP ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
622 | { |
---|
623 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
624 | { |
---|
625 | m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) ); |
---|
626 | } |
---|
627 | } |
---|
628 | |
---|
629 | |
---|
630 | /** decode coefficients |
---|
631 | * \param pcCU |
---|
632 | * \param uiAbsPartIdx |
---|
633 | * \param uiDepth |
---|
634 | * \param uiWidth |
---|
635 | * \param uiHeight |
---|
636 | * \returns Void |
---|
637 | */ |
---|
638 | Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP ) |
---|
639 | { |
---|
640 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
641 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
642 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
643 | |
---|
644 | #if H_3D_DIM_SDC |
---|
645 | if( pcCU->getSDCFlag( uiAbsPartIdx ) ) |
---|
646 | { |
---|
647 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
648 | assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 ); |
---|
649 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 ); |
---|
650 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 ); |
---|
651 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 ); |
---|
652 | return; |
---|
653 | } |
---|
654 | #endif |
---|
655 | |
---|
656 | #if H_3D_INTER_SDC |
---|
657 | if( pcCU->getInterSDCFlag( uiAbsPartIdx ) ) |
---|
658 | { |
---|
659 | assert( !pcCU->isSkipped( uiAbsPartIdx ) ); |
---|
660 | assert( !pcCU->isIntra( uiAbsPartIdx) ); |
---|
661 | assert( pcCU->getSlice()->getIsDepth() ); |
---|
662 | |
---|
663 | decodeInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth ); |
---|
664 | return; |
---|
665 | } |
---|
666 | #endif |
---|
667 | |
---|
668 | if( pcCU->isIntra(uiAbsPartIdx) ) |
---|
669 | { |
---|
670 | } |
---|
671 | else |
---|
672 | { |
---|
673 | UInt uiQtRootCbf = 1; |
---|
674 | if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) ) |
---|
675 | { |
---|
676 | m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf ); |
---|
677 | } |
---|
678 | if ( !uiQtRootCbf ) |
---|
679 | { |
---|
680 | pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth ); |
---|
681 | pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth ); |
---|
682 | return; |
---|
683 | } |
---|
684 | |
---|
685 | } |
---|
686 | xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP ); |
---|
687 | } |
---|
688 | |
---|
689 | #if H_3D_INTER_SDC |
---|
690 | Void TDecEntropy::decodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
691 | { |
---|
692 | pcCU->setInterSDCFlagSubParts( false, uiAbsPartIdx, 0, uiDepth); |
---|
693 | |
---|
694 | if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) |
---|
695 | { |
---|
696 | return; |
---|
697 | } |
---|
698 | |
---|
699 | if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
700 | { |
---|
701 | return; |
---|
702 | } |
---|
703 | |
---|
704 | m_pcEntropyDecoderIf->parseInterSDCFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
705 | } |
---|
706 | |
---|
707 | Void TDecEntropy::decodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
708 | { |
---|
709 | if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) |
---|
710 | { |
---|
711 | return; |
---|
712 | } |
---|
713 | |
---|
714 | if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) ) |
---|
715 | { |
---|
716 | return; |
---|
717 | } |
---|
718 | |
---|
719 | UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 ); |
---|
720 | |
---|
721 | // decode residual data for each segment |
---|
722 | for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ ) |
---|
723 | { |
---|
724 | m_pcEntropyDecoderIf->parseInterSDCResidualData( pcCU, uiAbsPartIdx, uiDepth, uiSeg ); |
---|
725 | } |
---|
726 | } |
---|
727 | #endif |
---|
728 | |
---|
729 | //! \} |
---|