source: 3DVCSoftware/trunk/source/Lib/TLibEncoder/TEncAdaptiveLoopFilter.h @ 2

Last change on this file since 2 was 2, checked in by hhi, 13 years ago

inital import

  • Property svn:eol-style set to native
File size: 15.6 KB
Line 
1
2
3/** \file     TEncAdaptiveLoopFilter.h
4 \brief    estimation part of adaptive loop filter class (header)
5 */
6
7#ifndef __TENCADAPTIVELOOPFILTER__
8#define __TENCADAPTIVELOOPFILTER__
9
10#include "../TLibCommon/TComAdaptiveLoopFilter.h"
11#include "../TLibCommon/TComPic.h"
12
13#include "TEncEntropy.h"
14#include "TEncSbac.h"
15#include "../TLibCommon/TComBitCounter.h"
16
17// ====================================================================================================================
18// Class definition
19// ====================================================================================================================
20#if MTK_SAO
21
22class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset
23{
24private:
25  Double            m_dLambdaLuma;
26  Double            m_dLambdaChroma;
27
28  TEncEntropy*      m_pcEntropyCoder;
29  TEncSbac***       m_pppcRDSbacCoder;
30  TEncSbac*         m_pcRDGoOnSbacCoder;
31
32  Int64  ***m_iCount ;     //[MAX_NUM_QAO_PART][MAX_NUM_QAO_TYPE][MAX_NUM_QAO_CLASS];
33  Int64  ***m_iOffset;     //[MAX_NUM_QAO_PART][MAX_NUM_QAO_TYPE][MAX_NUM_QAO_CLASS];
34  Int64  ***m_iOffsetOrg  ;      //[MAX_NUM_QAO_PART][MAX_NUM_QAO_TYPE];
35  Int64  **m_iRate  ;      //[MAX_NUM_QAO_PART][MAX_NUM_QAO_TYPE];
36  Int64  **m_iDist  ;      //[MAX_NUM_QAO_PART][MAX_NUM_QAO_TYPE];
37  Double **m_dCost  ;      //[MAX_NUM_QAO_PART][MAX_NUM_QAO_TYPE];
38  Double *m_dCostPartBest ;//[MAX_NUM_QAO_PART];
39  Int64  *m_iDistOrg;      //[MAX_NUM_QAO_PART];
40  Int    *m_iTypePartBest ;//[MAX_NUM_QAO_PART];
41
42  Bool    m_bUseSBACRD;
43
44public:
45  Void startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder);
46  Void endSaoEnc();
47  Void SAOProcess(Double dLambda);
48  Void xQuadTreeDecisionFunc(Int iPartIdx, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, Double &dCostFinal);
49  Void xQAOOnePart(SAOQTPart* pQAOOnePart, Int iPartIdx);
50  Void xPartTreeDisable(Int iPartIdx);
51  Void xGetQAOStats(TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest);
52  Void calcAoStatsCu(Int iAddr, Int iPartIdx);
53  Void destoryEncBuffer();
54  Void createEncBuffer();
55};
56#endif
57
58/// estimation part of adaptive loop filter class
59class TEncAdaptiveLoopFilter : public TComAdaptiveLoopFilter
60{
61private:
62  static const Int m_aiSymmetricArray9x9[81];     ///< scan index for 9x9 filter
63  static const Int m_aiSymmetricArray7x7[49];     ///< scan index for 7x7 filter
64  static const Int m_aiSymmetricArray5x5[25];     ///< scan index for 5x5 filter
65#if TI_ALF_MAX_VSIZE_7
66  static const Int m_aiSymmetricArray9x7[63];     ///< scan index for 9x7 filter
67#endif
68 
69  Double** m_ppdAlfCorr;
70  Double* m_pdDoubleAlfCoeff;
71 
72  SliceType m_eSliceType;
73  Int m_iPicNalReferenceIdc;
74 
75  Double m_dLambdaLuma;
76  Double m_dLambdaChroma;
77 
78  TEncEntropy* m_pcEntropyCoder;
79 
80  TComPic* m_pcPic;
81  ALFParam* m_pcBestAlfParam;
82  ALFParam* m_pcTempAlfParam;
83 
84  TComPicYuv* m_pcPicYuvBest;
85  TComPicYuv* m_pcPicYuvTmp;
86 
87  UInt m_uiNumSCUInCU;
88 
89  Int m_varIndTab[NO_VAR_BINS];
90  double ***m_yGlobalSym;
91  double ****m_EGlobalSym;
92  double *m_pixAcc;
93  Int **m_filterCoeffSymQuant;
94  imgpel **m_varImg;
95  imgpel **m_maskImg;
96  Int m_im_width;
97  Int m_im_height;
98  ALFParam *m_tempALFp;
99  TEncEntropy* m_pcDummyEntropyCoder;
100 
101  double **m_y_merged;
102  double ***m_E_merged;
103  double *m_pixAcc_merged;
104  double *m_y_temp;
105  double **m_E_temp;
106 
107  Int *m_filterCoeffQuantMod;
108  double *m_filterCoeff;
109  Int *m_filterCoeffQuant;
110  Int **m_diffFilterCoeffQuant;
111  Int **m_FilterCoeffQuantTemp;
112 
113#if MQT_ALF_NPASS
114  Int  m_iUsePreviousFilter;
115  Int  m_iDesignCurrentFilter;
116  Int  m_iFilterIdx;
117#if MQT_BA_RA
118  Int***   m_aiFilterCoeffSavedMethods[NUM_ALF_CLASS_METHOD];
119  Int***   m_aiFilterCoeffSaved;
120#else
121  Int  m_aiFilterCoeffSaved[9][NO_VAR_BINS][MAX_SQR_FILT_LENGTH];
122#endif
123  Int  m_iGOPSize;
124  Int  m_iCurrentPOC;
125  Int  m_iALFEncodePassReduction;
126  Int  m_iALFNumOfRedesign;
127  Int  m_iMatrixBaseFiltNo;
128
129#if TI_ALF_MAX_VSIZE_7
130  static Int  m_aiTapPos9x9_In9x9Sym[21];
131#else
132  static Int  m_aiTapPos9x9_In9x9Sym[22];
133#endif
134  static Int  m_aiTapPos7x7_In9x9Sym[14];
135  static Int  m_aiTapPos5x5_In9x9Sym[8];
136  static Int* m_iTapPosTabIn9x9Sym[NO_TEST_FILT];
137#endif
138
139#if MTK_NONCROSS_INLOOP_FILTER
140  TComPicYuv* m_pcSliceYuvTmp;
141#endif
142
143private:
144  // init / uninit internal variables
145  Void xInitParam      ();
146  Void xUninitParam    ();
147 
148  // create/destroy/copy/set functions of ALF control flags
149  Void xCreateTmpAlfCtrlFlags   ();
150  Void xDestroyTmpAlfCtrlFlags  ();
151  Void xCopyTmpAlfCtrlFlagsTo   ();
152  Void xCopyTmpAlfCtrlFlagsFrom ();
153 
154  // encoder ALF control flags
155  Void xEncodeCUAlfCtrlFlags  ();
156  Void xEncodeCUAlfCtrlFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth);
157 
158  // functions related to correlation computation
159#if MTK_NONCROSS_INLOOP_FILTER
160  Void xCalcCorrelationFunc   ( Int ypos, Int xpos, Pel* pOrg, Pel* pCmp, Int iTap, Int iWidth, Int iHeight, Int iOrgStride, Int iCmpStride, Bool bSymmCopyBlockMatrix);
161#else
162  Void xCalcCorrelationFunc   ( Pel* pOrg, Pel* pCmp, Int iTap, Int iWidth, Int iHeight, Int iOrgStride, Int iCmpStride);
163#endif
164
165  // functions related to filtering
166  Void xFilterCoefQuickSort   ( Double *coef_data, Int *coef_num, Int upper, Int lower );
167  Void xQuantFilterCoef       ( Double* h, Int* qh, Int tap, int bit_depth );
168  Void xClearFilterCoefInt    ( Int* qh, Int N );
169  Void xCopyDecToRestCUs      ( TComPicYuv* pcPicDec, TComPicYuv* pcPicRest );
170  Void xCopyDecToRestCU       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest );
171  Void xFilteringFrameChroma  ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest );
172 
173  // distortion / misc functions
174  UInt64 xCalcSSD             ( Pel* pOrg, Pel* pCmp, Int iWidth, Int iHeight, Int iStride );
175  Void   xCalcRDCost          ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicCmp, ALFParam* pAlfParam, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost );
176  Void   xCalcRDCostChroma    ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicCmp, ALFParam* pAlfParam, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost );
177  Void   xCalcRDCost          ( ALFParam* pAlfParam, UInt64& ruiRate, UInt64 uiDist, Double& rdCost );
178  Int    xGauss               ( Double **a, Int N );
179 
180#if MQT_ALF_NPASS
181  Void  xretriveBlockMatrix    (Int iNumTaps, Int* piTapPosInMaxFilter, Double*** pppdEBase, Double*** pppdETarget, Double** ppdyBase, Double** ppdyTarget );
182  Void  xcalcPredFilterCoeffPrev(Int filtNo);
183  Void  setALFEncodingParam(TComPic *pcPic);
184  Void  setFilterIdx(Int index);
185  Void  setInitialMask(TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec);
186#if MQT_BA_RA
187  Void  xFirstEstimateFilteringFrameLumaAllTap(imgpel* ImgOrg, imgpel* ImgDec, Int Stride, ALFParam* pcAlfSaved,Int* aiVarIndTabBest,Int** ppiBestCoeffSet, Int& ibestfiltNo,Int& ibestfilters_per_fr, Double** ppdBesty,Double*** pppdBestE,Double* pdBestpixAcc,UInt64& ruiRate,Int64& riDist,Double& rdCost); 
188#else
189  Void  xFirstFilteringFrameLumaAllTap(imgpel* ImgOrg, imgpel* ImgDec, imgpel* ImgRest, Int Stride);
190#endif
191  Int64 xFastFiltDistEstimation(Double** ppdE, Double* pdy, Int* piCoeff, Int iFiltLength);
192  Int64 xEstimateFiltDist      (Int filters_per_fr, Int* VarIndTab, Double*** pppdE, Double** ppdy, Int** ppiCoeffSet, Int iFiltLength);
193#endif
194
195
196#if MTK_NONCROSS_INLOOP_FILTER
197  Void xstoreInBlockMatrixforSlices  (imgpel* ImgOrg, imgpel* ImgDec, Int tap, Int iStride);
198  Void xstoreInBlockMatrixforOneSlice(CAlfSlice* pSlice, imgpel* ImgOrg, imgpel* ImgDec, Int tap, Int iStride, Bool bFirstSlice, Bool bLastSlice);
199  Void xfilterSlices_en              (imgpel* ImgDec, imgpel* ImgRest,int filtNo, int Stride);
200  Void xfilterOneSlice_en            (CAlfSlice* pSlice, imgpel* ImgDec, imgpel* ImgRest,int filtNo, int iStride);
201  Void calcVarforSlices              (imgpel **varmap, imgpel *imgY_pad, Int pad_size, Int fl, Int img_stride);
202
203  //only for chroma
204  Void xCalcCorrelationFuncforChromaSlices  (Int ComponentID, Pel* pOrg, Pel* pCmp, Int iTap, Int iOrgStride, Int iCmpStride);
205  Void xCalcCorrelationFuncforChromaOneSlice(CAlfSlice* pSlice, Pel* pOrg, Pel* pCmp, Int iTap, Int iStride, Bool bLastSlice);
206  Void xFrameChromaforSlices                (Int ComponentID, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, Int *qh, Int iTap);
207#endif
208
209
210protected:
211  /// do ALF for chroma
212  Void xEncALFChroma          ( UInt64 uiLumaRate, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiDist, UInt64& ruiBits );
213public:
214  TEncAdaptiveLoopFilter          ();
215  virtual ~TEncAdaptiveLoopFilter () {}
216 
217  /// allocate temporal memory
218  Void startALFEnc(TComPic* pcPic, TEncEntropy* pcEntropyCoder);
219 
220  /// destroy temporal memory
221  Void endALFEnc();
222 
223  /// estimate ALF parameters
224  Void ALFProcess(ALFParam* pcAlfParam, Double dLambda, UInt64& ruiDist, UInt64& ruiBits, UInt& ruiMaxAlfCtrlDepth );
225  /// test ALF for luma
226  Void xEncALFLuma_qc                  ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiMinRate, 
227                                         UInt64& ruiMinDist, Double& rdMinCost );
228  Void xCUAdaptiveControl_qc           ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiMinRate, 
229                                         UInt64& ruiMinDist, Double& rdMinCost );
230#if TSB_ALF_HEADER
231  Void xSetCUAlfCtrlFlags_qc            (UInt uiAlfCtrlDepth, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, 
232                                         UInt64& ruiDist, ALFParam *pAlfParam);
233  Void xSetCUAlfCtrlFlag_qc             (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiAlfCtrlDepth, TComPicYuv* pcPicOrg,
234                                         TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiDist, ALFParam *pAlfParam);
235#else
236  Void xSetCUAlfCtrlFlags_qc            (UInt uiAlfCtrlDepth, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, 
237                                         UInt64& ruiDist);
238  Void xSetCUAlfCtrlFlag_qc             (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiAlfCtrlDepth, TComPicYuv* pcPicOrg,
239                                         TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiDist);
240#endif
241  Void xReDesignFilterCoeff_qc          (TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec,  TComPicYuv* pcPicRest, Bool bReadCorr);
242  Void xFilterTapDecision_qc            (TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiMinRate, 
243                                         UInt64& ruiMinDist, Double& rdMinCost);
244  Void xFirstFilteringFrameLuma         (imgpel* ImgOrg, imgpel* ImgDec, imgpel* ImgRest, ALFParam* ALFp, Int tap,  Int Stride);
245#if MTK_NONCROSS_INLOOP_FILTER
246  Void xstoreInBlockMatrix(Int ypos, Int xpos, Int iheight, Int iwidth, Bool bResetBlockMatrix, Bool bSymmCopyBlockMatrix, imgpel* ImgOrg, imgpel* ImgDec, Int tap, Int Stride);
247#else
248  Void xstoreInBlockMatrix(imgpel* ImgOrg, imgpel* ImgDec, Int tap, Int Stride);
249#endif
250  Void xFilteringFrameLuma_qc(imgpel* ImgOrg, imgpel* imgY_pad, imgpel* ImgFilt, ALFParam* ALFp, Int tap, Int Stride);
251#if MTK_NONCROSS_INLOOP_FILTER
252  Void xfilterFrame_en(int ypos, int xpos, int iheight, int iwidth, imgpel* ImgDec, imgpel* ImgRest,int filtNo, int Stride);
253#else
254  Void xfilterFrame_en(imgpel* ImgDec, imgpel* ImgRest,int filtNo, int Stride);
255#endif
256  Void xcalcPredFilterCoeff(Int filtNo);
257#if MQT_ALF_NPASS 
258  UInt xcodeFiltCoeff(Int **filterCoeffSymQuant, Int filtNo, Int varIndTab[], Int filters_per_fr_best, Int frNo, ALFParam* ALFp);
259#else
260  Void xcodeFiltCoeff(Int **filterCoeffSymQuant, Int filtNo, Int varIndTab[], Int filters_per_fr_best, Int frNo, ALFParam* ALFp);
261#endif
262  Void xfindBestFilterVarPred(double **ySym, double ***ESym, double *pixAcc, Int **filterCoeffSym, Int **filterCoeffSymQuant,
263                              Int filtNo, Int *filters_per_fr_best, Int varIndTab[], imgpel **imgY_rec, imgpel **varImg, 
264                              imgpel **maskImg, imgpel **imgY_pad, double lambda_val);
265  double xfindBestCoeffCodMethod(int codedVarBins[NO_VAR_BINS], int *forceCoeff0, 
266                                 int **filterCoeffSymQuant, int fl, int sqrFiltLength, 
267                                 int filters_per_fr, double errorForce0CoeffTab[NO_VAR_BINS][2], 
268                                 double *errorQuant, double lambda);
269  Void xcollectStatCodeFilterCoeffForce0(int **pDiffQFilterCoeffIntPP, int fl, int sqrFiltLength, int filters_per_group, 
270                                         int bitsVarBin[]);
271  Void xdecideCoeffForce0(int codedVarBins[NO_VAR_BINS], double errorForce0Coeff[], double errorForce0CoeffTab[NO_VAR_BINS][2], 
272                          int bitsVarBin[NO_VAR_BINS], double lambda, int filters_per_fr);
273  Int xsendAllFiltersPPPredForce0(int **FilterCoeffQuant, int fl, int sqrFiltLength, int filters_per_group, 
274                                  int codedVarBins[NO_VAR_BINS], int createBistream, ALFParam* ALFp);
275  Int xsendAllFiltersPPPred(int **FilterCoeffQuant, int fl, int sqrFiltLength, 
276                            int filters_per_group, int createBistream, ALFParam* ALFp);
277  Int xcodeAuxInfo(int filtNo, int noFilters, int varIndTab[NO_VAR_BINS], int frNo, int createBitstream,int realfiltNo, ALFParam* ALFp);
278  Int xcodeFilterCoeff(int **pDiffQFilterCoeffIntPP, int fl, int sqrFiltLength, int filters_per_group, int createBitstream);
279  Int lengthGolomb(int coeffVal, int k);
280  Int lengthPredFlags(int force0, int predMethod, int codedVarBins[NO_VAR_BINS], 
281                      int filters_per_group, int createBitstream);
282  Int lengthFilterCoeffs(int sqrFiltLength, int filters_per_group, int pDepthInt[], 
283                         int **FilterCoeff, int kMinTab[], int createBitstream);
284  //cholesky related
285  Double findFilterCoeff(double ***EGlobalSeq, double **yGlobalSeq, double *pixAccGlobalSeq, int **filterCoeffSeq,
286                         int **filterCoeffQuantSeq, int intervalBest[NO_VAR_BINS][2], int varIndTab[NO_VAR_BINS], int sqrFiltLength, 
287                         int filters_per_fr, int *weights, int bit_depth, double errorTabForce0Coeff[NO_VAR_BINS][2]);
288  Double QuantizeIntegerFilterPP(double *filterCoeff, int *filterCoeffQuant, double **E, double *y, 
289                                 int sqrFiltLength, int *weights, int bit_depth);
290  Void roundFiltCoeff(int *FilterCoeffQuan, double *FilterCoeff, int sqrFiltLength, int factor);
291  double findFilterGroupingError(double ***EGlobalSeq, double **yGlobalSeq, double *pixAccGlobalSeq, 
292                                 int intervalBest[NO_VAR_BINS][2], int sqrFiltLength, int filters_per_fr);
293  double mergeFiltersGreedy(double **yGlobalSeq, double ***EGlobalSeq, double *pixAccGlobalSeq, 
294                            int intervalBest[NO_VAR_BINS][2], int sqrFiltLength, int noIntervals);
295  double calculateErrorAbs(double **A, double *b, double y, int size);
296  double calculateErrorCoeffProvided(double **A, double *b, double *c, int size);
297  Void add_b(double *bmerged, double **b, int start, int stop, int size);
298  Void add_A(double **Amerged, double ***A, int start, int stop, int size);
299  Int gnsSolveByChol(double **LHS, double *rhs, double *x, int noEq);
300  Void  gnsBacksubstitution(double R[MAX_SQR_FILT_LENGTH][MAX_SQR_FILT_LENGTH], double z[MAX_SQR_FILT_LENGTH], 
301                            int R_size, double A[MAX_SQR_FILT_LENGTH]);
302  Void gnsTransposeBacksubstitution(double U[MAX_SQR_FILT_LENGTH][MAX_SQR_FILT_LENGTH], double rhs[], double x[],
303                                    int order);
304  Int gnsCholeskyDec(double **inpMatr, double outMatr[MAX_SQR_FILT_LENGTH][MAX_SQR_FILT_LENGTH], int noEq);
305#if MQT_ALF_NPASS
306  Void  setGOPSize(Int val) { m_iGOPSize = val; }
307  Void  setALFEncodePassReduction (Int iVal) {m_iALFEncodePassReduction = iVal;}
308
309#if MQT_BA_RA
310  Void createAlfGlobalBuffers(Int iALFEncodePassReduction);
311  Void destroyAlfGlobalBuffers();
312#endif
313#endif
314};
315#endif
Note: See TracBrowser for help on using the repository browser.