Skip to content

Instantly share code, notes, and snippets.

@glebov21
Created September 29, 2023 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glebov21/0d60cba3f2e429cda3f8f7b9264fc3f4 to your computer and use it in GitHub Desktop.
Save glebov21/0d60cba3f2e429cda3f8f7b9264fc3f4 to your computer and use it in GitHub Desktop.
c# Contrast formula RGB
var contrast = 30; //[-255;+255]
float factor = (259f * (contrast + 255f)) / (255f * (259f - contrast));
Color.r = (byte)Math.Clamp(factor * (Color.r - 128) + 128, 0, 255);
Color.g = (byte)Math.Clamp(factor * (Color.g - 128) + 128, 0, 255);
Color.b = (byte)Math.Clamp(factor * (Color.b - 128) + 128, 0, 255);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment