Files
flameshot/src/utils/colorutils.cpp
Boyuan Yang a9c7cc7b04 Use SPDX-License-Identifier
closes: #1374 .

Use SPDX short-form identifiers instead of lengthy copyright
header to document per-file license and copyright.

This commit updates all files under src/ directory where applicable
as well as org.flameshot.Flameshot.metainfo.xml.
2021-02-20 19:22:53 -05:00

25 lines
660 B
C++

// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
#include "colorutils.h"
inline qreal getColorLuma(const QColor& c)
{
return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF();
}
bool ColorUtils::colorIsDark(const QColor& c)
{
// when luma <= 0.5, we considor it as a dark color
return getColorLuma(c) <= 0.5;
}
QColor ColorUtils::contrastColor(const QColor& c)
{
int change = colorIsDark(c) ? 30 : -45;
return QColor(qBound(0, c.red() + change, 255),
qBound(0, c.green() + change, 255),
qBound(0, c.blue() + change, 255));
}