forked from Makuna/NeoPixelBus
Const and Warning Correctness
const method correctness fix some warnings Missing Render method added back Fix examples to use new NeoShaderBase
This commit is contained in:
@ -36,12 +36,12 @@ const RgbColor White(255);
|
||||
const RgbColor Black(0);
|
||||
|
||||
// define a custom shader object that provides brightness support
|
||||
// based upon the NeoBitsBase
|
||||
template<typename T_COLOR_FEATURE> class BrightnessShader : public NeoBitsBase
|
||||
// based upon the NeoShaderBase
|
||||
template<typename T_COLOR_FEATURE> class BrightnessShader : public NeoShaderBase
|
||||
{
|
||||
public:
|
||||
BrightnessShader():
|
||||
NeoBitsBase(),
|
||||
NeoShaderBase(),
|
||||
_brightness(255) // default to full bright
|
||||
{}
|
||||
|
||||
|
@ -34,12 +34,12 @@ const RgbColor White(255);
|
||||
const RgbColor Black(0);
|
||||
|
||||
// define a custom shader object that provides brightness support
|
||||
// based upon the NeoBitsBase
|
||||
class BrightnessShader : public NeoBitsBase
|
||||
// based upon the NeoShaderBase
|
||||
class BrightnessShader : public NeoShaderBase
|
||||
{
|
||||
public:
|
||||
BrightnessShader():
|
||||
NeoBitsBase(),
|
||||
NeoShaderBase(),
|
||||
_brightness(255) // default to full bright
|
||||
{}
|
||||
|
||||
|
@ -75,12 +75,11 @@ public:
|
||||
_width(0),
|
||||
_height(0),
|
||||
_sizeRow(0),
|
||||
_bottomToTop(true),
|
||||
_bytesPerPixel(0)
|
||||
_bytesPerPixel(0),
|
||||
_bottomToTop(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
~NeoBitmapFile()
|
||||
{
|
||||
_file.close();
|
||||
@ -205,7 +204,7 @@ public:
|
||||
{
|
||||
for (int16_t x = 0; x < wSrc && indexPixel < destPixelCount; x++, indexPixel++)
|
||||
{
|
||||
if (xSrc < _width)
|
||||
if ((uint16_t)xSrc < _width)
|
||||
{
|
||||
if (readPixel(&color))
|
||||
{
|
||||
@ -239,7 +238,7 @@ public:
|
||||
{
|
||||
for (int16_t x = 0; x < wSrc; x++)
|
||||
{
|
||||
if (xFile < _width)
|
||||
if ((uint16_t)xFile < _width)
|
||||
{
|
||||
if (readPixel(&color))
|
||||
{
|
||||
@ -268,26 +267,26 @@ private:
|
||||
uint8_t _bytesPerPixel;
|
||||
bool _bottomToTop;
|
||||
|
||||
int16_t constrainX(int16_t x)
|
||||
int16_t constrainX(int16_t x) const
|
||||
{
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
else if (x >= _width)
|
||||
else if ((uint16_t)x >= _width)
|
||||
{
|
||||
x = _width - 1;
|
||||
}
|
||||
return x;
|
||||
};
|
||||
|
||||
int16_t constrainY(int16_t y)
|
||||
int16_t constrainY(int16_t y) const
|
||||
{
|
||||
if (y < 0)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
else if (y >= _height)
|
||||
else if ((uint16_t)y >= _height)
|
||||
{
|
||||
y = _height - 1;
|
||||
}
|
||||
|
@ -133,19 +133,38 @@ 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)
|
||||
{
|
||||
uint16_t countPixels = destBuffer.PixelCount();
|
||||
|
||||
if (countPixels > _method.PixelCount())
|
||||
{
|
||||
countPixels = _method.PixelCount();
|
||||
}
|
||||
|
||||
for (uint16_t indexPixel = 0; indexPixel < countPixels; indexPixel++)
|
||||
{
|
||||
typename T_BUFFER_METHOD::ColorObject color;
|
||||
|
||||
shader.Apply(indexPixel, (uint8_t*)(&color), _method.Pixels() + (indexPixel * _method.PixelSize()));
|
||||
|
||||
T_BUFFER_METHOD::ColorFeature::applyPixelColor(destBuffer.Pixels, indexPixel, color);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
T_BUFFER_METHOD _method;
|
||||
|
||||
uint16_t pixelIndex(
|
||||
int16_t x,
|
||||
int16_t y)
|
||||
int16_t y) const
|
||||
{
|
||||
uint16_t result = PixelIndex_OutOfBounds;
|
||||
|
||||
if (x >= 0 &&
|
||||
x < Width() &&
|
||||
(uint16_t)x < Width() &&
|
||||
y >= 0 &&
|
||||
y < Height())
|
||||
(uint16_t)y < Height())
|
||||
{
|
||||
result = x + y * Width();
|
||||
}
|
||||
|
@ -123,6 +123,7 @@ public:
|
||||
if (IsDirty() || shader.IsDirty())
|
||||
{
|
||||
uint16_t countPixels = destBuffer.PixelCount();
|
||||
|
||||
if (countPixels > _countPixels)
|
||||
{
|
||||
countPixels = _countPixels;
|
||||
|
@ -146,15 +146,15 @@ private:
|
||||
|
||||
uint16_t pixelIndex(uint16_t indexSprite,
|
||||
int16_t x,
|
||||
int16_t y)
|
||||
int16_t y) const
|
||||
{
|
||||
uint16_t result = PixelIndex_OutOfBounds;
|
||||
|
||||
if (indexSprite < _spriteCount &&
|
||||
x >= 0 &&
|
||||
x < SpriteWidth() &&
|
||||
(uint16_t)x < SpriteWidth() &&
|
||||
y >= 0 &&
|
||||
y < SpriteHeight())
|
||||
(uint16_t)y < SpriteHeight())
|
||||
{
|
||||
result = x + y * SpriteWidth() + indexSprite * _spriteHeight * SpriteWidth();
|
||||
}
|
||||
|
Reference in New Issue
Block a user