package temperature implements an algorithm to calculate the channel intensity for a color temperature.
- It is a modified reimplementation of
color-temperature.js by
Neil Bartlett (blog) in Go.
- It is optimized to reduce the number of conditions and do the conditions in integers instead of on floats.
- Add the 6500 whitepoint, which was missing (!)
- ... which itself is a modified reimplementation of Tanner Helland's implementation in Visual Basic.
- ... which itself is based on Mitchell Charity’s raw black body color
table.
- this table uses D65. sRGB specification uses D65 but assumes D50 external environment.
- 15 years later, Mitchell Charity changed his mind and now
recommends to use D58
instead of D65.
- He created a new D58 table.
- Original blog post.
Color Temperature is the color due to black body radiation at a given temperature. The temperature is given in Kelvin. The concept is widely used in photography and in tools such as f.lux.
The function here converts a given color temperature into a near equivalent in the RGB colorspace. The function is based on a curve fit on standard sparse set of Kelvin to RGB mappings with a whitepoint (255, 255, 255) at 6500K.
NOTE The approximations used are suitable for photo-manipulation and other non-critical uses. They are not suitable for medical or other high accuracy use cases.
Accuracy is best between 1000K and 30000K.
This project has been implemented specifically for the use case of APA-102 LEDs, driven by a Raspberry Pi, which are very cold by default. Then he reimplemented it in C++ with integer only arithmetic to run on a ESP8266.
Benchmark run on a Intel i7-5600U:
BenchmarkToRGBUsingTH1500-4 30000000 42.8 ns/op
BenchmarkToRGBUsingTH2500-4 30000000 56.8 ns/op
BenchmarkToRGBUsingTH6500-4 1000000000 2.35 ns/op
BenchmarkToRGBUsingTH7000-4 10000000 195 ns/op
BenchmarkToRGB1500-4 30000000 43.8 ns/op
BenchmarkToRGB2500-4 30000000 57.5 ns/op
BenchmarkToRGB6500-4 1000000000 2.34 ns/op
BenchmarkToRGB7000-4 30000000 57.8 ns/op
License is MIT.