feature (kernel): Implemented a color palette and fixed an alpha blending overflow bug

This commit is contained in:
antifallobst 2023-02-22 23:30:32 +01:00
parent 08dad6c971
commit 48f10b6e30
2 changed files with 33 additions and 4 deletions

View File

@ -18,6 +18,21 @@
#include "utils/stdtypes.h"
// Colors from https://gogh-co.github.io/Gogh/
typedef enum {
COLOR_PAL_GREY_DARK,
COLOR_PAL_PINK,
COLOR_PAL_GREEN_SIGNAL,
COLOR_PAL_ORANGE,
COLOR_PAL_BLUE,
COLOR_PAL_PURPLE,
COLOR_PAL_GREEN,
COLOR_PAL_GREY_LIGHT,
COLOR_PAL_RED,
COLOR_PAL_ENUM_END
} color_palette_E;
typedef struct {
uint8_t alpha;
uint8_t red;
@ -25,6 +40,8 @@ typedef struct {
uint8_t blue;
} color_argb_T;
extern color_argb_T color_palette[COLOR_PAL_ENUM_END];
color_argb_T color_argb_blend_alpha(color_argb_T background, color_argb_T foreground);
#endif //NOX_COLOR_H

View File

@ -15,11 +15,23 @@
#include "drivers/graphics/color.h"
color_argb_T color_palette[COLOR_PAL_ENUM_END] = {
{0xFF, 0x36, 0x36, 0x36}, // GREY_DARK
{0xFF, 0xFF, 0x08, 0x83}, // PINK
{0xFF, 0x83, 0xff, 0x08}, // GREEN_SIGNAL
{0xFF, 0xFF, 0x83, 0x08}, // ORANGE
{0xFF, 0x08, 0x83, 0xFF}, // BLUE
{0xFF, 0x83, 0x08, 0xFF}, // PURPLE
{0xFF, 0x08, 0xFF, 0x83}, // GREEN
{0xFF, 0xB6, 0xB6, 0xB6}, // GREY_LIGHT
{0xFF, 0xFF, 0x00, 0x00}, // RED
};
color_argb_T color_argb_blend_alpha(color_argb_T background, color_argb_T foreground) {
color_argb_T color = foreground;
color.red += ((foreground.red * foreground.alpha) + (background.red * (0xFF - foreground.alpha))) / 0xFF;
color.green += ((foreground.green * foreground.alpha) + (background.green * (0xFF - foreground.alpha))) / 0xFF;
color.blue += ((foreground.blue * foreground.alpha) + (background.blue * (0xFF - foreground.alpha))) / 0xFF;
color_argb_T color;
color.red = ((foreground.red * foreground.alpha) + (background.red * (0xFF - foreground.alpha))) / 0xFF;
color.green = ((foreground.green * foreground.alpha) + (background.green * (0xFF - foreground.alpha))) / 0xFF;
color.blue = ((foreground.blue * foreground.alpha) + (background.blue * (0xFF - foreground.alpha))) / 0xFF;
return color;
}