Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/util/qcolormap.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | class QColormapPrivate | - | ||||||
5 | { | - | ||||||
6 | public: | - | ||||||
7 | inline QColormapPrivate() | - | ||||||
8 | : ref(1), mode(QColormap::Direct), depth(0), numcolors(0) | - | ||||||
9 | { } never executed: end of block | 0 | ||||||
10 | - | |||||||
11 | QAtomicInt ref; | - | ||||||
12 | - | |||||||
13 | QColormap::Mode mode; | - | ||||||
14 | int depth; | - | ||||||
15 | int numcolors; | - | ||||||
16 | }; | - | ||||||
17 | - | |||||||
18 | static QColormapPrivate *screenMap = 0; | - | ||||||
19 | - | |||||||
20 | void QColormap::initialize() | - | ||||||
21 | { | - | ||||||
22 | screenMap = new QColormapPrivate; | - | ||||||
23 | if (__builtin_expect(!!(!QGuiApplication::primaryScreen()), false)
| 0 | ||||||
24 | QMessageLogger(__FILE__, 68, __PRETTY_FUNCTION__).warning("no screens available, assuming 24-bit color"); | - | ||||||
25 | screenMap->depth = 24; | - | ||||||
26 | screenMap->mode = QColormap::Direct; | - | ||||||
27 | return; never executed: return; | 0 | ||||||
28 | } | - | ||||||
29 | screenMap->depth = QGuiApplication::primaryScreen()->depth(); | - | ||||||
30 | if (screenMap->depth < 8
| 0 | ||||||
31 | screenMap->mode = QColormap::Indexed; | - | ||||||
32 | screenMap->numcolors = 256; | - | ||||||
33 | } never executed: else {end of block | 0 | ||||||
34 | screenMap->mode = QColormap::Direct; | - | ||||||
35 | screenMap->numcolors = -1; | - | ||||||
36 | } never executed: end of block | 0 | ||||||
37 | } | - | ||||||
38 | - | |||||||
39 | void QColormap::cleanup() | - | ||||||
40 | { | - | ||||||
41 | delete screenMap; | - | ||||||
42 | screenMap = 0; | - | ||||||
43 | } never executed: end of block | 0 | ||||||
44 | - | |||||||
45 | QColormap QColormap::instance(int ) | - | ||||||
46 | { | - | ||||||
47 | return never executed: QColormap();return QColormap(); never executed: return QColormap(); | 0 | ||||||
48 | } | - | ||||||
49 | - | |||||||
50 | QColormap::QColormap() | - | ||||||
51 | : d(screenMap) | - | ||||||
52 | { d->ref.ref(); } never executed: end of block | 0 | ||||||
53 | - | |||||||
54 | QColormap::QColormap(const QColormap &colormap) | - | ||||||
55 | :d (colormap.d) | - | ||||||
56 | { d->ref.ref(); } never executed: end of block | 0 | ||||||
57 | - | |||||||
58 | QColormap::~QColormap() | - | ||||||
59 | { | - | ||||||
60 | if (!d->ref.deref()
| 0 | ||||||
61 | delete d; never executed: delete d; | 0 | ||||||
62 | } never executed: end of block | 0 | ||||||
63 | - | |||||||
64 | QColormap::Mode QColormap::mode() const | - | ||||||
65 | { return never executed: d->mode;return d->mode; never executed: }return d->mode; | 0 | ||||||
66 | - | |||||||
67 | - | |||||||
68 | int QColormap::depth() const | - | ||||||
69 | { return never executed: d->depth;return d->depth; never executed: }return d->depth; | 0 | ||||||
70 | - | |||||||
71 | - | |||||||
72 | int QColormap::size() const | - | ||||||
73 | { | - | ||||||
74 | return never executed: d->numcolors;return d->numcolors; never executed: return d->numcolors; | 0 | ||||||
75 | } | - | ||||||
76 | - | |||||||
77 | - | |||||||
78 | - | |||||||
79 | - | |||||||
80 | static const int qt_rbits = (565/100); | - | ||||||
81 | static const int qt_gbits = (565/10%10); | - | ||||||
82 | static const int qt_bbits = (565%10); | - | ||||||
83 | static const int qt_red_shift = qt_bbits+qt_gbits-(8-qt_rbits); | - | ||||||
84 | static const int qt_green_shift = qt_bbits-(8-qt_gbits); | - | ||||||
85 | static const int qt_neg_blue_shift = 8-qt_bbits; | - | ||||||
86 | static const int qt_blue_mask = (1<<qt_bbits)-1; | - | ||||||
87 | static const int qt_green_mask = (1<<(qt_gbits+qt_bbits))-(1<<qt_bbits); | - | ||||||
88 | static const int qt_red_mask = (1<<(qt_rbits+qt_gbits+qt_bbits))-(1<<(qt_gbits+qt_bbits)); | - | ||||||
89 | - | |||||||
90 | static const int qt_red_rounding_shift = qt_red_shift + qt_rbits; | - | ||||||
91 | static const int qt_green_rounding_shift = qt_green_shift + qt_gbits; | - | ||||||
92 | static const int qt_blue_rounding_shift = qt_bbits - qt_neg_blue_shift; | - | ||||||
93 | - | |||||||
94 | inline ushort qt_convRgbTo16(QRgb c) | - | ||||||
95 | { | - | ||||||
96 | const int tr = qRed(c) << qt_red_shift; | - | ||||||
97 | const int tg = qGreen(c) << qt_green_shift; | - | ||||||
98 | const int tb = qBlue(c) >> qt_neg_blue_shift; | - | ||||||
99 | - | |||||||
100 | return never executed: (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask);return (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask); never executed: return (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask); | 0 | ||||||
101 | } | - | ||||||
102 | - | |||||||
103 | inline QRgb qt_conv16ToRgb(ushort c) | - | ||||||
104 | { | - | ||||||
105 | const int r=(c & qt_red_mask); | - | ||||||
106 | const int g=(c & qt_green_mask); | - | ||||||
107 | const int b=(c & qt_blue_mask); | - | ||||||
108 | const int tr = r >> qt_red_shift | r >> qt_red_rounding_shift; | - | ||||||
109 | const int tg = g >> qt_green_shift | g >> qt_green_rounding_shift; | - | ||||||
110 | const int tb = b << qt_neg_blue_shift | b >> qt_blue_rounding_shift; | - | ||||||
111 | - | |||||||
112 | return never executed: qRgb(tr,tg,tb);return qRgb(tr,tg,tb); never executed: return qRgb(tr,tg,tb); | 0 | ||||||
113 | } | - | ||||||
114 | - | |||||||
115 | uint QColormap::pixel(const QColor &color) const | - | ||||||
116 | { | - | ||||||
117 | QRgb rgb = color.rgba(); | - | ||||||
118 | if (d->mode == QColormap::Direct
| 0 | ||||||
119 | switch(d->depth) { | - | ||||||
120 | case never executed: 16:case 16: never executed: case 16: | 0 | ||||||
121 | return never executed: qt_convRgbTo16(rgb);return qt_convRgbTo16(rgb); never executed: return qt_convRgbTo16(rgb); | 0 | ||||||
122 | case never executed: 24:case 24: never executed: case 24: | 0 | ||||||
123 | case never executed: 32:case 32: never executed: case 32: | 0 | ||||||
124 | { | - | ||||||
125 | const int r = qRed(rgb); | - | ||||||
126 | const int g = qGreen(rgb); | - | ||||||
127 | const int b = qBlue(rgb); | - | ||||||
128 | const int red_shift = 16; | - | ||||||
129 | const int green_shift = 8; | - | ||||||
130 | const int red_mask = 0xff0000; | - | ||||||
131 | const int green_mask = 0x00ff00; | - | ||||||
132 | const int blue_mask = 0x0000ff; | - | ||||||
133 | const int tg = g << green_shift; | - | ||||||
134 | - | |||||||
135 | - | |||||||
136 | - | |||||||
137 | - | |||||||
138 | - | |||||||
139 | - | |||||||
140 | const int tr = r << red_shift; | - | ||||||
141 | return never executed: 0xff000000 | (b & blue_mask) | (tg & green_mask) | (tr & red_mask);return 0xff000000 | (b & blue_mask) | (tg & green_mask) | (tr & red_mask); never executed: return 0xff000000 | (b & blue_mask) | (tg & green_mask) | (tr & red_mask); | 0 | ||||||
142 | } | - | ||||||
143 | } | - | ||||||
144 | } never executed: end of block | 0 | ||||||
145 | - | |||||||
146 | - | |||||||
147 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
148 | } | - | ||||||
149 | - | |||||||
150 | const QColor QColormap::colorAt(uint pixel) const | - | ||||||
151 | { | - | ||||||
152 | if (d->mode == Direct
| 0 | ||||||
153 | if (d->depth == 16
| 0 | ||||||
154 | pixel = qt_conv16ToRgb(pixel); | - | ||||||
155 | } never executed: end of block | 0 | ||||||
156 | const int red_shift = 16; | - | ||||||
157 | const int green_shift = 8; | - | ||||||
158 | const int red_mask = 0xff0000; | - | ||||||
159 | const int green_mask = 0x00ff00; | - | ||||||
160 | const int blue_mask = 0x0000ff; | - | ||||||
161 | - | |||||||
162 | - | |||||||
163 | - | |||||||
164 | - | |||||||
165 | - | |||||||
166 | - | |||||||
167 | - | |||||||
168 | return never executed: QColor((pixel & red_mask) >> red_shift,return QColor((pixel & red_mask) >> red_shift, (pixel & green_mask) >> green_shift, (pixel & blue_mask)); never executed: return QColor((pixel & red_mask) >> red_shift, (pixel & green_mask) >> green_shift, (pixel & blue_mask)); | 0 | ||||||
169 | (pixel & green_mask) >> green_shift, never executed: return QColor((pixel & red_mask) >> red_shift, (pixel & green_mask) >> green_shift, (pixel & blue_mask)); | 0 | ||||||
170 | (pixel & blue_mask)); never executed: return QColor((pixel & red_mask) >> red_shift, (pixel & green_mask) >> green_shift, (pixel & blue_mask)); | 0 | ||||||
171 | } | - | ||||||
172 | - | |||||||
173 | - | |||||||
174 | - | |||||||
175 | - | |||||||
176 | return never executed: QColor();return QColor(); never executed: return QColor(); | 0 | ||||||
177 | } | - | ||||||
178 | - | |||||||
179 | const QVector<QColor> QColormap::colormap() const | - | ||||||
180 | { | - | ||||||
181 | return never executed: QVector<QColor>();return QVector<QColor>(); never executed: return QVector<QColor>(); | 0 | ||||||
182 | } | - | ||||||
183 | - | |||||||
184 | QColormap &QColormap::operator=(const QColormap &colormap) | - | ||||||
185 | { qAtomicAssign(d, colormap.d); return never executed: *this;return *this; never executed: }return *this; | 0 | ||||||
186 | - | |||||||
187 | - | |||||||
Switch to Source code | Preprocessed file |