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 | { } | - |
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(!!(!TRUE | never evaluated | FALSE | never evaluated |
QGuiApplication::primaryScreen())()), false)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
24 | QMessageLogger(__FILE__, 6268, __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 < 8TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
31 | screenMap->mode = QColormap::Indexed; | - |
32 | screenMap->numcolors = 256; | - |
33 | } never executed: end of block else { | 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 | } | - |
44 | | - |
45 | QColormap QColormap::instance(int ) | - |
46 | { | - |
47 | return QColormap(); | - |
48 | } | - |
49 | | - |
50 | QColormap::QColormap() | - |
51 | : d(screenMap) | - |
52 | { d->ref.ref(); } | - |
53 | | - |
54 | QColormap::QColormap(const QColormap &colormap) | - |
55 | :d (colormap.d) | - |
56 | { d->ref.ref(); } | - |
57 | | - |
58 | QColormap::~QColormap() | - |
59 | { | - |
60 | if (!d->ref.deref()) | - |
61 | delete d; | - |
62 | } | - |
63 | | - |
64 | QColormap::Mode QColormap::mode() const | - |
65 | { return d->mode; } | - |
66 | | - |
67 | | - |
68 | int QColormap::depth() const | - |
69 | { return d->depth; } | - |
70 | | - |
71 | | - |
72 | int QColormap::size() const | - |
73 | { | - |
74 | return d->numcolors; | - |
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 (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask); | - |
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 qRgb(tr,tg,tb); | - |
113 | } | - |
114 | | - |
115 | uint QColormap::pixel(const QColor &color) const | - |
116 | { | - |
117 | QRgb rgb = color.rgba(); | - |
118 | if (d->mode == QColormap::Direct) { | - |
119 | switch(d->depth) { | - |
120 | case 16: | - |
121 | return qt_convRgbTo16(rgb); | - |
122 | case 24: | - |
123 | case 32: | - |
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 0xff000000 | (b & blue_mask) | (tg & green_mask) | (tr & red_mask); | - |
142 | } | - |
143 | } | - |
144 | } | - |
145 | | - |
146 | | - |
147 | return 0; | - |
148 | } | - |
149 | | - |
150 | const QColor QColormap::colorAt(uint pixel) const | - |
151 | { | - |
152 | if (d->mode == Direct) { | - |
153 | if (d->depth == 16) { | - |
154 | pixel = qt_conv16ToRgb(pixel); | - |
155 | } | - |
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 QColor((pixel & red_mask) >> red_shift, | - |
169 | (pixel & green_mask) >> green_shift, | - |
170 | (pixel & blue_mask)); | - |
171 | } | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
176 | return QColor(); | - |
177 | } | - |
178 | | - |
179 | const QVector<QColor> QColormap::colormap() const | - |
180 | { | - |
181 | return QVector<QColor>(); | - |
182 | } | - |
183 | | - |
184 | QColormap &QColormap::operator=(const QColormap &colormap) | - |
185 | { qAtomicAssign(d, colormap.d); return *this; } | - |
186 | | - |
187 | | - |
| | |