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

Generated by Squish Coco Non-Commercial