Fixed clipping in drawBitmapPattern()

This commit is contained in:
Raphael Coeffic
2021-05-07 22:41:43 +02:00
parent 76cdb7f527
commit 21940b1572
+28 -15
View File
@@ -762,30 +762,43 @@ void BitmapBuffer::drawBitmapPattern(coord_t x, coord_t y, const uint8_t * bmp,
{ {
APPLY_OFFSET(); APPLY_OFFSET();
coord_t w = *((uint16_t *)bmp); // 'w' -> width of the font file coord_t bmpw = *((uint16_t *)bmp); // 'w' -> width of the font file
coord_t height = *(((uint16_t *)bmp)+1); // height of the font file coord_t bmph = *(((uint16_t *)bmp)+1); // height of the font file
// skip header // skip header
bmp += 4; bmp += 4;
// 'width' -> font character we want coord_t srcx = offset;
if (!width || width > w) { coord_t srcy = 0;
width = w;
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) { if (srcw <= 0 || srch <= 0) {
width = xmax - x;
}
if (y >= ymax || x >= xmax || width <= 0 || x + width < xmin || y + height < ymin) {
return; return;
} }
// TODO: DMACopyAlphaMask(data, _width, _height, x, y, bmp, bmpw, bmph,
// - add some defs to libopenui_depends.h srcx, srcy, srcw, srch, COLOR_VAL(flags));
//
DMACopyAlphaMask(data, _width, _height, x, y, bmp, w, height,
offset, 0, width, height, 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) uint8_t BitmapBuffer::drawChar(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, unsigned int index, LcdFlags flags)