private float MaskGamma(UnaryPixelOps.Level levels) { int count = 0; float total = 0; for (int c = 0; c < 3; c++) { if (mask[c]) { total += levels.GetGamma(c); count++; } } if (count > 0) { return total / count; } else { return 1; } }
private void UpdateGammaByMask(UnaryPixelOps.Level levels, float val) { float average = -1; if (!(mask[0] || mask[1] || mask[2])) { return; } do { average = MaskGamma(levels); float factor = val / average; for (int c = 0; c < 3; c++) { if (mask[c]) { levels.SetGamma(c, factor * levels.GetGamma(c)); } } } while (Math.Abs(val - average) > 0.001); }