private int method5(List <double[][]>[] rgbList, int chr) { List <double> subDiff = new List <double>(); List <double[][]> MR, MG, MB; List <double[][]> SR, SG, SB; int listSize = rgbList[0].Count; int windowSize = Math.Min(Global.maxWidth, listSize); int result = 0; int minWidth = 40; switch (chr) { case 0: // 4:4:4 for (int i = minWidth; i < windowSize; i++) { MR = rgbList[0].Take(listSize - i).ToList(); MG = rgbList[1].Take(listSize - i).ToList(); MB = rgbList[2].Take(listSize - i).ToList(); SR = rgbList[0].Skip(i).ToList(); SG = rgbList[1].Skip(i).ToList(); SB = rgbList[2].Skip(i).ToList(); subDiff.Add(UBDiffSum(MR, MG, MB, SR, SG, SB)); MR.Clear(); MG.Clear(); MB.Clear(); SR.Clear(); SG.Clear(); SB.Clear(); } result = subDiff.IndexOf(subDiff.Min()) + minWidth; break; case 1: // 4:4:0 for (int i = minWidth; i < windowSize; i++) { MR = rgbList[0].Where((item, index) => index % 2 != 0).Take(listSize / 2 - i).ToList(); MG = rgbList[1].Where((item, index) => index % 2 != 0).Take(listSize / 2 - i).ToList(); MB = rgbList[2].Where((item, index) => index % 2 != 0).Take(listSize / 2 - i).ToList(); SR = rgbList[0].Skip(2 * i).Where((item, index) => index % 2 == 0).ToList(); SG = rgbList[1].Skip(2 * i).Where((item, index) => index % 2 == 0).ToList(); SB = rgbList[2].Skip(2 * i).Where((item, index) => index % 2 == 0).ToList(); subDiff.Add(UBDiffSum(MR, MG, MB, SR, SG, SB)); MR.Clear(); MG.Clear(); MB.Clear(); SR.Clear(); SG.Clear(); SB.Clear(); } result = subDiff.IndexOf(subDiff.Min()) + minWidth; break; case 2: // 4:2:2 for (int i = minWidth; i < windowSize; i += 2) { MR = rgbList[0].Take(listSize - i).ToList(); MG = rgbList[1].Take(listSize - i).ToList(); MB = rgbList[2].Take(listSize - i).ToList(); SR = rgbList[0].Skip(i).ToList(); SG = rgbList[1].Skip(i).ToList(); SB = rgbList[2].Skip(i).ToList(); subDiff.Add(UBDiffSum(MR, MG, MB, SR, SG, SB)); MR.Clear(); MG.Clear(); MB.Clear(); SR.Clear(); SG.Clear(); SB.Clear(); } result = subDiff.IndexOf(subDiff.Min()) + minWidth / 2; break; case 3: //4:2:0 for (int i = minWidth; i < windowSize; i += 2) { MR = rgbList[0].Where((item, index) => index % 4 == 2 || index % 4 == 3).Take(listSize / 2 - i).ToList(); MG = rgbList[1].Where((item, index) => index % 4 == 2 || index % 4 == 3).Take(listSize / 2 - i).ToList(); MB = rgbList[2].Where((item, index) => index % 4 == 2 || index % 4 == 3).Take(listSize / 2 - i).ToList(); SR = rgbList[0].Skip(2 * i).Where((item, index) => index % 4 == 0 || index % 4 == 1).ToList(); SG = rgbList[1].Skip(2 * i).Where((item, index) => index % 4 == 0 || index % 4 == 1).ToList(); SB = rgbList[2].Skip(2 * i).Where((item, index) => index % 4 == 0 || index % 4 == 1).ToList(); subDiff.Add(UBDiffSum(MR, MG, MB, SR, SG, SB)); MR.Clear(); MG.Clear(); MB.Clear(); SR.Clear(); SG.Clear(); SB.Clear(); } result = subDiff.IndexOf(subDiff.Min()) + minWidth / 2; break; } return(result); }