2223QColor QColor::toRgb()
const noexcept
2225 if (!isValid() || cspec == Rgb)
2230 if (cspec != ExtendedRgb)
2231 color.ct.argb.alpha = ct.argb.alpha;
2232 color.ct.argb.pad = 0;
2237 if (ct.ahsv.saturation == 0 || ct.ahsv.hue == USHRT_MAX) {
2239 color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = ct.ahsv.value;
2244 const float h = ct.ahsv.hue == 36000 ? 0.0f : ct.ahsv.hue / 6000.0f;
2245 const float s = ct.ahsv.saturation /
float(USHRT_MAX);
2246 const float v = ct.ahsv.value /
float(USHRT_MAX);
2247 const int i =
int(h);
2248 const float f = h - i;
2249 const float p = v * (1.0f - s);
2252 const float q = v * (1.0f - (s * f));
2256 color.ct.argb.red = qRound(q * USHRT_MAX);
2257 color.ct.argb.green = qRound(v * USHRT_MAX);
2258 color.ct.argb.blue = qRound(p * USHRT_MAX);
2261 color.ct.argb.red = qRound(p * USHRT_MAX);
2262 color.ct.argb.green = qRound(q * USHRT_MAX);
2263 color.ct.argb.blue = qRound(v * USHRT_MAX);
2266 color.ct.argb.red = qRound(v * USHRT_MAX);
2267 color.ct.argb.green = qRound(p * USHRT_MAX);
2268 color.ct.argb.blue = qRound(q * USHRT_MAX);
2272 const float t = v * (1.0f - (s * (1.0f - f)));
2276 color.ct.argb.red = qRound(v * USHRT_MAX);
2277 color.ct.argb.green = qRound(t * USHRT_MAX);
2278 color.ct.argb.blue = qRound(p * USHRT_MAX);
2281 color.ct.argb.red = qRound(p * USHRT_MAX);
2282 color.ct.argb.green = qRound(v * USHRT_MAX);
2283 color.ct.argb.blue = qRound(t * USHRT_MAX);
2286 color.ct.argb.red = qRound(t * USHRT_MAX);
2287 color.ct.argb.green = qRound(p * USHRT_MAX);
2288 color.ct.argb.blue = qRound(v * USHRT_MAX);
2296 if (ct.ahsl.saturation == 0 || ct.ahsl.hue == USHRT_MAX) {
2298 color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = ct.ahsl.lightness;
2299 }
else if (ct.ahsl.lightness == 0) {
2301 color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = 0;
2304 const float h = ct.ahsl.hue == 36000 ? 0.0f : ct.ahsl.hue / 36000.0f;
2305 const float s = ct.ahsl.saturation /
float(USHRT_MAX);
2306 const float l = ct.ahsl.lightness /
float(USHRT_MAX);
2310 temp2 = l * (1.0f + s);
2312 temp2 = l + s - (l * s);
2314 const float temp1 = (2.0f * l) - temp2;
2315 float temp3[3] = { h + (1.0f / 3.0f),
2317 h - (1.0f / 3.0f) };
2319 for (
int i = 0; i != 3; ++i) {
2320 if (temp3[i] < 0.0f)
2322 else if (temp3[i] > 1.0f)
2325 const float sixtemp3 = temp3[i] * 6.0f;
2326 if (sixtemp3 < 1.0f)
2327 color.ct.array[i+1] = qRound((temp1 + (temp2 - temp1) * sixtemp3) * USHRT_MAX);
2328 else if ((temp3[i] * 2.0f) < 1.0f)
2329 color.ct.array[i+1] = qRound(temp2 * USHRT_MAX);
2330 else if ((temp3[i] * 3.0f) < 2.0f)
2331 color.ct.array[i+1] = qRound((temp1 + (temp2 -temp1) * (2.0f /3.0f - temp3[i]) * 6.0f) * USHRT_MAX);
2333 color.ct.array[i+1] = qRound(temp1 * USHRT_MAX);
2335 color.ct.argb.red = color.ct.argb.red == 1 ? 0 : color.ct.argb.red;
2336 color.ct.argb.green = color.ct.argb.green == 1 ? 0 : color.ct.argb.green;
2337 color.ct.argb.blue = color.ct.argb.blue == 1 ? 0 : color.ct.argb.blue;
2343 const float c = ct.acmyk.cyan /
float(USHRT_MAX);
2344 const float m = ct.acmyk.magenta /
float(USHRT_MAX);
2345 const float y = ct.acmyk.yellow /
float(USHRT_MAX);
2346 const float k = ct.acmyk.black /
float(USHRT_MAX);
2348 color.ct.argb.red = qRound((1.0f - (c * (1.0f - k) + k)) * USHRT_MAX);
2349 color.ct.argb.green = qRound((1.0f - (m * (1.0f - k) + k)) * USHRT_MAX);
2350 color.ct.argb.blue = qRound((1.0f - (y * (1.0f - k) + k)) * USHRT_MAX);
2354 color.ct.argb.alpha = qRound(USHRT_MAX *
float(castF16(ct.argbExtended.alphaF16)));
2355 color.ct.argb.red = qRound(USHRT_MAX * qBound(0.0f,
float(castF16(ct.argbExtended.redF16)), 1.0f));
2356 color.ct.argb.green = qRound(USHRT_MAX * qBound(0.0f,
float(castF16(ct.argbExtended.greenF16)), 1.0f));
2357 color.ct.argb.blue = qRound(USHRT_MAX * qBound(0.0f,
float(castF16(ct.argbExtended.blueF16)), 1.0f));
3187 0, 16711935, 8355967, 5570645, 4177983, 3342387, 2785322, 2387419,
3188 2088991, 1856881, 1671193, 1519266, 1392661, 1285533, 1193709, 1114129,
3189 1044495, 983055, 928440, 879575, 835596, 795806, 759633, 726605,
3190 696330, 668477, 642766, 618960, 596854, 576273, 557064, 539094,
3191 522247, 506422, 491527, 477483, 464220, 451673, 439787, 428511,
3192 417798, 407608, 397903, 388649, 379816, 371376, 363302, 355573,
3193 348165, 341059, 334238, 327685, 321383, 315319, 309480, 303853,
3194 298427, 293191, 288136, 283253, 278532, 273966, 269547, 265268,
3195 261123, 257106, 253211, 249431, 245763, 242201, 238741, 235379,
3196 232110, 228930, 225836, 222825, 219893, 217038, 214255, 211543,
3197 208899, 206320, 203804, 201348, 198951, 196611, 194324, 192091,
3198 189908, 187774, 185688, 183647, 181651, 179698, 177786, 175915,
3199 174082, 172287, 170529, 168807, 167119, 165464, 163842, 162251,
3200 160691, 159161, 157659, 156186, 154740, 153320, 151926, 150557,
3201 149213, 147893, 146595, 145321, 144068, 142837, 141626, 140436,
3202 139266, 138115, 136983, 135869, 134773, 133695, 132634, 131590,
3203 130561, 129549, 128553, 127572, 126605, 125653, 124715, 123792,
3204 122881, 121984, 121100, 120229, 119370, 118524, 117689, 116866,
3205 116055, 115254, 114465, 113686, 112918, 112160, 111412, 110675,
3206 109946, 109228, 108519, 107818, 107127, 106445, 105771, 105106,
3207 104449, 103800, 103160, 102527, 101902, 101284, 100674, 100071,
3208 99475, 98887, 98305, 97730, 97162, 96600, 96045, 95496,
3209 94954, 94417, 93887, 93362, 92844, 92331, 91823, 91322,
3210 90825, 90334, 89849, 89368, 88893, 88422, 87957, 87497,
3211 87041, 86590, 86143, 85702, 85264, 84832, 84403, 83979,
3212 83559, 83143, 82732, 82324, 81921, 81521, 81125, 80733,
3213 80345, 79961, 79580, 79203, 78829, 78459, 78093, 77729,
3214 77370, 77013, 76660, 76310, 75963, 75619, 75278, 74941,
3215 74606, 74275, 73946, 73620, 73297, 72977, 72660, 72346,
3216 72034, 71725, 71418, 71114, 70813, 70514, 70218, 69924,
3217 69633, 69344, 69057, 68773, 68491, 68211, 67934, 67659,
3218 67386, 67116, 66847, 66581, 66317, 66055, 65795, 65537