summaryrefslogtreecommitdiffstats
path: root/src/curve.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-02-16 19:53:06 +0100
committerMattias Andrée <maandree@operamail.com>2014-02-16 19:53:06 +0100
commit06f7f1f9f25cbf6ca947f3bb6a6ed4fd7b7e3c4d (patch)
tree5a00eb582f0d41fd72b97c3b7c79d08f43c59081 /src/curve.py
parentm todo (diff)
downloadblueshift-06f7f1f9f25cbf6ca947f3bb6a6ed4fd7b7e3c4d.tar.gz
blueshift-06f7f1f9f25cbf6ca947f3bb6a6ed4fd7b7e3c4d.tar.bz2
blueshift-06f7f1f9f25cbf6ca947f3bb6a6ed4fd7b7e3c4d.tar.xz
working with some exceptions
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/curve.py')
-rw-r--r--src/curve.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/curve.py b/src/curve.py
index 34adf29..9721da8 100644
--- a/src/curve.py
+++ b/src/curve.py
@@ -101,23 +101,25 @@ def cmf_2deg(temperature):
@param temperature:float The blackbody temperature in kelvins, clipped to [1000, 40000]
@return :(float, float, float) The red, green and blue components of the white point
'''
+ global cmf_2deg_cache
if cmf_2deg_cache is None:
with open(DATADIR + '/2deg', 'rb') as file:
cmf_2deg_cache = file.read()
- cmf_2deg_cache.decode('utf-8', 'error').split('\n')
+ cmf_2deg_cache = cmf_2deg_cache.decode('utf-8', 'error').split('\n')
+ cmf_2deg_cache = filter(lambda x : not x == '', cmf_2deg_cache)
cmf_2deg_cache = [[float(x) for x in x_y.split(' ')] for x_y in cmf_2deg_cache]
- temperature = min(max(0, temperature), 1000)
+ temp = min(max(1000, temperature), 40000)
x, y = 0, 0
if (temp % 100) == 0:
- (x, y) = temperature[(temp - 1000) // 100]
+ (x, y) = cmf_2deg_cache[(temp - 1000) // 100]
else:
temp -= 1000
- (x1, y1) = temperature[temp // 100]
- (x2, y2) = temperature[temp // 100 + 1]
+ (x1, y1) = cmf_2deg_cache[temp // 100]
+ (x2, y2) = cmf_2deg_cache[temp // 100 + 1]
temp = (temp % 100) / 100
x = x1 * temp + x2 * (1 - temp)
y = y1 * temp + y2 * (1 - temp)
- return ciexy_to_srgb(x, y, 1.0)
+ return ciexyy_to_srgb(x, y, 1.0)
cmf_10deg_cache = None
@@ -128,23 +130,25 @@ def cmf_10deg(temperature):
@param temperature:float The blackbody temperature in kelvins, clipped to [1000, 40000]
@return :(float, float, float) The red, green and blue components of the white point
'''
+ global cmf_10deg_cache
if cmf_10deg_cache is None:
with open(DATADIR + '/10deg', 'rb') as file:
cmf_10deg_cache = file.read()
- cmf_10deg_cache.decode('utf-8', 'error').split('\n')
+ cmf_10deg_cache = cmf_10deg_cache.decode('utf-8', 'error').split('\n')
+ cmf_10deg_cache = filter(lambda x : not x == '', cmf_10deg_cache)
cmf_10deg_cache = [[float(x) for x in x_y.split(' ')] for x_y in cmf_10deg_cache]
- temperature = min(max(0, temperature), 1000)
+ temp = min(max(1000, temperature), 40000)
x, y = 0, 0
if (temp % 100) == 0:
- (x, y) = temperature[(temp - 1000) // 100]
+ (x, y) = cmf_10deg_cache[(temp - 1000) // 100]
else:
temp -= 1000
- (x1, y1) = temperature[temp // 100]
- (x2, y2) = temperature[temp // 100 + 1]
+ (x1, y1) = cmf_10deg_cache[temp // 100]
+ (x2, y2) = cmf_10deg_cache[temp // 100 + 1]
temp = (temp % 100) / 100
x = x1 * temp + x2 * (1 - temp)
y = y1 * temp + y2 * (1 - temp)
- return ciexy_to_srgb(x, y, 1.0)
+ return ciexyy_to_srgb(x, y, 1.0)