mirror of https://github.com/MLXXXp/Arduboy2.git
Minor source format changes for drawCompressed()
No code changes from previous commit.
This commit is contained in:
parent
6f6849a5bb
commit
d44b89e01f
|
@ -846,17 +846,19 @@ void Arduboy2Base::drawSlowXYBitmap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct BitStreamReader {
|
// Helper for drawCompressed()
|
||||||
|
struct BitStreamReader
|
||||||
|
{
|
||||||
const uint8_t *source;
|
const uint8_t *source;
|
||||||
uint16_t sourceIndex;
|
uint16_t sourceIndex;
|
||||||
uint8_t bitBuffer;
|
uint8_t bitBuffer;
|
||||||
uint8_t byteBuffer;
|
uint8_t byteBuffer;
|
||||||
|
|
||||||
BitStreamReader(const uint8_t *source)
|
BitStreamReader(const uint8_t *source)
|
||||||
: source(source), sourceIndex(), bitBuffer(), byteBuffer()
|
: source(source), sourceIndex(), bitBuffer(), byteBuffer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t readBits(uint16_t bitCount)
|
uint16_t readBits(uint16_t bitCount)
|
||||||
{
|
{
|
||||||
uint16_t result = 0;
|
uint16_t result = 0;
|
||||||
|
@ -868,25 +870,22 @@ struct BitStreamReader {
|
||||||
this->byteBuffer = pgm_read_byte(&this->source[this->sourceIndex]);
|
this->byteBuffer = pgm_read_byte(&this->source[this->sourceIndex]);
|
||||||
++this->sourceIndex;
|
++this->sourceIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((this->byteBuffer & this->bitBuffer) != 0)
|
if ((this->byteBuffer & this->bitBuffer) != 0)
|
||||||
result |= (1 << i); // result |= bitshift_left[i];
|
result |= (1 << i); // result |= bitshift_left[i];
|
||||||
|
|
||||||
this->bitBuffer <<= 1;
|
this->bitBuffer <<= 1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void Arduboy2Base::drawCompressed(int16_t sx, int16_t sy, const uint8_t *bitmap, uint8_t color)
|
void Arduboy2Base::drawCompressed(int16_t sx, int16_t sy, const uint8_t *bitmap, uint8_t color)
|
||||||
{
|
{
|
||||||
// set up decompress state
|
// set up decompress state
|
||||||
|
|
||||||
BitStreamReader cs = BitStreamReader(bitmap);
|
BitStreamReader cs = BitStreamReader(bitmap);
|
||||||
|
|
||||||
// read header
|
// read header
|
||||||
|
|
||||||
int width = (int)cs.readBits(8) + 1;
|
int width = (int)cs.readBits(8) + 1;
|
||||||
int height = (int)cs.readBits(8) + 1;
|
int height = (int)cs.readBits(8) + 1;
|
||||||
uint8_t spanColour = (uint8_t)cs.readBits(1); // starting colour
|
uint8_t spanColour = (uint8_t)cs.readBits(1); // starting colour
|
||||||
|
@ -896,7 +895,6 @@ void Arduboy2Base::drawCompressed(int16_t sx, int16_t sy, const uint8_t *bitmap,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// sy = sy - (frame * height);
|
// sy = sy - (frame * height);
|
||||||
|
|
||||||
int yOffset = abs(sy) % 8;
|
int yOffset = abs(sy) % 8;
|
||||||
int startRow = sy / 8;
|
int startRow = sy / 8;
|
||||||
if (sy < 0) {
|
if (sy < 0) {
|
||||||
|
@ -909,7 +907,7 @@ void Arduboy2Base::drawCompressed(int16_t sx, int16_t sy, const uint8_t *bitmap,
|
||||||
|
|
||||||
int rowOffset = 0; // +(frame*rows);
|
int rowOffset = 0; // +(frame*rows);
|
||||||
int columnOffset = 0;
|
int columnOffset = 0;
|
||||||
|
|
||||||
uint8_t byte = 0x00;
|
uint8_t byte = 0x00;
|
||||||
uint8_t bit = 0x01;
|
uint8_t bit = 0x01;
|
||||||
while (rowOffset < rows) // + (frame*rows))
|
while (rowOffset < rows) // + (frame*rows))
|
||||||
|
@ -933,14 +931,15 @@ void Arduboy2Base::drawCompressed(int16_t sx, int16_t sy, const uint8_t *bitmap,
|
||||||
int bRow = startRow + rowOffset;
|
int bRow = startRow + rowOffset;
|
||||||
|
|
||||||
//if (byte) // possible optimisation
|
//if (byte) // possible optimisation
|
||||||
if ((bRow <= (HEIGHT / 8) - 1) && (bRow > -2) && (columnOffset + sx <= (WIDTH - 1)) && (columnOffset + sx >= 0))
|
if ((bRow <= (HEIGHT / 8) - 1) && (bRow > -2) &&
|
||||||
|
(columnOffset + sx <= (WIDTH - 1)) && (columnOffset + sx >= 0))
|
||||||
{
|
{
|
||||||
int16_t offset = (bRow * WIDTH) + sx + columnOffset;
|
int16_t offset = (bRow * WIDTH) + sx + columnOffset;
|
||||||
if (bRow >= 0)
|
if (bRow >= 0)
|
||||||
{
|
{
|
||||||
int16_t index = offset;
|
int16_t index = offset;
|
||||||
uint8_t value = byte << yOffset;
|
uint8_t value = byte << yOffset;
|
||||||
|
|
||||||
if (color != 0)
|
if (color != 0)
|
||||||
sBuffer[index] |= value;
|
sBuffer[index] |= value;
|
||||||
else
|
else
|
||||||
|
@ -950,7 +949,7 @@ void Arduboy2Base::drawCompressed(int16_t sx, int16_t sy, const uint8_t *bitmap,
|
||||||
{
|
{
|
||||||
int16_t index = offset + WIDTH;
|
int16_t index = offset + WIDTH;
|
||||||
uint8_t value = byte >> (8 - yOffset);
|
uint8_t value = byte >> (8 - yOffset);
|
||||||
|
|
||||||
if (color != 0)
|
if (color != 0)
|
||||||
sBuffer[index] |= value;
|
sBuffer[index] |= value;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue