How to implement a color contrast enriching algorithm?
<p>I am currently developing  an App. In this App I get some RGB color code from the server, that I want to display. </p>

<p>As the color I get should be the background color of a Label, there is some text, that should be displayed above it. The user defining the color is completely free in choosing a color, so I am in need of finding an algorithm, where the text color of the label is somehow contrasted to the color I get from the webservice.</p>

<p>Problem explained in an example:</p>

<ul>
<li>I choose <code>black 0x000000</code> to be the textcolor. If the user defines a color like <code>dark gray 0x111111</code>, the text's visibility would be very bad.</li>
</ul>

<p>In addition, I want the text color to be black or white in order to not over-color the app.</p>

<p>So how can I determine, if white or black is the better color for the textcolor, based on a RGB code I get from the server?</p>