7#include "kcolorspaces_p.h"
8#include "kguiaddons_colorhelpers_p.h"
14using namespace KColorSpaces;
16static inline qreal wrap(qreal a, qreal d = 1.0)
19 return (r < 0.0 ? d + r : (r > 0.0 ? r : 0.0));
27static const qreal yc[3] = {0.299, 0.587, 0.114};
29static const qreal yc[3] = {0.2126, 0.7152, 0.0722};
31static const qreal yc[3] = {0.34375, 0.5, 0.15625};
34qreal KHCY::gamma(qreal n)
39qreal KHCY::igamma(qreal n)
44qreal KHCY::lumag(qreal r, qreal g, qreal b)
46 return r * yc[0] + g * yc[1] + b * yc[2];
49KHCY::KHCY(qreal h_, qreal c_, qreal y_, qreal a_)
57KHCY::KHCY(
const QColor &color)
59 qreal r = gamma(color.
redF());
60 qreal g = gamma(color.
greenF());
61 qreal b = gamma(color.
blueF());
68 qreal p = qMax(qMax(r, g), b);
69 qreal n = qMin(qMin(r, g), b);
70 qreal d = 6.0 * (p - n);
76 h = ((b - r) / d) + (1.0 / 3.0);
78 h = ((r - g) / d) + (2.0 / 3.0);
82 if (r == g && g == b) {
85 c = qMax((y - n) / y, (p - y) / (1 - y));
102 tm = yc[0] + yc[1] * th;
103 }
else if (_hs < 2.0) {
105 tm = yc[1] + yc[0] * th;
106 }
else if (_hs < 3.0) {
108 tm = yc[1] + yc[2] * th;
109 }
else if (_hs < 4.0) {
111 tm = yc[2] + yc[1] * th;
112 }
else if (_hs < 5.0) {
114 tm = yc[2] + yc[0] * th;
117 tm = yc[0] + yc[2] * th;
125 tp = _y + _y * _c * (1.0 - tm) / tm;
126 to = _y + _y * _c * (th - tm) / tm;
129 tp = _y + (1.0 - _y) * _c;
130 to = _y + (1.0 - _y) * _c * (th - tm) / (1.0 - tm);
131 tn = _y - (1.0 - _y) * _c * tm / (1.0 - tm);
137 }
else if (_hs < 2.0) {
139 }
else if (_hs < 3.0) {
141 }
else if (_hs < 4.0) {
143 }
else if (_hs < 5.0) {
150qreal KHCY::hue(
const QColor &color)
152 return wrap(KHCY(color).h);
155qreal KHCY::chroma(
const QColor &color)
157 return KHCY(color).c;
160qreal KHCY::luma(
const QColor &color)
162 return lumag(gamma(color.
redF()), gamma(color.
greenF()), gamma(color.
blueF()));
QString normalize(QStringView str)
float alphaF() const const
float blueF() const const
QColor fromRgbF(float r, float g, float b, float a)
float greenF() const const