source: 3DVCSoftware/trunk/source/Lib/TLibCommon/TComTrQuant.h @ 1179

Last change on this file since 1179 was 1179, checked in by tech, 9 years ago

Merged branch 13.1-dev0@1178.

  • Property svn:eol-style set to native
File size: 13.6 KB
Line 
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-2015, 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     TComTrQuant.h
35    \brief    transform and quantization class (header)
36*/
37
38#ifndef __TCOMTRQUANT__
39#define __TCOMTRQUANT__
40
41#include "CommonDef.h"
42#include "TComYuv.h"
43#include "TComDataCU.h"
44#include "ContextTables.h"
45
46//! \ingroup TLibCommon
47//! \{
48
49// ====================================================================================================================
50// Constants
51// ====================================================================================================================
52
53#define QP_BITS                 15
54
55// ====================================================================================================================
56// Type definition
57// ====================================================================================================================
58
59typedef struct
60{
61  Int significantCoeffGroupBits[NUM_SIG_CG_FLAG_CTX][2];
62  Int significantBits[NUM_SIG_FLAG_CTX][2];
63  Int lastXBits[32];
64  Int lastYBits[32];
65  Int m_greaterOneBits[NUM_ONE_FLAG_CTX][2];
66  Int m_levelAbsBits[NUM_ABS_FLAG_CTX][2];
67
68  Int blockCbpBits[3*NUM_QT_CBF_CTX][2];
69  Int blockRootCbpBits[4][2];
70} estBitsSbacStruct;
71
72// ====================================================================================================================
73// Class definition
74// ====================================================================================================================
75
76/// QP class
77class QpParam
78{
79public:
80  QpParam();
81 
82  Int m_iQP;
83  Int m_iPer;
84  Int m_iRem;
85 
86public:
87  Int m_iBits;
88   
89  Void setQpParam( Int qpScaled )
90  {
91    m_iQP   = qpScaled;
92    m_iPer  = qpScaled / 6;
93    m_iRem  = qpScaled % 6;
94    m_iBits = QP_BITS + m_iPer;
95  }
96 
97  Void clear()
98  {
99    m_iQP   = 0;
100    m_iPer  = 0;
101    m_iRem  = 0;
102    m_iBits = 0;
103  }
104 
105 
106  Int per()   const { return m_iPer; }
107  Int rem()   const { return m_iRem; }
108  Int bits()  const { return m_iBits; }
109 
110  Int qp() {return m_iQP;}
111}; // END CLASS DEFINITION QpParam
112
113/// transform and quantization class
114class TComTrQuant
115{
116public:
117  TComTrQuant();
118  ~TComTrQuant();
119 
120  // initialize class
121  Void init                 ( UInt uiMaxTrSize, Bool useRDOQ = false, 
122    Bool useRDOQTS = false,
123    Bool bEnc = false, Bool useTransformSkipFast = false
124#if ADAPTIVE_QP_SELECTION
125    , Bool bUseAdaptQpSelect = false
126#endif
127    );
128 
129  // transform & inverse transform functions
130  Void transformNxN( TComDataCU* pcCU, 
131                     Pel*        pcResidual, 
132                     UInt        uiStride, 
133                     TCoeff*     rpcCoeff, 
134#if ADAPTIVE_QP_SELECTION
135                     Int*&       rpcArlCoeff, 
136#endif
137                     UInt        uiWidth, 
138                     UInt        uiHeight, 
139                     UInt&       uiAbsSum, 
140                     TextType    eTType, 
141                     UInt        uiAbsPartIdx,
142                     Bool        useTransformSkip = false );
143
144  Void invtransformNxN( Bool transQuantBypass, TextType eText, UInt uiMode,Pel* rpcResidual, UInt uiStride, TCoeff*   pcCoeff, UInt uiWidth, UInt uiHeight,  Int scalingListType, Bool useTransformSkip = false );
145  Void invRecurTransformNxN ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eTxt, Pel* rpcResidual, UInt uiAddr,   UInt uiStride, UInt uiWidth, UInt uiHeight,
146                             UInt uiMaxTrMode,  UInt uiTrMode, TCoeff* rpcCoeff );
147 
148  // Misc functions
149  Void setQPforQuant( Int qpy, TextType eTxtType, Int qpBdOffset, Int chromaQPOffset);
150
151#if RDOQ_CHROMA_LAMBDA
152  Void setLambdas ( const Double lambdas[3] ) { for (Int component = 0; component < 3; component++) m_lambdas[component] = lambdas[component]; }
153  Void selectLambda(TextType eTType) { m_dLambda = (eTType == TEXT_LUMA) ? m_lambdas[0] : ((eTType == TEXT_CHROMA_U) ? m_lambdas[1] : m_lambdas[2]); }
154#else
155  Void setLambda(Double dLambda) { m_dLambda = dLambda;}
156#endif
157  Void setRDOQOffset( UInt uiRDOQOffset ) { m_uiRDOQOffset = uiRDOQOffset; }
158 
159  estBitsSbacStruct* m_pcEstBitsSbac;
160 
161  static Int      calcPatternSigCtx( const UInt* sigCoeffGroupFlag, UInt posXCG, UInt posYCG, Int width, Int height );
162
163  static Int      getSigCtxInc     (
164                                     Int                             patternSigCtx,
165                                     UInt                            scanIdx,
166                                     Int                             posX,
167                                     Int                             posY,
168                                     Int                             log2BlkSize,
169                                     TextType                        textureType
170                                    );
171  static UInt getSigCoeffGroupCtxInc  ( const UInt*                   uiSigCoeffGroupFlag,
172                                       const UInt                       uiCGPosX,
173                                       const UInt                       uiCGPosY,
174                                       Int width, Int height);
175  Void initScalingList                      ();
176  Void destroyScalingList                   ();
177  Void setErrScaleCoeff    ( UInt list, UInt size, UInt qp);
178  Double* getErrScaleCoeff ( UInt list, UInt size, UInt qp) {return m_errScale[size][list][qp];};    //!< get Error Scale Coefficent
179  Int* getQuantCoeff       ( UInt list, UInt qp, UInt size) {return m_quantCoef[size][list][qp];};   //!< get Quant Coefficent
180  Int* getDequantCoeff     ( UInt list, UInt qp, UInt size) {return m_dequantCoef[size][list][qp];}; //!< get DeQuant Coefficent
181  Void setUseScalingList   ( Bool bUseScalingList){ m_scalingListEnabledFlag = bUseScalingList; };
182  Bool getUseScalingList   (){ return m_scalingListEnabledFlag; };
183  Void setFlatScalingList  ();
184  Void xsetFlatScalingList ( UInt list, UInt size, UInt qp);
185  Void xSetScalingListEnc  ( TComScalingList *scalingList, UInt list, UInt size, UInt qp);
186  Void xSetScalingListDec  ( TComScalingList *scalingList, UInt list, UInt size, UInt qp);
187  Void setScalingList      ( TComScalingList *scalingList);
188  Void setScalingListDec   ( TComScalingList *scalingList);
189  Void processScalingListEnc( Int *coeff, Int *quantcoeff, Int quantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc);
190  Void processScalingListDec( Int *coeff, Int *dequantcoeff, Int invQuantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc);
191#if ADAPTIVE_QP_SELECTION
192  Void    initSliceQpDelta() ;
193  Void    storeSliceQpNext(TComSlice* pcSlice);
194  Void    clearSliceARLCnt();
195  Int     getQpDelta(Int qp) { return m_qpDelta[qp]; } 
196  Int*    getSliceNSamples(){ return m_sliceNsamples ;} 
197  Double* getSliceSumC()    { return m_sliceSumC; }
198#endif
199protected:
200#if ADAPTIVE_QP_SELECTION
201  Int     m_qpDelta[MAX_QP+1]; 
202  Int     m_sliceNsamples[LEVEL_RANGE+1]; 
203  Double  m_sliceSumC[LEVEL_RANGE+1] ; 
204#endif
205  Int*    m_plTempCoeff;
206 
207  QpParam  m_cQP;
208#if RDOQ_CHROMA_LAMBDA
209  Double   m_lambdas[3];
210#endif
211  Double   m_dLambda;
212  UInt     m_uiRDOQOffset;
213  UInt     m_uiMaxTrSize;
214  Bool     m_bEnc;
215  Bool     m_useRDOQ;
216  Bool     m_useRDOQTS;
217#if ADAPTIVE_QP_SELECTION
218  Bool     m_bUseAdaptQpSelect;
219#endif
220  Bool     m_useTransformSkipFast;
221  Bool     m_scalingListEnabledFlag;
222  Int      *m_quantCoef      [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4
223  Int      *m_dequantCoef    [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of dequantization matrix coefficient 4x4
224  Double   *m_errScale       [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]; ///< array of quantization matrix coefficient 4x4
225private:
226  // forward Transform
227  Void xT   (Int bitDepth, UInt uiMode,Pel* pResidual, UInt uiStride, Int* plCoeff, Int iWidth, Int iHeight );
228 
229  // skipping Transform
230  Void xTransformSkip (Int bitDepth, Pel* piBlkResi, UInt uiStride, Int* psCoeff, Int width, Int height );
231
232  Void signBitHidingHDQ( TCoeff* pQCoef, TCoeff* pCoef, UInt const *scan, Int* deltaU, Int width, Int height );
233
234  // quantization
235  Void xQuant( TComDataCU* pcCU, 
236               Int*        pSrc, 
237               TCoeff*     pDes, 
238#if ADAPTIVE_QP_SELECTION
239               Int*&       pArlDes,
240#endif
241               Int         iWidth, 
242               Int         iHeight, 
243               UInt&       uiAcSum, 
244               TextType    eTType, 
245               UInt        uiAbsPartIdx );
246
247  // RDOQ functions
248 
249  Void           xRateDistOptQuant ( TComDataCU*                     pcCU,
250                                     Int*                            plSrcCoeff,
251                                     TCoeff*                         piDstCoeff,
252#if ADAPTIVE_QP_SELECTION
253                                     Int*&                           piArlDstCoeff,
254#endif
255                                     UInt                            uiWidth,
256                                     UInt                            uiHeight,
257                                     UInt&                           uiAbsSum,
258                                     TextType                        eTType,
259                                     UInt                            uiAbsPartIdx );
260__inline UInt              xGetCodedLevel  ( Double&                         rd64CodedCost,
261                                             Double&                         rd64CodedCost0,
262                                             Double&                         rd64CodedCostSig,
263                                             Int                             lLevelDouble,
264                                             UInt                            uiMaxAbsLevel,
265                                             UShort                          ui16CtxNumSig,
266                                             UShort                          ui16CtxNumOne,
267                                             UShort                          ui16CtxNumAbs,
268                                             UShort                          ui16AbsGoRice,
269                                             UInt                            c1Idx, 
270                                             UInt                            c2Idx, 
271                                             Int                             iQBits,
272                                             Double                          dTemp,
273                                             Bool                            bLast        ) const;
274__inline Int xGetICRate  ( UInt                            uiAbsLevel,
275                           UShort                          ui16CtxNumOne,
276                           UShort                          ui16CtxNumAbs,
277                           UShort                          ui16AbsGoRice
278                         , UInt                            c1Idx,
279                           UInt                            c2Idx
280                         ) const;
281  __inline Double xGetRateLast     ( const UInt                      uiPosX,
282                                     const UInt                      uiPosY ) const;
283  __inline Double xGetRateSigCoeffGroup (  UShort                    uiSignificanceCoeffGroup,
284                                     UShort                          ui16CtxNumSig ) const;
285  __inline Double xGetRateSigCoef (  UShort                          uiSignificance,
286                                     UShort                          ui16CtxNumSig ) const;
287  __inline Double xGetICost        ( Double                          dRate         ) const; 
288  __inline Double xGetIEPRate      (                                               ) const;
289 
290 
291  // dequantization
292  Void xDeQuant(Int bitDepth, const TCoeff* pSrc, Int* pDes, Int iWidth, Int iHeight, Int scalingListType );
293 
294  // inverse transform
295  Void xIT    (Int bitDepth, UInt uiMode, Int* plCoef, Pel* pResidual, UInt uiStride, Int iWidth, Int iHeight );
296 
297  // inverse skipping transform
298  Void xITransformSkip (Int bitDepth, Int* plCoef, Pel* pResidual, UInt uiStride, Int width, Int height );
299};// END CLASS DEFINITION TComTrQuant
300
301//! \}
302
303#endif // __TCOMTRQUANT__
Note: See TracBrowser for help on using the repository browser.