From 76ec0f58c63ce949107c7e2467bbbb3cef3da7d9 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Mon, 13 Mar 2023 16:15:37 -0700 Subject: [PATCH] Inverted elements (#662) * organize colors * move NeoGamma * refactor gamma files * inverted gamma support --- examples/NeoPixelBusLg/NeoPixelBusLg.ino | 3 + src/NeoPixelBus.h | 22 +--- src/NeoPixelBusLg.h | 9 ++ src/internal/NeoColors.h | 51 +++++++++ src/internal/NeoEase.h | 2 - src/internal/{ => colors}/HsbColor.cpp | 2 + src/internal/{ => colors}/HsbColor.h | 0 src/internal/{ => colors}/HslColor.cpp | 2 + src/internal/{ => colors}/HslColor.h | 0 src/internal/{ => colors}/HtmlColor.cpp | 3 + src/internal/{ => colors}/HtmlColor.h | 3 - .../{ => colors}/HtmlColorNameStrings.cpp | 0 .../{ => colors}/HtmlColorNameStrings.h | 0 src/internal/{ => colors}/HtmlColorNames.cpp | 5 +- .../{ => colors}/HtmlColorShortNames.cpp | 5 +- src/internal/colors/NeoGamma.h | 72 ++++++++++++ .../colors/NeoGammaCieLabEquationMethod.h | 41 +++++++ src/internal/colors/NeoGammaEquationMethod.h | 44 +++++++ src/internal/colors/NeoGammaInvertMethod.h | 48 ++++++++ src/internal/colors/NeoGammaNullMethod.h | 42 +++++++ .../NeoGammaTableMethod.cpp} | 5 +- .../NeoGammaTableMethod.h} | 107 +++--------------- src/internal/{ => colors}/NeoHueBlend.h | 0 src/internal/{ => colors}/Rgb16Color.h | 4 - src/internal/{ => colors}/Rgb48Color.cpp | 4 +- src/internal/{ => colors}/Rgb48Color.h | 5 - src/internal/{ => colors}/RgbColor.cpp | 2 + src/internal/{ => colors}/RgbColor.h | 3 - src/internal/{ => colors}/RgbColorBase.cpp | 1 + src/internal/{ => colors}/RgbColorBase.h | 0 src/internal/{ => colors}/Rgbw64Color.cpp | 2 + src/internal/{ => colors}/Rgbw64Color.h | 2 - src/internal/{ => colors}/RgbwColor.cpp | 2 + src/internal/{ => colors}/RgbwColor.h | 0 src/internal/{ => colors}/SegmentDigit.cpp | 0 src/internal/{ => colors}/SegmentDigit.h | 0 36 files changed, 354 insertions(+), 137 deletions(-) create mode 100644 src/internal/NeoColors.h rename src/internal/{ => colors}/HsbColor.cpp (97%) rename src/internal/{ => colors}/HsbColor.h (100%) rename src/internal/{ => colors}/HslColor.cpp (97%) rename src/internal/{ => colors}/HslColor.h (100%) rename src/internal/{ => colors}/HtmlColor.cpp (95%) rename src/internal/{ => colors}/HtmlColor.h (99%) rename src/internal/{ => colors}/HtmlColorNameStrings.cpp (100%) rename src/internal/{ => colors}/HtmlColorNameStrings.h (100%) rename src/internal/{ => colors}/HtmlColorNames.cpp (98%) rename src/internal/{ => colors}/HtmlColorShortNames.cpp (95%) create mode 100644 src/internal/colors/NeoGamma.h create mode 100644 src/internal/colors/NeoGammaCieLabEquationMethod.h create mode 100644 src/internal/colors/NeoGammaEquationMethod.h create mode 100644 src/internal/colors/NeoGammaInvertMethod.h create mode 100644 src/internal/colors/NeoGammaNullMethod.h rename src/internal/{NeoGamma.cpp => colors/NeoGammaTableMethod.cpp} (95%) rename src/internal/{NeoGamma.h => colors/NeoGammaTableMethod.h} (63%) rename src/internal/{ => colors}/NeoHueBlend.h (100%) rename src/internal/{ => colors}/Rgb16Color.h (99%) rename src/internal/{ => colors}/Rgb48Color.cpp (98%) rename src/internal/{ => colors}/Rgb48Color.h (99%) rename src/internal/{ => colors}/RgbColor.cpp (98%) rename src/internal/{ => colors}/RgbColor.h (99%) rename src/internal/{ => colors}/RgbColorBase.cpp (99%) rename src/internal/{ => colors}/RgbColorBase.h (100%) rename src/internal/{ => colors}/Rgbw64Color.cpp (98%) rename src/internal/{ => colors}/Rgbw64Color.h (99%) rename src/internal/{ => colors}/RgbwColor.cpp (98%) rename src/internal/{ => colors}/RgbwColor.h (100%) rename src/internal/{ => colors}/SegmentDigit.cpp (100%) rename src/internal/{ => colors}/SegmentDigit.h (100%) diff --git a/examples/NeoPixelBusLg/NeoPixelBusLg.ino b/examples/NeoPixelBusLg/NeoPixelBusLg.ino index c69a804..523f2d2 100644 --- a/examples/NeoPixelBusLg/NeoPixelBusLg.ino +++ b/examples/NeoPixelBusLg/NeoPixelBusLg.ino @@ -29,6 +29,9 @@ NeoPixelBusLg strip(PixelCount, PixelPin); // If you want to turn gamma correction off, then you can use the null gamma method // NeoPixelBusLg strip(PixelCount, PixelPin); +// If you use a LED driver between the NeoPixel chip and the LEDs that require the PWM range inverted +// NeoPixelBusLg> strip(PixelCount, PixelPin); + void setup() { Serial.begin(115200); diff --git a/src/NeoPixelBus.h b/src/NeoPixelBus.h index 72cb175..9eb964c 100644 --- a/src/NeoPixelBus.h +++ b/src/NeoPixelBus.h @@ -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" diff --git a/src/NeoPixelBusLg.h b/src/NeoPixelBusLg.h index 62eb9ae..67111e6 100644 --- a/src/NeoPixelBusLg.h +++ b/src/NeoPixelBusLg.h @@ -28,6 +28,15 @@ License along with NeoPixel. If not, see #include "NeoPixelBus.h" +// +// +// T_GAMMA - +// NeoGammaEquationMethod +// NeoGammaCieLabEquationMethod +// NeoGammaTableMethod +// NeoGammaNullMethod +// NeoGammaInvert + template class NeoPixelBusLg : public NeoPixelBus { diff --git a/src/internal/NeoColors.h b/src/internal/NeoColors.h new file mode 100644 index 0000000..70c4ae6 --- /dev/null +++ b/src/internal/NeoColors.h @@ -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 +. +-------------------------------------------------------------------------*/ +#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" \ No newline at end of file diff --git a/src/internal/NeoEase.h b/src/internal/NeoEase.h index 60a36ba..52c0012 100644 --- a/src/internal/NeoEase.h +++ b/src/internal/NeoEase.h @@ -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); diff --git a/src/internal/HsbColor.cpp b/src/internal/colors/HsbColor.cpp similarity index 97% rename from src/internal/HsbColor.cpp rename to src/internal/colors/HsbColor.cpp index 79d69dd..b45f511 100644 --- a/src/internal/HsbColor.cpp +++ b/src/internal/colors/HsbColor.cpp @@ -25,6 +25,8 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include +#include "../NeoSettings.h" +#include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb48Color.h" #include "HsbColor.h" diff --git a/src/internal/HsbColor.h b/src/internal/colors/HsbColor.h similarity index 100% rename from src/internal/HsbColor.h rename to src/internal/colors/HsbColor.h diff --git a/src/internal/HslColor.cpp b/src/internal/colors/HslColor.cpp similarity index 97% rename from src/internal/HslColor.cpp rename to src/internal/colors/HslColor.cpp index 1442c88..bd6c3f4 100644 --- a/src/internal/HslColor.cpp +++ b/src/internal/colors/HslColor.cpp @@ -26,6 +26,8 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include +#include "../NeoSettings.h" +#include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb48Color.h" #include "HslColor.h" diff --git a/src/internal/HslColor.h b/src/internal/colors/HslColor.h similarity index 100% rename from src/internal/HslColor.h rename to src/internal/colors/HslColor.h diff --git a/src/internal/HtmlColor.cpp b/src/internal/colors/HtmlColor.cpp similarity index 95% rename from src/internal/HtmlColor.cpp rename to src/internal/colors/HtmlColor.cpp index d24edbb..9e9af5f 100644 --- a/src/internal/HtmlColor.cpp +++ b/src/internal/colors/HtmlColor.cpp @@ -25,6 +25,9 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include +#include "../NeoSettings.h" +#include "RgbColorBase.h" +#include "RgbColor.h" #include "HtmlColor.h" static inline char hexdigit(uint8_t v) diff --git a/src/internal/HtmlColor.h b/src/internal/colors/HtmlColor.h similarity index 99% rename from src/internal/HtmlColor.h rename to src/internal/colors/HtmlColor.h index 3ca2ea9..3e63421 100644 --- a/src/internal/HtmlColor.h +++ b/src/internal/colors/HtmlColor.h @@ -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 diff --git a/src/internal/HtmlColorNameStrings.cpp b/src/internal/colors/HtmlColorNameStrings.cpp similarity index 100% rename from src/internal/HtmlColorNameStrings.cpp rename to src/internal/colors/HtmlColorNameStrings.cpp diff --git a/src/internal/HtmlColorNameStrings.h b/src/internal/colors/HtmlColorNameStrings.h similarity index 100% rename from src/internal/HtmlColorNameStrings.h rename to src/internal/colors/HtmlColorNameStrings.h diff --git a/src/internal/HtmlColorNames.cpp b/src/internal/colors/HtmlColorNames.cpp similarity index 98% rename from src/internal/HtmlColorNames.cpp rename to src/internal/colors/HtmlColorNames.cpp index cc3226c..ce6fd63 100644 --- a/src/internal/HtmlColorNames.cpp +++ b/src/internal/colors/HtmlColorNames.cpp @@ -26,7 +26,10 @@ License along with NeoPixel. If not, see #include -#include "NeoUtil.h" +#include "../NeoUtil.h" +#include "../NeoSettings.h" +#include "RgbColorBase.h" +#include "RgbColor.h" #include "HtmlColor.h" #include "HtmlColorNameStrings.h" diff --git a/src/internal/HtmlColorShortNames.cpp b/src/internal/colors/HtmlColorShortNames.cpp similarity index 95% rename from src/internal/HtmlColorShortNames.cpp rename to src/internal/colors/HtmlColorShortNames.cpp index 3b4c47f..14aaf26 100644 --- a/src/internal/HtmlColorShortNames.cpp +++ b/src/internal/colors/HtmlColorShortNames.cpp @@ -26,7 +26,10 @@ License along with NeoPixel. If not, see #include -#include "NeoUtil.h" +#include "../NeoUtil.h" +#include "../NeoSettings.h" +#include "RgbColorBase.h" +#include "RgbColor.h" #include "HtmlColor.h" #include "HtmlColorNameStrings.h" diff --git a/src/internal/colors/NeoGamma.h b/src/internal/colors/NeoGamma.h new file mode 100644 index 0000000..d017fa2 --- /dev/null +++ b/src/internal/colors/NeoGamma.h @@ -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 +. +-------------------------------------------------------------------------*/ +#pragma once + +// use one of the gamma method classes as a converter for this template class +// T_METHOD - +// NeoGammaEquationMethod +// NeoGammaCieLabEquationMethod +// NeoGammaTableMethod +// NeoGammaNullMethod +// NeoGammaInvert +// +template 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)); + } +}; + + + diff --git a/src/internal/colors/NeoGammaCieLabEquationMethod.h b/src/internal/colors/NeoGammaCieLabEquationMethod.h new file mode 100644 index 0000000..6603677 --- /dev/null +++ b/src/internal/colors/NeoGammaCieLabEquationMethod.h @@ -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 +. +-------------------------------------------------------------------------*/ +#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(255.0f * NeoEase::GammaCieLab(value / 255.0f) + 0.5f); + } + static uint16_t Correct(uint16_t value) + { + return static_cast(65535.0f * NeoEase::GammaCieLab(value / 65535.0f) + 0.5f); + } +}; \ No newline at end of file diff --git a/src/internal/colors/NeoGammaEquationMethod.h b/src/internal/colors/NeoGammaEquationMethod.h new file mode 100644 index 0000000..19ce687 --- /dev/null +++ b/src/internal/colors/NeoGammaEquationMethod.h @@ -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 +. +-------------------------------------------------------------------------*/ +#pragma once + + +// NeoGammaEquationMethod uses no memory but is slower than NeoGammaTableMethod +class NeoGammaEquationMethod +{ +public: + static uint8_t Correct(uint8_t value) + { + return static_cast(255.0f * NeoEase::Gamma(value / 255.0f) + 0.5f); + } + static uint16_t Correct(uint16_t value) + { + return static_cast(65535.0f * NeoEase::Gamma(value / 65535.0f) + 0.5f); + } +}; + + diff --git a/src/internal/colors/NeoGammaInvertMethod.h b/src/internal/colors/NeoGammaInvertMethod.h new file mode 100644 index 0000000..f28bdef --- /dev/null +++ b/src/internal/colors/NeoGammaInvertMethod.h @@ -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 +. +-------------------------------------------------------------------------*/ +#pragma once + +// use one of the gamma method classes as a base converter for this template class +// T_METHOD - +// NeoGammaEquationMethod +// NeoGammaCieLabEquationMethod +// NeoGammaTableMethod +// NeoGammaNullMethod +// +template 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); + } +}; \ No newline at end of file diff --git a/src/internal/colors/NeoGammaNullMethod.h b/src/internal/colors/NeoGammaNullMethod.h new file mode 100644 index 0000000..d1d4436 --- /dev/null +++ b/src/internal/colors/NeoGammaNullMethod.h @@ -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 +. +-------------------------------------------------------------------------*/ +#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; + } +}; diff --git a/src/internal/NeoGamma.cpp b/src/internal/colors/NeoGammaTableMethod.cpp similarity index 95% rename from src/internal/NeoGamma.cpp rename to src/internal/colors/NeoGammaTableMethod.cpp index 0937e54..f1d8782 100644 --- a/src/internal/NeoGamma.cpp +++ b/src/internal/colors/NeoGammaTableMethod.cpp @@ -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 -#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 diff --git a/src/internal/NeoGamma.h b/src/internal/colors/NeoGammaTableMethod.h similarity index 63% rename from src/internal/NeoGamma.h rename to src/internal/colors/NeoGammaTableMethod.h index ff3744f..4874a44 100644 --- a/src/internal/NeoGamma.h +++ b/src/internal/colors/NeoGammaTableMethod.h @@ -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(255.0f * NeoEase::Gamma(value / 255.0f) + 0.5f); - } - static uint16_t Correct(uint16_t value) - { - return static_cast(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(255.0f * NeoEase::GammaCieLab(value / 255.0f) + 0.5f); - } - static uint16_t Correct(uint16_t value) - { - return static_cast(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(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 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)); - } -}; - - - diff --git a/src/internal/NeoHueBlend.h b/src/internal/colors/NeoHueBlend.h similarity index 100% rename from src/internal/NeoHueBlend.h rename to src/internal/colors/NeoHueBlend.h diff --git a/src/internal/Rgb16Color.h b/src/internal/colors/Rgb16Color.h similarity index 99% rename from src/internal/Rgb16Color.h rename to src/internal/colors/Rgb16Color.h index 19f7d96..96da4f3 100644 --- a/src/internal/Rgb16Color.h +++ b/src/internal/colors/Rgb16Color.h @@ -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. diff --git a/src/internal/Rgb48Color.cpp b/src/internal/colors/Rgb48Color.cpp similarity index 98% rename from src/internal/Rgb48Color.cpp rename to src/internal/colors/Rgb48Color.cpp index bcc43ce..cec7722 100644 --- a/src/internal/Rgb48Color.cpp +++ b/src/internal/colors/Rgb48Color.cpp @@ -25,8 +25,10 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include -#include "Rgb48Color.h" +#include "../NeoSettings.h" +#include "RgbColorBase.h" #include "RgbColor.h" +#include "Rgb48Color.h" #include "HslColor.h" #include "HsbColor.h" #include "HtmlColor.h" diff --git a/src/internal/Rgb48Color.h b/src/internal/colors/Rgb48Color.h similarity index 99% rename from src/internal/Rgb48Color.h rename to src/internal/colors/Rgb48Color.h index f01e9be..838976c 100644 --- a/src/internal/Rgb48Color.h +++ b/src/internal/colors/Rgb48Color.h @@ -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 diff --git a/src/internal/RgbColor.cpp b/src/internal/colors/RgbColor.cpp similarity index 98% rename from src/internal/RgbColor.cpp rename to src/internal/colors/RgbColor.cpp index 5a6f1d8..a047a26 100644 --- a/src/internal/RgbColor.cpp +++ b/src/internal/colors/RgbColor.cpp @@ -25,6 +25,8 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include +#include "../NeoSettings.h" +#include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb16Color.h" #include "Rgb48Color.h" diff --git a/src/internal/RgbColor.h b/src/internal/colors/RgbColor.h similarity index 99% rename from src/internal/RgbColor.h rename to src/internal/colors/RgbColor.h index d116c62..9929bb4 100644 --- a/src/internal/RgbColor.h +++ b/src/internal/colors/RgbColor.h @@ -25,9 +25,6 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -#include "NeoSettings.h" -#include "RgbColorBase.h" - struct RgbwColor; // ------------------------------------------------------------------------ diff --git a/src/internal/RgbColorBase.cpp b/src/internal/colors/RgbColorBase.cpp similarity index 99% rename from src/internal/RgbColorBase.cpp rename to src/internal/colors/RgbColorBase.cpp index 7938915..92c43f9 100644 --- a/src/internal/RgbColorBase.cpp +++ b/src/internal/colors/RgbColorBase.cpp @@ -25,6 +25,7 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include +#include "../NeoSettings.h" #include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb48Color.h" diff --git a/src/internal/RgbColorBase.h b/src/internal/colors/RgbColorBase.h similarity index 100% rename from src/internal/RgbColorBase.h rename to src/internal/colors/RgbColorBase.h diff --git a/src/internal/Rgbw64Color.cpp b/src/internal/colors/Rgbw64Color.cpp similarity index 98% rename from src/internal/Rgbw64Color.cpp rename to src/internal/colors/Rgbw64Color.cpp index 7987158..4f53c39 100644 --- a/src/internal/Rgbw64Color.cpp +++ b/src/internal/colors/Rgbw64Color.cpp @@ -25,6 +25,8 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include +#include "../NeoSettings.h" +#include "RgbColorBase.h" #include "RgbColor.h" #include "RgbwColor.h" #include "Rgb48Color.h" diff --git a/src/internal/Rgbw64Color.h b/src/internal/colors/Rgbw64Color.h similarity index 99% rename from src/internal/Rgbw64Color.h rename to src/internal/colors/Rgbw64Color.h index 920ec25..569389e 100644 --- a/src/internal/Rgbw64Color.h +++ b/src/internal/colors/Rgbw64Color.h @@ -25,8 +25,6 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -#include "NeoSettings.h" - struct RgbColor; struct HslColor; struct HsbColor; diff --git a/src/internal/RgbwColor.cpp b/src/internal/colors/RgbwColor.cpp similarity index 98% rename from src/internal/RgbwColor.cpp rename to src/internal/colors/RgbwColor.cpp index ba67877..5391583 100644 --- a/src/internal/RgbwColor.cpp +++ b/src/internal/colors/RgbwColor.cpp @@ -25,6 +25,8 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include +#include "../NeoSettings.h" +#include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb48Color.h" #include "HslColor.h" diff --git a/src/internal/RgbwColor.h b/src/internal/colors/RgbwColor.h similarity index 100% rename from src/internal/RgbwColor.h rename to src/internal/colors/RgbwColor.h diff --git a/src/internal/SegmentDigit.cpp b/src/internal/colors/SegmentDigit.cpp similarity index 100% rename from src/internal/SegmentDigit.cpp rename to src/internal/colors/SegmentDigit.cpp diff --git a/src/internal/SegmentDigit.h b/src/internal/colors/SegmentDigit.h similarity index 100% rename from src/internal/SegmentDigit.h rename to src/internal/colors/SegmentDigit.h