aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2017-10-02 16:47:18 +1000
committerinmarket <andrewh@inmarket.com.au>2017-10-02 16:47:18 +1000
commitf9be386e52a745d19c880aa035c577bed3eb11c7 (patch)
treecf1e220a134e3be514442d44588b9f91c0326931
parentfdaf636b5f0c7ff5280438f524a07c29a2f7eea6 (diff)
downloaduGFX-f9be386e52a745d19c880aa035c577bed3eb11c7.tar.gz
uGFX-f9be386e52a745d19c880aa035c577bed3eb11c7.tar.bz2
uGFX-f9be386e52a745d19c880aa035c577bed3eb11c7.zip
Add alpha blending support
-rw-r--r--src/gdisp/gdisp.c60
-rw-r--r--src/gdisp/gdisp_colors.h9
2 files changed, 51 insertions, 18 deletions
diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c
index 1941bd88..3af31ac2 100644
--- a/src/gdisp/gdisp.c
+++ b/src/gdisp/gdisp.c
@@ -3649,26 +3649,54 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
}
#endif
-color_t gdispBlendColor(color_t fg, color_t bg, uint8_t alpha)
-{
- uint16_t fg_ratio = alpha + 1;
- uint16_t bg_ratio = 256 - alpha;
- uint16_t r, g, b;
+#if GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_RGB888
+ // Special alpha hacked version.
+ // Note: this will still work with real RGB888
+ color_t gdispBlendColor(color_t fg, color_t bg, uint8_t alpha)
+ {
+ uint16_t fg_ratio = alpha + 1;
+ uint16_t bg_ratio = 256 - alpha;
+ uint16_t a, r, g, b;
+
+ a = ALPHA_OF(fg) * fg_ratio;
+ r = RED_OF(fg) * fg_ratio;
+ g = GREEN_OF(fg) * fg_ratio;
+ b = BLUE_OF(fg) * fg_ratio;
+
+ a += ALPHA_OF(bg) * bg_ratio;
+ r += RED_OF(bg) * bg_ratio;
+ g += GREEN_OF(bg) * bg_ratio;
+ b += BLUE_OF(bg) * bg_ratio;
+
+ a >>= 8;
+ r >>= 8;
+ g >>= 8;
+ b >>= 8;
+
+ return ARGB2COLOR(a, r, g, b);
+ }
+#else
+ color_t gdispBlendColor(color_t fg, color_t bg, uint8_t alpha)
+ {
+ uint16_t fg_ratio = alpha + 1;
+ uint16_t bg_ratio = 256 - alpha;
+ uint16_t r, g, b;
- r = RED_OF(fg) * fg_ratio;
- g = GREEN_OF(fg) * fg_ratio;
- b = BLUE_OF(fg) * fg_ratio;
+ r = RED_OF(fg) * fg_ratio;
+ g = GREEN_OF(fg) * fg_ratio;
+ b = BLUE_OF(fg) * fg_ratio;
- r += RED_OF(bg) * bg_ratio;
- g += GREEN_OF(bg) * bg_ratio;
- b += BLUE_OF(bg) * bg_ratio;
+ r += RED_OF(bg) * bg_ratio;
+ g += GREEN_OF(bg) * bg_ratio;
+ b += BLUE_OF(bg) * bg_ratio;
- r >>= 8;
- g >>= 8;
- b >>= 8;
+ r >>= 8;
+ g >>= 8;
+ b >>= 8;
- return RGB2COLOR(r, g, b);
-}
+ return RGB2COLOR(r, g, b);
+ }
+#endif
color_t gdispContrastColor(color_t color) {
uint16_t r, g, b;
diff --git a/src/gdisp/gdisp_colors.h b/src/gdisp/gdisp_colors.h
index 5bfcfca2..0973e561 100644
--- a/src/gdisp/gdisp_colors.h
+++ b/src/gdisp/gdisp_colors.h
@@ -330,9 +330,14 @@ typedef uint16_t colorformat;
// Special hack to allow alpha on RGB888
#if GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_RGB888
- #define GFXTRANSPARENT (0xFF000000)
+ #define COLOR_BITS_A 8
+ #define COLOR_SHIFT_A 24
+ #define ALPHA_OF(c) (((c)>>24) ^ 0xFF)
+ #define EXACT_ALPHA_OF(c) ALPHA_OF((c))
#define AHTML2COLOR(h) ((h) ^ 0xFF000000)
- #define ARGB2COLOR(a,r,g,b) ((((COLOR_TYPE)(((a) ^ 0xFF) & 0xFF)) << 24) | RGB2COLOR_R(r) | RGB2COLOR_G(g) | RGB2COLOR_B(b))
+ #define RGB2COLOR_A(a) (((COLOR_TYPE)(((a) ^ 0xFF) & 0xFF)) << 24)
+ #define ARGB2COLOR(a,r,g,b) (RGB2COLOR_A(a) | RGB2COLOR_R(r) | RGB2COLOR_G(g) | RGB2COLOR_B(b))
+ #define GFXTRANSPARENT (0xFF000000)
#endif
//-------------------------