hrev54800 adds 1 changeset to branch 'master'
old head: 43586267083394bcf34ac1edc092658781e102e8
new head: 8a72ba1b54a6d15703a1f15a1fccbe736fe05b41
overview:
https://git.haiku-os.org/haiku/log/?qt=range&q=8a72ba1b54a6+%5E435862670833
----------------------------------------------------------------------------
8a72ba1b54a6: Tracker: improve algorithm to decide desktop text color
Fixes #16673
[ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]
----------------------------------------------------------------------------
Revision: hrev54800
Commit: 8a72ba1b54a6d15703a1f15a1fccbe736fe05b41
URL: https://git.haiku-os.org/haiku/commit/?id=8a72ba1b54a6
Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date: Sat Dec 19 09:15:45 2020 UTC
Ticket: https://dev.haiku-os.org/ticket/16673
----------------------------------------------------------------------------
2 files changed, 37 insertions(+), 17 deletions(-)
headers/private/interface/ColorConversion.h | 17 ++++++++++++
src/kits/tracker/PoseView.cpp | 37 +++++++++++++------------
----------------------------------------------------------------------------
diff --git a/headers/private/interface/ColorConversion.h
b/headers/private/interface/ColorConversion.h
index e64255fc33..3f5da158ca 100644
--- a/headers/private/interface/ColorConversion.h
+++ b/headers/private/interface/ColorConversion.h
@@ -4,6 +4,9 @@
#include <GraphicsDefs.h>
+#include <math.h>
+
+
class BPoint;
@@ -61,6 +64,20 @@ private:
status_t fCStatus;
};
+
+static inline uint8 perceptual_brightness(rgb_color color)
+{
+ // From http://alienryderflex.com/hsp.html
+ // Useful in particular to decide if the color is "light" or "dark"
+ // by checking if the perceptual brightness is > 127.
+ int r = color.red;
+ int g = color.green;
+ int b = color.blue;
+
+ return (uint8)roundf(sqrtf(
+ 0.299f * r * r + 0.587f * g * g + 0.114 * b * b));
+}
+
} // namespace BPrivate
#endif
diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp
index 72daadd12b..12b9c78012 100644
--- a/src/kits/tracker/PoseView.cpp
+++ b/src/kits/tracker/PoseView.cpp
@@ -51,6 +51,7 @@ All rights reserved.
#include <Application.h>
#include <Catalog.h>
#include <Clipboard.h>
+#include <ColorConversion.h>
#include <Debug.h>
#include <Dragger.h>
#include <fs_attr.h>
@@ -9035,31 +9036,33 @@ BPoseView::DrawPose(BPose* pose, int32 index, bool
fullDraw)
rgb_color
BPoseView::DeskTextColor() const
{
+ // The desktop color is chosen independently for the desktop.
+ // The text color is chosen globally for all directories.
+ // It's fairly easy to get something unreadable (even with the default
+ // settings, it's expected that text will be black on white in Tracker
+ // folders, but white on blue on the desktop).
+ // So here we check if the colors are different enough, and otherwise,
+ // force the text to be either white or black.
rgb_color textColor = ui_color(B_DOCUMENT_TEXT_COLOR);
rgb_color viewColor = ViewColor();
- float readabilityThreshold = abs(textColor.red - viewColor.red)
- + abs(textColor.green - viewColor.green)
- + abs(textColor.blue - viewColor.blue);
- if (readabilityThreshold > 384) {
- // The readability threshold is highly subjective, but 384 (out
of 768)
- // seems to be generally suitable for most circumstances.
+ int textBrightness = BPrivate::perceptual_brightness(textColor);
+ int viewBrightness = BPrivate::perceptual_brightness(viewColor);
+ if (abs(viewBrightness - textBrightness) > 127) {
+ // The colors are different enough, we can use them as is
return textColor;
} else {
- float blackWhiteThreshold = viewColor.red
- + (viewColor.green * 1.25f) + (viewColor.blue * 0.45f);
-
- if (blackWhiteThreshold >= 360) {
- viewColor.red = 0;
- viewColor.green = 0;
- viewColor.blue = 0;
+ if (viewBrightness > 127) {
+ textColor.red = 0;
+ textColor.green = 0;
+ textColor.blue = 0;
} else {
- viewColor.red = 255;
- viewColor.green = 255;
- viewColor.blue = 255;
+ textColor.red = 255;
+ textColor.green = 255;
+ textColor.blue = 255;
}
- return viewColor;
+ return textColor;
}
}