question: public static Color correctReadability ( Color foreground , Color background ) { int bd = getBrightnessDifference ( foreground , background ) ; if ( Math . abs ( bd ) < 50 ) { if ( getBrightness ( background ) > 180 ) { foreground = makeDarker ( foreground , 0.5f ) ; } else { foreground = makeBrighter ( foreground , 0.5f ) ; } } return foreground ; }
target:  Tries to change the color (if necessary) so it it better readable on the given background color. This works for a few colors, but is far from perfect. For example some colors have a high enough brightness difference, but they are still not very well readable, e.g. springgreen on light grey.