From 199975b95cdaebb0039699ed023f0217dc1436ec Mon Sep 17 00:00:00 2001 From: David PHAM-VAN <1387855+DavBfr@users.noreply.github.com> Date: Mon, 5 Sep 2022 05:30:26 -0300 Subject: [PATCH] Add BitmapBuffer::to8bitMask (#63) --- .../thirdparty/libopenui/src/bitmapbuffer.cpp | 26 +++++++++++++++++++ .../thirdparty/libopenui/src/bitmapbuffer.h | 4 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index a95aea46a..bc1c5493e 100644 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -917,6 +917,32 @@ void BitmapBuffer::drawAnnulusSector(coord_t x, coord_t y, coord_t internalRadiu } } +uint8_t * BitmapBuffer::to8bitMask(size_t* size) const { + *size = width() * height()+4; + uint8_t* mask = (uint8_t*)malloc(*size); + ((uint16_t*)mask)[0] = width(); + ((uint16_t*)mask)[1] = height(); + const pixel_t * p = getPixelPtrAbs(0, 0); + if (getFormat() == BMP_ARGB4444) { + auto ofs = 4u; + for (int i = width() * height(); i > 0; i--) { + ARGB_SPLIT(*p, a __attribute__((unused)), r, g, b); + auto v = ((uint32_t)r + (uint32_t)g + (uint32_t)b) / 3; + mask[ofs++] = ((OPACITY_MAX - v) << 4); + MOVE_TO_NEXT_RIGHT_PIXEL(p); + } + } else { // BMP_RGB565 + auto ofs = 4u; + for (int i = width() * height(); i > 0; i--) { + auto v = ((GET_RED(*p) >> 1) + (GET_GREEN(*p) >> 2) + (GET_BLUE(*p) >> 1)) / 3; + mask[ofs++] = ((OPACITY_MAX - v) << 4); + MOVE_TO_NEXT_RIGHT_PIXEL(p); + } + } + + return mask; +} + void BitmapBuffer::drawMask(coord_t x, coord_t y, const BitmapBuffer * mask, LcdFlags flags, coord_t offsetX, coord_t width) { if (!mask) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h index 1172b18aa..ccceec5f5 100644 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h @@ -320,7 +320,9 @@ class BitmapBuffer: public BitmapBufferBase static BitmapBuffer * load8bitMaskOnBackground(const uint8_t * lbm, LcdFlags foreground, LcdFlags background); static uint8_t * loadFont(const uint8_t * lbm, int len, int& w, int& h); - + + uint8_t * to8bitMask(size_t* size) const; + void drawMask(coord_t x, coord_t y, const BitmapBuffer * mask, LcdFlags flags, coord_t offsetX = 0, coord_t width = 0); void drawMask(coord_t x, coord_t y, const BitmapBuffer * mask, const BitmapBuffer * srcBitmap, coord_t offsetX = 0, coord_t offsetY = 0, coord_t width = 0, coord_t height = 0);