7#include "helperqttypes.h"
20static_assert(std::is_standard_layout_v<RgbColor>);
22static_assert(std::is_default_constructible_v<RgbColor>);
26static_assert(std::is_copy_constructible_v<RgbColor>);
47void RgbColor::fillAll(
QColor color, std::optional<double> hue)
49 rgb255 = GenericColor(
static_cast<double>(color.
redF() * 255),
50 static_cast<double>(color.
greenF() * 255),
51 static_cast<double>(color.
blueF() * 255));
53 rgbQColor = color.
toRgb();
56 const double hueDegree =
hue.value_or(
57 qBound(0., rgbQColor.
hueF() * 360, 360.));
60 const double hslSaturationPercentage =
61 qBound(0.,
static_cast<double>(color.
hslSaturationF()) * 100, 100.);
62 const double hslLightnessPercentage =
63 qBound(0.,
static_cast<double>(color.
lightnessF()) * 100, 100.);
64 hsl = GenericColor(hueDegree,
65 hslSaturationPercentage,
66 hslLightnessPercentage);
69 const double hsvSaturationPercentage =
70 qBound(0.0,
static_cast<double>(color.
hsvSaturationF()) * 100, 100.0);
71 const double hsvValuePercentage =
72 qBound<double>(0.0,
static_cast<double>(color.
valueF()) * 100, 100.0);
73 hsv = GenericColor(hueDegree,
74 hsvSaturationPercentage,
77 const double hwbWhitenessPercentage =
79 const double hwbBlacknessPercentage =
80 qBound(0.0, (1 - color.
valueF()) * 100, 100.0);
81 hwb = GenericColor(hueDegree,
82 hwbWhitenessPercentage,
83 hwbBlacknessPercentage);
93RgbColor RgbColor::fromRgb255(
const GenericColor &color, std::optional<double> hue)
96 const auto red =
static_cast<QColorFloatType
>(color.first / 255.0);
97 const auto green =
static_cast<QColorFloatType
>(color.second / 255.0);
98 const auto blue =
static_cast<QColorFloatType
>(color.third / 255.0);
99 constexpr auto zero =
static_cast<QColorFloatType
>(0);
100 constexpr auto one =
static_cast<QColorFloatType
>(1);
102 qBound(zero, green, one),
103 qBound(zero, blue, one));
104 result.fillAll(newRgbQColor, hue);
105 result.rgb255 = color;
115RgbColor RgbColor::fromRgbQColor(
const QColor &color)
118 result.fillAll(color, std::optional<double>());
128RgbColor RgbColor::fromHsl(
const GenericColor &color)
132 constexpr auto zero =
static_cast<QColorFloatType
>(0);
133 constexpr auto one =
static_cast<QColorFloatType
>(1);
135 qBound(zero,
static_cast<QColorFloatType
>(color.first / 360.0), one);
136 const auto hslSaturation =
137 qBound(zero,
static_cast<QColorFloatType
>(color.second / 100.0), one);
138 const auto hslLightness =
139 qBound(zero,
static_cast<QColorFloatType
>(color.third / 100.0), one);
140 const QColor newRgbQColor =
142 result.fillAll(newRgbQColor, color.first);
145 if (result.hsl.third == 0) {
149 result.hsv.second = result.hsl.second;
160RgbColor RgbColor::fromHsv(
const GenericColor &color)
163 constexpr auto zero =
static_cast<QColorFloatType
>(0);
164 constexpr auto one =
static_cast<QColorFloatType
>(1);
166 qBound(zero,
static_cast<QColorFloatType
>(color.first / 360.0), one);
167 const auto hsvSaturation =
168 qBound(zero,
static_cast<QColorFloatType
>(color.second / 100.0), one);
169 const auto hsvValue =
170 qBound(zero,
static_cast<QColorFloatType
>(color.third / 100.0), one);
171 const QColor newRgbQColor =
173 result.fillAll(newRgbQColor, color.first);
176 if (result.hsv.third == 0) {
180 result.hsl.second = result.hsv.second;
191RgbColor RgbColor::fromHwb(
const GenericColor &color)
194 GenericColor normalizedHwb = color;
195 const auto whitenessBlacknessSum =
196 normalizedHwb.second + normalizedHwb.third;
197 if (whitenessBlacknessSum > 100) {
198 normalizedHwb.second *= 100 / whitenessBlacknessSum;
199 normalizedHwb.third *= 100 / whitenessBlacknessSum;
202 const double quotient = (100 - normalizedHwb.third);
203 const auto newHsvSaturation =
209 : qBound<double>(0, 100 - normalizedHwb.second / quotient * 100, 100);
210 const auto newHsvValue = qBound<double>(0, 100 - normalizedHwb.third, 100);
211 const GenericColor newHsv = GenericColor(normalizedHwb.first,
214 const QColor newRgbQColor =
216 static_cast<QColorFloatType
>(newHsv.first / 360),
217 static_cast<QColorFloatType
>(newHsv.second / 100),
218 static_cast<QColorFloatType
>(newHsv.third / 100));
219 result.fillAll(newRgbQColor, normalizedHwb.first);
233bool RgbColor::operator==(
const RgbColor &other)
const
236 return (hsl == other.hsl)
237 && (hsv == other.hsv)
238 && (hwb == other.hwb)
239 && (rgb255 == other.rgb255)
240 && (rgbQColor == other.rgbQColor);
255 <<
" - hsl: " << value.hsl <<
"\n"
256 <<
" - hsv: " << value.hsv <<
"\n"
257 <<
" - hwb: " << value.hwb <<
"\n"
258 <<
" - rgb: " << value.rgb255 <<
"\n"
259 <<
" - rgbQColor: " << value.rgbQColor <<
"\n"
264static_assert(std::is_standard_layout_v<RgbColor>);
KGUIADDONS_EXPORT qreal hue(const QColor &)
QDebug operator<<(QDebug dbg, const DcrawInfoContainer &c)
The namespace of this library.
float blueF() const const
QColor fromHslF(float h, float s, float l, float a)
QColor fromHsvF(float h, float s, float v, float a)
QColor fromRgbF(float r, float g, float b, float a)
float greenF() const const
float hslSaturationF() const const
float hsvSaturationF() const const
float lightnessF() const const
QColor toRgb() const const
float valueF() const const