if((0.2126*sample.r) + (0.7152*sample.g) + (0.0722*sample.b) > level) { float brightenRatio = 1.0 / max(max(sample.r, sample.g), sample.b); sample.r *= brightenRatio; sample.g *= brightenRatio; sample.b *= brightenRatio; } else { sample.r = 0.0; sample.g = 0.0; sample.b = 0.0; }

The largest component ends up being 1.0 and the smaller components maintain the same ratio hence obtaining the same colour only brighter.