1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TDecEntropy.cpp |
---|
35 | \brief entropy decoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TDecEntropy.h" |
---|
39 | #include "TLibCommon/TComTU.h" |
---|
40 | |
---|
41 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
42 | #include "../TLibCommon/Debug.h" |
---|
43 | static const Bool bDebugRQT = DebugOptionList::DebugRQT.getInt()!=0; |
---|
44 | static const Bool bDebugPredEnabled = DebugOptionList::DebugPred.getInt()!=0; |
---|
45 | Bool g_bFinalEncode=true; |
---|
46 | #endif |
---|
47 | |
---|
48 | //! \ingroup TLibDecoder |
---|
49 | //! \{ |
---|
50 | |
---|
51 | Void TDecEntropy::setEntropyDecoder ( TDecEntropyIf* p ) |
---|
52 | { |
---|
53 | m_pcEntropyDecoderIf = p; |
---|
54 | } |
---|
55 | |
---|
56 | #include "TLibCommon/TComSampleAdaptiveOffset.h" |
---|
57 | |
---|
58 | Void TDecEntropy::decodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
59 | { |
---|
60 | m_pcEntropyDecoderIf->parseSkipFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | Void TDecEntropy::decodeCUTransquantBypassFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
65 | { |
---|
66 | m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | /** decode merge flag |
---|
71 | * \param pcSubCU |
---|
72 | * \param uiAbsPartIdx |
---|
73 | * \param uiDepth |
---|
74 | * \param uiPUIdx |
---|
75 | * \returns Void |
---|
76 | */ |
---|
77 | Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
78 | { |
---|
79 | // at least one merge candidate exists |
---|
80 | m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx ); |
---|
81 | } |
---|
82 | |
---|
83 | /** decode merge index |
---|
84 | * \param pcCU |
---|
85 | * \param uiPartIdx |
---|
86 | * \param uiAbsPartIdx |
---|
87 | * \param uiDepth |
---|
88 | * \returns Void |
---|
89 | */ |
---|
90 | Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
91 | { |
---|
92 | UInt uiMergeIndex = 0; |
---|
93 | m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex ); |
---|
94 | pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
95 | } |
---|
96 | |
---|
97 | Void TDecEntropy::decodeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
98 | { |
---|
99 | m_pcEntropyDecoderIf->parseSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
100 | } |
---|
101 | |
---|
102 | Void TDecEntropy::decodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
103 | { |
---|
104 | m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth ); |
---|
105 | } |
---|
106 | |
---|
107 | Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
108 | { |
---|
109 | m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
110 | } |
---|
111 | |
---|
112 | Void TDecEntropy::decodePredInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU ) |
---|
113 | { |
---|
114 | if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode. |
---|
115 | { |
---|
116 | decodeIntraDirModeLuma ( pcCU, uiAbsPartIdx, uiDepth ); |
---|
117 | if (pcCU->getPic()->getChromaFormat()!=CHROMA_400) |
---|
118 | { |
---|
119 | decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth ); |
---|
120 | if (enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) && pcCU->getPartitionSize( uiAbsPartIdx )==SIZE_NxN) |
---|
121 | { |
---|
122 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2; |
---|
123 | decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset, uiDepth+1 ); |
---|
124 | decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*2, uiDepth+1 ); |
---|
125 | decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*3, uiDepth+1 ); |
---|
126 | } |
---|
127 | } |
---|
128 | } |
---|
129 | else // if it is Inter mode, encode motion vector and reference index |
---|
130 | { |
---|
131 | decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU ); |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | /** Parse I_PCM information. |
---|
136 | * \param pcCU pointer to CUpointer to CU |
---|
137 | * \param uiAbsPartIdx CU index |
---|
138 | * \param uiDepth CU depth |
---|
139 | * \returns Void |
---|
140 | */ |
---|
141 | Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
142 | { |
---|
143 | if(!pcCU->getSlice()->getSPS()->getUsePCM() |
---|
144 | || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize()) |
---|
145 | || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) ) |
---|
146 | { |
---|
147 | return; |
---|
148 | } |
---|
149 | |
---|
150 | m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth ); |
---|
151 | } |
---|
152 | |
---|
153 | Void TDecEntropy::decodeIntraDirModeLuma ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
154 | { |
---|
155 | m_pcEntropyDecoderIf->parseIntraDirLumaAng( pcCU, uiAbsPartIdx, uiDepth ); |
---|
156 | } |
---|
157 | |
---|
158 | Void TDecEntropy::decodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
159 | { |
---|
160 | m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth ); |
---|
161 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
162 | if (bDebugPredEnabled) |
---|
163 | { |
---|
164 | UInt cdir=pcCU->getIntraDir(CHANNEL_TYPE_CHROMA, uiAbsPartIdx); |
---|
165 | if (cdir==36) |
---|
166 | { |
---|
167 | cdir=pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx); |
---|
168 | } |
---|
169 | printf("coding chroma Intra dir: %d, uiAbsPartIdx: %d, luma dir: %d\n", cdir, uiAbsPartIdx, pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx)); |
---|
170 | } |
---|
171 | #endif |
---|
172 | } |
---|
173 | |
---|
174 | |
---|
175 | /** decode motion information for every PU block. |
---|
176 | * \param pcCU |
---|
177 | * \param uiAbsPartIdx |
---|
178 | * \param uiDepth |
---|
179 | * \param pcSubCU |
---|
180 | * \returns Void |
---|
181 | */ |
---|
182 | Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU ) |
---|
183 | { |
---|
184 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
185 | UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) ); |
---|
186 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4; |
---|
187 | |
---|
188 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
189 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
190 | |
---|
191 | for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ ) |
---|
192 | { |
---|
193 | uhInterDirNeighbours[ui] = 0; |
---|
194 | } |
---|
195 | Int numValidMergeCand = 0; |
---|
196 | Bool hasMergedCandList = false; |
---|
197 | |
---|
198 | pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 ); |
---|
199 | pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 ); |
---|
200 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
201 | { |
---|
202 | decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
203 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
204 | { |
---|
205 | decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth ); |
---|
206 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
207 | if (bDebugPredEnabled) |
---|
208 | { |
---|
209 | std::cout << "Coded merge flag, CU absPartIdx: " << uiAbsPartIdx << " PU(" << uiPartIdx << ") absPartIdx: " << uiSubPartIdx; |
---|
210 | std::cout << " merge index: " << (UInt)pcCU->getMergeIndex(uiSubPartIdx) << std::endl; |
---|
211 | } |
---|
212 | #endif |
---|
213 | |
---|
214 | UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx); |
---|
215 | if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) |
---|
216 | { |
---|
217 | if ( !hasMergedCandList ) |
---|
218 | { |
---|
219 | pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); // temporarily set. |
---|
220 | pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
221 | pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth ); // restore. |
---|
222 | hasMergedCandList = true; |
---|
223 | } |
---|
224 | } |
---|
225 | else |
---|
226 | { |
---|
227 | uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx); |
---|
228 | pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex ); |
---|
229 | } |
---|
230 | |
---|
231 | pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); |
---|
232 | |
---|
233 | TComMv cTmpMv( 0, 0 ); |
---|
234 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
235 | { |
---|
236 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
237 | { |
---|
238 | pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth); |
---|
239 | pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth); |
---|
240 | pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
241 | pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
242 | |
---|
243 | } |
---|
244 | } |
---|
245 | } |
---|
246 | else |
---|
247 | { |
---|
248 | decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
249 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
250 | { |
---|
251 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
252 | { |
---|
253 | decodeRefFrmIdxPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
254 | decodeMvdPU ( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
255 | decodeMVPIdxPU ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
256 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
257 | if (bDebugPredEnabled) |
---|
258 | { |
---|
259 | std::cout << "refListIdx: " << uiRefListIdx << std::endl; |
---|
260 | std::cout << "MVD horizontal: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getHor() << std::endl; |
---|
261 | std::cout << "MVD vertical: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getVer() << std::endl; |
---|
262 | std::cout << "MVPIdxPU: " << pcCU->getMVPIdx(RefPicList( uiRefListIdx ), uiSubPartIdx) << std::endl; |
---|
263 | std::cout << "InterDir: " << (UInt)pcCU->getInterDir(uiSubPartIdx) << std::endl; |
---|
264 | } |
---|
265 | #endif |
---|
266 | } |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) ) |
---|
271 | { |
---|
272 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx); |
---|
273 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx); |
---|
274 | pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth); |
---|
275 | } |
---|
276 | } |
---|
277 | return; |
---|
278 | } |
---|
279 | |
---|
280 | /** decode inter direction for a PU block |
---|
281 | * \param pcCU |
---|
282 | * \param uiAbsPartIdx |
---|
283 | * \param uiDepth |
---|
284 | * \param uiPartIdx |
---|
285 | * \returns Void |
---|
286 | */ |
---|
287 | Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx ) |
---|
288 | { |
---|
289 | UInt uiInterDir; |
---|
290 | |
---|
291 | if ( pcCU->getSlice()->isInterP() ) |
---|
292 | { |
---|
293 | uiInterDir = 1; |
---|
294 | } |
---|
295 | else |
---|
296 | { |
---|
297 | m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx ); |
---|
298 | } |
---|
299 | |
---|
300 | pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
301 | } |
---|
302 | |
---|
303 | Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
304 | { |
---|
305 | Int iRefFrmIdx = 0; |
---|
306 | Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ); |
---|
307 | |
---|
308 | if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx ) |
---|
309 | { |
---|
310 | m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList ); |
---|
311 | } |
---|
312 | else if ( !iParseRefFrmIdx ) |
---|
313 | { |
---|
314 | iRefFrmIdx = NOT_VALID; |
---|
315 | } |
---|
316 | else |
---|
317 | { |
---|
318 | iRefFrmIdx = 0; |
---|
319 | } |
---|
320 | |
---|
321 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
322 | pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx ); |
---|
323 | } |
---|
324 | |
---|
325 | /** decode motion vector difference for a PU block |
---|
326 | * \param pcCU |
---|
327 | * \param uiAbsPartIdx |
---|
328 | * \param uiDepth |
---|
329 | * \param uiPartIdx |
---|
330 | * \param eRefList |
---|
331 | * \returns Void |
---|
332 | */ |
---|
333 | Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
334 | { |
---|
335 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
336 | { |
---|
337 | m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList ); |
---|
338 | } |
---|
339 | } |
---|
340 | |
---|
341 | Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
342 | { |
---|
343 | Int iMVPIdx = -1; |
---|
344 | |
---|
345 | TComMv cZeroMv( 0, 0 ); |
---|
346 | TComMv cMv = cZeroMv; |
---|
347 | Int iRefIdx = -1; |
---|
348 | |
---|
349 | TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList ); |
---|
350 | AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo(); |
---|
351 | |
---|
352 | iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr); |
---|
353 | cMv = cZeroMv; |
---|
354 | |
---|
355 | if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) ) |
---|
356 | { |
---|
357 | m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx ); |
---|
358 | } |
---|
359 | pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo); |
---|
360 | pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth); |
---|
361 | pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth ); |
---|
362 | if ( iRefIdx >= 0 ) |
---|
363 | { |
---|
364 | m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv); |
---|
365 | cMv += pcSubCUMvField->getMvd( uiPartAddr ); |
---|
366 | } |
---|
367 | |
---|
368 | PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr ); |
---|
369 | pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx); |
---|
370 | } |
---|
371 | |
---|
372 | Void TDecEntropy::xDecodeTransform ( Bool& bCodeDQP, Bool& isChromaQpAdjCoded, TComTU &rTu, const Int quadtreeTULog2MinSizeInCU ) |
---|
373 | { |
---|
374 | TComDataCU *pcCU=rTu.getCU(); |
---|
375 | const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(); |
---|
376 | const UInt uiDepth=rTu.GetTransformDepthTotal(); |
---|
377 | const UInt uiTrDepth = rTu.GetTransformDepthRel(); |
---|
378 | |
---|
379 | UInt uiSubdiv; |
---|
380 | const UInt numValidComponent = pcCU->getPic()->getNumberValidComponents(); |
---|
381 | const Bool bChroma = isChromaEnabled(pcCU->getPic()->getChromaFormat()); |
---|
382 | |
---|
383 | const UInt uiLog2TrafoSize = rTu.GetLog2LumaTrSize(); |
---|
384 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
385 | if (bDebugRQT) |
---|
386 | { |
---|
387 | printf("x..codeTransform: offsetLuma=%d offsetChroma=%d absPartIdx=%d, uiDepth=%d\n width=%d, height=%d, uiTrIdx=%d, uiInnerQuadIdx=%d\n", |
---|
388 | rTu.getCoefficientOffset(COMPONENT_Y), rTu.getCoefficientOffset(COMPONENT_Cb), uiAbsPartIdx, uiDepth, rTu.getRect(COMPONENT_Y).width, rTu.getRect(COMPONENT_Y).height, rTu.GetTransformDepthRel(), rTu.GetSectionNumber()); |
---|
389 | fflush(stdout); |
---|
390 | } |
---|
391 | #endif |
---|
392 | |
---|
393 | if( pcCU->isIntra(uiAbsPartIdx) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
394 | { |
---|
395 | uiSubdiv = 1; |
---|
396 | } |
---|
397 | else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->isInter(uiAbsPartIdx)) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) ) |
---|
398 | { |
---|
399 | uiSubdiv = (uiLog2TrafoSize >quadtreeTULog2MinSizeInCU); |
---|
400 | } |
---|
401 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
402 | { |
---|
403 | uiSubdiv = 1; |
---|
404 | } |
---|
405 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
406 | { |
---|
407 | uiSubdiv = 0; |
---|
408 | } |
---|
409 | else if( uiLog2TrafoSize == quadtreeTULog2MinSizeInCU ) |
---|
410 | { |
---|
411 | uiSubdiv = 0; |
---|
412 | } |
---|
413 | else |
---|
414 | { |
---|
415 | assert( uiLog2TrafoSize > quadtreeTULog2MinSizeInCU ); |
---|
416 | m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); |
---|
417 | } |
---|
418 | |
---|
419 | for(Int chan=COMPONENT_Cb; chan<numValidComponent; chan++) |
---|
420 | { |
---|
421 | const ComponentID compID=ComponentID(chan); |
---|
422 | const UInt trDepthTotalAdj=rTu.GetTransformDepthTotalAdj(compID); |
---|
423 | |
---|
424 | const Bool bFirstCbfOfCU = uiTrDepth == 0; |
---|
425 | |
---|
426 | if( bFirstCbfOfCU ) |
---|
427 | { |
---|
428 | pcCU->setCbfSubParts( 0, compID, rTu.GetAbsPartIdxTU(compID), trDepthTotalAdj); |
---|
429 | } |
---|
430 | if( bFirstCbfOfCU || rTu.ProcessingAllQuadrants(compID) ) |
---|
431 | { |
---|
432 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepth - 1 ) ) |
---|
433 | { |
---|
434 | m_pcEntropyDecoderIf->parseQtCbf( rTu, compID, (uiSubdiv == 0) ); |
---|
435 | } |
---|
436 | } |
---|
437 | } |
---|
438 | |
---|
439 | if( uiSubdiv ) |
---|
440 | { |
---|
441 | const UInt uiQPartNum = pcCU->getPic()->getNumPartitionsInCtu() >> ((uiDepth+1) << 1); |
---|
442 | UInt uiYUVCbf[MAX_NUM_COMPONENT] = {0,0,0}; |
---|
443 | |
---|
444 | TComTURecurse tuRecurseChild(rTu, true); |
---|
445 | |
---|
446 | do |
---|
447 | { |
---|
448 | xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurseChild, quadtreeTULog2MinSizeInCU ); |
---|
449 | UInt childTUAbsPartIdx=tuRecurseChild.GetAbsPartIdxTU(); |
---|
450 | for(UInt ch=0; ch<numValidComponent; ch++) |
---|
451 | { |
---|
452 | uiYUVCbf[ch] |= pcCU->getCbf(childTUAbsPartIdx , ComponentID(ch), uiTrDepth+1 ); |
---|
453 | } |
---|
454 | } while (tuRecurseChild.nextSection(rTu) ); |
---|
455 | |
---|
456 | for(UInt ch=0; ch<numValidComponent; ch++) |
---|
457 | { |
---|
458 | UChar *pBase = pcCU->getCbf( ComponentID(ch) ) + uiAbsPartIdx; |
---|
459 | const UChar flag = uiYUVCbf[ch] << uiTrDepth; |
---|
460 | |
---|
461 | for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui ) |
---|
462 | { |
---|
463 | pBase[ui] |= flag; |
---|
464 | } |
---|
465 | } |
---|
466 | } |
---|
467 | else |
---|
468 | { |
---|
469 | assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) ); |
---|
470 | pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth ); |
---|
471 | |
---|
472 | { |
---|
473 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
474 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
---|
475 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
476 | DTRACE_CABAC_T( "\tdepth=" ); |
---|
477 | DTRACE_CABAC_V( uiDepth ); |
---|
478 | DTRACE_CABAC_T( "\ttrdepth=" ); |
---|
479 | DTRACE_CABAC_V( uiTrDepth ); |
---|
480 | DTRACE_CABAC_T( "\n" ); |
---|
481 | } |
---|
482 | |
---|
483 | pcCU->setCbfSubParts ( 0, COMPONENT_Y, uiAbsPartIdx, uiDepth ); |
---|
484 | |
---|
485 | if( (!pcCU->isIntra(uiAbsPartIdx)) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && ((!bChroma) || (!pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cb, 0 ) && !pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cr, 0 )) )) |
---|
486 | { |
---|
487 | pcCU->setCbfSubParts( 1 << uiTrDepth, COMPONENT_Y, uiAbsPartIdx, uiDepth ); |
---|
488 | } |
---|
489 | else |
---|
490 | { |
---|
491 | m_pcEntropyDecoderIf->parseQtCbf( rTu, COMPONENT_Y, true ); |
---|
492 | } |
---|
493 | |
---|
494 | |
---|
495 | // transform_unit begin |
---|
496 | UInt cbf[MAX_NUM_COMPONENT]={0,0,0}; |
---|
497 | Bool validCbf = false; |
---|
498 | Bool validChromaCbf = false; |
---|
499 | const UInt uiTrIdx = rTu.GetTransformDepthRel(); |
---|
500 | |
---|
501 | for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++) |
---|
502 | { |
---|
503 | const ComponentID compID = ComponentID(ch); |
---|
504 | |
---|
505 | cbf[compID] = pcCU->getCbf( uiAbsPartIdx, compID, uiTrIdx ); |
---|
506 | |
---|
507 | if (cbf[compID] != 0) |
---|
508 | { |
---|
509 | validCbf = true; |
---|
510 | if (isChroma(compID)) |
---|
511 | { |
---|
512 | validChromaCbf = true; |
---|
513 | } |
---|
514 | } |
---|
515 | } |
---|
516 | |
---|
517 | if ( validCbf ) |
---|
518 | { |
---|
519 | |
---|
520 | // dQP: only for CTU |
---|
521 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
522 | { |
---|
523 | if ( bCodeDQP ) |
---|
524 | { |
---|
525 | const UInt uiAbsPartIdxCU=rTu.GetAbsPartIdxCU(); |
---|
526 | decodeQP( pcCU, uiAbsPartIdxCU); |
---|
527 | bCodeDQP = false; |
---|
528 | } |
---|
529 | } |
---|
530 | |
---|
531 | if ( pcCU->getSlice()->getUseChromaQpAdj() ) |
---|
532 | { |
---|
533 | if ( validChromaCbf && isChromaQpAdjCoded && !pcCU->getCUTransquantBypass(rTu.GetAbsPartIdxCU()) ) |
---|
534 | { |
---|
535 | decodeChromaQpAdjustment( pcCU, rTu.GetAbsPartIdxCU() ); |
---|
536 | isChromaQpAdjCoded = false; |
---|
537 | } |
---|
538 | } |
---|
539 | |
---|
540 | const UInt numValidComp=pcCU->getPic()->getNumberValidComponents(); |
---|
541 | |
---|
542 | for(UInt ch=COMPONENT_Y; ch<numValidComp; ch++) |
---|
543 | { |
---|
544 | const ComponentID compID=ComponentID(ch); |
---|
545 | |
---|
546 | if( rTu.ProcessComponentSection(compID) ) |
---|
547 | { |
---|
548 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
549 | if (bDebugRQT) |
---|
550 | { |
---|
551 | printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, rTu.getRect(compID).width, rTu.getRect(compID).height, 1); |
---|
552 | } |
---|
553 | #endif |
---|
554 | |
---|
555 | if (rTu.getRect(compID).width != rTu.getRect(compID).height) |
---|
556 | { |
---|
557 | //code two sub-TUs |
---|
558 | TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID); |
---|
559 | |
---|
560 | do |
---|
561 | { |
---|
562 | const UInt subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(), compID, (uiTrIdx + 1)); |
---|
563 | |
---|
564 | if (subTUCBF != 0) |
---|
565 | { |
---|
566 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
567 | if (bDebugRQT) |
---|
568 | { |
---|
569 | printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, subTUIterator.getRect(compID).width, subTUIterator.getRect(compID).height, 1); |
---|
570 | } |
---|
571 | #endif |
---|
572 | m_pcEntropyDecoderIf->parseCoeffNxN( subTUIterator, compID ); |
---|
573 | } |
---|
574 | } while (subTUIterator.nextSection(rTu)); |
---|
575 | } |
---|
576 | else |
---|
577 | { |
---|
578 | if(isChroma(compID) && (cbf[COMPONENT_Y] != 0)) |
---|
579 | { |
---|
580 | m_pcEntropyDecoderIf->parseCrossComponentPrediction( rTu, compID ); |
---|
581 | } |
---|
582 | |
---|
583 | if(cbf[compID] != 0) |
---|
584 | { |
---|
585 | m_pcEntropyDecoderIf->parseCoeffNxN( rTu, compID ); |
---|
586 | } |
---|
587 | } |
---|
588 | } |
---|
589 | } |
---|
590 | } |
---|
591 | // transform_unit end |
---|
592 | } |
---|
593 | } |
---|
594 | |
---|
595 | Void TDecEntropy::decodeQP ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
596 | { |
---|
597 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
598 | { |
---|
599 | m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) ); |
---|
600 | } |
---|
601 | } |
---|
602 | |
---|
603 | Void TDecEntropy::decodeChromaQpAdjustment( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
604 | { |
---|
605 | if ( pcCU->getSlice()->getUseChromaQpAdj() ) |
---|
606 | { |
---|
607 | m_pcEntropyDecoderIf->parseChromaQpAdjustment( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) ); |
---|
608 | } |
---|
609 | } |
---|
610 | |
---|
611 | |
---|
612 | /** decode coefficients |
---|
613 | * \param pcCU |
---|
614 | * \param uiAbsPartIdx |
---|
615 | * \param uiDepth |
---|
616 | * \param uiWidth |
---|
617 | * \param uiHeight |
---|
618 | * \returns Void |
---|
619 | */ |
---|
620 | Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool& bCodeDQP, Bool& isChromaQpAdjCoded ) |
---|
621 | { |
---|
622 | if( pcCU->isIntra(uiAbsPartIdx) ) |
---|
623 | { |
---|
624 | } |
---|
625 | else |
---|
626 | { |
---|
627 | UInt uiQtRootCbf = 1; |
---|
628 | if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) ) |
---|
629 | { |
---|
630 | m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf ); |
---|
631 | } |
---|
632 | if ( !uiQtRootCbf ) |
---|
633 | { |
---|
634 | static const UInt cbfZero[MAX_NUM_COMPONENT]={0,0,0}; |
---|
635 | pcCU->setCbfSubParts( cbfZero, uiAbsPartIdx, uiDepth ); |
---|
636 | pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth ); |
---|
637 | return; |
---|
638 | } |
---|
639 | |
---|
640 | } |
---|
641 | |
---|
642 | TComTURecurse tuRecurse(pcCU, uiAbsPartIdx, uiDepth); |
---|
643 | |
---|
644 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
645 | if (bDebugRQT) |
---|
646 | { |
---|
647 | printf("..codeCoeff: uiAbsPartIdx=%d, PU format=%d, 2Nx2N=%d, NxN=%d\n", uiAbsPartIdx, pcCU->getPartitionSize(uiAbsPartIdx), SIZE_2Nx2N, SIZE_NxN); |
---|
648 | } |
---|
649 | #endif |
---|
650 | |
---|
651 | Int quadtreeTULog2MinSizeInCU = pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx); |
---|
652 | |
---|
653 | xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurse, quadtreeTULog2MinSizeInCU ); |
---|
654 | } |
---|
655 | |
---|
656 | //! \} |
---|