From ac038474ceeee9b3fef9fe777c2d34def563d19e Mon Sep 17 00:00:00 2001 From: hexyoungs Date: Fri, 25 Sep 2020 10:40:53 +0800 Subject: [PATCH] feat: using luminance to determine text color of circlecounttool --- src/tools/circlecount/circlecounttool.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tools/circlecount/circlecounttool.cpp b/src/tools/circlecount/circlecounttool.cpp index 3b9ca65c..9a53a994 100644 --- a/src/tools/circlecount/circlecounttool.cpp +++ b/src/tools/circlecount/circlecounttool.cpp @@ -89,8 +89,11 @@ void CircleCountTool::process(QPainter& painter, textRect, Qt::AlignCenter, QString::number(m_count)); } - // Lightness value ranges from 0-255, we split at 75 as this looks best - if (m_color.lightness() <= 75) { + // Calculate the perceptive luminance - human eye favors green color + double luma = ((0.299 * m_color.red()) + (0.587 * m_color.green()) + + (0.114 * m_color.blue())) / + 255; + if (luma <= 0.5) { painter.setPen(Qt::white); } else { painter.setPen(Qt::black);