module Matter::Cluster::ColorControlUtils

Defined in:

matter/cluster/color_control_utils.cr

Constant Summary

KELVIN_TO_XY_LOOKUP = {1000 => {0.6528, 0.3444}, 1100 => {0.6388, 0.3562}, 1200 => {0.6250, 0.3675}, 1300 => {0.6116, 0.3779}, 1400 => {0.5985, 0.3878}, 1500 => {0.5857, 0.3972}, 1600 => {0.5732, 0.4062}, 1700 => {0.5611, 0.4147}, 1800 => {0.5494, 0.4228}, 1900 => {0.5381, 0.4305}, 2000 => {0.5271, 0.4378}, 2100 => {0.5164, 0.4448}, 2200 => {0.5061, 0.4514}, 2300 => {0.4961, 0.4577}, 2400 => {0.4864, 0.4637}, 2500 => {0.4770, 0.4694}, 2600 => {0.4678, 0.4749}, 2700 => {0.4590, 0.4800}, 2800 => {0.4503, 0.4849}, 2900 => {0.4420, 0.4895}, 3000 => {0.4338, 0.4939}, 3100 => {0.4259, 0.4981}, 3200 => {0.4182, 0.5020}, 3300 => {0.4107, 0.5057}, 3400 => {0.4034, 0.5092}, 3500 => {0.3962, 0.5126}, 3600 => {0.3893, 0.5157}, 3700 => {0.3825, 0.5187}, 3800 => {0.3759, 0.5215}, 3900 => {0.3694, 0.5242}, 4000 => {0.3631, 0.5267}, 4100 => {0.3569, 0.5291}, 4200 => {0.3509, 0.5313}, 4300 => {0.3450, 0.5335}, 4400 => {0.3392, 0.5355}, 4500 => {0.3335, 0.5374}, 4600 => {0.3280, 0.5392}, 4700 => {0.3225, 0.5409}, 4800 => {0.3172, 0.5425}, 4900 => {0.3119, 0.5440}, 5000 => {0.3068, 0.5454}, 5100 => {0.3017, 0.5468}, 5200 => {0.2968, 0.5480}, 5300 => {0.2919, 0.5492}, 5400 => {0.2871, 0.5503}, 5500 => {0.2824, 0.5514}, 5600 => {0.2778, 0.5523}, 5700 => {0.2732, 0.5533}, 5800 => {0.2688, 0.5541}, 5900 => {0.2644, 0.5549}, 6000 => {0.2600, 0.5557}, 6500 => {0.2422, 0.5584}, 7000 => {0.2268, 0.5601}, 7500 => {0.2135, 0.5610}, 8000 => {0.2021, 0.5614}, 8500 => {0.1922, 0.5613}, 9000 => {0.1834, 0.5609}, 9500 => {0.1756, 0.5603}, 10000 => {0.1686, 0.5594}, 15000 => {0.1249, 0.5456}, 20000 => {0.1033, 0.5329}, 25000 => {0.0899, 0.5230}, 30000 => {0.0807, 0.5156}, 35000 => {0.0740, 0.5099}, 40000 => {0.0687, 0.5054}}

Simplified Kelvin to XY lookup table (every 100K from 1000K to 40000K) From: https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/src/lib/kelvinToXy.ts

Class Method Summary

Class Method Detail

def self.hsv_to_rgb(hue : Float64, saturation : Float64, value : Float64 = 1.0) : Tuple(Float64, Float64, Float64) #

Converts HSV (Hue, Saturation, Value) to RGB Hue: 0-360 degrees Saturation: 0.0-1.0 Value: 0.0-1.0 (defaults to 1.0 for full brightness) Returns: [r, g, b] where each component is 0.0-1.0


[View source]
def self.mireds_to_xy(mireds : Float64) : Tuple(Float64, Float64) | Nil #

Converts color temperature (in Mireds) to XY coordinates Uses a simplified lookup table with linear interpolation mireds: Color temperature in Mireds (1,000,000 / Kelvin) Returns: [x, y] or nil if out of range


[View source]
def self.rgb_to_hsv(r : Float64, g : Float64, b : Float64) : Tuple(Float64, Float64, Float64) #

Converts RGB to HSV (Hue, Saturation, Value) R, G, B: 0.0-1.0 Returns: [hue (0-360), saturation (0.0-1.0), value (0.0-1.0)]


[View source]
def self.rgb_to_xy(r : Float64, g : Float64, b : Float64) : Tuple(Float64, Float64) #

Converts RGB to XY (CIE 1931 color space) R, G, B: 0.0-1.0 Returns: [x, y] where each coordinate is 0.0-1.0


[View source]
def self.xy_to_mireds(x : Float64, y : Float64) : Float64 #

Converts XY coordinates to color temperature (in Mireds) Uses McCamy's approximation x, y: CIE 1931 coordinates (0.0-1.0) Returns: Color temperature in Mireds


[View source]
def self.xy_to_rgb(x : Float64, y : Float64, brightness : Float64 = 254.0) : Tuple(Float64, Float64, Float64) #

Converts XY (CIE 1931 color space) to RGB X, Y: 0.0-1.0 (normalized coordinates) Brightness: 0.0-254.0 (defaults to 254.0 for maximum brightness) Returns: [r, g, b] where each component is 0.0-1.0


[View source]