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