I'm creating a custom beamer theme and defined a command to set the colors used in the presentation like that: `\definecolor{primarycolor}{HTML}{9C27B0}` (purple btw).  

Let's say `primarycolor` is my background color of a frame.

Now, I want to be able to calculate the brightness/luminance of a given color to determine a fitting color for the text (either black or white). In the case of purple, white would be a readable text-color.

I would do it like that (pseudo-code):   

`luminance := 0.2126 * Red + 0.7152 * Green + 0.0722 * Blue`   

`textcolor := luminance < 128 ? black : white`

How do I get the RGB values of a color and then determine the "contrast-color" (black or white)?