|
|
@ -104,6 +104,10 @@ func (col *Color) ToRGB() (col2 Color, ok bool) { |
|
|
|
rgb := col.XY.ToRGB() |
|
|
|
col2 = Color{RGB: &rgb} |
|
|
|
ok = true |
|
|
|
} else if col.K != nil { |
|
|
|
rgb := kToRGB(*col.K) |
|
|
|
col2 = Color{RGB: &rgb} |
|
|
|
ok = true |
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
@ -122,6 +126,10 @@ func (col *Color) ToHS() (col2 Color, ok bool) { |
|
|
|
hs := col.XY.ToHS() |
|
|
|
col2 = Color{HS: &hs} |
|
|
|
ok = true |
|
|
|
} else if col.K != nil { |
|
|
|
hs := kToRGB(*col.K).ToHS() |
|
|
|
col2 = Color{HS: &hs} |
|
|
|
ok = true |
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
@ -174,6 +182,10 @@ func (col *Color) ToXY() (col2 Color, ok bool) { |
|
|
|
xy := col.RGB.ToXY() |
|
|
|
col2 = Color{XY: &xy} |
|
|
|
ok = true |
|
|
|
} else if col.K != nil { |
|
|
|
xy := kToRGB(*col.K).ToXY() |
|
|
|
col2 = Color{XY: &xy} |
|
|
|
ok = true |
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
@ -436,3 +448,140 @@ func hex2digit(h byte) int { |
|
|
|
return int(h - '0') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func kToRGB(kelvin int) RGB { |
|
|
|
if kelvin < 1000 { |
|
|
|
kelvin = 1000 |
|
|
|
} else if kelvin > 12000 { |
|
|
|
kelvin = 12000 |
|
|
|
} |
|
|
|
if kelvin%100 == 0 { |
|
|
|
return kelvinRGBTable[kelvin] |
|
|
|
} |
|
|
|
|
|
|
|
fac := float64(kelvin%100) / 100 |
|
|
|
floor := (kelvin / 100) * 100 |
|
|
|
ceil := floor + 100 |
|
|
|
floorRGB := kelvinRGBTable[floor] |
|
|
|
ceilRGB := kelvinRGBTable[ceil] |
|
|
|
|
|
|
|
return RGB{ |
|
|
|
Red: (floorRGB.Red * fac) + (ceilRGB.Red * (1 - fac)), |
|
|
|
Green: (floorRGB.Green * fac) + (ceilRGB.Green * (1 - fac)), |
|
|
|
Blue: (floorRGB.Blue * fac) + (ceilRGB.Blue * (1 - fac)), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var kelvinRGBTable = map[int]RGB{ |
|
|
|
1000: {Red: 1.000, Green: 0.220, Blue: 0.000}, |
|
|
|
1100: {Red: 1.000, Green: 0.278, Blue: 0.000}, |
|
|
|
1200: {Red: 1.000, Green: 0.325, Blue: 0.000}, |
|
|
|
1300: {Red: 1.000, Green: 0.365, Blue: 0.000}, |
|
|
|
1400: {Red: 1.000, Green: 0.396, Blue: 0.000}, |
|
|
|
1500: {Red: 1.000, Green: 0.427, Blue: 0.000}, |
|
|
|
1600: {Red: 1.000, Green: 0.451, Blue: 0.000}, |
|
|
|
1700: {Red: 1.000, Green: 0.475, Blue: 0.000}, |
|
|
|
1800: {Red: 1.000, Green: 0.494, Blue: 0.000}, |
|
|
|
1900: {Red: 1.000, Green: 0.514, Blue: 0.000}, |
|
|
|
2000: {Red: 1.000, Green: 0.541, Blue: 0.071}, |
|
|
|
2100: {Red: 1.000, Green: 0.557, Blue: 0.129}, |
|
|
|
2200: {Red: 1.000, Green: 0.576, Blue: 0.173}, |
|
|
|
2300: {Red: 1.000, Green: 0.596, Blue: 0.212}, |
|
|
|
2400: {Red: 1.000, Green: 0.616, Blue: 0.247}, |
|
|
|
2500: {Red: 1.000, Green: 0.631, Blue: 0.282}, |
|
|
|
2600: {Red: 1.000, Green: 0.647, Blue: 0.310}, |
|
|
|
2700: {Red: 1.000, Green: 0.663, Blue: 0.341}, |
|
|
|
2800: {Red: 1.000, Green: 0.678, Blue: 0.369}, |
|
|
|
2900: {Red: 1.000, Green: 0.694, Blue: 0.396}, |
|
|
|
3000: {Red: 1.000, Green: 0.706, Blue: 0.420}, |
|
|
|
3100: {Red: 1.000, Green: 0.722, Blue: 0.447}, |
|
|
|
3200: {Red: 1.000, Green: 0.733, Blue: 0.471}, |
|
|
|
3300: {Red: 1.000, Green: 0.745, Blue: 0.494}, |
|
|
|
3400: {Red: 1.000, Green: 0.757, Blue: 0.518}, |
|
|
|
3500: {Red: 1.000, Green: 0.769, Blue: 0.537}, |
|
|
|
3600: {Red: 1.000, Green: 0.780, Blue: 0.561}, |
|
|
|
3700: {Red: 1.000, Green: 0.788, Blue: 0.580}, |
|
|
|
3800: {Red: 1.000, Green: 0.800, Blue: 0.600}, |
|
|
|
3900: {Red: 1.000, Green: 0.808, Blue: 0.624}, |
|
|
|
4000: {Red: 1.000, Green: 0.820, Blue: 0.639}, |
|
|
|
4100: {Red: 1.000, Green: 0.827, Blue: 0.659}, |
|
|
|
4200: {Red: 1.000, Green: 0.835, Blue: 0.678}, |
|
|
|
4300: {Red: 1.000, Green: 0.843, Blue: 0.694}, |
|
|
|
4400: {Red: 1.000, Green: 0.851, Blue: 0.714}, |
|
|
|
4500: {Red: 1.000, Green: 0.859, Blue: 0.729}, |
|
|
|
4600: {Red: 1.000, Green: 0.867, Blue: 0.745}, |
|
|
|
4700: {Red: 1.000, Green: 0.875, Blue: 0.761}, |
|
|
|
4800: {Red: 1.000, Green: 0.882, Blue: 0.776}, |
|
|
|
4900: {Red: 1.000, Green: 0.890, Blue: 0.792}, |
|
|
|
5000: {Red: 1.000, Green: 0.894, Blue: 0.808}, |
|
|
|
5100: {Red: 1.000, Green: 0.902, Blue: 0.824}, |
|
|
|
5200: {Red: 1.000, Green: 0.910, Blue: 0.835}, |
|
|
|
5300: {Red: 1.000, Green: 0.914, Blue: 0.851}, |
|
|
|
5400: {Red: 1.000, Green: 0.922, Blue: 0.863}, |
|
|
|
5500: {Red: 1.000, Green: 0.925, Blue: 0.878}, |
|
|
|
5600: {Red: 1.000, Green: 0.933, Blue: 0.890}, |
|
|
|
5700: {Red: 1.000, Green: 0.937, Blue: 0.902}, |
|
|
|
5800: {Red: 1.000, Green: 0.941, Blue: 0.914}, |
|
|
|
5900: {Red: 1.000, Green: 0.949, Blue: 0.925}, |
|
|
|
6000: {Red: 1.000, Green: 0.953, Blue: 0.937}, |
|
|
|
6100: {Red: 1.000, Green: 0.957, Blue: 0.949}, |
|
|
|
6200: {Red: 1.000, Green: 0.961, Blue: 0.961}, |
|
|
|
6300: {Red: 1.000, Green: 0.965, Blue: 0.969}, |
|
|
|
6400: {Red: 1.000, Green: 0.973, Blue: 0.984}, |
|
|
|
6500: {Red: 1.000, Green: 0.976, Blue: 0.992}, |
|
|
|
6600: {Red: 0.996, Green: 0.976, Blue: 1.000}, |
|
|
|
6700: {Red: 0.988, Green: 0.969, Blue: 1.000}, |
|
|
|
6800: {Red: 0.976, Green: 0.965, Blue: 1.000}, |
|
|
|
6900: {Red: 0.969, Green: 0.961, Blue: 1.000}, |
|
|
|
7000: {Red: 0.961, Green: 0.953, Blue: 1.000}, |
|
|
|
7100: {Red: 0.953, Green: 0.949, Blue: 1.000}, |
|
|
|
7200: {Red: 0.941, Green: 0.945, Blue: 1.000}, |
|
|
|
7300: {Red: 0.937, Green: 0.941, Blue: 1.000}, |
|
|
|
7400: {Red: 0.929, Green: 0.937, Blue: 1.000}, |
|
|
|
7500: {Red: 0.922, Green: 0.933, Blue: 1.000}, |
|
|
|
7600: {Red: 0.914, Green: 0.929, Blue: 1.000}, |
|
|
|
7700: {Red: 0.906, Green: 0.925, Blue: 1.000}, |
|
|
|
7800: {Red: 0.902, Green: 0.922, Blue: 1.000}, |
|
|
|
7900: {Red: 0.894, Green: 0.918, Blue: 1.000}, |
|
|
|
8000: {Red: 0.890, Green: 0.914, Blue: 1.000}, |
|
|
|
8100: {Red: 0.882, Green: 0.910, Blue: 1.000}, |
|
|
|
8200: {Red: 0.878, Green: 0.906, Blue: 1.000}, |
|
|
|
8300: {Red: 0.871, Green: 0.902, Blue: 1.000}, |
|
|
|
8400: {Red: 0.867, Green: 0.902, Blue: 1.000}, |
|
|
|
8500: {Red: 0.863, Green: 0.898, Blue: 1.000}, |
|
|
|
8600: {Red: 0.855, Green: 0.898, Blue: 1.000}, |
|
|
|
8700: {Red: 0.851, Green: 0.890, Blue: 1.000}, |
|
|
|
8800: {Red: 0.847, Green: 0.890, Blue: 1.000}, |
|
|
|
8900: {Red: 0.843, Green: 0.886, Blue: 1.000}, |
|
|
|
9000: {Red: 0.839, Green: 0.882, Blue: 1.000}, |
|
|
|
9100: {Red: 0.831, Green: 0.882, Blue: 1.000}, |
|
|
|
9200: {Red: 0.827, Green: 0.878, Blue: 1.000}, |
|
|
|
9300: {Red: 0.824, Green: 0.875, Blue: 1.000}, |
|
|
|
9400: {Red: 0.820, Green: 0.875, Blue: 1.000}, |
|
|
|
9500: {Red: 0.816, Green: 0.871, Blue: 1.000}, |
|
|
|
9600: {Red: 0.812, Green: 0.867, Blue: 1.000}, |
|
|
|
9700: {Red: 0.812, Green: 0.867, Blue: 1.000}, |
|
|
|
9800: {Red: 0.808, Green: 0.863, Blue: 1.000}, |
|
|
|
9900: {Red: 0.804, Green: 0.863, Blue: 1.000}, |
|
|
|
10000: {Red: 0.812, Green: 0.855, Blue: 1.000}, |
|
|
|
10100: {Red: 0.812, Green: 0.855, Blue: 1.000}, |
|
|
|
10200: {Red: 0.808, Green: 0.851, Blue: 1.000}, |
|
|
|
10300: {Red: 0.804, Green: 0.851, Blue: 1.000}, |
|
|
|
10400: {Red: 0.800, Green: 0.847, Blue: 1.000}, |
|
|
|
10500: {Red: 0.800, Green: 0.847, Blue: 1.000}, |
|
|
|
10600: {Red: 0.796, Green: 0.843, Blue: 1.000}, |
|
|
|
10700: {Red: 0.792, Green: 0.843, Blue: 1.000}, |
|
|
|
10800: {Red: 0.792, Green: 0.839, Blue: 1.000}, |
|
|
|
10900: {Red: 0.788, Green: 0.839, Blue: 1.000}, |
|
|
|
11000: {Red: 0.784, Green: 0.835, Blue: 1.000}, |
|
|
|
11100: {Red: 0.784, Green: 0.835, Blue: 1.000}, |
|
|
|
11200: {Red: 0.780, Green: 0.831, Blue: 1.000}, |
|
|
|
11300: {Red: 0.776, Green: 0.831, Blue: 1.000}, |
|
|
|
11400: {Red: 0.776, Green: 0.831, Blue: 1.000}, |
|
|
|
11500: {Red: 0.773, Green: 0.827, Blue: 1.000}, |
|
|
|
11600: {Red: 0.773, Green: 0.827, Blue: 1.000}, |
|
|
|
11700: {Red: 0.773, Green: 0.824, Blue: 1.000}, |
|
|
|
11800: {Red: 0.769, Green: 0.824, Blue: 1.000}, |
|
|
|
11900: {Red: 0.765, Green: 0.824, Blue: 1.000}, |
|
|
|
12000: {Red: 0.765, Green: 0.820, Blue: 1.000}, |
|
|
|
} |