Cosmetics

This commit is contained in:
Bertrand Songis
2021-04-11 16:21:11 +02:00
parent 910d1420e7
commit 46a47f225b
2 changed files with 58 additions and 46 deletions
+14 -14
View File
@@ -54,7 +54,7 @@ void BitmapBuffer::drawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t p
void BitmapBuffer::drawHorizontalLineAbs(coord_t x, coord_t y, coord_t w, uint8_t pat, LcdFlags flags) void BitmapBuffer::drawHorizontalLineAbs(coord_t x, coord_t y, coord_t w, uint8_t pat, LcdFlags flags)
{ {
pixel_t * p = getPixelPtr(x, y); pixel_t * p = getPixelPtrAbs(x, y);
pixel_t color = lcdColorTable[COLOR_IDX(flags)]; pixel_t color = lcdColorTable[COLOR_IDX(flags)];
uint8_t opacity = 0x0F - (flags >> 24); uint8_t opacity = 0x0F - (flags >> 24);
@@ -203,7 +203,7 @@ void BitmapBuffer::invertRect(coord_t x, coord_t y, coord_t w, coord_t h, LcdFla
RGB_SPLIT(color, red, green, blue); RGB_SPLIT(color, red, green, blue);
for (int i = y; i < y + h; i++) { for (int i = y; i < y + h; i++) {
pixel_t * p = getPixelPtr(x, i); pixel_t * p = getPixelPtrAbs(x, i);
for (int j = 0; j < w; j++) { for (int j = 0; j < w; j++) {
// TODO ASSERT_IN_DISPLAY(p); // TODO ASSERT_IN_DISPLAY(p);
RGB_SPLIT(*p, bgRed, bgGreen, bgBlue); RGB_SPLIT(*p, bgRed, bgGreen, bgBlue);
@@ -446,8 +446,8 @@ void BitmapBuffer::drawMask(coord_t x, coord_t y, const BitmapBuffer * mask, Lcd
for (coord_t row = 0; row < height; row++) { for (coord_t row = 0; row < height; row++) {
if (y + row < ymin || y + row >= ymax) if (y + row < ymin || y + row >= ymax)
continue; continue;
pixel_t * p = getPixelPtr(x, y + row); pixel_t * p = getPixelPtrAbs(x, y + row);
const pixel_t * q = mask->getPixelPtr(offsetX, row); const pixel_t * q = mask->getPixelPtrAbs(offsetX, row);
for (coord_t col = 0; col < width; col++) { for (coord_t col = 0; col < width; col++) {
drawAlphaPixel(p, *((uint8_t *)q), color); drawAlphaPixel(p, *((uint8_t *)q), color);
MOVE_TO_NEXT_RIGHT_PIXEL(p); MOVE_TO_NEXT_RIGHT_PIXEL(p);
@@ -490,10 +490,10 @@ void BitmapBuffer::drawMask(coord_t x, coord_t y, const BitmapBuffer * mask, con
for (coord_t row = 0; row < height; row++) { for (coord_t row = 0; row < height; row++) {
if (y + row < ymin || y + row >= ymax) if (y + row < ymin || y + row >= ymax)
continue; continue;
pixel_t * p = getPixelPtr(x, y + row); pixel_t * p = getPixelPtrAbs(x, y + row);
const pixel_t * q = mask->getPixelPtr(offsetX, offsetY + row); const pixel_t * q = mask->getPixelPtrAbs(offsetX, offsetY + row);
for (coord_t col = 0; col < width; col++) { for (coord_t col = 0; col < width; col++) {
drawAlphaPixel(p, *((uint8_t *)q), *srcBitmap->getPixelPtr(row, col)); drawAlphaPixel(p, *((uint8_t *)q), *srcBitmap->getPixelPtrAbs(row, col));
MOVE_TO_NEXT_RIGHT_PIXEL(p); MOVE_TO_NEXT_RIGHT_PIXEL(p);
MOVE_TO_NEXT_RIGHT_PIXEL(q); MOVE_TO_NEXT_RIGHT_PIXEL(q);
} }
@@ -536,7 +536,7 @@ void BitmapBuffer::drawBitmapPattern(coord_t x, coord_t y, const uint8_t * bmp,
ypixel = y + row; ypixel = y + row;
} }
if (xpixel >= xmin && xpixel < xmax) { if (xpixel >= xmin && xpixel < xmax) {
pixel_t * p = getPixelPtr(xpixel, ypixel); pixel_t * p = getPixelPtrAbs(xpixel, ypixel);
if (p) if (p)
drawAlphaPixel(p, *q, color); drawAlphaPixel(p, *q, color);
} }
@@ -720,7 +720,7 @@ BitmapBuffer * BitmapBuffer::loadMask(const char * filename)
{ {
BitmapBuffer * bitmap = BitmapBuffer::loadBitmap(filename); BitmapBuffer * bitmap = BitmapBuffer::loadBitmap(filename);
if (bitmap) { if (bitmap) {
pixel_t * p = bitmap->getPixelPtr(0, 0); pixel_t * p = bitmap->getPixelPtrAbs(0, 0);
for (int i = bitmap->width() * bitmap->height(); i > 0; i--) { for (int i = bitmap->width() * bitmap->height(); i > 0; i--) {
*((uint8_t *)p) = OPACITY_MAX - ((*p) >> 12); *((uint8_t *)p) = OPACITY_MAX - ((*p) >> 12);
MOVE_TO_NEXT_RIGHT_PIXEL(p); MOVE_TO_NEXT_RIGHT_PIXEL(p);
@@ -902,7 +902,7 @@ BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
switch (depth) { switch (depth) {
case 16: case 16:
for (int i = h - 1; i >= 0; i--) { for (int i = h - 1; i >= 0; i--) {
pixel_t * dst = bmp->getPixelPtr(0, i); pixel_t * dst = bmp->getPixelPtrAbs(0, i);
for (unsigned int j = 0; j < w; j++) { for (unsigned int j = 0; j < w; j++) {
result = f_read(&imgFile, (uint8_t *)dst, 2, &read); result = f_read(&imgFile, (uint8_t *)dst, 2, &read);
if (result != FR_OK || read != 2) { if (result != FR_OK || read != 2) {
@@ -917,7 +917,7 @@ BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
case 32: case 32:
for (int i = h - 1; i >= 0; i--) { for (int i = h - 1; i >= 0; i--) {
pixel_t * dst = bmp->getPixelPtr(0, i); pixel_t * dst = bmp->getPixelPtrAbs(0, i);
for (unsigned int j = 0; j < w; j++) { for (unsigned int j = 0; j < w; j++) {
uint32_t pixel; uint32_t pixel;
result = f_read(&imgFile, (uint8_t *)&pixel, 4, &read); result = f_read(&imgFile, (uint8_t *)&pixel, 4, &read);
@@ -936,7 +936,7 @@ BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
else { else {
hasAlpha = true; hasAlpha = true;
bmp->setFormat(BMP_ARGB4444); bmp->setFormat(BMP_ARGB4444);
for (pixel_t * p = bmp->getPixelPtr(j, i); p != bmp->getPixelPtr(0, h); MOVE_TO_NEXT_RIGHT_PIXEL(p)) { for (pixel_t * p = bmp->getPixelPtrAbs(j, i); p != bmp->getPixelPtrAbs(0, h); MOVE_TO_NEXT_RIGHT_PIXEL(p)) {
pixel_t tmp = *p; pixel_t tmp = *p;
*p = ((tmp >> 1) & 0x0f) + (((tmp >> 7) & 0x0f) << 4) + (((tmp >> 12) & 0x0f) << 8); *p = ((tmp >> 1) & 0x0f) + (((tmp >> 7) & 0x0f) << 4) + (((tmp >> 12) & 0x0f) << 8);
} }
@@ -960,7 +960,7 @@ BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
delete bmp; delete bmp;
return nullptr; return nullptr;
} }
pixel_t * dst = bmp->getPixelPtr(0, i); pixel_t * dst = bmp->getPixelPtrAbs(0, i);
for (uint32_t j=0; j<w; j++) { for (uint32_t j=0; j<w; j++) {
uint8_t index = (buf[j/2] >> ((j & 1) ? 0 : 4)) & 0x0F; uint8_t index = (buf[j/2] >> ((j & 1) ? 0 : 4)) & 0x0F;
uint8_t val = palette[index]; uint8_t val = palette[index];
@@ -1079,7 +1079,7 @@ BitmapBuffer * BitmapBuffer::load_stb(const char * filename)
#if 0 #if 0
DMABitmapConvert(bmp->data, img, w, h, n == 4 ? DMA2D_ARGB4444 : DMA2D_RGB565); DMABitmapConvert(bmp->data, img, w, h, n == 4 ? DMA2D_ARGB4444 : DMA2D_RGB565);
#else #else
pixel_t * dest = bmp->getPixelPtr(0, 0); pixel_t * dest = bmp->getPixelPtrAbs(0, 0);
const uint8_t * p = img; const uint8_t * p = img;
if (n == 4) { if (n == 4) {
for (int row = 0; row < h; ++row) { for (int row = 0; row < h; ++row) {
+44 -32
View File
@@ -153,7 +153,7 @@ class BitmapBufferBase
return _width * _height * sizeof(T); return _width * _height * sizeof(T);
} }
inline const pixel_t * getPixelPtr(coord_t x, coord_t y) const inline const pixel_t * getPixelPtrAbs(coord_t x, coord_t y) const
{ {
#if defined(LCD_VERTICAL_INVERT) #if defined(LCD_VERTICAL_INVERT)
x = _width - x - 1; x = _width - x - 1;
@@ -278,35 +278,15 @@ class BitmapBuffer: public BitmapBufferBase<pixel_t>
drawSolidFilledRect(0, 0, _width - offsetX, _height - offsetY, flags); drawSolidFilledRect(0, 0, _width - offsetX, _height - offsetY, flags);
} }
inline void drawPixel(pixel_t * p, pixel_t value)
{
if (data && (data <= p || p < data_end)) {
*p = value;
}
#if defined(DEBUG)
else if (!leakReported) {
leakReported = true;
TRACE("BitmapBuffer(%p).drawPixel(): buffer overrun, data: %p, written at: %p", this, data, p);
}
#endif
}
inline const pixel_t * getPixelPtr(coord_t x, coord_t y) const inline const pixel_t * getPixelPtr(coord_t x, coord_t y) const
{ {
#if defined(LCD_VERTICAL_INVERT) APPLY_OFFSET();
x = _width - x - 1;
y = _height - y - 1;
#endif
return &data[y * _width + x];
}
inline pixel_t * getPixelPtr(coord_t x, coord_t y) coord_t w = 1, h = 1;
{ if (!applyClippingRect(x, y, w, h))
#if defined(LCD_VERTICAL_INVERT) return nullptr;
x = _width - x - 1;
y = _height - y - 1; return getPixelPtrAbs(x, y);
#endif
return &data[y * _width + x];
} }
inline void drawPixel(coord_t x, coord_t y, pixel_t value) inline void drawPixel(coord_t x, coord_t y, pixel_t value)
@@ -484,8 +464,8 @@ class BitmapBuffer: public BitmapBufferBase<pixel_t>
scaledh = _height - y; scaledh = _height - y;
for (int i = 0; i < scaledh; i++) { for (int i = 0; i < scaledh; i++) {
pixel_t * p = getPixelPtr(x, y + i); pixel_t * p = getPixelPtrAbs(x, y + i);
const pixel_t * qstart = bmp->getPixelPtr(srcx, srcy + int(i / scale)); const pixel_t * qstart = bmp->getPixelPtrAbs(srcx, srcy + int(i / scale));
for (int j = 0; j < scaledw; j++) { for (int j = 0; j < scaledw; j++) {
const pixel_t * q = qstart; const pixel_t * q = qstart;
MOVE_PIXEL_RIGHT(q, int(j / scale)); MOVE_PIXEL_RIGHT(q, int(j / scale));
@@ -526,7 +506,7 @@ class BitmapBuffer: public BitmapBufferBase<pixel_t>
static BitmapBuffer * load_bmp(const char * filename); static BitmapBuffer * load_bmp(const char * filename);
static BitmapBuffer * load_stb(const char * filename); static BitmapBuffer * load_stb(const char * filename);
inline bool applyClippingRect(coord_t & x, coord_t & y, coord_t & w, coord_t & h) inline bool applyClippingRect(coord_t & x, coord_t & y, coord_t & w, coord_t & h) const
{ {
if (h < 0) { if (h < 0) {
y += h; y += h;
@@ -562,15 +542,47 @@ class BitmapBuffer: public BitmapBufferBase<pixel_t>
uint8_t drawChar(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, unsigned int index, LcdFlags flags); uint8_t drawChar(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, unsigned int index, LcdFlags flags);
inline void drawPixel(pixel_t * p, pixel_t value)
{
if (data && (data <= p || p < data_end)) {
*p = value;
}
#if defined(DEBUG)
else if (!leakReported) {
leakReported = true;
TRACE("BitmapBuffer(%p).drawPixel(): buffer overrun, data: %p, written at: %p", this, data, p);
}
#endif
}
inline const pixel_t * getPixelPtrAbs(coord_t x, coord_t y) const
{
#if defined(LCD_VERTICAL_INVERT)
x = _width - x - 1;
y = _height - y - 1;
#endif
return &data[y * _width + x];
}
inline pixel_t * getPixelPtrAbs(coord_t x, coord_t y)
{
#if defined(LCD_VERTICAL_INVERT)
x = _width - x - 1;
y = _height - y - 1;
#endif
return &data[y * _width + x];
}
inline void drawPixelAbs(coord_t x, coord_t y, pixel_t value) inline void drawPixelAbs(coord_t x, coord_t y, pixel_t value)
{ {
pixel_t * p = getPixelPtr(x, y); pixel_t * p = getPixelPtrAbs(x, y);
drawPixel(p, value); drawPixel(p, value);
} }
inline void drawAlphaPixelAbs(coord_t x, coord_t y, uint8_t opacity, uint16_t color) inline void drawAlphaPixelAbs(coord_t x, coord_t y, uint8_t opacity, uint16_t color)
{ {
pixel_t * p = getPixelPtr(x, y); pixel_t * p = getPixelPtrAbs(x, y);
drawAlphaPixel(p, opacity, color); drawAlphaPixel(p, opacity, color);
} }