From 722610b8ec424326c8bb5bdb9f62d5086d717972 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 12 Apr 2024 09:46:20 -0700 Subject: [PATCH] buffers --- src/NeoPixelBus.h | 8 +- src/internal/NeoBuffers.h | 4 +- src/internal/buffers/NeoBitmapFile.h | 38 ++-- src/internal/buffers/NeoBuffer.h | 64 ++++--- src/internal/buffers/NeoBufferContext.h | 20 +-- src/internal/buffers/NeoBufferMethods.h | 56 +++--- src/internal/buffers/NeoBufferProgmemMethod.h | 39 ++--- src/internal/buffers/NeoDib.h | 164 ------------------ src/internal/buffers/NeoShaderBase.h | 53 ------ src/internal/colors/Rgb48Color.h | 6 + src/internal/colors/RgbColor.h | 5 + src/internal/colors/RgbColorBase.h | 26 +++ src/internal/colors/Rgbw64Color.h | 5 + src/internal/colors/RgbwColor.h | 6 + 14 files changed, 157 insertions(+), 337 deletions(-) delete mode 100644 src/internal/buffers/NeoDib.h delete mode 100644 src/internal/buffers/NeoShaderBase.h diff --git a/src/NeoPixelBus.h b/src/NeoPixelBus.h index daa8085..708a37d 100644 --- a/src/NeoPixelBus.h +++ b/src/NeoPixelBus.h @@ -114,13 +114,11 @@ public: delete[] _pixels; } -/* Is this used anymore - operator NeoBufferContext() + + operator NeoBufferContext() { - Dirty(); // we assume you are playing with bits - return NeoBufferContext(_pixels(), PixelsSize()); + return NeoBufferContext(_pixels, _countPixels); } -*/ void Begin() { diff --git a/src/internal/NeoBuffers.h b/src/internal/NeoBuffers.h index a3eacc4..9121b4e 100644 --- a/src/internal/NeoBuffers.h +++ b/src/internal/NeoBuffers.h @@ -27,14 +27,12 @@ License along with NeoPixel. If not, see #include "buffers/LayoutMapCallback.h" #include "buffers/NeoShaderNop.h" -#include "buffers/NeoShaderBase.h" -#include "buffers/NeoBufferContext.h" +#include "buffers/NeoBufferContext.h" #include "buffers/NeoBuffer.h" #include "buffers/NeoBufferMethods.h" #include "buffers/NeoBufferProgmemMethod.h" -#include "buffers/NeoDib.h" #include "buffers/NeoBitmapFile.h" #include "buffers/NeoVerticalSpriteSheet.h" diff --git a/src/internal/buffers/NeoBitmapFile.h b/src/internal/buffers/NeoBitmapFile.h index 0cde704..d246fb9 100644 --- a/src/internal/buffers/NeoBitmapFile.h +++ b/src/internal/buffers/NeoBitmapFile.h @@ -67,10 +67,10 @@ enum BmpCompression BI_CmykRle4 }; -// T_COLOR_FEATURE - one of the Features +// T_COLOR_OBJECT - one of the color objects (RgbColor, RgbwColor) // T_FILE_METHOD - any standard File object following Arduino File methods/members // -template class NeoBitmapFile +template class NeoBitmapFile { public: NeoBitmapFile() : @@ -156,7 +156,7 @@ public: size_t PixelSize() const { - return T_COLOR_FEATURE::PixelSize; + return T_COLOR_OBJECT::Size; }; uint16_t PixelCount() const @@ -174,7 +174,7 @@ public: return _height; }; - typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) + T_COLOR_OBJECT GetPixelColor(int16_t x, int16_t y) { if (x < 0 || x >= _width || y < 0 || y >= _height) { @@ -183,7 +183,7 @@ public: return 0; } - typename T_COLOR_FEATURE::ColorObject color; + T_COLOR_OBJECT color; if (!seek(x, y) || !readPixel(&color)) { return 0; @@ -193,15 +193,15 @@ public: }; - template void Render(NeoBufferContext destBuffer, + template void Render(NeoBufferContext destBuffer, T_SHADER& shader, uint16_t indexPixel, int16_t xSrc, int16_t ySrc, int16_t wSrc) { - const uint16_t destPixelCount = destBuffer.PixelCount(); - typename T_COLOR_FEATURE::ColorObject color(0); + const uint16_t destPixelCount = destBuffer.PixelCount; + T_COLOR_OBJECT color(0); xSrc = constrainX(xSrc); ySrc = constrainY(ySrc); @@ -218,23 +218,23 @@ public: } } - T_COLOR_FEATURE::applyPixelColor(destBuffer.Pixels, indexPixel, color); + destBuffer.Pixels[indexPixel] = color; } } } - void Blt(NeoBufferContext destBuffer, + void Blt(NeoBufferContext destBuffer, uint16_t indexPixel, int16_t xSrc, int16_t ySrc, int16_t wSrc) { - NeoShaderNop shaderNop; + NeoShaderNop shaderNop; - Render>(destBuffer, shaderNop, indexPixel, xSrc, ySrc, wSrc); + Render>(destBuffer, shaderNop, indexPixel, xSrc, ySrc, wSrc); }; - template void Render(NeoBufferContext destBuffer, + template void Render(NeoBufferContext destBuffer, T_SHADER& shader, int16_t xDest, int16_t yDest, @@ -244,8 +244,8 @@ public: int16_t hSrc, LayoutMapCallback layoutMap) { - const uint16_t destPixelCount = destBuffer.PixelCount(); - typename T_COLOR_FEATURE::ColorObject color(0); + const uint16_t destPixelCount = destBuffer.PixelCount; + T_COLOR_OBJECT color(0); for (int16_t y = 0; y < hSrc; y++) { @@ -269,14 +269,14 @@ public: if (indexDest < destPixelCount) { - T_COLOR_FEATURE::applyPixelColor(destBuffer.Pixels, indexDest, color); + destBuffer.Pixels[indexDest] = color; } } } } }; - void Blt(NeoBufferContext destBuffer, + void Blt(NeoBufferContext destBuffer, int16_t xDest, int16_t yDest, int16_t xSrc, @@ -285,9 +285,9 @@ public: int16_t hSrc, LayoutMapCallback layoutMap) { - NeoShaderNop shaderNop; + NeoShaderNop shaderNop; - Render>(destBuffer, + Render>(destBuffer, shaderNop, xDest, yDest, diff --git a/src/internal/buffers/NeoBuffer.h b/src/internal/buffers/NeoBuffer.h index fa18994..8131301 100644 --- a/src/internal/buffers/NeoBuffer.h +++ b/src/internal/buffers/NeoBuffer.h @@ -33,7 +33,7 @@ template class NeoBuffer { public: NeoBuffer(uint16_t width, - uint16_t height, + uint16_t height = 1, PGM_VOID_P pixels = nullptr) : _method(width, height, pixels) { @@ -43,7 +43,7 @@ public: { } - operator NeoBufferContext() + operator NeoBufferContext() { return _method; } @@ -68,14 +68,27 @@ public: int16_t y, typename T_BUFFER_METHOD::ColorObject color) { - _method.SetPixelColor(PixelIndex(x, y), color); + _method.SetPixelColor(x, y, color); + }; + + void SetPixelColor( + uint16_t index, + typename T_BUFFER_METHOD::ColorObject color) + { + _method.SetPixelColor(index, color); }; typename T_BUFFER_METHOD::ColorObject GetPixelColor( int16_t x, int16_t y) const { - return _method.GetPixelColor(PixelIndex(x, y)); + return _method.GetPixelColor(x, y); + }; + + typename T_BUFFER_METHOD::ColorObject GetPixelColor( + uint16_t index) const + { + return _method.GetPixelColor(index); }; void ClearTo(typename T_BUFFER_METHOD::ColorObject color) @@ -83,12 +96,12 @@ public: _method.ClearTo(color); }; - void Blt(NeoBufferContext destBuffer, - uint16_t indexPixel) + void Blt(NeoBufferContext destBuffer, + uint16_t destPixelIndex) { uint16_t destPixelCount = destBuffer.PixelCount(); - // validate indexPixel - if (indexPixel >= destPixelCount) + // validate destPixelIndex + if (destPixelIndex >= destPixelCount) { return; } @@ -101,11 +114,14 @@ public: copyCount = srcPixelCount; } - uint8_t* pDest = T_BUFFER_METHOD::ColorFeature::getPixelAddress(destBuffer.Pixels, indexPixel); - _method.CopyPixels(pDest, _method.Pixels(), copyCount); + for (uint16_t index = 0; index < copyCount; index++) + { + typename T_BUFFER_METHOD::ColorObject color = _method.GetPixelColor(index); + destBuffer.Pixels[destPixelIndex + index] = color; + } } - void Blt(NeoBufferContext destBuffer, + void Blt(NeoBufferContext destBuffer, int16_t xDest, int16_t yDest, int16_t xSrc, @@ -120,20 +136,18 @@ public: { for (int16_t x = 0; x < wSrc; x++) { - uint16_t indexDest = layoutMap(xDest + x, yDest + y); + uint16_t destPixelIndex = layoutMap(xDest + x, yDest + y); - if (indexDest < destPixelCount) + if (destPixelIndex < destPixelCount) { - const uint8_t* pSrc = T_BUFFER_METHOD::ColorFeature::getPixelAddress(_method.Pixels(), PixelIndex(xSrc + x, ySrc + y)); - uint8_t* pDest = T_BUFFER_METHOD::ColorFeature::getPixelAddress(destBuffer.Pixels, indexDest); - - _method.CopyPixels(pDest, pSrc, 1); + typename T_BUFFER_METHOD::ColorObject color = _method.GetPixelColor(xSrc + x, ySrc + y); + destBuffer.Pixels[destPixelIndex] = color; } } } } - void Blt(NeoBufferContext destBuffer, + void Blt(NeoBufferContext destBuffer, int16_t xDest, int16_t yDest, LayoutMapCallback layoutMap) @@ -141,21 +155,19 @@ public: Blt(destBuffer, xDest, yDest, 0, 0, Width(), Height(), layoutMap); } - template void Render(NeoBufferContext destBuffer, T_SHADER& shader) + template void Render(NeoBufferContext destBuffer, T_SHADER& shader) { - uint16_t countPixels = destBuffer.PixelCount(); + uint16_t destPixelCount = destBuffer.PixelCount(); - if (countPixels > _method.PixelCount()) + if (destPixelCount > _method.PixelCount()) { - countPixels = _method.PixelCount(); + destPixelCount = _method.PixelCount(); } for (uint16_t indexPixel = 0; indexPixel < countPixels; indexPixel++) { - const uint8_t* pSrc = T_BUFFER_METHOD::ColorFeature::getPixelAddress(_method.Pixels(), indexPixel); - uint8_t* pDest = T_BUFFER_METHOD::ColorFeature::getPixelAddress(destBuffer.Pixels, indexPixel); - - shader.Apply(indexPixel, pDest, pSrc); + typename T_BUFFER_METHOD::ColorObject color = _method.GetPixelColor(indexPixel); + destBuffer.Pixels[indexPixel] = shader.Apply(color); } } diff --git a/src/internal/buffers/NeoBufferContext.h b/src/internal/buffers/NeoBufferContext.h index d1cb0b8..52d5e32 100644 --- a/src/internal/buffers/NeoBufferContext.h +++ b/src/internal/buffers/NeoBufferContext.h @@ -28,21 +28,17 @@ License along with NeoPixel. If not, see // This is used to allow a template classes that share common buffer concept to // be able to pass that common information to functions // The template classes just need to expose a conversion operator to this type -template struct NeoBufferContext +template struct NeoBufferContext { - NeoBufferContext(uint8_t* pixels, - size_t sizePixels) : + NeoBufferContext(T_COLOR_OBJECT* pixels, + size_t pixelsCount) : Pixels(pixels), - SizePixels(sizePixels) + PixelsCount(pixelsCount) { } - uint16_t PixelCount() const - { - return SizePixels / T_COLOR_FEATURE::PixelSize; - }; + typedef T_COLOR_OBJECT ColorObject; - uint8_t* Pixels; - const size_t SizePixels; - -}; \ No newline at end of file + T_COLOR_OBJECT* Pixels; + const size_t PixelsCount; + ; \ No newline at end of file diff --git a/src/internal/buffers/NeoBufferMethods.h b/src/internal/buffers/NeoBufferMethods.h index 70ba1db..d9f3184 100644 --- a/src/internal/buffers/NeoBufferMethods.h +++ b/src/internal/buffers/NeoBufferMethods.h @@ -26,30 +26,34 @@ License along with NeoPixel. If not, see #pragma once -template class NeoBufferMethod +template class NeoBufferMethod { public: NeoBufferMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels = nullptr) : _width(width), _height(height) { - _pixels = (uint8_t*)malloc(PixelsSize()); + _pixels = new T_COLOR_OBJECT[PixelCount()]; + if (pixels) { // copy from progmem to initialize - T_COLOR_FEATURE::movePixelsInc_P(_pixels, pixels, PixelCount()); + for (size_t index = 0; index < PixelCount(); index++) + { + _pixels[index] = T_COLOR_OBJECT::PgmRead(pixels + T_COLOR_OBJECT::Size * indexPixel); + } } } ~NeoBufferMethod() { - free(_pixels); + delete [] _pixels; _pixels = nullptr; } - operator NeoBufferContext() + operator NeoBufferContext() { - return NeoBufferContext(Pixels(), PixelsSize()); + return NeoBufferContext(Pixels(), PixelsCount()); } uint8_t* Pixels() const @@ -64,7 +68,7 @@ public: size_t PixelSize() const { - return T_COLOR_FEATURE::PixelSize; + return T_COLOR_OBJECT::Size; }; uint16_t PixelCount() const @@ -82,15 +86,15 @@ public: return _height; }; - void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color) + void SetPixelColor(uint16_t indexPixel, T_COLOR_OBJECT color) { if (indexPixel < PixelCount()) { - T_COLOR_FEATURE::applyPixelColor(_pixels, indexPixel, color); + _pixels[indexPixel] = color; } }; - void SetPixelColor(int16_t x, int16_t y, typename T_COLOR_FEATURE::ColorObject color) + void SetPixelColor(int16_t x, int16_t y, T_COLOR_OBJECT color) { if (x < 0 || x >= _width || y < 0 || y >= _height) { @@ -98,10 +102,10 @@ public: } uint16_t indexPixel = x + y * _width; - T_COLOR_FEATURE::applyPixelColor(_pixels, indexPixel, color); + _pixels[indexPixel] = color; }; - typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const + T_COLOR_OBJECT GetPixelColor(uint16_t indexPixel) const { if (indexPixel >= PixelCount()) { @@ -110,10 +114,10 @@ public: return 0; } - return T_COLOR_FEATURE::retrievePixelColor(_pixels, indexPixel); + return _pixels[indexPixel]; }; - typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const + T_COLOR_OBJECT GetPixelColor(int16_t x, int16_t y) const { if (x < 0 || x >= _width || y < 0 || y >= _height) { @@ -123,30 +127,26 @@ public: } uint16_t indexPixel = x + y * _width; - return T_COLOR_FEATURE::retrievePixelColor(_pixels, indexPixel); + return _pixels[indexPixel]; }; - void ClearTo(typename T_COLOR_FEATURE::ColorObject color) + void ClearTo(T_COLOR_OBJECT color) { - uint8_t temp[T_COLOR_FEATURE::PixelSize]; + T_COLOR_OBJECT* pixel = _pixels; + T_COLOR_OBJECT* pixelEnd = pixel + PixelCount(); - T_COLOR_FEATURE::applyPixelColor(temp, 0, color); - - T_COLOR_FEATURE::replicatePixel(_pixels, temp, PixelCount()); + while (pixel < pixelEnd) + { + *pixel++ = color; + } }; - void CopyPixels(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) - { - T_COLOR_FEATURE::movePixelsInc(pPixelDest, pPixelSrc, count); - } - - typedef typename T_COLOR_FEATURE::ColorObject ColorObject; - typedef T_COLOR_FEATURE ColorFeature; + typedef T_COLOR_OBJECT ColorObject; private: const uint16_t _width; const uint16_t _height; - uint8_t* _pixels; + T_COLOR_OBJECT* _pixels; }; diff --git a/src/internal/buffers/NeoBufferProgmemMethod.h b/src/internal/buffers/NeoBufferProgmemMethod.h index b03b72d..449598b 100644 --- a/src/internal/buffers/NeoBufferProgmemMethod.h +++ b/src/internal/buffers/NeoBufferProgmemMethod.h @@ -26,7 +26,7 @@ License along with NeoPixel. If not, see #pragma once -template class NeoBufferProgmemMethod +template class NeoBufferProgmemMethod { public: NeoBufferProgmemMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels) : @@ -36,9 +36,9 @@ public: { } - operator NeoBufferContext() + operator NeoBufferContext() { - return NeoBufferContext(Pixels(), PixelsSize()); + return NeoBufferContext(Pixels(), PixelsCount()); } const uint8_t* Pixels() const @@ -46,16 +46,6 @@ public: return reinterpret_cast(_pixels); }; - size_t PixelsSize() const - { - return PixelSize() * PixelCount(); - }; - - size_t PixelSize() const - { - return T_COLOR_FEATURE::PixelSize; - }; - uint16_t PixelCount() const { return _width * _height; @@ -71,17 +61,17 @@ public: return _height; }; - void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color) + void SetPixelColor(uint16_t indexPixel, T_COLOR_OBJECT color) { // PROGMEM is read only, this will do nothing }; - void SetPixelColor(uint16_t x, uint16_t y, typename T_COLOR_FEATURE::ColorObject color) + void SetPixelColor(uint16_t x, uint16_t y, T_COLOR_OBJECT color) { // PROGMEM is read only, this will do nothing }; - typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const + T_COLOR_OBJECT GetPixelColor(uint16_t indexPixel) const { if (indexPixel >= PixelCount()) { @@ -90,10 +80,11 @@ public: return 0; } - return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel); + return T_COLOR_OBJECT::PgmRead(_pixels + T_COLOR_OBJECT::Size * indexPixel); }; - typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const + + T_COLOR_OBJECT GetPixelColor(int16_t x, int16_t y) const { if (x < 0 || x >= _width || y < 0 || y >= _height) { @@ -103,21 +94,15 @@ public: } uint16_t indexPixel = x + y * _width; - return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel); + return GetPixelColor(indexPixel); }; - void ClearTo(typename T_COLOR_FEATURE::ColorObject color) + void ClearTo(T_COLOR_OBJECT color) { // PROGMEM is read only, this will do nothing }; - void CopyPixels(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) - { - T_COLOR_FEATURE::movePixelsInc_P(pPixelDest, pPixelSrc, count); - } - - typedef typename T_COLOR_FEATURE::ColorObject ColorObject; - typedef T_COLOR_FEATURE ColorFeature; + typedef T_COLOR_OBJECT ColorObject; private: const uint16_t _width; diff --git a/src/internal/buffers/NeoDib.h b/src/internal/buffers/NeoDib.h deleted file mode 100644 index f3d162f..0000000 --- a/src/internal/buffers/NeoDib.h +++ /dev/null @@ -1,164 +0,0 @@ -/*------------------------------------------------------------------------- -NeoDib - Device Independant Bitmap, interal data stored in RGB/RGBW format -rather than the ColorFeature format - -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 - -// T_COLOR_OBJECT - one of the color objects -// RgbColor -// RgbwColor -// Rgb16Color -// Rgb48Color -// Rgbw64Color -// SevenSegDigit -// -template class NeoDib -{ -public: - NeoDib(uint16_t countPixels) : - _countPixels(countPixels), - _state(0) - { - _pixels = (T_COLOR_OBJECT*)malloc(PixelsSize()); - ResetDirty(); - } - - ~NeoDib() - { - free((uint8_t*)_pixels); - } - - NeoDib& operator=(const NeoDib& other) - { - // check for self-assignment - if (&other == this) - { - return *this; - } - - uint16_t copyCount = other.PixelCount() < PixelCount() ? other.PixelCount() : PixelCount(); - - for (uint16_t pixel = 0; pixel < copyCount; pixel++) - { - _pixels[pixel] = other.Pixels()[pixel]; - } - - Dirty(); - return *this; - } - - T_COLOR_OBJECT* Pixels() const - { - return _pixels; - }; - - uint16_t PixelCount() const - { - return _countPixels; - }; - - size_t PixelsSize() const - { - return _countPixels * PixelSize(); - }; - - size_t PixelSize() const - { - return sizeof(T_COLOR_OBJECT); - }; - - void SetPixelColor( - uint16_t indexPixel, - T_COLOR_OBJECT color) - { - if (indexPixel < PixelCount()) - { - _pixels[indexPixel] = color; - Dirty(); - } - }; - - T_COLOR_OBJECT GetPixelColor( - uint16_t indexPixel) const - { - if (indexPixel >= PixelCount()) - { - return 0; - } - return _pixels[indexPixel]; - }; - - void ClearTo(T_COLOR_OBJECT color) - { - for (uint16_t pixel = 0; pixel < PixelCount(); pixel++) - { - _pixels[pixel] = color; - } - Dirty(); - }; - - template - void Render(NeoBufferContext destBuffer, T_SHADER& shader, uint16_t destIndexPixel = 0) - { - if (IsDirty() || shader.IsDirty()) - { - uint16_t countPixels = destBuffer.PixelCount(); - - if (countPixels > _countPixels) - { - countPixels = _countPixels; - } - - for (uint16_t indexPixel = 0; indexPixel < countPixels; indexPixel++) - { - T_COLOR_OBJECT color = shader.Apply(indexPixel, _pixels[indexPixel]); - T_COLOR_FEATURE::applyPixelColor(destBuffer.Pixels, destIndexPixel + indexPixel, color); - } - - shader.ResetDirty(); - ResetDirty(); - } - } - - bool IsDirty() const - { - return (_state & NEO_DIRTY); - }; - - void Dirty() - { - _state |= NEO_DIRTY; - }; - - void ResetDirty() - { - _state &= ~NEO_DIRTY; - }; - -private: - const uint16_t _countPixels; // Number of RGB LEDs in strip - T_COLOR_OBJECT* _pixels; - uint8_t _state; // internal state -}; \ No newline at end of file diff --git a/src/internal/buffers/NeoShaderBase.h b/src/internal/buffers/NeoShaderBase.h deleted file mode 100644 index 399c6f9..0000000 --- a/src/internal/buffers/NeoShaderBase.h +++ /dev/null @@ -1,53 +0,0 @@ -/*------------------------------------------------------------------------- -NeoShaderBase - -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 - -class NeoShaderBase -{ -public: - NeoShaderBase() : - _state(0) - { - } - - bool IsDirty() const - { - return (_state & NEO_DIRTY); - }; - - void Dirty() - { - _state |= NEO_DIRTY; - }; - - void ResetDirty() - { - _state &= ~NEO_DIRTY; - }; - -protected: - uint8_t _state; // internal state -}; \ No newline at end of file diff --git a/src/internal/colors/Rgb48Color.h b/src/internal/colors/Rgb48Color.h index 8326bfb..b125e1e 100644 --- a/src/internal/colors/Rgb48Color.h +++ b/src/internal/colors/Rgb48Color.h @@ -269,6 +269,12 @@ struct Rgb48Color : RgbColorBase float x, float y); + + static Rgb48Color PgmRead(PGM_VOID_P pPixelSrc) + { + return _PgmReadByWords(pPixelSrc); + } + uint32_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) { auto total = 0; diff --git a/src/internal/colors/RgbColor.h b/src/internal/colors/RgbColor.h index 4b8fbd7..a139618 100644 --- a/src/internal/colors/RgbColor.h +++ b/src/internal/colors/RgbColor.h @@ -259,6 +259,11 @@ struct RgbColor : RgbColorBase float x, float y); + static RgbColor PgmRead(PGM_VOID_P pPixelSrc) + { + return _PgmReadByBytes(pPixelSrc); + } + uint32_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) { auto total = 0; diff --git a/src/internal/colors/RgbColorBase.h b/src/internal/colors/RgbColorBase.h index aef9d9a..8b658fd 100644 --- a/src/internal/colors/RgbColorBase.h +++ b/src/internal/colors/RgbColorBase.h @@ -66,4 +66,30 @@ protected: } return 0; } + + template static T_COLOR + _PgmReadByBytes(PGM_VOID_P pPixelSrc) + { + const uint8_t* pSrc = reinterpret_cast(pPixelSrc); + const uint8_t* pEnd = pSrc + T_COLOR::Count; + uint8_t index = 0; + + while (pSrc < pEnd) + { + color[index++] = pgm_read_byte(pSrc++); + } + } + + template static T_COLOR + _PgmReadByWords(PGM_VOID_P pPixelSrc) + { + const uint16_t* pSrc = reinterpret_cast(pPixelSrc); + const uint16_t* pEnd = pSrc + T_COLOR::Count; + uint8_t index = 0; + + while (pSrc < pEnd) + { + color[index++] = pgm_read_word(pSrc++); + } + } }; \ No newline at end of file diff --git a/src/internal/colors/Rgbw64Color.h b/src/internal/colors/Rgbw64Color.h index a697fe8..6e6e815 100644 --- a/src/internal/colors/Rgbw64Color.h +++ b/src/internal/colors/Rgbw64Color.h @@ -300,6 +300,11 @@ struct Rgbw64Color : RgbColorBase float x, float y); + static Rgbw64Color PgmRead(PGM_VOID_P pPixelSrc) + { + return _PgmReadByWords(pPixelSrc); + } + uint32_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) { auto total = 0; diff --git a/src/internal/colors/RgbwColor.h b/src/internal/colors/RgbwColor.h index b6c04d4..0020278 100644 --- a/src/internal/colors/RgbwColor.h +++ b/src/internal/colors/RgbwColor.h @@ -277,6 +277,12 @@ struct RgbwColor : RgbColorBase float x, float y); + + static RgbwColor PgmRead(PGM_VOID_P pPixelSrc) + { + return _PgmReadByBytes(pPixelSrc); + } + uint16_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) { auto total = 0;