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 TEncAdaptiveLoopFilter.h |
---|
35 | \brief estimation part of adaptive loop filter class (header) |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef __TENCADAPTIVELOOPFILTER__ |
---|
39 | #define __TENCADAPTIVELOOPFILTER__ |
---|
40 | |
---|
41 | #include "TLibCommon/TComAdaptiveLoopFilter.h" |
---|
42 | #include "TLibCommon/TComPic.h" |
---|
43 | |
---|
44 | #include "TEncEntropy.h" |
---|
45 | #include "TEncSbac.h" |
---|
46 | #include "TLibCommon/TComBitCounter.h" |
---|
47 | |
---|
48 | //! \ingroup TLibEncoder |
---|
49 | //! \{ |
---|
50 | |
---|
51 | #if LCU_SYNTAX_ALF |
---|
52 | #define LCUALF_FILTER_BUDGET_CONTROL_ENC 1 //!< filter budget control |
---|
53 | #define LCUALF_AVOID_USING_BOTTOM_LINES_ENCODER 1 //!< avoid using LCU bottom lines when lcu-based encoder RDO is used |
---|
54 | #endif |
---|
55 | |
---|
56 | // ==================================================================================================================== |
---|
57 | // Class definition |
---|
58 | // ==================================================================================================================== |
---|
59 | |
---|
60 | #if LCU_SYNTAX_ALF |
---|
61 | /// correlation info |
---|
62 | struct AlfCorrData |
---|
63 | { |
---|
64 | Double*** ECorr; //!< auto-correlation matrix |
---|
65 | Double** yCorr; //!< cross-correlation |
---|
66 | Double* pixAcc; |
---|
67 | Int componentID; |
---|
68 | |
---|
69 | //constructor & operator |
---|
70 | AlfCorrData(); |
---|
71 | AlfCorrData(Int cIdx); |
---|
72 | ~AlfCorrData(); |
---|
73 | Void reset(); |
---|
74 | Void mergeFrom(const AlfCorrData& src, Int* mergeTable, Bool doPixAccMerge); |
---|
75 | AlfCorrData& operator += (const AlfCorrData& src); |
---|
76 | }; |
---|
77 | |
---|
78 | /// picture quad-tree info |
---|
79 | struct AlfPicQTPart |
---|
80 | { |
---|
81 | Int componentID; |
---|
82 | Int partCUXS; |
---|
83 | Int partCUYS; |
---|
84 | Int partCUXE; |
---|
85 | Int partCUYE; |
---|
86 | Int partIdx; |
---|
87 | Int partLevel; |
---|
88 | Int partCol; |
---|
89 | Int partRow; |
---|
90 | Int childPartIdx[4]; |
---|
91 | Int parentPartIdx; |
---|
92 | Bool isBottomLevel; |
---|
93 | Bool isSplit; |
---|
94 | Bool isProcessed; |
---|
95 | Double splitMinCost; |
---|
96 | Int64 splitMinDist; |
---|
97 | Int64 splitMinRate; |
---|
98 | Double selfMinCost; |
---|
99 | Int64 selfMinDist; |
---|
100 | Int64 selfMinRate; |
---|
101 | Int numFilterBudget; |
---|
102 | |
---|
103 | AlfUnitParam* alfUnitParam; |
---|
104 | AlfCorrData* alfCorr; |
---|
105 | |
---|
106 | //constructor & operator |
---|
107 | AlfPicQTPart(); |
---|
108 | ~AlfPicQTPart(); |
---|
109 | AlfPicQTPart& operator= (const AlfPicQTPart& src); |
---|
110 | }; |
---|
111 | |
---|
112 | #endif |
---|
113 | |
---|
114 | |
---|
115 | /// estimation part of adaptive loop filter class |
---|
116 | class TEncAdaptiveLoopFilter : public TComAdaptiveLoopFilter |
---|
117 | { |
---|
118 | private: |
---|
119 | /// |
---|
120 | /// variables for correlation calculation |
---|
121 | /// |
---|
122 | #if !LCU_SYNTAX_ALF |
---|
123 | Double** m_ppdAlfCorr; |
---|
124 | Double* m_pdDoubleAlfCoeff; |
---|
125 | Double** m_ppdAlfCorrCb; |
---|
126 | Double** m_ppdAlfCorrCr; |
---|
127 | double ***m_yGlobalSym; |
---|
128 | double ****m_EGlobalSym; |
---|
129 | double *m_pixAcc; |
---|
130 | #endif |
---|
131 | double **m_y_merged; |
---|
132 | double ***m_E_merged; |
---|
133 | double *m_pixAcc_merged; |
---|
134 | double *m_y_temp; |
---|
135 | double **m_E_temp; |
---|
136 | #if LCU_SYNTAX_ALF |
---|
137 | static const Int m_alfNumPartsInRowTab[5]; |
---|
138 | static const Int m_alfNumPartsLevelTab[5]; |
---|
139 | static const Int m_alfNumCulPartsLevelTab[5]; |
---|
140 | |
---|
141 | Int m_lastSliceIdx; |
---|
142 | Bool m_picBasedALFEncode; |
---|
143 | Bool m_alfCoefInSlice; |
---|
144 | Int* m_numSlicesDataInOneLCU; |
---|
145 | Int* m_coeffNoFilter[NO_VAR_BINS]; //!< used for RDO |
---|
146 | AlfParamSet* m_bestAlfParamSet; |
---|
147 | AlfCorrData** m_alfCorr[NUM_ALF_COMPONENT]; |
---|
148 | AlfCorrData* m_alfCorrMerged[NUM_ALF_COMPONENT]; //!< used for RDO |
---|
149 | AlfUnitParam* m_alfPicFiltUnits[NUM_ALF_COMPONENT]; |
---|
150 | Int m_alfPQTMaxDepth; |
---|
151 | AlfPicQTPart* m_alfPQTPart[NUM_ALF_COMPONENT]; |
---|
152 | #if LCUALF_FILTER_BUDGET_CONTROL_ENC |
---|
153 | Double m_alfFiltBudgetPerLcu; |
---|
154 | Int m_alfUsedFilterNum; |
---|
155 | #endif |
---|
156 | #endif |
---|
157 | |
---|
158 | /// |
---|
159 | /// ALF parameters |
---|
160 | /// |
---|
161 | #if !LCU_SYNTAX_ALF |
---|
162 | ALFParam* m_pcBestAlfParam; |
---|
163 | ALFParam* m_pcTempAlfParam; |
---|
164 | ALFParam* pcAlfParamShape0; |
---|
165 | ALFParam* pcAlfParamShape1; |
---|
166 | #endif |
---|
167 | ALFParam *m_tempALFp; |
---|
168 | |
---|
169 | /// |
---|
170 | /// temporary picture buffers or pointers |
---|
171 | /// |
---|
172 | TComPicYuv* m_pcPicYuvBest; |
---|
173 | TComPicYuv* m_pcPicYuvTmp; |
---|
174 | #if !LCU_SYNTAX_ALF |
---|
175 | TComPicYuv* pcPicYuvRecShape0; |
---|
176 | TComPicYuv* pcPicYuvRecShape1; |
---|
177 | #endif |
---|
178 | |
---|
179 | /// |
---|
180 | /// temporary filter buffers or pointers |
---|
181 | /// |
---|
182 | Int *m_filterCoeffQuantMod; |
---|
183 | double *m_filterCoeff; |
---|
184 | Int *m_filterCoeffQuant; |
---|
185 | Int **m_filterCoeffSymQuant; |
---|
186 | Int **m_diffFilterCoeffQuant; |
---|
187 | Int **m_FilterCoeffQuantTemp; |
---|
188 | #if !LCU_SYNTAX_ALF |
---|
189 | Int** m_mergeTableSavedMethods[NUM_ALF_CLASS_METHOD]; |
---|
190 | Int*** m_aiFilterCoeffSavedMethods[NUM_ALF_CLASS_METHOD]; //!< time-delayed filter set buffer |
---|
191 | Int* m_iPreviousFilterShapeMethods[NUM_ALF_CLASS_METHOD]; |
---|
192 | #endif |
---|
193 | /// |
---|
194 | /// coding control parameters |
---|
195 | /// |
---|
196 | Double m_dLambdaLuma; |
---|
197 | Double m_dLambdaChroma; |
---|
198 | #if !LCU_SYNTAX_ALF |
---|
199 | Int m_iUsePreviousFilter; //!< for N-pass encoding- 1: time-delayed filtering is allowed. 0: not allowed. |
---|
200 | Int m_iDesignCurrentFilter; //!< for N-pass encoding- 1: design filters for current slice. 0: design filters for future slice reference |
---|
201 | Int m_iGOPSize; //!< GOP size |
---|
202 | Int m_iCurrentPOC; //!< POC |
---|
203 | #endif |
---|
204 | Int m_iALFEncodePassReduction; //!< 0: 16-pass encoding, 1: 1-pass encoding, 2: 2-pass encoding |
---|
205 | |
---|
206 | Int m_iALFMaxNumberFilters; //!< ALF Max Number Filters per unit |
---|
207 | |
---|
208 | Int m_iALFNumOfRedesign; //!< number of redesigning filter for each CU control depth |
---|
209 | |
---|
210 | /// |
---|
211 | /// variables for on/off control |
---|
212 | /// |
---|
213 | Pel **m_maskImg; |
---|
214 | Bool m_bAlfCUCtrlEnabled; //!< if input ALF CU control param is NULL, this variable is set to be false (Disable CU control) |
---|
215 | std::vector<AlfCUCtrlInfo> m_vBestAlfCUCtrlParam; //!< ALF CU control parameters container to store the ALF CU control parameters after RDO |
---|
216 | |
---|
217 | /// |
---|
218 | /// miscs. |
---|
219 | /// |
---|
220 | TEncEntropy* m_pcEntropyCoder; |
---|
221 | private: |
---|
222 | |
---|
223 | #if LCU_SYNTAX_ALF |
---|
224 | Void disableComponentAlfParam(Int compIdx, AlfParamSet* alfParamSet, AlfUnitParam* alfUnitPic); |
---|
225 | Void copyAlfParamSet(AlfParamSet* dst, AlfParamSet* src); |
---|
226 | Void initALFEncoderParam(AlfParamSet* alfParamSet, std::vector<AlfCUCtrlInfo>* alfCtrlParam); |
---|
227 | Void assignALFEncoderParam(AlfParamSet* alfParamSet, std::vector<AlfCUCtrlInfo>* alfCtrlParam); |
---|
228 | Void getStatistics(TComPicYuv* pPicOrg, TComPicYuv* pPicDec); |
---|
229 | Void getOneCompStatistics(AlfCorrData** alfCorrComp, Int compIdx, Pel* imgOrg, Pel* imgDec, Int stride, Int formatShift, Bool isRedesignPhase); |
---|
230 | Void getStatisticsOneLCU(Bool skipLCUBottomLines, Int compIdx, AlfLCUInfo* alfLCU, AlfCorrData* alfCorr, Pel* pPicOrg, Pel* pPicSrc, Int stride, Int formatShift, Bool isRedesignPhase); |
---|
231 | #if HHI_INTERVIEW_SKIP |
---|
232 | Void decideParameters(TComPicYuv* pPicOrg, TComPicYuv* pPicDec, TComPicYuv* pPicRest, TComPicYuv* pUsedPelMap, AlfParamSet* alfParamSet, std::vector<AlfCUCtrlInfo>* alfCtrlParam) ; |
---|
233 | #else |
---|
234 | Void decideParameters(TComPicYuv* pPicOrg, TComPicYuv* pPicDec, TComPicYuv* pPicRest, AlfParamSet* alfParamSet, std::vector<AlfCUCtrlInfo>* alfCtrlParam); |
---|
235 | #endif |
---|
236 | Void deriveFilterInfo(Int compIdx, AlfCorrData* alfCorr, ALFParam* alfFiltParam, Int maxNumFilters); |
---|
237 | #if HHI_INTERVIEW_SKIP |
---|
238 | Void decideBlockControl(Pel* pOrg, Pel* pDec, Pel* pRest, Pel* pUsed, Int stride, AlfPicQTPart* alfPicQTPart, AlfParamSet* & alfParamSet, Int64 &minRate, Int64 &minDist, Double &minCost); |
---|
239 | #else |
---|
240 | Void decideBlockControl(Pel* pOrg, Pel* pDec, Pel* pRest, Int stride, AlfPicQTPart* alfPicQTPart, AlfParamSet* & alfParamSet, Int64 &minRate, Int64 &minDist, Double &minCost); |
---|
241 | #endif |
---|
242 | Void copyPicQT(AlfPicQTPart* alfPicQTPartDest, AlfPicQTPart* alfPicQTPartSrc); |
---|
243 | Void copyPixelsInOneRegion(Pel* imgDest, Pel* imgSrc, Int stride, Int yPos, Int height, Int xPos, Int width); |
---|
244 | Void reDesignQT(AlfPicQTPart *alfPicQTPart, Int partIdx, Int partLevel); |
---|
245 | #if HHI_INTERVIEW_SKIP |
---|
246 | Void setCUAlfCtrlFlags(UInt uiAlfCtrlDepth, Pel* imgOrg, Pel* imgDec, Pel* imgRest, Pel* imgUsed, Int stride, UInt64& ruiDist, std::vector<AlfCUCtrlInfo>& vAlfCUCtrlParam); |
---|
247 | Void setCUAlfCtrlFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiAlfCtrlDepth, Pel* imgOrg, Pel* imgDec, Pel* imgRest, Pel* imgUsed, Int stride, UInt64& ruiDist, std::vector<UInt>& vCUCtrlFlag) ; |
---|
248 | #else |
---|
249 | Void setCUAlfCtrlFlags(UInt uiAlfCtrlDepth, Pel* imgOrg, Pel* imgDec, Pel* imgRest, Int stride, UInt64& ruiDist, std::vector<AlfCUCtrlInfo>& vAlfCUCtrlParam); |
---|
250 | Void setCUAlfCtrlFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiAlfCtrlDepth, Pel* imgOrg, Pel* imgDec, Pel* imgRest, Int stride, UInt64& ruiDist, std::vector<UInt>& vCUCtrlFlag); |
---|
251 | #endif |
---|
252 | Void xCopyDecToRestCUs( Pel* imgDec, Pel* imgRest, Int stride ); |
---|
253 | Void xCopyDecToRestCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Pel* imgDec, Pel* imgRest, Int stride ); |
---|
254 | #if ALF_SINGLE_FILTER_SHAPE |
---|
255 | Void calcCorrOneCompRegionChma(Pel* imgOrg, Pel* imgPad, Int stride, Int yPos, Int xPos, Int height, Int width, Double **eCorr, Double *yCorr, Bool isSymmCopyBlockMatrix); //!< Calculate correlations for chroma |
---|
256 | Void calcCorrOneCompRegionLuma(Pel* imgOrg, Pel* imgPad, Int stride, Int yPos, Int xPos, Int height, Int width, Double ***eCorr, Double **yCorr, Double *pixAcc, Bool isforceCollection, Bool isSymmCopyBlockMatrix); |
---|
257 | #endif |
---|
258 | |
---|
259 | //LCU-based mode decision |
---|
260 | #if HHI_INTERVIEW_SKIP |
---|
261 | Void executeLCUBasedModeDecision(AlfParamSet* alfParamSet, Int compIdx, Pel* pOrg, Pel* pDec, Pel* pRest, Pel* pUsed, Int stride, Int formatShift, AlfCorrData** alfCorrLCUs); |
---|
262 | #else |
---|
263 | Void executeLCUBasedModeDecision(AlfParamSet* alfParamSet, Int compIdx, Pel* pOrg, Pel* pDec, Pel* pRest, Int stride, Int formatShift, AlfCorrData** alfCorrLCUs); |
---|
264 | #endif |
---|
265 | Void decideLCUALFUnitParam(Int compIdx, AlfUnitParam* alfUnitPic, Int lcuIdx, Int lcuPos, Int numLCUWidth, AlfUnitParam* alfUnitParams, AlfCorrData* alfCorr, std::vector<ALFParam*>& storedFilters, Int maxNumFilter, Double lambda, Bool isLeftUnitAvailable, Bool isUpUnitAvailable); |
---|
266 | Void getFiltOffAlfUnitParam(AlfUnitParam* alfFiltOffParam, Int lcuPos, AlfUnitParam* alfUnitPic, Bool isLeftUnitAvailable, Bool isUpUnitAvailable); |
---|
267 | Int64 estimateFilterDistortion(Int compIdx, AlfCorrData* alfCorr, Int** coeff = NULL, Int filterSetSize = 1, Int* mergeTable = NULL, Bool doPixAccMerge = false); |
---|
268 | Int calculateAlfUnitRateRDO(AlfUnitParam* alfUnitParam, Int numStoredFilters = 0); |
---|
269 | #if HHI_INTERVIEW_SKIP |
---|
270 | Int64 calcAlfLCUDist(Bool skipLCUBottomLines, Int compIdx, AlfLCUInfo& alfLCUInfo, Pel* picSrc, Pel* picCmp, Pel* picUsed, Int stride, Int formatShift) ; |
---|
271 | #else |
---|
272 | Int64 calcAlfLCUDist(Bool skipLCUBottomLines, Int compIdx, AlfLCUInfo& alfLCUInfo, Pel* picSrc, Pel* picCmp, Int stride, Int formatShift); |
---|
273 | #endif |
---|
274 | Void reconstructOneAlfLCU(Int compIdx, AlfLCUInfo& alfLCUInfo, AlfUnitParam* alfUnitParam, Pel* picDec, Pel* picRest, Int stride, Int formatShift); |
---|
275 | Void copyOneAlfLCU(AlfLCUInfo& alfLCUInfo, Pel* picDst, Pel* picSrc, Int stride, Int formatShift); |
---|
276 | |
---|
277 | //picture-based mode decision |
---|
278 | #if HHI_INTERVIEW_SKIP |
---|
279 | Void executePicBasedModeDecision(AlfParamSet* alfParamSet, AlfPicQTPart* alfPicQTPart, Int compIdx, Pel* pOrg, Pel* pDec, Pel* pRest, Pel* pUsed, Int stride, Int formatShift, AlfCorrData** alfCorrLCUs); |
---|
280 | #else |
---|
281 | Void executePicBasedModeDecision(AlfParamSet* alfParamSet, AlfPicQTPart* alfPicQTPart, Int compIdx, Pel* pOrg, Pel* pDec, Pel* pRest, Int stride, Int formatShift, AlfCorrData** alfCorrLCUs); |
---|
282 | #endif |
---|
283 | Void creatPQTPart (Int partLevel, Int partRow, Int partCol, Int parentPartIdx, Int partCUXS, Int partCUXE, Int partCUYS, Int partCUYE); |
---|
284 | Void resetPQTPart (); |
---|
285 | Int convertLevelRowCol2Idx (Int level, Int row, Int col); |
---|
286 | Void convertIdx2LevelRowCol (Int idx, Int *level, Int *row, Int *col); |
---|
287 | Void executeModeDecisionOnePart (AlfPicQTPart *alfPicQTPart, AlfCorrData** alfPicLCUCorr, Int partIdx, Int partLevel); |
---|
288 | Void decideQTPartition (AlfPicQTPart* alfPicQTPart, AlfCorrData** alfPicLCUCorr, Int partIdx, Int partLevel, Double &cost, Int64 &dist, Int64 &rate); |
---|
289 | Void patchAlfUnitParams(AlfPicQTPart* alfPicQTPart, Int partIdx, AlfUnitParam* alfUnitPic); |
---|
290 | Void checkMerge(Int compIdx, AlfUnitParam* alfUnitPic); |
---|
291 | Void transferToAlfParamSet(Int compIdx, AlfUnitParam* alfUnitPic, AlfParamSet* & alfParamSet); |
---|
292 | Int calculateAlfParamSetRateRDO(Int compIdx, AlfParamSet* alfParamSet, std::vector<AlfCUCtrlInfo>* alfCUCtrlParam); |
---|
293 | #endif |
---|
294 | #if !LCU_SYNTAX_ALF |
---|
295 | // init / uninit internal variables |
---|
296 | Void xInitParam (); |
---|
297 | Void xUninitParam (); |
---|
298 | #endif |
---|
299 | // ALF on/off control related functions |
---|
300 | Void xCreateTmpAlfCtrlFlags (); |
---|
301 | Void xDestroyTmpAlfCtrlFlags (); |
---|
302 | Void xCopyTmpAlfCtrlFlagsTo (); |
---|
303 | Void xCopyTmpAlfCtrlFlagsFrom (); |
---|
304 | Void getCtrlFlagsFromCU(AlfLCUInfo* pcAlfLCU, std::vector<UInt> *pvFlags, Int iAlfDepth, UInt uiMaxNumSUInLCU); |
---|
305 | Void xEncodeCUAlfCtrlFlags (std::vector<AlfCUCtrlInfo> &vAlfCUCtrlParam); |
---|
306 | Void xEncodeCUAlfCtrlFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth); |
---|
307 | #if !LCU_SYNTAX_ALF |
---|
308 | Void xCUAdaptiveControl_qc ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiMinRate, UInt64& ruiMinDist, Double& rdMinCost ); |
---|
309 | Void xSetCUAlfCtrlFlags_qc (UInt uiAlfCtrlDepth, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiDist, std::vector<AlfCUCtrlInfo>& vAlfCUCtrlParam); |
---|
310 | Void xSetCUAlfCtrlFlag_qc (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiAlfCtrlDepth, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiDist, std::vector<UInt>& vCUCtrlFlag); |
---|
311 | |
---|
312 | // functions related to correlation computation |
---|
313 | Void xstoreInBlockMatrix(Int ypos, Int xpos, Int iheight, Int iwidth, Bool bResetBlockMatrix, Bool bSymmCopyBlockMatrix, Pel* pImgOrg, Pel* pImgPad, Int filtNo, Int stride); //!< Calculate correlations for luma |
---|
314 | Void xstoreInBlockMatrixforRegion(std::vector< AlfLCUInfo* > &vpAlfLCU, Pel* ImgOrg, Pel* ImgDec, Int tap, Int iStride, Bool bFirstSlice, Bool bLastSlice); //!< Calculate block autocorrelations and crosscorrelations for one ALF slice |
---|
315 | Void xstoreInBlockMatrixforSlices (Pel* ImgOrg, Pel* ImgDec, Int tap, Int iStride); //!< Calculate block autocorrelations and crosscorrelations for ALF slices |
---|
316 | Void xCalcCorrelationFunc(Int ypos, Int xpos, Pel* pImgOrg, Pel* pImgPad, Int filtNo, Int iWidth, Int iHeight, Int iOrgStride, Int iCmpStride, Bool bSymmCopyBlockMatrix); //!< Calculate correlations for chroma |
---|
317 | Void xCalcCorrelationFuncforChromaRegion(std::vector< AlfLCUInfo* > &vpAlfLCU, Pel* pOrg, Pel* pCmp, Int filtNo, Int iStride, Bool bLastSlice, Int iFormatShift); //!< Calculate autocorrelations and crosscorrelations for one chroma slice |
---|
318 | Void xCalcCorrelationFuncforChromaSlices (Int ComponentID, Pel* pOrg, Pel* pCmp, Int iTap, Int iOrgStride, Int iCmpStride); //!< Calculate autocorrelations and crosscorrelations for chroma slices |
---|
319 | #endif |
---|
320 | // functions related to filtering |
---|
321 | Void xFilterCoefQuickSort ( Double *coef_data, Int *coef_num, Int upper, Int lower ); |
---|
322 | Void xQuantFilterCoef ( Double* h, Int* qh, Int tap, int bit_depth ); |
---|
323 | #if !LCU_SYNTAX_ALF |
---|
324 | Void xClearFilterCoefInt ( Int* qh, Int N ); |
---|
325 | Void xCopyDecToRestCUs ( TComPicYuv* pcPicDec, TComPicYuv* pcPicRest ); |
---|
326 | Void xCopyDecToRestCU ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest ); |
---|
327 | Void xFilteringFrameChroma (ALFParam* pcAlfParam, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest); |
---|
328 | Int setFilterIdx(Int index); //!< set filter buffer index |
---|
329 | Void setInitialMask(TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec); //!< set initial m_maskImg |
---|
330 | Void saveFilterCoeffToBuffer(Int **filterSet, Int numFilter, Int* mergeTable, Int mode, Int filtNo); //!< save filter coefficients to buffer |
---|
331 | Void setMaskWithTimeDelayedResults(TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec); //!< set initial m_maskImg with previous (time-delayed) filters |
---|
332 | Void decideFilterShapeLuma(Pel* ImgOrg, Pel* ImgDec, Int Stride, ALFParam* pcAlfSaved, UInt64& ruiRate, UInt64& ruiDist,Double& rdCost); //!< Estimate RD cost of all filter size & store the best one |
---|
333 | Void xFilterTapDecisionChroma (UInt64 uiLumaRate, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiDist, UInt64& ruiBits); |
---|
334 | Int64 xFastFiltDistEstimationChroma (Double** ppdCorr, Int* piCoeff, Int iSqrFiltLength); |
---|
335 | Void xfilterSlicesEncoder(Pel* ImgDec, Pel* ImgRest, Int iStride, Int filtNo, Int** filterCoeff, Int* mergeTable, Pel** varImg); //!< Calculate ALF grouping indices for ALF slices |
---|
336 | Void setALFEncodingParam(TComPic *pcPic); //!< set ALF encoding parameters |
---|
337 | Void xReDesignFilterCoeff_qc (TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, Bool bReadCorr); |
---|
338 | Void xFirstFilteringFrameLuma (Pel* imgOrg, Pel* imgDec, Pel* imgRest, ALFParam* ALFp, Int filtNo, Int stride); |
---|
339 | Void xFilteringFrameLuma(Pel* imgOrg, Pel* imgPad, Pel* imgFilt, ALFParam* ALFp, Int filtNo, Int stride); |
---|
340 | Void xEncALFLuma ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiMinRate, UInt64& ruiMinDist, Double& rdMinCost ); //!< estimate adaptation mode and filter shape |
---|
341 | #endif |
---|
342 | // distortion / misc functions |
---|
343 | #if HHI_INTERVIEW_SKIP |
---|
344 | UInt64 xCalcSSD ( Pel* pOrg, Pel* pCmp, Pel* pUsed, Int iWidth, Int iHeight, Int iStride ); |
---|
345 | #else |
---|
346 | UInt64 xCalcSSD ( Pel* pOrg, Pel* pCmp, Int iWidth, Int iHeight, Int iStride ); |
---|
347 | #endif |
---|
348 | #if !LCU_SYNTAX_ALF |
---|
349 | #if HHI_INTERVIEW_SKIP |
---|
350 | Void xCalcRDCost ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicCmp, ALFParam* pAlfParam, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost, std::vector<AlfCUCtrlInfo>* pvAlfCUCtrlParam = NULL); |
---|
351 | Void xCalcRDCost ( ALFParam* pAlfParam, UInt64& ruiRate, UInt64 uiDist, Double& rdCost, std::vector<AlfCUCtrlInfo>* pvAlfCUCtrlParam = NULL); |
---|
352 | Void xCalcRDCostChroma ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicCmp, ALFParam* pAlfParam, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost ); |
---|
353 | #else |
---|
354 | Void xCalcRDCost ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicCmp, ALFParam* pAlfParam, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost, std::vector<AlfCUCtrlInfo>* pvAlfCUCtrlParam = NULL); |
---|
355 | Void xCalcRDCost ( ALFParam* pAlfParam, UInt64& ruiRate, UInt64 uiDist, Double& rdCost, std::vector<AlfCUCtrlInfo>* pvAlfCUCtrlParam = NULL); |
---|
356 | Void xCalcRDCostChroma ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicCmp, ALFParam* pAlfParam, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost ); |
---|
357 | #endif |
---|
358 | #endif |
---|
359 | Int64 xFastFiltDistEstimation(Double** ppdE, Double* pdy, Int* piCoeff, Int iFiltLength); //!< Estimate filtering distortion by correlation values and filter coefficients |
---|
360 | #if !LCU_SYNTAX_ALF |
---|
361 | Int64 xEstimateFiltDist (Int filters_per_fr, Int* VarIndTab, Double*** pppdE, Double** ppdy, Int** ppiCoeffSet, Int iFiltLength); //!< Estimate total filtering cost of all groups |
---|
362 | UInt64 xCalcRateChroma (ALFParam* pAlfParam); |
---|
363 | Void xCalcALFCoeffChroma (Int iChromaIdc, Int iShape, Int* piCoeff); |
---|
364 | #endif |
---|
365 | |
---|
366 | /// code filter coefficients |
---|
367 | UInt xcodeFiltCoeff(Int **filterCoeffSymQuant, Int filter_shape, Int varIndTab[], Int filters_per_fr_best, ALFParam* ALFp); |
---|
368 | #if LCU_SYNTAX_ALF |
---|
369 | Void xfindBestFilterVarPred(double **ySym, double ***ESym, double *pixAcc, Int **filterCoeffSym, Int **filterCoeffSymQuant,Int filter_shape, Int *filters_per_fr_best, Int varIndTab[], Pel **imgY_rec, Pel **varImg, Pel **maskImg, Pel **imgY_pad, double lambda_val, Int numMaxFilters = NO_FILTERS); |
---|
370 | #else |
---|
371 | Void xfindBestFilterVarPred(double **ySym, double ***ESym, double *pixAcc, Int **filterCoeffSym, Int **filterCoeffSymQuant,Int filter_shape, Int *filters_per_fr_best, Int varIndTab[], Pel **imgY_rec, Pel **varImg, Pel **maskImg, Pel **imgY_pad, double lambda_val); |
---|
372 | #endif |
---|
373 | double xfindBestCoeffCodMethod(int **filterCoeffSymQuant, int filter_shape, int sqrFiltLength, int filters_per_fr, double errorForce0CoeffTab[NO_VAR_BINS][2], double lambda); |
---|
374 | Int xsendAllFiltersPPPred(int **FilterCoeffQuant, int filter_shape, int sqrFiltLength, int filters_per_group, int createBistream, ALFParam* ALFp); |
---|
375 | Int xcodeAuxInfo(int filters_per_fr, int varIndTab[NO_VAR_BINS], int filter_shape, ALFParam* ALFp); |
---|
376 | Int xcodeFilterCoeff(int **pDiffQFilterCoeffIntPP, int filter_shape, int sqrFiltLength, int filters_per_group, int createBitstream); |
---|
377 | Int lengthGolomb(int coeffVal, int k); |
---|
378 | Int lengthPredFlags(int force0, int predMethod, int codedVarBins[NO_VAR_BINS], int filters_per_group, int createBitstream); |
---|
379 | Int lengthFilterCoeffs(int sqrFiltLength, int filters_per_group, int pDepthInt[], int **FilterCoeff, int kMinTab[], int createBitstream); |
---|
380 | Void predictALFCoeffLumaEnc(ALFParam* pcAlfParam, Int **pfilterCoeffSym, Int filter_shape); //!< prediction of luma ALF coefficients |
---|
381 | //cholesky related |
---|
382 | Int xGauss( Double **a, Int N ); |
---|
383 | Double findFilterCoeff(double ***EGlobalSeq, double **yGlobalSeq, double *pixAccGlobalSeq, int **filterCoeffSeq,int **filterCoeffQuantSeq, int intervalBest[NO_VAR_BINS][2], int varIndTab[NO_VAR_BINS], int sqrFiltLength, int filters_per_fr, int *weights, double errorTabForce0Coeff[NO_VAR_BINS][2]); |
---|
384 | Double QuantizeIntegerFilterPP(Double *filterCoeff, Int *filterCoeffQuant, Double **E, Double *y, Int sqrFiltLength, Int *weights); |
---|
385 | Void roundFiltCoeff(int *FilterCoeffQuan, double *FilterCoeff, int sqrFiltLength, int factor); |
---|
386 | double mergeFiltersGreedy(double **yGlobalSeq, double ***EGlobalSeq, double *pixAccGlobalSeq, int intervalBest[NO_VAR_BINS][2], int sqrFiltLength, int noIntervals); |
---|
387 | double calculateErrorAbs(double **A, double *b, double y, int size); |
---|
388 | double calculateErrorCoeffProvided(double **A, double *b, double *c, int size); |
---|
389 | Void add_b(double *bmerged, double **b, int start, int stop, int size); |
---|
390 | Void add_A(double **Amerged, double ***A, int start, int stop, int size); |
---|
391 | Int gnsSolveByChol(double **LHS, double *rhs, double *x, int noEq); |
---|
392 | Void gnsBacksubstitution(double R[ALF_MAX_NUM_COEF][ALF_MAX_NUM_COEF], double z[ALF_MAX_NUM_COEF], int R_size, double A[ALF_MAX_NUM_COEF]); |
---|
393 | Void gnsTransposeBacksubstitution(double U[ALF_MAX_NUM_COEF][ALF_MAX_NUM_COEF], double rhs[], double x[],int order); |
---|
394 | Int gnsCholeskyDec(double **inpMatr, double outMatr[ALF_MAX_NUM_COEF][ALF_MAX_NUM_COEF], int noEq); |
---|
395 | |
---|
396 | public: |
---|
397 | TEncAdaptiveLoopFilter (); |
---|
398 | virtual ~TEncAdaptiveLoopFilter () {} |
---|
399 | |
---|
400 | Void startALFEnc(TComPic* pcPic, TEncEntropy* pcEntropyCoder); //!< allocate temporal memory |
---|
401 | Void endALFEnc(); //!< destroy temporal memory |
---|
402 | #if LCU_SYNTAX_ALF |
---|
403 | #if ALF_CHROMA_LAMBDA |
---|
404 | #if HHI_INTERVIEW_SKIP |
---|
405 | Void ALFProcess( AlfParamSet* alfParamSet, std::vector<AlfCUCtrlInfo>* alfCtrlParam, Double lambdaLuma, Double lambdaChroma, Bool bInterviewSkip); |
---|
406 | #else |
---|
407 | Void ALFProcess( AlfParamSet* alfParamSet, std::vector<AlfCUCtrlInfo>* alfCtrlParam, Double lambdaLuma, Double lambdaChroma); |
---|
408 | #endif |
---|
409 | #else |
---|
410 | #if HHI_INTERVIEW_SKIP |
---|
411 | Void ALFProcess( AlfParamSet* alfParamSet, std::vector<AlfCUCtrlInfo>* alfCtrlParam, Double lambda, Bool bInterviewSkip); |
---|
412 | #else |
---|
413 | Void ALFProcess( AlfParamSet* alfParamSet, std::vector<AlfCUCtrlInfo>* alfCtrlParam, Double lambda); |
---|
414 | #endif |
---|
415 | #endif |
---|
416 | Void initALFEnc(Bool isAlfParamInSlice, Bool isPicBasedEncode, Int numSlices, AlfParamSet* & alfParams, std::vector<AlfCUCtrlInfo>* & alfCUCtrlParam); |
---|
417 | Void uninitALFEnc(AlfParamSet* & alfParams, std::vector<AlfCUCtrlInfo>* & alfCUCtrlParam); |
---|
418 | Void resetPicAlfUnit(); |
---|
419 | Void setAlfCoefInSlice(Bool b) {m_alfCoefInSlice = b;} |
---|
420 | #else |
---|
421 | #if ALF_CHROMA_LAMBDA |
---|
422 | #if HHI_INTERVIEW_SKIP |
---|
423 | Void ALFProcess(ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>* pvAlfCtrlParam, Double dLambdaLuma, Double dLambdaChroma, UInt64& ruiDist, UInt64& ruiBits, Bool bInterviewSkip); //!< estimate ALF parameters |
---|
424 | #else |
---|
425 | Void ALFProcess(ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>* pvAlfCtrlParam, Double dLambdaLuma, Double dLambdaChroma, UInt64& ruiDist, UInt64& ruiBits); //!< estimate ALF parameters |
---|
426 | #endif |
---|
427 | #else |
---|
428 | #if HHI_INTERVIEW_SKIP |
---|
429 | Void ALFProcess(ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>* pvAlfCtrlParam, Double dLambda, UInt64& ruiDist, UInt64& ruiBits, Bool bInterviewSkip); //!< estimate ALF parameters |
---|
430 | #else |
---|
431 | Void ALFProcess(ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>* pvAlfCtrlParam, Double dLambda, UInt64& ruiDist, UInt64& ruiBits); //!< estimate ALF parameters |
---|
432 | #endif |
---|
433 | #endif |
---|
434 | |
---|
435 | Void setGOPSize(Int val) { m_iGOPSize = val; } //!< set GOP size |
---|
436 | #endif |
---|
437 | Void setALFEncodePassReduction (Int iVal) {m_iALFEncodePassReduction = iVal;} //!< set N-pass encoding. 0: 16(14)-pass encoding, 1: 1-pass encoding, 2: 2-pass encoding |
---|
438 | |
---|
439 | Void setALFMaxNumberFilters (Int iVal) {m_iALFMaxNumberFilters = iVal;} //!< set ALF Max Number of Filters |
---|
440 | |
---|
441 | #if LCU_SYNTAX_ALF |
---|
442 | Void createAlfGlobalBuffers(); //!< create ALF global buffers |
---|
443 | Void initPicQuadTreePartition(Bool isPicBasedEncode); |
---|
444 | #else |
---|
445 | Void createAlfGlobalBuffers(Int iALFEncodePassReduction); //!< create ALF global buffers |
---|
446 | #endif |
---|
447 | Void destroyAlfGlobalBuffers(); //!< destroy ALF global buffers |
---|
448 | Void PCMLFDisableProcess (TComPic* pcPic); |
---|
449 | }; |
---|
450 | |
---|
451 | //! \} |
---|
452 | |
---|
453 | #endif |
---|