Skip to content

Commit

Permalink
Test if a color can be considered dark for issue #715.
Browse files Browse the repository at this point in the history
  • Loading branch information
gijsbers committed Oct 30, 2023
1 parent 56f4701 commit 6d5d516
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ycolor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,17 @@ unsigned char YColor::green() { return fPixel->green() >> 8; }
unsigned char YColor::blue() { return fPixel->blue() >> 8; }
unsigned char YColor::alpha() { return fPixel->alpha() >> 8; }

bool YColor::isDark() {
float ys = 0;
if (fPixel) {
float r = float(fPixel->red()) / 65535.0f;
float g = float(fPixel->green()) / 65535.0f;
float b = float(fPixel->blue()) / 65535.0f;
ys += r * r * 0.2126f;
ys += g * g * 0.7152f;
ys += b * b * 0.0722f;
}
return ys < 0.3948f;
}

// vim: set sw=4 ts=4 et:
1 change: 1 addition & 0 deletions src/ycolor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class YColor {
YColor darker();
YColor brighter();
YColor& reverse();
bool isDark();

bool operator==(YColor& c);
bool operator!=(YColor& c);
Expand Down

0 comments on commit 6d5d516

Please sign in to comment.