animations and buffers (#664)

This commit is contained in:
Michael Miller
2023-03-14 13:41:50 -07:00
committed by GitHub
parent d39ae30d05
commit caef973bc2
15 changed files with 342 additions and 180 deletions

View File

@@ -27,7 +27,7 @@ License along with NeoPixel. If not, see
#pragma once
#include <Arduino.h>
#include "internal/NeoEase.h"
#include "internal/animations/NeoEase.h"
enum AnimationState
{

View File

@@ -33,18 +33,12 @@ const uint8_t NEO_DIRTY = 0x80; // a change was made to pixel data that requires
const uint16_t PixelIndex_OutOfBounds = 0xffff;
#include "internal/NeoUtil.h"
#include "internal/NeoEase.h"
#include "internal/animations/NeoEase.h"
#include "internal/NeoSettings.h"
#include "internal/NeoColors.h"
#include "internal/NeoColorFeatures.h"
#include "internal/NeoTopologies.h"
#include "internal/NeoBufferContext.h"
#include "internal/NeoBufferMethods.h"
#include "internal/NeoBuffer.h"
#include "internal/NeoSpriteSheet.h"
#include "internal/NeoDib.h"
#include "internal/NeoBitmapFile.h"
#include "internal/NeoBuffers.h"
#include "internal/NeoBusChannel.h"

40
src/internal/NeoBuffers.h Normal file
View File

@@ -0,0 +1,40 @@
/*-------------------------------------------------------------------------
NeoBuffers includes all the classes that describe pixel buffers
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 "buffers/LayoutMapCallback.h"
#include "buffers/NeoShaderNop.h"
#include "buffers/NeoShaderBase.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"

View File

@@ -0,0 +1,41 @@
/*-------------------------------------------------------------------------
LayoutMapCallback
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
#if defined(NEOPIXEBUS_NO_STL)
typedef uint16_t(*LayoutMapCallback)(int16_t x, int16_t y);
#else
#undef max
#undef min
#include <functional>
typedef std::function<uint16_t(int16_t x, int16_t y)> LayoutMapCallback;
#endif

View File

@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------
NeoPixel library
NeoBitmapFile
Written by Michael C. Miller.
@@ -67,6 +67,9 @@ enum BmpCompression
BI_CmykRle4
};
// T_COLOR_FEATURE - one of the Features
// T_FILE_METHOD - any standard File object following Arduino File methods/members
//
template<typename T_COLOR_FEATURE, typename T_FILE_METHOD> class NeoBitmapFile
{
public:

View File

@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------
NeoPixel library
NeoBuffer
Written by Michael C. Miller.
@@ -25,6 +25,10 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
// T_BUFFER_METHOD - one of
// NeoBufferMethod
// NeoBufferProgmemMethod
//
template<typename T_BUFFER_METHOD> class NeoBuffer
{
public:

View File

@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------
NeoPixel library
NeoBufferContext
Written by Michael C. Miller.

View File

@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------
NeoPixel library
NeoBufferMethod
Written by Michael C. Miller.
@@ -26,20 +26,6 @@ License along with NeoPixel. If not, see
#pragma once
#if defined(NEOPIXEBUS_NO_STL)
typedef uint16_t(*LayoutMapCallback)(int16_t x, int16_t y);
#else
#undef max
#undef min
#include <functional>
typedef std::function<uint16_t(int16_t x, int16_t y)> LayoutMapCallback;
#endif
template<typename T_COLOR_FEATURE> class NeoBufferMethod
{
public:
@@ -162,102 +148,5 @@ private:
uint8_t* _pixels;
};
template<typename T_COLOR_FEATURE> class NeoBufferProgmemMethod
{
public:
NeoBufferProgmemMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels) :
_width(width),
_height(height),
_pixels(pixels)
{
}
operator NeoBufferContext<T_COLOR_FEATURE>()
{
return NeoBufferContext<T_COLOR_FEATURE>(Pixels(), PixelsSize());
}
uint8_t* Pixels() const
{
return (uint8_t*)_pixels;
};
size_t PixelsSize() const
{
return PixelSize() * PixelCount();
};
size_t PixelSize() const
{
return T_COLOR_FEATURE::PixelSize;
};
uint16_t PixelCount() const
{
return _width * _height;
};
uint16_t Width() const
{
return _width;
};
uint16_t Height() const
{
return _height;
};
void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color)
{
// PROGMEM is read only, this will do nothing
};
void SetPixelColor(uint16_t x, uint16_t y, typename T_COLOR_FEATURE::ColorObject color)
{
// PROGMEM is read only, this will do nothing
};
typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const
{
if (indexPixel >= PixelCount())
{
// Pixel # is out of bounds, this will get converted to a
// color object type initialized to 0 (black)
return 0;
}
return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel);
};
typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const
{
if (x < 0 || x >= _width || y < 0 || y >= _height)
{
// Pixel # is out of bounds, this will get converted to a
// color object type initialized to 0 (black)
return 0;
}
uint16_t indexPixel = x + y * _width;
return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel);
};
void ClearTo(typename T_COLOR_FEATURE::ColorObject 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;
private:
const uint16_t _width;
const uint16_t _height;
PGM_VOID_P _pixels;
};

View File

@@ -0,0 +1,126 @@
/*-------------------------------------------------------------------------
NeoBufferProgmemMethod
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
template<typename T_COLOR_FEATURE> class NeoBufferProgmemMethod
{
public:
NeoBufferProgmemMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels) :
_width(width),
_height(height),
_pixels(pixels)
{
}
operator NeoBufferContext<T_COLOR_FEATURE>()
{
return NeoBufferContext<T_COLOR_FEATURE>(Pixels(), PixelsSize());
}
uint8_t* Pixels() const
{
return (uint8_t*)_pixels;
};
size_t PixelsSize() const
{
return PixelSize() * PixelCount();
};
size_t PixelSize() const
{
return T_COLOR_FEATURE::PixelSize;
};
uint16_t PixelCount() const
{
return _width * _height;
};
uint16_t Width() const
{
return _width;
};
uint16_t Height() const
{
return _height;
};
void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color)
{
// PROGMEM is read only, this will do nothing
};
void SetPixelColor(uint16_t x, uint16_t y, typename T_COLOR_FEATURE::ColorObject color)
{
// PROGMEM is read only, this will do nothing
};
typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const
{
if (indexPixel >= PixelCount())
{
// Pixel # is out of bounds, this will get converted to a
// color object type initialized to 0 (black)
return 0;
}
return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel);
};
typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const
{
if (x < 0 || x >= _width || y < 0 || y >= _height)
{
// Pixel # is out of bounds, this will get converted to a
// color object type initialized to 0 (black)
return 0;
}
uint16_t indexPixel = x + y * _width;
return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel);
};
void ClearTo(typename T_COLOR_FEATURE::ColorObject 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;
private:
const uint16_t _width;
const uint16_t _height;
PGM_VOID_P _pixels;
};

View File

@@ -1,5 +1,6 @@
/*-------------------------------------------------------------------------
NeoPixel library
NeoDib - Device Independant Bitmap, interal data stored in RGB/RGBW format
rather than the ColorFeature format
Written by Michael C. Miller.
@@ -25,59 +26,14 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
template<typename T_COLOR_OBJECT> class NeoShaderNop
{
public:
NeoShaderNop()
{
}
bool IsDirty() const
{
return true;
};
void Dirty()
{
};
void ResetDirty()
{
};
T_COLOR_OBJECT Apply(uint16_t, T_COLOR_OBJECT color)
{
return color;
};
};
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
};
// T_COLOR_OBJECT - one of the color objects
// RgbColor
// RgbwColor
// Rgb16Color
// Rgb48Color
// Rgbw64Color
// SevenSegDigit
//
template<typename T_COLOR_OBJECT> class NeoDib
{
public:

View File

@@ -0,0 +1,53 @@
/*-------------------------------------------------------------------------
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
<http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------*/
#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
};

View File

@@ -0,0 +1,53 @@
/*-------------------------------------------------------------------------
NeoShaderNop
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
template<typename T_COLOR_OBJECT> class NeoShaderNop
{
public:
NeoShaderNop()
{
}
bool IsDirty() const
{
return true;
};
void Dirty()
{
};
void ResetDirty()
{
};
T_COLOR_OBJECT Apply(uint16_t, T_COLOR_OBJECT color)
{
return color;
};
};

View File

@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------
NeoPixel library
NeoVerticalSpriteSheet
Written by Michael C. Miller.
@@ -25,7 +25,10 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
// T_BUFFER_METHOD - one of
// NeoBufferMethod
// NeoBufferProgmemMethod
//
template<typename T_BUFFER_METHOD> class NeoVerticalSpriteSheet
{
public: