flutter_statusbarcolor icon indicating copy to clipboard operation
flutter_statusbarcolor copied to clipboard

useWhiteForeground() should use "HSP Color Model" for better results

Open slavap opened this issue 5 years ago • 0 comments

http://alienryderflex.com/hsp.html

Current implementation tends to choose black in cases when white is much more appropriate.

  /// Returns - a number in the rage of 0 (black) to 255 (white).
  ///
  /// See **HSP Color Model**: http://alienryderflex.com/hsp.html
  static int calcBrightness(Color color) {
    var v = sqrt(pow(color.red, 2) * 0.299 + pow(color.green, 2) * 0.587 + pow(color.blue, 2) * 0.114);
    int brightness = v.round();
    return brightness;
  }

  static bool useWhiteForeground(Color color) {
    // I selected cutoff value of 130 by trial and error and it reflects my taste,
    // every value in the rage 128-145 will give acceptable results.
    return calcBrightness(color) < 130 ? true : false;
  }

slavap avatar Dec 12 '19 02:12 slavap