painting/qcolor_p.cpp

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

Generated by Squish Coco Non-Commercial