Created
September 29, 2023 11:25
-
-
Save glebov21/0d60cba3f2e429cda3f8f7b9264fc3f4 to your computer and use it in GitHub Desktop.
c# Contrast formula RGB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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