Changeset 296 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComAdaptiveLoopFilter.cpp
- Timestamp:
- 20 Feb 2013, 22:07:43 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibCommon/TComAdaptiveLoopFilter.cpp
r56 r296 46 46 47 47 48 #if !LCU_SYNTAX_ALF49 ALFParam::~ALFParam()50 {51 if (coeff_chroma != NULL)52 {53 delete[] coeff_chroma;54 }55 if (coeffmulti)56 {57 for (Int i=0; i<NO_VAR_BINS; i++)58 {59 if (coeffmulti[i] != NULL)60 {61 delete[] coeffmulti[i];62 }63 }64 delete[] coeffmulti;65 }66 67 if (nbSPred != NULL)68 {69 delete[] nbSPred;70 }71 if (filterPattern != NULL)72 {73 delete[] filterPattern;74 }75 }76 #endif77 48 78 49 // ==================================================================================================================== … … 80 51 // ==================================================================================================================== 81 52 82 #if ALF_SINGLE_FILTER_SHAPE83 53 Int TComAdaptiveLoopFilter::weightsShape1Sym[ALF_MAX_NUM_COEF+1] = 84 54 { … … 109 79 depthIntShape1Sym 110 80 }; 111 #else 112 //Shape0: Star5x5 113 Int TComAdaptiveLoopFilter::weightsShape0Sym[10] = 114 { 115 2, 2, 2, 116 2, 2, 2, 117 2, 2, 1, 1 118 }; 119 120 121 //Shape1: Cross9x9 122 Int TComAdaptiveLoopFilter::weightsShape1Sym[10] = 123 { 124 2, 125 2, 126 2, 127 2, 128 2, 2, 2, 2, 1, 129 1 130 }; 131 132 133 Int* TComAdaptiveLoopFilter::weightsTabShapes[NUM_ALF_FILTER_SHAPE] = 134 { 135 weightsShape0Sym, weightsShape1Sym 136 }; 137 138 Int TComAdaptiveLoopFilter::m_sqrFiltLengthTab[NUM_ALF_FILTER_SHAPE] = 139 { 140 9, 9 141 }; 142 143 // Shape0 144 Int depthIntShape0Sym[10] = 145 { 146 1, 3, 1, 147 3, 4, 3, 148 3, 4, 5, 5 149 }; 150 // Shape1 151 Int depthIntShape1Sym[10] = 152 { 153 5, 154 6, 155 7, 156 8, 157 5, 6, 7, 8, 9, 158 9 159 }; 160 161 162 Int* pDepthIntTabShapes[NUM_ALF_FILTER_SHAPE] = 163 { 164 depthIntShape0Sym, depthIntShape1Sym 165 }; 166 #endif 167 168 #if LCU_SYNTAX_ALF 81 169 82 Int kTableShape1[ALF_MAX_NUM_COEF+1] = 170 83 { … … 179 92 kTableShape1 180 93 }; 181 #endif182 94 183 95 // ==================================================================================================================== … … 194 106 } 195 107 196 #if LCU_SYNTAX_ALF197 108 /// AlfCUCtrlInfo 198 109 Void AlfCUCtrlInfo::reset() … … 530 441 } 531 442 532 #endif533 443 534 444 … … 543 453 m_pvpAlfLCU = NULL; 544 454 m_pvpSliceTileAlfLCU = NULL; 545 #if LCU_SYNTAX_ALF546 455 for(Int c=0; c< NUM_ALF_COMPONENT; c++) 547 456 { … … 550 459 m_varImg = NULL; 551 460 m_filterCoeffSym = NULL; 552 #endif553 461 554 462 } … … 755 663 Void TComAdaptiveLoopFilter::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth ) 756 664 { 757 #if LCU_SYNTAX_ALF758 665 destroy(); 759 #endif760 666 if ( !m_pcTempPicYuv ) 761 667 { … … 765 671 m_img_height = iPicHeight; 766 672 m_img_width = iPicWidth; 767 #if LCU_SYNTAX_ALF768 673 initMatrix_Pel(&(m_varImg), m_img_height, m_img_width); 769 #else770 for(Int i=0; i< NUM_ALF_CLASS_METHOD; i++)771 {772 initMatrix_Pel(&(m_varImgMethods[i]), m_img_height, m_img_width);773 }774 #endif775 674 initMatrix_int(&m_filterCoeffSym, NO_VAR_BINS, ALF_MAX_NUM_COEF); 776 675 UInt uiNumLCUsInWidth = m_img_width / uiMaxCUWidth; … … 782 681 m_uiNumCUsInFrame = uiNumLCUsInWidth* uiNumLCUsInHeight; 783 682 784 #if LCU_SYNTAX_ALF785 683 m_numLCUInPicWidth = uiNumLCUsInWidth; 786 684 m_numLCUInPicHeight= uiNumLCUsInHeight; 787 685 m_lcuHeight = uiMaxCUHeight; 788 #if ALF_SINGLE_FILTER_SHAPE789 686 m_lineIdxPadBot = m_lcuHeight - 4 - 3; // DFRegion, Vertical Taps 790 #else791 m_lineIdxPadBot = m_lcuHeight - 4 - 4; // DFRegion, Vertical Taps792 #endif793 687 m_lineIdxPadTop = m_lcuHeight - 4; // DFRegion 794 688 795 689 m_lcuHeightChroma = m_lcuHeight>>1; 796 #if ALF_SINGLE_FILTER_SHAPE797 690 m_lineIdxPadBotChroma = m_lcuHeightChroma - 2 - 3; // DFRegion, Vertical Taps 798 #else799 m_lineIdxPadBotChroma = m_lcuHeightChroma - 2 - 4; // DFRegion, Vertical Taps800 #endif801 691 m_lineIdxPadTopChroma = m_lcuHeightChroma - 2 ; // DFRegion 802 692 803 693 createLCUAlfInfo(); 804 #else805 createRegionIndexMap(m_varImgMethods[ALF_RA], m_img_width, m_img_height);806 #endif807 694 } 808 695 … … 813 700 m_pcTempPicYuv->destroy(); 814 701 delete m_pcTempPicYuv; 815 #if LCU_SYNTAX_ALF816 702 m_pcTempPicYuv = NULL; 817 #endif 818 } 819 #if LCU_SYNTAX_ALF 703 } 820 704 if(m_varImg != NULL) 821 705 { … … 828 712 m_filterCoeffSym = NULL; 829 713 } 830 #else831 for(Int i=0; i< NUM_ALF_CLASS_METHOD; i++)832 {833 destroyMatrix_Pel(m_varImgMethods[i]);834 }835 destroyMatrix_int(m_filterCoeffSym);836 #endif837 #if LCU_SYNTAX_ALF838 714 destroyLCUAlfInfo(); 839 #endif 840 841 } 842 843 #if !LCU_SYNTAX_ALF 844 // -------------------------------------------------------------------------------------------------------------------- 845 // allocate / free / copy functions 846 // -------------------------------------------------------------------------------------------------------------------- 847 Void TComAdaptiveLoopFilter::allocALFParam(ALFParam* pAlfParam) 848 { 849 pAlfParam->alf_flag = 0; 850 pAlfParam->coeff_chroma = new Int[ALF_MAX_NUM_COEF]; 851 ::memset(pAlfParam->coeff_chroma, 0, sizeof(Int)*ALF_MAX_NUM_COEF ); 852 pAlfParam->coeffmulti = new Int*[NO_VAR_BINS]; 853 for (int i=0; i<NO_VAR_BINS; i++) 854 { 855 pAlfParam->coeffmulti[i] = new Int[ALF_MAX_NUM_COEF]; 856 ::memset(pAlfParam->coeffmulti[i], 0, sizeof(Int)*ALF_MAX_NUM_COEF ); 857 } 858 pAlfParam->nbSPred = new Int[NO_VAR_BINS]; 859 ::memset(pAlfParam->nbSPred, 0, sizeof(Int)*NO_VAR_BINS); 860 pAlfParam->filterPattern = new Int[NO_VAR_BINS]; 861 ::memset(pAlfParam->filterPattern, 0, sizeof(Int)*NO_VAR_BINS); 862 pAlfParam->alf_pcr_region_flag = 0; 863 } 864 865 Void TComAdaptiveLoopFilter::freeALFParam(ALFParam* pAlfParam) 866 { 867 assert(pAlfParam != NULL); 868 if (pAlfParam->coeff_chroma != NULL) 869 { 870 delete[] pAlfParam->coeff_chroma; 871 pAlfParam->coeff_chroma = NULL; 872 } 873 for (int i=0; i<NO_VAR_BINS; i++) 874 { 875 delete[] pAlfParam->coeffmulti[i]; 876 pAlfParam->coeffmulti[i] = NULL; 877 } 878 delete[] pAlfParam->coeffmulti; 879 pAlfParam->coeffmulti = NULL; 880 881 delete[] pAlfParam->nbSPred; 882 pAlfParam->nbSPred = NULL; 883 884 delete[] pAlfParam->filterPattern; 885 pAlfParam->filterPattern = NULL; 886 } 887 888 889 Void TComAdaptiveLoopFilter::copyALFParam(ALFParam* pDesAlfParam, ALFParam* pSrcAlfParam) 890 { 891 pDesAlfParam->alf_flag = pSrcAlfParam->alf_flag; 892 pDesAlfParam->chroma_idc = pSrcAlfParam->chroma_idc; 893 pDesAlfParam->num_coeff = pSrcAlfParam->num_coeff; 894 pDesAlfParam->filter_shape_chroma = pSrcAlfParam->filter_shape_chroma; 895 pDesAlfParam->num_coeff_chroma = pSrcAlfParam->num_coeff_chroma; 896 pDesAlfParam->alf_pcr_region_flag = pSrcAlfParam->alf_pcr_region_flag; 897 ::memcpy(pDesAlfParam->coeff_chroma, pSrcAlfParam->coeff_chroma, sizeof(Int)*ALF_MAX_NUM_COEF); 898 pDesAlfParam->filter_shape = pSrcAlfParam->filter_shape; 899 ::memcpy(pDesAlfParam->filterPattern, pSrcAlfParam->filterPattern, sizeof(Int)*NO_VAR_BINS); 900 pDesAlfParam->startSecondFilter = pSrcAlfParam->startSecondFilter; 901 902 //Coeff send related 903 pDesAlfParam->filters_per_group = pSrcAlfParam->filters_per_group; //this can be updated using codedVarBins 904 pDesAlfParam->predMethod = pSrcAlfParam->predMethod; 905 ::memcpy(pDesAlfParam->nbSPred, pSrcAlfParam->nbSPred, sizeof(Int)*NO_VAR_BINS); 906 for (int i=0; i<NO_VAR_BINS; i++) 907 { 908 ::memcpy(pDesAlfParam->coeffmulti[i], pSrcAlfParam->coeffmulti[i], sizeof(Int)*ALF_MAX_NUM_COEF); 909 } 910 } 911 // -------------------------------------------------------------------------------------------------------------------- 912 // prediction of filter coefficients 913 // -------------------------------------------------------------------------------------------------------------------- 914 915 Void TComAdaptiveLoopFilter::predictALFCoeffChroma( ALFParam* pAlfParam ) 916 { 917 Int i, sum, pred, N; 918 const Int* pFiltMag = NULL; 919 pFiltMag = weightsTabShapes[pAlfParam->filter_shape_chroma]; 920 N = pAlfParam->num_coeff_chroma; 921 sum=0; 922 for(i=0; i<N;i++) 923 { 924 sum+=pFiltMag[i]*pAlfParam->coeff_chroma[i]; 925 } 926 pred=(1<<ALF_NUM_BIT_SHIFT)-(sum-pAlfParam->coeff_chroma[N-1]); 927 #if ALF_CHROMA_COEF_PRED_HARMONIZATION 928 pAlfParam->coeff_chroma[N-1]=pAlfParam->coeff_chroma[N-1] - pred; 929 #else 930 pAlfParam->coeff_chroma[N-1]=pred-pAlfParam->coeff_chroma[N-1]; 931 #endif 932 } 933 934 #if ALF_CHROMA_COEF_PRED_HARMONIZATION 935 Void TComAdaptiveLoopFilter::reconstructALFCoeffChroma( ALFParam* pAlfParam ) 936 { 937 Int i, sum, pred, N; 938 const Int* pFiltMag = NULL; 939 pFiltMag = weightsTabShapes[pAlfParam->filter_shape_chroma]; 940 N = pAlfParam->num_coeff_chroma; 941 sum=0; 942 for(i=0; i<N;i++) 943 { 944 sum+=pFiltMag[i]*pAlfParam->coeff_chroma[i]; 945 } 946 pred=(1<<ALF_NUM_BIT_SHIFT)-(sum-pAlfParam->coeff_chroma[N-1]); 947 pAlfParam->coeff_chroma[N-1]=pred+ pAlfParam->coeff_chroma[N-1]; 948 } 949 #endif 950 #endif 715 716 } 717 951 718 952 719 // -------------------------------------------------------------------------------------------------------------------- … … 954 721 // -------------------------------------------------------------------------------------------------------------------- 955 722 956 #if LCU_SYNTAX_ALF957 723 /** ALF reconstruction process for one picture 958 724 * \param [in, out] pcPic the decoded/filtered picture (input: decoded picture; output filtered picture) … … 1113 879 } 1114 880 1115 #else1116 1117 /**1118 \param [in, out] pcPic picture (TComPic) class (input/output)1119 \param [in] pcAlfParam ALF parameter1120 \param [in,out] vAlfCUCtrlParam ALF CU control parameters1121 \todo for temporal buffer, it uses residual picture buffer, which may not be safe. Make it be safer.1122 */1123 Void TComAdaptiveLoopFilter::ALFProcess(TComPic* pcPic, ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>& vAlfCUCtrlParam)1124 {1125 assert(m_uiNumSlicesInPic == vAlfCUCtrlParam.size());1126 if(!pcAlfParam->alf_flag)1127 {1128 return;1129 }1130 1131 m_lcuHeight = pcPic->getSlice(0)->getSPS()->getMaxCUHeight();1132 #if ALF_SINGLE_FILTER_SHAPE1133 m_lineIdxPadBot = m_lcuHeight - 4 - 3; // DFRegion, Vertical Taps1134 #else1135 m_lineIdxPadBot = m_lcuHeight - 4 - 4; // DFRegion, Vertical Taps1136 #endif1137 m_lineIdxPadTop = m_lcuHeight - 4; // DFRegion1138 1139 m_lcuHeightChroma = m_lcuHeight>>1;1140 #if ALF_SINGLE_FILTER_SHAPE1141 m_lineIdxPadBotChroma = m_lcuHeightChroma - 2 - 3; // DFRegion, Vertical Taps1142 #else1143 m_lineIdxPadBotChroma = m_lcuHeightChroma - 2 - 4; // DFRegion, Vertical Taps1144 #endif1145 m_lineIdxPadTopChroma = m_lcuHeightChroma - 2 ; // DFRegion1146 1147 TComPicYuv* pcPicYuvRec = pcPic->getPicYuvRec();1148 TComPicYuv* pcPicYuvExtRec = m_pcTempPicYuv;1149 pcPicYuvRec ->copyToPic ( pcPicYuvExtRec );1150 pcPicYuvExtRec->setBorderExtension ( false );1151 pcPicYuvExtRec->extendPicBorder ();1152 1153 if(m_uiNumSlicesInPic == 1)1154 {1155 AlfCUCtrlInfo* pcAlfCtrlParam = &(vAlfCUCtrlParam[0]);1156 if(pcAlfCtrlParam->cu_control_flag)1157 {1158 UInt idx = 0;1159 for(UInt uiCUAddr = 0; uiCUAddr < pcPic->getNumCUsInFrame(); uiCUAddr++)1160 {1161 TComDataCU *pcCU = pcPic->getCU(uiCUAddr);1162 setAlfCtrlFlags(pcAlfCtrlParam, pcCU, 0, 0, idx);1163 }1164 }1165 }1166 else1167 {1168 transferCtrlFlagsFromAlfParam(vAlfCUCtrlParam);1169 }1170 xALFLuma(pcPic, pcAlfParam, vAlfCUCtrlParam, pcPicYuvExtRec, pcPicYuvRec);1171 if(pcAlfParam->chroma_idc)1172 {1173 #if ALF_CHROMA_COEF_PRED_HARMONIZATION1174 reconstructALFCoeffChroma(pcAlfParam);1175 #else1176 predictALFCoeffChroma(pcAlfParam);1177 #endif1178 checkFilterCoeffValue(pcAlfParam->coeff_chroma, pcAlfParam->num_coeff_chroma, true );1179 1180 xALFChroma( pcAlfParam, pcPicYuvExtRec, pcPicYuvRec);1181 }1182 }1183 #endif1184 881 // ==================================================================================================================== 1185 882 // Protected member functions … … 1216 913 } 1217 914 1218 #if !LCU_SYNTAX_ALF1219 1220 Void TComAdaptiveLoopFilter::xALFLuma(TComPic* pcPic, ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>& vAlfCUCtrlParam,TComPicYuv* pcPicDec, TComPicYuv* pcPicRest)1221 {1222 Int LumaStride = pcPicDec->getStride();1223 Pel* pDec = pcPicDec->getLumaAddr();1224 Pel* pRest = pcPicRest->getLumaAddr();1225 1226 decodeFilterSet(pcAlfParam, m_varIndTab, m_filterCoeffSym);1227 1228 m_uiVarGenMethod = pcAlfParam->alf_pcr_region_flag;1229 m_varImg = m_varImgMethods[m_uiVarGenMethod];1230 calcVar(m_varImg, pRest, LumaStride, pcAlfParam->alf_pcr_region_flag);1231 1232 if(!m_bUseNonCrossALF)1233 {1234 Bool bCUCtrlEnabled = false;1235 for(UInt s=0; s< m_uiNumSlicesInPic; s++)1236 {1237 if(!pcPic->getValidSlice(s))1238 {1239 continue;1240 }1241 if( vAlfCUCtrlParam[s].cu_control_flag == 1)1242 {1243 bCUCtrlEnabled = true;1244 }1245 }1246 1247 if(bCUCtrlEnabled)1248 {1249 xCUAdaptive(pcPic, pcAlfParam->filter_shape, pRest, pDec, LumaStride);1250 }1251 else1252 {1253 filterLuma(pRest, pDec, LumaStride, 0, m_img_height-1, 0, m_img_width-1, pcAlfParam->filter_shape, m_filterCoeffSym, m_varIndTab, m_varImg);1254 }1255 }1256 else1257 {1258 Pel* pTemp = m_pcSliceYuvTmp->getLumaAddr();1259 for(UInt s=0; s< m_uiNumSlicesInPic; s++)1260 {1261 if(!pcPic->getValidSlice(s))1262 {1263 continue;1264 }1265 std::vector< std::vector<AlfLCUInfo*> > & vpSliceTileAlfLCU = m_pvpSliceTileAlfLCU[s];1266 1267 for(Int t=0; t< (Int)vpSliceTileAlfLCU.size(); t++)1268 {1269 std::vector<AlfLCUInfo*> & vpAlfLCU = vpSliceTileAlfLCU[t];1270 1271 copyRegion(vpAlfLCU, pTemp, pDec, LumaStride);1272 extendRegionBorder(vpAlfLCU, pTemp, LumaStride);1273 if(vAlfCUCtrlParam[s].cu_control_flag == 1)1274 {1275 xCUAdaptiveRegion(vpAlfLCU, pTemp, pRest, LumaStride, pcAlfParam->filter_shape, m_filterCoeffSym, m_varIndTab, m_varImg);1276 }1277 else1278 {1279 filterLumaRegion(vpAlfLCU, pTemp, pRest, LumaStride, pcAlfParam->filter_shape, m_filterCoeffSym, m_varIndTab, m_varImg);1280 }1281 }1282 }1283 }1284 }1285 1286 Void TComAdaptiveLoopFilter::decodeFilterSet(ALFParam* pcAlfParam, Int* varIndTab, Int** filterCoeff)1287 {1288 // reconstruct merge table1289 memset(m_varIndTab, 0, NO_VAR_BINS * sizeof(Int));1290 if(pcAlfParam->filters_per_group > 1)1291 {1292 for(Int i = 1; i < NO_VAR_BINS; ++i)1293 {1294 if(pcAlfParam->filterPattern[i])1295 {1296 varIndTab[i] = varIndTab[i-1] + 1;1297 }1298 else1299 {1300 varIndTab[i] = varIndTab[i-1];1301 }1302 }1303 }1304 predictALFCoeffLuma( pcAlfParam);1305 // reconstruct filter sets1306 reconstructFilterCoeffs( pcAlfParam, filterCoeff);1307 1308 }1309 1310 1311 Void TComAdaptiveLoopFilter::filterLuma(Pel *pImgRes, Pel *pImgPad, Int stride,1312 Int ypos, Int yposEnd, Int xpos, Int xposEnd,1313 Int filtNo, Int** filterSet, Int* mergeTable, Pel** ppVarImg)1314 {1315 static Int numBitsMinus1= (Int)ALF_NUM_BIT_SHIFT;1316 static Int offset = (1<<( (Int)ALF_NUM_BIT_SHIFT-1));1317 static Int shiftHeight = (Int)(log((double)VAR_SIZE_H)/log(2.0));1318 static Int shiftWidth = (Int)(log((double)VAR_SIZE_W)/log(2.0));1319 1320 Pel *pImgPad1,*pImgPad2,*pImgPad3,*pImgPad4;1321 Pel *pVar;1322 Int i, j, pixelInt;1323 Int *coef = NULL;1324 1325 pImgPad += (ypos*stride);1326 pImgRes += (ypos*stride);1327 1328 Int yLineInLCU;1329 Int paddingLine;1330 #if !ALF_SINGLE_FILTER_SHAPE1331 Int varInd = 0;1332 #endif1333 Int newCenterCoeff[4][NO_VAR_BINS];1334 1335 for(i=0; i< 4; i++)1336 {1337 ::memset(&(newCenterCoeff[i][0]), 0, sizeof(Int)*NO_VAR_BINS);1338 }1339 1340 #if ALF_SINGLE_FILTER_SHAPE1341 if(filtNo == ALF_CROSS9x7_SQUARE3x3)1342 #else1343 if(filtNo == ALF_CROSS9x9)1344 #endif1345 {1346 for (i=0; i<NO_VAR_BINS; i++)1347 {1348 coef = filterSet[i];1349 //VB line 11350 newCenterCoeff[0][i] = coef[8] + ((coef[0] + coef[1] + coef[2] + coef[3])<<1);1351 //VB line 21352 newCenterCoeff[1][i] = coef[8] + ((coef[0] + coef[1] + coef[2])<<1);1353 //VB line 31354 newCenterCoeff[2][i] = coef[8] + ((coef[0] + coef[1])<<1);1355 //VB line 41356 newCenterCoeff[3][i] = coef[8] + ((coef[0])<<1);1357 }1358 }1359 1360 1361 switch(filtNo)1362 {1363 #if !ALF_SINGLE_FILTER_SHAPE1364 case ALF_STAR5x5:1365 {1366 for(i= ypos; i<= yposEnd; i++)1367 {1368 1369 yLineInLCU = i % m_lcuHeight;1370 1371 if (yLineInLCU<m_lineIdxPadBot || i-yLineInLCU+m_lcuHeight >= m_img_height)1372 {1373 pImgPad1 = pImgPad + stride;1374 pImgPad2 = pImgPad - stride;1375 pImgPad3 = pImgPad + 2*stride;1376 pImgPad4 = pImgPad - 2*stride;1377 }1378 else if (yLineInLCU<m_lineIdxPadTop)1379 {1380 paddingLine = - yLineInLCU + m_lineIdxPadTop - 1;1381 pImgPad1 = pImgPad + min(paddingLine, 1)*stride;1382 pImgPad2 = pImgPad - stride;1383 pImgPad3 = pImgPad + min(paddingLine, 2)*stride;1384 pImgPad4 = pImgPad - 2*stride;1385 }1386 else1387 {1388 paddingLine = yLineInLCU - m_lineIdxPadTop ;1389 pImgPad1 = pImgPad + stride;1390 pImgPad2 = pImgPad - min(paddingLine, 1)*stride;1391 pImgPad3 = pImgPad + 2*stride;1392 pImgPad4 = pImgPad - min(paddingLine, 2)*stride;1393 }1394 1395 pVar = ppVarImg[i>>shiftHeight] + (xpos>>shiftWidth);1396 1397 if ( (yLineInLCU == m_lineIdxPadTop || yLineInLCU == m_lineIdxPadTop-1) && i-yLineInLCU+m_lcuHeight < m_img_height )1398 {1399 for(j= xpos; j<= xposEnd; j++)1400 {1401 pImgRes[j] = pImgPad[j];1402 }1403 }1404 else if ( (yLineInLCU == m_lineIdxPadTop+1 || yLineInLCU == m_lineIdxPadTop-2) && i-yLineInLCU+m_lcuHeight < m_img_height )1405 {1406 for(j= xpos; j<= xposEnd ; j++)1407 {1408 if (j % VAR_SIZE_W==0)1409 {1410 coef = filterSet[mergeTable[*(pVar++)]];1411 }1412 1413 pixelInt = 0;1414 1415 pixelInt += coef[0]* (pImgPad3[j+2]+pImgPad4[j-2]);1416 pixelInt += coef[1]* (pImgPad3[j ]+pImgPad4[j ]);1417 pixelInt += coef[2]* (pImgPad3[j-2]+pImgPad4[j+2]);1418 1419 pixelInt += coef[3]* (pImgPad1[j+1]+pImgPad2[j-1]);1420 pixelInt += coef[4]* (pImgPad1[j ]+pImgPad2[j ]);1421 pixelInt += coef[5]* (pImgPad1[j-1]+pImgPad2[j+1]);1422 1423 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);1424 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);1425 pixelInt += coef[8]* (pImgPad[j ]);1426 1427 pixelInt=(int)((pixelInt+offset) >> numBitsMinus1);1428 pImgRes[j] = ( Clip( pixelInt ) + pImgPad[j] ) >> 1;1429 }1430 }1431 else1432 {1433 1434 for(j= xpos; j<= xposEnd ; j++)1435 {1436 if (j % VAR_SIZE_W==0)1437 {1438 coef = filterSet[mergeTable[*(pVar++)]];1439 }1440 1441 pixelInt = 0;1442 1443 pixelInt += coef[0]* (pImgPad3[j+2]+pImgPad4[j-2]);1444 pixelInt += coef[1]* (pImgPad3[j ]+pImgPad4[j ]);1445 pixelInt += coef[2]* (pImgPad3[j-2]+pImgPad4[j+2]);1446 1447 pixelInt += coef[3]* (pImgPad1[j+1]+pImgPad2[j-1]);1448 pixelInt += coef[4]* (pImgPad1[j ]+pImgPad2[j ]);1449 pixelInt += coef[5]* (pImgPad1[j-1]+pImgPad2[j+1]);1450 1451 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);1452 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);1453 pixelInt += coef[8]* (pImgPad[j ]);1454 1455 pixelInt=(Int)((pixelInt+offset) >> numBitsMinus1);1456 pImgRes[j] = Clip( pixelInt );1457 }1458 1459 }1460 1461 pImgPad += stride;1462 pImgRes += stride;1463 }1464 }1465 break;1466 case ALF_CROSS9x9:1467 {1468 Pel *pImgPad5, *pImgPad6, *pImgPad7, *pImgPad8;1469 #else1470 case ALF_CROSS9x7_SQUARE3x3:1471 {1472 Pel *pImgPad5, *pImgPad6;1473 #endif1474 for(i= ypos; i<= yposEnd; i++)1475 {1476 yLineInLCU = i % m_lcuHeight;1477 1478 if (yLineInLCU<m_lineIdxPadBot || i-yLineInLCU+m_lcuHeight >= m_img_height)1479 {1480 pImgPad1 = pImgPad + stride;1481 pImgPad2 = pImgPad - stride;1482 pImgPad3 = pImgPad + 2*stride;1483 pImgPad4 = pImgPad - 2*stride;1484 pImgPad5 = pImgPad + 3*stride;1485 pImgPad6 = pImgPad - 3*stride;1486 #if !ALF_SINGLE_FILTER_SHAPE1487 pImgPad7 = pImgPad + 4*stride;1488 pImgPad8 = pImgPad - 4*stride;1489 #endif1490 }1491 else if (yLineInLCU<m_lineIdxPadTop)1492 {1493 paddingLine = - yLineInLCU + m_lineIdxPadTop - 1;1494 #if ALF_SINGLE_FILTER_SHAPE1495 pImgPad1 = (paddingLine < 1) ? pImgPad : pImgPad + min(paddingLine, 1)*stride;1496 pImgPad2 = (paddingLine < 1) ? pImgPad : pImgPad - stride;1497 pImgPad3 = (paddingLine < 2) ? pImgPad : pImgPad + min(paddingLine, 2)*stride;1498 pImgPad4 = (paddingLine < 2) ? pImgPad : pImgPad - 2*stride;1499 pImgPad5 = (paddingLine < 3) ? pImgPad : pImgPad + min(paddingLine, 3)*stride;1500 pImgPad6 = (paddingLine < 3) ? pImgPad : pImgPad - 3*stride;1501 #else1502 pImgPad1 = pImgPad + min(paddingLine, 1)*stride;1503 pImgPad2 = pImgPad - stride;1504 pImgPad3 = pImgPad + min(paddingLine, 2)*stride;1505 pImgPad4 = pImgPad - 2*stride;1506 pImgPad5 = pImgPad + min(paddingLine, 3)*stride;1507 pImgPad6 = pImgPad - 3*stride;1508 pImgPad7 = pImgPad + min(paddingLine, 4)*stride;1509 pImgPad8 = pImgPad - 4*stride;1510 #endif1511 }1512 else1513 {1514 paddingLine = yLineInLCU - m_lineIdxPadTop ;1515 #if ALF_SINGLE_FILTER_SHAPE1516 pImgPad1 = (paddingLine < 1) ? pImgPad : pImgPad + stride;1517 pImgPad2 = (paddingLine < 1) ? pImgPad : pImgPad - min(paddingLine, 1)*stride;1518 pImgPad3 = (paddingLine < 2) ? pImgPad : pImgPad + 2*stride;1519 pImgPad4 = (paddingLine < 2) ? pImgPad : pImgPad - min(paddingLine, 2)*stride;1520 pImgPad5 = (paddingLine < 3) ? pImgPad : pImgPad + 3*stride;1521 pImgPad6 = (paddingLine < 3) ? pImgPad : pImgPad - min(paddingLine, 3)*stride;1522 #else1523 pImgPad1 = pImgPad + stride;1524 pImgPad2 = pImgPad - min(paddingLine, 1)*stride;1525 pImgPad3 = pImgPad + 2*stride;1526 pImgPad4 = pImgPad - min(paddingLine, 2)*stride;1527 pImgPad5 = pImgPad + 3*stride;1528 pImgPad6 = pImgPad - min(paddingLine, 3)*stride;1529 pImgPad7 = pImgPad + 4*stride;1530 pImgPad8 = pImgPad - min(paddingLine, 4)*stride;1531 #endif1532 }1533 1534 pVar = ppVarImg[i>>shiftHeight] + (xpos>>shiftWidth);1535 1536 #if ALF_SINGLE_FILTER_SHAPE1537 {1538 for(j= xpos; j<= xposEnd ; j++)1539 {1540 if (j % VAR_SIZE_W==0)1541 {1542 coef = filterSet[mergeTable[*(pVar++)]];1543 }1544 1545 pixelInt = 0;1546 1547 pixelInt += coef[0]* (pImgPad5[j]+pImgPad6[j]);1548 pixelInt += coef[1]* (pImgPad3[j]+pImgPad4[j]);1549 pixelInt += coef[2]* (pImgPad1[j-1]+pImgPad2[j+1]);1550 pixelInt += coef[3]* (pImgPad1[j]+pImgPad2[j]);1551 pixelInt += coef[4]* (pImgPad1[j+1]+pImgPad2[j-1]);1552 pixelInt += coef[5]* (pImgPad[j+4]+pImgPad[j-4]);1553 pixelInt += coef[6]* (pImgPad[j+3]+pImgPad[j-3]);1554 pixelInt += coef[7]* (pImgPad[j+2]+pImgPad[j-2]);1555 pixelInt += coef[8]* (pImgPad[j+1]+pImgPad[j-1]);1556 pixelInt += coef[9]* (pImgPad[j ]);1557 1558 pixelInt=(Int)((pixelInt+offset) >> numBitsMinus1);1559 pImgRes[j] = Clip( pixelInt );1560 }1561 }1562 #else1563 if ( (yLineInLCU == m_lineIdxPadTop || yLineInLCU == m_lineIdxPadTop-1) && i-yLineInLCU+m_lcuHeight < m_img_height )1564 {1565 for(j= xpos; j<= xposEnd ; j++)1566 {1567 if (j % VAR_SIZE_W==0)1568 {1569 varInd = *(pVar++);1570 coef = filterSet[mergeTable[varInd]];1571 }1572 1573 pixelInt = 0;1574 1575 pixelInt += coef[4]* (pImgPad[j+4]+pImgPad[j-4]);1576 pixelInt += coef[5]* (pImgPad[j+3]+pImgPad[j-3]);1577 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);1578 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);1579 pixelInt += newCenterCoeff[0][mergeTable[varInd]]* (pImgPad[j]);1580 1581 pixelInt=(int)((pixelInt+offset) >> numBitsMinus1);1582 pImgRes[j] = Clip( pixelInt );1583 }1584 }1585 else if ( (yLineInLCU == m_lineIdxPadTop+1 || yLineInLCU == m_lineIdxPadTop-2) && i-yLineInLCU+m_lcuHeight < m_img_height )1586 {1587 for(j= xpos; j<= xposEnd ; j++)1588 {1589 if (j % VAR_SIZE_W==0)1590 {1591 varInd = *(pVar++);1592 coef = filterSet[mergeTable[varInd]];1593 }1594 1595 pixelInt = 0;1596 1597 pixelInt += coef[3]* (pImgPad1[j]+pImgPad2[j]);1598 1599 pixelInt += coef[4]* (pImgPad[j+4]+pImgPad[j-4]);1600 pixelInt += coef[5]* (pImgPad[j+3]+pImgPad[j-3]);1601 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);1602 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);1603 pixelInt += newCenterCoeff[1][mergeTable[varInd]]* (pImgPad[j]);1604 1605 pixelInt=(int)((pixelInt+offset) >> numBitsMinus1);1606 pImgRes[j] = Clip( pixelInt );1607 }1608 }1609 else if ( (yLineInLCU == m_lineIdxPadTop+2 || yLineInLCU == m_lineIdxPadTop-3) && i-yLineInLCU+m_lcuHeight < m_img_height )1610 {1611 for(j= xpos; j<= xposEnd ; j++)1612 {1613 if (j % VAR_SIZE_W==0)1614 {1615 varInd = *(pVar++);1616 coef = filterSet[mergeTable[varInd]];1617 }1618 1619 pixelInt = 0;1620 1621 pixelInt += coef[2]* (pImgPad3[j]+pImgPad4[j]);1622 1623 pixelInt += coef[3]* (pImgPad1[j]+pImgPad2[j]);1624 1625 pixelInt += coef[4]* (pImgPad[j+4]+pImgPad[j-4]);1626 pixelInt += coef[5]* (pImgPad[j+3]+pImgPad[j-3]);1627 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);1628 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);1629 pixelInt += newCenterCoeff[2][mergeTable[varInd]]* (pImgPad[j ]);1630 1631 pixelInt=(int)((pixelInt+offset) >> numBitsMinus1);1632 pImgRes[j] = Clip( pixelInt );1633 }1634 }1635 else if ( (yLineInLCU == m_lineIdxPadTop+3 || yLineInLCU == m_lineIdxPadTop-4) && i-yLineInLCU+m_lcuHeight < m_img_height )1636 {1637 for(j= xpos; j<= xposEnd ; j++)1638 {1639 if (j % VAR_SIZE_W==0)1640 {1641 varInd = *(pVar++);1642 coef = filterSet[mergeTable[varInd]];1643 }1644 1645 pixelInt = 0;1646 1647 pixelInt += coef[1]* (pImgPad5[j]+pImgPad6[j]);1648 1649 pixelInt += coef[2]* (pImgPad3[j]+pImgPad4[j]);1650 1651 pixelInt += coef[3]* (pImgPad1[j]+pImgPad2[j]);1652 1653 pixelInt += coef[4]* (pImgPad[j+4]+pImgPad[j-4]);1654 pixelInt += coef[5]* (pImgPad[j+3]+pImgPad[j-3]);1655 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);1656 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);1657 pixelInt += newCenterCoeff[3][mergeTable[varInd]]* (pImgPad[j ]);1658 1659 pixelInt=(int)((pixelInt+offset) >> numBitsMinus1);1660 pImgRes[j] = Clip( pixelInt );1661 }1662 }1663 else1664 {1665 for(j= xpos; j<= xposEnd ; j++)1666 {1667 if (j % VAR_SIZE_W==0)1668 {1669 coef = filterSet[mergeTable[*(pVar++)]];1670 }1671 1672 pixelInt = 0;1673 1674 pixelInt += coef[0]* (pImgPad7[j]+pImgPad8[j]);1675 1676 pixelInt += coef[1]* (pImgPad5[j]+pImgPad6[j]);1677 1678 pixelInt += coef[2]* (pImgPad3[j]+pImgPad4[j]);1679 1680 pixelInt += coef[3]* (pImgPad1[j]+pImgPad2[j]);1681 1682 pixelInt += coef[4]* (pImgPad[j+4]+pImgPad[j-4]);1683 pixelInt += coef[5]* (pImgPad[j+3]+pImgPad[j-3]);1684 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);1685 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);1686 pixelInt += coef[8]* (pImgPad[j ]);1687 1688 pixelInt=(Int)((pixelInt+offset) >> numBitsMinus1);1689 pImgRes[j] = Clip( pixelInt );1690 }1691 }1692 #endif1693 pImgPad += stride;1694 pImgRes += stride;1695 }1696 }1697 break;1698 default:1699 {1700 printf("Not a supported filter shape\n");1701 assert(0);1702 exit(1);1703 }1704 }1705 }1706 1707 1708 1709 Void TComAdaptiveLoopFilter::xCUAdaptive(TComPic* pcPic, Int filtNo, Pel *imgYFilt, Pel *imgYRec, Int Stride)1710 {1711 // for every CU, call CU-adaptive ALF process1712 for( UInt uiCUAddr = 0; uiCUAddr < pcPic->getNumCUsInFrame() ; uiCUAddr++ )1713 {1714 TComDataCU* pcCU = pcPic->getCU( uiCUAddr );1715 xSubCUAdaptive(pcCU, filtNo, imgYFilt, imgYRec, 0, 0, Stride);1716 }1717 }1718 1719 Void TComAdaptiveLoopFilter::xSubCUAdaptive(TComDataCU* pcCU, Int filtNo, Pel *imgYFilt, Pel *imgYRec, UInt uiAbsPartIdx, UInt uiDepth, Int Stride)1720 {1721 TComPic* pcPic = pcCU->getPic();1722 1723 if(pcPic==NULL)1724 {1725 return;1726 }1727 Bool bBoundary = false;1728 UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];1729 UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1;1730 UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];1731 UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;1732 1733 // check picture boundary1734 if ( ( uiRPelX >= m_img_width ) || ( uiBPelY >= m_img_height ) )1735 {1736 bBoundary = true;1737 }1738 1739 if ( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary )1740 {1741 UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2;1742 for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts )1743 {1744 uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];1745 uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];1746 1747 if( ( uiLPelX < m_img_width ) && ( uiTPelY < m_img_height ) )1748 xSubCUAdaptive(pcCU, filtNo, imgYFilt, imgYRec, uiAbsPartIdx, uiDepth+1, Stride);1749 }1750 return;1751 }1752 1753 if ( pcCU->getAlfCtrlFlag(uiAbsPartIdx) )1754 {1755 filterLuma(imgYFilt, imgYRec, Stride, uiTPelY, min(uiBPelY,(unsigned int)(m_img_height-1)), uiLPelX, min(uiRPelX,(unsigned int)(m_img_width-1))1756 ,filtNo, m_filterCoeffSym, m_varIndTab, m_varImg);1757 }1758 }1759 1760 /** Predict ALF luma filter coefficients. Centre coefficient is always predicted. Left neighbour is predicted according to flag.1761 */1762 Void TComAdaptiveLoopFilter::predictALFCoeffLuma(ALFParam* pcAlfParam)1763 {1764 Int sum, coeffPred, ind;1765 const Int* pFiltMag = NULL;1766 pFiltMag = weightsTabShapes[pcAlfParam->filter_shape];1767 for(ind = 0; ind < pcAlfParam->filters_per_group; ++ind)1768 {1769 sum = 0;1770 for(Int i = 0; i < pcAlfParam->num_coeff-2; i++)1771 {1772 sum += pFiltMag[i]*pcAlfParam->coeffmulti[ind][i];1773 }1774 if(pcAlfParam->nbSPred[ind]==0)1775 {1776 if((pcAlfParam->predMethod==0)|(ind==0))1777 {1778 coeffPred = ((1<<ALF_NUM_BIT_SHIFT)-sum) >> 2;1779 }1780 else1781 {1782 coeffPred = (0-sum) >> 2;1783 }1784 pcAlfParam->coeffmulti[ind][pcAlfParam->num_coeff-2] = coeffPred + pcAlfParam->coeffmulti[ind][pcAlfParam->num_coeff-2];1785 }1786 sum += pFiltMag[pcAlfParam->num_coeff-2]*pcAlfParam->coeffmulti[ind][pcAlfParam->num_coeff-2];1787 if((pcAlfParam->predMethod==0)|(ind==0))1788 {1789 coeffPred = (1<<ALF_NUM_BIT_SHIFT)-sum;1790 }1791 else1792 {1793 coeffPred = -sum;1794 }1795 pcAlfParam->coeffmulti[ind][pcAlfParam->num_coeff-1] = coeffPred + pcAlfParam->coeffmulti[ind][pcAlfParam->num_coeff-1];1796 }1797 }1798 1799 Void TComAdaptiveLoopFilter::reconstructFilterCoeffs(ALFParam* pcAlfParam,int **pfilterCoeffSym)1800 {1801 int i, ind;1802 1803 // Copy non zero filters in filterCoeffTmp1804 for(ind = 0; ind < pcAlfParam->filters_per_group; ++ind)1805 {1806 for(i = 0; i < pcAlfParam->num_coeff; i++)1807 {1808 pfilterCoeffSym[ind][i] = pcAlfParam->coeffmulti[ind][i];1809 }1810 }1811 // Undo prediction1812 for(ind = 1; ind < pcAlfParam->filters_per_group; ++ind)1813 {1814 if(pcAlfParam->predMethod)1815 {1816 // Prediction1817 for(i = 0; i < pcAlfParam->num_coeff; ++i)1818 {1819 pfilterCoeffSym[ind][i] = (int)(pfilterCoeffSym[ind][i] + pfilterCoeffSym[ind - 1][i]);1820 }1821 }1822 }1823 1824 for(ind = 0; ind < pcAlfParam->filters_per_group; ind++)1825 {1826 checkFilterCoeffValue(pfilterCoeffSym[ind], pcAlfParam->num_coeff, false );1827 }1828 }1829 1830 1831 #endif1832 915 1833 916 static Pel Clip_post(int high, int val) … … 1836 919 } 1837 920 1838 #if !LCU_SYNTAX_ALF1839 1840 /** Calculate ALF grouping indices for block-based (BA) mode1841 * \param [out] imgYvar grouping indices buffer1842 * \param [in] imgYpad picture buffer1843 * \param [in] stride picture stride size1844 * \param [in] adaptationMode ALF_BA or ALF_RA mode1845 */1846 Void TComAdaptiveLoopFilter::calcVar(Pel **imgYvar, Pel *imgYpad, Int stride, Int adaptationMode)1847 {1848 if(adaptationMode == ALF_RA)1849 {1850 return;1851 }1852 static Int shiftH = (Int)(log((double)VAR_SIZE_H)/log(2.0));1853 static Int shiftW = (Int)(log((double)VAR_SIZE_W)/log(2.0));1854 static Int varmax = (Int)NO_VAR_BINS-1;1855 #if ALF_16_BA_GROUPS1856 static Int th[NO_VAR_BINS] = {0, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5};1857 static Int avgVarTab[3][6] = { {0, 1, 2, 3, 4, 5,},1858 {0, 6, 7, 8, 9, 10,},1859 {0, 11, 12, 13, 14, 15} };1860 #else1861 static Int step1 = (Int)((Int)(NO_VAR_BINS)/3) - 1;1862 static Int th[NO_VAR_BINS] = {0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4};1863 #endif1864 Int i, j, avgvar, vertical, horizontal,direction, yoffset;1865 Pel *pimgYpad, *pimgYpadup, *pimgYpaddown;1866 1867 for(i = 0; i < m_img_height - 3; i=i+4)1868 {1869 yoffset = ((i)*stride) + stride;1870 pimgYpad = &imgYpad [yoffset];1871 pimgYpadup = &imgYpad [yoffset + stride];1872 pimgYpaddown = &imgYpad [yoffset - stride];1873 1874 for(j = 0; j < m_img_width - 3 ; j=j+4)1875 {1876 // Compute at sub-sample by 21877 vertical = abs((pimgYpad[j+1]<<1 ) - pimgYpaddown[j+1] - pimgYpadup[j+1]);1878 horizontal = abs((pimgYpad[j+1]<<1 ) - pimgYpad [j+2] - pimgYpad [j ]);1879 1880 vertical += abs((pimgYpad[j+2]<<1 ) - pimgYpaddown[j+2] - pimgYpadup[j+2]);1881 horizontal += abs((pimgYpad[j+2]<<1 ) - pimgYpad [j+3] - pimgYpad [j+1]);1882 1883 vertical += abs((pimgYpad[j+1+stride]<<1) - pimgYpaddown[j+1+stride] - pimgYpadup[j+1+stride]);1884 horizontal += abs((pimgYpad[j+1+stride]<<1) - pimgYpad [j+2+stride] - pimgYpad [j+stride ]);1885 1886 vertical += abs((pimgYpad[j+2+stride]<<1) - pimgYpaddown[j+2+stride] - pimgYpadup[j+2+stride]);1887 horizontal += abs((pimgYpad[j+2+stride]<<1) - pimgYpad [j+3+stride] - pimgYpad [j+1+stride]);1888 1889 direction = 0;1890 if (vertical > 2*horizontal)1891 {1892 direction = 1; //vertical1893 }1894 if (horizontal > 2*vertical)1895 {1896 direction = 2; //horizontal1897 }1898 1899 avgvar = (vertical + horizontal) >> 2;1900 avgvar = (Pel) Clip_post(varmax, avgvar >>(g_uiBitIncrement+1));1901 avgvar = th[avgvar];1902 #if ALF_16_BA_GROUPS1903 avgvar = avgVarTab[direction][avgvar];1904 #else1905 avgvar = Clip_post(step1, (Int) avgvar ) + (step1+1)*direction;1906 #endif1907 imgYvar[(i )>>shiftH][(j)>>shiftW] = avgvar;1908 }1909 }1910 }1911 1912 Void TComAdaptiveLoopFilter::createRegionIndexMap(Pel **imgYVar, Int imgWidth, Int imgHeight)1913 {1914 int varStepSizeWidth = VAR_SIZE_W;1915 int varStepSizeHeight = VAR_SIZE_H;1916 int shiftHeight = (int)(log((double)varStepSizeHeight)/log(2.0));1917 int shiftWidth = (int)(log((double)varStepSizeWidth)/log(2.0));1918 1919 int i, j;1920 int regionTable[NO_VAR_BINS] = {0, 1, 4, 5, 15, 2, 3, 6, 14, 11, 10, 7, 13, 12, 9, 8};1921 int xInterval;1922 int yInterval;1923 int yIndex;1924 int yIndexOffset;1925 int yStartLine;1926 int yEndLine;1927 1928 xInterval = ((( (imgWidth+63)/64) + 1) / 4 * 64)>>shiftWidth;1929 yInterval = ((((imgHeight+63)/64) + 1) / 4 * 64)>>shiftHeight;1930 1931 for (yIndex = 0; yIndex < 4 ; yIndex++)1932 {1933 yIndexOffset = yIndex * 4;1934 yStartLine = yIndex * yInterval;1935 yEndLine = (yIndex == 3) ? imgHeight>>shiftHeight : (yStartLine+yInterval);1936 1937 for(i = yStartLine; i < yEndLine ; i++)1938 {1939 for(j = 0; j < xInterval ; j++)1940 {1941 imgYVar[i][j] = regionTable[yIndexOffset+0];1942 }1943 1944 for(j = xInterval; j < xInterval*2 ; j++)1945 {1946 imgYVar[i][j] = regionTable[yIndexOffset+1];1947 }1948 1949 for(j = xInterval*2; j < xInterval*3 ; j++)1950 {1951 imgYVar[i][j] = regionTable[yIndexOffset+2];1952 }1953 1954 for(j = xInterval*3; j < imgWidth>>shiftWidth ; j++)1955 {1956 imgYVar[i][j] = regionTable[yIndexOffset+3];1957 }1958 }1959 }1960 1961 }1962 1963 // --------------------------------------------------------------------------------------------------------------------1964 // ALF for chroma1965 // --------------------------------------------------------------------------------------------------------------------1966 1967 /**1968 \param pcPicDec picture before ALF1969 \param pcPicRest picture after ALF1970 \param qh filter coefficient1971 \param iTap filter tap1972 \param iColor 0 for Cb and 1 for Cr1973 */1974 Void TComAdaptiveLoopFilter::filterChroma(Pel *pImgRes, Pel *pImgPad, Int stride,1975 Int ypos, Int yposEnd, Int xpos, Int xposEnd,1976 Int filtNo, Int* coef)1977 {1978 static Int numBitsMinus1= (Int)ALF_NUM_BIT_SHIFT;1979 static Int offset = (1<<( (Int)ALF_NUM_BIT_SHIFT-1));1980 1981 Pel *pImgPad1,*pImgPad2,*pImgPad3,*pImgPad4;1982 Int i, j, pixelInt;1983 1984 pImgPad += (ypos*stride);1985 pImgRes += (ypos*stride);1986 1987 Int imgHeightChroma = m_img_height>>1;1988 Int yLineInLCU;1989 Int paddingline;1990 Int newCenterCoeff[4];1991 1992 ::memset(newCenterCoeff, 0, sizeof(Int)*4);1993 #if ALF_SINGLE_FILTER_SHAPE1994 if(filtNo == ALF_CROSS9x7_SQUARE3x3)1995 #else1996 if (filtNo == ALF_CROSS9x9)1997 #endif1998 {1999 //VB line 12000 newCenterCoeff[0] = coef[8] + ((coef[0] + coef[1] + coef[2] + coef[3])<<1);2001 //VB line 22002 newCenterCoeff[1] = coef[8] + ((coef[0] + coef[1] + coef[2])<<1);2003 //VB line 32004 newCenterCoeff[2] = coef[8] + ((coef[0] + coef[1])<<1);2005 //VB line 42006 newCenterCoeff[3] = coef[8] + ((coef[0])<<1);2007 }2008 2009 switch(filtNo)2010 {2011 #if !ALF_SINGLE_FILTER_SHAPE2012 case ALF_STAR5x5:2013 {2014 for(i= ypos; i<= yposEnd; i++)2015 {2016 yLineInLCU = i % m_lcuHeightChroma;2017 2018 if (yLineInLCU < m_lineIdxPadBotChroma || i-yLineInLCU+m_lcuHeightChroma >= imgHeightChroma )2019 {2020 pImgPad1 = pImgPad + stride;2021 pImgPad2 = pImgPad - stride;2022 pImgPad3 = pImgPad + 2*stride;2023 pImgPad4 = pImgPad - 2*stride;2024 }2025 else if (yLineInLCU < m_lineIdxPadTopChroma)2026 {2027 paddingline = - yLineInLCU + m_lineIdxPadTopChroma - 1;2028 pImgPad1 = pImgPad + min(paddingline, 1)*stride;2029 pImgPad2 = pImgPad - stride;2030 pImgPad3 = pImgPad + min(paddingline, 2)*stride;2031 pImgPad4 = pImgPad - 2*stride;2032 }2033 else2034 {2035 paddingline = yLineInLCU - m_lineIdxPadTopChroma ;2036 pImgPad1 = pImgPad + stride;2037 pImgPad2 = pImgPad - min(paddingline, 1)*stride;2038 pImgPad3 = pImgPad + 2*stride;2039 pImgPad4 = pImgPad - min(paddingline, 2)*stride;2040 }2041 2042 if ( (yLineInLCU == m_lineIdxPadTopChroma || yLineInLCU == m_lineIdxPadTopChroma-1) && i-yLineInLCU+m_lcuHeightChroma < imgHeightChroma )2043 {2044 for(j= xpos; j<= xposEnd ; j++)2045 {2046 pImgRes[j] = pImgPad[j];2047 }2048 }2049 else if ( (yLineInLCU == m_lineIdxPadTopChroma+1 || yLineInLCU == m_lineIdxPadTopChroma-2) && i-yLineInLCU+m_lcuHeightChroma < imgHeightChroma )2050 {2051 for(j= xpos; j<= xposEnd ; j++)2052 {2053 pixelInt = 0;2054 2055 pixelInt += coef[0]* (pImgPad3[j+2]+pImgPad4[j-2]);2056 pixelInt += coef[1]* (pImgPad3[j ]+pImgPad4[j ]);2057 pixelInt += coef[2]* (pImgPad3[j-2]+pImgPad4[j+2]);2058 2059 pixelInt += coef[3]* (pImgPad1[j+1]+pImgPad2[j-1]);2060 pixelInt += coef[4]* (pImgPad1[j ]+pImgPad2[j ]);2061 pixelInt += coef[5]* (pImgPad1[j-1]+pImgPad2[j+1]);2062 2063 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);2064 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);2065 pixelInt += coef[8]* (pImgPad[j ]);2066 2067 pixelInt=(Int)((pixelInt+offset) >> numBitsMinus1);2068 2069 pImgRes[j] = (Clip( pixelInt ) + pImgPad[j]) >> 1;2070 }2071 }2072 else2073 {2074 2075 for(j= xpos; j<= xposEnd ; j++)2076 {2077 pixelInt = 0;2078 2079 pixelInt += coef[0]* (pImgPad3[j+2]+pImgPad4[j-2]);2080 pixelInt += coef[1]* (pImgPad3[j ]+pImgPad4[j ]);2081 pixelInt += coef[2]* (pImgPad3[j-2]+pImgPad4[j+2]);2082 2083 pixelInt += coef[3]* (pImgPad1[j+1]+pImgPad2[j-1]);2084 pixelInt += coef[4]* (pImgPad1[j ]+pImgPad2[j ]);2085 pixelInt += coef[5]* (pImgPad1[j-1]+pImgPad2[j+1]);2086 2087 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);2088 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);2089 pixelInt += coef[8]* (pImgPad[j ]);2090 2091 pixelInt=(Int)((pixelInt+offset) >> numBitsMinus1);2092 2093 pImgRes[j] = Clip( pixelInt );2094 }2095 2096 }2097 pImgPad += stride;2098 pImgRes += stride;2099 }2100 }2101 break;2102 case ALF_CROSS9x9:2103 {2104 Pel *pImgPad5, *pImgPad6, *pImgPad7, *pImgPad8;2105 #else2106 case ALF_CROSS9x7_SQUARE3x3:2107 {2108 Pel *pImgPad5, *pImgPad6;2109 #endif2110 for(i= ypos; i<= yposEnd; i++)2111 {2112 yLineInLCU = i % m_lcuHeightChroma;2113 #if ALF_SINGLE_FILTER_SHAPE2114 if (yLineInLCU<2 && i> 2)2115 #else2116 if (yLineInLCU<2)2117 #endif2118 {2119 paddingline = yLineInLCU + 2 ;2120 pImgPad1 = pImgPad + stride;2121 pImgPad2 = pImgPad - stride;2122 pImgPad3 = pImgPad + 2*stride;2123 pImgPad4 = pImgPad - 2*stride;2124 #if ALF_SINGLE_FILTER_SHAPE2125 pImgPad5 = (paddingline < 3) ? pImgPad : pImgPad + 3*stride;2126 pImgPad6 = (paddingline < 3) ? pImgPad : pImgPad - min(paddingline, 3)*stride;2127 #else2128 pImgPad5 = pImgPad + 3*stride;2129 pImgPad6 = pImgPad - min(paddingline, 3)*stride;2130 pImgPad7 = pImgPad + 4*stride;2131 pImgPad8 = pImgPad - min(paddingline, 4)*stride;2132 #endif2133 }2134 else if (yLineInLCU < m_lineIdxPadBotChroma || i-yLineInLCU+m_lcuHeightChroma >= imgHeightChroma )2135 {2136 pImgPad1 = pImgPad + stride;2137 pImgPad2 = pImgPad - stride;2138 pImgPad3 = pImgPad + 2*stride;2139 pImgPad4 = pImgPad - 2*stride;2140 pImgPad5 = pImgPad + 3*stride;2141 pImgPad6 = pImgPad - 3*stride;2142 #if !ALF_SINGLE_FILTER_SHAPE2143 pImgPad7 = pImgPad + 4*stride;2144 pImgPad8 = pImgPad - 4*stride;2145 #endif2146 }2147 else if (yLineInLCU < m_lineIdxPadTopChroma)2148 {2149 paddingline = - yLineInLCU + m_lineIdxPadTopChroma - 1;2150 #if ALF_SINGLE_FILTER_SHAPE2151 pImgPad1 = (paddingline < 1) ? pImgPad : pImgPad + min(paddingline, 1)*stride;2152 pImgPad2 = (paddingline < 1) ? pImgPad : pImgPad - stride;2153 pImgPad3 = (paddingline < 2) ? pImgPad : pImgPad + min(paddingline, 2)*stride;2154 pImgPad4 = (paddingline < 2) ? pImgPad : pImgPad - 2*stride;2155 pImgPad5 = (paddingline < 3) ? pImgPad : pImgPad + min(paddingline, 3)*stride;2156 pImgPad6 = (paddingline < 3) ? pImgPad : pImgPad - 3*stride;2157 #else2158 pImgPad1 = pImgPad + min(paddingline, 1)*stride;2159 pImgPad2 = pImgPad - stride;2160 pImgPad3 = pImgPad + min(paddingline, 2)*stride;2161 pImgPad4 = pImgPad - 2*stride;2162 pImgPad5 = pImgPad + min(paddingline, 3)*stride;2163 pImgPad6 = pImgPad - 3*stride;2164 pImgPad7 = pImgPad + min(paddingline, 4)*stride;2165 pImgPad8 = pImgPad - 4*stride;2166 #endif2167 }2168 else2169 {2170 paddingline = yLineInLCU - m_lineIdxPadTopChroma ;2171 #if ALF_SINGLE_FILTER_SHAPE2172 pImgPad1 = (paddingline < 1) ? pImgPad : pImgPad + stride;2173 pImgPad2 = (paddingline < 1) ? pImgPad : pImgPad - min(paddingline, 1)*stride;2174 pImgPad3 = (paddingline < 2) ? pImgPad : pImgPad + 2*stride;2175 pImgPad4 = (paddingline < 2) ? pImgPad : pImgPad - min(paddingline, 2)*stride;2176 pImgPad5 = (paddingline < 3) ? pImgPad : pImgPad + 3*stride;2177 pImgPad6 = (paddingline < 3) ? pImgPad : pImgPad - min(paddingline, 3)*stride;2178 #else2179 pImgPad1 = pImgPad + stride;2180 pImgPad2 = pImgPad - min(paddingline, 1)*stride;2181 pImgPad3 = pImgPad + 2*stride;2182 pImgPad4 = pImgPad - min(paddingline, 2)*stride;2183 pImgPad5 = pImgPad + 3*stride;2184 pImgPad6 = pImgPad - min(paddingline, 3)*stride;2185 pImgPad7 = pImgPad + 4*stride;2186 pImgPad8 = pImgPad - min(paddingline, 4)*stride;2187 #endif2188 }2189 2190 #if ALF_SINGLE_FILTER_SHAPE2191 for(j= xpos; j<= xposEnd ; j++)2192 {2193 pixelInt = 0;2194 2195 pixelInt += coef[0]* (pImgPad5[j]+pImgPad6[j]);2196 pixelInt += coef[1]* (pImgPad3[j]+pImgPad4[j]);2197 pixelInt += coef[2]* (pImgPad1[j-1]+pImgPad2[j+1]);2198 pixelInt += coef[3]* (pImgPad1[j]+pImgPad2[j]);2199 pixelInt += coef[4]* (pImgPad1[j+1]+pImgPad2[j-1]);2200 pixelInt += coef[5]* (pImgPad[j+4]+pImgPad[j-4]);2201 pixelInt += coef[6]* (pImgPad[j+3]+pImgPad[j-3]);2202 pixelInt += coef[7]* (pImgPad[j+2]+pImgPad[j-2]);2203 pixelInt += coef[8]* (pImgPad[j+1]+pImgPad[j-1]);2204 pixelInt += coef[9]* (pImgPad[j ]);2205 2206 pixelInt=(Int)((pixelInt+offset) >> numBitsMinus1);2207 2208 pImgRes[j] = Clip( pixelInt );2209 }2210 #else2211 if ( (yLineInLCU == m_lineIdxPadTopChroma || yLineInLCU == m_lineIdxPadTopChroma-1) && i-yLineInLCU+m_lcuHeightChroma < imgHeightChroma )2212 {2213 for(j= xpos; j<= xposEnd ; j++)2214 {2215 pixelInt = 0;2216 2217 pixelInt += coef[4]* (pImgPad[j+4]+pImgPad[j-4]);2218 pixelInt += coef[5]* (pImgPad[j+3]+pImgPad[j-3]);2219 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);2220 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);2221 pixelInt += newCenterCoeff[0]* (pImgPad[j ]);2222 2223 pixelInt=(Int)((pixelInt+offset) >> numBitsMinus1);2224 2225 pImgRes[j] = Clip( pixelInt );2226 }2227 }2228 else if ( (yLineInLCU == m_lineIdxPadTopChroma+1 || yLineInLCU == m_lineIdxPadTopChroma-2) && i-yLineInLCU+m_lcuHeightChroma < imgHeightChroma )2229 {2230 for(j= xpos; j<= xposEnd ; j++)2231 {2232 pixelInt = 0;2233 2234 pixelInt += coef[3]* (pImgPad1[j]+pImgPad2[j]);2235 2236 pixelInt += coef[4]* (pImgPad[j+4]+pImgPad[j-4]);2237 pixelInt += coef[5]* (pImgPad[j+3]+pImgPad[j-3]);2238 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);2239 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);2240 pixelInt += newCenterCoeff[1]* (pImgPad[j ]);2241 2242 pixelInt=(Int)((pixelInt+offset) >> numBitsMinus1);2243 2244 pImgRes[j] = Clip( pixelInt );2245 }2246 }2247 else if ( (yLineInLCU == 0 && i>0) || (yLineInLCU == m_lineIdxPadTopChroma-3 && i-yLineInLCU+m_lcuHeightChroma < imgHeightChroma) )2248 {2249 for(j= xpos; j<= xposEnd ; j++)2250 {2251 pixelInt = 0;2252 2253 pixelInt += coef[2]* (pImgPad3[j]+pImgPad4[j]);2254 2255 pixelInt += coef[3]* (pImgPad1[j]+pImgPad2[j]);2256 2257 pixelInt += coef[4]* (pImgPad[j+4]+pImgPad[j-4]);2258 pixelInt += coef[5]* (pImgPad[j+3]+pImgPad[j-3]);2259 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);2260 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);2261 pixelInt += newCenterCoeff[2]* (pImgPad[j ]);2262 2263 pixelInt=(Int)((pixelInt+offset) >> numBitsMinus1);2264 2265 pImgRes[j] = Clip( pixelInt );2266 }2267 }2268 else if ( (yLineInLCU == 1 && i>1) || (yLineInLCU == m_lineIdxPadTopChroma-4 && i-yLineInLCU+m_lcuHeightChroma < imgHeightChroma) )2269 {2270 for(j= xpos; j<= xposEnd ; j++)2271 {2272 pixelInt = 0;2273 2274 pixelInt += coef[1]* (pImgPad5[j]+pImgPad6[j]);2275 2276 pixelInt += coef[2]* (pImgPad3[j]+pImgPad4[j]);2277 2278 pixelInt += coef[3]* (pImgPad1[j]+pImgPad2[j]);2279 2280 pixelInt += coef[4]* (pImgPad[j+4]+pImgPad[j-4]);2281 pixelInt += coef[5]* (pImgPad[j+3]+pImgPad[j-3]);2282 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);2283 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);2284 pixelInt += newCenterCoeff[3]* (pImgPad[j ]);2285 2286 pixelInt=(Int)((pixelInt+offset) >> numBitsMinus1);2287 2288 pImgRes[j] = Clip( pixelInt );2289 }2290 }2291 else2292 {2293 for(j= xpos; j<= xposEnd ; j++)2294 {2295 pixelInt = 0;2296 2297 pixelInt += coef[0]* (pImgPad7[j]+pImgPad8[j]);2298 2299 pixelInt += coef[1]* (pImgPad5[j]+pImgPad6[j]);2300 2301 pixelInt += coef[2]* (pImgPad3[j]+pImgPad4[j]);2302 2303 pixelInt += coef[3]* (pImgPad1[j]+pImgPad2[j]);2304 2305 pixelInt += coef[4]* (pImgPad[j+4]+pImgPad[j-4]);2306 pixelInt += coef[5]* (pImgPad[j+3]+pImgPad[j-3]);2307 pixelInt += coef[6]* (pImgPad[j+2]+pImgPad[j-2]);2308 pixelInt += coef[7]* (pImgPad[j+1]+pImgPad[j-1]);2309 pixelInt += coef[8]* (pImgPad[j ]);2310 2311 pixelInt=(Int)((pixelInt+offset) >> numBitsMinus1);2312 2313 pImgRes[j] = Clip( pixelInt );2314 }2315 }2316 #endif2317 pImgPad += stride;2318 pImgRes += stride;2319 2320 }2321 }2322 2323 break;2324 default:2325 {2326 printf("Not a supported filter shape\n");2327 assert(0);2328 exit(1);2329 }2330 }2331 2332 }2333 2334 /** Chroma filtering for multi-slice picture2335 * \param componentID slice parameters2336 * \param pcPicDecYuv original picture2337 * \param pcPicRestYuv picture before filtering2338 * \param coeff filter coefficients2339 * \param filtNo filter shape2340 * \param chromaFormatShift size adjustment for chroma (1 for 4:2:0 format)2341 */2342 Void TComAdaptiveLoopFilter::xFilterChromaSlices(Int componentID, TComPicYuv* pcPicDecYuv, TComPicYuv* pcPicRestYuv, Int *coeff, Int filtNo, Int chromaFormatShift)2343 {2344 Pel* pPicDec = (componentID == ALF_Cb)?( pcPicDecYuv->getCbAddr()):( pcPicDecYuv->getCrAddr());2345 Pel* pPicSlice = (componentID == ALF_Cb)?(m_pcSliceYuvTmp->getCbAddr()):(m_pcSliceYuvTmp->getCrAddr());2346 Pel* pRest = (componentID == ALF_Cb)?( pcPicRestYuv->getCbAddr()):( pcPicRestYuv->getCrAddr());2347 Int stride = pcPicDecYuv->getCStride();2348 2349 for(UInt s=0; s< m_uiNumSlicesInPic; s++)2350 {2351 if(!m_pcPic->getValidSlice(s))2352 {2353 continue;2354 }2355 std::vector< std::vector<AlfLCUInfo*> > & vpSliceTileAlfLCU = m_pvpSliceTileAlfLCU[s];2356 2357 for(Int t=0; t< (Int)vpSliceTileAlfLCU.size(); t++)2358 {2359 std::vector<AlfLCUInfo*> & vpAlfLCU = vpSliceTileAlfLCU[t];2360 2361 copyRegion(vpAlfLCU, pPicSlice, pPicDec, stride, chromaFormatShift);2362 extendRegionBorder(vpAlfLCU, pPicSlice, stride, chromaFormatShift);2363 filterChromaRegion(vpAlfLCU, pPicSlice, pRest, stride, coeff, filtNo, chromaFormatShift);2364 }2365 }2366 }2367 2368 /** Chroma filtering for one component in multi-slice picture2369 * \param componentID slice parameters2370 * \param pcPicDecYuv original picture2371 * \param pcPicRestYuv picture before filtering2372 * \param shape filter shape2373 * \param pCoeff filter coefficients2374 */2375 Void TComAdaptiveLoopFilter::xFilterChromaOneCmp(Int componentID, TComPicYuv *pDecYuv, TComPicYuv *pRestYuv, Int shape, Int *pCoeff)2376 {2377 Int chromaFormatShift = 1;2378 if(!m_bUseNonCrossALF)2379 {2380 Pel* pDec = (componentID == ALF_Cb)?(pDecYuv->getCbAddr()): (pDecYuv->getCrAddr());2381 Pel* pRest = (componentID == ALF_Cb)?(pRestYuv->getCbAddr()):(pRestYuv->getCrAddr());2382 Int iStride = pDecYuv->getCStride();2383 filterChroma(pRest, pDec, iStride, 0, (Int)(m_img_height>>1) -1, 0, (Int)(m_img_width>>1)-1, shape, pCoeff);2384 }2385 else2386 {2387 xFilterChromaSlices(componentID, pDecYuv, pRestYuv, pCoeff, shape, chromaFormatShift);2388 }2389 }2390 2391 /** Chroma filtering for multi-slice picture2392 * \param pcAlfParam ALF parameters2393 * \param pcPicDec to-be-filtered picture buffer2394 * \param pcPicRest filtered picture buffer2395 */2396 Void TComAdaptiveLoopFilter::xALFChroma(ALFParam* pcAlfParam, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest)2397 {2398 if((pcAlfParam->chroma_idc>>1)&0x01)2399 {2400 xFilterChromaOneCmp(ALF_Cb, pcPicDec, pcPicRest, pcAlfParam->filter_shape_chroma, pcAlfParam->coeff_chroma);2401 }2402 2403 if(pcAlfParam->chroma_idc&0x01)2404 {2405 xFilterChromaOneCmp(ALF_Cr, pcPicDec, pcPicRest, pcAlfParam->filter_shape_chroma, pcAlfParam->coeff_chroma);2406 }2407 }2408 2409 #endif2410 921 2411 922 Void TComAdaptiveLoopFilter::setAlfCtrlFlags(AlfCUCtrlInfo* pAlfParam, TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt &idx) … … 2498 1009 * \param numSlicesInPic number of slices in picture 2499 1010 */ 2500 #if LCU_SYNTAX_ALF2501 1011 Void TComAdaptiveLoopFilter::createPicAlfInfo(TComPic* pcPic, Int numSlicesInPic, Int alfQP) 2502 #else2503 Void TComAdaptiveLoopFilter::createPicAlfInfo(TComPic* pcPic, Int numSlicesInPic)2504 #endif2505 1012 { 2506 1013 m_uiNumSlicesInPic = numSlicesInPic; … … 2510 1017 m_pcPic = pcPic; 2511 1018 2512 #if LCU_SYNTAX_ALF2513 1019 m_isNonCrossSlice = pcPic->getIndependentSliceBoundaryForNDBFilter(); 2514 1020 m_suWidth = pcPic->getMinCUWidth(); 2515 1021 m_suHeight= pcPic->getMinCUHeight(); 2516 1022 m_alfQP = alfQP; 2517 #endif2518 #if !LCU_SYNTAX_ALF2519 if(m_uiNumSlicesInPic > 1 || m_bUseNonCrossALF)2520 {2521 #endif2522 1023 m_ppSliceAlfLCUs = new AlfLCUInfo*[m_uiNumSlicesInPic]; 2523 1024 m_pvpAlfLCU = new std::vector< AlfLCUInfo* >[m_uiNumSlicesInPic]; … … 2584 1085 m_pcSliceYuvTmp = pcPic->getYuvPicBufferForIndependentBoundaryProcessing(); 2585 1086 } 2586 #if !LCU_SYNTAX_ALF2587 }2588 #endif2589 1087 2590 1088 } … … 2594 1092 Void TComAdaptiveLoopFilter::destroyPicAlfInfo() 2595 1093 { 2596 #if !LCU_SYNTAX_ALF2597 if(m_bUseNonCrossALF)2598 {2599 #endif2600 1094 for(Int s=0; s< m_uiNumSlicesInPic; s++) 2601 1095 { … … 2614 1108 delete[] m_pvpSliceTileAlfLCU; 2615 1109 m_pvpSliceTileAlfLCU = NULL; 2616 #if !LCU_SYNTAX_ALF 2617 } 2618 #endif 2619 } 2620 2621 #if !LCU_SYNTAX_ALF 2622 /** ALF for cu-on/off-controlled region 2623 * \param vpAlfLCU ALF LCU information container 2624 * \param imgDec to-be-filtered picture buffer 2625 * \param imgRest filtered picture buffer 2626 * \param stride picture buffer stride size 2627 * \param filtNo filter shape 2628 * \param filterCoeff filter coefficients 2629 * \param mergeTable merge table for filter set 2630 * \param varImg BA index 2631 */ 2632 Void TComAdaptiveLoopFilter::xCUAdaptiveRegion(std::vector<AlfLCUInfo*> &vpAlfLCU, Pel* imgDec, Pel* imgRest, Int stride, Int filtNo, Int** filterCoeff, Int* mergeTable, Pel** varImg) 2633 { 2634 UInt SUWidth = m_pcPic->getMinCUWidth(); 2635 UInt SUHeight = m_pcPic->getMinCUHeight(); 2636 UInt idx, startSU, endSU, currSU, LCUX, LCUY, LPelX, TPelY; 2637 TComDataCU* pcCU; 2638 2639 for(idx=0; idx< vpAlfLCU.size(); idx++) 2640 { 2641 AlfLCUInfo& rAlfLCU = *(vpAlfLCU[idx]); 2642 pcCU = rAlfLCU.pcCU; 2643 startSU = rAlfLCU.startSU; 2644 endSU = rAlfLCU.endSU; 2645 LCUX = pcCU->getCUPelX(); 2646 LCUY = pcCU->getCUPelY(); 2647 2648 for(currSU= startSU; currSU<= endSU; currSU++) 2649 { 2650 LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ]; 2651 TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ]; 2652 if( !( LPelX < m_img_width ) || !( TPelY < m_img_height ) ) 2653 { 2654 continue; 2655 } 2656 if(pcCU->getAlfCtrlFlag(currSU)) 2657 { 2658 filterLuma(imgRest, imgDec, stride, TPelY, TPelY+ SUHeight-1, LPelX, LPelX+ SUWidth-1, filtNo, m_filterCoeffSym, m_varIndTab, m_varImg); 2659 } 2660 } 2661 } 2662 2663 } 2664 2665 /** ALF for "non" cu-on/off-controlled region 2666 * \param vpAlfLCU ALF LCU information container 2667 * \param imgDec to-be-filtered picture buffer 2668 * \param imgRest filtered picture buffer 2669 * \param stride picture buffer stride size 2670 * \param filtNo filter shape 2671 * \param filterCoeff filter coefficients 2672 * \param mergeTable merge table for filter set 2673 * \param varImg BA index 2674 */ 2675 Void TComAdaptiveLoopFilter::filterLumaRegion(std::vector<AlfLCUInfo*> &vpAlfLCU, Pel* imgDec, Pel* imgRest, Int stride, Int filtNo, Int** filterCoeff, Int* mergeTable, Pel** varImg) 2676 { 2677 2678 Int height, width; 2679 Int ypos, xpos; 2680 2681 for(Int i=0; i< vpAlfLCU.size(); i++) 2682 { 2683 AlfLCUInfo& rAlfLCU = *(vpAlfLCU[i]); 2684 for(UInt j=0; j< rAlfLCU.numSGU; j++) 2685 { 2686 ypos = (Int)(rAlfLCU[j].posY ); 2687 xpos = (Int)(rAlfLCU[j].posX ); 2688 height = (Int)(rAlfLCU[j].height); 2689 width = (Int)(rAlfLCU[j].width ); 2690 2691 filterLuma(imgRest, imgDec, stride, ypos, ypos+ height-1, xpos, xpos+ width-1, filtNo, filterCoeff, mergeTable, varImg); 2692 } 2693 } 2694 } 2695 2696 2697 /** Perform ALF for one chroma region 2698 * \param vpAlfLCU ALF LCU data container 2699 * \param pDec to-be-filtered picture buffer 2700 * \param pRest filtered picture buffer 2701 * \param stride picture buffer stride 2702 * \param coeff filter coefficients 2703 * \param filtNo filter shape 2704 * \param chromaFormatShift chroma component size adjustment (1 for 4:2:0) 2705 */ 2706 Void TComAdaptiveLoopFilter::filterChromaRegion(std::vector<AlfLCUInfo*> &vpAlfLCU, Pel* pDec, Pel* pRest, Int stride, Int *coeff, Int filtNo, Int chromaFormatShift) 2707 { 2708 Int height, width; 2709 Int ypos, xpos; 2710 2711 for(Int i=0; i< vpAlfLCU.size(); i++) 2712 { 2713 AlfLCUInfo& cAlfLCU = *(vpAlfLCU[i]); 2714 for(Int j=0; j< cAlfLCU.numSGU; j++) 2715 { 2716 ypos = (Int)(cAlfLCU[j].posY >> chromaFormatShift); 2717 xpos = (Int)(cAlfLCU[j].posX >> chromaFormatShift); 2718 height = (Int)(cAlfLCU[j].height >> chromaFormatShift); 2719 width = (Int)(cAlfLCU[j].width >> chromaFormatShift); 2720 2721 filterChroma(pRest, pDec, stride, ypos, ypos+ height -1, xpos, xpos+ width-1, filtNo, coeff); 2722 } 2723 } 2724 } 2725 2726 #endif 1110 } 1111 2727 1112 2728 1113 /** Copy ALF CU control flags from ALF parameters for slices … … 2846 1231 { 2847 1232 NDBFBlockInfo& rSGU = rAlfLCU[n]; 2848 #if LCU_SYNTAX_ALF2849 1233 if(rSGU.allBordersAvailable) 2850 1234 { 2851 1235 continue; 2852 1236 } 2853 #endif2854 1237 posX = rSGU.posX >> formatShift; 2855 1238 posY = rSGU.posY >> formatShift; … … 3127 1510 } 3128 1511 3129 #if LCU_SYNTAX_ALF3130 1512 /** reconstruct ALF luma coefficient 3131 1513 * \param [in] alfLCUParam ALF parameters … … 3232 1614 coeffPred = (1<<ALF_NUM_BIT_SHIFT) - sum; 3233 1615 #endif 3234 #if ALF_CHROMA_COEF_PRED_HARMONIZATION3235 1616 filterCoeff[0][alfLCUParam->num_coeff-1] = coeffPred + alfLCUParam->coeffmulti[0][alfLCUParam->num_coeff-1]; 3236 #else3237 filterCoeff[0][alfLCUParam->num_coeff-1] = coeffPred - alfLCUParam->coeffmulti[0][alfLCUParam->num_coeff-1];3238 #endif3239 1617 } 3240 1618 … … 3444 1822 Int pred = (1<<ALF_NUM_BIT_SHIFT) - (sum); 3445 1823 #endif 3446 #if ALF_CHROMA_COEF_PRED_HARMONIZATION3447 1824 coeff[numCoef-1] = coeff[numCoef-1] - pred; 3448 #else 3449 coeff[numCoef-1] = pred- coeff[numCoef-1]; 3450 #endif 3451 } 3452 3453 #if ALF_SINGLE_FILTER_SHAPE 1825 } 1826 3454 1827 /** filtering pixels 3455 1828 * \param [out] imgRes filtered picture … … 3576 1949 } 3577 1950 } 3578 #endif3579 1951 3580 1952 #if LCUALF_QP_DEPENDENT_BITS … … 3623 1995 static Int shiftW = (Int)(log((double)VAR_SIZE_W)/log(2.0)); 3624 1996 static Int varMax = (Int)NO_VAR_BINS-1; 3625 #if ALF_16_BA_GROUPS3626 1997 static Int th[NO_VAR_BINS] = {0, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5}; 3627 1998 static Int avgVarTab[3][6] = { {0, 1, 2, 3, 4, 5,}, 3628 1999 {0, 6, 7, 8, 9, 10,}, 3629 2000 {0, 11, 12, 13, 14, 15} }; 3630 #else3631 static Int step = (Int)((Int)(NO_VAR_BINS)/3) - 1;3632 static Int th[NO_VAR_BINS] = {0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4};3633 #endif3634 2001 3635 2002 Int i, j, avgVar, vertical, horizontal, direction, yOffset; … … 3683 2050 avgVar = (Pel) Clip_post( varMax, avgVar>>(g_uiBitIncrement+1) ); 3684 2051 avgVar = th[avgVar]; 3685 #if ALF_16_BA_GROUPS3686 2052 avgVar = avgVarTab[direction][avgVar]; 3687 #else3688 avgVar = Clip_post(step, (Int)avgVar) + (step+1)*direction;3689 #endif3690 2053 imgYvar[i>>shiftH][j>>shiftW] = avgVar; 3691 2054 } … … 3767 2130 return pBuf; 3768 2131 } 3769 #endif3770 2132 3771 2133
Note: See TracChangeset for help on using the changeset viewer.