155 |
|
|
156 |
Wr,Wg,Wb = 0.3, 0.59, 0.11 |
Wr,Wg,Wb = 0.3, 0.59, 0.11 |
157 |
|
|
158 |
|
# Gamma correction used with the perceptual non-linearity in YtoL and LtoY |
159 |
|
# conversion functions. |
160 |
|
# |
161 |
|
gamma = 2 |
162 |
|
# |
163 |
|
# Usually, the default display gamma of 1.0 actually yields an intensity |
164 |
|
# exponent of 0.5 so gamma correction of 2.0 here should result in linear |
165 |
|
# intensity. (The CIE L* computation assumes linear intensity). |
166 |
|
|
167 |
def YSTtoRGB(v): |
def YSTtoRGB(v): |
168 |
n = 1.0 / (Wr+Wg+Wb) |
n = 1.0 / (Wr+Wg+Wb) |
169 |
mat = [ [n, n*(Wg+Wb), n*(Wb - Wg) / math.sqrt(3) ], |
mat = [ [n, n*(Wg+Wb), n*(Wb - Wg) / math.sqrt(3) ], |
221 |
Y: luminance between 0 and 1 |
Y: luminance between 0 and 1 |
222 |
returns: lightness between 0 and 100 |
returns: lightness between 0 and 100 |
223 |
""" |
""" |
224 |
|
Y = Y**gamma |
225 |
if Y <= (216./24389): |
if Y <= (216./24389): |
226 |
return Y * (24389./27) |
return Y * (24389./27) |
227 |
else: |
else: |
234 |
returns: luminance between 0 and 1 |
returns: luminance between 0 and 1 |
235 |
""" |
""" |
236 |
if L <= 8: |
if L <= 8: |
237 |
return L * (27./24389) |
return pow(L * (27./24389), 1.0 / gamma) |
238 |
else: |
else: |
239 |
return pow((L + 16.0) / 116, 3) |
return pow((L + 16.0) / 116, 3.0 / gamma) |