Move opacity in a separate parameter and use true color instead of palette index

This commit is contained in:
Raphael Coeffic
2021-05-07 22:41:43 +02:00
parent 784bf73ae9
commit 8ec57dd39e
3 changed files with 44 additions and 50 deletions
+35 -23
View File
@@ -41,7 +41,7 @@ void BitmapBuffer::drawAlphaPixel(pixel_t * p, uint8_t opacity, uint16_t color)
}
}
void BitmapBuffer::drawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t pat, LcdFlags flags)
void BitmapBuffer::drawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t pat, LcdFlags flags, uint8_t opacity)
{
APPLY_OFFSET();
@@ -49,14 +49,19 @@ void BitmapBuffer::drawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t p
if (!applyClippingRect(x, y, w, h))
return;
drawHorizontalLineAbs(x, y, w, pat, flags);
drawHorizontalLineAbs(x, y, w, pat, flags, opacity);
}
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, uint8_t opacity)
{
pixel_t * p = getPixelPtrAbs(x, y);
pixel_t color = lcdColorTable[COLOR_IDX(flags)];
uint8_t opacity = 0x0F - (flags >> 24);
pixel_t color = COLOR_VAL(flags);
// Opacity needs to be inverted:
// 0 : Opaque
// 15 : Translucid
//
opacity = 0x0F - opacity;
if (pat == SOLID) {
while (w--) {
@@ -78,7 +83,7 @@ void BitmapBuffer::drawHorizontalLineAbs(coord_t x, coord_t y, coord_t w, uint8_
}
}
void BitmapBuffer::drawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat, LcdFlags flags)
void BitmapBuffer::drawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat, LcdFlags flags, uint8_t opacity)
{
APPLY_OFFSET();
@@ -86,9 +91,13 @@ void BitmapBuffer::drawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat
if (!applyClippingRect(x, y, w, h))
return;
pixel_t color = lcdColorTable[COLOR_IDX(flags)];
uint8_t opacity = 0x0F - (flags >> 24);
// Opacity needs to be inverted:
// 0 : Opaque
// 15 : Translucid
//
opacity = 0x0F - opacity;
pixel_t color = COLOR_VAL(flags);
if (pat == SOLID) {
while (h--) {
drawAlphaPixelAbs(x, y, opacity, color);
@@ -120,7 +129,8 @@ void BitmapBuffer::drawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint
x2 += offsetX;
y2 += offsetY;
pixel_t color = lcdColorTable[COLOR_IDX(flags)];
// No 'opacity' here, only 'color'
pixel_t color = COLOR_VAL(flags);
int dx = x2 - x1; /* the horizontal distance of the line */
int dy = y2 - y1; /* the vertical distance of the line */
@@ -163,13 +173,13 @@ void BitmapBuffer::drawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint
}
}
void BitmapBuffer::drawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t thickness, uint8_t pat, LcdFlags flags)
void BitmapBuffer::drawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t thickness, uint8_t pat, LcdFlags flags, uint8_t opacity)
{
for (unsigned i = 0; i < thickness; i++) {
drawVerticalLine(x + i, y, h, pat, flags);
drawVerticalLine(x + w - 1 - i, y, h, pat, flags);
drawHorizontalLine(x, y + h - 1 - i, w, pat, flags);
drawHorizontalLine(x, y + i, w, pat, flags);
drawVerticalLine(x + i, y, h, pat, flags, opacity);
drawVerticalLine(x + w - 1 - i, y, h, pat, flags, opacity);
drawHorizontalLine(x, y + h - 1 - i, w, pat, flags, opacity);
drawHorizontalLine(x, y + i, w, pat, flags, opacity);
}
}
@@ -180,10 +190,11 @@ void BitmapBuffer::drawSolidFilledRect(coord_t x, coord_t y, coord_t w, coord_t
if (!applyClippingRect(x, y, w, h))
return;
DMAFillRect(data, _width, _height, x, y, w, h, lcdColorTable[COLOR_IDX(flags)]);
// No 'opacity' here, only 'color'
DMAFillRect(data, _width, _height, x, y, w, h, COLOR_VAL(flags));
}
void BitmapBuffer::drawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat, LcdFlags flags)
void BitmapBuffer::drawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat, LcdFlags flags, uint8_t opacity)
{
APPLY_OFFSET();
@@ -191,7 +202,7 @@ void BitmapBuffer::drawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, ui
return;
for (coord_t i = y; i < y + h; i++) {
drawHorizontalLineAbs(x, i, w, pat, flags);
drawHorizontalLineAbs(x, i, w, pat, flags, opacity);
}
}
@@ -199,7 +210,8 @@ void BitmapBuffer::invertRect(coord_t x, coord_t y, coord_t w, coord_t h, LcdFla
{
APPLY_OFFSET();
pixel_t color = lcdColorTable[COLOR_IDX(flags)];
// No 'opacity' here, only 'color'
pixel_t color = COLOR_VAL(flags);
RGB_SPLIT(color, red, green, blue);
for (int i = y; i < y + h; i++) {
@@ -218,7 +230,7 @@ void BitmapBuffer::drawCircle(coord_t x, coord_t y, coord_t radius, LcdFlags fla
int x1 = radius;
int y1 = 0;
int decisionOver2 = 1 - x1;
pixel_t color = lcdColorTable[COLOR_IDX(flags)];
pixel_t color = COLOR_VAL(flags);
while (y1 <= x1) {
drawPixel(x1 + x, y1 + y, color);
@@ -353,7 +365,7 @@ void BitmapBuffer::drawBitmapPatternPie(coord_t x, coord_t y, const uint8_t * im
Slope startSlope(startAngle);
Slope endSlope(endAngle);
pixel_t color = lcdColorTable[COLOR_IDX(flags)];
pixel_t color = COLOR_VAL(flags);
coord_t width = *((uint16_t *)img);
coord_t height = *(((uint16_t *)img) + 1);
@@ -390,7 +402,7 @@ void BitmapBuffer::drawAnnulusSector(coord_t x, coord_t y, coord_t internalRadiu
Slope startSlope(startAngle);
Slope endSlope(endAngle);
pixel_t color = lcdColorTable[COLOR_IDX(flags)];
pixel_t color = COLOR_VAL(flags);
APPLY_OFFSET();
coord_t internalDist = internalRadius * internalRadius;
@@ -441,7 +453,7 @@ void BitmapBuffer::drawMask(coord_t x, coord_t y, const BitmapBuffer * mask, Lcd
if (y >= ymax || x >= xmax || width <= 0 || x + width < xmin || y + height < ymin)
return;
pixel_t color = lcdColorTable[COLOR_IDX(flags)];
pixel_t color = COLOR_VAL(flags);
for (coord_t row = 0; row < height; row++) {
if (y + row < ymin || y + row >= ymax)
@@ -519,7 +531,7 @@ void BitmapBuffer::drawBitmapPattern(coord_t x, coord_t y, const uint8_t * bmp,
return;
}
pixel_t color = lcdColorTable[COLOR_IDX(flags)];
pixel_t color = COLOR_VAL(flags);
for (coord_t row=0; row<height; row++) {
if (y + row < ymin || y + row >= ymax)
+5 -5
View File
@@ -314,9 +314,9 @@ class BitmapBuffer: public BitmapBufferBase<pixel_t>
drawAlphaPixelAbs(x, y, opacity, value);
}
void drawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t pat = SOLID, LcdFlags flags = 0);
void drawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t pat = SOLID, LcdFlags flags = 0, uint8_t opacity = OPACITY_MAX);
void drawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat = SOLID, LcdFlags flags = 0);
void drawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat = SOLID, LcdFlags flags = 0, uint8_t opacity = OPACITY_MAX);
void drawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags att);
@@ -330,7 +330,7 @@ class BitmapBuffer: public BitmapBufferBase<pixel_t>
drawSolidFilledRect(x, y, 1, h, flags);
}
void drawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t thickness = 1, uint8_t pat = SOLID, LcdFlags flags = 0);
void drawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t thickness = 1, uint8_t pat = SOLID, LcdFlags flags = 0, uint8_t opacity = OPACITY_MAX);
inline void drawSolidRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t thickness = 1, LcdFlags flags = 0)
{
@@ -342,7 +342,7 @@ class BitmapBuffer: public BitmapBufferBase<pixel_t>
void drawSolidFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, LcdFlags flags = 0);
void drawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat = SOLID, LcdFlags flags = 0);
void drawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat = SOLID, LcdFlags flags = 0, uint8_t opacity = OPACITY_MAX);
void invertRect(coord_t x, coord_t y, coord_t w, coord_t h, LcdFlags flags = 0);
@@ -587,7 +587,7 @@ class BitmapBuffer: public BitmapBufferBase<pixel_t>
drawAlphaPixel(p, opacity, color);
}
void drawHorizontalLineAbs(coord_t x, coord_t y, coord_t w, uint8_t pat, LcdFlags flags);
void drawHorizontalLineAbs(coord_t x, coord_t y, coord_t w, uint8_t pat, LcdFlags flags, uint8_t opacity);
};
extern BitmapBuffer * lcd;
+4 -22
View File
@@ -75,31 +75,13 @@
(((color) & 0x001F) << 3)
#define OPACITY_MAX 0x0Fu
#define OPACITY(value) ((value) << 24u)
#define OPACITY(value) ((value) & OPACITY_MAX)
#define RGB(r, g, b) (uint16_t)((((r) & 0xF8) << 8) + (((g) & 0xFC) << 3) + (((b) & 0xF8) >> 3))
#define ARGB(a, r, g, b) (uint16_t)((((a) & 0xF0) << 8) + (((r) & 0xF0) << 4) + (((g) & 0xF0) << 0) + (((b) & 0xF0) >> 4))
#define COLOR(index) LcdFlags(unsigned(index) << 16u)
#define COLOR_IDX(flags) uint8_t((flags) >> 16u)
#define COLOR2FLAGS(color) LcdFlags(unsigned(color) << 16u)
#define COLOR_VAL(flags) ((flags) >> 16u)
#define COLOR_MASK(flags) ((flags) & 0xFFFF0000u)
#define DEFAULT_COLOR COLOR(DEFAULT_COLOR_INDEX)
#define DEFAULT_BGCOLOR COLOR(DEFAULT_BGCOLOR_INDEX)
#define FOCUS_COLOR COLOR(FOCUS_COLOR_INDEX)
#define FOCUS_BGCOLOR COLOR(FOCUS_BGCOLOR_INDEX)
#define DISABLE_COLOR COLOR(DISABLE_COLOR_INDEX)
#define HIGHLIGHT_COLOR COLOR(HIGHLIGHT_COLOR_INDEX)
#define CHECKBOX_COLOR COLOR(CHECKBOX_COLOR_INDEX)
#define SCROLLBAR_COLOR COLOR(SCROLLBAR_COLOR_INDEX)
#define MENU_COLOR COLOR(MENU_COLOR_INDEX)
#define MENU_BGCOLOR COLOR(MENU_BGCOLOR_INDEX)
#define MENU_TITLE_BGCOLOR COLOR(MENU_TITLE_BGCOLOR_INDEX)
#define MENU_LINE_COLOR COLOR(MENU_LINE_COLOR_INDEX)
#define MENU_HIGHLIGHT_COLOR COLOR(MENU_HIGHLIGHT_COLOR_INDEX)
#define MENU_HIGHLIGHT_BGCOLOR COLOR(MENU_HIGHLIGHT_BGCOLOR_INDEX)
#define OVERLAY_COLOR COLOR(OVERLAY_COLOR_INDEX)
#define TABLE_BGCOLOR COLOR(TABLE_BGCOLOR_INDEX)
#define TABLE_HEADER_BGCOLOR COLOR(TABLE_HEADER_BGCOLOR_INDEX)
#define CUSTOM_COLOR COLOR(CUSTOM_COLOR_INDEX)
#define COLOR(index) (lcdColorTable[ unsigned(index) & 0xFF ] << 16u)