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 | |
---|
114 | #if SEC_DEPTH_INTRA_SKIP_MODE_K0033 |
---|
115 | Void TEncEntropy::encodeDIS( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
116 | { |
---|
117 | if ( !pcCU->getSlice()->getIsDepth() ) |
---|
118 | { |
---|
119 | return; |
---|
120 | } |
---|
121 | if( bRD ) |
---|
122 | { |
---|
123 | uiAbsPartIdx = 0; |
---|
124 | } |
---|
125 | m_pcEntropyCoderIf->codeDIS( pcCU, uiAbsPartIdx ); |
---|
126 | } |
---|
127 | #else |
---|
128 | #if H_3D_SINGLE_DEPTH |
---|
129 | Void TEncEntropy::encodeSingleDepthMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
130 | { |
---|
131 | if(!pcCU->getSlice()->getIntraSingleFlag() ) |
---|
132 | { |
---|
133 | return; |
---|
134 | } |
---|
135 | if( bRD ) |
---|
136 | { |
---|
137 | uiAbsPartIdx = 0; |
---|
138 | } |
---|
139 | m_pcEntropyCoderIf->codeSingleDepthMode( pcCU, uiAbsPartIdx ); |
---|
140 | } |
---|
141 | #endif |
---|
142 | #endif |
---|
143 | |
---|
144 | /** encode merge flag |
---|
145 | * \param pcCU |
---|
146 | * \param uiAbsPartIdx |
---|
147 | * \returns Void |
---|
148 | */ |
---|
149 | Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
150 | { |
---|
151 | // at least one merge candidate exists |
---|
152 | m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx ); |
---|
153 | } |
---|
154 | |
---|
155 | /** encode merge index |
---|
156 | * \param pcCU |
---|
157 | * \param uiAbsPartIdx |
---|
158 | * \param uiPUIdx |
---|
159 | * \param bRD |
---|
160 | * \returns Void |
---|
161 | */ |
---|
162 | Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
163 | { |
---|
164 | if( bRD ) |
---|
165 | { |
---|
166 | uiAbsPartIdx = 0; |
---|
167 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
168 | } |
---|
169 | m_pcEntropyCoderIf->codeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
170 | } |
---|
171 | |
---|
172 | #if H_3D_IC |
---|
173 | Void TEncEntropy::encodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
174 | { |
---|
175 | if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() || pcCU->getARPW( uiAbsPartIdx ) > 0 ) |
---|
176 | { |
---|
177 | return; |
---|
178 | } |
---|
179 | |
---|
180 | if( !pcCU->getSlice()->getApplyIC() ) |
---|
181 | { |
---|
182 | return; |
---|
183 | } |
---|
184 | |
---|
185 | if( bRD ) |
---|
186 | { |
---|
187 | uiAbsPartIdx = 0; |
---|
188 | } |
---|
189 | else |
---|
190 | { |
---|
191 | Int ICEnableCandidate = pcCU->getSlice()->getICEnableCandidate(pcCU->getSlice()->getDepth()); |
---|
192 | Int ICEnableNum = pcCU->getSlice()->getICEnableNum(pcCU->getSlice()->getDepth()); |
---|
193 | ICEnableCandidate++; |
---|
194 | if(pcCU->getICFlag(uiAbsPartIdx)) |
---|
195 | { |
---|
196 | ICEnableNum++; |
---|
197 | } |
---|
198 | pcCU->getSlice()->setICEnableCandidate(pcCU->getSlice()->getDepth(), ICEnableCandidate); |
---|
199 | pcCU->getSlice()->setICEnableNum(pcCU->getSlice()->getDepth(), ICEnableNum); |
---|
200 | } |
---|
201 | if( pcCU->isICFlagRequired( uiAbsPartIdx ) ) |
---|
202 | { |
---|
203 | m_pcEntropyCoderIf->codeICFlag( pcCU, uiAbsPartIdx ); |
---|
204 | } |
---|
205 | } |
---|
206 | #endif |
---|
207 | |
---|
208 | #if H_3D_ARP |
---|
209 | Void TEncEntropy::encodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
210 | { |
---|
211 | if( !pcCU->getSlice()->getARPStepNum() || pcCU->isIntra( uiAbsPartIdx ) ) |
---|
212 | { |
---|
213 | return; |
---|
214 | } |
---|
215 | |
---|
216 | if ( pcCU->getPartitionSize(uiAbsPartIdx)!=SIZE_2Nx2N ) |
---|
217 | { |
---|
218 | assert(pcCU->getARPW (uiAbsPartIdx) == 0); |
---|
219 | } |
---|
220 | else |
---|
221 | { |
---|
222 | m_pcEntropyCoderIf->codeARPW( pcCU, uiAbsPartIdx ); |
---|
223 | } |
---|
224 | } |
---|
225 | #endif |
---|
226 | |
---|
227 | /** encode prediction mode |
---|
228 | * \param pcCU |
---|
229 | * \param uiAbsPartIdx |
---|
230 | * \param bRD |
---|
231 | * \returns Void |
---|
232 | */ |
---|
233 | Void TEncEntropy::encodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
234 | { |
---|
235 | if( bRD ) |
---|
236 | { |
---|
237 | uiAbsPartIdx = 0; |
---|
238 | } |
---|
239 | if ( pcCU->getSlice()->isIntra() ) |
---|
240 | { |
---|
241 | return; |
---|
242 | } |
---|
243 | |
---|
244 | m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx ); |
---|
245 | } |
---|
246 | |
---|
247 | // Split mode |
---|
248 | Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
249 | { |
---|
250 | if( bRD ) |
---|
251 | { |
---|
252 | uiAbsPartIdx = 0; |
---|
253 | } |
---|
254 | m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
255 | } |
---|
256 | |
---|
257 | /** encode partition size |
---|
258 | * \param pcCU |
---|
259 | * \param uiAbsPartIdx |
---|
260 | * \param uiDepth |
---|
261 | * \param bRD |
---|
262 | * \returns Void |
---|
263 | */ |
---|
264 | Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD ) |
---|
265 | { |
---|
266 | if( bRD ) |
---|
267 | { |
---|
268 | uiAbsPartIdx = 0; |
---|
269 | } |
---|
270 | |
---|
271 | m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
272 | |
---|
273 | #if H_3D_DBBP |
---|
274 | if( pcCU->getSlice()->getDepthBasedBlkPartFlag() && (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2NxN || pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_Nx2N) && pcCU->getWidth(uiAbsPartIdx) > 8 && pcCU->getSlice()->getDefaultRefViewIdxAvailableFlag() ) |
---|
275 | { |
---|
276 | encodeDBBPFlag(pcCU, uiAbsPartIdx, bRD); |
---|
277 | } |
---|
278 | #endif |
---|
279 | } |
---|
280 | |
---|
281 | /** Encode I_PCM information. |
---|
282 | * \param pcCU pointer to CU |
---|
283 | * \param uiAbsPartIdx CU index |
---|
284 | * \param bRD flag indicating estimation or encoding |
---|
285 | * \returns Void |
---|
286 | */ |
---|
287 | Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
288 | { |
---|
289 | if(!pcCU->getSlice()->getSPS()->getUsePCM() |
---|
290 | || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize()) |
---|
291 | || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize())) |
---|
292 | { |
---|
293 | return; |
---|
294 | } |
---|
295 | |
---|
296 | if( bRD ) |
---|
297 | { |
---|
298 | uiAbsPartIdx = 0; |
---|
299 | } |
---|
300 | |
---|
301 | m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx ); |
---|
302 | } |
---|
303 | |
---|
304 | Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP ) |
---|
305 | { |
---|
306 | const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth; |
---|
307 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
308 | UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA , uiTrIdx ); |
---|
309 | UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
310 | UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
311 | |
---|
312 | if(uiTrIdx==0) |
---|
313 | { |
---|
314 | m_bakAbsPartIdxCU = uiAbsPartIdx; |
---|
315 | } |
---|
316 | if( uiLog2TrafoSize == 2 ) |
---|
317 | { |
---|
318 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
319 | if( ( uiAbsPartIdx % partNum ) == 0 ) |
---|
320 | { |
---|
321 | m_uiBakAbsPartIdx = uiAbsPartIdx; |
---|
322 | m_uiBakChromaOffset = offsetChroma; |
---|
323 | } |
---|
324 | else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
325 | { |
---|
326 | cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
327 | cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
328 | } |
---|
329 | } |
---|
330 | |
---|
331 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
332 | { |
---|
333 | assert( uiSubdiv ); |
---|
334 | } |
---|
335 | else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) && (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) ) |
---|
336 | { |
---|
337 | if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
338 | { |
---|
339 | assert( uiSubdiv ); |
---|
340 | } |
---|
341 | else |
---|
342 | { |
---|
343 | assert(!uiSubdiv ); |
---|
344 | } |
---|
345 | } |
---|
346 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
347 | { |
---|
348 | assert( uiSubdiv ); |
---|
349 | } |
---|
350 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
351 | { |
---|
352 | assert( !uiSubdiv ); |
---|
353 | } |
---|
354 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
355 | { |
---|
356 | assert( !uiSubdiv ); |
---|
357 | } |
---|
358 | else |
---|
359 | { |
---|
360 | assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
361 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); |
---|
362 | } |
---|
363 | |
---|
364 | const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
365 | const Bool bFirstCbfOfCU = uiTrDepthCurr == 0; |
---|
366 | if( bFirstCbfOfCU || uiLog2TrafoSize > 2 ) |
---|
367 | { |
---|
368 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ) |
---|
369 | { |
---|
370 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
371 | } |
---|
372 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ) |
---|
373 | { |
---|
374 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
375 | } |
---|
376 | } |
---|
377 | else if( uiLog2TrafoSize == 2 ) |
---|
378 | { |
---|
379 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ); |
---|
380 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ); |
---|
381 | } |
---|
382 | |
---|
383 | if( uiSubdiv ) |
---|
384 | { |
---|
385 | UInt size; |
---|
386 | width >>= 1; |
---|
387 | height >>= 1; |
---|
388 | size = width*height; |
---|
389 | uiTrIdx++; |
---|
390 | ++uiDepth; |
---|
391 | const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
392 | |
---|
393 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
394 | |
---|
395 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
396 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
397 | |
---|
398 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
399 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
400 | |
---|
401 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
402 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
403 | } |
---|
404 | else |
---|
405 | { |
---|
406 | #if !H_MV_ENC_DEC_TRAC |
---|
407 | { |
---|
408 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
409 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
---|
410 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
411 | DTRACE_CABAC_T( "\tdepth=" ); |
---|
412 | DTRACE_CABAC_V( uiDepth ); |
---|
413 | DTRACE_CABAC_T( "\ttrdepth=" ); |
---|
414 | DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
415 | DTRACE_CABAC_T( "\n" ); |
---|
416 | } |
---|
417 | #endif |
---|
418 | |
---|
419 | if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
420 | { |
---|
421 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) ); |
---|
422 | // printf( "saved one bin! " ); |
---|
423 | } |
---|
424 | else |
---|
425 | { |
---|
426 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
427 | } |
---|
428 | |
---|
429 | |
---|
430 | if ( cbfY || cbfU || cbfV ) |
---|
431 | { |
---|
432 | // dQP: only for LCU once |
---|
433 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
434 | { |
---|
435 | if ( bCodeDQP ) |
---|
436 | { |
---|
437 | encodeQP( pcCU, m_bakAbsPartIdxCU ); |
---|
438 | bCodeDQP = false; |
---|
439 | } |
---|
440 | } |
---|
441 | } |
---|
442 | if( cbfY ) |
---|
443 | { |
---|
444 | Int trWidth = width; |
---|
445 | Int trHeight = height; |
---|
446 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
447 | } |
---|
448 | if( uiLog2TrafoSize > 2 ) |
---|
449 | { |
---|
450 | Int trWidth = width >> 1; |
---|
451 | Int trHeight = height >> 1; |
---|
452 | if( cbfU ) |
---|
453 | { |
---|
454 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
455 | } |
---|
456 | if( cbfV ) |
---|
457 | { |
---|
458 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
459 | } |
---|
460 | } |
---|
461 | else |
---|
462 | { |
---|
463 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
464 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
465 | { |
---|
466 | Int trWidth = width; |
---|
467 | Int trHeight = height; |
---|
468 | if( cbfU ) |
---|
469 | { |
---|
470 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
471 | } |
---|
472 | if( cbfV ) |
---|
473 | { |
---|
474 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
475 | } |
---|
476 | } |
---|
477 | } |
---|
478 | } |
---|
479 | } |
---|
480 | |
---|
481 | // Intra direction for Luma |
---|
482 | Void TEncEntropy::encodeIntraDirModeLuma ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU ) |
---|
483 | { |
---|
484 | m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU); |
---|
485 | } |
---|
486 | |
---|
487 | // Intra direction for Chroma |
---|
488 | Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
489 | { |
---|
490 | if( bRD ) |
---|
491 | { |
---|
492 | uiAbsPartIdx = 0; |
---|
493 | } |
---|
494 | |
---|
495 | m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx ); |
---|
496 | } |
---|
497 | |
---|
498 | Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
499 | { |
---|
500 | if( bRD ) |
---|
501 | { |
---|
502 | uiAbsPartIdx = 0; |
---|
503 | } |
---|
504 | if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode. |
---|
505 | { |
---|
506 | encodeIntraDirModeLuma ( pcCU, uiAbsPartIdx,true ); |
---|
507 | #if H_3D_DIM_SDC |
---|
508 | if(!pcCU->getSDCFlag(uiAbsPartIdx)) |
---|
509 | #endif |
---|
510 | encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD ); |
---|
511 | } |
---|
512 | else // if it is Inter mode, encode motion vector and reference index |
---|
513 | { |
---|
514 | encodePUWise( pcCU, uiAbsPartIdx, bRD ); |
---|
515 | } |
---|
516 | } |
---|
517 | |
---|
518 | /** encode motion information for every PU block |
---|
519 | * \param pcCU |
---|
520 | * \param uiAbsPartIdx |
---|
521 | * \param bRD |
---|
522 | * \returns Void |
---|
523 | */ |
---|
524 | Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
525 | { |
---|
526 | if ( bRD ) |
---|
527 | { |
---|
528 | uiAbsPartIdx = 0; |
---|
529 | } |
---|
530 | |
---|
531 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
532 | UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) ); |
---|
533 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ); |
---|
534 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4; |
---|
535 | |
---|
536 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
537 | { |
---|
538 | #if H_MV_ENC_DEC_TRAC |
---|
539 | DTRACE_PU_S("=========== prediction_unit ===========\n") |
---|
540 | //Todo: |
---|
541 | //DTRACE_PU("x0", uiLPelX) |
---|
542 | //DTRACE_PU("x1", uiTPelY) |
---|
543 | #endif |
---|
544 | encodeMergeFlag( pcCU, uiSubPartIdx ); |
---|
545 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
546 | { |
---|
547 | encodeMergeIndex( pcCU, uiSubPartIdx ); |
---|
548 | } |
---|
549 | else |
---|
550 | { |
---|
551 | encodeInterDirPU( pcCU, uiSubPartIdx ); |
---|
552 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
553 | { |
---|
554 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
555 | { |
---|
556 | encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
557 | encodeMvdPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
558 | encodeMVPIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
559 | } |
---|
560 | } |
---|
561 | } |
---|
562 | } |
---|
563 | |
---|
564 | return; |
---|
565 | } |
---|
566 | |
---|
567 | Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
568 | { |
---|
569 | if ( !pcCU->getSlice()->isInterB() ) |
---|
570 | { |
---|
571 | return; |
---|
572 | } |
---|
573 | |
---|
574 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
575 | return; |
---|
576 | } |
---|
577 | |
---|
578 | /** encode reference frame index for a PU block |
---|
579 | * \param pcCU |
---|
580 | * \param uiAbsPartIdx |
---|
581 | * \param eRefList |
---|
582 | * \returns Void |
---|
583 | */ |
---|
584 | Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
585 | { |
---|
586 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
587 | { |
---|
588 | if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) ) |
---|
589 | { |
---|
590 | return; |
---|
591 | } |
---|
592 | |
---|
593 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
594 | { |
---|
595 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
596 | } |
---|
597 | } |
---|
598 | |
---|
599 | return; |
---|
600 | } |
---|
601 | |
---|
602 | /** encode motion vector difference for a PU block |
---|
603 | * \param pcCU |
---|
604 | * \param uiAbsPartIdx |
---|
605 | * \param eRefList |
---|
606 | * \returns Void |
---|
607 | */ |
---|
608 | Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
609 | { |
---|
610 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
611 | |
---|
612 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
613 | { |
---|
614 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
615 | } |
---|
616 | return; |
---|
617 | } |
---|
618 | |
---|
619 | Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
620 | { |
---|
621 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) ) |
---|
622 | { |
---|
623 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
624 | } |
---|
625 | |
---|
626 | return; |
---|
627 | } |
---|
628 | |
---|
629 | Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
630 | { |
---|
631 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth ); |
---|
632 | } |
---|
633 | |
---|
634 | Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
635 | { |
---|
636 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx ); |
---|
637 | } |
---|
638 | |
---|
639 | Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
640 | { |
---|
641 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
642 | } |
---|
643 | |
---|
644 | Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
---|
645 | { |
---|
646 | m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth ); |
---|
647 | } |
---|
648 | Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU ) |
---|
649 | { |
---|
650 | m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU ); |
---|
651 | } |
---|
652 | |
---|
653 | // dQP |
---|
654 | Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
655 | { |
---|
656 | if( bRD ) |
---|
657 | { |
---|
658 | uiAbsPartIdx = 0; |
---|
659 | } |
---|
660 | |
---|
661 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
662 | { |
---|
663 | m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx ); |
---|
664 | } |
---|
665 | } |
---|
666 | |
---|
667 | |
---|
668 | // texture |
---|
669 | /** encode coefficients |
---|
670 | * \param pcCU |
---|
671 | * \param uiAbsPartIdx |
---|
672 | * \param uiDepth |
---|
673 | * \param uiWidth |
---|
674 | * \param uiHeight |
---|
675 | */ |
---|
676 | Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP ) |
---|
677 | { |
---|
678 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
679 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
680 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
681 | #if H_3D_DIM_SDC |
---|
682 | if( pcCU->getSDCFlag( uiAbsPartIdx ) && pcCU->isIntra( uiAbsPartIdx ) ) |
---|
683 | { |
---|
684 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
685 | assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 ); |
---|
686 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 ); |
---|
687 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 ); |
---|
688 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 ); |
---|
689 | } |
---|
690 | |
---|
691 | if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx ) ) |
---|
692 | { |
---|
693 | assert( !pcCU->isSkipped( uiAbsPartIdx ) ); |
---|
694 | assert( !pcCU->isIntra( uiAbsPartIdx) ); |
---|
695 | assert( pcCU->getSlice()->getIsDepth() ); |
---|
696 | } |
---|
697 | |
---|
698 | if( pcCU->getSlice()->getIsDepth() && ( pcCU->getSDCFlag( uiAbsPartIdx ) || pcCU->isIntra( uiAbsPartIdx ) ) ) |
---|
699 | { |
---|
700 | Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1; |
---|
701 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2; |
---|
702 | |
---|
703 | if( !pcCU->getSDCFlag( uiAbsPartIdx ) ) |
---|
704 | { |
---|
705 | for( Int iPart = 0; iPart < iPartNum; iPart++ ) |
---|
706 | { |
---|
707 | if( getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset*iPart ) ) < DIM_NUM_TYPE ) |
---|
708 | { |
---|
709 | m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart ); |
---|
710 | } |
---|
711 | } |
---|
712 | } |
---|
713 | else |
---|
714 | { |
---|
715 | m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx ); |
---|
716 | return; |
---|
717 | } |
---|
718 | } |
---|
719 | #endif |
---|
720 | |
---|
721 | if( pcCU->isIntra(uiAbsPartIdx) ) |
---|
722 | { |
---|
723 | #if !H_MV |
---|
724 | DTRACE_CABAC_VL( g_nSymbolCounter++ ) |
---|
725 | DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" ) |
---|
726 | DTRACE_CABAC_V( uiDepth ) |
---|
727 | DTRACE_CABAC_T( "\n" ) |
---|
728 | #endif |
---|
729 | } |
---|
730 | else |
---|
731 | { |
---|
732 | if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) ) |
---|
733 | { |
---|
734 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
735 | } |
---|
736 | if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) ) |
---|
737 | { |
---|
738 | return; |
---|
739 | } |
---|
740 | } |
---|
741 | |
---|
742 | xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP); |
---|
743 | } |
---|
744 | |
---|
745 | Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType ) |
---|
746 | { |
---|
747 | // This is for Transform unit processing. This may be used at mode selection stage for Inter. |
---|
748 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType ); |
---|
749 | } |
---|
750 | |
---|
751 | Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) |
---|
752 | { |
---|
753 | eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA; |
---|
754 | |
---|
755 | m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType ); |
---|
756 | } |
---|
757 | |
---|
758 | Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ) |
---|
759 | { |
---|
760 | Int count = 0; |
---|
761 | |
---|
762 | for ( Int i = 0; i < uiSize; i++ ) |
---|
763 | { |
---|
764 | count += pcCoef[i] != 0; |
---|
765 | } |
---|
766 | |
---|
767 | return count; |
---|
768 | } |
---|
769 | |
---|
770 | /** encode quantization matrix |
---|
771 | * \param scalingList quantization matrix information |
---|
772 | */ |
---|
773 | Void TEncEntropy::encodeScalingList( TComScalingList* scalingList ) |
---|
774 | { |
---|
775 | m_pcEntropyCoderIf->codeScalingList( scalingList ); |
---|
776 | } |
---|
777 | |
---|
778 | #if H_3D_INTER_SDC |
---|
779 | Void TEncEntropy::encodeDeltaDC ( TComDataCU* pcCU, UInt absPartIdx ) |
---|
780 | { |
---|
781 | m_pcEntropyCoderIf->codeDeltaDC( pcCU, absPartIdx ); |
---|
782 | } |
---|
783 | |
---|
784 | Void TEncEntropy::encodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
785 | { |
---|
786 | if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getInterSdcFlag() ) || |
---|
787 | ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getIntraSdcWedgeFlag() ) ) |
---|
788 | { |
---|
789 | return; |
---|
790 | } |
---|
791 | |
---|
792 | if( !pcCU->getSlice()->getIsDepth() || pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N || pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
793 | { |
---|
794 | return; |
---|
795 | } |
---|
796 | |
---|
797 | assert( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) ); |
---|
798 | |
---|
799 | if( bRD ) |
---|
800 | { |
---|
801 | uiAbsPartIdx = 0; |
---|
802 | } |
---|
803 | |
---|
804 | m_pcEntropyCoderIf->codeSDCFlag( pcCU, uiAbsPartIdx ); |
---|
805 | } |
---|
806 | |
---|
807 | #endif |
---|
808 | #if H_3D_DBBP |
---|
809 | Void TEncEntropy::encodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
810 | { |
---|
811 | if( bRD ) |
---|
812 | { |
---|
813 | uiAbsPartIdx = 0; |
---|
814 | } |
---|
815 | m_pcEntropyCoderIf->codeDBBPFlag( pcCU, uiAbsPartIdx ); |
---|
816 | } |
---|
817 | #endif |
---|
818 | //! \} |
---|