diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2022-12-28 17:50:00 +0100 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2022-12-28 18:16:23 +0100 |
| commit | 78cf29ba29aede2f0463e1747dc728787428d543 (patch) | |
| tree | 8970367f542bd08e595072c1b9c2ce3cd49624d3 /src/fl_color.cxx | |
| parent | 31327cd649b8ad5a6271057d823abe59a5362c60 (diff) | |
Improve and extend fl_contrast() (#370)
- Add internal fl_contrast_cielab() as the new default.
- Keep old function as internal fl_contrast_legacy().
- Add fl_contrast_mode() to switch between fl_contrast() functions.
- Add fl_contrast_level() to fine tune fl_contrast() per mode.
- Add option to register and use a custom contrast function.
- Add test/contrast.cxx test program.
- Move all fl_contrast() related code to a new file src/fl_contrast.cxx.
- Add fl_lightness() convenience function for perceived lightness.
- Add fl_luminance() convenience function for physical luminance.
Diffstat (limited to 'src/fl_color.cxx')
| -rw-r--r-- | src/fl_color.cxx | 30 |
1 files changed, 0 insertions, 30 deletions
diff --git a/src/fl_color.cxx b/src/fl_color.cxx index d925a73ee..dd1f07066 100644 --- a/src/fl_color.cxx +++ b/src/fl_color.cxx @@ -169,35 +169,5 @@ Fl_Color fl_inactive(Fl_Color c) { } /** - Returns a color that contrasts with the background color. - - This will be the foreground color if it contrasts sufficiently with the - background color. Otherwise, returns \p FL_WHITE or \p FL_BLACK depending - on which color provides the best contrast. - \param[in] fg,bg foreground and background colors - \return contrasting color - */ -Fl_Color fl_contrast(Fl_Color fg, Fl_Color bg) { - unsigned c1, c2; // RGB colors - int l1, l2; // Luminosities - - // Get the RGB values for each color... - if (fg & 0xffffff00) c1 = (unsigned)fg; - else c1 = fl_cmap[fg]; - - if (bg & 0xffffff00) c2 = (unsigned)bg; - else c2 = fl_cmap[bg]; - - // Compute the luminosity... - l1 = ((c1 >> 24) * 30 + ((c1 >> 16) & 255) * 59 + ((c1 >> 8) & 255) * 11) / 100; - l2 = ((c2 >> 24) * 30 + ((c2 >> 16) & 255) * 59 + ((c2 >> 8) & 255) * 11) / 100; - - // Compare and return the contrasting color... - if ((l1 - l2) > 99) return fg; - else if ((l2 - l1) > 99) return fg; - else if (l2 > 127) return FL_BLACK; - else return FL_WHITE; -} -/** \} */ |
