qcolor_p.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/painting/qcolor_p.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qglobal.h"-
41#include "qrgb.h"-
42#include "qstringlist.h"-
43#include "private/qtools_p.h"-
44-
45#include <algorithm>-
46-
47QT_BEGIN_NAMESPACE-
48-
49/*!-
50 \internal-
51 If s[0..1] is a valid hex number, returns its integer value,-
52 otherwise returns -1.-
53 */-
54static inline int hex2int(const char *s)-
55{-
56 const int hi = QtMiscUtils::fromHex(s[0]);-
57 if (hi < 0)
hi < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
58 return -1;
never executed: return -1;
0
59 const int lo = QtMiscUtils::fromHex(s[1]);-
60 if (lo < 0)
lo < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
61 return -1;
never executed: return -1;
0
62 return (hi << 4) | lo;
never executed: return (hi << 4) | lo;
0
63}-
64-
65/*!-
66 \internal-
67 If s is a valid hex digit, returns its integer value,-
68 multiplied by 0x11, otherwise returns -1.-
69 */-
70static inline int hex2int(char s)-
71{-
72 const int h = QtMiscUtils::fromHex(s);-
73 return h < 0 ? h : (h << 4) | h;
never executed: return h < 0 ? h : (h << 4) | h;
0
74}-
75-
76bool qt_get_hex_rgb(const char *name, QRgb *rgb)-
77{-
78 if(name[0] != '#')
name[0] != '#'Description
TRUEnever evaluated
FALSEnever evaluated
0
79 return false;
never executed: return false;
0
80 name++;-
81 int len = qstrlen(name);-
82 int a, r, g, b;-
83 a = 255;-
84 if (len == 12) {
len == 12Description
TRUEnever evaluated
FALSEnever evaluated
0
85 r = hex2int(name);-
86 g = hex2int(name + 4);-
87 b = hex2int(name + 8);-
88 } else if (len == 9) {
never executed: end of block
len == 9Description
TRUEnever evaluated
FALSEnever evaluated
0
89 r = hex2int(name);-
90 g = hex2int(name + 3);-
91 b = hex2int(name + 6);-
92 } else if (len == 8) {
never executed: end of block
len == 8Description
TRUEnever evaluated
FALSEnever evaluated
0
93 a = hex2int(name);-
94 r = hex2int(name + 2);-
95 g = hex2int(name + 4);-
96 b = hex2int(name + 6);-
97 } else if (len == 6) {
never executed: end of block
len == 6Description
TRUEnever evaluated
FALSEnever evaluated
0
98 r = hex2int(name);-
99 g = hex2int(name + 2);-
100 b = hex2int(name + 4);-
101 } else if (len == 3) {
never executed: end of block
len == 3Description
TRUEnever evaluated
FALSEnever evaluated
0
102 r = hex2int(name[0]);-
103 g = hex2int(name[1]);-
104 b = hex2int(name[2]);-
105 } else {
never executed: end of block
0
106 r = g = b = -1;-
107 }
never executed: end of block
0
108 if ((uint)r > 255 || (uint)g > 255 || (uint)b > 255 || (uint)a > 255) {
(uint)r > 255Description
TRUEnever evaluated
FALSEnever evaluated
(uint)g > 255Description
TRUEnever evaluated
FALSEnever evaluated
(uint)b > 255Description
TRUEnever evaluated
FALSEnever evaluated
(uint)a > 255Description
TRUEnever evaluated
FALSEnever evaluated
0
109 *rgb = 0;-
110 return false;
never executed: return false;
0
111 }-
112 *rgb = qRgba(r, g ,b, a);-
113 return true;
never executed: return true;
0
114}-
115-
116bool qt_get_hex_rgb(const QChar *str, int len, QRgb *rgb)-
117{-
118 if (len > 13)
len > 13Description
TRUEnever evaluated
FALSEnever evaluated
0
119 return false;
never executed: return false;
0
120 char tmp[16];-
121 for(int i = 0; i < len; ++i)
i < lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
122 tmp[i] = str[i].toLatin1();
never executed: tmp[i] = str[i].toLatin1();
0
123 tmp[len] = 0;-
124 return qt_get_hex_rgb(tmp, rgb);
never executed: return qt_get_hex_rgb(tmp, rgb);
0
125}-
126-
127#ifndef QT_NO_COLORNAMES-
128-
129/*-
130 CSS color names = SVG 1.0 color names + transparent (rgba(0,0,0,0))-
131*/-
132-
133#ifdef rgb-
134# undef rgb-
135#endif-
136#define rgb(r,g,b) (0xff000000 | (r << 16) | (g << 8) | b)-
137-
138static const struct RGBData {-
139 const char name[21];-
140 uint value;-
141} rgbTbl[] = {-
142 { "aliceblue", rgb(240, 248, 255) },-
143 { "antiquewhite", rgb(250, 235, 215) },-
144 { "aqua", rgb( 0, 255, 255) },-
145 { "aquamarine", rgb(127, 255, 212) },-
146 { "azure", rgb(240, 255, 255) },-
147 { "beige", rgb(245, 245, 220) },-
148 { "bisque", rgb(255, 228, 196) },-
149 { "black", rgb( 0, 0, 0) },-
150 { "blanchedalmond", rgb(255, 235, 205) },-
151 { "blue", rgb( 0, 0, 255) },-
152 { "blueviolet", rgb(138, 43, 226) },-
153 { "brown", rgb(165, 42, 42) },-
154 { "burlywood", rgb(222, 184, 135) },-
155 { "cadetblue", rgb( 95, 158, 160) },-
156 { "chartreuse", rgb(127, 255, 0) },-
157 { "chocolate", rgb(210, 105, 30) },-
158 { "coral", rgb(255, 127, 80) },-
159 { "cornflowerblue", rgb(100, 149, 237) },-
160 { "cornsilk", rgb(255, 248, 220) },-
161 { "crimson", rgb(220, 20, 60) },-
162 { "cyan", rgb( 0, 255, 255) },-
163 { "darkblue", rgb( 0, 0, 139) },-
164 { "darkcyan", rgb( 0, 139, 139) },-
165 { "darkgoldenrod", rgb(184, 134, 11) },-
166 { "darkgray", rgb(169, 169, 169) },-
167 { "darkgreen", rgb( 0, 100, 0) },-
168 { "darkgrey", rgb(169, 169, 169) },-
169 { "darkkhaki", rgb(189, 183, 107) },-
170 { "darkmagenta", rgb(139, 0, 139) },-
171 { "darkolivegreen", rgb( 85, 107, 47) },-
172 { "darkorange", rgb(255, 140, 0) },-
173 { "darkorchid", rgb(153, 50, 204) },-
174 { "darkred", rgb(139, 0, 0) },-
175 { "darksalmon", rgb(233, 150, 122) },-
176 { "darkseagreen", rgb(143, 188, 143) },-
177 { "darkslateblue", rgb( 72, 61, 139) },-
178 { "darkslategray", rgb( 47, 79, 79) },-
179 { "darkslategrey", rgb( 47, 79, 79) },-
180 { "darkturquoise", rgb( 0, 206, 209) },-
181 { "darkviolet", rgb(148, 0, 211) },-
182 { "deeppink", rgb(255, 20, 147) },-
183 { "deepskyblue", rgb( 0, 191, 255) },-
184 { "dimgray", rgb(105, 105, 105) },-
185 { "dimgrey", rgb(105, 105, 105) },-
186 { "dodgerblue", rgb( 30, 144, 255) },-
187 { "firebrick", rgb(178, 34, 34) },-
188 { "floralwhite", rgb(255, 250, 240) },-
189 { "forestgreen", rgb( 34, 139, 34) },-
190 { "fuchsia", rgb(255, 0, 255) },-
191 { "gainsboro", rgb(220, 220, 220) },-
192 { "ghostwhite", rgb(248, 248, 255) },-
193 { "gold", rgb(255, 215, 0) },-
194 { "goldenrod", rgb(218, 165, 32) },-
195 { "gray", rgb(128, 128, 128) },-
196 { "green", rgb( 0, 128, 0) },-
197 { "greenyellow", rgb(173, 255, 47) },-
198 { "grey", rgb(128, 128, 128) },-
199 { "honeydew", rgb(240, 255, 240) },-
200 { "hotpink", rgb(255, 105, 180) },-
201 { "indianred", rgb(205, 92, 92) },-
202 { "indigo", rgb( 75, 0, 130) },-
203 { "ivory", rgb(255, 255, 240) },-
204 { "khaki", rgb(240, 230, 140) },-
205 { "lavender", rgb(230, 230, 250) },-
206 { "lavenderblush", rgb(255, 240, 245) },-
207 { "lawngreen", rgb(124, 252, 0) },-
208 { "lemonchiffon", rgb(255, 250, 205) },-
209 { "lightblue", rgb(173, 216, 230) },-
210 { "lightcoral", rgb(240, 128, 128) },-
211 { "lightcyan", rgb(224, 255, 255) },-
212 { "lightgoldenrodyellow", rgb(250, 250, 210) },-
213 { "lightgray", rgb(211, 211, 211) },-
214 { "lightgreen", rgb(144, 238, 144) },-
215 { "lightgrey", rgb(211, 211, 211) },-
216 { "lightpink", rgb(255, 182, 193) },-
217 { "lightsalmon", rgb(255, 160, 122) },-
218 { "lightseagreen", rgb( 32, 178, 170) },-
219 { "lightskyblue", rgb(135, 206, 250) },-
220 { "lightslategray", rgb(119, 136, 153) },-
221 { "lightslategrey", rgb(119, 136, 153) },-
222 { "lightsteelblue", rgb(176, 196, 222) },-
223 { "lightyellow", rgb(255, 255, 224) },-
224 { "lime", rgb( 0, 255, 0) },-
225 { "limegreen", rgb( 50, 205, 50) },-
226 { "linen", rgb(250, 240, 230) },-
227 { "magenta", rgb(255, 0, 255) },-
228 { "maroon", rgb(128, 0, 0) },-
229 { "mediumaquamarine", rgb(102, 205, 170) },-
230 { "mediumblue", rgb( 0, 0, 205) },-
231 { "mediumorchid", rgb(186, 85, 211) },-
232 { "mediumpurple", rgb(147, 112, 219) },-
233 { "mediumseagreen", rgb( 60, 179, 113) },-
234 { "mediumslateblue", rgb(123, 104, 238) },-
235 { "mediumspringgreen", rgb( 0, 250, 154) },-
236 { "mediumturquoise", rgb( 72, 209, 204) },-
237 { "mediumvioletred", rgb(199, 21, 133) },-
238 { "midnightblue", rgb( 25, 25, 112) },-
239 { "mintcream", rgb(245, 255, 250) },-
240 { "mistyrose", rgb(255, 228, 225) },-
241 { "moccasin", rgb(255, 228, 181) },-
242 { "navajowhite", rgb(255, 222, 173) },-
243 { "navy", rgb( 0, 0, 128) },-
244 { "oldlace", rgb(253, 245, 230) },-
245 { "olive", rgb(128, 128, 0) },-
246 { "olivedrab", rgb(107, 142, 35) },-
247 { "orange", rgb(255, 165, 0) },-
248 { "orangered", rgb(255, 69, 0) },-
249 { "orchid", rgb(218, 112, 214) },-
250 { "palegoldenrod", rgb(238, 232, 170) },-
251 { "palegreen", rgb(152, 251, 152) },-
252 { "paleturquoise", rgb(175, 238, 238) },-
253 { "palevioletred", rgb(219, 112, 147) },-
254 { "papayawhip", rgb(255, 239, 213) },-
255 { "peachpuff", rgb(255, 218, 185) },-
256 { "peru", rgb(205, 133, 63) },-
257 { "pink", rgb(255, 192, 203) },-
258 { "plum", rgb(221, 160, 221) },-
259 { "powderblue", rgb(176, 224, 230) },-
260 { "purple", rgb(128, 0, 128) },-
261 { "red", rgb(255, 0, 0) },-
262 { "rosybrown", rgb(188, 143, 143) },-
263 { "royalblue", rgb( 65, 105, 225) },-
264 { "saddlebrown", rgb(139, 69, 19) },-
265 { "salmon", rgb(250, 128, 114) },-
266 { "sandybrown", rgb(244, 164, 96) },-
267 { "seagreen", rgb( 46, 139, 87) },-
268 { "seashell", rgb(255, 245, 238) },-
269 { "sienna", rgb(160, 82, 45) },-
270 { "silver", rgb(192, 192, 192) },-
271 { "skyblue", rgb(135, 206, 235) },-
272 { "slateblue", rgb(106, 90, 205) },-
273 { "slategray", rgb(112, 128, 144) },-
274 { "slategrey", rgb(112, 128, 144) },-
275 { "snow", rgb(255, 250, 250) },-
276 { "springgreen", rgb( 0, 255, 127) },-
277 { "steelblue", rgb( 70, 130, 180) },-
278 { "tan", rgb(210, 180, 140) },-
279 { "teal", rgb( 0, 128, 128) },-
280 { "thistle", rgb(216, 191, 216) },-
281 { "tomato", rgb(255, 99, 71) },-
282 { "transparent", 0 },-
283 { "turquoise", rgb( 64, 224, 208) },-
284 { "violet", rgb(238, 130, 238) },-
285 { "wheat", rgb(245, 222, 179) },-
286 { "white", rgb(255, 255, 255) },-
287 { "whitesmoke", rgb(245, 245, 245) },-
288 { "yellow", rgb(255, 255, 0) },-
289 { "yellowgreen", rgb(154, 205, 50) }-
290};-
291-
292static const int rgbTblSize = sizeof(rgbTbl) / sizeof(RGBData);-
293-
294#undef rgb-
295-
296#if defined(Q_CC_MSVC) && _MSC_VER < 1600-
297inline bool operator<(const RGBData &data1, const RGBData &data2)-
298{ return qstrcmp(data1.name, data2.name) < 0; }-
299#endif-
300-
301inline bool operator<(const char *name, const RGBData &data)-
302{
never executed: return qstrcmp(name, data.name) < 0;
return qstrcmp(name, data.name) < 0; }
never executed: return qstrcmp(name, data.name) < 0;
0
303inline bool operator<(const RGBData &data, const char *name)-
304{
never executed: return qstrcmp(data.name, name) < 0;
return qstrcmp(data.name, name) < 0; }
never executed: return qstrcmp(data.name, name) < 0;
0
305-
306static bool get_named_rgb(const char *name_no_space, QRgb *rgb)-
307{-
308 const RGBData *r = std::lower_bound(rgbTbl, rgbTbl + rgbTblSize, name_no_space);-
309 if ((r != rgbTbl + rgbTblSize) && !(name_no_space < *r)) {
(r != rgbTbl + rgbTblSize)Description
TRUEnever evaluated
FALSEnever evaluated
!(name_no_space < *r)Description
TRUEnever evaluated
FALSEnever evaluated
0
310 *rgb = r->value;-
311 return true;
never executed: return true;
0
312 }-
313 return false;
never executed: return false;
0
314}-
315-
316bool qt_get_named_rgb(const char *name, QRgb* rgb)-
317{-
318 int len = int(strlen(name));-
319 if(len > 255)
len > 255Description
TRUEnever evaluated
FALSEnever evaluated
0
320 return false;
never executed: return false;
0
321 char name_no_space[256];-
322 int pos = 0;-
323 for(int i = 0; i < len; i++) {
i < lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
324 if(name[i] != '\t' && name[i] != ' ')
name[i] != '\t'Description
TRUEnever evaluated
FALSEnever evaluated
name[i] != ' 'Description
TRUEnever evaluated
FALSEnever evaluated
0
325 name_no_space[pos++] = QChar::toLower(name[i]);
never executed: name_no_space[pos++] = QChar::toLower(name[i]);
0
326 }
never executed: end of block
0
327 name_no_space[pos] = 0;-
328-
329 return get_named_rgb(name_no_space, rgb);
never executed: return get_named_rgb(name_no_space, rgb);
0
330}-
331-
332bool qt_get_named_rgb(const QChar *name, int len, QRgb *rgb)-
333{-
334 if(len > 255)
len > 255Description
TRUEnever evaluated
FALSEnever evaluated
0
335 return false;
never executed: return false;
0
336 char name_no_space[256];-
337 int pos = 0;-
338 for(int i = 0; i < len; i++) {
i < lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
339 if(name[i] != QLatin1Char('\t') && name[i] != QLatin1Char(' '))
name[i] != QLatin1Char('\t')Description
TRUEnever evaluated
FALSEnever evaluated
name[i] != QLatin1Char(' ')Description
TRUEnever evaluated
FALSEnever evaluated
0
340 name_no_space[pos++] = name[i].toLower().toLatin1();
never executed: name_no_space[pos++] = name[i].toLower().toLatin1();
0
341 }
never executed: end of block
0
342 name_no_space[pos] = 0;-
343 return get_named_rgb(name_no_space, rgb);
never executed: return get_named_rgb(name_no_space, rgb);
0
344}-
345-
346-
347uint qt_get_rgb_val(const char *name)-
348{-
349 QRgb r = 0;-
350 qt_get_named_rgb(name,&r);-
351 return r;
never executed: return r;
0
352}-
353-
354QStringList qt_get_colornames()-
355{-
356 int i = 0;-
357 QStringList lst;-
358 lst.reserve(rgbTblSize);-
359 for (i = 0; i < rgbTblSize; i++)
i < rgbTblSizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
360 lst << QLatin1String(rgbTbl[i].name);
never executed: lst << QLatin1String(rgbTbl[i].name);
0
361 return lst;
never executed: return lst;
0
362}-
363-
364#else-
365-
366bool qt_get_named_rgb(const char *, QRgb*)-
367{-
368 return false;-
369}-
370-
371uint qt_get_rgb_val(const char *)-
372{-
373 return 0;-
374}-
375QStringList qt_get_colornames()-
376{-
377 return QStringList();-
378}-
379#endif // QT_NO_COLORNAMES-
380-
381QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9