diff options
author | inmarket <andrewh@inmarket.com.au> | 2014-05-11 20:05:31 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2014-05-11 20:05:31 +1000 |
commit | 3a98279583cb5d8489fff26f89d148b6f807aa07 (patch) | |
tree | 482bb8d556830e0e3263172b760df669bd97e026 /src/gdisp/gdisp.c | |
parent | 0a7f498f3ed27fabc072efc3776d8d4a2de308e7 (diff) | |
download | uGFX-3a98279583cb5d8489fff26f89d148b6f807aa07.tar.gz uGFX-3a98279583cb5d8489fff26f89d148b6f807aa07.tar.bz2 uGFX-3a98279583cb5d8489fff26f89d148b6f807aa07.zip |
Add gdispContrastColor() and remove divides from gdispBlendColors()
Diffstat (limited to 'src/gdisp/gdisp.c')
-rw-r--r-- | src/gdisp/gdisp.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c index 9f3ff11b..e9ede8ab 100644 --- a/src/gdisp/gdisp.c +++ b/src/gdisp/gdisp.c @@ -3020,13 +3020,23 @@ color_t gdispBlendColor(color_t fg, color_t bg, uint8_t alpha) g += GREEN_OF(bg) * bg_ratio; b += BLUE_OF(bg) * bg_ratio; - r /= 256; - g /= 256; - b /= 256; + r >>= 8; + g >>= 8; + b >>= 8; return RGB2COLOR(r, g, b); } +color_t gdispContrastColor(color_t color) { + uint16_t r, g, b; + + r = RED_OF(color) > 128 ? 0 : 255; + g = GREEN_OF(color) > 128 ? 0 : 255; + b = BLUE_OF(color) > 128 ? 0 : 255; + + return RGB2COLOR(r, g, b); +} + #if (!defined(gdispPackPixels) && !defined(GDISP_PIXELFORMAT_CUSTOM)) void gdispPackPixels(pixel_t *buf, coord_t cx, coord_t x, coord_t y, color_t color) { /* No mutex required as we only read static data */ |