From e4b47d435ed8e9bfbb7923f1b3d21953a589f302 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 16 Aug 2018 12:35:49 -0700 Subject: [PATCH] Const and Warning Correctness const method correctness fix some warnings Missing Render method added back Fix examples to use new NeoShaderBase --- .../NeoPixelBufferShader.ino | 6 ++--- .../NeoPixelDibTest/NeoPixelDibTest.ino | 6 ++--- src/internal/NeoBitmapFile.h | 19 +++++++------- src/internal/NeoBuffer.h | 25 ++++++++++++++++--- src/internal/NeoDib.h | 1 + src/internal/NeoSpriteSheet.h | 6 ++--- 6 files changed, 41 insertions(+), 22 deletions(-) diff --git a/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino b/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino index 37a109f..c2c8e74 100644 --- a/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino +++ b/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino @@ -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 class BrightnessShader : public NeoBitsBase +// based upon the NeoShaderBase +template class BrightnessShader : public NeoShaderBase { public: BrightnessShader(): - NeoBitsBase(), + NeoShaderBase(), _brightness(255) // default to full bright {} diff --git a/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino b/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino index c421b5b..1a13c13 100644 --- a/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino +++ b/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino @@ -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 {} diff --git a/src/internal/NeoBitmapFile.h b/src/internal/NeoBitmapFile.h index 6979678..96a1624 100644 --- a/src/internal/NeoBitmapFile.h +++ b/src/internal/NeoBitmapFile.h @@ -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; } diff --git a/src/internal/NeoBuffer.h b/src/internal/NeoBuffer.h index 86176c9..996a778 100644 --- a/src/internal/NeoBuffer.h +++ b/src/internal/NeoBuffer.h @@ -133,19 +133,38 @@ public: Blt(destBuffer, xDest, yDest, 0, 0, Width(), Height(), layoutMap); } + template void Render(NeoBufferContext 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(); } diff --git a/src/internal/NeoDib.h b/src/internal/NeoDib.h index ef69ce6..7327061 100644 --- a/src/internal/NeoDib.h +++ b/src/internal/NeoDib.h @@ -123,6 +123,7 @@ public: if (IsDirty() || shader.IsDirty()) { uint16_t countPixels = destBuffer.PixelCount(); + if (countPixels > _countPixels) { countPixels = _countPixels; diff --git a/src/internal/NeoSpriteSheet.h b/src/internal/NeoSpriteSheet.h index a0f277e..83fb978 100644 --- a/src/internal/NeoSpriteSheet.h +++ b/src/internal/NeoSpriteSheet.h @@ -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(); }