mirror of
https://github.com/fltk/fltk.git
synced 2026-06-01 06:14:28 +08:00
fl_contrast() now compares the luminosity of each color (STR
#837) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4339 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -2,6 +2,8 @@ CHANGES IN FLTK 1.1.7
|
|||||||
|
|
||||||
- Documentation fixes (STR #648, STR #692, STR #730, STR
|
- Documentation fixes (STR #648, STR #692, STR #730, STR
|
||||||
#744, STR #745)
|
#744, STR #745)
|
||||||
|
- fl_contrast() now compares the luminosity of each color
|
||||||
|
(STR #837)
|
||||||
- Fl_Input_ crashed on some platforms when wrapping
|
- Fl_Input_ crashed on some platforms when wrapping
|
||||||
international text characters (STR #836)
|
international text characters (STR #836)
|
||||||
- Fixed some BMP images loading bugs (STR #825)
|
- Fixed some BMP images loading bugs (STR #825)
|
||||||
|
|||||||
+13
-7
@@ -362,20 +362,26 @@ Fl_Color fl_inactive(Fl_Color c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Fl_Color fl_contrast(Fl_Color fg, Fl_Color bg) {
|
Fl_Color fl_contrast(Fl_Color fg, Fl_Color bg) {
|
||||||
unsigned c1, c2;
|
unsigned c1, c2; // RGB colors
|
||||||
|
int l1, l2; // Luminosities
|
||||||
|
|
||||||
|
|
||||||
|
// Get the RGB values for each color...
|
||||||
if (fg & 0xffffff00) c1 = (unsigned)fg;
|
if (fg & 0xffffff00) c1 = (unsigned)fg;
|
||||||
else c1 = fl_cmap[fg];
|
else c1 = fl_cmap[fg];
|
||||||
|
|
||||||
if (bg & 0xffffff00) c2 = (unsigned)bg;
|
if (bg & 0xffffff00) c2 = (unsigned)bg;
|
||||||
else c2 = fl_cmap[bg];
|
else c2 = fl_cmap[bg];
|
||||||
|
|
||||||
if ((c1^c2)&0x80800000)
|
// Compute the luminosity...
|
||||||
return fg;
|
l1 = ((c1 >> 24) * 31 + ((c1 >> 16) & 255) * 61 + ((c1 >> 8) & 255) * 8) / 100;
|
||||||
else if (c2&0x80800000)
|
l2 = ((c2 >> 24) * 31 + ((c2 >> 16) & 255) * 61 + ((c2 >> 8) & 255) * 8) / 100;
|
||||||
return FL_BLACK;
|
|
||||||
else
|
// Compare and return the contrasting color...
|
||||||
return FL_WHITE;
|
if ((l1 - l2) > 127) return fg;
|
||||||
|
else if ((l2 - l1) > 127) return fg;
|
||||||
|
else if (l2 > 127) return FL_BLACK;
|
||||||
|
else return FL_WHITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user