Compare commits

...

14 Commits
2.7.6 ... fixes

32 changed files with 862 additions and 2276 deletions

9
CMakeLists.txt Normal file
View File

@ -0,0 +1,9 @@
idf_component_register(
SRCS
src/internal/Esp32_i2s.c
src/internal/NeoEsp32RmtMethod.cpp
INCLUDE_DIRS
src
REQUIRES
driver
)

View File

@ -28,11 +28,18 @@ License along with NeoPixel. If not, see
#include "NeoPixelBus.h"
class NeoPixelBrightnessBusInterface
{
public:
virtual ~NeoPixelBrightnessBusInterface() = default;
virtual void SetBrightness(uint8_t brightness) = 0;
};
template<typename T_COLOR_FEATURE, typename T_METHOD> class NeoPixelBrightnessBus :
public NeoPixelBus<T_COLOR_FEATURE, T_METHOD>
public NeoPixelBus<T_COLOR_FEATURE, T_METHOD>, public NeoPixelBrightnessBusInterface
{
private:
void ScaleColor(uint16_t scale, typename T_COLOR_FEATURE::ColorObject* color)
{
uint8_t* ptr = (uint8_t*)color;
@ -83,7 +90,7 @@ public:
{
}
void SetBrightness(uint8_t brightness)
void SetBrightness(uint8_t brightness) override
{
// Only update if there is a change
if (brightness != _brightness)
@ -109,13 +116,13 @@ public:
return _brightness;
}
void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color)
void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color) override
{
ConvertColor(&color);
NeoPixelBus<T_COLOR_FEATURE, T_METHOD>::SetPixelColor(indexPixel, color);
}
typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const
typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const override
{
typename T_COLOR_FEATURE::ColorObject color = NeoPixelBus<T_COLOR_FEATURE, T_METHOD>::GetPixelColor(indexPixel);
RecoverColor(&color);

View File

@ -25,8 +25,6 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
#include <Arduino.h>
// some platforms do not come with STL or properly defined one, specifically functional
// if you see...
// undefined reference to `std::__throw_bad_function_call()'
@ -53,7 +51,6 @@ License along with NeoPixel. If not, see
#include "internal/RgbColor.h"
#include "internal/HslColor.h"
#include "internal/HsbColor.h"
#include "internal/HtmlColor.h"
#include "internal/RgbwColor.h"
#include "internal/SegmentDigit.h"
@ -113,10 +110,20 @@ License along with NeoPixel. If not, see
#error "Platform Currently Not Supported, please add an Issue at Github/Makuna/NeoPixelBus"
#endif
template<typename T_COLOR_FEATURE>
class NeoPixelBusInterface
{
public:
virtual ~NeoPixelBusInterface() = default;
virtual void Begin() = 0;
virtual void Show(bool maintainBufferConsistency = true) = 0;
virtual bool CanShow() const = 0;
virtual void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color) = 0;
virtual typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const = 0;
};
template<typename T_COLOR_FEATURE, typename T_METHOD> class NeoPixelBus
template<typename T_COLOR_FEATURE, typename T_METHOD> class NeoPixelBus : public NeoPixelBusInterface<T_COLOR_FEATURE>
{
public:
// Constructor: number of LEDs, pin number
@ -143,9 +150,7 @@ public:
{
}
~NeoPixelBus()
{
}
~NeoPixelBus() override = default;
operator NeoBufferContext<T_COLOR_FEATURE>()
{
@ -153,7 +158,7 @@ public:
return NeoBufferContext<T_COLOR_FEATURE>(_pixels(), PixelsSize());
}
void Begin()
void Begin() override
{
_method.Initialize();
Dirty();
@ -166,7 +171,7 @@ public:
Dirty();
}
void Show(bool maintainBufferConsistency = true)
void Show(bool maintainBufferConsistency = true) override
{
if (!IsDirty())
{
@ -178,7 +183,7 @@ public:
ResetDirty();
}
inline bool CanShow() const
inline bool CanShow() const override
{
return _method.IsReadyToUpdate();
};
@ -218,7 +223,7 @@ public:
return _countPixels;
};
void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color)
void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color) override
{
if (indexPixel < _countPixels)
{
@ -227,7 +232,7 @@ public:
}
};
typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const
typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const override
{
if (indexPixel < _countPixels)
{

View File

@ -56,7 +56,7 @@ public:
}
void SetString(uint16_t indexDigit,
const String& str,
const std::string& str,
uint8_t brightness,
uint8_t defaultBrightness = 0)
{

View File

@ -64,19 +64,6 @@ public:
}
}
static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count)
{
uint8_t* pEnd = pPixelDest + (count * PixelSize);
const uint8_t* pSrc = (const uint8_t*)pPixelSrc;
while (pPixelDest < pEnd)
{
*pPixelDest++ = pgm_read_byte(pSrc++);
*pPixelDest++ = pgm_read_byte(pSrc++);
*pPixelDest++ = pgm_read_byte(pSrc++);
*pPixelDest++ = pgm_read_byte(pSrc++);
}
}
static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
{
uint8_t* pDestBack = pPixelDest + (count * PixelSize);
@ -131,19 +118,6 @@ public:
}
}
static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count)
{
uint8_t* pEnd = pPixelDest + (count * PixelSize);
const uint8_t* pSrc = (const uint8_t*)pPixelSrc;
while (pPixelDest < pEnd)
{
*pPixelDest++ = pgm_read_byte(pSrc++);
*pPixelDest++ = pgm_read_byte(pSrc++);
*pPixelDest++ = pgm_read_byte(pSrc++);
*pPixelDest++ = pgm_read_byte(pSrc++);
}
}
static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
{
uint8_t* pDestBack = pPixelDest + (count * PixelSize);
@ -228,20 +202,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
pgm_read_byte(p++); // ignore the first byte
color.B = pgm_read_byte(p++);
color.G = pgm_read_byte(p++);
color.R = pgm_read_byte(p);
return color;
}
};
class DotStarLbgrFeature : public DotStar4ElementsNoSettings
@ -269,20 +229,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits
color.B = pgm_read_byte(p++);
color.G = pgm_read_byte(p++);
color.R = pgm_read_byte(p);
return color;
}
};
class DotStarGrbFeature : public DotStar3ElementsNoSettings
@ -310,20 +256,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
pgm_read_byte(p++); // ignore the first byte
color.G = pgm_read_byte(p++);
color.R = pgm_read_byte(p++);
color.B = pgm_read_byte(p);
return color;
}
};
class DotStarLgrbFeature : public DotStar4ElementsNoSettings
@ -351,20 +283,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits
color.G = pgm_read_byte(p++);
color.R = pgm_read_byte(p++);
color.B = pgm_read_byte(p);
return color;
}
};
/* RGB Feature -- Some APA102s ship in RGB order */
@ -393,20 +311,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
pgm_read_byte(p++); // ignore the first byte
color.R = pgm_read_byte(p++);
color.G = pgm_read_byte(p++);
color.B = pgm_read_byte(p);
return color;
}
};
class DotStarLrgbFeature : public DotStar4ElementsNoSettings
@ -434,20 +338,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits
color.R = pgm_read_byte(p++);
color.G = pgm_read_byte(p++);
color.B = pgm_read_byte(p);
return color;
}
};
/* RBG Feature -- Some APA102s ship in RBG order */
class DotStarRbgFeature : public DotStar3ElementsNoSettings
@ -475,20 +365,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
pgm_read_byte(p++); // ignore the first byte
color.R = pgm_read_byte(p++);
color.B = pgm_read_byte(p++);
color.G = pgm_read_byte(p);
return color;
}
};
class DotStarLrbgFeature : public DotStar4ElementsNoSettings
@ -516,20 +392,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits
color.R = pgm_read_byte(p++);
color.B = pgm_read_byte(p++);
color.G = pgm_read_byte(p);
return color;
}
};
/* GBR Feature -- Some APA102s ship in GBR order */
@ -558,20 +420,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
pgm_read_byte(p++); // ignore the first byte
color.G = pgm_read_byte(p++);
color.B = pgm_read_byte(p++);
color.R = pgm_read_byte(p);
return color;
}
};
class DotStarLgbrFeature : public DotStar4ElementsNoSettings
@ -599,20 +447,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits
color.G = pgm_read_byte(p++);
color.B = pgm_read_byte(p++);
color.R = pgm_read_byte(p);
return color;
}
};
/* BRG Feature -- Some APA102s ship in BRG order */
class DotStarBrgFeature : public DotStar3ElementsNoSettings
@ -640,20 +474,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
pgm_read_byte(p++); // ignore the first byte
color.B = pgm_read_byte(p++);
color.R = pgm_read_byte(p++);
color.G = pgm_read_byte(p);
return color;
}
};
class DotStarLbrgFeature : public DotStar4ElementsNoSettings
@ -681,18 +501,4 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits
color.B = pgm_read_byte(p++);
color.R = pgm_read_byte(p++);
color.G = pgm_read_byte(p);
return color;
}
};

View File

@ -122,7 +122,7 @@ private:
typedef DotStarMethodBase<TwoWireBitBangImple> DotStarMethod;
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) && !defined(ESP32)
#include "TwoWireSpiImple.h"
typedef DotStarMethodBase<TwoWireSpiImple<SpiSpeed40Mhz>> DotStarSpi40MhzMethod;
typedef DotStarMethodBase<TwoWireSpiImple<SpiSpeed20Mhz>> DotStarSpi20MhzMethod;

View File

@ -45,8 +45,9 @@
#include "driver/dac.h"
#include "Esp32_i2s.h"
#include "esp32-hal.h"
#include "esp32-hal-log.h"
#if ESP_IDF_VERSION_MAJOR<4
#if ESP_IDF_VERSION_MAJOR<=4
#define I2S_BASE_CLK (160000000L)
#endif

View File

@ -1,68 +0,0 @@
/*-------------------------------------------------------------------------
HsbColor provides a color object that can be directly consumed by NeoPixelBus
Written by Michael C. Miller.
I invest time and resources providing this open source code,
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
-------------------------------------------------------------------------
This file is part of the Makuna/NeoPixelBus library.
NeoPixelBus is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
NeoPixelBus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with NeoPixel. If not, see
<http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------*/
#include "RgbColor.h"
#include "HsbColor.h"
HsbColor::HsbColor(const RgbColor& color)
{
// convert colors to float between (0.0 - 1.0)
float r = color.R / 255.0f;
float g = color.G / 255.0f;
float b = color.B / 255.0f;
float max = (r > g && r > b) ? r : (g > b) ? g : b;
float min = (r < g && r < b) ? r : (g < b) ? g : b;
float d = max - min;
float h = 0.0;
float v = max;
float s = (v == 0.0f) ? 0 : (d / v);
if (d != 0.0f)
{
if (r == max)
{
h = (g - b) / d + (g < b ? 6.0f : 0.0f);
}
else if (g == max)
{
h = (b - r) / d + 2.0f;
}
else
{
h = (r - g) / d + 4.0f;
}
h /= 6.0f;
}
H = h;
S = s;
B = v;
}

View File

@ -1,4 +1,3 @@
/*-------------------------------------------------------------------------
HsbColor provides a color object that can be directly consumed by NeoPixelBus
@ -26,35 +25,34 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
#include <Arduino.h>
struct RgbColor;
// ------------------------------------------------------------------------
// HsbColor represents a color object that is represented by Hue, Saturation, Brightness
// component values. It contains helpful color routines to manipulate the
// component values. It contains helpful color routines to manipulate the
// color.
// ------------------------------------------------------------------------
struct HsbColor
{
// ------------------------------------------------------------------------
// Construct a HsbColor that will have its values set in latter operations
// ------------------------------------------------------------------------
constexpr HsbColor();
// ------------------------------------------------------------------------
// Construct a HsbColor using H, S, B values (0.0 - 1.0)
// ------------------------------------------------------------------------
HsbColor(float h, float s, float b) :
H(h), S(s), B(b)
{
};
constexpr HsbColor(float h, float s, float b);
// ------------------------------------------------------------------------
// Construct a HsbColor using HsbColor
// ------------------------------------------------------------------------
constexpr HsbColor(const HsbColor& color);
// ------------------------------------------------------------------------
// Construct a HsbColor using RgbColor
// ------------------------------------------------------------------------
HsbColor(const RgbColor& color);
// ------------------------------------------------------------------------
// Construct a HsbColor that will have its values set in latter operations
// CAUTION: The H,S,B members are not initialized and may not be consistent
// ------------------------------------------------------------------------
HsbColor()
{
};
constexpr HsbColor(const RgbColor& color);
// ------------------------------------------------------------------------
// LinearBlend between two colors by the amount defined by progress variable
@ -63,14 +61,10 @@ struct HsbColor
// progress - (0.0 - 1.0) value where 0.0 will return left and 1.0 will return right
// and a value between will blend the color weighted linearly between them
// ------------------------------------------------------------------------
template <typename T_NEOHUEBLEND> static HsbColor LinearBlend(const HsbColor& left,
template <typename T_NEOHUEBLEND>
static constexpr HsbColor LinearBlend(const HsbColor& left,
const HsbColor& right,
float progress)
{
return HsbColor(T_NEOHUEBLEND::HueBlend(left.H, right.H, progress),
left.S + ((right.S - left.S) * progress),
left.B + ((right.B - left.B) * progress));
}
float progress);
// ------------------------------------------------------------------------
// BilinearBlend between four colors by the amount defined by 2d variable
@ -81,33 +75,107 @@ struct HsbColor
// x - unit value (0.0 - 1.0) that defines the blend progress in horizontal space
// y - unit value (0.0 - 1.0) that defines the blend progress in vertical space
// ------------------------------------------------------------------------
template <typename T_NEOHUEBLEND> static HsbColor BilinearBlend(const HsbColor& c00,
template <typename T_NEOHUEBLEND>
static constexpr HsbColor BilinearBlend(const HsbColor& c00,
const HsbColor& c01,
const HsbColor& c10,
const HsbColor& c11,
float x,
float y)
{
float v00 = (1.0f - x) * (1.0f - y);
float v10 = x * (1.0f - y);
float v01 = (1.0f - x) * y;
float v11 = x * y;
return HsbColor(
T_NEOHUEBLEND::HueBlend(
T_NEOHUEBLEND::HueBlend(c00.H, c10.H, x),
T_NEOHUEBLEND::HueBlend(c01.H, c11.H, x),
y),
c00.S * v00 + c10.S * v10 + c01.S * v01 + c11.S * v11,
c00.B * v00 + c10.B * v10 + c01.B * v01 + c11.B * v11);
};
float y);
// ------------------------------------------------------------------------
// Hue, Saturation, Brightness color members
// Hue, Saturation, Brightness color members
// ------------------------------------------------------------------------
float H;
float S;
float B;
float H{};
float S{};
float B{};
private:
static constexpr HsbColor convertToHsbColor(const RgbColor& color);
};
#include "RgbColor.h"
constexpr HsbColor::HsbColor() = default;
constexpr HsbColor::HsbColor(float h, float s, float b) :
H{h}, S{s}, B{b}
{
}
constexpr HsbColor::HsbColor(const HsbColor& color) = default;
constexpr HsbColor::HsbColor(const RgbColor& color) :
HsbColor{convertToHsbColor(color)}
{
}
//template <typename T_NEOHUEBLEND>
//static constexpr HsbColor HsbColor::LinearBlend<T_NEOHUEBLEND>(const HsbColor& left,
// const HsbColor& right,
// float progress)
//{
// return HsbColor(T_NEOHUEBLEND::HueBlend(left.H, right.H, progress),
// left.S + ((right.S - left.S) * progress),
// left.B + ((right.B - left.B) * progress));
//}
//template <typename T_NEOHUEBLEND>
//static constexpr HsbColor HsbColor::BilinearBlend<T_NEOHUEBLEND>(const HsbColor& c00,
// const HsbColor& c01,
// const HsbColor& c10,
// const HsbColor& c11,
// float x,
// float y)
//{
// float v00 = (1.0f - x) * (1.0f - y);
// float v10 = x * (1.0f - y);
// float v01 = (1.0f - x) * y;
// float v11 = x * y;
// return HsbColor(
// T_NEOHUEBLEND::HueBlend(
// T_NEOHUEBLEND::HueBlend(c00.H, c10.H, x),
// T_NEOHUEBLEND::HueBlend(c01.H, c11.H, x),
// y),
// c00.S * v00 + c10.S * v10 + c01.S * v01 + c11.S * v11,
// c00.B * v00 + c10.B * v10 + c01.B * v01 + c11.B * v11);
//}
constexpr HsbColor HsbColor::convertToHsbColor(const RgbColor& color)
{
// convert colors to float between (0.0 - 1.0)
float r = color.R / 255.0f;
float g = color.G / 255.0f;
float b = color.B / 255.0f;
float max = (r > g && r > b) ? r : (g > b) ? g : b;
float min = (r < g && r < b) ? r : (g < b) ? g : b;
float d = max - min;
HsbColor hsb{};
hsb.H = 0.f;
hsb.B = max;
hsb.S = (hsb.B == 0.0f) ? 0 : (d / hsb.B);
if (d != 0.0f)
{
if (r == max)
{
hsb.H = (g - b) / d + (g < b ? 6.0f : 0.0f);
}
else if (g == max)
{
hsb.H = (b - r) / d + 2.0f;
}
else
{
hsb.H = (r - g) / d + 4.0f;
}
hsb.H /= 6.0f;
}
return hsb;
}

View File

@ -1,72 +0,0 @@
/*-------------------------------------------------------------------------
HslColor provides a color object that can be directly consumed by NeoPixelBus
Written by Michael C. Miller.
I invest time and resources providing this open source code,
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
-------------------------------------------------------------------------
This file is part of the Makuna/NeoPixelBus library.
NeoPixelBus is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
NeoPixelBus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with NeoPixel. If not, see
<http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------*/
#include "RgbColor.h"
#include "HslColor.h"
HslColor::HslColor(const RgbColor& color)
{
// convert colors to float between (0.0 - 1.0)
float r = color.R / 255.0f;
float g = color.G / 255.0f;
float b = color.B / 255.0f;
float max = (r > g && r > b) ? r : (g > b) ? g : b;
float min = (r < g && r < b) ? r : (g < b) ? g : b;
float h, s, l;
l = (max + min) / 2.0f;
if (max == min)
{
h = s = 0.0f;
}
else
{
float d = max - min;
s = (l > 0.5f) ? d / (2.0f - (max + min)) : d / (max + min);
if (r > g && r > b)
{
h = (g - b) / d + (g < b ? 6.0f : 0.0f);
}
else if (g > b)
{
h = (b - r) / d + 2.0f;
}
else
{
h = (r - g) / d + 4.0f;
}
h /= 6.0f;
}
H = h;
S = s;
L = l;
}

View File

@ -25,37 +25,35 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
#include <Arduino.h>
struct RgbColor;
// ------------------------------------------------------------------------
// HslColor represents a color object that is represented by Hue, Saturation, Lightness
// component values. It contains helpful color routines to manipulate the
// component values. It contains helpful color routines to manipulate the
// color.
// ------------------------------------------------------------------------
struct HslColor
{
// ------------------------------------------------------------------------
// Construct a HslColor that will have its values set in latter operations
// ------------------------------------------------------------------------
constexpr HslColor();
// ------------------------------------------------------------------------
// Construct a HslColor using H, S, L values (0.0 - 1.0)
// L should be limited to between (0.0 - 0.5)
// ------------------------------------------------------------------------
HslColor(float h, float s, float l) :
H(h), S(s), L(l)
{
};
constexpr HslColor(float h, float s, float l);
// ------------------------------------------------------------------------
// Construct a HslColor using HslColor
// ------------------------------------------------------------------------
constexpr HslColor(const HslColor& color);
// ------------------------------------------------------------------------
// Construct a HslColor using RgbColor
// ------------------------------------------------------------------------
HslColor(const RgbColor& color);
// ------------------------------------------------------------------------
// Construct a HslColor that will have its values set in latter operations
// CAUTION: The H,S,L members are not initialized and may not be consistent
// ------------------------------------------------------------------------
HslColor()
{
};
constexpr HslColor(const RgbColor& color);
// ------------------------------------------------------------------------
// LinearBlend between two colors by the amount defined by progress variable
@ -64,14 +62,10 @@ struct HslColor
// progress - (0.0 - 1.0) value where 0.0 will return left and 1.0 will return right
// and a value between will blend the color weighted linearly between them
// ------------------------------------------------------------------------
template <typename T_NEOHUEBLEND> static HslColor LinearBlend(const HslColor& left,
template <typename T_NEOHUEBLEND>
static constexpr HslColor LinearBlend(const HslColor& left,
const HslColor& right,
float progress)
{
return HslColor(T_NEOHUEBLEND::HueBlend(left.H, right.H, progress),
left.S + ((right.S - left.S) * progress),
left.L + ((right.L - left.L) * progress));
};
float progress);
// ------------------------------------------------------------------------
// BilinearBlend between four colors by the amount defined by 2d variable
@ -82,32 +76,110 @@ struct HslColor
// x - unit value (0.0 - 1.0) that defines the blend progress in horizontal space
// y - unit value (0.0 - 1.0) that defines the blend progress in vertical space
// ------------------------------------------------------------------------
template <typename T_NEOHUEBLEND> static HslColor BilinearBlend(const HslColor& c00,
template <typename T_NEOHUEBLEND>
static constexpr HslColor BilinearBlend(const HslColor& c00,
const HslColor& c01,
const HslColor& c10,
const HslColor& c11,
float x,
float y)
{
float v00 = (1.0f - x) * (1.0f - y);
float v10 = x * (1.0f - y);
float v01 = (1.0f - x) * y;
float v11 = x * y;
return HslColor(
T_NEOHUEBLEND::HueBlend(
T_NEOHUEBLEND::HueBlend(c00.H, c10.H, x),
T_NEOHUEBLEND::HueBlend(c01.H, c11.H, x),
y),
c00.S * v00 + c10.S * v10 + c01.S * v01 + c11.S * v11,
c00.L * v00 + c10.L * v10 + c01.L * v01 + c11.L * v11);
};
float y);
// ------------------------------------------------------------------------
// Hue, Saturation, Lightness color members
// Hue, Saturation, Lightness color members
// ------------------------------------------------------------------------
float H;
float S;
float L;
float H{};
float S{};
float L{};
private:
static constexpr HslColor convertToHslColor(const RgbColor& color);
};
#include "RgbColor.h"
constexpr HslColor::HslColor() = default;
constexpr HslColor::HslColor(float h, float s, float l) :
H{h}, S{s}, L{l}
{
}
constexpr HslColor::HslColor(const HslColor& color) = default;
constexpr HslColor::HslColor(const RgbColor& color) :
HslColor{convertToHslColor(color)}
{
}
//template <typename T_NEOHUEBLEND>
//static constexpr HslColor HslColor::LinearBlend<T_NEOHUEBLEND>(const HslColor& left,
// const HslColor& right,
// float progress)
//{
// return HslColor(T_NEOHUEBLEND::HueBlend(left.H, right.H, progress),
// left.S + ((right.S - left.S) * progress),
// left.L + ((right.L - left.L) * progress));
//};
//template <typename T_NEOHUEBLEND>
//static constexpr HslColor HslColor::BilinearBlend<T_NEOHUEBLEND>(const HslColor& c00,
// const HslColor& c01,
// const HslColor& c10,
// const HslColor& c11,
// float x,
// float y)
//{
// float v00 = (1.0f - x) * (1.0f - y);
// float v10 = x * (1.0f - y);
// float v01 = (1.0f - x) * y;
// float v11 = x * y;
// return HslColor(
// T_NEOHUEBLEND::HueBlend(
// T_NEOHUEBLEND::HueBlend(c00.H, c10.H, x),
// T_NEOHUEBLEND::HueBlend(c01.H, c11.H, x),
// y),
// c00.S * v00 + c10.S * v10 + c01.S * v01 + c11.S * v11,
// c00.L * v00 + c10.L * v10 + c01.L * v01 + c11.L * v11);
//}
constexpr HslColor HslColor::convertToHslColor(const RgbColor& color)
{
// convert colors to float between (0.0 - 1.0)
float r = color.R / 255.0f;
float g = color.G / 255.0f;
float b = color.B / 255.0f;
float max = (r > g && r > b) ? r : (g > b) ? g : b;
float min = (r < g && r < b) ? r : (g < b) ? g : b;
HslColor hsl;
hsl.L = (max + min) / 2.0f;
if (max == min)
{
hsl.H = hsl.S = 0.0f;
}
else
{
float d = max - min;
hsl.S = (hsl.L > 0.5f) ? d / (2.0f - (max + min)) : d / (max + min);
if (r > g && r > b)
{
hsl.H = (g - b) / d + (g < b ? 6.0f : 0.0f);
}
else if (g > b)
{
hsl.H = (b - r) / d + 2.0f;
}
else
{
hsl.H = (r - g) / d + 4.0f;
}
hsl.H /= 6.0f;
}
return hsl;
}

View File

@ -1,58 +0,0 @@
/*-------------------------------------------------------------------------
This file contains the HtmlColor implementation
Written by Unai Uribarri
I invest time and resources providing this open source code,
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
-------------------------------------------------------------------------
This file is part of the Makuna/NeoPixelBus library.
NeoPixelBus is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
NeoPixelBus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with NeoPixel. If not, see
<http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------*/
#include "HtmlColor.h"
static inline char hexdigit(uint8_t v)
{
return v + (v < 10 ? '0' : 'a' - 10);
}
size_t HtmlColor::ToNumericalString(char* buf, size_t bufSize) const
{
size_t bufLen = bufSize - 1;
if (bufLen-- > 0)
{
if (bufLen > 0)
{
buf[0] = '#';
}
uint32_t color = Color;
for (uint8_t indexDigit = 6; indexDigit > 0; indexDigit--)
{
if (bufLen > indexDigit)
{
buf[indexDigit] = hexdigit(color & 0x0000000f);
}
color >>= 4;
}
buf[(bufLen < 7 ? bufLen : 7)] = 0;
}
return 7;
}

View File

@ -1,340 +0,0 @@
/*-------------------------------------------------------------------------
HtmlColor provides a color object that can be directly consumed by NeoPixelBus
Written by Michael C. Miller.
I invest time and resources providing this open source code,
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
-------------------------------------------------------------------------
This file is part of the Makuna/NeoPixelBus library.
NeoPixelBus is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
NeoPixelBus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with NeoPixel. If not, see
<http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------*/
#pragma once
#include <Arduino.h>
#include "RgbColor.h"
#define MAX_HTML_COLOR_NAME_LEN 21
#ifndef pgm_read_ptr
// ESP8266 doesn't define this macro
#define pgm_read_ptr(addr) (*reinterpret_cast<const void* const *>(addr))
#endif
#ifndef countof
#define countof(array) (sizeof(array)/sizeof(array[0]))
#endif
// ------------------------------------------------------------------------
// HtmlColorPair represents an association between a name and a HTML color code
// ------------------------------------------------------------------------
struct HtmlColorPair
{
PGM_P Name;
uint32_t Color;
};
// ------------------------------------------------------------------------
// HtmlShortColorNames is a template class used for Parse and ToString
// ------------------------------------------------------------------------
class HtmlShortColorNames
{
public:
static const HtmlColorPair* Pair(uint8_t index);
static uint8_t Count();
};
// ------------------------------------------------------------------------
// HtmlColorNames is a template class used for Parse and ToString
// ------------------------------------------------------------------------
class HtmlColorNames
{
public:
static const HtmlColorPair* Pair(uint8_t index);
static uint8_t Count();
};
// ------------------------------------------------------------------------
// HtmlColor represents a color object that is represented by a single uint32
// value. It contains minimal routines and used primarily as a helper to
// initialize other color objects
// ------------------------------------------------------------------------
struct HtmlColor
{
// ------------------------------------------------------------------------
// Construct a HtmlColor using a single value (0-0xffffff)
// This works well for hexidecimal color definitions
// 0xff0000 = red, 0x00ff00 = green, and 0x0000ff = blue
// ------------------------------------------------------------------------
HtmlColor(uint32_t color) :
Color(color)
{
};
// ------------------------------------------------------------------------
// Construct a HtmlColor using RgbColor
// ------------------------------------------------------------------------
HtmlColor(const RgbColor& color)
{
Color = (uint32_t)color.R << 16 | (uint32_t)color.G << 8 | (uint32_t)color.B;
}
// ------------------------------------------------------------------------
// Construct a HtmlColor that will have its values set in latter operations
// CAUTION: The Color member is not initialized and may not be consistent
// ------------------------------------------------------------------------
HtmlColor()
{
};
// ------------------------------------------------------------------------
// Comparison operators
// ------------------------------------------------------------------------
bool operator==(const HtmlColor& other) const
{
return (Color == other.Color);
};
bool operator!=(const HtmlColor& other) const
{
return !(*this == other);
};
// ------------------------------------------------------------------------
// Parse a HTML4/CSS3 color name
// T_HTMLCOLORNAMES - template class that defines the collection of names
// name - the color name
// nameSize - the max size of name to check
//
// returns - zero if failed, or the number of chars parsed
//
// It will stop parsing name when a null terminator is reached,
// nameSize is reached, no match is found in the name/color pair table, or
// a non-alphanumeric is read like seperators or whitespace.
//
// It also accepts 3 or 6 digit hexadecimal notation (#rgb or #rrggbb),
// but it doesn't accept RGB, RGBA nor HSL values.
//
// See https://www.w3.org/TR/css3-color/#SRGB
//
// name must point to the first non-whitespace character to be parsed
// parsing will stop at the first non-alpha numeric
//
// Name MUST NOT be a PROGMEM pointer
//
// examples:
// Parse<HtmlShortColorNames>(buff, buffSize);
// Parse<HtmlColorNames>(buff, buffSize);
// ------------------------------------------------------------------------
template <typename T_HTMLCOLORNAMES> size_t Parse(const char* name, size_t nameSize)
{
if (nameSize > 0)
{
if (name[0] == '#')
{
// Parse an hexadecimal notation "#rrbbgg" or "#rgb"
//
uint8_t temp[6]; // stores preconverted chars to hex values
uint8_t tempSize = 0;
for (uint8_t indexChar = 1; indexChar < nameSize && indexChar < 8; ++indexChar)
{
char c = name[indexChar];
if (c >= '0' && c <= '9')
{
c -= '0';
}
else
{
// Convert a letter to lower case (only for ASCII letters)
// It's faster & smaller than tolower()
c |= 32;
if (c >= 'a' && c <= 'f')
{
c = c - 'a' + 10;
}
else
{
// we found an non hexidecimal char
// which could be null, deliminator, or other spacing
break;
}
}
temp[tempSize] = c;
tempSize++;
}
if (tempSize != 3 && tempSize != 6)
{
// invalid count of numerical chars
return 0;
}
else
{
uint32_t color = 0;
for (uint8_t indexChar = 0; indexChar < tempSize; ++indexChar)
{
color = color * 16 + temp[indexChar];
if (tempSize == 3)
{
// 3 digit hexadecimal notation can be supported easily
// duplicating digits.
color = color * 16 + temp[indexChar];
}
}
Color = color;
return tempSize;
}
}
else
{
// parse a standard name for the color
//
// the normal list is small enough a binary search isn't interesting,
for (uint8_t indexName = 0; indexName < T_HTMLCOLORNAMES::Count(); ++indexName)
{
const HtmlColorPair* colorPair = T_HTMLCOLORNAMES::Pair(indexName);
PGM_P searchName = reinterpret_cast<PGM_P>(pgm_read_ptr(&(colorPair->Name)));
size_t str1Size = nameSize;
const char* str1 = name;
const char* str2P = searchName;
uint16_t result;
while (str1Size > 0)
{
char ch1 = tolower(*str1++);
char ch2 = tolower(pgm_read_byte(str2P++));
result = ch1 - ch2;
if (result != 0 || ch2 == '\0')
{
if (ch2 == '\0' && !isalnum(ch1))
{
// the string continues but is not part of a
// valid color name,
// ends in white space, deliminator, etc
result = 0;
}
break;
}
result = -1; // have not reached the end of searchName;
str1Size--;
}
if (result == 0)
{
Color = pgm_read_dword(&colorPair->Color);
return nameSize - str1Size;
}
}
}
}
return 0;
}
template <typename T_HTMLCOLORNAMES> size_t Parse(const char* name)
{
return Parse<T_HTMLCOLORNAMES>(name, MAX_HTML_COLOR_NAME_LEN + 1);
}
template <typename T_HTMLCOLORNAMES> size_t Parse(String const &name)
{
return Parse<T_HTMLCOLORNAMES>(name.c_str(), name.length() + 1);
}
// ------------------------------------------------------------------------
// Converts this color code to its HTML4/CSS3 name
// T_HTMLCOLORNAMES - template class that defines the collection of names
// buf - buffer to write the string
// bufSize - actual size of buf array
//
// It returns the number of chars required not including the NUL terminator.
//
// If there is not enough space in the buffer, it will write as many
// characters as allowed and will always finish the buffer with a NUL char
//
// examples:
// ToString<HtmlShortColorNames>(buf, bufSize);
// ToString<htmlColorNames>(buf, bufSize);
// ------------------------------------------------------------------------
template <typename T_HTMLCOLORNAMES> size_t ToString(char* buf, size_t bufSize) const
{
// search for a color value/name pairs first
for (uint8_t indexName = 0; indexName < T_HTMLCOLORNAMES::Count(); ++indexName)
{
const HtmlColorPair* colorPair = T_HTMLCOLORNAMES::Pair(indexName);
if (pgm_read_dword(&colorPair->Color) == Color)
{
PGM_P name = (PGM_P)pgm_read_ptr(&colorPair->Name);
strncpy_P(buf, name, bufSize);
return strlen_P(name);
}
}
// no color name pair match, convert using numerical format
return ToNumericalString(buf, bufSize);
}
// ------------------------------------------------------------------------
// Converts this color code to its HTML4/CSS3 numerical name
//
// buf - buffer to write the string
// bufSize - actual size of buf array
//
// It returns the number of chars required not including the NUL terminator.
//
// If there is not enough space in the buffer, it will write as many
// characters as allowed and will always finish the buffer with a NUL char
// ------------------------------------------------------------------------
size_t ToNumericalString(char* buf, size_t bufSize) const;
// ------------------------------------------------------------------------
// BilinearBlend between four colors by the amount defined by 2d variable
// c00 - upper left quadrant color
// c01 - upper right quadrant color
// c10 - lower left quadrant color
// c11 - lower right quadrant color
// x - unit value (0.0 - 1.0) that defines the blend progress in horizontal space
// y - unit value (0.0 - 1.0) that defines the blend progress in vertical space
// ------------------------------------------------------------------------
static HtmlColor BilinearBlend(const HtmlColor& c00,
const HtmlColor& c01,
const HtmlColor& c10,
const HtmlColor& c11,
float x,
float y)
{
return RgbColor::BilinearBlend(c00, c01, c10, c11, x, y);
}
// ------------------------------------------------------------------------
// Color member (0-0xffffff) where
// 0xff0000 is red
// 0x00ff00 is green
// 0x0000ff is blue
// ------------------------------------------------------------------------
uint32_t Color;
};

View File

@ -1,178 +0,0 @@
/*-------------------------------------------------------------------------
HtmlColorNameStrings provides the implemenation of the color string names
Written by Michael C. Miller.
I invest time and resources providing this open source code,
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
-------------------------------------------------------------------------
This file is part of the Makuna/NeoPixelBus library.
NeoPixelBus is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
NeoPixelBus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with NeoPixel. If not, see
<http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------*/
#include "HtmlColorNameStrings.h"
/* HTML4 color names */
const char c_HtmlNameAqua[] PROGMEM = "aqua";
const char c_HtmlNameBlack[] PROGMEM = "black";
const char c_HtmlNameBlue[] PROGMEM = "blue";
const char c_HtmlNameFuchsia[] PROGMEM = "fuchsia";
const char c_HtmlNameGray[] PROGMEM = "gray";
const char c_HtmlNameGreen[] PROGMEM = "green";
const char c_HtmlNameLime[] PROGMEM = "lime";
const char c_HtmlNameMaroon[] PROGMEM = "maroon";
const char c_HtmlNameNavy[] PROGMEM = "navy";
const char c_HtmlNameOlive[] PROGMEM = "olive";
const char c_HtmlNameOrange[] PROGMEM = "orange";
const char c_HtmlNamePurple[] PROGMEM = "purple";
const char c_HtmlNameRed[] PROGMEM = "red";
const char c_HtmlNameSilver[] PROGMEM = "silver";
const char c_HtmlNameTeal[] PROGMEM = "teal";
const char c_HtmlNameWhite[] PROGMEM = "white";
const char c_HtmlNameYellow[] PROGMEM = "yellow";
/* Additional CSS3 color names */
const char c_HtmlNameAliceBlue[] PROGMEM = "aliceblue";
const char c_HtmlNameAntiqueWhite[] PROGMEM = "antiquewhite";
const char c_HtmlNameAquamarine[] PROGMEM = "aquamarine";
const char c_HtmlNameAzure[] PROGMEM = "azure";
const char c_HtmlNameBeige[] PROGMEM = "beige";
const char c_HtmlNameBisque[] PROGMEM = "bisque";
const char c_HtmlNameBlanchedAlmond[] PROGMEM = "blanchedalmond";
const char c_HtmlNameBlueViolet[] PROGMEM = "blueviolet";
const char c_HtmlNameBrown[] PROGMEM = "brown";
const char c_HtmlNameBurlyWood[] PROGMEM = "burlywood";
const char c_HtmlNameCadetBlue[] PROGMEM = "cadetblue";
const char c_HtmlNameChartreuse[] PROGMEM = "chartreuse";
const char c_HtmlNameChocolate[] PROGMEM = "chocolate";
const char c_HtmlNameCoral[] PROGMEM = "coral";
const char c_HtmlNameCornflowerBlue[] PROGMEM = "cornflowerblue";
const char c_HtmlNameCornsilk[] PROGMEM = "cornsilk";
const char c_HtmlNameCrimson[] PROGMEM = "crimson";
const char c_HtmlNameCyan[] PROGMEM = "cyan";
const char c_HtmlNameDarkBlue[] PROGMEM = "darkblue";
const char c_HtmlNameDarkCyan[] PROGMEM = "darkcyan";
const char c_HtmlNameDarkGoldenrod[] PROGMEM = "darkgoldenrod";
const char c_HtmlNameDarkGray[] PROGMEM = "darkgray";
const char c_HtmlNameDarkGreen[] PROGMEM = "darkgreen";
const char c_HtmlNameDarkGrey[] PROGMEM = "darkgrey";
const char c_HtmlNameDarkKhaki[] PROGMEM = "darkkhaki";
const char c_HtmlNameDarkMagenta[] PROGMEM = "darkmagenta";
const char c_HtmlNameDarkOliveGreen[] PROGMEM = "darkolivegreen";
const char c_HtmlNameDarkOrange[] PROGMEM = "darkorange";
const char c_HtmlNameDarkOrchid[] PROGMEM = "darkorchid";
const char c_HtmlNameDarkRed[] PROGMEM = "darkred";
const char c_HtmlNameDarkSalmon[] PROGMEM = "darksalmon";
const char c_HtmlNameDarkSeaGreen[] PROGMEM = "darkseagreen";
const char c_HtmlNameDarkSlateBlue[] PROGMEM = "darkslateblue";
const char c_HtmlNameDarkSlateGray[] PROGMEM = "darkslategray";
const char c_HtmlNameDarkSlateGrey[] PROGMEM = "darkslategrey";
const char c_HtmlNameDarkTurquoise[] PROGMEM = "darkturquoise";
const char c_HtmlNameDarkViolet[] PROGMEM = "darkviolet";
const char c_HtmlNameDeepPink[] PROGMEM = "deeppink";
const char c_HtmlNameDeepSkyBlue[] PROGMEM = "deepskyblue";
const char c_HtmlNameDimGray[] PROGMEM = "dimgray";
const char c_HtmlNameDimGrey[] PROGMEM = "dimgrey";
const char c_HtmlNameDodgerBlue[] PROGMEM = "dodgerblue";
const char c_HtmlNameFirebrick[] PROGMEM = "firebrick";
const char c_HtmlNameFloralWhite[] PROGMEM = "floralwhite";
const char c_HtmlNameForestGreen[] PROGMEM = "forestgreen";
const char c_HtmlNameGainsboro[] PROGMEM = "gainsboro";
const char c_HtmlNameGhostWhite[] PROGMEM = "ghostwhite";
const char c_HtmlNameGold[] PROGMEM = "gold";
const char c_HtmlNameGoldenrod[] PROGMEM = "goldenrod";
const char c_HtmlNameGreenYellow[] PROGMEM = "greenyellow";
const char c_HtmlNameGrey[] PROGMEM = "grey";
const char c_HtmlNameHoneydew[] PROGMEM = "honeydew";
const char c_HtmlNameHotPink[] PROGMEM = "hotpink";
const char c_HtmlNameIndianRed[] PROGMEM = "indianred";
const char c_HtmlNameIndigo[] PROGMEM = "indigo";
const char c_HtmlNameIvory[] PROGMEM = "ivory";
const char c_HtmlNameKhaki[] PROGMEM = "khaki";
const char c_HtmlNameLavender[] PROGMEM = "lavender";
const char c_HtmlNameLavenderBlush[] PROGMEM = "lavenderblush";
const char c_HtmlNameLawnGreen[] PROGMEM = "lawngreen";
const char c_HtmlNameLemonChiffon[] PROGMEM = "lemonchiffon";
const char c_HtmlNameLightBlue[] PROGMEM = "lightblue";
const char c_HtmlNameLightCoral[] PROGMEM = "lightcoral";
const char c_HtmlNameLightCyan[] PROGMEM = "lightcyan";
const char c_HtmlNameLightGoldenrodYellow[] PROGMEM = "lightgoldenrodyellow";
const char c_HtmlNameLightGray[] PROGMEM = "lightgray";
const char c_HtmlNameLightGreen[] PROGMEM = "lightgreen";
const char c_HtmlNameLightGrey[] PROGMEM = "lightgrey";
const char c_HtmlNameLightPink[] PROGMEM = "lightpink";
const char c_HtmlNameLightSalmon[] PROGMEM = "lightsalmon";
const char c_HtmlNameLightSeaGreen[] PROGMEM = "lightseagreen";
const char c_HtmlNameLightSkyBlue[] PROGMEM = "lightskyblue";
const char c_HtmlNameLightSlateGray[] PROGMEM = "lightslategray";
const char c_HtmlNameLightSlateGrey[] PROGMEM = "lightslategrey";
const char c_HtmlNameLightSteelBlue[] PROGMEM = "lightsteelblue";
const char c_HtmlNameLightYellow[] PROGMEM = "lightyellow";
const char c_HtmlNameLimeGreen[] PROGMEM = "limegreen";
const char c_HtmlNameLinen[] PROGMEM = "linen";
const char c_HtmlNameMagenta[] PROGMEM = "magenta";
const char c_HtmlNameMediumAquamarine[] PROGMEM = "mediumaquamarine";
const char c_HtmlNameMediumBlue[] PROGMEM = "mediumblue";
const char c_HtmlNameMediumOrchid[] PROGMEM = "mediumorchid";
const char c_HtmlNameMediumPurple[] PROGMEM = "mediumpurple";
const char c_HtmlNameMediumSeagreen[] PROGMEM = "mediumseagreen";
const char c_HtmlNameMediumSlateBlue[] PROGMEM = "mediumslateblue";
const char c_HtmlNameMediumSpringGreen[] PROGMEM = "mediumspringgreen";
const char c_HtmlNameMediumTurquoise[] PROGMEM = "mediumturquoise";
const char c_HtmlNameMediumVioletRed[] PROGMEM = "mediumvioletred";
const char c_HtmlNameMidnightBlue[] PROGMEM = "midnightblue";
const char c_HtmlNameMintCream[] PROGMEM = "mintcream";
const char c_HtmlNameMistyRose[] PROGMEM = "mistyrose";
const char c_HtmlNameMoccasin[] PROGMEM = "moccasin";
const char c_HtmlNameNavajoWhite[] PROGMEM = "navajowhite";
const char c_HtmlNameOldLace[] PROGMEM = "oldlace";
const char c_HtmlNameOliveDrab[] PROGMEM = "olivedrab";
const char c_HtmlNameOrangeRed[] PROGMEM = "orangered";
const char c_HtmlNameOrchid[] PROGMEM = "orchid";
const char c_HtmlNamePaleGoldenrod[] PROGMEM = "palegoldenrod";
const char c_HtmlNamePaleGreen[] PROGMEM = "palegreen";
const char c_HtmlNamePaleTurquoise[] PROGMEM = "paleturquoise";
const char c_HtmlNamePaleVioletRed[] PROGMEM = "palevioletred";
const char c_HtmlNamePapayaWhip[] PROGMEM = "papayawhip";
const char c_HtmlNamePeachPuff[] PROGMEM = "peachpuff";
const char c_HtmlNamePeru[] PROGMEM = "peru";
const char c_HtmlNamePink[] PROGMEM = "pink";
const char c_HtmlNamePlum[] PROGMEM = "plum";
const char c_HtmlNamePowderBlue[] PROGMEM = "powderblue";
const char c_HtmlNameRosyBrown[] PROGMEM = "rosybrown";
const char c_HtmlNameRoyalBlue[] PROGMEM = "royalblue";
const char c_HtmlNameSaddleBrown[] PROGMEM = "saddlebrown";
const char c_HtmlNameSalmon[] PROGMEM = "salmon";
const char c_HtmlNameSandyBrown[] PROGMEM = "sandybrown";
const char c_HtmlNameSeaGreen[] PROGMEM = "seagreen";
const char c_HtmlNameSeaShell[] PROGMEM = "seashell";
const char c_HtmlNameSienna[] PROGMEM = "sienna";
const char c_HtmlNameSkyBlue[] PROGMEM = "skyblue";
const char c_HtmlNameSlateBlue[] PROGMEM = "slateblue";
const char c_HtmlNameSlateGray[] PROGMEM = "slategray";
const char c_HtmlNameSlateGrey[] PROGMEM = "slategrey";
const char c_HtmlNameSnow[] PROGMEM = "snow";
const char c_HtmlNameSpringGreen[] PROGMEM = "springgreen";
const char c_HtmlNameSteelBlue[] PROGMEM = "steelblue";
const char c_HtmlNameTan[] PROGMEM = "tan";
const char c_HtmlNameThistle[] PROGMEM = "thistle";
const char c_HtmlNameTomato[] PROGMEM = "tomato";
const char c_HtmlNameTurquoise[] PROGMEM = "turquoise";
const char c_HtmlNameViolet[] PROGMEM = "violet";
const char c_HtmlNameWheat[] PROGMEM = "wheat";
const char c_HtmlNameWhiteSmoke[] PROGMEM = "whitesmoke";
const char c_HtmlNameYellowGreen[] PROGMEM = "yellowgreen";

View File

@ -1,180 +0,0 @@
/*-------------------------------------------------------------------------
HtmlColorNameStrings provides the declaration of the color string names
Written by Michael C. Miller.
I invest time and resources providing this open source code,
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
-------------------------------------------------------------------------
This file is part of the Makuna/NeoPixelBus library.
NeoPixelBus is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
NeoPixelBus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with NeoPixel. If not, see
<http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------*/
#pragma once
#include <Arduino.h>
/* HTML4 color names */
extern const char c_HtmlNameAqua[] PROGMEM;
extern const char c_HtmlNameBlack[] PROGMEM;
extern const char c_HtmlNameBlue[] PROGMEM;
extern const char c_HtmlNameFuchsia[] PROGMEM;
extern const char c_HtmlNameGray[] PROGMEM;
extern const char c_HtmlNameGreen[] PROGMEM;
extern const char c_HtmlNameLime[] PROGMEM;
extern const char c_HtmlNameMaroon[] PROGMEM;
extern const char c_HtmlNameNavy[] PROGMEM;
extern const char c_HtmlNameOlive[] PROGMEM;
extern const char c_HtmlNameOrange[] PROGMEM;
extern const char c_HtmlNamePurple[] PROGMEM;
extern const char c_HtmlNameRed[] PROGMEM;
extern const char c_HtmlNameSilver[] PROGMEM;
extern const char c_HtmlNameTeal[] PROGMEM;
extern const char c_HtmlNameWhite[] PROGMEM;
extern const char c_HtmlNameYellow[] PROGMEM;
/* Additional CSS3 color names */
extern const char c_HtmlNameAliceBlue[] PROGMEM;
extern const char c_HtmlNameAntiqueWhite[] PROGMEM;
extern const char c_HtmlNameAquamarine[] PROGMEM;
extern const char c_HtmlNameAzure[] PROGMEM;
extern const char c_HtmlNameBeige[] PROGMEM;
extern const char c_HtmlNameBisque[] PROGMEM;
extern const char c_HtmlNameBlanchedAlmond[] PROGMEM;
extern const char c_HtmlNameBlueViolet[] PROGMEM;
extern const char c_HtmlNameBrown[] PROGMEM;
extern const char c_HtmlNameBurlyWood[] PROGMEM;
extern const char c_HtmlNameCadetBlue[] PROGMEM;
extern const char c_HtmlNameChartreuse[] PROGMEM;
extern const char c_HtmlNameChocolate[] PROGMEM;
extern const char c_HtmlNameCoral[] PROGMEM;
extern const char c_HtmlNameCornflowerBlue[] PROGMEM;
extern const char c_HtmlNameCornsilk[] PROGMEM;
extern const char c_HtmlNameCrimson[] PROGMEM;
extern const char c_HtmlNameCyan[] PROGMEM;
extern const char c_HtmlNameDarkBlue[] PROGMEM;
extern const char c_HtmlNameDarkCyan[] PROGMEM;
extern const char c_HtmlNameDarkGoldenrod[] PROGMEM;
extern const char c_HtmlNameDarkGray[] PROGMEM;
extern const char c_HtmlNameDarkGreen[] PROGMEM;
extern const char c_HtmlNameDarkGrey[] PROGMEM;
extern const char c_HtmlNameDarkKhaki[] PROGMEM;
extern const char c_HtmlNameDarkMagenta[] PROGMEM;
extern const char c_HtmlNameDarkOliveGreen[] PROGMEM;
extern const char c_HtmlNameDarkOrange[] PROGMEM;
extern const char c_HtmlNameDarkOrchid[] PROGMEM;
extern const char c_HtmlNameDarkRed[] PROGMEM;
extern const char c_HtmlNameDarkSalmon[] PROGMEM;
extern const char c_HtmlNameDarkSeaGreen[] PROGMEM;
extern const char c_HtmlNameDarkSlateBlue[] PROGMEM;
extern const char c_HtmlNameDarkSlateGray[] PROGMEM;
extern const char c_HtmlNameDarkSlateGrey[] PROGMEM;
extern const char c_HtmlNameDarkTurquoise[] PROGMEM;
extern const char c_HtmlNameDarkViolet[] PROGMEM;
extern const char c_HtmlNameDeepPink[] PROGMEM;
extern const char c_HtmlNameDeepSkyBlue[] PROGMEM;
extern const char c_HtmlNameDimGray[] PROGMEM;
extern const char c_HtmlNameDimGrey[] PROGMEM;
extern const char c_HtmlNameDodgerBlue[] PROGMEM;
extern const char c_HtmlNameFirebrick[] PROGMEM;
extern const char c_HtmlNameFloralWhite[] PROGMEM;
extern const char c_HtmlNameForestGreen[] PROGMEM;
extern const char c_HtmlNameGainsboro[] PROGMEM;
extern const char c_HtmlNameGhostWhite[] PROGMEM;
extern const char c_HtmlNameGold[] PROGMEM;
extern const char c_HtmlNameGoldenrod[] PROGMEM;
extern const char c_HtmlNameGreenYellow[] PROGMEM;
extern const char c_HtmlNameGrey[] PROGMEM;
extern const char c_HtmlNameHoneydew[] PROGMEM;
extern const char c_HtmlNameHotPink[] PROGMEM;
extern const char c_HtmlNameIndianRed[] PROGMEM;
extern const char c_HtmlNameIndigo[] PROGMEM;
extern const char c_HtmlNameIvory[] PROGMEM;
extern const char c_HtmlNameKhaki[] PROGMEM;
extern const char c_HtmlNameLavender[] PROGMEM;
extern const char c_HtmlNameLavenderBlush[] PROGMEM;
extern const char c_HtmlNameLawnGreen[] PROGMEM;
extern const char c_HtmlNameLemonChiffon[] PROGMEM;
extern const char c_HtmlNameLightBlue[] PROGMEM;
extern const char c_HtmlNameLightCoral[] PROGMEM;
extern const char c_HtmlNameLightCyan[] PROGMEM;
extern const char c_HtmlNameLightGoldenrodYellow[] PROGMEM;
extern const char c_HtmlNameLightGray[] PROGMEM;
extern const char c_HtmlNameLightGreen[] PROGMEM;
extern const char c_HtmlNameLightGrey[] PROGMEM;
extern const char c_HtmlNameLightPink[] PROGMEM;
extern const char c_HtmlNameLightSalmon[] PROGMEM;
extern const char c_HtmlNameLightSeaGreen[] PROGMEM;
extern const char c_HtmlNameLightSkyBlue[] PROGMEM;
extern const char c_HtmlNameLightSlateGray[] PROGMEM;
extern const char c_HtmlNameLightSlateGrey[] PROGMEM;
extern const char c_HtmlNameLightSteelBlue[] PROGMEM;
extern const char c_HtmlNameLightYellow[] PROGMEM;
extern const char c_HtmlNameLimeGreen[] PROGMEM;
extern const char c_HtmlNameLinen[] PROGMEM;
extern const char c_HtmlNameMagenta[] PROGMEM;
extern const char c_HtmlNameMediumAquamarine[] PROGMEM;
extern const char c_HtmlNameMediumBlue[] PROGMEM;
extern const char c_HtmlNameMediumOrchid[] PROGMEM;
extern const char c_HtmlNameMediumPurple[] PROGMEM;
extern const char c_HtmlNameMediumSeagreen[] PROGMEM;
extern const char c_HtmlNameMediumSlateBlue[] PROGMEM;
extern const char c_HtmlNameMediumSpringGreen[] PROGMEM;
extern const char c_HtmlNameMediumTurquoise[] PROGMEM;
extern const char c_HtmlNameMediumVioletRed[] PROGMEM;
extern const char c_HtmlNameMidnightBlue[] PROGMEM;
extern const char c_HtmlNameMintCream[] PROGMEM;
extern const char c_HtmlNameMistyRose[] PROGMEM;
extern const char c_HtmlNameMoccasin[] PROGMEM;
extern const char c_HtmlNameNavajoWhite[] PROGMEM;
extern const char c_HtmlNameOldLace[] PROGMEM;
extern const char c_HtmlNameOliveDrab[] PROGMEM;
extern const char c_HtmlNameOrangeRed[] PROGMEM;
extern const char c_HtmlNameOrchid[] PROGMEM;
extern const char c_HtmlNamePaleGoldenrod[] PROGMEM;
extern const char c_HtmlNamePaleGreen[] PROGMEM;
extern const char c_HtmlNamePaleTurquoise[] PROGMEM;
extern const char c_HtmlNamePaleVioletRed[] PROGMEM;
extern const char c_HtmlNamePapayaWhip[] PROGMEM;
extern const char c_HtmlNamePeachPuff[] PROGMEM;
extern const char c_HtmlNamePeru[] PROGMEM;
extern const char c_HtmlNamePink[] PROGMEM;
extern const char c_HtmlNamePlum[] PROGMEM;
extern const char c_HtmlNamePowderBlue[] PROGMEM;
extern const char c_HtmlNameRosyBrown[] PROGMEM;
extern const char c_HtmlNameRoyalBlue[] PROGMEM;
extern const char c_HtmlNameSaddleBrown[] PROGMEM;
extern const char c_HtmlNameSalmon[] PROGMEM;
extern const char c_HtmlNameSandyBrown[] PROGMEM;
extern const char c_HtmlNameSeaGreen[] PROGMEM;
extern const char c_HtmlNameSeaShell[] PROGMEM;
extern const char c_HtmlNameSienna[] PROGMEM;
extern const char c_HtmlNameSkyBlue[] PROGMEM;
extern const char c_HtmlNameSlateBlue[] PROGMEM;
extern const char c_HtmlNameSlateGray[] PROGMEM;
extern const char c_HtmlNameSlateGrey[] PROGMEM;
extern const char c_HtmlNameSnow[] PROGMEM;
extern const char c_HtmlNameSpringGreen[] PROGMEM;
extern const char c_HtmlNameSteelBlue[] PROGMEM;
extern const char c_HtmlNameTan[] PROGMEM;
extern const char c_HtmlNameThistle[] PROGMEM;
extern const char c_HtmlNameTomato[] PROGMEM;
extern const char c_HtmlNameTurquoise[] PROGMEM;
extern const char c_HtmlNameViolet[] PROGMEM;
extern const char c_HtmlNameWheat[] PROGMEM;
extern const char c_HtmlNameWhiteSmoke[] PROGMEM;
extern const char c_HtmlNameYellowGreen[] PROGMEM;

View File

@ -1,188 +0,0 @@
/*-------------------------------------------------------------------------
HtmlColorNames provides a template class for access to the full name table
Written by Michael C. Miller.
I invest time and resources providing this open source code,
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
-------------------------------------------------------------------------
This file is part of the Makuna/NeoPixelBus library.
NeoPixelBus is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
NeoPixelBus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with NeoPixel. If not, see
<http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------*/
#include "HtmlColor.h"
#include "HtmlColorNameStrings.h"
static const HtmlColorPair c_ColorNames[] PROGMEM = {
{ c_HtmlNameAliceBlue, 0xf0f8ff },
{ c_HtmlNameAntiqueWhite, 0xfaebd7 },
{ c_HtmlNameAqua, 0xffff },
{ c_HtmlNameAquamarine, 0x7fffd4 },
{ c_HtmlNameAzure, 0xf0ffff },
{ c_HtmlNameBeige, 0xf5f5dc },
{ c_HtmlNameBisque, 0xffe4c4 },
{ c_HtmlNameBlack, 0x0 },
{ c_HtmlNameBlanchedAlmond, 0xffebcd },
{ c_HtmlNameBlue, 0xff },
{ c_HtmlNameBlueViolet, 0x8a2be2 },
{ c_HtmlNameBrown, 0xa52a2a },
{ c_HtmlNameBurlyWood, 0xdeb887 },
{ c_HtmlNameCadetBlue, 0x5f9ea0 },
{ c_HtmlNameChartreuse, 0x7fff00 },
{ c_HtmlNameChocolate, 0xd2691e },
{ c_HtmlNameCoral, 0xff7f50 },
{ c_HtmlNameCornflowerBlue, 0x6495ed },
{ c_HtmlNameCornsilk, 0xfff8dc },
{ c_HtmlNameCrimson, 0xdc143c },
{ c_HtmlNameCyan, 0xffff },
{ c_HtmlNameDarkBlue, 0x8b },
{ c_HtmlNameDarkCyan, 0x8b8b },
{ c_HtmlNameDarkGoldenrod, 0xb8860b },
{ c_HtmlNameDarkGray, 0xa9a9a9 },
{ c_HtmlNameDarkGreen, 0x6400 },
{ c_HtmlNameDarkGrey, 0xa9a9a9 },
{ c_HtmlNameDarkKhaki, 0xbdb76b },
{ c_HtmlNameDarkMagenta, 0x8b008b },
{ c_HtmlNameDarkOliveGreen, 0x556b2f },
{ c_HtmlNameDarkOrange, 0xff8c00 },
{ c_HtmlNameDarkOrchid, 0x9932cc },
{ c_HtmlNameDarkRed, 0x8b0000 },
{ c_HtmlNameDarkSalmon, 0xe9967a },
{ c_HtmlNameDarkSeaGreen, 0x8fbc8f },
{ c_HtmlNameDarkSlateBlue, 0x483d8b },
{ c_HtmlNameDarkSlateGray, 0x2f4f4f },
{ c_HtmlNameDarkSlateGrey, 0x2f4f4f },
{ c_HtmlNameDarkTurquoise, 0xced1 },
{ c_HtmlNameDarkViolet, 0x9400d3 },
{ c_HtmlNameDeepPink, 0xff1493 },
{ c_HtmlNameDeepSkyBlue, 0xbfff },
{ c_HtmlNameDimGray, 0x696969 },
{ c_HtmlNameDimGrey, 0x696969 },
{ c_HtmlNameDodgerBlue, 0x1e90ff },
{ c_HtmlNameFirebrick, 0xb22222 },
{ c_HtmlNameFloralWhite, 0xfffaf0 },
{ c_HtmlNameForestGreen, 0x228b22 },
{ c_HtmlNameFuchsia, 0xff00ff },
{ c_HtmlNameGainsboro, 0xdcdcdc },
{ c_HtmlNameGhostWhite, 0xf8f8ff },
{ c_HtmlNameGold, 0xffd700 },
{ c_HtmlNameGoldenrod, 0xdaa520 },
{ c_HtmlNameGray, 0x808080 },
{ c_HtmlNameGreen, 0x8000 },
{ c_HtmlNameGreenYellow, 0xadff2f },
{ c_HtmlNameGrey, 0x808080 },
{ c_HtmlNameHoneydew, 0xf0fff0 },
{ c_HtmlNameHotPink, 0xff69b4 },
{ c_HtmlNameIndianRed, 0xcd5c5c },
{ c_HtmlNameIndigo, 0x4b0082 },
{ c_HtmlNameIvory, 0xfffff0 },
{ c_HtmlNameKhaki, 0xf0e68c },
{ c_HtmlNameLavender, 0xe6e6fa },
{ c_HtmlNameLavenderBlush, 0xfff0f5 },
{ c_HtmlNameLawnGreen, 0x7cfc00 },
{ c_HtmlNameLemonChiffon, 0xfffacd },
{ c_HtmlNameLightBlue, 0xadd8e6 },
{ c_HtmlNameLightCoral, 0xf08080 },
{ c_HtmlNameLightCyan, 0xe0ffff },
{ c_HtmlNameLightGoldenrodYellow, 0xfafad2 },
{ c_HtmlNameLightGray, 0xd3d3d3 },
{ c_HtmlNameLightGreen, 0x90ee90 },
{ c_HtmlNameLightGrey, 0xd3d3d3 },
{ c_HtmlNameLightPink, 0xffb6c1 },
{ c_HtmlNameLightSalmon, 0xffa07a },
{ c_HtmlNameLightSeaGreen, 0x20b2aa },
{ c_HtmlNameLightSkyBlue, 0x87cefa },
{ c_HtmlNameLightSlateGray, 0x778899 },
{ c_HtmlNameLightSlateGrey, 0x778899 },
{ c_HtmlNameLightSteelBlue, 0xb0c4de },
{ c_HtmlNameLightYellow, 0xffffe0 },
{ c_HtmlNameLime, 0xff00 },
{ c_HtmlNameLimeGreen, 0x32cd32 },
{ c_HtmlNameLinen, 0xfaf0e6 },
{ c_HtmlNameMagenta, 0xff00ff },
{ c_HtmlNameMaroon, 0x800000 },
{ c_HtmlNameMediumAquamarine, 0x66cdaa },
{ c_HtmlNameMediumBlue, 0xcd },
{ c_HtmlNameMediumOrchid, 0xba55d3 },
{ c_HtmlNameMediumPurple, 0x9370d8 },
{ c_HtmlNameMediumSeagreen, 0x3cb371 },
{ c_HtmlNameMediumSlateBlue, 0x7b68ee },
{ c_HtmlNameMediumSpringGreen, 0xfa9a },
{ c_HtmlNameMediumTurquoise, 0x48d1cc },
{ c_HtmlNameMediumVioletRed, 0xc71585 },
{ c_HtmlNameMidnightBlue, 0x191970 },
{ c_HtmlNameMintCream, 0xf5fffa },
{ c_HtmlNameMistyRose, 0xffe4e1 },
{ c_HtmlNameMoccasin, 0xffe4b5 },
{ c_HtmlNameNavajoWhite, 0xffdead },
{ c_HtmlNameNavy, 0x80 },
{ c_HtmlNameOldLace, 0xfdf5e6 },
{ c_HtmlNameOlive, 0x808000 },
{ c_HtmlNameOliveDrab, 0x6b8e23 },
{ c_HtmlNameOrange, 0xffa500 },
{ c_HtmlNameOrangeRed, 0xff4500 },
{ c_HtmlNameOrchid, 0xda70d6 },
{ c_HtmlNamePaleGoldenrod, 0xeee8aa },
{ c_HtmlNamePaleGreen, 0x98fb98 },
{ c_HtmlNamePaleTurquoise, 0xafeeee },
{ c_HtmlNamePaleVioletRed, 0xd87093 },
{ c_HtmlNamePapayaWhip, 0xffefd5 },
{ c_HtmlNamePeachPuff, 0xffdab9 },
{ c_HtmlNamePeru, 0xcd853f },
{ c_HtmlNamePink, 0xffc0cb },
{ c_HtmlNamePlum, 0xdda0dd },
{ c_HtmlNamePowderBlue, 0xb0e0e6 },
{ c_HtmlNamePurple, 0x800080 },
{ c_HtmlNameRed, 0xff0000 },
{ c_HtmlNameRosyBrown, 0xbc8f8f },
{ c_HtmlNameRoyalBlue, 0x4169e1 },
{ c_HtmlNameSaddleBrown, 0x8b4513 },
{ c_HtmlNameSalmon, 0xfa8072 },
{ c_HtmlNameSandyBrown, 0xf4a460 },
{ c_HtmlNameSeaGreen, 0x2e8b57 },
{ c_HtmlNameSeaShell, 0xfff5ee },
{ c_HtmlNameSienna, 0xa0522d },
{ c_HtmlNameSilver, 0xc0c0c0 },
{ c_HtmlNameSkyBlue, 0x87ceeb },
{ c_HtmlNameSlateBlue, 0x6a5acd },
{ c_HtmlNameSlateGray, 0x708090 },
{ c_HtmlNameSlateGrey, 0x708090 },
{ c_HtmlNameSnow, 0xfffafa },
{ c_HtmlNameSpringGreen, 0xff7f },
{ c_HtmlNameSteelBlue, 0x4682b4 },
{ c_HtmlNameTan, 0xd2b48c },
{ c_HtmlNameTeal, 0x8080 },
{ c_HtmlNameThistle, 0xd8bfd8 },
{ c_HtmlNameTomato, 0xff6347 },
{ c_HtmlNameTurquoise, 0x40e0d0 },
{ c_HtmlNameViolet, 0xee82ee },
{ c_HtmlNameWheat, 0xf5deb3 },
{ c_HtmlNameWhite, 0xffffff },
{ c_HtmlNameWhiteSmoke, 0xf5f5f5 },
{ c_HtmlNameYellow, 0xffff00 },
{ c_HtmlNameYellowGreen, 0x9acd32 },
};
const HtmlColorPair* HtmlColorNames::Pair(uint8_t index)
{
return &c_ColorNames[index];
}
uint8_t HtmlColorNames::Count()
{
return countof(c_ColorNames);
}

View File

@ -1,59 +0,0 @@
/*-------------------------------------------------------------------------
HtmlShortColorNames provides a template class for access to the short name table
Written by Michael C. Miller.
I invest time and resources providing this open source code,
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
-------------------------------------------------------------------------
This file is part of the Makuna/NeoPixelBus library.
NeoPixelBus is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
NeoPixelBus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with NeoPixel. If not, see
<http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------*/
#include "HtmlColor.h"
#include "HtmlColorNameStrings.h"
static const HtmlColorPair c_ShortColorNames[] PROGMEM = {
{ c_HtmlNameAqua, 0xffff },
{ c_HtmlNameBlack, 0x0 },
{ c_HtmlNameBlue, 0xff },
{ c_HtmlNameFuchsia, 0xff00ff },
{ c_HtmlNameGray, 0x808080 },
{ c_HtmlNameGreen, 0x8000 },
{ c_HtmlNameLime, 0xff00 },
{ c_HtmlNameMaroon, 0x800000 },
{ c_HtmlNameNavy, 0x80 },
{ c_HtmlNameOlive, 0x808000 },
{ c_HtmlNameOrange, 0xffa500 },
{ c_HtmlNamePurple, 0x800080 },
{ c_HtmlNameRed, 0xff0000 },
{ c_HtmlNameSilver, 0xc0c0c0 },
{ c_HtmlNameTeal, 0x8080 },
{ c_HtmlNameWhite, 0xffffff },
{ c_HtmlNameYellow, 0xffff00 },
};
const HtmlColorPair* HtmlShortColorNames::Pair(uint8_t index)
{
return &c_ShortColorNames[index];
}
uint8_t HtmlShortColorNames::Count()
{
return countof(c_ShortColorNames);
}

View File

@ -84,18 +84,6 @@ public:
}
}
static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count)
{
uint8_t* pEnd = pPixelDest + (count * PixelSize);
const uint8_t* pSrc = (const uint8_t*)pPixelSrc;
while (pPixelDest < pEnd)
{
*pPixelDest++ = pgm_read_byte(pSrc++);
*pPixelDest++ = pgm_read_byte(pSrc++);
*pPixelDest++ = pgm_read_byte(pSrc++);
}
}
static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
{
uint8_t* pDestBack = pPixelDest + (count * PixelSize);
@ -134,19 +122,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.B = (pgm_read_byte(p++)) << 1;
color.R = (pgm_read_byte(p++)) << 1;
color.G = (pgm_read_byte(p)) << 1;
return color;
}
};
class Lpd8806GrbFeature : public Lpd88063Elements
@ -172,18 +147,5 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.G = (pgm_read_byte(p++)) << 1;
color.R = (pgm_read_byte(p++)) << 1;
color.B = (pgm_read_byte(p)) << 1;
return color;
}
};

View File

@ -118,7 +118,7 @@ private:
typedef Lpd8806MethodBase<TwoWireBitBangImple> Lpd8806Method;
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) && !defined(ESP32)
#include "TwoWireSpiImple.h"
typedef Lpd8806MethodBase<TwoWireSpiImple<SpiSpeed20Mhz>> Lpd8806Spi20MhzMethod;
typedef Lpd8806MethodBase<TwoWireSpiImple<SpiSpeed10Mhz>> Lpd8806Spi10MhzMethod;

View File

@ -61,16 +61,6 @@ public:
}
}
static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count)
{
uint8_t* pEnd = pPixelDest + (count * PixelSize);
const uint8_t* pSrc = (const uint8_t*)pPixelSrc;
while (pPixelDest < pEnd)
{
*pPixelDest++ = pgm_read_byte(pSrc++);
}
}
static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
{
uint8_t* pDestBack = pPixelDest + (count * PixelSize);
@ -121,17 +111,6 @@ public:
}
}
static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count)
{
uint32_t* pDest = (uint32_t*)pPixelDest;
const uint32_t* pSrc = (const uint32_t*)pPixelSrc;
uint32_t* pEnd = pDest + count;
while (pDest < pEnd)
{
*pDest++ = pgm_read_dword(pSrc++);
}
}
static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
{
uint32_t* pDest = (uint32_t*)pPixelDest;
@ -212,20 +191,7 @@ public:
color.B = *p;
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.G = pgm_read_byte(p++);
color.R = pgm_read_byte(p++);
color.B = pgm_read_byte(p);
return color;
}
}
};
class NeoGrbwFeature : public Neo4ElementsNoSettings
@ -254,20 +220,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.G = pgm_read_byte(p++);
color.R = pgm_read_byte(p++);
color.B = pgm_read_byte(p++);
color.W = pgm_read_byte(p);
return color;
}
};
class NeoRgbwFeature : public Neo4ElementsNoSettings
@ -295,20 +247,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.R = pgm_read_byte(p++);
color.G = pgm_read_byte(p++);
color.B = pgm_read_byte(p++);
color.W = pgm_read_byte(p);
return color;
}
};
class NeoRgbFeature : public Neo3ElementsNoSettings
@ -334,19 +272,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.R = pgm_read_byte(p++);
color.G = pgm_read_byte(p++);
color.B = pgm_read_byte(p);
return color;
}
};
class NeoBrgFeature : public Neo3ElementsNoSettings
@ -372,19 +297,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.B = pgm_read_byte(p++);
color.R = pgm_read_byte(p++);
color.G = pgm_read_byte(p);
return color;
}
};
class NeoRbgFeature : public Neo3ElementsNoSettings
@ -410,18 +322,4 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.R = pgm_read_byte(p++);
color.B = pgm_read_byte(p++);
color.G = pgm_read_byte(p);
return color;
}
};

View File

@ -28,11 +28,9 @@ License along with NeoPixel. If not, see
#ifdef ARDUINO_ARCH_ESP32
extern "C"
{
#include <Arduino.h>
#include <esp_log.h>
#include "Esp32_i2s.h"
}
const uint16_t c_dmaBytesPerPixelBytes = 4;
@ -170,7 +168,9 @@ public:
FillBuffers();
i2sWrite(T_BUS::I2sBusNumber, _i2sBuffer, _i2sBufferSize, false, false);
const auto written = i2sWrite(T_BUS::I2sBusNumber, _i2sBuffer, _i2sBufferSize, false, false);
if (written != _i2sBufferSize)
ESP_LOGW("NEOPIXL", "written != bufferSize %zd %u", written, _i2sBufferSize);
}
uint8_t* getData() const
@ -273,4 +273,4 @@ typedef NeoEsp32I2s1Ws2812xInvertedMethod Neo800KbpsInvertedMethod;
typedef NeoEsp32I2s1400KbpsInvertedMethod Neo400KbpsInvertedMethod;
*/
#endif
#endif

View File

@ -305,7 +305,7 @@ public:
// Need 100% focus on instruction timing
#if defined(ARDUINO_ARCH_ESP32)
delay(1); // required
vTaskDelay(1 / portTICK_PERIOD_MS); // required
portMUX_TYPE updateMux = portMUX_INITIALIZER_UNLOCKED;
portENTER_CRITICAL(&updateMux);
@ -398,4 +398,4 @@ typedef NeoEsp8266BitBang400KbpsInvertedMethod NeoEsp8266BitBangApa106InvertedMe
#endif
// ESP bitbang doesn't have defaults and should avoided except for testing
#endif
#endif

View File

@ -61,16 +61,6 @@ public:
}
}
static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count)
{
uint8_t* pEnd = pPixelDest + (count * PixelSize);
const uint8_t* pSrc = (const uint8_t*)pPixelSrc;
while (pPixelDest < pEnd)
{
*pPixelDest++ = pgm_read_byte(pSrc++);
}
}
static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
{
uint8_t* pDestBack = pPixelDest + (count * PixelSize);
@ -110,21 +100,6 @@ public:
}
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
uint8_t commonSize = (PixelSize < color.SegmentCount) ? PixelSize : color.SegmentCount;
for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++)
{
color.Segment[iSegment] = pgm_read_byte(p++);
}
return color;
}
};
typedef NeoAbcdefgSegmentFeature SevenSegmentFeature; // Abcdefg order is default
typedef NeoAbcdefgSegmentFeature SevenSegmentFeature; // Abcdefg order is default

View File

@ -25,6 +25,8 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
#include <cstdint>
class NeoNoSettings
{
};
@ -59,4 +61,4 @@ public:
uint16_t GreenTenthMilliAmpere; // in 1/10th ma
uint16_t BlueTenthMilliAmpere; // in 1/10th ma
uint16_t WhiteCurrent; // in 1/10th ma
};
};

View File

@ -113,19 +113,5 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.W = pgm_read_byte(p++);
color.R = pgm_read_byte(p++);
color.G = pgm_read_byte(p++);
color.B = pgm_read_byte(p);
return color;
}
};

View File

@ -64,19 +64,6 @@ public:
}
}
static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count)
{
uint8_t* pEnd = pPixelDest + (count * PixelSize);
const uint8_t* pSrc = (const uint8_t*)pPixelSrc;
while (pPixelDest < pEnd)
{
*pPixelDest++ = pgm_read_byte(pSrc++);
*pPixelDest++ = pgm_read_byte(pSrc++);
*pPixelDest++ = pgm_read_byte(pSrc++);
*pPixelDest++ = pgm_read_byte(pSrc++);
}
}
static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
{
uint8_t* pDestBack = pPixelDest + (count * PixelSize);
@ -139,20 +126,6 @@ public:
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
pgm_read_byte(p++); // ignore the first byte
color.B = pgm_read_byte(p++);
color.G = pgm_read_byte(p++);
color.R = pgm_read_byte(p);
return color;
}
};

View File

@ -114,7 +114,7 @@ private:
typedef P9813MethodBase<TwoWireBitBangImple> P9813Method;
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) && !defined(ESP32)
#include "TwoWireSpiImple.h"
typedef P9813MethodBase<TwoWireSpiImple<SpiSpeed20Mhz>> P9813Spi20MhzMethod;
typedef P9813MethodBase<TwoWireSpiImple<SpiSpeed10Mhz>> P9813Spi10MhzMethod;

View File

@ -1,261 +0,0 @@
/*-------------------------------------------------------------------------
RgbColor provides a color object that can be directly consumed by NeoPixelBus
Written by Michael C. Miller.
I invest time and resources providing this open source code,
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
-------------------------------------------------------------------------
This file is part of the Makuna/NeoPixelBus library.
NeoPixelBus is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
NeoPixelBus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with NeoPixel. If not, see
<http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------*/
#include "RgbColor.h"
#include "HslColor.h"
#include "HsbColor.h"
#include "HtmlColor.h"
static float _CalcColor(float p, float q, float t)
{
if (t < 0.0f)
t += 1.0f;
if (t > 1.0f)
t -= 1.0f;
if (t < 1.0f / 6.0f)
return p + (q - p) * 6.0f * t;
if (t < 0.5f)
return q;
if (t < 2.0f / 3.0f)
return p + ((q - p) * (2.0f / 3.0f - t) * 6.0f);
return p;
}
RgbColor::RgbColor(const HtmlColor& color)
{
uint32_t temp = color.Color;
B = (temp & 0xff);
temp = temp >> 8;
G = (temp & 0xff);
temp = temp >> 8;
R = (temp & 0xff);
};
RgbColor::RgbColor(const HslColor& color)
{
float r;
float g;
float b;
float h = color.H;
float s = color.S;
float l = color.L;
if (color.S == 0.0f || color.L == 0.0f)
{
r = g = b = l; // achromatic or black
}
else
{
float q = l < 0.5f ? l * (1.0f + s) : l + s - (l * s);
float p = 2.0f * l - q;
r = _CalcColor(p, q, h + 1.0f / 3.0f);
g = _CalcColor(p, q, h);
b = _CalcColor(p, q, h - 1.0f / 3.0f);
}
R = (uint8_t)(r * 255.0f);
G = (uint8_t)(g * 255.0f);
B = (uint8_t)(b * 255.0f);
}
RgbColor::RgbColor(const HsbColor& color)
{
float r;
float g;
float b;
float h = color.H;
float s = color.S;
float v = color.B;
if (color.S == 0.0f)
{
r = g = b = v; // achromatic or black
}
else
{
if (h < 0.0f)
{
h += 1.0f;
}
else if (h >= 1.0f)
{
h -= 1.0f;
}
h *= 6.0f;
int i = (int)h;
float f = h - i;
float q = v * (1.0f - s * f);
float p = v * (1.0f - s);
float t = v * (1.0f - s * (1.0f - f));
switch (i)
{
case 0:
r = v;
g = t;
b = p;
break;
case 1:
r = q;
g = v;
b = p;
break;
case 2:
r = p;
g = v;
b = t;
break;
case 3:
r = p;
g = q;
b = v;
break;
case 4:
r = t;
g = p;
b = v;
break;
default:
r = v;
g = p;
b = q;
break;
}
}
R = (uint8_t)(r * 255.0f);
G = (uint8_t)(g * 255.0f);
B = (uint8_t)(b * 255.0f);
}
uint8_t RgbColor::CalculateBrightness() const
{
return (uint8_t)(((uint16_t)R + (uint16_t)G + (uint16_t)B) / 3);
}
RgbColor RgbColor::Dim(uint8_t ratio) const
{
// specifically avoids float math
return RgbColor(_elementDim(R, ratio), _elementDim(G, ratio), _elementDim(B, ratio));
}
RgbColor RgbColor::Brighten(uint8_t ratio) const
{
// specifically avoids float math
return RgbColor(_elementBrighten(R, ratio), _elementBrighten(G, ratio), _elementBrighten(B, ratio));
}
void RgbColor::Darken(uint8_t delta)
{
if (R > delta)
{
R -= delta;
}
else
{
R = 0;
}
if (G > delta)
{
G -= delta;
}
else
{
G = 0;
}
if (B > delta)
{
B -= delta;
}
else
{
B = 0;
}
}
void RgbColor::Lighten(uint8_t delta)
{
if (R < 255 - delta)
{
R += delta;
}
else
{
R = 255;
}
if (G < 255 - delta)
{
G += delta;
}
else
{
G = 255;
}
if (B < 255 - delta)
{
B += delta;
}
else
{
B = 255;
}
}
RgbColor RgbColor::LinearBlend(const RgbColor& left, const RgbColor& right, float progress)
{
return RgbColor( left.R + ((right.R - left.R) * progress),
left.G + ((right.G - left.G) * progress),
left.B + ((right.B - left.B) * progress));
}
RgbColor RgbColor::BilinearBlend(const RgbColor& c00,
const RgbColor& c01,
const RgbColor& c10,
const RgbColor& c11,
float x,
float y)
{
float v00 = (1.0f - x) * (1.0f - y);
float v10 = x * (1.0f - y);
float v01 = (1.0f - x) * y;
float v11 = x * y;
return RgbColor(
c00.R * v00 + c10.R * v10 + c01.R * v01 + c11.R * v11,
c00.G * v00 + c10.G * v10 + c01.G * v01 + c11.G * v11,
c00.B * v00 + c10.B * v10 + c01.B * v01 + c11.B * v11);
}

View File

@ -25,111 +25,98 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
#include <Arduino.h>
#include <cstdint>
#include <cstdlib>
#include <algorithm>
#include "NeoSettings.h"
struct HslColor;
struct HsbColor;
struct HtmlColor;
// ------------------------------------------------------------------------
// RgbColor represents a color object that is represented by Red, Green, Blue
// component values. It contains helpful color routines to manipulate the
// component values. It contains helpful color routines to manipulate the
// color.
// ------------------------------------------------------------------------
struct RgbColor
{
typedef NeoRgbCurrentSettings SettingsObject;
using SettingsObject = NeoRgbCurrentSettings;
// ------------------------------------------------------------------------
// Construct a RgbColor that will have its values set in latter operations
// ------------------------------------------------------------------------
constexpr RgbColor();
// ------------------------------------------------------------------------
// Construct a RgbColor using R, G, B values (0-255)
// ------------------------------------------------------------------------
RgbColor(uint8_t r, uint8_t g, uint8_t b) :
R(r), G(g), B(b)
{
};
constexpr RgbColor(uint8_t r, uint8_t g, uint8_t b);
// ------------------------------------------------------------------------
// Construct a RgbColor using a single brightness value (0-255)
// This works well for creating gray tone colors
// (0) = black, (255) = white, (128) = gray
// ------------------------------------------------------------------------
RgbColor(uint8_t brightness) :
R(brightness), G(brightness), B(brightness)
{
};
// ------------------------------------------------------------------------
// Construct a RgbColor using HtmlColor
// ------------------------------------------------------------------------
RgbColor(const HtmlColor& color);
constexpr RgbColor(uint8_t brightness);
// ------------------------------------------------------------------------
// Construct a RgbColor using HslColor
// ------------------------------------------------------------------------
RgbColor(const HslColor& color);
constexpr RgbColor(const RgbColor& color);
// ------------------------------------------------------------------------
// Construct a RgbColor using HslColor
// ------------------------------------------------------------------------
constexpr RgbColor(const HslColor& color);
// ------------------------------------------------------------------------
// Construct a RgbColor using HsbColor
// ------------------------------------------------------------------------
RgbColor(const HsbColor& color);
// ------------------------------------------------------------------------
// Construct a RgbColor that will have its values set in latter operations
// CAUTION: The R,G,B members are not initialized and may not be consistent
// ------------------------------------------------------------------------
RgbColor()
{
};
constexpr RgbColor(const HsbColor& color);
// ------------------------------------------------------------------------
// Comparison operators
// ------------------------------------------------------------------------
bool operator==(const RgbColor& other) const
{
return (R == other.R && G == other.G && B == other.B);
};
constexpr bool operator==(const RgbColor& other) const;
bool operator!=(const RgbColor& other) const
{
return !(*this == other);
};
constexpr bool operator!=(const RgbColor& other) const;
// ------------------------------------------------------------------------
// CalculateBrightness will calculate the overall brightness
// NOTE: This is a simple linear brightness
// ------------------------------------------------------------------------
uint8_t CalculateBrightness() const;
constexpr uint8_t CalculateBrightness() const;
// ------------------------------------------------------------------------
// Dim will return a new color that is blended to black with the given ratio
// ratio - (0-255) where 255 will return the original color and 0 will return black
//
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
RgbColor Dim(uint8_t ratio) const;
constexpr RgbColor Dim(uint8_t ratio) const;
// ------------------------------------------------------------------------
// Brighten will return a new color that is blended to white with the given ratio
// ratio - (0-255) where 255 will return the original color and 0 will return white
//
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
RgbColor Brighten(uint8_t ratio) const;
constexpr RgbColor Brighten(uint8_t ratio) const;
// ------------------------------------------------------------------------
// Darken will adjust the color by the given delta toward black
// NOTE: This is a simple linear change
// delta - (0-255) the amount to dim the color
// ------------------------------------------------------------------------
void Darken(uint8_t delta);
constexpr void Darken(uint8_t delta);
// ------------------------------------------------------------------------
// Lighten will adjust the color by the given delta toward white
// NOTE: This is a simple linear change
// delta - (0-255) the amount to lighten the color
// ------------------------------------------------------------------------
void Lighten(uint8_t delta);
constexpr void Lighten(uint8_t delta);
// ------------------------------------------------------------------------
// LinearBlend between two colors by the amount defined by progress variable
@ -138,8 +125,8 @@ struct RgbColor
// progress - (0.0 - 1.0) value where 0 will return left and 1.0 will return right
// and a value between will blend the color weighted linearly between them
// ------------------------------------------------------------------------
static RgbColor LinearBlend(const RgbColor& left, const RgbColor& right, float progress);
static constexpr RgbColor LinearBlend(const RgbColor& left, const RgbColor& right, float progress);
// ------------------------------------------------------------------------
// BilinearBlend between four colors by the amount defined by 2d variable
// c00 - upper left quadrant color
@ -149,51 +136,310 @@ struct RgbColor
// x - unit value (0.0 - 1.0) that defines the blend progress in horizontal space
// y - unit value (0.0 - 1.0) that defines the blend progress in vertical space
// ------------------------------------------------------------------------
static RgbColor BilinearBlend(const RgbColor& c00,
const RgbColor& c01,
const RgbColor& c10,
const RgbColor& c11,
float x,
static constexpr RgbColor BilinearBlend(const RgbColor& c00,
const RgbColor& c01,
const RgbColor& c10,
const RgbColor& c11,
float x,
float y);
uint32_t CalcTotalTenthMilliAmpere(const SettingsObject& settings)
{
auto total = 0;
total += R * settings.RedTenthMilliAmpere / 255;
total += G * settings.GreenTenthMilliAmpere / 255;
total += B * settings.BlueTenthMilliAmpere / 255;
return total;
}
constexpr uint32_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) const;
// ------------------------------------------------------------------------
// Red, Green, Blue color members (0-255) where
// Red, Green, Blue color members (0-255) where
// (0,0,0) is black and (255,255,255) is white
// ------------------------------------------------------------------------
uint8_t R;
uint8_t G;
uint8_t B;
uint8_t R{};
uint8_t G{};
uint8_t B{};
private:
inline static uint8_t _elementDim(uint8_t value, uint8_t ratio)
{
return (static_cast<uint16_t>(value) * (static_cast<uint16_t>(ratio) + 1)) >> 8;
}
inline static uint8_t _elementBrighten(uint8_t value, uint8_t ratio)
{
uint16_t element = ((static_cast<uint16_t>(value) + 1) << 8) / (static_cast<uint16_t>(ratio) + 1);
if (element > 255)
{
element = 255;
}
else
{
element -= 1;
}
return element;
}
inline static constexpr uint8_t _elementDim(uint8_t value, uint8_t ratio);
inline static constexpr uint8_t _elementBrighten(uint8_t value, uint8_t ratio);
inline static constexpr float _CalcColor(float p, float q, float t);
inline static constexpr RgbColor convertToRgbColor(const HslColor& color);
inline static constexpr RgbColor convertToRgbColor(HsbColor color);
inline static constexpr bool fuzzyCompare(double p1, double p2);
inline static constexpr bool fuzzyCompare(float p1, float p2);
};
#include "HslColor.h"
#include "HsbColor.h"
constexpr RgbColor::RgbColor() = default;
constexpr RgbColor::RgbColor(uint8_t r, uint8_t g, uint8_t b) :
R{r}, G{g}, B{b}
{
}
constexpr RgbColor::RgbColor(uint8_t brightness) :
R{brightness}, G{brightness}, B{brightness}
{
}
constexpr RgbColor::RgbColor(const RgbColor& color) = default;
constexpr RgbColor::RgbColor(const HslColor& color) :
RgbColor{convertToRgbColor(color)}
{
}
constexpr RgbColor::RgbColor(const HsbColor& color) :
RgbColor{convertToRgbColor(color)}
{
}
constexpr bool RgbColor::operator==(const RgbColor& other) const
{
return (R == other.R && G == other.G && B == other.B);
};
constexpr bool RgbColor::operator!=(const RgbColor& other) const
{
return !(*this == other);
};
constexpr uint8_t RgbColor::CalculateBrightness() const
{
return (uint8_t)(((uint16_t)R + (uint16_t)G + (uint16_t)B) / 3);
}
constexpr RgbColor RgbColor::Dim(uint8_t ratio) const
{
// specifically avoids float math
return RgbColor(_elementDim(R, ratio), _elementDim(G, ratio), _elementDim(B, ratio));
}
constexpr RgbColor RgbColor::Brighten(uint8_t ratio) const
{
// specifically avoids float math
return RgbColor(_elementBrighten(R, ratio), _elementBrighten(G, ratio), _elementBrighten(B, ratio));
}
constexpr void RgbColor::Darken(uint8_t delta)
{
if (R > delta)
{
R -= delta;
}
else
{
R = 0;
}
if (G > delta)
{
G -= delta;
}
else
{
G = 0;
}
if (B > delta)
{
B -= delta;
}
else
{
B = 0;
}
}
constexpr void RgbColor::Lighten(uint8_t delta)
{
if (R < 255 - delta)
{
R += delta;
}
else
{
R = 255;
}
if (G < 255 - delta)
{
G += delta;
}
else
{
G = 255;
}
if (B < 255 - delta)
{
B += delta;
}
else
{
B = 255;
}
}
constexpr RgbColor RgbColor::LinearBlend(const RgbColor& left, const RgbColor& right, float progress)
{
return RgbColor( left.R + ((right.R - left.R) * progress),
left.G + ((right.G - left.G) * progress),
left.B + ((right.B - left.B) * progress));
}
constexpr RgbColor RgbColor::BilinearBlend(const RgbColor& c00,
const RgbColor& c01,
const RgbColor& c10,
const RgbColor& c11,
float x,
float y)
{
float v00 = (1.0f - x) * (1.0f - y);
float v10 = x * (1.0f - y);
float v01 = (1.0f - x) * y;
float v11 = x * y;
return RgbColor(
c00.R * v00 + c10.R * v10 + c01.R * v01 + c11.R * v11,
c00.G * v00 + c10.G * v10 + c01.G * v01 + c11.G * v11,
c00.B * v00 + c10.B * v10 + c01.B * v01 + c11.B * v11);
}
constexpr uint32_t RgbColor::CalcTotalTenthMilliAmpere(const SettingsObject& settings) const
{
auto total = 0;
total += R * settings.RedTenthMilliAmpere / 255;
total += G * settings.GreenTenthMilliAmpere / 255;
total += B * settings.BlueTenthMilliAmpere / 255;
return total;
}
constexpr uint8_t RgbColor::_elementDim(uint8_t value, uint8_t ratio)
{
return (static_cast<uint16_t>(value) * (static_cast<uint16_t>(ratio) + 1)) >> 8;
}
constexpr uint8_t RgbColor::_elementBrighten(uint8_t value, uint8_t ratio)
{
uint16_t element = ((static_cast<uint16_t>(value) + 1) << 8) / (static_cast<uint16_t>(ratio) + 1);
if (element > 255)
{
element = 255;
}
else
{
element -= 1;
}
return element;
}
constexpr float RgbColor::_CalcColor(float p, float q, float t)
{
if (t < 0.0f)
t += 1.0f;
if (t > 1.0f)
t -= 1.0f;
if (t < 1.0f / 6.0f)
return p + (q - p) * 6.0f * t;
if (t < 0.5f)
return q;
if (t < 2.0f / 3.0f)
return p + ((q - p) * (2.0f / 3.0f - t) * 6.0f);
return p;
}
constexpr RgbColor RgbColor::convertToRgbColor(const HslColor& color)
{
float r{};
float g{};
float b{};
float h = color.H;
float s = color.S;
float l = color.L;
if (color.S == 0.0f || color.L == 0.0f)
{
r = g = b = l; // achromatic or black
}
else
{
float q = l < 0.5f ? l * (1.0f + s) : l + s - (l * s);
float p = 2.0f * l - q;
r = _CalcColor(p, q, h + 1.0f / 3.0f);
g = _CalcColor(p, q, h);
b = _CalcColor(p, q, h - 1.0f / 3.0f);
}
return RgbColor{(uint8_t)(r * 255.0f), (uint8_t)(g * 255.0f), (uint8_t)(b * 255.0f)};
}
constexpr RgbColor RgbColor::convertToRgbColor(HsbColor color)
{
if (fuzzyCompare(color.S, 0.0f))
return RgbColor{uint8_t(color.B), uint8_t(color.B), uint8_t(color.B)}; // achromatic or black
RgbColor rgb{};
if (color.H < 0.0f)
color.H += 1.0f;
else if (color.H >= 1.0f)
color.H -= 1.0f;
color.H *= 6.0f;
int i = (int)color.H;
float f = color.H - i;
float q = color.B * (1.0f - color.S * f);
float p = color.B * (1.0f - color.S);
float t = color.B * (1.0f - color.S * (1.0f - f));
switch (i)
{
case 0:
rgb.R = color.B;
rgb.G = t;
rgb.B = p;
break;
case 1:
rgb.R = q;
rgb.G = color.B;
rgb.B = p;
break;
case 2:
rgb.R = p;
rgb.G = color.B;
rgb.B = t;
break;
case 3:
rgb.R = p;
rgb.G = q;
rgb.B = color.B;
break;
case 4:
rgb.R = t;
rgb.G = p;
rgb.B = color.B;
break;
default:
rgb.R = color.B;
rgb.G = p;
rgb.B = q;
break;
}
return rgb;
}
constexpr bool RgbColor::fuzzyCompare(double p1, double p2)
{
return (std::abs(p1 - p2) * 1000000000000. <= std::min(std::abs(p1), std::abs(p2)));
}
constexpr bool RgbColor::fuzzyCompare(float p1, float p2)
{
return (std::abs(p1 - p2) * 100000.f <= std::min(std::abs(p1), std::abs(p2)));
}

View File

@ -1,190 +0,0 @@
/*-------------------------------------------------------------------------
RgbwColor provides a color object that can be directly consumed by NeoPixelBus
Written by Michael C. Miller.
I invest time and resources providing this open source code,
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
-------------------------------------------------------------------------
This file is part of the Makuna/NeoPixelBus library.
NeoPixelBus is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
NeoPixelBus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with NeoPixel. If not, see
<http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------*/
#include "RgbColor.h"
#include "HslColor.h"
#include "HsbColor.h"
#include "RgbwColor.h"
#include "HtmlColor.h"
RgbwColor::RgbwColor(const HtmlColor& color)
{
uint32_t temp = color.Color;
B = (temp & 0xff);
temp = temp >> 8;
G = (temp & 0xff);
temp = temp >> 8;
R = (temp & 0xff);
temp = temp >> 8;
W = (temp & 0xff);
};
RgbwColor::RgbwColor(const HslColor& color)
{
RgbColor rgbColor(color);
*this = rgbColor;
}
RgbwColor::RgbwColor(const HsbColor& color)
{
RgbColor rgbColor(color);
*this = rgbColor;
}
uint8_t RgbwColor::CalculateBrightness() const
{
uint8_t colorB = (uint8_t)(((uint16_t)R + (uint16_t)G + (uint16_t)B) / 3);
if (W > colorB)
{
return W;
}
else
{
return colorB;
}
}
RgbwColor RgbwColor::Dim(uint8_t ratio) const
{
// specifically avoids float math
return RgbwColor(_elementDim(R, ratio), _elementDim(G, ratio), _elementDim(B, ratio), _elementDim(W, ratio));
}
RgbwColor RgbwColor::Brighten(uint8_t ratio) const
{
// specifically avoids float math
return RgbwColor(_elementBrighten(R, ratio), _elementBrighten(G, ratio), _elementBrighten(B, ratio), _elementBrighten(W, ratio));
}
void RgbwColor::Darken(uint8_t delta)
{
if (R > delta)
{
R -= delta;
}
else
{
R = 0;
}
if (G > delta)
{
G -= delta;
}
else
{
G = 0;
}
if (B > delta)
{
B -= delta;
}
else
{
B = 0;
}
if (W > delta)
{
W -= delta;
}
else
{
W = 0;
}
}
void RgbwColor::Lighten(uint8_t delta)
{
if (IsColorLess())
{
if (W < 255 - delta)
{
W += delta;
}
else
{
W = 255;
}
}
else
{
if (R < 255 - delta)
{
R += delta;
}
else
{
R = 255;
}
if (G < 255 - delta)
{
G += delta;
}
else
{
G = 255;
}
if (B < 255 - delta)
{
B += delta;
}
else
{
B = 255;
}
}
}
RgbwColor RgbwColor::LinearBlend(const RgbwColor& left, const RgbwColor& right, float progress)
{
return RgbwColor( left.R + ((right.R - left.R) * progress),
left.G + ((right.G - left.G) * progress),
left.B + ((right.B - left.B) * progress),
left.W + ((right.W - left.W) * progress) );
}
RgbwColor RgbwColor::BilinearBlend(const RgbwColor& c00,
const RgbwColor& c01,
const RgbwColor& c10,
const RgbwColor& c11,
float x,
float y)
{
float v00 = (1.0f - x) * (1.0f - y);
float v10 = x * (1.0f - y);
float v01 = (1.0f - x) * y;
float v11 = x * y;
return RgbwColor(
c00.R * v00 + c10.R * v10 + c01.R * v01 + c11.R * v11,
c00.G * v00 + c10.G * v10 + c01.G * v01 + c11.G * v11,
c00.B * v00 + c10.B * v10 + c01.B * v01 + c11.B * v11,
c00.W * v00 + c10.W * v10 + c01.W * v01 + c11.W * v11 );
}

View File

@ -25,7 +25,9 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
#include <Arduino.h>
#include <cstdint>
#include "NeoSettings.h"
struct RgbColor;
struct HslColor;
@ -38,95 +40,68 @@ struct HsbColor;
// ------------------------------------------------------------------------
struct RgbwColor
{
typedef NeoRgbwCurrentSettings SettingsObject;
using SettingsObject = NeoRgbwCurrentSettings;
// ------------------------------------------------------------------------
// Construct a RgbwColor that will have its values set in latter operations
// ------------------------------------------------------------------------
constexpr RgbwColor();
// ------------------------------------------------------------------------
// Construct a RgbwColor using R, G, B, W values (0-255)
// ------------------------------------------------------------------------
RgbwColor(uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0) :
R(r), G(g), B(b), W(w)
{
};
constexpr RgbwColor(uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0);
// ------------------------------------------------------------------------
// Construct a RgbColor using a single brightness value (0-255)
// This works well for creating gray tone colors
// (0) = black, (255) = white, (128) = gray
// ------------------------------------------------------------------------
RgbwColor(uint8_t brightness) :
R(0), G(0), B(0), W(brightness)
{
};
constexpr RgbwColor(uint8_t brightness);
// ------------------------------------------------------------------------
// Construct a RgbwColor using RgbwColor
// ------------------------------------------------------------------------
constexpr RgbwColor(const RgbwColor& color);
// ------------------------------------------------------------------------
// Construct a RgbwColor using RgbColor
// ------------------------------------------------------------------------
RgbwColor(const RgbColor& color) :
R(color.R),
G(color.G),
B(color.B),
W(0)
{
};
// ------------------------------------------------------------------------
// Construct a RgbwColor using HtmlColor
// ------------------------------------------------------------------------
RgbwColor(const HtmlColor& color);
constexpr RgbwColor(const RgbColor& color);
// ------------------------------------------------------------------------
// Construct a RgbwColor using HslColor
// ------------------------------------------------------------------------
RgbwColor(const HslColor& color);
constexpr RgbwColor(const HslColor& color);
// ------------------------------------------------------------------------
// Construct a RgbwColor using HsbColor
// ------------------------------------------------------------------------
RgbwColor(const HsbColor& color);
// ------------------------------------------------------------------------
// Construct a RgbwColor that will have its values set in latter operations
// CAUTION: The R,G,B, W members are not initialized and may not be consistent
// ------------------------------------------------------------------------
RgbwColor()
{
};
constexpr RgbwColor(const HsbColor& color);
// ------------------------------------------------------------------------
// Comparison operators
// ------------------------------------------------------------------------
bool operator==(const RgbwColor& other) const
{
return (R == other.R && G == other.G && B == other.B && W == other.W);
};
constexpr bool operator==(const RgbwColor& other) const;
bool operator!=(const RgbwColor& other) const
{
return !(*this == other);
};
constexpr bool operator!=(const RgbwColor& other) const;
// ------------------------------------------------------------------------
// Returns if the color is grey, all values are equal other than white
// ------------------------------------------------------------------------
bool IsMonotone() const
{
return (R == B && R == G);
};
constexpr bool IsMonotone() const;
// ------------------------------------------------------------------------
// Returns if the color components are all zero, the white component maybe
// anything
// ------------------------------------------------------------------------
bool IsColorLess() const
{
return (R == 0 && B == 0 && G == 0);
};
constexpr bool IsColorLess() const;
// ------------------------------------------------------------------------
// CalculateBrightness will calculate the overall brightness
// NOTE: This is a simple linear brightness
// ------------------------------------------------------------------------
uint8_t CalculateBrightness() const;
constexpr uint8_t CalculateBrightness() const;
// ------------------------------------------------------------------------
// Dim will return a new color that is blended to black with the given ratio
@ -134,7 +109,7 @@ struct RgbwColor
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
RgbwColor Dim(uint8_t ratio) const;
constexpr RgbwColor Dim(uint8_t ratio) const;
// ------------------------------------------------------------------------
// Brighten will return a new color that is blended to white with the given ratio
@ -142,21 +117,21 @@ struct RgbwColor
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
RgbwColor Brighten(uint8_t ratio) const;
constexpr RgbwColor Brighten(uint8_t ratio) const;
// ------------------------------------------------------------------------
// Darken will adjust the color by the given delta toward black
// NOTE: This is a simple linear change
// delta - (0-255) the amount to dim the color
// ------------------------------------------------------------------------
void Darken(uint8_t delta);
constexpr void Darken(uint8_t delta);
// ------------------------------------------------------------------------
// Lighten will adjust the color by the given delta toward white
// NOTE: This is a simple linear change
// delta - (0-255) the amount to lighten the color
// ------------------------------------------------------------------------
void Lighten(uint8_t delta);
constexpr void Lighten(uint8_t delta);
// ------------------------------------------------------------------------
// LinearBlend between two colors by the amount defined by progress variable
@ -165,8 +140,8 @@ struct RgbwColor
// progress - (0.0 - 1.0) value where 0 will return left and 1.0 will return right
// and a value between will blend the color weighted linearly between them
// ------------------------------------------------------------------------
static RgbwColor LinearBlend(const RgbwColor& left, const RgbwColor& right, float progress);
static constexpr RgbwColor LinearBlend(const RgbwColor& left, const RgbwColor& right, float progress);
// ------------------------------------------------------------------------
// BilinearBlend between four colors by the amount defined by 2d variable
// c00 - upper left quadrant color
@ -176,54 +151,249 @@ struct RgbwColor
// x - unit value (0.0 - 1.0) that defines the blend progress in horizontal space
// y - unit value (0.0 - 1.0) that defines the blend progress in vertical space
// ------------------------------------------------------------------------
static RgbwColor BilinearBlend(const RgbwColor& c00,
static constexpr RgbwColor BilinearBlend(const RgbwColor& c00,
const RgbwColor& c01,
const RgbwColor& c10,
const RgbwColor& c11,
float x,
float y);
uint16_t CalcTotalTenthMilliAmpere(const SettingsObject& settings)
{
auto total = 0;
total += R * settings.RedTenthMilliAmpere / 255;
total += G * settings.GreenTenthMilliAmpere / 255;
total += B * settings.BlueTenthMilliAmpere / 255;
total += W * settings.WhiteCurrent / 255;
return total;
}
constexpr uint16_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) const;
// ------------------------------------------------------------------------
// Red, Green, Blue, White color members (0-255) where
// (0,0,0,0) is black and (255,255,255, 0) and (0,0,0,255) is white
// Note (255,255,255,255) is extreme bright white
// ------------------------------------------------------------------------
uint8_t R;
uint8_t G;
uint8_t B;
uint8_t W;
uint8_t R{};
uint8_t G{};
uint8_t B{};
uint8_t W{};
private:
inline static uint8_t _elementDim(uint8_t value, uint8_t ratio)
inline static constexpr uint8_t _elementDim(uint8_t value, uint8_t ratio);
inline static constexpr uint8_t _elementBrighten(uint8_t value, uint8_t ratio);
};
#include "RgbColor.h"
#include "HslColor.h"
#include "HsbColor.h"
constexpr RgbwColor::RgbwColor() = default;
constexpr RgbwColor::RgbwColor(uint8_t r, uint8_t g, uint8_t b, uint8_t w) :
R{r}, G{g}, B{b}, W{w}
{
}
constexpr RgbwColor::RgbwColor(uint8_t brightness) :
R{}, G{}, B{}, W{brightness}
{
}
constexpr RgbwColor::RgbwColor(const RgbwColor& color) = default;
constexpr RgbwColor::RgbwColor(const RgbColor& color) :
R{color.R},
G{color.G},
B{color.B},
W{}
{
}
constexpr RgbwColor::RgbwColor(const HslColor& color) :
RgbwColor{RgbColor{color}}
{
}
constexpr RgbwColor::RgbwColor(const HsbColor& color) :
RgbwColor{RgbColor{color}}
{
}
constexpr bool RgbwColor::operator==(const RgbwColor& other) const
{
return (R == other.R && G == other.G && B == other.B && W == other.W);
}
constexpr bool RgbwColor::operator!=(const RgbwColor& other) const
{
return !(*this == other);
}
constexpr bool RgbwColor::IsMonotone() const
{
return (R == B && R == G);
}
constexpr bool RgbwColor::IsColorLess() const
{
return (R == 0 && B == 0 && G == 0);
}
constexpr uint8_t RgbwColor::CalculateBrightness() const
{
uint8_t colorB = (uint8_t)(((uint16_t)R + (uint16_t)G + (uint16_t)B) / 3);
if (W > colorB)
{
return (static_cast<uint16_t>(value) * (static_cast<uint16_t>(ratio) + 1)) >> 8;
return W;
}
else
{
return colorB;
}
}
constexpr RgbwColor RgbwColor::Dim(uint8_t ratio) const
{
// specifically avoids float math
return RgbwColor{_elementDim(R, ratio), _elementDim(G, ratio), _elementDim(B, ratio), _elementDim(W, ratio)};
}
constexpr RgbwColor RgbwColor::Brighten(uint8_t ratio) const
{
// specifically avoids float math
return RgbwColor{_elementBrighten(R, ratio), _elementBrighten(G, ratio), _elementBrighten(B, ratio), _elementBrighten(W, ratio)};
}
constexpr void RgbwColor::Darken(uint8_t delta)
{
if (R > delta)
{
R -= delta;
}
else
{
R = 0;
}
inline static uint8_t _elementBrighten(uint8_t value, uint8_t ratio)
if (G > delta)
{
uint16_t element = ((static_cast<uint16_t>(value) + 1) << 8) / (static_cast<uint16_t>(ratio) + 1);
G -= delta;
}
else
{
G = 0;
}
if (element > 255)
if (B > delta)
{
B -= delta;
}
else
{
B = 0;
}
if (W > delta)
{
W -= delta;
}
else
{
W = 0;
}
}
constexpr void RgbwColor::Lighten(uint8_t delta)
{
if (IsColorLess())
{
if (W < 255 - delta)
{
element = 255;
W += delta;
}
else
{
element -= 1;
W = 255;
}
return element;
}
};
else
{
if (R < 255 - delta)
{
R += delta;
}
else
{
R = 255;
}
if (G < 255 - delta)
{
G += delta;
}
else
{
G = 255;
}
if (B < 255 - delta)
{
B += delta;
}
else
{
B = 255;
}
}
}
constexpr RgbwColor RgbwColor::LinearBlend(const RgbwColor& left, const RgbwColor& right, float progress)
{
return RgbwColor( left.R + ((right.R - left.R) * progress),
left.G + ((right.G - left.G) * progress),
left.B + ((right.B - left.B) * progress),
left.W + ((right.W - left.W) * progress) );
}
constexpr RgbwColor RgbwColor::BilinearBlend(const RgbwColor& c00,
const RgbwColor& c01,
const RgbwColor& c10,
const RgbwColor& c11,
float x,
float y)
{
float v00 = (1.0f - x) * (1.0f - y);
float v10 = x * (1.0f - y);
float v01 = (1.0f - x) * y;
float v11 = x * y;
return RgbwColor(
c00.R * v00 + c10.R * v10 + c01.R * v01 + c11.R * v11,
c00.G * v00 + c10.G * v10 + c01.G * v01 + c11.G * v11,
c00.B * v00 + c10.B * v10 + c01.B * v01 + c11.B * v11,
c00.W * v00 + c10.W * v10 + c01.W * v01 + c11.W * v11 );
}
constexpr uint16_t RgbwColor::CalcTotalTenthMilliAmpere(const SettingsObject& settings) const
{
auto total = 0;
total += R * settings.RedTenthMilliAmpere / 255;
total += G * settings.GreenTenthMilliAmpere / 255;
total += B * settings.BlueTenthMilliAmpere / 255;
total += W * settings.WhiteCurrent / 255;
return total;
}
constexpr uint8_t RgbwColor::_elementDim(uint8_t value, uint8_t ratio)
{
return (static_cast<uint16_t>(value) * (static_cast<uint16_t>(ratio) + 1)) >> 8;
}
constexpr uint8_t RgbwColor::_elementBrighten(uint8_t value, uint8_t ratio)
{
uint16_t element = ((static_cast<uint16_t>(value) + 1) << 8) / (static_cast<uint16_t>(ratio) + 1);
if (element > 255)
{
element = 255;
}
else
{
element -= 1;
}
return element;
}

View File

@ -118,7 +118,7 @@ private:
typedef Ws2801MethodBase<TwoWireBitBangImple> NeoWs2801Method;
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) && !defined(ESP32)
#include "TwoWireSpiImple.h"
typedef Ws2801MethodBase<TwoWireSpiImple<SpiSpeed20Mhz>> NeoWs2801Spi20MhzMethod;
typedef Ws2801MethodBase<TwoWireSpiImple<SpiSpeed10Mhz>> NeoWs2801Spi10MhzMethod;