-
-
Notifications
You must be signed in to change notification settings - Fork 264
FAQ #4
There is a HslColor object that will automatically convert to any of the other color object by just assigning them. The color objects are RgbColor, RgbwColor, HslColor, HsbColor, and HtmlColor.
HslColor myColor(0.244f, 1.0f, 0.5f);
RgbColor rgbOfMyColor = myColor;
Further, all the color objects can be used by the SetPixelColor().
HslColor myColor(0.244f, 1.0f, 0.5f);
strip.SetPixelColor(0, myColor);
The only limitation is that the RgbwColor can not be used directly with a NeoPixelBus defined with a 3 element feature like NeoRgbFeature or NeoGrbFeature. This is due to the loss of color that could happen. So the following will create a compile error.
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(2,2);
...
RgbwColor myColor(124, 64, 124, 10);
strip.SetPixelColor(0, myColor); // compiler error
The issue is what does it mean to convert RGBW value to just RGB? How is the white handled in the conversion? There is no standard to how this should be done so it is left up to you for your application.
You could just ignore the white like below.
RgbwColor myColor(124, 64, 124, 10);
RgbColor myRgbColor(myColor.R, myColor.G, myColor.B); // converted ignore the white
Or you could blend the white in as demonstrated by this simple example.
RgbwColor myColor(124, 64, 124, 10);
RgbColor myRgbColor(myColor.R + myColor.W, myColor.G + myColor.W, myColor.B + myColor.W); // blend in white