From f603207a8ea7678018f88acf95ea71fa45396e97 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 15 May 2021 01:09:57 +0200 Subject: [PATCH] Added 8bit mask loading --- .../thirdparty/libopenui/src/bitmapbuffer.cpp | 29 +++++++++++++++++++ .../thirdparty/libopenui/src/bitmapbuffer.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index 4a611aa65..9ab2724af 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -996,6 +996,20 @@ BitmapBuffer * BitmapBuffer::loadMask(const char * filename) return bitmap; } +BitmapBuffer * BitmapBuffer::load8bitMask(const uint8_t * lbm) +{ + BitmapBuffer * bitmap = new BitmapBuffer(BMP_RGB565,lbm[0],lbm[1]); + if (bitmap) { + pixel_t * p = bitmap->getPixelPtrAbs(0, 0); + const uint8_t * src = lbm + 2; + for (int i = bitmap->width() * bitmap->height(); i > 0; i--) { + *((uint8_t *)p) = (*(src++) >> 4); + MOVE_TO_NEXT_RIGHT_PIXEL(p); + } + } + return bitmap; +} + BitmapBuffer * BitmapBuffer::invertMask() const { BitmapBuffer * result = new BitmapBuffer(format, width(), height()); @@ -1052,6 +1066,21 @@ BitmapBuffer * BitmapBuffer::loadMaskOnBackground(const char * filename, LcdFlag return result; } +BitmapBuffer * BitmapBuffer::load8bitMaskOnBackground(const uint8_t * lbm, LcdFlags foreground, LcdFlags background) +{ + BitmapBuffer * result = nullptr; + BitmapBuffer * mask = BitmapBuffer::load8bitMask(lbm); + if (mask) { + result = new BitmapBuffer(BMP_RGB565, mask->width(), mask->height()); + if (result) { + result->clear(background); + result->drawMask(0, 0, mask, foreground); + } + delete mask; + } + return result; +} + FIL imgFile __DMA; BitmapBuffer * BitmapBuffer::load_bmp(const char * filename) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h index f447a6344..cc42766aa 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h @@ -293,8 +293,10 @@ class BitmapBuffer: public BitmapBufferBase static BitmapBuffer * loadBitmap(const char * filename); static BitmapBuffer * loadMask(const char * filename); + static BitmapBuffer * load8bitMask(const uint8_t * lbm); static BitmapBuffer * loadMaskOnBackground(const char * filename, LcdFlags foreground, LcdFlags background); + static BitmapBuffer * load8bitMaskOnBackground(const uint8_t * lbm, LcdFlags foreground, LcdFlags background); void drawMask(coord_t x, coord_t y, const BitmapBuffer * mask, LcdFlags flags, coord_t offsetX = 0, coord_t width = 0);