public static Color contrastForegroundColor(Color color) {
		float[] rgbs = new float[3];
		color.getRGBColorComponents(rgbs);
		int fR = rgbs[0] > 0.5 ? 0 : 1;
		int fG = rgbs[1] > 0.5 ? 0 : 1;
		int fB = rgbs[2] > 0.5 ? 0 : 1;

		// Note: the more accurate operation for calculating luminance is:
		// float gamma = 2.2;
		// float luminance = 0.2126 * pow(r, gamma) + 
		//                   0.7152 * pow(g, gamma) + 
		//                   0.0722 * pow(b, gamma);

		// less precise, faster calculation
		double luminance = 0.2126 * (fR * fR) + 0.7152 * (fG * fG) + 0.0722 * (fB * fB);
		Color foreground = Color.WHITE;
		if (luminance < 0.54) { // about half (a bit fudge, since we are approximating the pow())
			foreground = Color.BLACK;
		}
		return foreground;
	}
A method to produce a color (either black or white) that contrasts with the given color. This
is useful for finding a readable foreground color for a given background.

@param color the color for which to find a contrast.
@return the contrasting color.
Ghidra/Framework/Gui/src/main/java/ghidra/util/ColorUtils.java