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-2015, 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 | #include "TLibCommon/TComPrediction.h" |
---|
41 | |
---|
42 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
43 | #include "../TLibCommon/Debug.h" |
---|
44 | static const Bool bDebugRQT = DebugOptionList::DebugRQT.getInt()!=0; |
---|
45 | static const Bool bDebugPredEnabled = DebugOptionList::DebugPred.getInt()!=0; |
---|
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 | #if H_3D |
---|
63 | Void TDecEntropy::decodeDIS( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
64 | { |
---|
65 | if( !pcCU->getSlice()->getDepthIntraSkipFlag() ) |
---|
66 | { |
---|
67 | return; |
---|
68 | } |
---|
69 | |
---|
70 | m_pcEntropyDecoderIf->parseDIS( pcCU, uiAbsPartIdx, uiDepth ); |
---|
71 | } |
---|
72 | #endif |
---|
73 | |
---|
74 | Void TDecEntropy::decodeCUTransquantBypassFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
75 | { |
---|
76 | m_pcEntropyDecoderIf->parseCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | /** decode merge flag |
---|
81 | * \param pcSubCU |
---|
82 | * \param uiAbsPartIdx |
---|
83 | * \param uiDepth |
---|
84 | * \param uiPUIdx |
---|
85 | * \returns Void |
---|
86 | */ |
---|
87 | Void TDecEntropy::decodeMergeFlag( TComDataCU* pcSubCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
88 | { |
---|
89 | // at least one merge candidate exists |
---|
90 | m_pcEntropyDecoderIf->parseMergeFlag( pcSubCU, uiAbsPartIdx, uiDepth, uiPUIdx ); |
---|
91 | } |
---|
92 | |
---|
93 | /** decode merge index |
---|
94 | * \param pcCU |
---|
95 | * \param uiPartIdx |
---|
96 | * \param uiAbsPartIdx |
---|
97 | * \param uiDepth |
---|
98 | * \returns Void |
---|
99 | */ |
---|
100 | Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
101 | { |
---|
102 | UInt uiMergeIndex = 0; |
---|
103 | m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex ); |
---|
104 | pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
105 | } |
---|
106 | |
---|
107 | #if H_3D_ARP |
---|
108 | Void TDecEntropy::decodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
109 | { |
---|
110 | if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) ) |
---|
111 | { |
---|
112 | return; |
---|
113 | } |
---|
114 | |
---|
115 | if( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) |
---|
116 | { |
---|
117 | pcCU->setARPWSubParts( 0 , uiAbsPartIdx, uiDepth ); |
---|
118 | } |
---|
119 | else |
---|
120 | { |
---|
121 | m_pcEntropyDecoderIf->parseARPW( pcCU , uiAbsPartIdx , uiDepth ); |
---|
122 | } |
---|
123 | } |
---|
124 | #endif |
---|
125 | |
---|
126 | #if H_3D_IC |
---|
127 | Void TDecEntropy::decodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
128 | { |
---|
129 | pcCU->setICFlagSubParts( false , uiAbsPartIdx, 0, uiDepth ); |
---|
130 | |
---|
131 | if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() || pcCU->getARPW( uiAbsPartIdx ) > 0 ) |
---|
132 | { |
---|
133 | return; |
---|
134 | } |
---|
135 | |
---|
136 | if( !pcCU->getSlice()->getApplyIC() ) |
---|
137 | return; |
---|
138 | |
---|
139 | if( pcCU->isICFlagRequired( uiAbsPartIdx ) ) |
---|
140 | m_pcEntropyDecoderIf->parseICFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
141 | } |
---|
142 | #endif |
---|
143 | |
---|
144 | Void TDecEntropy::decodeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
145 | { |
---|
146 | m_pcEntropyDecoderIf->parseSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
147 | } |
---|
148 | |
---|
149 | Void TDecEntropy::decodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
150 | { |
---|
151 | m_pcEntropyDecoderIf->parsePredMode( pcCU, uiAbsPartIdx, uiDepth ); |
---|
152 | } |
---|
153 | |
---|
154 | Void TDecEntropy::decodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
155 | { |
---|
156 | m_pcEntropyDecoderIf->parsePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
157 | } |
---|
158 | |
---|
159 | Void TDecEntropy::decodePredInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU ) |
---|
160 | { |
---|
161 | if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode. |
---|
162 | { |
---|
163 | decodeIntraDirModeLuma ( pcCU, uiAbsPartIdx, uiDepth ); |
---|
164 | #if NH_3D_SDC_INTRA |
---|
165 | decodeSDCFlag ( pcCU, uiAbsPartIdx, uiDepth ); |
---|
166 | #endif |
---|
167 | if (pcCU->getPic()->getChromaFormat()!=CHROMA_400) |
---|
168 | { |
---|
169 | decodeIntraDirModeChroma( pcCU, uiAbsPartIdx, uiDepth ); |
---|
170 | if (enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) && pcCU->getPartitionSize( uiAbsPartIdx )==SIZE_NxN) |
---|
171 | { |
---|
172 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2; |
---|
173 | decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset, uiDepth+1 ); |
---|
174 | decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*2, uiDepth+1 ); |
---|
175 | decodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*3, uiDepth+1 ); |
---|
176 | } |
---|
177 | } |
---|
178 | } |
---|
179 | else // if it is Inter mode, encode motion vector and reference index |
---|
180 | { |
---|
181 | decodePUWise( pcCU, uiAbsPartIdx, uiDepth, pcSubCU ); |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | /** Parse I_PCM information. |
---|
186 | * \param pcCU pointer to CUpointer to CU |
---|
187 | * \param uiAbsPartIdx CU index |
---|
188 | * \param uiDepth CU depth |
---|
189 | * \returns Void |
---|
190 | */ |
---|
191 | Void TDecEntropy::decodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
192 | { |
---|
193 | if(!pcCU->getSlice()->getSPS()->getUsePCM() |
---|
194 | || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize()) |
---|
195 | || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize()) ) |
---|
196 | { |
---|
197 | return; |
---|
198 | } |
---|
199 | |
---|
200 | m_pcEntropyDecoderIf->parseIPCMInfo( pcCU, uiAbsPartIdx, uiDepth ); |
---|
201 | } |
---|
202 | |
---|
203 | Void TDecEntropy::decodeIntraDirModeLuma ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
204 | { |
---|
205 | m_pcEntropyDecoderIf->parseIntraDirLumaAng( pcCU, uiAbsPartIdx, uiDepth ); |
---|
206 | } |
---|
207 | |
---|
208 | Void TDecEntropy::decodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
209 | { |
---|
210 | m_pcEntropyDecoderIf->parseIntraDirChroma( pcCU, uiAbsPartIdx, uiDepth ); |
---|
211 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
212 | if (bDebugPredEnabled) |
---|
213 | { |
---|
214 | UInt cdir=pcCU->getIntraDir(CHANNEL_TYPE_CHROMA, uiAbsPartIdx); |
---|
215 | if (cdir==36) |
---|
216 | { |
---|
217 | cdir=pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx); |
---|
218 | } |
---|
219 | printf("coding chroma Intra dir: %d, uiAbsPartIdx: %d, luma dir: %d\n", cdir, uiAbsPartIdx, pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx)); |
---|
220 | } |
---|
221 | #endif |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | /** decode motion information for every PU block. |
---|
226 | * \param pcCU |
---|
227 | * \param uiAbsPartIdx |
---|
228 | * \param uiDepth |
---|
229 | * \param pcSubCU |
---|
230 | * \returns Void |
---|
231 | */ |
---|
232 | Void TDecEntropy::decodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU ) |
---|
233 | { |
---|
234 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
235 | UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) ); |
---|
236 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxTotalCUDepth() - uiDepth ) << 1 ) ) >> 4; |
---|
237 | #if H_3D_IV_MERGE |
---|
238 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists |
---|
239 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM]; |
---|
240 | #else |
---|
241 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
242 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
243 | #endif |
---|
244 | #if H_3D_SPIVMP |
---|
245 | Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM]; |
---|
246 | TComMvField* pcMvFieldSP = new TComMvField[pcCU->getPic()->getPicSym()->getNumPartition()*2]; |
---|
247 | UChar* puhInterDirSP = new UChar[pcCU->getPic()->getPicSym()->getNumPartition()]; |
---|
248 | #endif |
---|
249 | #if H_3D_IV_MERGE |
---|
250 | pcSubCU->copyDVInfoFrom( pcCU, uiAbsPartIdx); |
---|
251 | #endif |
---|
252 | for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ ) |
---|
253 | { |
---|
254 | uhInterDirNeighbours[ui] = 0; |
---|
255 | } |
---|
256 | Int numValidMergeCand = 0; |
---|
257 | Bool hasMergedCandList = false; |
---|
258 | |
---|
259 | pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 ); |
---|
260 | pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 ); |
---|
261 | #if H_3D |
---|
262 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
263 | { |
---|
264 | #if H_MV_ENC_DEC_TRAC |
---|
265 | DTRACE_PU_S("=========== prediction_unit ===========\n") |
---|
266 | // ToDo: |
---|
267 | //DTRACE_PU("x0", uiLPelX) |
---|
268 | //DTRACE_PU("x1", uiTPelY) |
---|
269 | #endif |
---|
270 | |
---|
271 | ////// Parse PUs syntax |
---|
272 | decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
273 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
274 | { |
---|
275 | decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth ); |
---|
276 | } |
---|
277 | else |
---|
278 | { |
---|
279 | decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
280 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
281 | { |
---|
282 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
283 | { |
---|
284 | decodeRefFrmIdxPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
285 | decodeMvdPU ( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
286 | decodeMVPIdxPU ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
287 | } |
---|
288 | } |
---|
289 | } |
---|
290 | } |
---|
291 | |
---|
292 | ////// Parse CUs extension syntax |
---|
293 | decodeDBBPFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
294 | decodeSDCFlag ( pcCU, uiAbsPartIdx, uiDepth ); |
---|
295 | |
---|
296 | #if H_3D_ARP |
---|
297 | decodeARPW ( pcCU, uiAbsPartIdx, uiDepth ); |
---|
298 | #endif |
---|
299 | #if H_3D_IC |
---|
300 | decodeICFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
301 | #endif |
---|
302 | |
---|
303 | ////// Decode motion vectors |
---|
304 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
305 | { |
---|
306 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
307 | { |
---|
308 | UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx); |
---|
309 | #if H_3D_DBBP |
---|
310 | if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 && pcCU->getDBBPFlag(uiAbsPartIdx) == false ) |
---|
311 | #else |
---|
312 | if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) |
---|
313 | #endif |
---|
314 | { |
---|
315 | pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
316 | if ( !isMerged ) |
---|
317 | { |
---|
318 | #if H_3D_VSP |
---|
319 | Int vspFlag[MRG_MAX_NUM_CANDS_MEM]; |
---|
320 | memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM); |
---|
321 | #if H_3D_SPIVMP |
---|
322 | memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM); |
---|
323 | #endif |
---|
324 | pcSubCU->initAvailableFlags(); |
---|
325 | pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand); |
---|
326 | pcSubCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours |
---|
327 | #if H_3D_SPIVMP |
---|
328 | , pcMvFieldSP, puhInterDirSP |
---|
329 | #endif |
---|
330 | , numValidMergeCand ); |
---|
331 | pcSubCU->buildMCL( cMvFieldNeighbours, uhInterDirNeighbours, vspFlag |
---|
332 | #if H_3D_SPIVMP |
---|
333 | , bSPIVMPFlag |
---|
334 | #endif |
---|
335 | , numValidMergeCand ); |
---|
336 | pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); |
---|
337 | |
---|
338 | #else |
---|
339 | #if H_3D |
---|
340 | pcSubCU->initAvailableFlags(); |
---|
341 | pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand); |
---|
342 | pcSubCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
343 | |
---|
344 | #else |
---|
345 | pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
346 | #endif |
---|
347 | #endif |
---|
348 | isMerged = true; |
---|
349 | } |
---|
350 | pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth ); |
---|
351 | } |
---|
352 | else |
---|
353 | { |
---|
354 | uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx); |
---|
355 | #if H_3D_VSP |
---|
356 | Int vspFlag[MRG_MAX_NUM_CANDS_MEM]; |
---|
357 | memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM); |
---|
358 | #if H_3D_SPIVMP |
---|
359 | memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM); |
---|
360 | #endif |
---|
361 | pcSubCU->initAvailableFlags(); |
---|
362 | pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex ); |
---|
363 | pcSubCU->xGetInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours |
---|
364 | #if H_3D_SPIVMP |
---|
365 | , pcMvFieldSP, puhInterDirSP |
---|
366 | #endif |
---|
367 | ,numValidMergeCand, uiMergeIndex ); |
---|
368 | pcSubCU->buildMCL( cMvFieldNeighbours, uhInterDirNeighbours, vspFlag |
---|
369 | #if H_3D_SPIVMP |
---|
370 | , bSPIVMPFlag |
---|
371 | #endif |
---|
372 | ,numValidMergeCand ); |
---|
373 | pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); |
---|
374 | #else |
---|
375 | #if H_3D |
---|
376 | pcSubCU->initAvailableFlags(); |
---|
377 | pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex ); |
---|
378 | pcSubCU->xGetInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex ); |
---|
379 | #else |
---|
380 | pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex ); |
---|
381 | #endif |
---|
382 | #endif |
---|
383 | } |
---|
384 | pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); |
---|
385 | |
---|
386 | TComMv cTmpMv( 0, 0 ); |
---|
387 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
388 | { |
---|
389 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
390 | { |
---|
391 | pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth); |
---|
392 | pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth); |
---|
393 | pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
394 | pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
395 | #if H_3D_VSP |
---|
396 | #if H_3D_DBBP |
---|
397 | if( pcCU->getVSPFlag( uiSubPartIdx ) != 0 && !pcCU->getDBBPFlag( uiAbsPartIdx ) ) |
---|
398 | #else |
---|
399 | if( pcCU->getVSPFlag( uiSubPartIdx ) != 0 ) |
---|
400 | #endif |
---|
401 | { |
---|
402 | if ( uhInterDirNeighbours[ uiMergeIndex ] & (1<<uiRefListIdx) ) |
---|
403 | { |
---|
404 | UInt dummy; |
---|
405 | Int vspSize; |
---|
406 | Int width, height; |
---|
407 | pcCU->getPartIndexAndSize( uiPartIdx, dummy, width, height, uiSubPartIdx, pcCU->getTotalNumPart()==256 ); |
---|
408 | pcCU->setMvFieldPUForVSP( pcCU, uiSubPartIdx, width, height, RefPicList( uiRefListIdx ), cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx(), vspSize ); |
---|
409 | pcCU->setVSPFlag( uiSubPartIdx, vspSize ); |
---|
410 | } |
---|
411 | } |
---|
412 | #endif |
---|
413 | } |
---|
414 | } |
---|
415 | #if H_3D_SPIVMP |
---|
416 | pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); |
---|
417 | if (bSPIVMPFlag[uiMergeIndex] != 0) |
---|
418 | { |
---|
419 | Int iWidth, iHeight; |
---|
420 | UInt uiIdx; |
---|
421 | pcCU->getPartIndexAndSize( uiPartIdx, uiIdx, iWidth, iHeight, uiSubPartIdx, true ); |
---|
422 | |
---|
423 | UInt uiSPAddr; |
---|
424 | |
---|
425 | Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; |
---|
426 | |
---|
427 | pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); |
---|
428 | |
---|
429 | for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++) |
---|
430 | { |
---|
431 | pcCU->getSPAbsPartIdx(uiSubPartIdx, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr); |
---|
432 | pcCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight); |
---|
433 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight); |
---|
434 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight); |
---|
435 | } |
---|
436 | } |
---|
437 | #endif |
---|
438 | } |
---|
439 | else |
---|
440 | { |
---|
441 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
442 | { |
---|
443 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
444 | { |
---|
445 | decodeMvsAMVP ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
446 | } |
---|
447 | } |
---|
448 | } |
---|
449 | |
---|
450 | if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) ) |
---|
451 | { |
---|
452 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx); |
---|
453 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx); |
---|
454 | pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth); |
---|
455 | } |
---|
456 | } |
---|
457 | #else |
---|
458 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
459 | { |
---|
460 | #if H_MV_ENC_DEC_TRAC |
---|
461 | DTRACE_PU_S("=========== prediction_unit ===========\n") |
---|
462 | // ToDo: |
---|
463 | //DTRACE_PU("x0", uiLPelX) |
---|
464 | //DTRACE_PU("x1", uiTPelY) |
---|
465 | #endif |
---|
466 | decodeMergeFlag( pcCU, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
467 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
468 | { |
---|
469 | decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth ); |
---|
470 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
471 | if (bDebugPredEnabled) |
---|
472 | { |
---|
473 | std::cout << "Coded merge flag, CU absPartIdx: " << uiAbsPartIdx << " PU(" << uiPartIdx << ") absPartIdx: " << uiSubPartIdx; |
---|
474 | std::cout << " merge index: " << (UInt)pcCU->getMergeIndex(uiSubPartIdx) << std::endl; |
---|
475 | } |
---|
476 | #endif |
---|
477 | |
---|
478 | UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx); |
---|
479 | if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) |
---|
480 | { |
---|
481 | if ( !hasMergedCandList ) |
---|
482 | { |
---|
483 | pcSubCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); // temporarily set. |
---|
484 | pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
485 | pcSubCU->setPartSizeSubParts( ePartSize, 0, uiDepth ); // restore. |
---|
486 | hasMergedCandList = true; |
---|
487 | } |
---|
488 | } |
---|
489 | else |
---|
490 | { |
---|
491 | uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx); |
---|
492 | pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex ); |
---|
493 | } |
---|
494 | |
---|
495 | pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth ); |
---|
496 | |
---|
497 | TComMv cTmpMv( 0, 0 ); |
---|
498 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
499 | { |
---|
500 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
501 | { |
---|
502 | pcCU->setMVPIdxSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth); |
---|
503 | pcCU->setMVPNumSubParts( 0, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, uiDepth); |
---|
504 | pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
505 | pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], ePartSize, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
506 | |
---|
507 | } |
---|
508 | } |
---|
509 | } |
---|
510 | else |
---|
511 | { |
---|
512 | decodeInterDirPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx ); |
---|
513 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
514 | { |
---|
515 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
516 | { |
---|
517 | decodeRefFrmIdxPU( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
518 | decodeMvdPU ( pcCU, uiSubPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
519 | decodeMVPIdxPU ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) ); |
---|
520 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
521 | if (bDebugPredEnabled) |
---|
522 | { |
---|
523 | std::cout << "refListIdx: " << uiRefListIdx << std::endl; |
---|
524 | std::cout << "MVD horizontal: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getHor() << std::endl; |
---|
525 | std::cout << "MVD vertical: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getVer() << std::endl; |
---|
526 | std::cout << "MVPIdxPU: " << pcCU->getMVPIdx(RefPicList( uiRefListIdx ), uiSubPartIdx) << std::endl; |
---|
527 | std::cout << "InterDir: " << (UInt)pcCU->getInterDir(uiSubPartIdx) << std::endl; |
---|
528 | } |
---|
529 | #endif |
---|
530 | } |
---|
531 | } |
---|
532 | } |
---|
533 | |
---|
534 | if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) ) |
---|
535 | { |
---|
536 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx); |
---|
537 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( -1, ePartSize, uiSubPartIdx, uiDepth, uiPartIdx); |
---|
538 | pcCU->setInterDirSubParts( 1, uiSubPartIdx, uiPartIdx, uiDepth); |
---|
539 | } |
---|
540 | } |
---|
541 | #endif |
---|
542 | #if H_3D_SPIVMP |
---|
543 | delete[] pcMvFieldSP; |
---|
544 | delete[] puhInterDirSP; |
---|
545 | #endif |
---|
546 | return; |
---|
547 | } |
---|
548 | |
---|
549 | /** decode inter direction for a PU block |
---|
550 | * \param pcCU |
---|
551 | * \param uiAbsPartIdx |
---|
552 | * \param uiDepth |
---|
553 | * \param uiPartIdx |
---|
554 | * \returns Void |
---|
555 | */ |
---|
556 | Void TDecEntropy::decodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx ) |
---|
557 | { |
---|
558 | UInt uiInterDir; |
---|
559 | |
---|
560 | if ( pcCU->getSlice()->isInterP() ) |
---|
561 | { |
---|
562 | uiInterDir = 1; |
---|
563 | } |
---|
564 | else |
---|
565 | { |
---|
566 | m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx ); |
---|
567 | } |
---|
568 | |
---|
569 | pcCU->setInterDirSubParts( uiInterDir, uiAbsPartIdx, uiPartIdx, uiDepth ); |
---|
570 | } |
---|
571 | |
---|
572 | Void TDecEntropy::decodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
573 | { |
---|
574 | Int iRefFrmIdx = 0; |
---|
575 | Int iParseRefFrmIdx = pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ); |
---|
576 | |
---|
577 | if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx ) |
---|
578 | { |
---|
579 | m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList ); |
---|
580 | } |
---|
581 | else if ( !iParseRefFrmIdx ) |
---|
582 | { |
---|
583 | iRefFrmIdx = NOT_VALID; |
---|
584 | } |
---|
585 | else |
---|
586 | { |
---|
587 | iRefFrmIdx = 0; |
---|
588 | } |
---|
589 | |
---|
590 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
591 | pcCU->getCUMvField( eRefList )->setAllRefIdx( iRefFrmIdx, ePartSize, uiAbsPartIdx, uiDepth, uiPartIdx ); |
---|
592 | } |
---|
593 | |
---|
594 | /** decode motion vector difference for a PU block |
---|
595 | * \param pcCU |
---|
596 | * \param uiAbsPartIdx |
---|
597 | * \param uiDepth |
---|
598 | * \param uiPartIdx |
---|
599 | * \param eRefList |
---|
600 | * \returns Void |
---|
601 | */ |
---|
602 | Void TDecEntropy::decodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
603 | { |
---|
604 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
605 | { |
---|
606 | m_pcEntropyDecoderIf->parseMvd( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth, eRefList ); |
---|
607 | } |
---|
608 | } |
---|
609 | |
---|
610 | #if H_3D |
---|
611 | Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
612 | { |
---|
613 | Int iMVPIdx = -1; |
---|
614 | |
---|
615 | if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) ) |
---|
616 | { |
---|
617 | m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx ); |
---|
618 | #if H_MV_ENC_DEC_TRAC |
---|
619 | #if ENC_DEC_TRACE |
---|
620 | if ( eRefList == REF_PIC_LIST_0 ) |
---|
621 | { |
---|
622 | DTRACE_PU("mvp_l0_flag", iMVPIdx) |
---|
623 | } |
---|
624 | else |
---|
625 | { |
---|
626 | DTRACE_PU("mvp_l1_flag", iMVPIdx) |
---|
627 | } |
---|
628 | #endif |
---|
629 | #endif |
---|
630 | } |
---|
631 | pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth ); |
---|
632 | } |
---|
633 | |
---|
634 | Void TDecEntropy::decodeMvsAMVP( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
635 | { |
---|
636 | TComMv cZeroMv( 0, 0 ); |
---|
637 | TComMv cMv = cZeroMv; |
---|
638 | Int iRefIdx = -1; |
---|
639 | |
---|
640 | TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList ); |
---|
641 | AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo(); |
---|
642 | |
---|
643 | iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr); |
---|
644 | cMv = cZeroMv; |
---|
645 | |
---|
646 | pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo); |
---|
647 | pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth); |
---|
648 | if ( iRefIdx >= 0 ) |
---|
649 | { |
---|
650 | m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv); |
---|
651 | cMv += pcSubCUMvField->getMvd( uiPartAddr ); |
---|
652 | } |
---|
653 | |
---|
654 | PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr ); |
---|
655 | pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx); |
---|
656 | } |
---|
657 | #else |
---|
658 | Void TDecEntropy::decodeMVPIdxPU( TComDataCU* pcSubCU, UInt uiPartAddr, UInt uiDepth, UInt uiPartIdx, RefPicList eRefList ) |
---|
659 | { |
---|
660 | Int iMVPIdx = -1; |
---|
661 | |
---|
662 | TComMv cZeroMv( 0, 0 ); |
---|
663 | TComMv cMv = cZeroMv; |
---|
664 | Int iRefIdx = -1; |
---|
665 | |
---|
666 | TComCUMvField* pcSubCUMvField = pcSubCU->getCUMvField( eRefList ); |
---|
667 | AMVPInfo* pAMVPInfo = pcSubCUMvField->getAMVPInfo(); |
---|
668 | |
---|
669 | iRefIdx = pcSubCUMvField->getRefIdx(uiPartAddr); |
---|
670 | cMv = cZeroMv; |
---|
671 | |
---|
672 | if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) ) |
---|
673 | { |
---|
674 | m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx ); |
---|
675 | #if H_MV_ENC_DEC_TRAC |
---|
676 | #if ENC_DEC_TRACE |
---|
677 | if ( eRefList == REF_PIC_LIST_0 ) |
---|
678 | { |
---|
679 | DTRACE_PU("mvp_l0_flag", iMVPIdx) |
---|
680 | } |
---|
681 | else |
---|
682 | { |
---|
683 | DTRACE_PU("mvp_l1_flag", iMVPIdx) |
---|
684 | } |
---|
685 | #endif |
---|
686 | #endif |
---|
687 | } |
---|
688 | pcSubCU->fillMvpCand(uiPartIdx, uiPartAddr, eRefList, iRefIdx, pAMVPInfo); |
---|
689 | pcSubCU->setMVPNumSubParts(pAMVPInfo->iN, eRefList, uiPartAddr, uiPartIdx, uiDepth); |
---|
690 | pcSubCU->setMVPIdxSubParts( iMVPIdx, eRefList, uiPartAddr, uiPartIdx, uiDepth ); |
---|
691 | if ( iRefIdx >= 0 ) |
---|
692 | { |
---|
693 | m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv); |
---|
694 | cMv += pcSubCUMvField->getMvd( uiPartAddr ); |
---|
695 | } |
---|
696 | |
---|
697 | PartSize ePartSize = pcSubCU->getPartitionSize( uiPartAddr ); |
---|
698 | pcSubCU->getCUMvField( eRefList )->setAllMv(cMv, ePartSize, uiPartAddr, 0, uiPartIdx); |
---|
699 | } |
---|
700 | #endif |
---|
701 | |
---|
702 | Void TDecEntropy::xDecodeTransform ( Bool& bCodeDQP, Bool& isChromaQpAdjCoded, TComTU &rTu, const Int quadtreeTULog2MinSizeInCU ) |
---|
703 | { |
---|
704 | |
---|
705 | TComDataCU *pcCU=rTu.getCU(); |
---|
706 | const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU(); |
---|
707 | const UInt uiDepth=rTu.GetTransformDepthTotal(); |
---|
708 | const UInt uiTrDepth = rTu.GetTransformDepthRel(); |
---|
709 | |
---|
710 | #if H_MV_ENC_DEC_TRAC |
---|
711 | #if ENC_DEC_TRACE |
---|
712 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
713 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
714 | |
---|
715 | DTRACE_TU_S("=========== transform_tree ===========\n") |
---|
716 | DTRACE_TU("x0", uiLPelX) |
---|
717 | DTRACE_TU("x1", uiTPelY) |
---|
718 | |
---|
719 | DTRACE_TU("log2TrafoSize", pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth ) |
---|
720 | DTRACE_TU("trafoDepth" , uiDepth) |
---|
721 | #endif |
---|
722 | #endif |
---|
723 | |
---|
724 | UInt uiSubdiv; |
---|
725 | const UInt numValidComponent = pcCU->getPic()->getNumberValidComponents(); |
---|
726 | const Bool bChroma = isChromaEnabled(pcCU->getPic()->getChromaFormat()); |
---|
727 | |
---|
728 | const UInt uiLog2TrafoSize = rTu.GetLog2LumaTrSize(); |
---|
729 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
730 | if (bDebugRQT) |
---|
731 | { |
---|
732 | printf("x..codeTransform: offsetLuma=%d offsetChroma=%d absPartIdx=%d, uiDepth=%d\n width=%d, height=%d, uiTrIdx=%d, uiInnerQuadIdx=%d\n", |
---|
733 | rTu.getCoefficientOffset(COMPONENT_Y), rTu.getCoefficientOffset(COMPONENT_Cb), uiAbsPartIdx, uiDepth, rTu.getRect(COMPONENT_Y).width, rTu.getRect(COMPONENT_Y).height, rTu.GetTransformDepthRel(), rTu.GetSectionNumber()); |
---|
734 | fflush(stdout); |
---|
735 | } |
---|
736 | #endif |
---|
737 | |
---|
738 | if( pcCU->isIntra(uiAbsPartIdx) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
739 | { |
---|
740 | uiSubdiv = 1; |
---|
741 | } |
---|
742 | else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->isInter(uiAbsPartIdx)) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) ) |
---|
743 | { |
---|
744 | uiSubdiv = (uiLog2TrafoSize >quadtreeTULog2MinSizeInCU); |
---|
745 | } |
---|
746 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
747 | { |
---|
748 | uiSubdiv = 1; |
---|
749 | } |
---|
750 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
751 | { |
---|
752 | uiSubdiv = 0; |
---|
753 | } |
---|
754 | else if( uiLog2TrafoSize == quadtreeTULog2MinSizeInCU ) |
---|
755 | { |
---|
756 | uiSubdiv = 0; |
---|
757 | } |
---|
758 | else |
---|
759 | { |
---|
760 | assert( uiLog2TrafoSize > quadtreeTULog2MinSizeInCU ); |
---|
761 | m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); |
---|
762 | } |
---|
763 | |
---|
764 | for(Int chan=COMPONENT_Cb; chan<numValidComponent; chan++) |
---|
765 | { |
---|
766 | const ComponentID compID=ComponentID(chan); |
---|
767 | const UInt trDepthTotalAdj=rTu.GetTransformDepthTotalAdj(compID); |
---|
768 | |
---|
769 | const Bool bFirstCbfOfCU = uiTrDepth == 0; |
---|
770 | |
---|
771 | if( bFirstCbfOfCU ) |
---|
772 | { |
---|
773 | pcCU->setCbfSubParts( 0, compID, rTu.GetAbsPartIdxTU(compID), trDepthTotalAdj); |
---|
774 | } |
---|
775 | if( bFirstCbfOfCU || rTu.ProcessingAllQuadrants(compID) ) |
---|
776 | { |
---|
777 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepth - 1 ) ) |
---|
778 | { |
---|
779 | m_pcEntropyDecoderIf->parseQtCbf( rTu, compID, (uiSubdiv == 0) ); |
---|
780 | } |
---|
781 | } |
---|
782 | } |
---|
783 | |
---|
784 | if( uiSubdiv ) |
---|
785 | { |
---|
786 | const UInt uiQPartNum = pcCU->getPic()->getNumPartitionsInCtu() >> ((uiDepth+1) << 1); |
---|
787 | UInt uiYUVCbf[MAX_NUM_COMPONENT] = {0,0,0}; |
---|
788 | |
---|
789 | TComTURecurse tuRecurseChild(rTu, true); |
---|
790 | |
---|
791 | do |
---|
792 | { |
---|
793 | xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurseChild, quadtreeTULog2MinSizeInCU ); |
---|
794 | UInt childTUAbsPartIdx=tuRecurseChild.GetAbsPartIdxTU(); |
---|
795 | for(UInt ch=0; ch<numValidComponent; ch++) |
---|
796 | { |
---|
797 | uiYUVCbf[ch] |= pcCU->getCbf(childTUAbsPartIdx , ComponentID(ch), uiTrDepth+1 ); |
---|
798 | } |
---|
799 | } while (tuRecurseChild.nextSection(rTu) ); |
---|
800 | |
---|
801 | for(UInt ch=0; ch<numValidComponent; ch++) |
---|
802 | { |
---|
803 | UChar *pBase = pcCU->getCbf( ComponentID(ch) ) + uiAbsPartIdx; |
---|
804 | const UChar flag = uiYUVCbf[ch] << uiTrDepth; |
---|
805 | |
---|
806 | for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui ) |
---|
807 | { |
---|
808 | pBase[ui] |= flag; |
---|
809 | } |
---|
810 | } |
---|
811 | } |
---|
812 | else |
---|
813 | { |
---|
814 | assert( uiDepth >= pcCU->getDepth( uiAbsPartIdx ) ); |
---|
815 | pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiDepth ); |
---|
816 | |
---|
817 | #if !H_MV_ENC_DEC_TRAC |
---|
818 | { |
---|
819 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
820 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
---|
821 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
822 | DTRACE_CABAC_T( "\tdepth=" ); |
---|
823 | DTRACE_CABAC_V( uiDepth ); |
---|
824 | DTRACE_CABAC_T( "\ttrdepth=" ); |
---|
825 | DTRACE_CABAC_V( uiTrDepth ); |
---|
826 | DTRACE_CABAC_T( "\n" ); |
---|
827 | } |
---|
828 | #endif |
---|
829 | |
---|
830 | pcCU->setCbfSubParts ( 0, COMPONENT_Y, uiAbsPartIdx, uiDepth ); |
---|
831 | |
---|
832 | if( (!pcCU->isIntra(uiAbsPartIdx)) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && ((!bChroma) || (!pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cb, 0 ) && !pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cr, 0 )) )) |
---|
833 | { |
---|
834 | pcCU->setCbfSubParts( 1 << uiTrDepth, COMPONENT_Y, uiAbsPartIdx, uiDepth ); |
---|
835 | } |
---|
836 | else |
---|
837 | { |
---|
838 | m_pcEntropyDecoderIf->parseQtCbf( rTu, COMPONENT_Y, true ); |
---|
839 | } |
---|
840 | |
---|
841 | |
---|
842 | // transform_unit begin |
---|
843 | UInt cbf[MAX_NUM_COMPONENT]={0,0,0}; |
---|
844 | Bool validCbf = false; |
---|
845 | Bool validChromaCbf = false; |
---|
846 | const UInt uiTrIdx = rTu.GetTransformDepthRel(); |
---|
847 | |
---|
848 | for(UInt ch=0; ch<pcCU->getPic()->getNumberValidComponents(); ch++) |
---|
849 | { |
---|
850 | const ComponentID compID = ComponentID(ch); |
---|
851 | |
---|
852 | cbf[compID] = pcCU->getCbf( uiAbsPartIdx, compID, uiTrIdx ); |
---|
853 | |
---|
854 | if (cbf[compID] != 0) |
---|
855 | { |
---|
856 | validCbf = true; |
---|
857 | if (isChroma(compID)) |
---|
858 | { |
---|
859 | validChromaCbf = true; |
---|
860 | } |
---|
861 | } |
---|
862 | } |
---|
863 | |
---|
864 | if ( validCbf ) |
---|
865 | { |
---|
866 | |
---|
867 | // dQP: only for CTU |
---|
868 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
869 | { |
---|
870 | if ( bCodeDQP ) |
---|
871 | { |
---|
872 | const UInt uiAbsPartIdxCU=rTu.GetAbsPartIdxCU(); |
---|
873 | decodeQP( pcCU, uiAbsPartIdxCU); |
---|
874 | bCodeDQP = false; |
---|
875 | } |
---|
876 | } |
---|
877 | |
---|
878 | if ( pcCU->getSlice()->getUseChromaQpAdj() ) |
---|
879 | { |
---|
880 | if ( validChromaCbf && isChromaQpAdjCoded && !pcCU->getCUTransquantBypass(rTu.GetAbsPartIdxCU()) ) |
---|
881 | { |
---|
882 | decodeChromaQpAdjustment( pcCU, rTu.GetAbsPartIdxCU() ); |
---|
883 | isChromaQpAdjCoded = false; |
---|
884 | } |
---|
885 | } |
---|
886 | |
---|
887 | const UInt numValidComp=pcCU->getPic()->getNumberValidComponents(); |
---|
888 | |
---|
889 | for(UInt ch=COMPONENT_Y; ch<numValidComp; ch++) |
---|
890 | { |
---|
891 | const ComponentID compID=ComponentID(ch); |
---|
892 | |
---|
893 | if( rTu.ProcessComponentSection(compID) ) |
---|
894 | { |
---|
895 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
896 | if (bDebugRQT) |
---|
897 | { |
---|
898 | printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, rTu.getRect(compID).width, rTu.getRect(compID).height, 1); |
---|
899 | } |
---|
900 | #endif |
---|
901 | |
---|
902 | if (rTu.getRect(compID).width != rTu.getRect(compID).height) |
---|
903 | { |
---|
904 | //code two sub-TUs |
---|
905 | TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID); |
---|
906 | |
---|
907 | do |
---|
908 | { |
---|
909 | const UInt subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(), compID, (uiTrIdx + 1)); |
---|
910 | |
---|
911 | if (subTUCBF != 0) |
---|
912 | { |
---|
913 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
914 | if (bDebugRQT) |
---|
915 | { |
---|
916 | printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, subTUIterator.getRect(compID).width, subTUIterator.getRect(compID).height, 1); |
---|
917 | } |
---|
918 | #endif |
---|
919 | m_pcEntropyDecoderIf->parseCoeffNxN( subTUIterator, compID ); |
---|
920 | } |
---|
921 | } while (subTUIterator.nextSection(rTu)); |
---|
922 | } |
---|
923 | else |
---|
924 | { |
---|
925 | if(isChroma(compID) && (cbf[COMPONENT_Y] != 0)) |
---|
926 | { |
---|
927 | m_pcEntropyDecoderIf->parseCrossComponentPrediction( rTu, compID ); |
---|
928 | } |
---|
929 | |
---|
930 | if(cbf[compID] != 0) |
---|
931 | { |
---|
932 | m_pcEntropyDecoderIf->parseCoeffNxN( rTu, compID ); |
---|
933 | } |
---|
934 | } |
---|
935 | } |
---|
936 | } |
---|
937 | } |
---|
938 | // transform_unit end |
---|
939 | } |
---|
940 | } |
---|
941 | |
---|
942 | Void TDecEntropy::decodeQP ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
943 | { |
---|
944 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
945 | { |
---|
946 | m_pcEntropyDecoderIf->parseDeltaQP( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) ); |
---|
947 | } |
---|
948 | } |
---|
949 | |
---|
950 | Void TDecEntropy::decodeChromaQpAdjustment( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
951 | { |
---|
952 | if ( pcCU->getSlice()->getUseChromaQpAdj() ) |
---|
953 | { |
---|
954 | m_pcEntropyDecoderIf->parseChromaQpAdjustment( pcCU, uiAbsPartIdx, pcCU->getDepth( uiAbsPartIdx ) ); |
---|
955 | } |
---|
956 | } |
---|
957 | |
---|
958 | |
---|
959 | //! decode coefficients |
---|
960 | Void TDecEntropy::decodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool& bCodeDQP, Bool& isChromaQpAdjCoded ) |
---|
961 | { |
---|
962 | #if NH_3D_SDC_INTRA |
---|
963 | if( pcCU->getSDCFlag( uiAbsPartIdx ) && pcCU->isIntra( uiAbsPartIdx) ) |
---|
964 | { |
---|
965 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
966 | assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 ); |
---|
967 | assert( pcCU->getCbf(uiAbsPartIdx, COMPONENT_Y) == 1 ); |
---|
968 | } |
---|
969 | #endif |
---|
970 | #if H_3D_INTER_SDC |
---|
971 | if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx) ) |
---|
972 | { |
---|
973 | assert( !pcCU->isSkipped( uiAbsPartIdx ) ); |
---|
974 | assert( !pcCU->isIntra( uiAbsPartIdx) ); |
---|
975 | assert( pcCU->getSlice()->getIsDepth() ); |
---|
976 | } |
---|
977 | #endif |
---|
978 | #if NH_3D |
---|
979 | if( pcCU->getSlice()->getIsDepth() ) |
---|
980 | { |
---|
981 | #if NH_3D_SDC_INTRA || H_3D_INTER_SDC |
---|
982 | if( pcCU->getSDCFlag( uiAbsPartIdx ) ) |
---|
983 | { |
---|
984 | m_pcEntropyDecoderIf->parseDeltaDC( pcCU, uiAbsPartIdx, uiDepth ); |
---|
985 | return; |
---|
986 | } |
---|
987 | #endif |
---|
988 | #if NH_3D_DMM |
---|
989 | if( pcCU->isIntra( uiAbsPartIdx ) ) |
---|
990 | { |
---|
991 | Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1; |
---|
992 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2; |
---|
993 | for( Int iPart = 0; iPart < iPartNum; iPart++ ) |
---|
994 | { |
---|
995 | if( isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx + uiPartOffset*iPart ) ) ) |
---|
996 | { |
---|
997 | m_pcEntropyDecoderIf->parseDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart, uiDepth + ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ); |
---|
998 | } |
---|
999 | } |
---|
1000 | } |
---|
1001 | #endif |
---|
1002 | } |
---|
1003 | #endif |
---|
1004 | |
---|
1005 | if( pcCU->isIntra(uiAbsPartIdx) ) |
---|
1006 | { |
---|
1007 | } |
---|
1008 | else |
---|
1009 | { |
---|
1010 | UInt uiQtRootCbf = 1; |
---|
1011 | if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) ) |
---|
1012 | { |
---|
1013 | m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf ); |
---|
1014 | } |
---|
1015 | if ( !uiQtRootCbf ) |
---|
1016 | { |
---|
1017 | static const UInt cbfZero[MAX_NUM_COMPONENT]={0,0,0}; |
---|
1018 | pcCU->setCbfSubParts( cbfZero, uiAbsPartIdx, uiDepth ); |
---|
1019 | pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth ); |
---|
1020 | return; |
---|
1021 | } |
---|
1022 | |
---|
1023 | } |
---|
1024 | |
---|
1025 | TComTURecurse tuRecurse(pcCU, uiAbsPartIdx, uiDepth); |
---|
1026 | |
---|
1027 | #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST |
---|
1028 | if (bDebugRQT) |
---|
1029 | { |
---|
1030 | printf("..codeCoeff: uiAbsPartIdx=%d, PU format=%d, 2Nx2N=%d, NxN=%d\n", uiAbsPartIdx, pcCU->getPartitionSize(uiAbsPartIdx), SIZE_2Nx2N, SIZE_NxN); |
---|
1031 | } |
---|
1032 | #endif |
---|
1033 | |
---|
1034 | Int quadtreeTULog2MinSizeInCU = pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx); |
---|
1035 | |
---|
1036 | xDecodeTransform( bCodeDQP, isChromaQpAdjCoded, tuRecurse, quadtreeTULog2MinSizeInCU ); |
---|
1037 | } |
---|
1038 | |
---|
1039 | #if NH_3D_SDC_INTRA || H_3D_INTER_SDC |
---|
1040 | Void TDecEntropy::decodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1041 | { |
---|
1042 | pcCU->setSDCFlagSubParts( false, uiAbsPartIdx, uiDepth ); |
---|
1043 | if ( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1044 | { |
---|
1045 | return; |
---|
1046 | } |
---|
1047 | |
---|
1048 | |
---|
1049 | if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getInterSdcFlag() ) || |
---|
1050 | ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getIntraSdcWedgeFlag() ) ) |
---|
1051 | { |
---|
1052 | return; |
---|
1053 | } |
---|
1054 | |
---|
1055 | if( !pcCU->getSlice()->getIsDepth() || pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N || pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1056 | { |
---|
1057 | return; |
---|
1058 | } |
---|
1059 | |
---|
1060 | assert( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) ); |
---|
1061 | m_pcEntropyDecoderIf->parseSDCFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1062 | } |
---|
1063 | #endif |
---|
1064 | #if H_3D_DBBP |
---|
1065 | Void TDecEntropy::decodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1066 | { |
---|
1067 | if( pcCU->getSlice()->getDepthBasedBlkPartFlag() && (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2NxN || pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_Nx2N) && pcCU->getWidth(uiAbsPartIdx) > 8 && pcCU->getSlice()->getDefaultRefViewIdxAvailableFlag() ) |
---|
1068 | { |
---|
1069 | m_pcEntropyDecoderIf->parseDBBPFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1070 | } |
---|
1071 | } |
---|
1072 | #endif |
---|
1073 | |
---|
1074 | |
---|
1075 | |
---|
1076 | //! \} |
---|