temperature icon indicating copy to clipboard operation
temperature copied to clipboard

Converts between color temperature in Kelvin and in RGB (Golang)

temperature

package temperature implements an algorithm to calculate the channel intensity for a color temperature.

GoDoc

Explanation

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.

History

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.

Performance

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

License is MIT.