Calculating Color Brightness - gchudnov/cpp-colors GitHub Wiki

To determine whether you should be using white or black text depending on the background color, calculate the color brightness:

  color c1 = boost::lexical_cast<color>(L"#ffef4444");
  auto value = brightness(c1); // value == brightness_value::dark

The returned brightness value gives a perceived brightness for a color.

To ensure that the text is visible on the background of a given color, select white for brightness_value::dark and black for brightness_value::light.

⚠️ **GitHub.com Fallback** ⚠️