OpenCoverage

qcolormap.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/util/qcolormap.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets 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 The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qcolormap.h"-
41#include "qcolor.h"-
42#include "qpaintdevice.h"-
43#include "qscreen.h"-
44#include "qguiapplication.h"-
45-
46QT_BEGIN_NAMESPACE-
47-
48class QColormapPrivate-
49{-
50public:-
51 inline QColormapPrivate()-
52 : ref(1), mode(QColormap::Direct), depth(0), numcolors(0)-
53 { }
never executed: end of block
0
54-
55 QAtomicInt ref;-
56-
57 QColormap::Mode mode;-
58 int depth;-
59 int numcolors;-
60};-
61-
62static QColormapPrivate *screenMap = 0;-
63-
64void QColormap::initialize()-
65{-
66 screenMap = new QColormapPrivate;-
67 if (Q_UNLIKELY(!QGuiApplication::primaryScreen())) {
__builtin_expe...een()), false)Description
TRUEnever evaluated
FALSEnever 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) {
screenMap->depth < 8Description
TRUEnever evaluated
FALSEnever 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-
83void QColormap::cleanup()-
84{-
85 delete screenMap;-
86 screenMap = 0;-
87}
never executed: end of block
0
88-
89QColormap QColormap::instance(int /*screen*/)-
90{-
91 return QColormap();
never executed: return QColormap();
0
92}-
93-
94QColormap::QColormap()-
95 : d(screenMap)-
96{
never executed: end of block
d->ref.ref(); }
never executed: end of block
0
97-
98QColormap::QColormap(const QColormap &colormap)-
99 :d (colormap.d)-
100{
never executed: end of block
d->ref.ref(); }
never executed: end of block
0
101-
102QColormap::~QColormap()-
103{-
104 if (!d->ref.deref())
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0
105 delete d;
never executed: delete d;
0
106}
never executed: end of block
0
107-
108QColormap::Mode QColormap::mode() const-
109{
never executed: return d->mode;
return d->mode; }
never executed: return d->mode;
0
110-
111-
112int QColormap::depth() const-
113{
never executed: return d->depth;
return d->depth; }
never executed: return d->depth;
0
114-
115-
116int QColormap::size() const-
117{-
118 return d->numcolors;
never executed: return d->numcolors;
0
119}-
120-
121#ifndef QT_QWS_DEPTH16_RGB-
122#define QT_QWS_DEPTH16_RGB 565-
123#endif-
124static const int qt_rbits = (QT_QWS_DEPTH16_RGB/100);-
125static const int qt_gbits = (QT_QWS_DEPTH16_RGB/10%10);-
126static const int qt_bbits = (QT_QWS_DEPTH16_RGB%10);-
127static const int qt_red_shift = qt_bbits+qt_gbits-(8-qt_rbits);-
128static const int qt_green_shift = qt_bbits-(8-qt_gbits);-
129static const int qt_neg_blue_shift = 8-qt_bbits;-
130static const int qt_blue_mask = (1<<qt_bbits)-1;-
131static const int qt_green_mask = (1<<(qt_gbits+qt_bbits))-(1<<qt_bbits);-
132static const int qt_red_mask = (1<<(qt_rbits+qt_gbits+qt_bbits))-(1<<(qt_gbits+qt_bbits));-
133-
134static const int qt_red_rounding_shift = qt_red_shift + qt_rbits;-
135static const int qt_green_rounding_shift = qt_green_shift + qt_gbits;-
136static const int qt_blue_rounding_shift = qt_bbits - qt_neg_blue_shift;-
137-
138inline 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);
never executed: return (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask);
0
145}-
146-
147inline 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);
never executed: return qRgb(tr,tg,tb);
0
157}-
158-
159uint QColormap::pixel(const QColor &color) const-
160{-
161 QRgb rgb = color.rgba();-
162 if (d->mode == QColormap::Direct) {
d->mode == QColormap::DirectDescription
TRUEnever evaluated
FALSEnever evaluated
0
163 switch(d->depth) {-
164 case 16:
never executed: case 16:
0
165 return qt_convRgbTo16(rgb);
never executed: return qt_convRgbTo16(rgb);
0
166 case 24:
never executed: case 24:
0
167 case 32:
never executed: case 32:
0
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);
never executed: return 0xff000000 | (b & blue_mask) | (tg & green_mask) | (tr & red_mask);
0
186 }-
187 }-
188 }
never executed: end of block
0
189 //XXX-
190 //return qt_screen->alloc(qRed(rgb), qGreen(rgb), qBlue(rgb));-
191 return 0;
never executed: return 0;
0
192}-
193-
194const QColor QColormap::colorAt(uint pixel) const-
195{-
196 if (d->mode == Direct) {
d->mode == DirectDescription
TRUEnever evaluated
FALSEnever evaluated
0
197 if (d->depth == 16) {
d->depth == 16Description
TRUEnever evaluated
FALSEnever evaluated
0
198 pixel = qt_conv16ToRgb(pixel);-
199 }
never executed: end of block
0
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,
never executed: return QColor((pixel & red_mask) >> red_shift, (pixel & green_mask) >> green_shift, (pixel & blue_mask));
0
213 (pixel & green_mask) >> green_shift,
never executed: return QColor((pixel & red_mask) >> red_shift, (pixel & green_mask) >> green_shift, (pixel & blue_mask));
0
214 (pixel & blue_mask));
never executed: return QColor((pixel & red_mask) >> red_shift, (pixel & green_mask) >> green_shift, (pixel & blue_mask));
0
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();
never executed: return QColor();
0
221}-
222-
223const QVector<QColor> QColormap::colormap() const-
224{-
225 return QVector<QColor>();
never executed: return QVector<QColor>();
0
226}-
227-
228QColormap &QColormap::operator=(const QColormap &colormap)-
229{
never executed: return *this;
qAtomicAssign(d, colormap.d); return *this; }
never executed: return *this;
0
230-
231QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9