Inverted elements (#662)

* organize colors

* move NeoGamma

* refactor gamma files

* inverted gamma support
This commit is contained in:
Michael Miller
2023-03-13 16:15:37 -07:00
committed by GitHub
parent f5bace5a1a
commit 76ec0f58c6
36 changed files with 354 additions and 137 deletions

View File

@@ -29,6 +29,9 @@ NeoPixelBusLg<NeoRgbFeature, NeoWs2812xMethod> strip(PixelCount, PixelPin);
// If you want to turn gamma correction off, then you can use the null gamma method
// NeoPixelBusLg<NeoRgbFeature, NeoWs2812xMethod, NeoGammaNullMethod> strip(PixelCount, PixelPin);
// If you use a LED driver between the NeoPixel chip and the LEDs that require the PWM range inverted
// NeoPixelBusLg<NeoRgbFeature, NeoWs2812xMethod, NeoGammaInvertMethod<NeoGammaNullMethod>> strip(PixelCount, PixelPin);
void setup()
{
Serial.begin(115200);

View File

@@ -31,24 +31,9 @@ License along with NeoPixel. If not, see
#define NEO_DIRTY 0x80 // a change was made to pixel data that requires a show
#include "internal/NeoUtil.h"
#include "internal/NeoHueBlend.h"
#include "internal/NeoEase.h"
#include "internal/NeoSettings.h"
#include "internal/RgbColor.h"
#include "internal/Rgb16Color.h"
#include "internal/Rgb48Color.h"
#include "internal/HslColor.h"
#include "internal/HsbColor.h"
#include "internal/HtmlColor.h"
#include "internal/RgbwColor.h"
#include "internal/Rgbw64Color.h"
#include "internal/SegmentDigit.h"
#include "internal/NeoColors.h"
#include "internal/NeoColorFeatures.h"
#include "internal/Layouts.h"
@@ -64,9 +49,6 @@ License along with NeoPixel. If not, see
#include "internal/NeoDib.h"
#include "internal/NeoBitmapFile.h"
#include "internal/NeoEase.h"
#include "internal/NeoGamma.h"
#include "internal/NeoBusChannel.h"
#include "internal/DotStarGenericMethod.h"

View File

@@ -28,6 +28,15 @@ License along with NeoPixel. If not, see
#include "NeoPixelBus.h"
//
//
// T_GAMMA -
// NeoGammaEquationMethod
// NeoGammaCieLabEquationMethod
// NeoGammaTableMethod
// NeoGammaNullMethod
// NeoGammaInvert<one of the above>
template<typename T_COLOR_FEATURE, typename T_METHOD, typename T_GAMMA = NeoGammaEquationMethod> class NeoPixelBusLg :
public NeoPixelBus<T_COLOR_FEATURE, T_METHOD>
{

51
src/internal/NeoColors.h Normal file
View File

@@ -0,0 +1,51 @@
/*-------------------------------------------------------------------------
NeoColors includes all the color classes that describe color and
modify colors for 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 "colors/NeoHueBlend.h"
#include "colors/RgbColorBase.h"
#include "colors/RgbColor.h"
#include "colors/Rgb16Color.h"
#include "colors/Rgb48Color.h"
#include "colors/HslColor.h"
#include "colors/HsbColor.h"
#include "colors/HtmlColor.h"
#include "colors/RgbwColor.h"
#include "colors/Rgbw64Color.h"
#include "colors/SegmentDigit.h"
#include "colors/NeoGamma.h"
#include "colors/NeoGammaEquationMethod.h"
#include "colors/NeoGammaCieLabEquationMethod.h"
#include "colors/NeoGammaTableMethod.h"
#include "colors/NeoGammaNullMethod.h"
#include "colors/NeoGammaInvertMethod.h"

View File

@@ -26,8 +26,6 @@ License along with NeoPixel. If not, see
#pragma once
#include "internal/NeoUtil.h"
#if defined(NEOPIXEBUS_NO_STL)
typedef float(*AnimEaseFunction)(float unitValue);

View File

@@ -25,6 +25,8 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#include <Arduino.h>
#include "../NeoSettings.h"
#include "RgbColorBase.h"
#include "RgbColor.h"
#include "Rgb48Color.h"
#include "HsbColor.h"

View File

@@ -26,6 +26,8 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#include <Arduino.h>
#include "../NeoSettings.h"
#include "RgbColorBase.h"
#include "RgbColor.h"
#include "Rgb48Color.h"
#include "HslColor.h"

View File

@@ -25,6 +25,9 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#include <Arduino.h>
#include "../NeoSettings.h"
#include "RgbColorBase.h"
#include "RgbColor.h"
#include "HtmlColor.h"
static inline char hexdigit(uint8_t v)

View File

@@ -25,9 +25,6 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
#include "RgbColor.h"
#define MAX_HTML_COLOR_NAME_LEN 21
#ifndef pgm_read_ptr

View File

@@ -26,7 +26,10 @@ License along with NeoPixel. If not, see
#include <Arduino.h>
#include "NeoUtil.h"
#include "../NeoUtil.h"
#include "../NeoSettings.h"
#include "RgbColorBase.h"
#include "RgbColor.h"
#include "HtmlColor.h"
#include "HtmlColorNameStrings.h"

View File

@@ -26,7 +26,10 @@ License along with NeoPixel. If not, see
#include <Arduino.h>
#include "NeoUtil.h"
#include "../NeoUtil.h"
#include "../NeoSettings.h"
#include "RgbColorBase.h"
#include "RgbColor.h"
#include "HtmlColor.h"
#include "HtmlColorNameStrings.h"

View File

@@ -0,0 +1,72 @@
/*-------------------------------------------------------------------------
NeoGamma class is used to correct RGB colors for human eye gamma levels equally
across all color channels
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
// use one of the gamma method classes as a converter for this template class
// T_METHOD -
// NeoGammaEquationMethod
// NeoGammaCieLabEquationMethod
// NeoGammaTableMethod
// NeoGammaNullMethod
// NeoGammaInvert<one of the above>
//
template<typename T_METHOD> class NeoGamma
{
public:
static RgbColor Correct(const RgbColor& original)
{
return RgbColor(T_METHOD::Correct(original.R),
T_METHOD::Correct(original.G),
T_METHOD::Correct(original.B));
}
static RgbwColor Correct(const RgbwColor& original)
{
return RgbwColor(T_METHOD::Correct(original.R),
T_METHOD::Correct(original.G),
T_METHOD::Correct(original.B),
T_METHOD::Correct(original.W) );
}
static Rgb48Color Correct(const Rgb48Color& original)
{
return Rgb48Color(T_METHOD::Correct(original.R),
T_METHOD::Correct(original.G),
T_METHOD::Correct(original.B));
}
static Rgbw64Color Correct(const Rgbw64Color& original)
{
return Rgbw64Color(T_METHOD::Correct(original.R),
T_METHOD::Correct(original.G),
T_METHOD::Correct(original.B),
T_METHOD::Correct(original.W));
}
};

View File

@@ -0,0 +1,41 @@
/*-------------------------------------------------------------------------
NeoGammaCieLabEquationMethod class is used to correct RGB colors for human eye gamma levels equally
across all color channels
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
// Alternative equation to provide at least one official model for specific LEDs
class NeoGammaCieLabEquationMethod
{
public:
static uint8_t Correct(uint8_t value)
{
return static_cast<uint8_t>(255.0f * NeoEase::GammaCieLab(value / 255.0f) + 0.5f);
}
static uint16_t Correct(uint16_t value)
{
return static_cast<uint16_t>(65535.0f * NeoEase::GammaCieLab(value / 65535.0f) + 0.5f);
}
};

View File

@@ -0,0 +1,44 @@
/*-------------------------------------------------------------------------
NeoGammaEquationMethod class is used to correct RGB colors for human eye gamma levels equally
across all color channels
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
// NeoGammaEquationMethod uses no memory but is slower than NeoGammaTableMethod
class NeoGammaEquationMethod
{
public:
static uint8_t Correct(uint8_t value)
{
return static_cast<uint8_t>(255.0f * NeoEase::Gamma(value / 255.0f) + 0.5f);
}
static uint16_t Correct(uint16_t value)
{
return static_cast<uint16_t>(65535.0f * NeoEase::Gamma(value / 65535.0f) + 0.5f);
}
};

View File

@@ -0,0 +1,48 @@
/*-------------------------------------------------------------------------
NeoGammaInvertMethod class is used to correct RGB colors for human eye gamma levels equally
across all color channels
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
// use one of the gamma method classes as a base converter for this template class
// T_METHOD -
// NeoGammaEquationMethod
// NeoGammaCieLabEquationMethod
// NeoGammaTableMethod
// NeoGammaNullMethod
//
template<typename T_METHOD> class NeoGammaInvertMethod
{
public:
static uint8_t Correct(uint8_t value)
{
return ~T_METHOD::Correct(value);
}
static uint16_t Correct(uint16_t value)
{
return ~T_METHOD::Correct(value);
}
};

View File

@@ -0,0 +1,42 @@
/*-------------------------------------------------------------------------
NeoGammaNullMethod class is used to correct RGB colors for human eye gamma levels equally
across all color channels
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
// no gamma correction at all
class NeoGammaNullMethod
{
public:
static uint8_t Correct(uint8_t value)
{
return value;
}
static uint16_t Correct(uint16_t value)
{
return value;
}
};

View File

@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------
NeoPixelGamma class is used to correct RGB colors for human eye gamma levels
NeoGamma classes are used to correct RGB colors for human eye gamma levels
Written by Michael C. Miller.
@@ -25,7 +25,8 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#include <Arduino.h>
#include "NeoPixelBus.h"
#include "../NeoUtil.h"
#include "NeoGammaTableMethod.h"
const uint8_t NeoGammaTableMethod::_table[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16

View File

@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------
NeoGamma class is used to correct RGB colors for human eye gamma levels equally
NeoGammaTableMethod class is used to correct RGB colors for human eye gamma levels equally
across all color channels
Written by Michael C. Miller.
@@ -26,51 +26,24 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
// NeoGammaEquationMethod uses no memory but is slower than NeoGammaTableMethod
class NeoGammaEquationMethod
{
public:
static uint8_t Correct(uint8_t value)
{
return static_cast<uint8_t>(255.0f * NeoEase::Gamma(value / 255.0f) + 0.5f);
}
static uint16_t Correct(uint16_t value)
{
return static_cast<uint16_t>(65535.0f * NeoEase::Gamma(value / 65535.0f) + 0.5f);
}
};
// Alternative equation to provide at least one official model for specific LEDs
class NeoGammaCieLabEquationMethod
{
public:
static uint8_t Correct(uint8_t value)
{
return static_cast<uint8_t>(255.0f * NeoEase::GammaCieLab(value / 255.0f) + 0.5f);
}
static uint16_t Correct(uint16_t value)
{
return static_cast<uint16_t>(65535.0f * NeoEase::GammaCieLab(value / 65535.0f) + 0.5f);
}
};
struct NeoGamma16LowHint
{
uint8_t pos;
uint8_t count;
};
// NeoGammaTableMethod uses 256 bytes of memory, but is significantly faster
class NeoGammaTableMethod
{
protected:
struct NeoGamma16LowHint
{
uint8_t pos;
uint8_t count;
};
public:
static uint8_t Correct(uint8_t value)
{
return _table[value];
}
static uint16_t Correct(uint16_t value)
{
{
// since a single monolithic table would be an unreasonable memory usage
// this will use a hybrid of two tables, the base 255 table for the hibyte
// and a smaller table with hints on how to use the table for certain values
@@ -82,7 +55,7 @@ public:
{0,6}, {1,6}, {2,6}, {3,6}, {4,6}, {5,6}, {0,4}, {1,4}, {2,4}, {3,4}, {0,4}, {1,4}, {2,4}, {3,4}, {0,3}, {1,3},
{2,3}, {0,4}, {1,4}, {2,4}, {3,4}, {0,3}, {1,3}, {2,3}, {0,3}, {1,3}, {2,3}, {0,2}, {1,2}, {0,3}, {1,3}, {2,3},
{0,2}, {1,2}, {0,2}, {1,2}, {0,3}, {1,3}, {2,3}, {0,2}, {1,2}
};
};
uint8_t hi = (value >> 8);
uint16_t lo = (value & 0x00ff);
@@ -127,66 +100,14 @@ public:
lowResult = delta * lo;
}
}
}
return (static_cast<uint16_t>(hiResult) << 8) + lowResult;
}
private:
static const uint8_t _table[256];
};
// no gamma correction at all
class NeoGammaNullMethod
{
public:
static uint8_t Correct(uint8_t value)
{
return value;
}
static uint16_t Correct(uint16_t value)
{
return value;
}
};
// use one of the method classes above as a converter for this template class
template<typename T_METHOD> class NeoGamma
{
public:
static RgbColor Correct(const RgbColor& original)
{
return RgbColor(T_METHOD::Correct(original.R),
T_METHOD::Correct(original.G),
T_METHOD::Correct(original.B));
}
static RgbwColor Correct(const RgbwColor& original)
{
return RgbwColor(T_METHOD::Correct(original.R),
T_METHOD::Correct(original.G),
T_METHOD::Correct(original.B),
T_METHOD::Correct(original.W) );
}
static Rgb48Color Correct(const Rgb48Color& original)
{
return Rgb48Color(T_METHOD::Correct(original.R),
T_METHOD::Correct(original.G),
T_METHOD::Correct(original.B));
}
static Rgbw64Color Correct(const Rgbw64Color& original)
{
return Rgbw64Color(T_METHOD::Correct(original.R),
T_METHOD::Correct(original.G),
T_METHOD::Correct(original.B),
T_METHOD::Correct(original.W));
}
};

View File

@@ -25,10 +25,6 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
#include "NeoSettings.h"
#include "RgbColorBase.h"
// ------------------------------------------------------------------------
// Rgb16Color represents a color object that is represented by Red, Green, Blue
// component values stored in a single 16 bit value using 565 model.

View File

@@ -25,8 +25,10 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#include <Arduino.h>
#include "Rgb48Color.h"
#include "../NeoSettings.h"
#include "RgbColorBase.h"
#include "RgbColor.h"
#include "Rgb48Color.h"
#include "HslColor.h"
#include "HsbColor.h"
#include "HtmlColor.h"

View File

@@ -25,11 +25,6 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
#include "NeoSettings.h"
#include "RgbColorBase.h"
#include "RgbColor.h"
// ------------------------------------------------------------------------
// Rgb48Color represents a color object that is represented by Red, Green, Blue
// component values. It contains helpful color routines to manipulate the

View File

@@ -25,6 +25,8 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#include <Arduino.h>
#include "../NeoSettings.h"
#include "RgbColorBase.h"
#include "RgbColor.h"
#include "Rgb16Color.h"
#include "Rgb48Color.h"

View File

@@ -25,9 +25,6 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
#include "NeoSettings.h"
#include "RgbColorBase.h"
struct RgbwColor;
// ------------------------------------------------------------------------

View File

@@ -25,6 +25,7 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#include <Arduino.h>
#include "../NeoSettings.h"
#include "RgbColorBase.h"
#include "RgbColor.h"
#include "Rgb48Color.h"

View File

@@ -25,6 +25,8 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#include <Arduino.h>
#include "../NeoSettings.h"
#include "RgbColorBase.h"
#include "RgbColor.h"
#include "RgbwColor.h"
#include "Rgb48Color.h"

View File

@@ -25,8 +25,6 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
#include "NeoSettings.h"
struct RgbColor;
struct HslColor;
struct HsbColor;

View File

@@ -25,6 +25,8 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#include <Arduino.h>
#include "../NeoSettings.h"
#include "RgbColorBase.h"
#include "RgbColor.h"
#include "Rgb48Color.h"
#include "HslColor.h"