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