Created
June 23, 2015 21:34
-
-
Save jc4p/d9da27e47c7933fe6b03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Calculates if the given textColor is readable when laid ontop of the given backgroundColor. | |
* | |
* http://www.seas.upenn.edu/~cse400/CSE400_2012_2013/reports/01_report.pdf | |
*/ | |
public static boolean isTextReadable(int backgroundColor, int textColor) { | |
double brightnessBackground = (299*Color.red(backgroundColor) + 587*Color.green(backgroundColor) + 114*Color.blue(backgroundColor)) / 1000.0; | |
double brightnessText = (299*Color.red(textColor) + 587*Color.green(textColor) + 114*Color.blue(textColor)) / 1000.0; | |
double brightnessDelta = Math.abs(brightnessBackground - brightnessText); | |
double hueDelta = Math.abs(Color.red(backgroundColor) - Color.red(textColor)) + | |
Math.abs(Color.green(backgroundColor) - Color.green(textColor)) + Math.abs(Color.blue(backgroundColor) - Color.blue(textColor)); | |
return brightnessDelta > 125 && hueDelta > 500; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment