Skip to content

Instantly share code, notes, and snippets.

@dobrokot
Created January 24, 2016 16:07
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 dobrokot/7c86c6c03d6e7d289143 to your computer and use it in GitHub Desktop.
Save dobrokot/7c86c6c03d6e7d289143 to your computer and use it in GitHub Desktop.
test color mixing in sRGB
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