Created
January 24, 2016 16:07
-
-
Save dobrokot/7c86c6c03d6e7d289143 to your computer and use it in GitHub Desktop.
test color mixing in sRGB
This file contains 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
def sRGB_to_linear(c): | |
a = 0.055 | |
if c <= 0.04045: | |
return c / 12.92 | |
else: | |
return ((c + a) / (1+a)) ** 2.4 | |
def linear_to_sRGB(c): | |
a = 0.055 | |
if c <= 0.0031308: | |
return 12.92 * c | |
else: | |
return (1 + a)*(c ** (1/2.4)) - a | |
def mix_srgb(x, y): | |
s = (sRGB_to_linear(x) + sRGB_to_linear(y))/2.0 | |
return linear_to_sRGB(s) | |
print mix_srgb(0, 248 / 255.0) * 255.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment