forked from Makuna/NeoPixelBus
spritesheet
This commit is contained in:
@@ -107,7 +107,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calc how many we can copy
|
// calc how many we can copy
|
||||||
uint16_t copyCount = destPixelCount - indexPixel;
|
uint16_t copyCount = destPixelCount - destPixelIndex;
|
||||||
uint16_t srcPixelCount = PixelCount();
|
uint16_t srcPixelCount = PixelCount();
|
||||||
if (copyCount > srcPixelCount)
|
if (copyCount > srcPixelCount)
|
||||||
{
|
{
|
||||||
|
@@ -83,12 +83,12 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void Blt(NeoBufferContext<typename T_BUFFER_METHOD::ColorFeature> destBuffer,
|
void Blt(NeoBufferContext<typename T_BUFFER_METHOD::ColorFeature> destBuffer,
|
||||||
uint16_t indexPixel,
|
uint16_t destPixelIndex,
|
||||||
uint16_t indexSprite)
|
uint16_t indexSprite)
|
||||||
{
|
{
|
||||||
uint16_t destPixelCount = destBuffer.PixelCount();
|
uint16_t destPixelCount = destBuffer.PixelCount();
|
||||||
// validate indexPixel
|
// validate destPixelIndex
|
||||||
if (indexPixel >= destPixelCount)
|
if (destPixelIndex >= destPixelCount)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -98,17 +98,20 @@ public:
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// calc how many we can copy
|
// calc how many we can copy
|
||||||
uint16_t copyCount = destPixelCount - indexPixel;
|
uint16_t copyCount = destPixelCount - destPixelIndex;
|
||||||
|
|
||||||
if (copyCount > SpriteWidth())
|
if (copyCount > SpriteWidth())
|
||||||
{
|
{
|
||||||
copyCount = SpriteWidth();
|
copyCount = SpriteWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* pDest = T_BUFFER_METHOD::ColorFeature::getPixelAddress(destBuffer.Pixels, indexPixel);
|
for (uint16_t index = 0; index < copyCount; index++)
|
||||||
const uint8_t* pSrc = T_BUFFER_METHOD::ColorFeature::getPixelAddress(_method.Pixels(), pixelIndex(indexSprite, 0, 0));
|
{
|
||||||
_method.CopyPixels(pDest, pSrc, copyCount);
|
typename T_BUFFER_METHOD::ColorObject color = _method.GetPixelColor(pixelIndex(indexSprite, index));
|
||||||
|
destBuffer.Pixels[destPixelIndex + index] = color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Blt(NeoBufferContext<typename T_BUFFER_METHOD::ColorFeature> destBuffer,
|
void Blt(NeoBufferContext<typename T_BUFFER_METHOD::ColorFeature> destBuffer,
|
||||||
@@ -131,10 +134,8 @@ public:
|
|||||||
|
|
||||||
if (indexDest < destPixelCount)
|
if (indexDest < destPixelCount)
|
||||||
{
|
{
|
||||||
const uint8_t* pSrc = T_BUFFER_METHOD::ColorFeature::getPixelAddress(_method.Pixels(), pixelIndex(indexSprite, srcX, srcY));
|
typename T_BUFFER_METHOD::ColorObject color = _method.GetPixelColor(pixelIndex(indexSprite, srcX, srcY));
|
||||||
uint8_t* pDest = T_BUFFER_METHOD::ColorFeature::getPixelAddress(destBuffer.Pixels, indexDest);
|
destBuffer.Pixels[destPixelIndex + indexDest] = color;
|
||||||
|
|
||||||
_method.CopyPixels(pDest, pSrc, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,4 +164,17 @@ private:
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t pixelIndex(uint16_t indexSprite,
|
||||||
|
uint16_t index) const
|
||||||
|
{
|
||||||
|
uint16_t result = PixelIndex_OutOfBounds;
|
||||||
|
|
||||||
|
if (indexSprite < _spriteCount &&
|
||||||
|
index < SpriteWidth() * SpriteHeight())
|
||||||
|
{
|
||||||
|
result = index + indexSprite * _spriteHeight * SpriteWidth();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
};
|
};
|
Reference in New Issue
Block a user