File tree 2 files changed +12
-1
lines changed
2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -196,10 +196,18 @@ def calculateColorTemperature(rgb):
196
196
Y = (- 0.32466 * rgb ['r' ]) + (1.57837 * rgb ['g' ]) + (- 0.73191 * rgb ['b' ])
197
197
Z = (- 0.68202 * rgb ['r' ]) + (0.77073 * rgb ['g' ]) + ( 0.56332 * rgb ['b' ])
198
198
199
+ # Check for divide by 0 (total darkness) and return None.
200
+ if (x + y + z ) == 0 :
201
+ return None
202
+
199
203
# 2. Calculate the chromaticity co-ordinates
200
204
xc = (X ) / (X + Y + Z )
201
205
yc = (Y ) / (X + Y + Z )
202
206
207
+ # Check for divide by 0 again and return None.
208
+ if (0.1858 - yc ) == 0 :
209
+ return None
210
+
203
211
# 3. Use McCamy's formula to determine the CCT
204
212
n = (xc - 0.3320 ) / (0.1858 - yc )
205
213
Original file line number Diff line number Diff line change 16
16
colorTemp = tcs .calculateColorTemperature (rgb )
17
17
lux = tcs .calculateLux (rgb )
18
18
print rgb
19
- print "Color Temperature: %d K" % colorTemp
19
+ if colorTemp is None :
20
+ print 'Too dark to determine color temperature!'
21
+ else :
22
+ print "Color Temperature: %d K" % colorTemp
20
23
print "Luminosity: %d lux" % lux
21
24
tcs .setInterrupt (True )
22
25
sleep (1 )
You can’t perform that action at this time.
0 commit comments