private int MaskAvg(ColorBgra before) { int count = 0, total = 0; for (int c = 0; c < 3; c++) { if (mask [c]) { total += before [c]; count++; } } if (count > 0) { return total / count; } else { return 0; } }