12#include "private/qtools_p.h"
24#if QT_VERSION >= QT_VERSION_CHECK(7,0,0) || QT_POINTER_SIZE > 4
60 }
else if (
len == 9) {
64 if (
r == -1 ||
g == -1 ||
b == -1)
66 r = (
r << 4) | (
r >> 8);
67 g = (
g << 4) | (
g >> 8);
68 b = (
b << 4) | (
b >> 8);
69 }
else if (
len == 8) {
74 }
else if (
len == 6) {
78 }
else if (
len == 3) {
93 return rgba64->toArgb32();
102 for (
size_t i = 0;
i <
len; ++
i)
103 tmp[
i] =
str[
i].toLatin1();
115#ifndef QT_NO_COLORNAMES
124#define rgb(r,g,b) (0xff000000 | (r << 16) | (g << 8) | b)
131 {
"aliceblue",
rgb(240, 248, 255) },
132 {
"antiquewhite",
rgb(250, 235, 215) },
133 {
"aqua",
rgb( 0, 255, 255) },
134 {
"aquamarine",
rgb(127, 255, 212) },
135 {
"azure",
rgb(240, 255, 255) },
136 {
"beige",
rgb(245, 245, 220) },
137 {
"bisque",
rgb(255, 228, 196) },
138 {
"black",
rgb( 0, 0, 0) },
139 {
"blanchedalmond",
rgb(255, 235, 205) },
140 {
"blue",
rgb( 0, 0, 255) },
141 {
"blueviolet",
rgb(138, 43, 226) },
142 {
"brown",
rgb(165, 42, 42) },
143 {
"burlywood",
rgb(222, 184, 135) },
144 {
"cadetblue",
rgb( 95, 158, 160) },
145 {
"chartreuse",
rgb(127, 255, 0) },
146 {
"chocolate",
rgb(210, 105, 30) },
147 {
"coral",
rgb(255, 127, 80) },
148 {
"cornflowerblue",
rgb(100, 149, 237) },
149 {
"cornsilk",
rgb(255, 248, 220) },
150 {
"crimson",
rgb(220, 20, 60) },
151 {
"cyan",
rgb( 0, 255, 255) },
152 {
"darkblue",
rgb( 0, 0, 139) },
153 {
"darkcyan",
rgb( 0, 139, 139) },
154 {
"darkgoldenrod",
rgb(184, 134, 11) },
155 {
"darkgray",
rgb(169, 169, 169) },
156 {
"darkgreen",
rgb( 0, 100, 0) },
157 {
"darkgrey",
rgb(169, 169, 169) },
158 {
"darkkhaki",
rgb(189, 183, 107) },
159 {
"darkmagenta",
rgb(139, 0, 139) },
160 {
"darkolivegreen",
rgb( 85, 107, 47) },
161 {
"darkorange",
rgb(255, 140, 0) },
162 {
"darkorchid",
rgb(153, 50, 204) },
163 {
"darkred",
rgb(139, 0, 0) },
164 {
"darksalmon",
rgb(233, 150, 122) },
165 {
"darkseagreen",
rgb(143, 188, 143) },
166 {
"darkslateblue",
rgb( 72, 61, 139) },
167 {
"darkslategray",
rgb( 47, 79, 79) },
168 {
"darkslategrey",
rgb( 47, 79, 79) },
169 {
"darkturquoise",
rgb( 0, 206, 209) },
170 {
"darkviolet",
rgb(148, 0, 211) },
171 {
"deeppink",
rgb(255, 20, 147) },
172 {
"deepskyblue",
rgb( 0, 191, 255) },
173 {
"dimgray",
rgb(105, 105, 105) },
174 {
"dimgrey",
rgb(105, 105, 105) },
175 {
"dodgerblue",
rgb( 30, 144, 255) },
176 {
"firebrick",
rgb(178, 34, 34) },
177 {
"floralwhite",
rgb(255, 250, 240) },
178 {
"forestgreen",
rgb( 34, 139, 34) },
179 {
"fuchsia",
rgb(255, 0, 255) },
180 {
"gainsboro",
rgb(220, 220, 220) },
181 {
"ghostwhite",
rgb(248, 248, 255) },
182 {
"gold",
rgb(255, 215, 0) },
183 {
"goldenrod",
rgb(218, 165, 32) },
184 {
"gray",
rgb(128, 128, 128) },
185 {
"green",
rgb( 0, 128, 0) },
186 {
"greenyellow",
rgb(173, 255, 47) },
187 {
"grey",
rgb(128, 128, 128) },
188 {
"honeydew",
rgb(240, 255, 240) },
189 {
"hotpink",
rgb(255, 105, 180) },
190 {
"indianred",
rgb(205, 92, 92) },
191 {
"indigo",
rgb( 75, 0, 130) },
192 {
"ivory",
rgb(255, 255, 240) },
193 {
"khaki",
rgb(240, 230, 140) },
194 {
"lavender",
rgb(230, 230, 250) },
195 {
"lavenderblush",
rgb(255, 240, 245) },
196 {
"lawngreen",
rgb(124, 252, 0) },
197 {
"lemonchiffon",
rgb(255, 250, 205) },
198 {
"lightblue",
rgb(173, 216, 230) },
199 {
"lightcoral",
rgb(240, 128, 128) },
200 {
"lightcyan",
rgb(224, 255, 255) },
201 {
"lightgoldenrodyellow",
rgb(250, 250, 210) },
202 {
"lightgray",
rgb(211, 211, 211) },
203 {
"lightgreen",
rgb(144, 238, 144) },
204 {
"lightgrey",
rgb(211, 211, 211) },
205 {
"lightpink",
rgb(255, 182, 193) },
206 {
"lightsalmon",
rgb(255, 160, 122) },
207 {
"lightseagreen",
rgb( 32, 178, 170) },
208 {
"lightskyblue",
rgb(135, 206, 250) },
209 {
"lightslategray",
rgb(119, 136, 153) },
210 {
"lightslategrey",
rgb(119, 136, 153) },
211 {
"lightsteelblue",
rgb(176, 196, 222) },
212 {
"lightyellow",
rgb(255, 255, 224) },
213 {
"lime",
rgb( 0, 255, 0) },
214 {
"limegreen",
rgb( 50, 205, 50) },
215 {
"linen",
rgb(250, 240, 230) },
216 {
"magenta",
rgb(255, 0, 255) },
217 {
"maroon",
rgb(128, 0, 0) },
218 {
"mediumaquamarine",
rgb(102, 205, 170) },
219 {
"mediumblue",
rgb( 0, 0, 205) },
220 {
"mediumorchid",
rgb(186, 85, 211) },
221 {
"mediumpurple",
rgb(147, 112, 219) },
222 {
"mediumseagreen",
rgb( 60, 179, 113) },
223 {
"mediumslateblue",
rgb(123, 104, 238) },
224 {
"mediumspringgreen",
rgb( 0, 250, 154) },
225 {
"mediumturquoise",
rgb( 72, 209, 204) },
226 {
"mediumvioletred",
rgb(199, 21, 133) },
227 {
"midnightblue",
rgb( 25, 25, 112) },
228 {
"mintcream",
rgb(245, 255, 250) },
229 {
"mistyrose",
rgb(255, 228, 225) },
230 {
"moccasin",
rgb(255, 228, 181) },
231 {
"navajowhite",
rgb(255, 222, 173) },
232 {
"navy",
rgb( 0, 0, 128) },
233 {
"oldlace",
rgb(253, 245, 230) },
234 {
"olive",
rgb(128, 128, 0) },
235 {
"olivedrab",
rgb(107, 142, 35) },
236 {
"orange",
rgb(255, 165, 0) },
237 {
"orangered",
rgb(255, 69, 0) },
238 {
"orchid",
rgb(218, 112, 214) },
239 {
"palegoldenrod",
rgb(238, 232, 170) },
240 {
"palegreen",
rgb(152, 251, 152) },
241 {
"paleturquoise",
rgb(175, 238, 238) },
242 {
"palevioletred",
rgb(219, 112, 147) },
243 {
"papayawhip",
rgb(255, 239, 213) },
244 {
"peachpuff",
rgb(255, 218, 185) },
245 {
"peru",
rgb(205, 133, 63) },
246 {
"pink",
rgb(255, 192, 203) },
247 {
"plum",
rgb(221, 160, 221) },
248 {
"powderblue",
rgb(176, 224, 230) },
249 {
"purple",
rgb(128, 0, 128) },
250 {
"red",
rgb(255, 0, 0) },
251 {
"rosybrown",
rgb(188, 143, 143) },
252 {
"royalblue",
rgb( 65, 105, 225) },
253 {
"saddlebrown",
rgb(139, 69, 19) },
254 {
"salmon",
rgb(250, 128, 114) },
255 {
"sandybrown",
rgb(244, 164, 96) },
256 {
"seagreen",
rgb( 46, 139, 87) },
257 {
"seashell",
rgb(255, 245, 238) },
258 {
"sienna",
rgb(160, 82, 45) },
259 {
"silver",
rgb(192, 192, 192) },
260 {
"skyblue",
rgb(135, 206, 235) },
261 {
"slateblue",
rgb(106, 90, 205) },
262 {
"slategray",
rgb(112, 128, 144) },
263 {
"slategrey",
rgb(112, 128, 144) },
264 {
"snow",
rgb(255, 250, 250) },
265 {
"springgreen",
rgb( 0, 255, 127) },
266 {
"steelblue",
rgb( 70, 130, 180) },
267 {
"tan",
rgb(210, 180, 140) },
268 {
"teal",
rgb( 0, 128, 128) },
269 {
"thistle",
rgb(216, 191, 216) },
270 {
"tomato",
rgb(255, 99, 71) },
271 {
"transparent", 0 },
272 {
"turquoise",
rgb( 64, 224, 208) },
273 {
"violet",
rgb(238, 130, 238) },
274 {
"wheat",
rgb(245, 222, 179) },
275 {
"white",
rgb(255, 255, 255) },
276 {
"whitesmoke",
rgb(245, 245, 245) },
277 {
"yellow",
rgb(255, 255, 0) },
278 {
"yellowgreen",
rgb(154, 205, 50) }
285 for (
auto it =
e.name; *
it ; ++
it) {
291 }(),
"the lookup code expects color names to be US-ASCII-only");
310static char to_char(
char ch)
noexcept {
return ch; }
311static char to_char(
QChar ch)
noexcept {
return ch.toLatin1(); }
316 if (
name.size() > 255)
318 char name_no_space[256];
321 for (
auto c :
name) {
322 if (
c != u
'\t' &&
c != u
' ')
326 name_no_space[
pos] = 0;
336#ifndef QT_NO_COLORNAMES
581#define QCOLOR_INT_RANGE_CHECK(fn, var) \
583 if (var < 0 || var > 255) { \
584 qWarning(#fn": invalid value %d", var); \
585 var = qMax(0, qMin(var, 255)); \
589#define QCOLOR_REAL_RANGE_CHECK(fn, var) \
591 if (var < 0.0f || var > 1.0f) { \
592 qWarning(#fn": invalid value %g", var); \
593 var = qMax(0.0f, qMin(var, 1.0f)); \
657#define QRGB(r, g, b) \
658 QRgb(((0xffu << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)))
659#define QRGBA(r, g, b, a) \
660 QRgb(((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff))
662 static const QRgb global_colors[] = {
733 ct.argb.alpha = 0xffff;
846#if QT_DEPRECATED_SINCE(6, 6)
925 return isValidColorName(
name);
935 return isValidColorName(
name);
985 if (
name.front() == u
'#') {
988#ifndef QT_NO_COLORNAMES
1027 *
h = ct.ahsv.hue == USHRT_MAX ? -1.0f : ct.ahsv.hue / 36000.0f;
1028 *
s = ct.ahsv.saturation / float(USHRT_MAX);
1029 *
v = ct.ahsv.value / float(USHRT_MAX);
1032 *
a = ct.ahsv.alpha / float(USHRT_MAX);
1055 *
h = ct.ahsv.hue == USHRT_MAX ? -1 : ct.ahsv.hue / 100;
1073 if (((h < 0.0f || h > 1.0f) &&
h != -1.0f)
1074 || (s < 0.0f || s > 1.0f)
1075 || (v < 0.0f || v > 1.0f)
1076 || (a < 0.0f || a > 1.0f)) {
1077 qWarning(
"QColor::setHsvF: HSV parameters out of range");
1083 ct.ahsv.alpha =
qRound(
a * USHRT_MAX);
1084 ct.ahsv.hue =
h == -1.0f ? USHRT_MAX :
qRound(
h * 36000.0f);
1085 ct.ahsv.saturation =
qRound(
s * USHRT_MAX);
1086 ct.ahsv.value =
qRound(
v * USHRT_MAX);
1102 qWarning(
"QColor::setHsv: HSV parameters out of range");
1108 ct.ahsv.alpha =
a * 0x101;
1109 ct.ahsv.hue =
h == -1 ? USHRT_MAX : (
h % 360) * 100;
1110 ct.ahsv.saturation =
s * 0x101;
1111 ct.ahsv.value =
v * 0x101;
1137 *
h = ct.ahsl.hue == USHRT_MAX ? -1.0f : ct.ahsl.hue / 36000.0f;
1138 *
s = ct.ahsl.saturation / float(USHRT_MAX);
1139 *l = ct.ahsl.lightness / float(USHRT_MAX);
1142 *
a = ct.ahsl.alpha / float(USHRT_MAX);
1167 *
h = ct.ahsl.hue == USHRT_MAX ? -1 : ct.ahsl.hue / 100;
1187 if (((h < 0.0f || h > 1.0f) &&
h != -1.0f)
1188 || (s < 0.0f || s > 1.0f)
1189 || (l < 0.0f || l > 1.0f)
1190 || (a < 0.0f || a > 1.0f)) {
1191 qWarning(
"QColor::setHslF: HSL parameters out of range");
1197 ct.ahsl.alpha =
qRound(
a * USHRT_MAX);
1198 ct.ahsl.hue =
h == -1.0f ? USHRT_MAX :
qRound(
h * 36000.0f);
1199 ct.ahsl.saturation =
qRound(
s * USHRT_MAX);
1200 ct.ahsl.lightness =
qRound(l * USHRT_MAX);
1218 qWarning(
"QColor::setHsl: HSL parameters out of range");
1224 ct.ahsl.alpha =
a * 0x101;
1225 ct.ahsl.hue =
h == -1 ? USHRT_MAX : (
h % 360) * 100;
1226 ct.ahsl.saturation =
s * 0x101;
1227 ct.ahsl.lightness = l * 0x101;
1234 return *
reinterpret_cast<qfloat16 *
>(&
v);
1239 return *
reinterpret_cast<const qfloat16 *
>(&
v);
1263 *
r = ct.argb.red / float(USHRT_MAX);
1264 *
g = ct.argb.green / float(USHRT_MAX);
1265 *
b = ct.argb.blue / float(USHRT_MAX);
1267 *
a = ct.argb.alpha / float(USHRT_MAX);
1269 *
r =
castF16(ct.argbExtended.redF16);
1270 *
g =
castF16(ct.argbExtended.greenF16);
1271 *
b =
castF16(ct.argbExtended.blueF16);
1273 *
a =
castF16(ct.argbExtended.alphaF16);
1319 if (a < 0.0f || a > 1.0f) {
1320 qWarning(
"QColor::setRgbF: Alpha parameter is out of range");
1324 if (r < 0.0f || r > 1.0f ||
1325 g < 0.0f || g > 1.0f ||
1332 ct.argbExtended.pad = 0;
1336 ct.argb.red =
qRound(
r * USHRT_MAX);
1337 ct.argb.green =
qRound(
g * USHRT_MAX);
1338 ct.argb.blue =
qRound(
b * USHRT_MAX);
1339 ct.argb.alpha =
qRound(
a * USHRT_MAX);
1352 if (!isRgbaValid(
r,
g,
b,
a)) {
1353 qWarning(
"QColor::setRgb: RGB parameters out of range");
1359 ct.argb.alpha =
a * 0x101;
1360 ct.argb.red =
r * 0x101;
1361 ct.argb.green =
g * 0x101;
1362 ct.argb.blue =
b * 0x101;
1391 ct.argb.alpha =
qAlpha(rgba) * 0x101;
1392 ct.argb.red =
qRed(rgba) * 0x101;
1393 ct.argb.green =
qGreen(rgba) * 0x101;
1394 ct.argb.blue =
qBlue(rgba) * 0x101;
1412 return qRgba64(ct.argb.red, ct.argb.green, ct.argb.blue, ct.argb.alpha);
1425 ct.argb.alpha = rgba.alpha();
1426 ct.argb.red = rgba.red();
1427 ct.argb.green = rgba.green();
1428 ct.argb.blue = rgba.blue();
1454 ct.argb.alpha = 0xffff;
1455 ct.argb.red =
qRed(
rgb) * 0x101;
1469 return qRound(
float(
castF16(ct.argbExtended.alphaF16)) * 255);
1485 constexpr float f = 1.0f / 255;
1489 ct.argb.alpha =
alpha * 0x101;
1500 return castF16(ct.argbExtended.alphaF16);
1501 return ct.argb.alpha / float(USHRT_MAX);
1518 float tmp =
alpha * USHRT_MAX;
1519 ct.argb.alpha =
qRound(tmp);
1547 ct.argb.red =
red * 0x101;
1574 ct.argb.green =
green * 0x101;
1603 ct.argb.blue =
blue * 0x101;
1614 return ct.argb.red / float(USHRT_MAX);
1616 return castF16(ct.argbExtended.redF16);
1630 if (cspec ==
Rgb &&
red >= 0.0f &&
red <= 1.0f)
1646 return ct.argb.green / float(USHRT_MAX);
1648 return castF16(ct.argbExtended.greenF16);
1678 return ct.argb.blue / float(USHRT_MAX);
1680 return castF16(ct.argbExtended.blueF16);
1722 return ct.ahsv.hue == USHRT_MAX ? -1 : ct.ahsv.hue / 100;
1785 return ct.ahsv.hue == USHRT_MAX ? -1.0f : ct.ahsv.hue / 36000.0f;
1810 return ct.ahsv.saturation / float(USHRT_MAX);
1822 return ct.ahsv.value / float(USHRT_MAX);
1836 return ct.ahsl.hue == USHRT_MAX ? -1 : ct.ahsl.hue / 100;
1878 return ct.ahsl.hue == USHRT_MAX ? -1.0f : ct.ahsl.hue / 36000.0f;
1892 return ct.ahsl.saturation / float(USHRT_MAX);
1906 return ct.ahsl.lightness / float(USHRT_MAX);
1967 return ct.acmyk.cyan / float(USHRT_MAX);
1979 return ct.acmyk.magenta / float(USHRT_MAX);
1991 return ct.acmyk.yellow / float(USHRT_MAX);
2003 return ct.acmyk.black / float(USHRT_MAX);
2019 constexpr float f = 1.0f / USHRT_MAX;
2026 color.ct.argbExtended.pad = 0;
2043 color.ct.argb.alpha = ct.argb.alpha;
2044 color.ct.argb.pad = 0;
2049 if (ct.ahsv.saturation == 0 || ct.ahsv.hue == USHRT_MAX) {
2051 color.ct.argb.red =
color.ct.argb.green =
color.ct.argb.blue = ct.ahsv.value;
2056 const float h = ct.ahsv.hue == 36000 ? 0.0f : ct.ahsv.hue / 6000.0f;
2057 const float s = ct.ahsv.saturation / float(USHRT_MAX);
2058 const float v = ct.ahsv.value / float(USHRT_MAX);
2059 const int i = int(
h);
2060 const float f =
h -
i;
2061 const float p =
v * (1.0f -
s);
2064 const float q =
v * (1.0f - (
s *
f));
2084 const float t =
v * (1.0f - (
s * (1.0f -
f)));
2108 if (ct.ahsl.saturation == 0 || ct.ahsl.hue == USHRT_MAX) {
2110 color.ct.argb.red =
color.ct.argb.green =
color.ct.argb.blue = ct.ahsl.lightness;
2111 }
else if (ct.ahsl.lightness == 0) {
2116 const float h = ct.ahsl.hue == 36000 ? 0.0f : ct.ahsl.hue / 36000.0f;
2117 const float s = ct.ahsl.saturation / float(USHRT_MAX);
2118 const float l = ct.ahsl.lightness / float(USHRT_MAX);
2122 temp2 = l * (1.0f +
s);
2124 temp2 = l +
s - (l *
s);
2126 const float temp1 = (2.0f * l) - temp2;
2127 float temp3[3] = {
h + (1.0f / 3.0f),
2129 h - (1.0f / 3.0f) };
2131 for (
int i = 0;
i != 3; ++
i) {
2132 if (temp3[
i] < 0.0f)
2134 else if (temp3[
i] > 1.0f)
2137 const float sixtemp3 = temp3[
i] * 6.0f;
2138 if (sixtemp3 < 1.0f)
2139 color.ct.array[
i+1] =
qRound((temp1 + (temp2 - temp1) * sixtemp3) * USHRT_MAX);
2140 else if ((temp3[
i] * 2.0f) < 1.0f)
2142 else if ((temp3[
i] * 3.0f) < 2.0f)
2143 color.ct.array[
i+1] =
qRound((temp1 + (temp2 -temp1) * (2.0f /3.0f - temp3[
i]) * 6.0f) * USHRT_MAX);
2148 color.ct.argb.green =
color.ct.argb.green == 1 ? 0 :
color.ct.argb.green;
2149 color.ct.argb.blue =
color.ct.argb.blue == 1 ? 0 :
color.ct.argb.blue;
2155 const float c = ct.acmyk.cyan / float(USHRT_MAX);
2156 const float m = ct.acmyk.magenta / float(USHRT_MAX);
2157 const float y = ct.acmyk.yellow / float(USHRT_MAX);
2158 const float k = ct.acmyk.black / float(USHRT_MAX);
2160 color.ct.argb.red =
qRound((1.0f - (
c * (1.0f - k) + k)) * USHRT_MAX);
2161 color.ct.argb.green =
qRound((1.0f - (
m * (1.0f - k) + k)) * USHRT_MAX);
2162 color.ct.argb.blue =
qRound((1.0f - (
y * (1.0f - k) + k)) * USHRT_MAX);
2179#define Q_MAX_3(a, b, c) ( ( a > b && a > c) ? a : (b > c ? b : c) )
2180#define Q_MIN_3(a, b, c) ( ( a < b && a < c) ? a : (b < c ? b : c) )
2198 color.ct.ahsv.alpha = ct.argb.alpha;
2199 color.ct.ahsv.pad = 0;
2201 const float r = ct.argb.red / float(USHRT_MAX);
2202 const float g = ct.argb.green / float(USHRT_MAX);
2203 const float b = ct.argb.blue / float(USHRT_MAX);
2206 const float delta = max - min;
2210 color.ct.ahsv.hue = USHRT_MAX;
2211 color.ct.ahsv.saturation = 0;
2215 color.ct.ahsv.saturation =
qRound((delta / max) * USHRT_MAX);
2217 hue = ((
g -
b) /delta);
2219 hue = (2.0f + (
b -
r) / delta);
2221 hue = (4.0f + (
r -
g) / delta);
2223 Q_ASSERT_X(
false,
"QColor::toHsv",
"internal error");
2249 color.ct.ahsl.alpha = ct.argb.alpha;
2250 color.ct.ahsl.pad = 0;
2252 const float r = ct.argb.red / float(USHRT_MAX);
2253 const float g = ct.argb.green / float(USHRT_MAX);
2254 const float b = ct.argb.blue / float(USHRT_MAX);
2257 const float delta = max - min;
2258 const float delta2 = max + min;
2263 color.ct.ahsl.hue = USHRT_MAX;
2264 color.ct.ahsl.saturation = 0;
2269 color.ct.ahsl.saturation =
qRound((delta / delta2) * USHRT_MAX);
2271 color.ct.ahsl.saturation =
qRound((delta / (2.0f - delta2)) * USHRT_MAX);
2273 hue = ((
g -
b) /delta);
2275 hue = (2.0f + (
b -
r) / delta);
2277 hue = (4.0f + (
r -
g) / delta);
2279 Q_ASSERT_X(
false,
"QColor::toHsv",
"internal error");
2304 color.ct.acmyk.alpha = ct.argb.alpha;
2306 if (!ct.argb.red && !ct.argb.green && !ct.argb.blue) {
2308 color.ct.acmyk.cyan = 0;
2309 color.ct.acmyk.magenta = 0;
2310 color.ct.acmyk.yellow = 0;
2311 color.ct.acmyk.black = USHRT_MAX;
2314 const float r = ct.argb.red / float(USHRT_MAX);
2315 const float g = ct.argb.green / float(USHRT_MAX);
2316 const float b = ct.argb.blue / float(USHRT_MAX);
2323 c = (
c - k) / (1.0f - k);
2324 m = (
m - k) / (1.0f - k);
2325 y = (
y - k) / (1.0f - k);
2338 if (colorSpec == cspec)
2340 switch (colorSpec) {
2344 return toExtendedRgb();
2401 if (!isRgbaValid(
r,
g,
b,
a)) {
2402 qWarning(
"QColor::fromRgb: RGB parameters out of range");
2408 color.ct.argb.alpha =
a * 0x101;
2409 color.ct.argb.red =
r * 0x101;
2410 color.ct.argb.green =
g * 0x101;
2411 color.ct.argb.blue =
b * 0x101;
2412 color.ct.argb.pad = 0;
2429 if (a < 0.0f || a > 1.0f) {
2430 qWarning(
"QColor::fromRgbF: Alpha parameter out of range");
2434 if (r < 0.0f || r > 1.0f
2435 || g < 0.0f || g > 1.0f
2436 || b < 0.0f || b > 1.0f) {
2443 color.ct.argbExtended.pad = 0;
2453 color.ct.argb.pad = 0;
2485 color.setRgba64(rgba64);
2501 if (((h < 0 || h >= 360) &&
h != -1)
2504 || a < 0 || a > 255) {
2505 qWarning(
"QColor::fromHsv: HSV parameters out of range");
2511 color.ct.ahsv.alpha =
a * 0x101;
2512 color.ct.ahsv.hue =
h == -1 ? USHRT_MAX : (
h % 360) * 100;
2513 color.ct.ahsv.saturation =
s * 0x101;
2514 color.ct.ahsv.value =
v * 0x101;
2515 color.ct.ahsv.pad = 0;
2532 if (((h < 0.0f || h > 1.0f) &&
h != -1.0f)
2533 || (s < 0.0f || s > 1.0f)
2534 || (v < 0.0f || v > 1.0f)
2535 || (a < 0.0f || a > 1.0f)) {
2536 qWarning(
"QColor::fromHsvF: HSV parameters out of range");
2543 color.ct.ahsv.hue =
h == -1.0f ? USHRT_MAX :
qRound(
h * 36000.0f);
2546 color.ct.ahsv.pad = 0;
2564 if (((h < 0 || h >= 360) &&
h != -1)
2567 || a < 0 || a > 255) {
2568 qWarning(
"QColor::fromHsl: HSL parameters out of range");
2574 color.ct.ahsl.alpha =
a * 0x101;
2575 color.ct.ahsl.hue =
h == -1 ? USHRT_MAX : (
h % 360) * 100;
2576 color.ct.ahsl.saturation =
s * 0x101;
2577 color.ct.ahsl.lightness = l * 0x101;
2578 color.ct.ahsl.pad = 0;
2596 if (((h < 0.0f || h > 1.0f) &&
h != -1.0f)
2597 || (s < 0.0f || s > 1.0f)
2598 || (l < 0.0f || l > 1.0f)
2599 || (a < 0.0f || a > 1.0f)) {
2600 qWarning(
"QColor::fromHslF: HSL parameters out of range");
2607 color.ct.ahsl.hue = (
h == -1.0f) ? USHRT_MAX :
qRound(
h * 36000.0f);
2608 if (
color.ct.ahsl.hue == 36000)
2609 color.ct.ahsl.hue = 0;
2612 color.ct.ahsl.pad = 0;
2628 if (!
c || !
m || !
y || !k)
2657 if (!
c || !
m || !
y || !k)
2665 *
c = ct.acmyk.cyan / float(USHRT_MAX);
2666 *
m = ct.acmyk.magenta / float(USHRT_MAX);
2667 *
y = ct.acmyk.yellow / float(USHRT_MAX);
2668 *k = ct.acmyk.black / float(USHRT_MAX);
2671 *
a = ct.acmyk.alpha / float(USHRT_MAX);
2684 if (c < 0 || c > 255
2688 || a < 0 || a > 255) {
2689 qWarning(
"QColor::setCmyk: CMYK parameters out of range");
2695 ct.acmyk.alpha =
a * 0x101;
2696 ct.acmyk.cyan =
c * 0x101;
2697 ct.acmyk.magenta =
m * 0x101;
2698 ct.acmyk.yellow =
y * 0x101;
2699 ct.acmyk.black = k * 0x101;
2714 if (c < 0.0f || c > 1.0f
2715 || m < 0.0f || m > 1.0f
2716 || y < 0.0f || y > 1.0f
2717 || k < 0.0f || k > 1.0f
2718 || a < 0.0f || a > 1.0f) {
2719 qWarning(
"QColor::setCmykF: CMYK parameters out of range");
2725 ct.acmyk.alpha =
qRound(
a * USHRT_MAX);
2726 ct.acmyk.cyan =
qRound(
c * USHRT_MAX);
2727 ct.acmyk.magenta =
qRound(
m * USHRT_MAX);
2728 ct.acmyk.yellow =
qRound(
y * USHRT_MAX);
2729 ct.acmyk.black =
qRound(k * USHRT_MAX);
2743 if (c < 0 || c > 255
2747 || a < 0 || a > 255) {
2748 qWarning(
"QColor::fromCmyk: CMYK parameters out of range");
2754 color.ct.acmyk.alpha =
a * 0x101;
2755 color.ct.acmyk.cyan =
c * 0x101;
2756 color.ct.acmyk.magenta =
m * 0x101;
2757 color.ct.acmyk.yellow =
y * 0x101;
2758 color.ct.acmyk.black = k * 0x101;
2775 if (c < 0.0f || c > 1.0f
2776 || m < 0.0f || m > 1.0f
2777 || y < 0.0f || y > 1.0f
2778 || k < 0.0f || k > 1.0f
2779 || a < 0.0f || a > 1.0f) {
2780 qWarning(
"QColor::fromCmykF: CMYK parameters out of range");
2816 else if (factor < 100)
2817 return darker(10000 / factor);
2820 int s = hsv.ct.ahsv.saturation;
2821 uint v = hsv.ct.ahsv.value;
2824 if (
v > USHRT_MAX) {
2832 hsv.ct.ahsv.saturation =
s;
2833 hsv.ct.ahsv.value =
v;
2861 else if (factor < 100)
2862 return lighter(10000 / factor);
2865 hsv.ct.ahsv.value = (hsv.ct.ahsv.value * 100) / factor;
2889 if ((cspec == ExtendedRgb ||
color.cspec == ExtendedRgb) &&
2896 return (cspec ==
color.cspec
2897 && ct.argb.alpha ==
color.ct.argb.alpha
2899 && ((ct.ahsv.hue % 36000) == (
color.ct.ahsv.hue % 36000)))
2900 || (ct.argb.red ==
color.ct.argb.red))
2901 && ct.argb.green ==
color.ct.argb.green
2902 && ct.argb.blue ==
color.ct.argb.blue
2903 && ct.argb.pad ==
color.ct.argb.pad);
2932void QColor::invalidate() noexcept
2935 ct.argb.alpha = USHRT_MAX;
2946#ifndef QT_NO_DEBUG_STREAM
2951 dbg.nospace() <<
"QColor(Invalid)";
2953 dbg.nospace() <<
"QColor(ARGB " <<
c.alphaF() <<
", " <<
c.redF() <<
", " <<
c.greenF() <<
", " <<
c.blueF() <<
')';
2955 dbg.nospace() <<
"QColor(Ext. ARGB " <<
c.alphaF() <<
", " <<
c.redF() <<
", " <<
c.greenF() <<
", " <<
c.blueF() <<
')';
2957 dbg.nospace() <<
"QColor(AHSV " <<
c.alphaF() <<
", " <<
c.hueF() <<
", " <<
c.saturationF() <<
", " <<
c.valueF() <<
')';
2959 dbg.nospace() <<
"QColor(ACMYK " <<
c.alphaF() <<
", " <<
c.cyanF() <<
", " <<
c.magentaF() <<
", " <<
c.yellowF() <<
", "
2960 <<
c.blackF()<<
')';
2962 dbg.nospace() <<
"QColor(AHSL " <<
c.alphaF() <<
", " <<
c.hslHueF() <<
", " <<
c.hslSaturationF() <<
", " <<
c.lightnessF() <<
')';
2968#ifndef QT_NO_DATASTREAM
2979 if (
stream.version() < 7) {
2980 if (!
color.isValid())
2983 if (
stream.version() == 1)
2984 p = ((
p << 16) & 0xff0000) | ((
p >> 16) & 0xff) | (
p & 0xff00ff00);
3015 if (
stream.version() < 7) {
3018 if (
p == 0x49000000) {
3022 if (
stream.version() == 1)
3023 p = ((
p << 16) & 0xff0000) | ((
p >> 16) & 0xff) | (
p & 0xff00ff00);
3050 0, 16711935, 8355967, 5570645, 4177983, 3342387, 2785322, 2387419,
3051 2088991, 1856881, 1671193, 1519266, 1392661, 1285533, 1193709, 1114129,
3052 1044495, 983055, 928440, 879575, 835596, 795806, 759633, 726605,
3053 696330, 668477, 642766, 618960, 596854, 576273, 557064, 539094,
3054 522247, 506422, 491527, 477483, 464220, 451673, 439787, 428511,
3055 417798, 407608, 397903, 388649, 379816, 371376, 363302, 355573,
3056 348165, 341059, 334238, 327685, 321383, 315319, 309480, 303853,
3057 298427, 293191, 288136, 283253, 278532, 273966, 269547, 265268,
3058 261123, 257106, 253211, 249431, 245763, 242201, 238741, 235379,
3059 232110, 228930, 225836, 222825, 219893, 217038, 214255, 211543,
3060 208899, 206320, 203804, 201348, 198951, 196611, 194324, 192091,
3061 189908, 187774, 185688, 183647, 181651, 179698, 177786, 175915,
3062 174082, 172287, 170529, 168807, 167119, 165464, 163842, 162251,
3063 160691, 159161, 157659, 156186, 154740, 153320, 151926, 150557,
3064 149213, 147893, 146595, 145321, 144068, 142837, 141626, 140436,
3065 139266, 138115, 136983, 135869, 134773, 133695, 132634, 131590,
3066 130561, 129549, 128553, 127572, 126605, 125653, 124715, 123792,
3067 122881, 121984, 121100, 120229, 119370, 118524, 117689, 116866,
3068 116055, 115254, 114465, 113686, 112918, 112160, 111412, 110675,
3069 109946, 109228, 108519, 107818, 107127, 106445, 105771, 105106,
3070 104449, 103800, 103160, 102527, 101902, 101284, 100674, 100071,
3071 99475, 98887, 98305, 97730, 97162, 96600, 96045, 95496,
3072 94954, 94417, 93887, 93362, 92844, 92331, 91823, 91322,
3073 90825, 90334, 89849, 89368, 88893, 88422, 87957, 87497,
3074 87041, 86590, 86143, 85702, 85264, 84832, 84403, 83979,
3075 83559, 83143, 82732, 82324, 81921, 81521, 81125, 80733,
3076 80345, 79961, 79580, 79203, 78829, 78459, 78093, 77729,
3077 77370, 77013, 76660, 76310, 75963, 75619, 75278, 74941,
3078 74606, 74275, 73946, 73620, 73297, 72977, 72660, 72346,
3079 72034, 71725, 71418, 71114, 70813, 70514, 70218, 69924,
3080 69633, 69344, 69057, 68773, 68491, 68211, 67934, 67659,
3081 67386, 67116, 66847, 66581, 66317, 66055, 65795, 65537
The QColor class provides colors based on RGB, HSV or CMYK values.
float blackF() const noexcept
Returns the black color component of this color.
float valueF() const noexcept
Returns the value color component of this color.
int saturation() const noexcept
Returns the HSV saturation color component of this color.
void setHslF(float h, float s, float l, float a=1.0)
void getHsl(int *h, int *s, int *l, int *a=nullptr) const
QColor toExtendedRgb() const noexcept
Create and returns an extended RGB QColor based on this color.
QColor convertTo(Spec colorSpec) const noexcept
Creates a copy of this color in the format specified by colorSpec.
void getRgbF(float *r, float *g, float *b, float *a=nullptr) const
Sets the contents pointed to by r, g, b, and a, to the red, green, blue, and alpha-channel (transpare...
void setRedF(float red)
Sets the red color component of this color to red.
float hsvHueF() const noexcept
Returns the hue color component of this color.
void setAlphaF(float alpha)
Sets the alpha of this color to alpha.
Spec
The type of color specified, either RGB, extended RGB, HSV, CMYK or HSL.
static QColor fromHslF(float h, float s, float l, float a=1.0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
int hsvSaturation() const noexcept
Returns the HSV saturation color component of this color.
QColor & operator=(Qt::GlobalColor color) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
QColor darker(int f=200) const noexcept
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
float yellowF() const noexcept
Returns the yellow color component of this color.
void setHsl(int h, int s, int l, int a=255)
float hueF() const noexcept
Returns the HSV hue color component of this color.
constexpr QColor() noexcept
Constructs an invalid color with the RGB value (0, 0, 0).
static QColor fromRgb(QRgb rgb) noexcept
Static convenience function that returns a QColor constructed from the given QRgb value rgb.
QColor toHsv() const noexcept
Creates and returns an HSV QColor based on this color.
QColor toRgb() const noexcept
Create and returns an RGB QColor based on this color.
void setBlueF(float blue)
Sets the blue color component of this color to blue.
QRgb rgb() const noexcept
Returns the RGB value of the color.
float greenF() const noexcept
Returns the green color component of this color.
void setRgba64(QRgba64 rgba) noexcept
void getHslF(float *h, float *s, float *l, float *a=nullptr) const
void setGreen(int green)
Sets the green color component of this color to green.
QRgb qRgba(int r, int g, int b, int a)
Returns the ARGB quadruplet ({a}, {r}, {g}, {b}).
QRgb rgba() const noexcept
Returns the RGB value of the color, including its alpha.
void getCmykF(float *c, float *m, float *y, float *k, float *a=nullptr) const
Sets the contents pointed to by c, m, y, k, and a, to the cyan, magenta, yellow, black,...
int lightness() const noexcept
void getHsvF(float *h, float *s, float *v, float *a=nullptr) const
Sets the contents pointed to by h, s, v, and a, to the hue, saturation, value, and alpha-channel (tra...
QRgba64 rgba64() const noexcept
int cyan() const noexcept
Returns the cyan color component of this color.
void setBlue(int blue)
Sets the blue color component of this color to blue.
static QColor fromRgba(QRgb rgba) noexcept
Static convenience function that returns a QColor constructed from the given QRgb value rgba.
bool operator!=(const QColor &c) const noexcept
Returns true if this color has different color specification or component values from color; otherwis...
int black() const noexcept
Returns the black color component of this color.
void setGreenF(float green)
Sets the green color component of this color to green.
int alpha() const noexcept
Returns the alpha color component of this color.
int red() const noexcept
Returns the red color component of this color.
static QColor fromString(QAnyStringView name) noexcept
float magentaF() const noexcept
Returns the magenta color component of this color.
int hue() const noexcept
Returns the HSV hue color component of this color.
int blue() const noexcept
Returns the blue color component of this color.
int green() const noexcept
Returns the green color component of this color.
void setAlpha(int alpha)
Sets the alpha of this color to alpha.
float cyanF() const noexcept
Returns the cyan color component of this color.
float redF() const noexcept
Returns the red color component of this color.
void setHsv(int h, int s, int v, int a=255)
Sets a HSV color value; h is the hue, s is the saturation, v is the value and a is the alpha componen...
static QColor fromCmyk(int c, int m, int y, int k, int a=255)
Static convenience function that returns a QColor constructed from the given CMYK color values: c (cy...
void setRgba(QRgb rgba) noexcept
Sets the RGB value to rgba, including its alpha.
void setCmyk(int c, int m, int y, int k, int a=255)
Sets the color to CMYK values, c (cyan), m (magenta), y (yellow), k (black), and a (alpha-channel,...
int hsvHue() const noexcept
Returns the HSV hue color component of this color.
float saturationF() const noexcept
Returns the HSV saturation color component of this color.
int value() const noexcept
Returns the value color component of this color.
int magenta() const noexcept
Returns the magenta color component of this color.
void setRgb(int r, int g, int b, int a=255)
Sets the RGB value to r, g, b and the alpha value to a.
static QColor fromHsvF(float h, float s, float v, float a=1.0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
float hsvSaturationF() const noexcept
Returns the HSV saturation color component of this color.
float lightnessF() const noexcept
float hslSaturationF() const noexcept
QColor lighter(int f=150) const noexcept
float hslHueF() const noexcept
QString name(NameFormat format=HexRgb) const
void getRgb(int *r, int *g, int *b, int *a=nullptr) const
Sets the contents pointed to by r, g, b, and a, to the red, green, blue, and alpha-channel (transpare...
QColor toHsl() const noexcept
Creates and returns an HSL QColor based on this color.
static QColor fromCmykF(float c, float m, float y, float k, float a=1.0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool operator==(const QColor &c) const noexcept
Returns true if this color has the same color specification and component values as color; otherwise ...
void setRgbF(float r, float g, float b, float a=1.0)
Sets the color channels of this color to r (red), g (green), b (blue) and a (alpha,...
QColor toCmyk() const noexcept
Creates and returns a CMYK QColor based on this color.
void setCmykF(float c, float m, float y, float k, float a=1.0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
int hslHue() const noexcept
void getCmyk(int *c, int *m, int *y, int *k, int *a=nullptr) const
Sets the contents pointed to by c, m, y, k, and a, to the cyan, magenta, yellow, black,...
float alphaF() const noexcept
Returns the alpha color component of this color.
static QColor fromHsv(int h, int s, int v, int a=255)
Static convenience function that returns a QColor constructed from the HSV color values,...
int hslSaturation() const noexcept
static QColor fromHsl(int h, int s, int l, int a=255)
int yellow() const noexcept
Returns the yellow color component of this color.
static bool isValidColorName(QAnyStringView) noexcept
float blueF() const noexcept
Returns the blue color component of this color.
void setHsvF(float h, float s, float v, float a=1.0)
Sets a HSV color value; h is the hue, s is the saturation, v is the value and a is the alpha componen...
NameFormat
How to format the output of the name() function.
void setRed(int red)
Sets the red color component of this color to red.
void getHsv(int *h, int *s, int *v, int *a=nullptr) const
Sets the contents pointed to by h, s, v, and a, to the hue, saturation, value, and alpha-channel (tra...
bool isValid() const noexcept
Returns true if the color is valid; otherwise returns false.
static QColor fromRgbF(float r, float g, float b, float a=1.0)
Static convenience function that returns a QColor constructed from the RGB color values,...
static QStringList colorNames()
Returns a QStringList containing the color names Qt knows about.
static QColor fromRgba64(ushort r, ushort g, ushort b, ushort a=USHRT_MAX) noexcept
\inmodule QtCore\reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString right(qsizetype n) const
Returns a substring that contains the n rightmost characters of the string.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
\keyword 16-bit Floating Point Support\inmodule QtCore \inheaderfile QFloat16
QSet< QString >::iterator it
Combined button and popup list for selecting options.
constexpr int fromHex(char32_t c) noexcept
constexpr char toAsciiLower(char ch) noexcept
QAnyStringView qToAnyStringViewIgnoringNull(const QStringLike &s) noexcept
size_t qstrlen(const char *str)
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
static QStringList get_colornames()
std::optional< QRgb > qt_get_hex_rgb(const char *name)
const uint qt_inv_premul_factor[256]
QDataStream & operator>>(QDataStream &stream, QColor &color)
static constexpr struct RGBData rgbTbl[]
static std::optional< QRgb > get_named_rgb(QAnyStringView name)
static const int rgbTblSize
static std::optional< QRgba64 > get_hex_rgb(const char *name, size_t len)
static std::optional< QRgb > get_named_rgb_no_space(const char *name_no_space)
#define QCOLOR_INT_RANGE_CHECK(fn, var)
static qfloat16 & castF16(quint16 &v)
static int hex2int(const char *s, int n)
#define QRGBA(r, g, b, a)
QDebug operator<<(QDebug dbg, const QColor &c)
#define QCOLOR_REAL_RANGE_CHECK(fn, var)
bool operator<(const char *name, const RGBData &data)
static constexpr uint qt_div_257(uint x)
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
bool qFuzzyIsNull(qfloat16 f) noexcept
int qRound(qfloat16 d) noexcept
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qBound(const T &min, const T &val, const T &max)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble GLdouble GLdouble q
GLfloat GLfloat GLfloat alpha
static bool fromString(const QMetaObject *mo, QString s, Allocate &&allocate)
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
#define Q_ASSERT_X(cond, x, msg)
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
constexpr int qRed(QRgb rgb)
constexpr int qGreen(QRgb rgb)
constexpr int qBlue(QRgb rgb)
constexpr int qAlpha(QRgb rgb)
constexpr QRgba64 qRgba64(quint16 r, quint16 g, quint16 b, quint16 a)
QT_BEGIN_NAMESPACE typedef signed char qint8
static constexpr size_t MaxInternalSize