Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include "qcolormap.h" | - |
41 | #include "qcolor.h" | - |
42 | #include "qpaintdevice.h" | - |
43 | #include "qscreen.h" | - |
44 | #include "qguiapplication.h" | - |
45 | | - |
46 | QT_BEGIN_NAMESPACE | - |
47 | | - |
48 | class QColormapPrivate | - |
49 | { | - |
50 | public: | - |
51 | inline QColormapPrivate() | - |
52 | : ref(1), mode(QColormap::Direct), depth(0), numcolors(0) | - |
53 | { } | - |
54 | | - |
55 | QAtomicInt ref; | - |
56 | | - |
57 | QColormap::Mode mode; | - |
58 | int depth; | - |
59 | int numcolors; | - |
60 | }; | - |
61 | | - |
62 | static QColormapPrivate *screenMap = 0; | - |
63 | | - |
64 | void QColormap::initialize() | - |
65 | { | - |
66 | screenMap = new QColormapPrivate; | - |
67 | if (Q_UNLIKELY(!QGuiApplication::primaryScreen())())) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
68 | qWarning("no screens available, assuming 24-bit color"); | - |
69 | screenMap->depth = 24; | - |
70 | screenMap->mode = QColormap::Direct; | - |
71 | return; never executed: return; | 0 |
72 | } | - |
73 | screenMap->depth = QGuiApplication::primaryScreen()->depth(); | - |
74 | if (screenMap->depth < 8) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
75 | screenMap->mode = QColormap::Indexed; | - |
76 | screenMap->numcolors = 256; | - |
77 | } else { never executed: end of block | 0 |
78 | screenMap->mode = QColormap::Direct; | - |
79 | screenMap->numcolors = -1; | - |
80 | } never executed: end of block | 0 |
81 | } | - |
82 | | - |
83 | void QColormap::cleanup() | - |
84 | { | - |
85 | delete screenMap; | - |
86 | screenMap = 0; | - |
87 | } | - |
88 | | - |
89 | QColormap QColormap::instance(int ) | - |
90 | { | - |
91 | return QColormap(); | - |
92 | } | - |
93 | | - |
94 | QColormap::QColormap() | - |
95 | : d(screenMap) | - |
96 | { d->ref.ref(); } | - |
97 | | - |
98 | QColormap::QColormap(const QColormap &colormap) | - |
99 | :d (colormap.d) | - |
100 | { d->ref.ref(); } | - |
101 | | - |
102 | QColormap::~QColormap() | - |
103 | { | - |
104 | if (!d->ref.deref()) | - |
105 | delete d; | - |
106 | } | - |
107 | | - |
108 | QColormap::Mode QColormap::mode() const | - |
109 | { return d->mode; } | - |
110 | | - |
111 | | - |
112 | int QColormap::depth() const | - |
113 | { return d->depth; } | - |
114 | | - |
115 | | - |
116 | int QColormap::size() const | - |
117 | { | - |
118 | return d->numcolors; | - |
119 | } | - |
120 | | - |
121 | #ifndef QT_QWS_DEPTH16_RGB | - |
122 | #define QT_QWS_DEPTH16_RGB 565 | - |
123 | #endif | - |
124 | static const int qt_rbits = (QT_QWS_DEPTH16_RGB/100); | - |
125 | static const int qt_gbits = (QT_QWS_DEPTH16_RGB/10%10); | - |
126 | static const int qt_bbits = (QT_QWS_DEPTH16_RGB%10); | - |
127 | static const int qt_red_shift = qt_bbits+qt_gbits-(8-qt_rbits); | - |
128 | static const int qt_green_shift = qt_bbits-(8-qt_gbits); | - |
129 | static const int qt_neg_blue_shift = 8-qt_bbits; | - |
130 | static const int qt_blue_mask = (1<<qt_bbits)-1; | - |
131 | static const int qt_green_mask = (1<<(qt_gbits+qt_bbits))-(1<<qt_bbits); | - |
132 | static const int qt_red_mask = (1<<(qt_rbits+qt_gbits+qt_bbits))-(1<<(qt_gbits+qt_bbits)); | - |
133 | | - |
134 | static const int qt_red_rounding_shift = qt_red_shift + qt_rbits; | - |
135 | static const int qt_green_rounding_shift = qt_green_shift + qt_gbits; | - |
136 | static const int qt_blue_rounding_shift = qt_bbits - qt_neg_blue_shift; | - |
137 | | - |
138 | inline ushort qt_convRgbTo16(QRgb c) | - |
139 | { | - |
140 | const int tr = qRed(c) << qt_red_shift; | - |
141 | const int tg = qGreen(c) << qt_green_shift; | - |
142 | const int tb = qBlue(c) >> qt_neg_blue_shift; | - |
143 | | - |
144 | return (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask); | - |
145 | } | - |
146 | | - |
147 | inline QRgb qt_conv16ToRgb(ushort c) | - |
148 | { | - |
149 | const int r=(c & qt_red_mask); | - |
150 | const int g=(c & qt_green_mask); | - |
151 | const int b=(c & qt_blue_mask); | - |
152 | const int tr = r >> qt_red_shift | r >> qt_red_rounding_shift; | - |
153 | const int tg = g >> qt_green_shift | g >> qt_green_rounding_shift; | - |
154 | const int tb = b << qt_neg_blue_shift | b >> qt_blue_rounding_shift; | - |
155 | | - |
156 | return qRgb(tr,tg,tb); | - |
157 | } | - |
158 | | - |
159 | uint QColormap::pixel(const QColor &color) const | - |
160 | { | - |
161 | QRgb rgb = color.rgba(); | - |
162 | if (d->mode == QColormap::Direct) { | - |
163 | switch(d->depth) { | - |
164 | case 16: | - |
165 | return qt_convRgbTo16(rgb); | - |
166 | case 24: | - |
167 | case 32: | - |
168 | { | - |
169 | const int r = qRed(rgb); | - |
170 | const int g = qGreen(rgb); | - |
171 | const int b = qBlue(rgb); | - |
172 | const int red_shift = 16; | - |
173 | const int green_shift = 8; | - |
174 | const int red_mask = 0xff0000; | - |
175 | const int green_mask = 0x00ff00; | - |
176 | const int blue_mask = 0x0000ff; | - |
177 | const int tg = g << green_shift; | - |
178 | #ifdef QT_QWS_DEPTH_32_BGR | - |
179 | if (qt_screen->pixelType() == QScreen::BGRPixel) { | - |
180 | const int tb = b << red_shift; | - |
181 | return 0xff000000 | (r & blue_mask) | (tg & green_mask) | (tb & red_mask); | - |
182 | } | - |
183 | #endif | - |
184 | const int tr = r << red_shift; | - |
185 | return 0xff000000 | (b & blue_mask) | (tg & green_mask) | (tr & red_mask); | - |
186 | } | - |
187 | } | - |
188 | } | - |
189 | | - |
190 | | - |
191 | return 0; | - |
192 | } | - |
193 | | - |
194 | const QColor QColormap::colorAt(uint pixel) const | - |
195 | { | - |
196 | if (d->mode == Direct) { | - |
197 | if (d->depth == 16) { | - |
198 | pixel = qt_conv16ToRgb(pixel); | - |
199 | } | - |
200 | const int red_shift = 16; | - |
201 | const int green_shift = 8; | - |
202 | const int red_mask = 0xff0000; | - |
203 | const int green_mask = 0x00ff00; | - |
204 | const int blue_mask = 0x0000ff; | - |
205 | #ifdef QT_QWS_DEPTH_32_BGR | - |
206 | if (qt_screen->pixelType() == QScreen::BGRPixel) { | - |
207 | return QColor((pixel & blue_mask), | - |
208 | (pixel & green_mask) >> green_shift, | - |
209 | (pixel & red_mask) >> red_shift); | - |
210 | } | - |
211 | #endif | - |
212 | return QColor((pixel & red_mask) >> red_shift, | - |
213 | (pixel & green_mask) >> green_shift, | - |
214 | (pixel & blue_mask)); | - |
215 | } | - |
216 | #if 0 // XXX | - |
217 | Q_ASSERT_X(int(pixel) < qt_screen->numCols(), "QColormap::colorAt", "pixel out of bounds of palette"); | - |
218 | return QColor(qt_screen->clut()[pixel]); | - |
219 | #endif | - |
220 | return QColor(); | - |
221 | } | - |
222 | | - |
223 | const QVector<QColor> QColormap::colormap() const | - |
224 | { | - |
225 | return QVector<QColor>(); | - |
226 | } | - |
227 | | - |
228 | QColormap &QColormap::operator=(const QColormap &colormap) | - |
229 | { qAtomicAssign(d, colormap.d); return *this; } | - |
230 | | - |
231 | QT_END_NAMESPACE | - |
| | |