117 |
|
|
118 |
|
|
119 |
# The YST color space below is a linear color space with |
# The YST color space below is a linear color space with |
120 |
# a lightness component and a color plane vector whose angle and |
# a luminance component and a color plane vector whose angle and |
121 |
# radius specify the hue and saturation, respectively. |
# radius specify the hue and saturation, respectively. |
122 |
# Opposite colors are 180 degrees apart. |
# Opposite colors are 180 degrees apart. |
123 |
# |
# |
124 |
# The Y component is the CIE Y lightness (but the weights can be changed) and |
# The Y component is the CIE Y luminance (but the weights can be changed) and |
125 |
# the ST-plane has the RGB primaries 120 (R = 0, G = 120, B = 240) degrees apart |
# the ST-plane has the RGB primaries 120 (R = 0, G = 120, B = 240) degrees apart |
126 |
# at radius 1. |
# at radius 1. |
127 |
# |
# |
128 |
# Lightness weights of the RGB primaries used in YST color space functions |
# Luminance weights of the RGB primaries used in YST color space functions |
129 |
Wr = 0.212671 |
Wr = 0.212671 |
130 |
Wg = 0.715160 |
Wg = 0.715160 |
131 |
Wb = 0.072169 |
Wb = 0.072169 |
186 |
def YtoL(Y): |
def YtoL(Y): |
187 |
""" |
""" |
188 |
Convert linear luminance into perceptual lightness (CIE L*) |
Convert linear luminance into perceptual lightness (CIE L*) |
189 |
Y: lightness between 0 and 1 |
Y: luminance between 0 and 1 |
190 |
returns: luminance between 0 and 100 |
returns: lightness between 0 and 100 |
191 |
""" |
""" |
192 |
if Y <= (216./24389): |
if Y <= (216./24389): |
193 |
return Y * (24389./27) |
return Y * (24389./27) |
197 |
def LtoY(L): |
def LtoY(L): |
198 |
""" |
""" |
199 |
Convert perceptual lightness (CIE L*) into linear luminance |
Convert perceptual lightness (CIE L*) into linear luminance |
200 |
L: luminance between 0 and 100 |
L: lightness between 0 and 100 |
201 |
returns: lightness between 0 and 1 |
returns: luminance between 0 and 1 |
202 |
""" |
""" |
203 |
if L <= 8: |
if L <= 8: |
204 |
return L * (27./24389) |
return L * (27./24389) |