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