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