forked from Makuna/NeoPixelBus
buffers
This commit is contained in:
@@ -114,13 +114,11 @@ public:
|
||||
delete[] _pixels;
|
||||
}
|
||||
|
||||
/* Is this used anymore
|
||||
operator NeoBufferContext<T_COLOR_FEATURE>()
|
||||
|
||||
operator NeoBufferContext<T_EXPOSED_COLOR_OBJECT>()
|
||||
{
|
||||
Dirty(); // we assume you are playing with bits
|
||||
return NeoBufferContext<T_COLOR_FEATURE>(_pixels(), PixelsSize());
|
||||
return NeoBufferContext<T_EXPOSED_COLOR_OBJECT>(_pixels, _countPixels);
|
||||
}
|
||||
*/
|
||||
|
||||
void Begin()
|
||||
{
|
||||
|
@@ -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"
|
||||
|
||||
|
@@ -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<typename T_COLOR_FEATURE, typename T_FILE_METHOD> class NeoBitmapFile
|
||||
template<typename T_COLOR_OBJECT, typename T_FILE_METHOD> 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 <typename T_SHADER> void Render(NeoBufferContext<T_COLOR_FEATURE> destBuffer,
|
||||
template <typename T_SHADER> void Render(NeoBufferContext<T_COLOR_OBJECT> 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<T_COLOR_FEATURE> destBuffer,
|
||||
void Blt(NeoBufferContext<T_COLOR_OBJECT> destBuffer,
|
||||
uint16_t indexPixel,
|
||||
int16_t xSrc,
|
||||
int16_t ySrc,
|
||||
int16_t wSrc)
|
||||
{
|
||||
NeoShaderNop<typename T_COLOR_FEATURE::ColorObject, typename T_COLOR_FEATURE::ColorObject> shaderNop;
|
||||
NeoShaderNop<T_COLOR_OBJECT, T_COLOR_OBJECT> shaderNop;
|
||||
|
||||
Render<NeoShaderNop<typename T_COLOR_FEATURE::ColorObject, typename T_COLOR_FEATURE::ColorObject>>(destBuffer, shaderNop, indexPixel, xSrc, ySrc, wSrc);
|
||||
Render<NeoShaderNop<T_COLOR_OBJECT, T_COLOR_OBJECT>>(destBuffer, shaderNop, indexPixel, xSrc, ySrc, wSrc);
|
||||
};
|
||||
|
||||
template <typename T_SHADER> void Render(NeoBufferContext<T_COLOR_FEATURE> destBuffer,
|
||||
template <typename T_SHADER> void Render(NeoBufferContext<T_COLOR_OBJECT> 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<T_COLOR_FEATURE> destBuffer,
|
||||
void Blt(NeoBufferContext<T_COLOR_OBJECT> destBuffer,
|
||||
int16_t xDest,
|
||||
int16_t yDest,
|
||||
int16_t xSrc,
|
||||
@@ -285,9 +285,9 @@ public:
|
||||
int16_t hSrc,
|
||||
LayoutMapCallback layoutMap)
|
||||
{
|
||||
NeoShaderNop<typename T_COLOR_FEATURE::ColorObject, typename T_COLOR_FEATURE::ColorObject> shaderNop;
|
||||
NeoShaderNop<T_COLOR_OBJECT, T_COLOR_OBJECT> shaderNop;
|
||||
|
||||
Render<NeoShaderNop<typename T_COLOR_FEATURE::ColorObject, typename T_COLOR_FEATURE::ColorObject>>(destBuffer,
|
||||
Render<NeoShaderNop<T_COLOR_OBJECT, T_COLOR_OBJECT>>(destBuffer,
|
||||
shaderNop,
|
||||
xDest,
|
||||
yDest,
|
||||
|
@@ -33,7 +33,7 @@ template<typename T_BUFFER_METHOD> 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<typename T_BUFFER_METHOD::ColorFeature>()
|
||||
operator NeoBufferContext<typename T_BUFFER_METHOD::ColorObject>()
|
||||
{
|
||||
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<typename T_BUFFER_METHOD::ColorFeature> destBuffer,
|
||||
uint16_t indexPixel)
|
||||
void Blt(NeoBufferContext<typename T_BUFFER_METHOD::ColorObject> 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<typename T_BUFFER_METHOD::ColorFeature> destBuffer,
|
||||
void Blt(NeoBufferContext<typename T_BUFFER_METHOD::ColorObject> 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<typename T_BUFFER_METHOD::ColorFeature> destBuffer,
|
||||
void Blt(NeoBufferContext<typename T_BUFFER_METHOD::ColorObject> destBuffer,
|
||||
int16_t xDest,
|
||||
int16_t yDest,
|
||||
LayoutMapCallback layoutMap)
|
||||
@@ -141,21 +155,19 @@ public:
|
||||
Blt(destBuffer, xDest, yDest, 0, 0, Width(), Height(), layoutMap);
|
||||
}
|
||||
|
||||
template <typename T_SHADER> void Render(NeoBufferContext<typename T_BUFFER_METHOD::ColorFeature> destBuffer, T_SHADER& shader)
|
||||
template <typename T_SHADER> void Render(NeoBufferContext<typename T_BUFFER_METHOD::ColorObject> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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 <typename T_COLOR_FEATURE> struct NeoBufferContext
|
||||
template <typename T_COLOR_OBJECT> 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;
|
||||
|
||||
};
|
||||
T_COLOR_OBJECT* Pixels;
|
||||
const size_t PixelsCount;
|
||||
;
|
@@ -26,30 +26,34 @@ License along with NeoPixel. If not, see
|
||||
|
||||
#pragma once
|
||||
|
||||
template<typename T_COLOR_FEATURE> class NeoBufferMethod
|
||||
template<typename T_COLOR_OBJECT> 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<T_COLOR_FEATURE>()
|
||||
operator NeoBufferContext<T_COLOR_OBJECT>()
|
||||
{
|
||||
return NeoBufferContext<T_COLOR_FEATURE>(Pixels(), PixelsSize());
|
||||
return NeoBufferContext<T_COLOR_OBJECT>(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());
|
||||
};
|
||||
|
||||
void CopyPixels(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
|
||||
while (pixel < pixelEnd)
|
||||
{
|
||||
T_COLOR_FEATURE::movePixelsInc(pPixelDest, pPixelSrc, count);
|
||||
*pixel++ = color;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -26,7 +26,7 @@ License along with NeoPixel. If not, see
|
||||
|
||||
#pragma once
|
||||
|
||||
template<typename T_COLOR_FEATURE> class NeoBufferProgmemMethod
|
||||
template<typename T_COLOR_OBJECT> class NeoBufferProgmemMethod
|
||||
{
|
||||
public:
|
||||
NeoBufferProgmemMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels) :
|
||||
@@ -36,9 +36,9 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
operator NeoBufferContext<T_COLOR_FEATURE>()
|
||||
operator NeoBufferContext<T_COLOR_OBJECT>()
|
||||
{
|
||||
return NeoBufferContext<T_COLOR_FEATURE>(Pixels(), PixelsSize());
|
||||
return NeoBufferContext<T_COLOR_OBJECT>(Pixels(), PixelsCount());
|
||||
}
|
||||
|
||||
const uint8_t* Pixels() const
|
||||
@@ -46,16 +46,6 @@ public:
|
||||
return reinterpret_cast<const 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;
|
||||
@@ -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;
|
||||
|
@@ -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
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
|
||||
// T_COLOR_OBJECT - one of the color objects
|
||||
// RgbColor
|
||||
// RgbwColor
|
||||
// Rgb16Color
|
||||
// Rgb48Color
|
||||
// Rgbw64Color
|
||||
// SevenSegDigit
|
||||
//
|
||||
template<typename T_COLOR_OBJECT> 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 <typename T_COLOR_FEATURE, typename T_SHADER>
|
||||
void Render(NeoBufferContext<T_COLOR_FEATURE> 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
|
||||
};
|
@@ -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
|
||||
<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
|
||||
};
|
@@ -269,6 +269,12 @@ struct Rgb48Color : RgbColorBase
|
||||
float x,
|
||||
float y);
|
||||
|
||||
|
||||
static Rgb48Color PgmRead(PGM_VOID_P pPixelSrc)
|
||||
{
|
||||
return _PgmReadByWords<Rgb48Color>(pPixelSrc);
|
||||
}
|
||||
|
||||
uint32_t CalcTotalTenthMilliAmpere(const SettingsObject& settings)
|
||||
{
|
||||
auto total = 0;
|
||||
|
@@ -259,6 +259,11 @@ struct RgbColor : RgbColorBase
|
||||
float x,
|
||||
float y);
|
||||
|
||||
static RgbColor PgmRead(PGM_VOID_P pPixelSrc)
|
||||
{
|
||||
return _PgmReadByBytes<RgbColor>(pPixelSrc);
|
||||
}
|
||||
|
||||
uint32_t CalcTotalTenthMilliAmpere(const SettingsObject& settings)
|
||||
{
|
||||
auto total = 0;
|
||||
|
@@ -66,4 +66,30 @@ protected:
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T_COLOR> static T_COLOR
|
||||
_PgmReadByBytes(PGM_VOID_P pPixelSrc)
|
||||
{
|
||||
const uint8_t* pSrc = reinterpret_cast<const uint8_t*>(pPixelSrc);
|
||||
const uint8_t* pEnd = pSrc + T_COLOR::Count;
|
||||
uint8_t index = 0;
|
||||
|
||||
while (pSrc < pEnd)
|
||||
{
|
||||
color[index++] = pgm_read_byte(pSrc++);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T_COLOR> static T_COLOR
|
||||
_PgmReadByWords(PGM_VOID_P pPixelSrc)
|
||||
{
|
||||
const uint16_t* pSrc = reinterpret_cast<const uint16_t*>(pPixelSrc);
|
||||
const uint16_t* pEnd = pSrc + T_COLOR::Count;
|
||||
uint8_t index = 0;
|
||||
|
||||
while (pSrc < pEnd)
|
||||
{
|
||||
color[index++] = pgm_read_word(pSrc++);
|
||||
}
|
||||
}
|
||||
};
|
@@ -300,6 +300,11 @@ struct Rgbw64Color : RgbColorBase
|
||||
float x,
|
||||
float y);
|
||||
|
||||
static Rgbw64Color PgmRead(PGM_VOID_P pPixelSrc)
|
||||
{
|
||||
return _PgmReadByWords<Rgbw64Color>(pPixelSrc);
|
||||
}
|
||||
|
||||
uint32_t CalcTotalTenthMilliAmpere(const SettingsObject& settings)
|
||||
{
|
||||
auto total = 0;
|
||||
|
@@ -277,6 +277,12 @@ struct RgbwColor : RgbColorBase
|
||||
float x,
|
||||
float y);
|
||||
|
||||
|
||||
static RgbwColor PgmRead(PGM_VOID_P pPixelSrc)
|
||||
{
|
||||
return _PgmReadByBytes<RgbwColor>(pPixelSrc);
|
||||
}
|
||||
|
||||
uint16_t CalcTotalTenthMilliAmpere(const SettingsObject& settings)
|
||||
{
|
||||
auto total = 0;
|
||||
|
Reference in New Issue
Block a user