From 991fa9e6781d51642090913a4f213b7fe643896d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 5 Apr 2014 16:50:36 +0200 Subject: m + add support for naming (as a string) a colour temperature constant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blackbody.py | 34 ++++++++++++++++++++++++++++++++-- src/curve.py | 10 +++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/blackbody.py b/src/blackbody.py index 6e2702a..5df7a79 100644 --- a/src/blackbody.py +++ b/src/blackbody.py @@ -38,15 +38,18 @@ K_MATCH_FLAME = 1700 K_CANDLE_FLAME = 1850 K_CANDLELIGHT = K_CANDLE_FLAME K_SUNSET = 1850 -K_SUNRISE = SUNSET +K_SUNRISE = K_SUNSET K_F_LUX_W32_CANDLE = 1900 K_HIGH_PRESSURE_SODIUM = 2100 K_F_LUX_MAC_CANDLE = 2300 K_F_LUX_W32_WARM_INCANDESCENT = 2300 K_STANDARD_INCANDESCENT = 2500 -K_INCANDESCENT = STANDARD_INCANDESCENT +K_INCANDESCENT = K_STANDARD_INCANDESCENT K_F_LUX_MAC_TUNGSTEN = 2700 K_F_LUX_W32_INCANDESCENT = 2700 +K_EXTRA_SOFT = 2700 +K_PIANO_PIANO_LUX = K_EXTRA_SOFT +K_PIANO_PIANO = K_PIANO_PIANO_LUX K_INCANDESCENT_LAMP = (2700 + 3300) / 2 K_EARLY_SUNRISE = (2800 + 3200) / 2 K_LATE_SUNSUN = K_EARLY_SUNRISE @@ -64,6 +67,7 @@ K_F_LUX_MAC_HALOGEN = 3400 K_F_LUX_W32_HALOGEN = 3400 K_SOFT = 3700 K_PIANO_LUX = K_SOFT +K_PIANO = K_PIANO_LUX K_MOONLIGHT = (4100 + 4150) / 2 K_COOL_WHITE = 4200 K_F_LUX_MAC_FLOURESCENT = 4200 @@ -81,6 +85,9 @@ K_DAYLIGHT_WHITE_COMPACT_FLUORESCENT_LAMPS = K_COOL_WHITE_COMPACT_FLUORESCENT_LA K_F_LUX_MAC_DAYLIGHT = 5000 K_D55 = 5500 K_F_LUX_W32_DAYLIGHT = 5500 +K_MODERATELY_SOFT = 5500 +K_MEZZO_PIANO_LUX = K_MODERATELY_SOFT +K_MEZZO_PIANO = K_MEZZO_PIANO_LUX K_CRYSTAL_VERTICAL = 5600 K_CLEAR_MID_DAY = 5600 K_VERTICAL_DAYLIGHT = (5500 + 6000) / 2 @@ -92,11 +99,16 @@ K_D65 = 6500 K_NEUTRAL = K_D65 K_WHITE = K_NEUTRAL K_MEZZO_LUX = K_NEUTRAL +K_MEZZO = K_MEZZO_LUX K_SHARP = 7000 K_FORTE_LUX = K_SHARP +K_FORTE = K_FORTE_LUX K_D75 = 7500 K_BLUE_FILTER = 8000 K_NORTH_LIGHT = 10000 +K_EXTRA_SHARP = 10000 +K_FORTE_FORTE_LUX = K_EXTRA_SHARP +K_FORTE_FORTE = K_FORTE_FORTE_LUX K_BLUE_SKY = K_NORTH_LIGHT K_SKYLIGHT = (9000 + 15000) / 2 K_OUTDOOR_SHADE = K_SKYLIGHT @@ -298,3 +310,21 @@ def clip_whitepoint(rgb): ''' return [min(max(0, x), 1) for x in rgb] + +def kelvins(temperature): # TODO demo and document this + ''' + Resolve and colour temperature name + + @param temperature:float|str The colour temperature + @return :float The colour temperature + ''' + # If float (or something we do not allow) return the input + if not isinstance(temperature, str): + return temperature + # Replace punctuation with underscore + temperature = temperature.replace('.', '_').replace('-', '_').replace(' ', '_') + # Add prefix and turn into upper case + temperature = 'K_' + temperature.upper() + # Evaluate (that is, return the named variable) + return eval(temperature) + diff --git a/src/curve.py b/src/curve.py index 7efb26e..24e7330 100644 --- a/src/curve.py +++ b/src/curve.py @@ -59,7 +59,7 @@ def temperature(temperature, algorithm): ''' Change colour temperature according to the CIE illuminant series D using CIE sRBG - @param temperature:float The blackbody temperature in kelvins + @param temperature:float|str The blackbody temperature in kelvins, or a name @param algorithm:(float)→(float, float, float) Algorithm for calculating a white point, for example `cmf_10deg` ''' rgb_temperature(temperature, algorithm) @@ -69,9 +69,11 @@ def rgb_temperature(temperature, algorithm): ''' Change colour temperature according to the CIE illuminant series D using CIE sRBG - @param temperature:float The blackbody temperature in kelvins + @param temperature:float|str The blackbody temperature in kelvins, or a name @param algorithm:(float)→(float, float, float) Algorithm for calculating a white point, for example `cmf_10deg` ''' + # Resolve colour temperature name + temperature = kelvins(temperature) # TODO demo and document this and add to textconf and lisp-esque # Do nothing if the temperature is neutral if temperature == 6500: return # Otherwise manipulate the colour curves @@ -82,9 +84,11 @@ def cie_temperature(temperature, algorithm): ''' Change colour temperature according to the CIE illuminant series D using CIE xyY - @param temperature:float The blackbody temperature in kelvins + @param temperature:float|str The blackbody temperature in kelvins, or a name @param algorithm:(float)→(float, float, float) Algorithm for calculating a white point, for example `cmf_10deg` ''' + # Resolve colour temperature name + temperature = kelvins(temperature) # Do nothing if the temperature is neutral if temperature == 6500: return # Otherwise manipulate the colour curves -- cgit v1.2.3-70-g09d2