diff --git a/enabler/src/de/schildbach/pte/dto/Style.java b/enabler/src/de/schildbach/pte/dto/Style.java index a7107b1b..8c61c80c 100644 --- a/enabler/src/de/schildbach/pte/dto/Style.java +++ b/enabler/src/de/schildbach/pte/dto/Style.java @@ -128,13 +128,16 @@ public class Style implements Serializable return color & 0xff; } - public static int deriveForegroundColor(final int backgroundColor) + public static float perceivedBrightness(final int color) { // formula for perceived brightness computation: http://www.w3.org/TR/AERT#color-contrast - final double a = 1 - (0.299 * Style.red(backgroundColor) + 0.587 * Style.green(backgroundColor) + 0.114 * Style.blue(backgroundColor)) / 255; + return (0.299f * Style.red(color) + 0.587f * Style.green(color) + 0.114f * Style.blue(color)) / 256; + } + public static int deriveForegroundColor(final int backgroundColor) + { // dark colors, white font. Or light colors, black font - if (a >= 0.5) + if (perceivedBrightness(backgroundColor) < 0.5) return WHITE; else return BLACK;