1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TEncEntropy.cpp |
---|
35 | \brief entropy encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TEncEntropy.h" |
---|
39 | #include "TLibCommon/TypeDef.h" |
---|
40 | #include "TLibCommon/TComSampleAdaptiveOffset.h" |
---|
41 | |
---|
42 | //! \ingroup TLibEncoder |
---|
43 | //! \{ |
---|
44 | |
---|
45 | Void TEncEntropy::setEntropyCoder ( TEncEntropyIf* e, TComSlice* pcSlice ) |
---|
46 | { |
---|
47 | m_pcEntropyCoderIf = e; |
---|
48 | m_pcEntropyCoderIf->setSlice ( pcSlice ); |
---|
49 | } |
---|
50 | |
---|
51 | Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice ) |
---|
52 | { |
---|
53 | m_pcEntropyCoderIf->codeSliceHeader( pcSlice ); |
---|
54 | return; |
---|
55 | } |
---|
56 | |
---|
57 | Void TEncEntropy::encodeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
58 | { |
---|
59 | m_pcEntropyCoderIf->codeTilesWPPEntryPoint( pSlice ); |
---|
60 | } |
---|
61 | |
---|
62 | Void TEncEntropy::encodeTerminatingBit ( UInt uiIsLast ) |
---|
63 | { |
---|
64 | m_pcEntropyCoderIf->codeTerminatingBit( uiIsLast ); |
---|
65 | |
---|
66 | return; |
---|
67 | } |
---|
68 | |
---|
69 | Void TEncEntropy::encodeSliceFinish() |
---|
70 | { |
---|
71 | m_pcEntropyCoderIf->codeSliceFinish(); |
---|
72 | } |
---|
73 | |
---|
74 | Void TEncEntropy::encodePPS( TComPPS* pcPPS ) |
---|
75 | { |
---|
76 | m_pcEntropyCoderIf->codePPS( pcPPS ); |
---|
77 | return; |
---|
78 | } |
---|
79 | |
---|
80 | Void TEncEntropy::encodeSPS( TComSPS* pcSPS ) |
---|
81 | { |
---|
82 | m_pcEntropyCoderIf->codeSPS( pcSPS ); |
---|
83 | return; |
---|
84 | } |
---|
85 | |
---|
86 | Void TEncEntropy::encodeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
87 | { |
---|
88 | if( bRD ) |
---|
89 | { |
---|
90 | uiAbsPartIdx = 0; |
---|
91 | } |
---|
92 | m_pcEntropyCoderIf->codeCUTransquantBypassFlag( pcCU, uiAbsPartIdx ); |
---|
93 | } |
---|
94 | |
---|
95 | Void TEncEntropy::encodeVPS( TComVPS* pcVPS ) |
---|
96 | { |
---|
97 | m_pcEntropyCoderIf->codeVPS( pcVPS ); |
---|
98 | return; |
---|
99 | } |
---|
100 | |
---|
101 | Void TEncEntropy::encodeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
102 | { |
---|
103 | if ( pcCU->getSlice()->isIntra() ) |
---|
104 | { |
---|
105 | return; |
---|
106 | } |
---|
107 | if( bRD ) |
---|
108 | { |
---|
109 | uiAbsPartIdx = 0; |
---|
110 | } |
---|
111 | m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
112 | } |
---|
113 | #if H_3D_SINGLE_DEPTH |
---|
114 | Void TEncEntropy::encodeSingleDepthMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
115 | { |
---|
116 | if(!pcCU->getSlice()->getIntraSingleFlag() ) |
---|
117 | { |
---|
118 | return; |
---|
119 | } |
---|
120 | if( bRD ) |
---|
121 | { |
---|
122 | uiAbsPartIdx = 0; |
---|
123 | } |
---|
124 | m_pcEntropyCoderIf->codeSingleDepthMode( pcCU, uiAbsPartIdx ); |
---|
125 | } |
---|
126 | #endif |
---|
127 | /** encode merge flag |
---|
128 | * \param pcCU |
---|
129 | * \param uiAbsPartIdx |
---|
130 | * \returns Void |
---|
131 | */ |
---|
132 | Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
133 | { |
---|
134 | // at least one merge candidate exists |
---|
135 | m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx ); |
---|
136 | } |
---|
137 | |
---|
138 | /** encode merge index |
---|
139 | * \param pcCU |
---|
140 | * \param uiAbsPartIdx |
---|
141 | * \param uiPUIdx |
---|
142 | * \param bRD |
---|
143 | * \returns Void |
---|
144 | */ |
---|
145 | Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
146 | { |
---|
147 | if( bRD ) |
---|
148 | { |
---|
149 | uiAbsPartIdx = 0; |
---|
150 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
151 | } |
---|
152 | m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
153 | } |
---|
154 | |
---|
155 | #if H_3D_IC |
---|
156 | Void TEncEntropy::encodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
157 | { |
---|
158 | if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() || pcCU->getARPW( uiAbsPartIdx ) > 0 ) |
---|
159 | { |
---|
160 | return; |
---|
161 | } |
---|
162 | |
---|
163 | if( !pcCU->getSlice()->getApplyIC() ) |
---|
164 | { |
---|
165 | return; |
---|
166 | } |
---|
167 | |
---|
168 | if( bRD ) |
---|
169 | { |
---|
170 | uiAbsPartIdx = 0; |
---|
171 | } |
---|
172 | else |
---|
173 | { |
---|
174 | Int ICEnableCandidate = pcCU->getSlice()->getICEnableCandidate(pcCU->getSlice()->getDepth()); |
---|
175 | Int ICEnableNum = pcCU->getSlice()->getICEnableNum(pcCU->getSlice()->getDepth()); |
---|
176 | ICEnableCandidate++; |
---|
177 | if(pcCU->getICFlag(uiAbsPartIdx)) |
---|
178 | { |
---|
179 | ICEnableNum++; |
---|
180 | } |
---|
181 | pcCU->getSlice()->setICEnableCandidate(pcCU->getSlice()->getDepth(), ICEnableCandidate); |
---|
182 | pcCU->getSlice()->setICEnableNum(pcCU->getSlice()->getDepth(), ICEnableNum); |
---|
183 | } |
---|
184 | if( pcCU->isICFlagRequired( uiAbsPartIdx ) ) |
---|
185 | { |
---|
186 | m_pcEntropyCoderIf->codeICFlag( pcCU, uiAbsPartIdx ); |
---|
187 | } |
---|
188 | } |
---|
189 | #endif |
---|
190 | |
---|
191 | #if H_3D_ARP |
---|
192 | Void TEncEntropy::encodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
193 | { |
---|
194 | if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) ) |
---|
195 | { |
---|
196 | return; |
---|
197 | } |
---|
198 | |
---|
199 | if ( pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_2Nx2N ) |
---|
200 | { |
---|
201 | assert(pcCU->getARPW (uiAbsPartIdx) == 0); |
---|
202 | } |
---|
203 | else |
---|
204 | { |
---|
205 | m_pcEntropyCoderIf->codeARPW( pcCU, uiAbsPartIdx ); |
---|
206 | } |
---|
207 | } |
---|
208 | #endif |
---|
209 | |
---|
210 | /** encode prediction mode |
---|
211 | * \param pcCU |
---|
212 | * \param uiAbsPartIdx |
---|
213 | * \param bRD |
---|
214 | * \returns Void |
---|
215 | */ |
---|
216 | Void TEncEntropy::encodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
217 | { |
---|
218 | if( bRD ) |
---|
219 | { |
---|
220 | uiAbsPartIdx = 0; |
---|
221 | } |
---|
222 | if ( pcCU->getSlice()->isIntra() ) |
---|
223 | { |
---|
224 | return; |
---|
225 | } |
---|
226 | |
---|
227 | m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx ); |
---|
228 | } |
---|
229 | |
---|
230 | // Split mode |
---|
231 | Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
232 | { |
---|
233 | if( bRD ) |
---|
234 | { |
---|
235 | uiAbsPartIdx = 0; |
---|
236 | } |
---|
237 | m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
238 | } |
---|
239 | |
---|
240 | /** encode partition size |
---|
241 | * \param pcCU |
---|
242 | * \param uiAbsPartIdx |
---|
243 | * \param uiDepth |
---|
244 | * \param bRD |
---|
245 | * \returns Void |
---|
246 | */ |
---|
247 | Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
248 | { |
---|
249 | if( bRD ) |
---|
250 | { |
---|
251 | uiAbsPartIdx = 0; |
---|
252 | } |
---|
253 | |
---|
254 | m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
255 | |
---|
256 | #if H_3D_DBBP |
---|
257 | if( pcCU->getSlice()->getDepthBasedBlkPartFlag() && (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2NxN || pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_Nx2N) && pcCU->getWidth(uiAbsPartIdx) > 8 && pcCU->getSlice()->getDefaultRefViewIdxAvailableFlag() ) |
---|
258 | { |
---|
259 | encodeDBBPFlag(pcCU, uiAbsPartIdx, bRD); |
---|
260 | } |
---|
261 | #endif |
---|
262 | } |
---|
263 | |
---|
264 | /** Encode I_PCM information. |
---|
265 | * \param pcCU pointer to CU |
---|
266 | * \param uiAbsPartIdx CU index |
---|
267 | * \param bRD flag indicating estimation or encoding |
---|
268 | * \returns Void |
---|
269 | */ |
---|
270 | Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
271 | { |
---|
272 | if(!pcCU->getSlice()->getSPS()->getUsePCM() |
---|
273 | || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize()) |
---|
274 | || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize())) |
---|
275 | { |
---|
276 | return; |
---|
277 | } |
---|
278 | |
---|
279 | if( bRD ) |
---|
280 | { |
---|
281 | uiAbsPartIdx = 0; |
---|
282 | } |
---|
283 | |
---|
284 | m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx ); |
---|
285 | } |
---|
286 | |
---|
287 | Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP ) |
---|
288 | { |
---|
289 | const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth; |
---|
290 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
291 | UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA , uiTrIdx ); |
---|
292 | UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
293 | UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
294 | |
---|
295 | if(uiTrIdx==0) |
---|
296 | { |
---|
297 | m_bakAbsPartIdxCU = uiAbsPartIdx; |
---|
298 | } |
---|
299 | if( uiLog2TrafoSize == 2 ) |
---|
300 | { |
---|
301 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
302 | if( ( uiAbsPartIdx % partNum ) == 0 ) |
---|
303 | { |
---|
304 | m_uiBakAbsPartIdx = uiAbsPartIdx; |
---|
305 | m_uiBakChromaOffset = offsetChroma; |
---|
306 | } |
---|
307 | else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
308 | { |
---|
309 | cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
310 | cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
311 | } |
---|
312 | } |
---|
313 | |
---|
314 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
315 | { |
---|
316 | assert( uiSubdiv ); |
---|
317 | } |
---|
318 | else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) && (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) ) |
---|
319 | { |
---|
320 | if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
321 | { |
---|
322 | assert( uiSubdiv ); |
---|
323 | } |
---|
324 | else |
---|
325 | { |
---|
326 | assert(!uiSubdiv ); |
---|
327 | } |
---|
328 | } |
---|
329 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
330 | { |
---|
331 | assert( uiSubdiv ); |
---|
332 | } |
---|
333 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
334 | { |
---|
335 | assert( !uiSubdiv ); |
---|
336 | } |
---|
337 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
338 | { |
---|
339 | assert( !uiSubdiv ); |
---|
340 | } |
---|
341 | else |
---|
342 | { |
---|
343 | assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
344 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); |
---|
345 | } |
---|
346 | |
---|
347 | const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
348 | const Bool bFirstCbfOfCU = uiTrDepthCurr == 0; |
---|
349 | if( bFirstCbfOfCU || uiLog2TrafoSize > 2 ) |
---|
350 | { |
---|
351 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ) |
---|
352 | { |
---|
353 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
354 | } |
---|
355 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ) |
---|
356 | { |
---|
357 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
358 | } |
---|
359 | } |
---|
360 | else if( uiLog2TrafoSize == 2 ) |
---|
361 | { |
---|
362 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ); |
---|
363 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ); |
---|
364 | } |
---|
365 | |
---|
366 | if( uiSubdiv ) |
---|
367 | { |
---|
368 | UInt size; |
---|
369 | width >>= 1; |
---|
370 | height >>= 1; |
---|
371 | size = width*height; |
---|
372 | uiTrIdx++; |
---|
373 | ++uiDepth; |
---|
374 | const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
375 | |
---|
376 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
377 | |
---|
378 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
379 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
380 | |
---|
381 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
382 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
383 | |
---|
384 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
385 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
386 | } |
---|
387 | else |
---|
388 | { |
---|
389 | #if !H_MV_ENC_DEC_TRAC |
---|
390 | { |
---|
391 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
392 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
---|
393 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
394 | DTRACE_CABAC_T( "\tdepth=" ); |
---|
395 | DTRACE_CABAC_V( uiDepth ); |
---|
396 | DTRACE_CABAC_T( "\ttrdepth=" ); |
---|
397 | DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
398 | DTRACE_CABAC_T( "\n" ); |
---|
399 | } |
---|
400 | #endif |
---|
401 | |
---|
402 | if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
403 | { |
---|
404 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) ); |
---|
405 | // printf( "saved one bin! " ); |
---|
406 | } |
---|
407 | else |
---|
408 | { |
---|
409 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
410 | } |
---|
411 | |
---|
412 | |
---|
413 | if ( cbfY || cbfU || cbfV ) |
---|
414 | { |
---|
415 | // dQP: only for LCU once |
---|
416 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
417 | { |
---|
418 | if ( bCodeDQP ) |
---|
419 | { |
---|
420 | encodeQP( pcCU, m_bakAbsPartIdxCU ); |
---|
421 | bCodeDQP = false; |
---|
422 | } |
---|
423 | } |
---|
424 | } |
---|
425 | if( cbfY ) |
---|
426 | { |
---|
427 | Int trWidth = width; |
---|
428 | Int trHeight = height; |
---|
429 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
430 | } |
---|
431 | if( uiLog2TrafoSize > 2 ) |
---|
432 | { |
---|
433 | Int trWidth = width >> 1; |
---|
434 | Int trHeight = height >> 1; |
---|
435 | if( cbfU ) |
---|
436 | { |
---|
437 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
438 | } |
---|
439 | if( cbfV ) |
---|
440 | { |
---|
441 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
442 | } |
---|
443 | } |
---|
444 | else |
---|
445 | { |
---|
446 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
447 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
448 | { |
---|
449 | Int trWidth = width; |
---|
450 | Int trHeight = height; |
---|
451 | if( cbfU ) |
---|
452 | { |
---|
453 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
454 | } |
---|
455 | if( cbfV ) |
---|
456 | { |
---|
457 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
458 | } |
---|
459 | } |
---|
460 | } |
---|
461 | } |
---|
462 | } |
---|
463 | |
---|
464 | // Intra direction for Luma |
---|
465 | Void TEncEntropy::encodeIntraDirModeLuma ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU ) |
---|
466 | { |
---|
467 | m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU); |
---|
468 | } |
---|
469 | |
---|
470 | // Intra direction for Chroma |
---|
471 | Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
472 | { |
---|
473 | if( bRD ) |
---|
474 | { |
---|
475 | uiAbsPartIdx = 0; |
---|
476 | } |
---|
477 | |
---|
478 | m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx ); |
---|
479 | } |
---|
480 | |
---|
481 | Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
482 | { |
---|
483 | if( bRD ) |
---|
484 | { |
---|
485 | uiAbsPartIdx = 0; |
---|
486 | } |
---|
487 | if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode. |
---|
488 | { |
---|
489 | encodeIntraDirModeLuma ( pcCU, uiAbsPartIdx,true ); |
---|
490 | #if H_3D_DIM_SDC |
---|
491 | if(!pcCU->getSDCFlag(uiAbsPartIdx)) |
---|
492 | #endif |
---|
493 | encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD ); |
---|
494 | } |
---|
495 | else // if it is Inter mode, encode motion vector and reference index |
---|
496 | { |
---|
497 | encodePUWise( pcCU, uiAbsPartIdx, bRD ); |
---|
498 | } |
---|
499 | } |
---|
500 | |
---|
501 | /** encode motion information for every PU block |
---|
502 | * \param pcCU |
---|
503 | * \param uiAbsPartIdx |
---|
504 | * \param bRD |
---|
505 | * \returns Void |
---|
506 | */ |
---|
507 | Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
508 | { |
---|
509 | if ( bRD ) |
---|
510 | { |
---|
511 | uiAbsPartIdx = 0; |
---|
512 | } |
---|
513 | |
---|
514 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
515 | UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) ); |
---|
516 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ); |
---|
517 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4; |
---|
518 | |
---|
519 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
520 | { |
---|
521 | #if H_MV_ENC_DEC_TRAC |
---|
522 | DTRACE_PU_S("=========== prediction_unit ===========\n") |
---|
523 | //Todo: |
---|
524 | //DTRACE_PU("x0", uiLPelX) |
---|
525 | //DTRACE_PU("x1", uiTPelY) |
---|
526 | #endif |
---|
527 | encodeMergeFlag( pcCU, uiSubPartIdx ); |
---|
528 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
529 | { |
---|
530 | encodeMergeIndex( pcCU, uiSubPartIdx ); |
---|
531 | } |
---|
532 | else |
---|
533 | { |
---|
534 | encodeInterDirPU( pcCU, uiSubPartIdx ); |
---|
535 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
536 | { |
---|
537 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
538 | { |
---|
539 | encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
540 | encodeMvdPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
541 | encodeMVPIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
542 | } |
---|
543 | } |
---|
544 | } |
---|
545 | } |
---|
546 | |
---|
547 | return; |
---|
548 | } |
---|
549 | |
---|
550 | Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
551 | { |
---|
552 | if ( !pcCU->getSlice()->isInterB() ) |
---|
553 | { |
---|
554 | return; |
---|
555 | } |
---|
556 | |
---|
557 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
558 | return; |
---|
559 | } |
---|
560 | |
---|
561 | /** encode reference frame index for a PU block |
---|
562 | * \param pcCU |
---|
563 | * \param uiAbsPartIdx |
---|
564 | * \param eRefList |
---|
565 | * \returns Void |
---|
566 | */ |
---|
567 | Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
568 | { |
---|
569 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
570 | { |
---|
571 | if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) ) |
---|
572 | { |
---|
573 | return; |
---|
574 | } |
---|
575 | |
---|
576 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
577 | { |
---|
578 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
579 | } |
---|
580 | } |
---|
581 | |
---|
582 | return; |
---|
583 | } |
---|
584 | |
---|
585 | /** encode motion vector difference for a PU block |
---|
586 | * \param pcCU |
---|
587 | * \param uiAbsPartIdx |
---|
588 | * \param eRefList |
---|
589 | * \returns Void |
---|
590 | */ |
---|
591 | Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
592 | { |
---|
593 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
594 | |
---|
595 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
596 | { |
---|
597 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
598 | } |
---|
599 | return; |
---|
600 | } |
---|
601 | |
---|
602 | Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
603 | { |
---|
604 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) ) |
---|
605 | { |
---|
606 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
607 | } |
---|
608 | |
---|
609 | return; |
---|
610 | } |
---|
611 | |
---|
612 | Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
613 | { |
---|
614 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth ); |
---|
615 | } |
---|
616 | |
---|
617 | Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
618 | { |
---|
619 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx ); |
---|
620 | } |
---|
621 | |
---|
622 | Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
623 | { |
---|
624 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
625 | } |
---|
626 | |
---|
627 | Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
---|
628 | { |
---|
629 | m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth ); |
---|
630 | } |
---|
631 | Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU ) |
---|
632 | { |
---|
633 | m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU ); |
---|
634 | } |
---|
635 | |
---|
636 | // dQP |
---|
637 | Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
638 | { |
---|
639 | if( bRD ) |
---|
640 | { |
---|
641 | uiAbsPartIdx = 0; |
---|
642 | } |
---|
643 | |
---|
644 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
645 | { |
---|
646 | m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx ); |
---|
647 | } |
---|
648 | } |
---|
649 | |
---|
650 | |
---|
651 | // texture |
---|
652 | /** encode coefficients |
---|
653 | * \param pcCU |
---|
654 | * \param uiAbsPartIdx |
---|
655 | * \param uiDepth |
---|
656 | * \param uiWidth |
---|
657 | * \param uiHeight |
---|
658 | */ |
---|
659 | Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP ) |
---|
660 | { |
---|
661 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
662 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
663 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
664 | #if H_3D_DIM_SDC |
---|
665 | if( pcCU->getSDCFlag( uiAbsPartIdx ) && pcCU->isIntra( uiAbsPartIdx ) ) |
---|
666 | { |
---|
667 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
668 | assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 ); |
---|
669 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 ); |
---|
670 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 ); |
---|
671 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 ); |
---|
672 | } |
---|
673 | |
---|
674 | if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx ) ) |
---|
675 | { |
---|
676 | assert( !pcCU->isSkipped( uiAbsPartIdx ) ); |
---|
677 | assert( !pcCU->isIntra( uiAbsPartIdx) ); |
---|
678 | assert( pcCU->getSlice()->getIsDepth() ); |
---|
679 | } |
---|
680 | |
---|
681 | if( pcCU->getSlice()->getIsDepth() && ( pcCU->getSDCFlag( uiAbsPartIdx ) || pcCU->isIntra( uiAbsPartIdx ) ) ) |
---|
682 | { |
---|
683 | Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1; |
---|
684 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2; |
---|
685 | |
---|
686 | if( !pcCU->getSDCFlag( uiAbsPartIdx ) ) |
---|
687 | { |
---|
688 | for( Int iPart = 0; iPart < iPartNum; iPart++ ) |
---|
689 | { |
---|
690 | if( getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset*iPart ) ) < DIM_NUM_TYPE ) |
---|
691 | { |
---|
692 | m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart ); |
---|
693 | } |
---|
694 | } |
---|
695 | } |
---|
696 | else |
---|
697 | { |
---|
698 | m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx ); |
---|
699 | return; |
---|
700 | } |
---|
701 | } |
---|
702 | #endif |
---|
703 | |
---|
704 | if( pcCU->isIntra(uiAbsPartIdx) ) |
---|
705 | { |
---|
706 | #if !H_MV |
---|
707 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
708 | DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" ) |
---|
709 | DTRACE_CABAC_V( uiDepth ) |
---|
710 | DTRACE_CABAC_T( "\n" ) |
---|
711 | #endif |
---|
712 | } |
---|
713 | else |
---|
714 | { |
---|
715 | if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) ) |
---|
716 | { |
---|
717 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
718 | } |
---|
719 | if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) ) |
---|
720 | { |
---|
721 | return; |
---|
722 | } |
---|
723 | } |
---|
724 | |
---|
725 | xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP); |
---|
726 | } |
---|
727 | |
---|
728 | Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType ) |
---|
729 | { |
---|
730 | // This is for Transform unit processing. This may be used at mode selection stage for Inter. |
---|
731 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType ); |
---|
732 | } |
---|
733 | |
---|
734 | Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) |
---|
735 | { |
---|
736 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA; |
---|
737 | |
---|
738 | m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType ); |
---|
739 | } |
---|
740 | |
---|
741 | Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ) |
---|
742 | { |
---|
743 | Int count = 0; |
---|
744 | |
---|
745 | for ( Int i = 0; i < uiSize; i++ ) |
---|
746 | { |
---|
747 | count += pcCoef[i] != 0; |
---|
748 | } |
---|
749 | |
---|
750 | return count; |
---|
751 | } |
---|
752 | |
---|
753 | /** encode quantization matrix |
---|
754 | * \param scalingList quantization matrix information |
---|
755 | */ |
---|
756 | Void TEncEntropy::encodeScalingList( TComScalingList* scalingList ) |
---|
757 | { |
---|
758 | m_pcEntropyCoderIf->codeScalingList( scalingList ); |
---|
759 | } |
---|
760 | |
---|
761 | #if H_3D_INTER_SDC |
---|
762 | Void TEncEntropy::encodeDeltaDC ( TComDataCU* pcCU, UInt absPartIdx ) |
---|
763 | { |
---|
764 | m_pcEntropyCoderIf->codeDeltaDC( pcCU, absPartIdx ); |
---|
765 | } |
---|
766 | |
---|
767 | Void TEncEntropy::encodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
768 | { |
---|
769 | if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getInterSdcFlag() ) || |
---|
770 | ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getIntraSdcWedgeFlag() ) ) |
---|
771 | { |
---|
772 | return; |
---|
773 | } |
---|
774 | |
---|
775 | if( !pcCU->getSlice()->getIsDepth() || pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N || pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
776 | { |
---|
777 | return; |
---|
778 | } |
---|
779 | |
---|
780 | assert( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) ); |
---|
781 | |
---|
782 | if( bRD ) |
---|
783 | { |
---|
784 | uiAbsPartIdx = 0; |
---|
785 | } |
---|
786 | |
---|
787 | m_pcEntropyCoderIf->codeSDCFlag( pcCU, uiAbsPartIdx ); |
---|
788 | } |
---|
789 | |
---|
790 | #endif |
---|
791 | #if H_3D_DBBP |
---|
792 | Void TEncEntropy::encodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
793 | { |
---|
794 | if( bRD ) |
---|
795 | { |
---|
796 | uiAbsPartIdx = 0; |
---|
797 | } |
---|
798 | m_pcEntropyCoderIf->codeDBBPFlag( pcCU, uiAbsPartIdx ); |
---|
799 | } |
---|
800 | #endif |
---|
801 | //! \} |
---|