Add horizontalFlip() and verticalFlip() to BitmapBuffer

This commit is contained in:
Bertrand Songis
2020-04-08 16:14:59 +02:00
parent f60fc76628
commit 4e27a07a38
2 changed files with 31 additions and 1 deletions
+26
View File
@@ -676,6 +676,32 @@ BitmapBuffer * BitmapBuffer::loadMask(const char * filename)
return bitmap;
}
BitmapBuffer * BitmapBuffer::horizontalFlip() const
{
BitmapBuffer * result = new BitmapBuffer(format, width(), height());
pixel_t * srcData = data;
pixel_t * destData = result->data;
for (uint8_t y = 0; y < height(); y++) {
for (uint8_t x = 0; x < width(); x++) {
destData[x] = srcData[width() - 1 - x];
}
srcData += width();
destData += width();
}
return result;
}
BitmapBuffer * BitmapBuffer::verticalFlip() const
{
BitmapBuffer * result = new BitmapBuffer(format, width(), height());
for (uint8_t y = 0; y < height(); y++) {
for (uint8_t x = 0; x < width(); x++) {
result->data[y * width() + x] = data[(height() - 1 - y) * width() + x];
}
}
return result;
}
BitmapBuffer * BitmapBuffer::loadMaskOnBackground(const char * filename, LcdFlags foreground, LcdFlags background)
{
BitmapBuffer * result = nullptr;
+5 -1
View File
@@ -232,7 +232,7 @@ class RLEBitmap:
}
};
class BitmapBuffer: public BitmapBufferBase<uint16_t>
class BitmapBuffer: public BitmapBufferBase<pixel_t>
{
private:
bool dataAllocated;
@@ -500,6 +500,10 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
drawBitmap(x + xshift, y + yshift, bitmap, 0, 0, 0, 0, scale);
}
BitmapBuffer * horizontalFlip() const;
BitmapBuffer * verticalFlip() const;
protected:
static BitmapBuffer * load_bmp(const char * filename);
static BitmapBuffer * load_stb(const char * filename);