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 | #if H_3D_IC |
---|
160 | Void TEncEntropy::encodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
161 | { |
---|
162 | if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() ) |
---|
163 | { |
---|
164 | return; |
---|
165 | } |
---|
166 | |
---|
167 | if( !pcCU->getSlice()->getApplyIC() ) |
---|
168 | return; |
---|
169 | |
---|
170 | if( bRD ) |
---|
171 | { |
---|
172 | uiAbsPartIdx = 0; |
---|
173 | } |
---|
174 | |
---|
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 | m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
243 | } |
---|
244 | |
---|
245 | /** Encode I_PCM information. |
---|
246 | * \param pcCU pointer to CU |
---|
247 | * \param uiAbsPartIdx CU index |
---|
248 | * \param bRD flag indicating estimation or encoding |
---|
249 | * \returns Void |
---|
250 | */ |
---|
251 | Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
252 | { |
---|
253 | if(!pcCU->getSlice()->getSPS()->getUsePCM() |
---|
254 | || pcCU->getWidth(uiAbsPartIdx) > (1<<pcCU->getSlice()->getSPS()->getPCMLog2MaxSize()) |
---|
255 | || pcCU->getWidth(uiAbsPartIdx) < (1<<pcCU->getSlice()->getSPS()->getPCMLog2MinSize())) |
---|
256 | { |
---|
257 | return; |
---|
258 | } |
---|
259 | #if H_3D_DIM_SDC |
---|
260 | if( pcCU->getSDCFlag(uiAbsPartIdx) ) |
---|
261 | { |
---|
262 | return; |
---|
263 | } |
---|
264 | #endif |
---|
265 | |
---|
266 | if( bRD ) |
---|
267 | { |
---|
268 | uiAbsPartIdx = 0; |
---|
269 | } |
---|
270 | |
---|
271 | m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx ); |
---|
272 | } |
---|
273 | |
---|
274 | Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP ) |
---|
275 | { |
---|
276 | const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth; |
---|
277 | const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth; |
---|
278 | UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA , uiTrIdx ); |
---|
279 | UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
280 | UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
281 | |
---|
282 | if(uiTrIdx==0) |
---|
283 | { |
---|
284 | m_bakAbsPartIdxCU = uiAbsPartIdx; |
---|
285 | } |
---|
286 | if( uiLog2TrafoSize == 2 ) |
---|
287 | { |
---|
288 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
289 | if( ( uiAbsPartIdx % partNum ) == 0 ) |
---|
290 | { |
---|
291 | m_uiBakAbsPartIdx = uiAbsPartIdx; |
---|
292 | m_uiBakChromaOffset = offsetChroma; |
---|
293 | } |
---|
294 | else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
295 | { |
---|
296 | cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx ); |
---|
297 | cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx ); |
---|
298 | } |
---|
299 | } |
---|
300 | |
---|
301 | if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) ) |
---|
302 | { |
---|
303 | assert( uiSubdiv ); |
---|
304 | } |
---|
305 | else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) && (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) ) |
---|
306 | { |
---|
307 | if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
308 | { |
---|
309 | assert( uiSubdiv ); |
---|
310 | } |
---|
311 | else |
---|
312 | { |
---|
313 | assert(!uiSubdiv ); |
---|
314 | } |
---|
315 | } |
---|
316 | else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) |
---|
317 | { |
---|
318 | assert( uiSubdiv ); |
---|
319 | } |
---|
320 | else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) |
---|
321 | { |
---|
322 | assert( !uiSubdiv ); |
---|
323 | } |
---|
324 | else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) |
---|
325 | { |
---|
326 | assert( !uiSubdiv ); |
---|
327 | } |
---|
328 | else |
---|
329 | { |
---|
330 | assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); |
---|
331 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); |
---|
332 | } |
---|
333 | |
---|
334 | const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx ); |
---|
335 | const Bool bFirstCbfOfCU = uiTrDepthCurr == 0; |
---|
336 | if( bFirstCbfOfCU || uiLog2TrafoSize > 2 ) |
---|
337 | { |
---|
338 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ) |
---|
339 | { |
---|
340 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ); |
---|
341 | } |
---|
342 | if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ) |
---|
343 | { |
---|
344 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ); |
---|
345 | } |
---|
346 | } |
---|
347 | else if( uiLog2TrafoSize == 2 ) |
---|
348 | { |
---|
349 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) ); |
---|
350 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) ); |
---|
351 | } |
---|
352 | |
---|
353 | if( uiSubdiv ) |
---|
354 | { |
---|
355 | UInt size; |
---|
356 | width >>= 1; |
---|
357 | height >>= 1; |
---|
358 | size = width*height; |
---|
359 | uiTrIdx++; |
---|
360 | ++uiDepth; |
---|
361 | const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1); |
---|
362 | |
---|
363 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
364 | |
---|
365 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
366 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
367 | |
---|
368 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
369 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
370 | |
---|
371 | uiAbsPartIdx += partNum; offsetLuma += size; offsetChroma += (size>>2); |
---|
372 | xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ); |
---|
373 | } |
---|
374 | else |
---|
375 | { |
---|
376 | #if !H_MV_ENC_DEC_TRAC |
---|
377 | { |
---|
378 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
379 | DTRACE_CABAC_T( "\tTrIdx: abspart=" ); |
---|
380 | DTRACE_CABAC_V( uiAbsPartIdx ); |
---|
381 | DTRACE_CABAC_T( "\tdepth=" ); |
---|
382 | DTRACE_CABAC_V( uiDepth ); |
---|
383 | DTRACE_CABAC_T( "\ttrdepth=" ); |
---|
384 | DTRACE_CABAC_V( pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
385 | DTRACE_CABAC_T( "\n" ); |
---|
386 | } |
---|
387 | #endif |
---|
388 | |
---|
389 | if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) |
---|
390 | { |
---|
391 | assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) ); |
---|
392 | // printf( "saved one bin! " ); |
---|
393 | } |
---|
394 | else |
---|
395 | { |
---|
396 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) ); |
---|
397 | } |
---|
398 | |
---|
399 | |
---|
400 | if ( cbfY || cbfU || cbfV ) |
---|
401 | { |
---|
402 | // dQP: only for LCU once |
---|
403 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
404 | { |
---|
405 | if ( bCodeDQP ) |
---|
406 | { |
---|
407 | encodeQP( pcCU, m_bakAbsPartIdxCU ); |
---|
408 | bCodeDQP = false; |
---|
409 | } |
---|
410 | } |
---|
411 | } |
---|
412 | if( cbfY ) |
---|
413 | { |
---|
414 | Int trWidth = width; |
---|
415 | Int trHeight = height; |
---|
416 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); |
---|
417 | } |
---|
418 | if( uiLog2TrafoSize > 2 ) |
---|
419 | { |
---|
420 | Int trWidth = width >> 1; |
---|
421 | Int trHeight = height >> 1; |
---|
422 | if( cbfU ) |
---|
423 | { |
---|
424 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
425 | } |
---|
426 | if( cbfV ) |
---|
427 | { |
---|
428 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
429 | } |
---|
430 | } |
---|
431 | else |
---|
432 | { |
---|
433 | UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 ); |
---|
434 | if( ( uiAbsPartIdx % partNum ) == (partNum - 1) ) |
---|
435 | { |
---|
436 | Int trWidth = width; |
---|
437 | Int trHeight = height; |
---|
438 | if( cbfU ) |
---|
439 | { |
---|
440 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U ); |
---|
441 | } |
---|
442 | if( cbfV ) |
---|
443 | { |
---|
444 | m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V ); |
---|
445 | } |
---|
446 | } |
---|
447 | } |
---|
448 | } |
---|
449 | } |
---|
450 | |
---|
451 | // Intra direction for Luma |
---|
452 | Void TEncEntropy::encodeIntraDirModeLuma ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU ) |
---|
453 | { |
---|
454 | m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, absPartIdx , isMultiplePU); |
---|
455 | } |
---|
456 | |
---|
457 | // Intra direction for Chroma |
---|
458 | Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
459 | { |
---|
460 | if( bRD ) |
---|
461 | { |
---|
462 | uiAbsPartIdx = 0; |
---|
463 | } |
---|
464 | |
---|
465 | m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx ); |
---|
466 | } |
---|
467 | |
---|
468 | Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
469 | { |
---|
470 | if( bRD ) |
---|
471 | { |
---|
472 | uiAbsPartIdx = 0; |
---|
473 | } |
---|
474 | if( pcCU->isIntra( uiAbsPartIdx ) ) // If it is Intra mode, encode intra prediction mode. |
---|
475 | { |
---|
476 | encodeIntraDirModeLuma ( pcCU, uiAbsPartIdx,true ); |
---|
477 | #if H_3D_DIM_SDC |
---|
478 | if(!pcCU->getSDCFlag(uiAbsPartIdx)) |
---|
479 | #endif |
---|
480 | encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD ); |
---|
481 | } |
---|
482 | else // if it is Inter mode, encode motion vector and reference index |
---|
483 | { |
---|
484 | encodePUWise( pcCU, uiAbsPartIdx, bRD ); |
---|
485 | } |
---|
486 | } |
---|
487 | |
---|
488 | /** encode motion information for every PU block |
---|
489 | * \param pcCU |
---|
490 | * \param uiAbsPartIdx |
---|
491 | * \param bRD |
---|
492 | * \returns Void |
---|
493 | */ |
---|
494 | Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
495 | { |
---|
496 | if ( bRD ) |
---|
497 | { |
---|
498 | uiAbsPartIdx = 0; |
---|
499 | } |
---|
500 | |
---|
501 | PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx ); |
---|
502 | UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) ); |
---|
503 | UInt uiDepth = pcCU->getDepth( uiAbsPartIdx ); |
---|
504 | UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4; |
---|
505 | |
---|
506 | for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset ) |
---|
507 | { |
---|
508 | #if H_MV_ENC_DEC_TRAC |
---|
509 | DTRACE_PU_S("=========== prediction_unit ===========\n") |
---|
510 | //Todo: |
---|
511 | //DTRACE_PU("x0", uiLPelX) |
---|
512 | //DTRACE_PU("x1", uiTPelY) |
---|
513 | #endif |
---|
514 | encodeMergeFlag( pcCU, uiSubPartIdx ); |
---|
515 | if ( pcCU->getMergeFlag( uiSubPartIdx ) ) |
---|
516 | { |
---|
517 | encodeMergeIndex( pcCU, uiSubPartIdx ); |
---|
518 | } |
---|
519 | else |
---|
520 | { |
---|
521 | encodeInterDirPU( pcCU, uiSubPartIdx ); |
---|
522 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
523 | { |
---|
524 | if ( pcCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
525 | { |
---|
526 | encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
527 | encodeMvdPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
528 | encodeMVPIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) ); |
---|
529 | } |
---|
530 | } |
---|
531 | } |
---|
532 | } |
---|
533 | |
---|
534 | return; |
---|
535 | } |
---|
536 | |
---|
537 | Void TEncEntropy::encodeInterDirPU( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
538 | { |
---|
539 | if ( !pcCU->getSlice()->isInterB() ) |
---|
540 | { |
---|
541 | return; |
---|
542 | } |
---|
543 | |
---|
544 | m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx ); |
---|
545 | return; |
---|
546 | } |
---|
547 | |
---|
548 | /** encode reference frame index for a PU block |
---|
549 | * \param pcCU |
---|
550 | * \param uiAbsPartIdx |
---|
551 | * \param eRefList |
---|
552 | * \returns Void |
---|
553 | */ |
---|
554 | Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
555 | { |
---|
556 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
557 | { |
---|
558 | if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) ) |
---|
559 | { |
---|
560 | return; |
---|
561 | } |
---|
562 | |
---|
563 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
564 | { |
---|
565 | m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
566 | } |
---|
567 | } |
---|
568 | |
---|
569 | return; |
---|
570 | } |
---|
571 | |
---|
572 | /** encode motion vector difference for a PU block |
---|
573 | * \param pcCU |
---|
574 | * \param uiAbsPartIdx |
---|
575 | * \param eRefList |
---|
576 | * \returns Void |
---|
577 | */ |
---|
578 | Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
579 | { |
---|
580 | assert( !pcCU->isIntra( uiAbsPartIdx ) ); |
---|
581 | |
---|
582 | if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) ) |
---|
583 | { |
---|
584 | m_pcEntropyCoderIf->codeMvd( pcCU, uiAbsPartIdx, eRefList ); |
---|
585 | } |
---|
586 | return; |
---|
587 | } |
---|
588 | |
---|
589 | Void TEncEntropy::encodeMVPIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
590 | { |
---|
591 | if ( (pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList )) ) |
---|
592 | { |
---|
593 | m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList ); |
---|
594 | } |
---|
595 | |
---|
596 | return; |
---|
597 | } |
---|
598 | |
---|
599 | Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
600 | { |
---|
601 | m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth ); |
---|
602 | } |
---|
603 | |
---|
604 | Void TEncEntropy::encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
605 | { |
---|
606 | m_pcEntropyCoderIf->codeTransformSubdivFlag( uiSymbol, uiCtx ); |
---|
607 | } |
---|
608 | |
---|
609 | Void TEncEntropy::encodeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
610 | { |
---|
611 | m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx ); |
---|
612 | } |
---|
613 | |
---|
614 | Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
---|
615 | { |
---|
616 | m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth ); |
---|
617 | } |
---|
618 | Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU ) |
---|
619 | { |
---|
620 | m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU ); |
---|
621 | } |
---|
622 | |
---|
623 | // dQP |
---|
624 | Void TEncEntropy::encodeQP( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
625 | { |
---|
626 | if( bRD ) |
---|
627 | { |
---|
628 | uiAbsPartIdx = 0; |
---|
629 | } |
---|
630 | |
---|
631 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
632 | { |
---|
633 | m_pcEntropyCoderIf->codeDeltaQP( pcCU, uiAbsPartIdx ); |
---|
634 | } |
---|
635 | } |
---|
636 | |
---|
637 | |
---|
638 | // texture |
---|
639 | /** encode coefficients |
---|
640 | * \param pcCU |
---|
641 | * \param uiAbsPartIdx |
---|
642 | * \param uiDepth |
---|
643 | * \param uiWidth |
---|
644 | * \param uiHeight |
---|
645 | */ |
---|
646 | Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP ) |
---|
647 | { |
---|
648 | UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight(); |
---|
649 | UInt uiLumaOffset = uiMinCoeffSize*uiAbsPartIdx; |
---|
650 | UInt uiChromaOffset = uiLumaOffset>>2; |
---|
651 | #if QC_SDC_UNIFY_G0130 |
---|
652 | #if H_3D_DIM_SDC |
---|
653 | if( pcCU->getSDCFlag( uiAbsPartIdx ) && pcCU->isIntra( uiAbsPartIdx ) ) |
---|
654 | { |
---|
655 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
656 | assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 ); |
---|
657 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 ); |
---|
658 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 ); |
---|
659 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 ); |
---|
660 | } |
---|
661 | #endif |
---|
662 | |
---|
663 | #if H_3D_INTER_SDC |
---|
664 | if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx ) ) |
---|
665 | { |
---|
666 | assert( !pcCU->isSkipped( uiAbsPartIdx ) ); |
---|
667 | assert( !pcCU->isIntra( uiAbsPartIdx) ); |
---|
668 | assert( pcCU->getSlice()->getIsDepth() ); |
---|
669 | } |
---|
670 | #endif |
---|
671 | |
---|
672 | if( pcCU->getSDCFlag( uiAbsPartIdx ) || pcCU->isIntra( uiAbsPartIdx ) ) |
---|
673 | { |
---|
674 | Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1; |
---|
675 | UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2; |
---|
676 | |
---|
677 | if( !pcCU->getSDCFlag( uiAbsPartIdx ) ) |
---|
678 | { |
---|
679 | for( Int iPart = 0; iPart < iPartNum; iPart++ ) |
---|
680 | { |
---|
681 | if( getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset*iPart ) ) < DIM_NUM_TYPE ) |
---|
682 | { |
---|
683 | m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart ); |
---|
684 | } |
---|
685 | } |
---|
686 | } |
---|
687 | else |
---|
688 | { |
---|
689 | m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx ); |
---|
690 | return; |
---|
691 | } |
---|
692 | } |
---|
693 | #else |
---|
694 | #if H_3D_DIM_SDC |
---|
695 | if( pcCU->getSDCFlag( uiAbsPartIdx ) ) |
---|
696 | { |
---|
697 | assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ); |
---|
698 | assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 ); |
---|
699 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 ); |
---|
700 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 ); |
---|
701 | assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 ); |
---|
702 | return; |
---|
703 | } |
---|
704 | #endif |
---|
705 | |
---|
706 | #if H_3D_INTER_SDC |
---|
707 | if( pcCU->getInterSDCFlag( uiAbsPartIdx ) ) |
---|
708 | { |
---|
709 | assert( !pcCU->isSkipped( uiAbsPartIdx ) ); |
---|
710 | assert( !pcCU->isIntra( uiAbsPartIdx) ); |
---|
711 | assert( pcCU->getSlice()->getIsDepth() ); |
---|
712 | |
---|
713 | encodeInterSDCResidualData( pcCU, uiAbsPartIdx, false ); |
---|
714 | return; |
---|
715 | } |
---|
716 | #endif |
---|
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 | /** Encode SAO Offset |
---|
757 | * \param saoLcuParam SAO LCU paramters |
---|
758 | */ |
---|
759 | Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx) |
---|
760 | { |
---|
761 | UInt uiSymbol; |
---|
762 | Int i; |
---|
763 | |
---|
764 | uiSymbol = saoLcuParam->typeIdx + 1; |
---|
765 | if (compIdx!=2) |
---|
766 | { |
---|
767 | m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol); |
---|
768 | } |
---|
769 | if (uiSymbol) |
---|
770 | { |
---|
771 | if (saoLcuParam->typeIdx < 4 && compIdx != 2) |
---|
772 | { |
---|
773 | saoLcuParam->subTypeIdx = saoLcuParam->typeIdx; |
---|
774 | } |
---|
775 | Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY; |
---|
776 | Int offsetTh = 1 << min(bitDepth - 5,5); |
---|
777 | if( saoLcuParam->typeIdx == SAO_BO ) |
---|
778 | { |
---|
779 | for( i=0; i< saoLcuParam->length; i++) |
---|
780 | { |
---|
781 | UInt absOffset = ( (saoLcuParam->offset[i] < 0) ? -saoLcuParam->offset[i] : saoLcuParam->offset[i]); |
---|
782 | m_pcEntropyCoderIf->codeSaoMaxUvlc(absOffset, offsetTh-1); |
---|
783 | } |
---|
784 | for( i=0; i< saoLcuParam->length; i++) |
---|
785 | { |
---|
786 | if (saoLcuParam->offset[i] != 0) |
---|
787 | { |
---|
788 | UInt sign = (saoLcuParam->offset[i] < 0) ? 1 : 0 ; |
---|
789 | m_pcEntropyCoderIf->codeSAOSign(sign); |
---|
790 | } |
---|
791 | } |
---|
792 | uiSymbol = (UInt) (saoLcuParam->subTypeIdx); |
---|
793 | m_pcEntropyCoderIf->codeSaoUflc(5, uiSymbol); |
---|
794 | } |
---|
795 | else if( saoLcuParam->typeIdx < 4 ) |
---|
796 | { |
---|
797 | m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[0], offsetTh-1); |
---|
798 | m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[1], offsetTh-1); |
---|
799 | m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[2], offsetTh-1); |
---|
800 | m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[3], offsetTh-1); |
---|
801 | if (compIdx!=2) |
---|
802 | { |
---|
803 | uiSymbol = (UInt) (saoLcuParam->subTypeIdx); |
---|
804 | m_pcEntropyCoderIf->codeSaoUflc(2, uiSymbol); |
---|
805 | } |
---|
806 | } |
---|
807 | } |
---|
808 | } |
---|
809 | |
---|
810 | /** Encode SAO unit interleaving |
---|
811 | * \param rx |
---|
812 | * \param ry |
---|
813 | * \param pSaoParam |
---|
814 | * \param pcCU |
---|
815 | * \param iCUAddrInSlice |
---|
816 | * \param iCUAddrUpInSlice |
---|
817 | * \param bLFCrossSliceBoundaryFlag |
---|
818 | */ |
---|
819 | Void TEncEntropy::encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp) |
---|
820 | { |
---|
821 | if (saoFlag) |
---|
822 | { |
---|
823 | if (rx>0 && cuAddrInSlice!=0 && allowMergeLeft) |
---|
824 | { |
---|
825 | m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeLeftFlag); |
---|
826 | } |
---|
827 | else |
---|
828 | { |
---|
829 | saoLcuParam->mergeLeftFlag = 0; |
---|
830 | } |
---|
831 | if (saoLcuParam->mergeLeftFlag == 0) |
---|
832 | { |
---|
833 | if ( (ry > 0) && (cuAddrUpInSlice>=0) && allowMergeUp ) |
---|
834 | { |
---|
835 | m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeUpFlag); |
---|
836 | } |
---|
837 | else |
---|
838 | { |
---|
839 | saoLcuParam->mergeUpFlag = 0; |
---|
840 | } |
---|
841 | if (!saoLcuParam->mergeUpFlag) |
---|
842 | { |
---|
843 | encodeSaoOffset(saoLcuParam, compIdx); |
---|
844 | } |
---|
845 | } |
---|
846 | } |
---|
847 | } |
---|
848 | |
---|
849 | Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ) |
---|
850 | { |
---|
851 | Int count = 0; |
---|
852 | |
---|
853 | for ( Int i = 0; i < uiSize; i++ ) |
---|
854 | { |
---|
855 | count += pcCoef[i] != 0; |
---|
856 | } |
---|
857 | |
---|
858 | return count; |
---|
859 | } |
---|
860 | |
---|
861 | /** encode quantization matrix |
---|
862 | * \param scalingList quantization matrix information |
---|
863 | */ |
---|
864 | Void TEncEntropy::encodeScalingList( TComScalingList* scalingList ) |
---|
865 | { |
---|
866 | m_pcEntropyCoderIf->codeScalingList( scalingList ); |
---|
867 | } |
---|
868 | |
---|
869 | #if H_3D_INTER_SDC |
---|
870 | #if QC_SDC_UNIFY_G0130 |
---|
871 | Void TEncEntropy::encodeDeltaDC ( TComDataCU* pcCU, UInt absPartIdx ) |
---|
872 | { |
---|
873 | m_pcEntropyCoderIf->codeDeltaDC( pcCU, absPartIdx ); |
---|
874 | } |
---|
875 | |
---|
876 | Void TEncEntropy::encodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
877 | { |
---|
878 | if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) || |
---|
879 | ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getVPS()->getVpsDepthModesFlag( pcCU->getSlice()->getLayerIdInVps() ) ) ) |
---|
880 | { |
---|
881 | return; |
---|
882 | } |
---|
883 | |
---|
884 | if( !pcCU->getSlice()->getIsDepth() || ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N ) || pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
885 | { |
---|
886 | return; |
---|
887 | } |
---|
888 | |
---|
889 | assert( ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) ); |
---|
890 | |
---|
891 | if( bRD ) |
---|
892 | { |
---|
893 | uiAbsPartIdx = 0; |
---|
894 | } |
---|
895 | |
---|
896 | m_pcEntropyCoderIf->codeSDCFlag( pcCU, uiAbsPartIdx ); |
---|
897 | } |
---|
898 | #else |
---|
899 | Void TEncEntropy::encodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
900 | { |
---|
901 | if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) |
---|
902 | { |
---|
903 | return; |
---|
904 | } |
---|
905 | |
---|
906 | if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
907 | { |
---|
908 | return; |
---|
909 | } |
---|
910 | |
---|
911 | if( bRD ) |
---|
912 | { |
---|
913 | uiAbsPartIdx = 0; |
---|
914 | } |
---|
915 | |
---|
916 | m_pcEntropyCoderIf->codeInterSDCFlag( pcCU, uiAbsPartIdx ); |
---|
917 | } |
---|
918 | |
---|
919 | Void TEncEntropy::encodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD ) |
---|
920 | { |
---|
921 | if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) |
---|
922 | { |
---|
923 | return; |
---|
924 | } |
---|
925 | |
---|
926 | if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) ) |
---|
927 | { |
---|
928 | return; |
---|
929 | } |
---|
930 | |
---|
931 | if( bRD ) |
---|
932 | { |
---|
933 | uiAbsPartIdx = 0; |
---|
934 | } |
---|
935 | |
---|
936 | // number of segments depends on prediction mode for INTRA |
---|
937 | UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 ); |
---|
938 | |
---|
939 | // encode residual data for each segment |
---|
940 | for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ ) |
---|
941 | { |
---|
942 | m_pcEntropyCoderIf->codeInterSDCResidualData( pcCU, uiAbsPartIdx, uiSeg ); |
---|
943 | } |
---|
944 | } |
---|
945 | #endif |
---|
946 | #endif |
---|
947 | |
---|
948 | //! \} |
---|