source: 3DVCSoftware/trunk/source/Lib/TLibCommon/TComAdaptiveLoopFilter.h @ 296

Last change on this file since 296 was 296, checked in by tech, 11 years ago

Reintegrated branch 5.1-dev0 rev. 295.

  • Property svn:eol-style set to native
File size: 10.9 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-2012, 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     TComAdaptiveLoopFilter.h
35    \brief    adaptive loop filter class (header)
36*/
37
38#ifndef __TCOMADAPTIVELOOPFILTER__
39#define __TCOMADAPTIVELOOPFILTER__
40
41#include "CommonDef.h"
42#include "TComPic.h"
43
44//! \ingroup TLibCommon
45//! \{
46
47// ====================================================================================================================
48// Constants
49// ====================================================================================================================
50
51  #define LCUALF_QP_DEPENDENT_BITS    1 
52
53#define ALF_FILTER_LEN       10
54#define ALF_MAX_NUM_COEF     ALF_FILTER_LEN    //!< maximum number of filter coefficients
55#define MAX_SQR_FILT_LENGTH   41                                      //!< ((max_horizontal_tap * max_vertical_tap) / 2 + 1) = ((11 * 5) / 2 + 1)
56
57#if LCUALF_QP_DEPENDENT_BITS
58#define ALF_QP1               28
59#define ALF_QP2               34
60#define ALF_QP3               39
61#else
62#define ALF_NUM_BIT_SHIFT     8                                       ///< bit shift parameter for quantization of ALF param.
63#endif
64
65#define VAR_SIZE_H            4
66#define VAR_SIZE_W            4
67#define NO_VAR_BINS           16
68#define NO_FILTERS            16
69#define MAX_SCAN_VAL          13
70#define MAX_EXP_GOLOMB        16
71
72
73
74/// Luma/Chroma component ID
75enum ALFComponentID
76{
77  ALF_Y = 0,
78  ALF_Cb,
79  ALF_Cr,
80  NUM_ALF_COMPONENT
81};
82/// ALF LCU merge type
83enum ALFLCUMergeType
84{
85  ALF_MERGE_DISABLED = 0,
86  ALF_MERGE_UP,
87  ALF_MERGE_LEFT,
88  ALF_MERGE_FIRST,
89  NUM_ALF_MERGE_TYPE
90};
91///
92/// Filter shape
93///
94enum ALFFilterShape
95{
96  ALF_CROSS9x7_SQUARE3x3 = 0,
97  NUM_ALF_FILTER_SHAPE
98};
99
100extern Int* kTableTabShapes[NUM_ALF_FILTER_SHAPE];
101extern Int depthIntShape1Sym[ALF_MAX_NUM_COEF+1];
102extern Int *pDepthIntTabShapes[NUM_ALF_FILTER_SHAPE];
103
104// ====================================================================================================================
105// Class definition
106// ====================================================================================================================
107
108/// ALF CU control parameters
109struct AlfCUCtrlInfo
110{
111  Int  cu_control_flag;                    //!< slice-level ALF CU control enabled/disabled flag
112  UInt num_alf_cu_flag;                    //!< number of ALF CU control flags
113  UInt alf_max_depth;                      //!< ALF CU control depth
114  std::vector<UInt> alf_cu_flag;           //!< ALF CU control flags (container)
115
116  const AlfCUCtrlInfo& operator= (const AlfCUCtrlInfo& src);  //!< "=" operator
117  AlfCUCtrlInfo():cu_control_flag(0), num_alf_cu_flag(0), alf_max_depth(0) {} //!< constructor
118  Void reset();
119};
120
121
122///
123/// LCU-based ALF processing info
124///
125struct AlfLCUInfo
126{
127  TComDataCU* pcCU;            //!< TComDataCU pointer
128  Int         sliceID;        //!< slice ID
129  Int         tileID;         //!< tile ID
130  UInt        numSGU;        //!< number of slice granularity blocks
131  UInt        startSU;       //!< starting SU z-scan address in LCU
132  UInt        endSU;         //!< ending SU z-scan address in LCU
133  Bool        bAllSUsInLCUInSameSlice; //!< true: all SUs in this LCU belong to same slice
134  std::vector<NDBFBlockInfo*> vpAlfBlock; //!< container for filter block pointers
135
136  NDBFBlockInfo& operator[] (Int idx) { return *( vpAlfBlock[idx]); } //!< [] operator
137  AlfLCUInfo():pcCU(NULL), sliceID(0), tileID(0), numSGU(0), startSU(0), endSU(0), bAllSUsInLCUInSameSlice(false) {} //!< constructor
138};
139
140
141///
142/// adaptive loop filter class
143///
144class TComAdaptiveLoopFilter
145{
146
147protected: //protected member variables
148
149  // filter shape information
150  static Int weightsShape1Sym[ALF_MAX_NUM_COEF+1];
151  static Int *weightsTabShapes[NUM_ALF_FILTER_SHAPE];
152  static Int m_sqrFiltLengthTab[NUM_ALF_FILTER_SHAPE];
153
154  // temporary buffer
155  TComPicYuv*   m_pcTempPicYuv;                          ///< temporary picture buffer for ALF processing
156  TComPicYuv* m_pcSliceYuvTmp;    //!< temporary picture buffer pointer when non-across slice boundary ALF is enabled
157
158
159  //filter coefficients buffer
160  Int **m_filterCoeffSym;
161
162  //classification
163  Int      m_varIndTab[NO_VAR_BINS];
164  Pel** m_varImg;
165
166  //parameters
167  Int   m_img_height;
168  Int   m_img_width;
169  Bool  m_bUseNonCrossALF;       //!< true for performing non-cross slice boundary ALF
170  UInt  m_uiNumSlicesInPic;      //!< number of slices in picture
171  Int   m_iSGDepth;              //!< slice granularity depth
172  UInt  m_uiNumCUsInFrame;
173
174  Int m_lcuHeight;
175  Int m_lineIdxPadBot;
176  Int m_lineIdxPadTop;
177
178  Int m_lcuHeightChroma;
179  Int m_lineIdxPadBotChroma;
180  Int m_lineIdxPadTopChroma;
181
182  //slice
183  TComPic* m_pcPic;
184  AlfLCUInfo** m_ppSliceAlfLCUs;
185  std::vector< AlfLCUInfo* > *m_pvpAlfLCU;
186  std::vector< std::vector< AlfLCUInfo* > > *m_pvpSliceTileAlfLCU;
187
188  Int m_suWidth;
189  Int m_suHeight;
190  Int m_numLCUInPicWidth;
191  Int m_numLCUInPicHeight;
192  ALFParam** m_alfFiltInfo[NUM_ALF_COMPONENT];
193  Bool m_isNonCrossSlice;
194  Int m_alfQP;
195
196private: //private member variables
197
198
199protected: //protected methods
200
201  Void createLCUAlfInfo();
202  Void destroyLCUAlfInfo();
203  Pel* getPicBuf(TComPicYuv* pPicYuv, Int compIdx);
204  Void predictALFCoeffChroma(Int* coeff, Int numCoef= ALF_MAX_NUM_COEF);
205  Void assignAlfOnOffControlFlags(TComPic* pcPic, std::vector<AlfCUCtrlInfo>& vAlfCUCtrlParam);
206  Void recALF(Int compIdx, ALFParam** alfLCUParams, Pel* pDec, Pel* pRest, Int stride, Int formatShift, std::vector<AlfCUCtrlInfo>* alfCUCtrlParam, Bool caculateBAIdx);
207  Void reconstructCoefInfo(Int compIdx, ALFParam* alfLCUParam, Int** filterCoeff, Int* varIndTab= NULL);
208  Void reconstructLumaCoefficients(ALFParam* alfLCUParam, Int** filterCoeff);
209  Void reconstructChromaCoefficients(ALFParam* alfLCUParam, Int** filterCoeff);
210  Void filterRegion(Int compIdx, ALFParam** alfLCUParams, std::vector<AlfLCUInfo*>& regionLCUInfo, Pel* pDec, Pel* pRest, Int stride, Int formatShift, Bool caculateBAIdx);
211  Void filterRegionCUControl(ALFParam** alfLCUParams, std::vector<AlfLCUInfo*>& regionLCUInfo, Pel* pDec, Pel* pRest, Int stride, Bool caculateBAIdx);
212  Bool isEnabledComponent(ALFParam** alfLCUParam);
213  Int  getAlfPrecisionBit(Int qp);
214  Void filterOneCompRegion(Pel *imgRes, Pel *imgPad, Int stride, Bool isChroma, Int yPos, Int yPosEnd, Int xPos, Int xPosEnd, Int** filterSet, Int* mergeTable, Pel** varImg); 
215  Void calcOneRegionVar(Pel **imgYvar, Pel *imgYpad, Int stride, Bool isOnlyOneGroup, Int yPos, Int yPosEnd, Int xPos, Int xPosEnd);
216
217
218  Void InitAlfLCUInfo(AlfLCUInfo& rAlfLCU, Int sliceID, Int tileID, TComDataCU* pcCU, UInt maxNumSUInLCU);
219  Void checkFilterCoeffValue( Int *filter, Int filterLength, Bool isChroma );
220  Void setAlfCtrlFlags(AlfCUCtrlInfo* pAlfParam, TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt &idx);
221  Void transferCtrlFlagsFromAlfParam(std::vector<AlfCUCtrlInfo>& vAlfParamSlices); //!< Copy ALF CU control flags from ALF parameters for slices 
222  Void transferCtrlFlagsFromAlfParamOneSlice(std::vector<AlfLCUInfo*> &vpAlfLCU, Bool bCUCtrlEnabled, Int iAlfDepth, std::vector<UInt>& vCtrlFlags); //!< Copy ALF CU control flags from ALF parameter for one slice
223  Void extendBorderCoreFunction(Pel* pPel, Int stride, Bool* pbAvail, UInt width, UInt height, UInt extSize); //!< Extend slice boundary border 
224  Void copyRegion(std::vector<AlfLCUInfo*> &vpAlfLCU, Pel* pPicDst, Pel* pPicSrc, Int stride, Int formatShift = 0);
225  Void extendRegionBorder(std::vector<AlfLCUInfo*> &vpAlfLCU, Pel* pPelSrc, Int stride, Int formatShift = 0);
226  Int  getCtrlFlagsFromAlfParam(AlfLCUInfo* pcAlfLCU, Int iAlfDepth, UInt* puiFlags);
227
228  Void xPCMRestoration        (TComPic* pcPic);
229  Void xPCMCURestoration      (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth);
230  Void xPCMSampleRestoration  (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, TextType ttText);
231
232public: //public methods, interface functions
233
234  TComAdaptiveLoopFilter();
235  virtual ~TComAdaptiveLoopFilter() {}
236
237  Void create  ( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth );
238  Void destroy ();
239
240  Void ALFProcess          (TComPic* pcPic, std::vector<AlfCUCtrlInfo>& vAlfCUCtrlParam, Bool isAlfCoefInSlice);
241  Void resetLCUAlfInfo     ();
242  Int  getNumLCUInPicWidth ()  {return m_numLCUInPicWidth;}
243  Int  getNumLCUInPicHeight() {return m_numLCUInPicHeight;}
244
245  ALFParam*** getAlfLCUParam() {return m_alfFiltInfo;}
246  Int  getNumCUsInPic()  {return m_uiNumCUsInFrame;} //!< get number of LCU in picture for ALF process
247  Void createPicAlfInfo (TComPic* pcPic, Int uiNumSlicesInPic = 1, Int alfQP = 26);
248  Void destroyPicAlfInfo();
249
250  Void PCMLFDisableProcess    ( TComPic* pcPic);                        ///< interface function for ALF process
251
252protected: //memory allocation
253  Void destroyMatrix_Pel(Pel **m2D);
254  Void destroyMatrix_int(int **m2D);
255  Void initMatrix_int(int ***m2D, int d1, int d2);
256  Void initMatrix_Pel(Pel ***m2D, int d1, int d2);
257  Void destroyMatrix4D_double(double ****m4D, int d1, int d2);
258  Void destroyMatrix3D_double(double ***m3D, int d1);
259  Void destroyMatrix_double(double **m2D);
260  Void initMatrix4D_double(double *****m4D, int d1, int d2, int d3, int d4);
261  Void initMatrix3D_double(double ****m3D, int d1, int d2, int d3);
262  Void initMatrix_double(double ***m2D, int d1, int d2);
263  Void no_mem_exit(const char *where);
264  Void xError(const char *text, int code);
265};
266
267//! \}
268
269#endif
Note: See TracBrowser for help on using the repository browser.