From 21940b15723608b601185a95cf10b3ca3b4090bb Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 26 Apr 2021 19:56:39 +0200 Subject: [PATCH] Fixed clipping in drawBitmapPattern() --- .../thirdparty/libopenui/src/bitmapbuffer.cpp | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index 354604818..237286757 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -762,30 +762,43 @@ void BitmapBuffer::drawBitmapPattern(coord_t x, coord_t y, const uint8_t * bmp, { APPLY_OFFSET(); - coord_t w = *((uint16_t *)bmp); // 'w' -> width of the font file - coord_t height = *(((uint16_t *)bmp)+1); // height of the font file + coord_t bmpw = *((uint16_t *)bmp); // 'w' -> width of the font file + coord_t bmph = *(((uint16_t *)bmp)+1); // height of the font file // skip header bmp += 4; - // 'width' -> font character we want - if (!width || width > w) { - width = w; + coord_t srcx = offset; + coord_t srcy = 0; + + coord_t srcw = (width != 0 ? width : bmpw); + coord_t srch = bmph; + if (srcx + srcw > bmpw) srcw = bmpw - srcx; + if (srcy + srch > bmph) srch = bmph - srcy; + + if (x < xmin) { + srcw += x - xmin; + srcx -= x - xmin; + x = xmin; + } + if (y < ymin) { + srch += y - ymin; + srcy -= y - ymin; + y = ymin; + } + if (x + srcw > xmax) { + srcw = xmax - x; + } + if (y + srch > ymax) { + srch = ymax - y; } - if (x + width > xmax) { - width = xmax - x; - } - - if (y >= ymax || x >= xmax || width <= 0 || x + width < xmin || y + height < ymin) { + if (srcw <= 0 || srch <= 0) { return; } - // TODO: - // - add some defs to libopenui_depends.h - // - DMACopyAlphaMask(data, _width, _height, x, y, bmp, w, height, - offset, 0, width, height, COLOR_VAL(flags)); + DMACopyAlphaMask(data, _width, _height, x, y, bmp, bmpw, bmph, + srcx, srcy, srcw, srch, COLOR_VAL(flags)); } uint8_t BitmapBuffer::drawChar(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, unsigned int index, LcdFlags flags)