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) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://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 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qcolormap.h"-
35#include "qcolor.h"-
36#include "qpaintdevice.h"-
37#include "qscreen.h"-
38#include "qguiapplication.h"-
39-
40QT_BEGIN_NAMESPACE-
41-
42class QColormapPrivate-
43{-
44public:-
45 inline QColormapPrivate()-
46 : ref(1), mode(QColormap::Direct), depth(0), numcolors(0)-
47 { }
never executed: end of block
0
48-
49 QAtomicInt ref;-
50-
51 QColormap::Mode mode;-
52 int depth;-
53 int numcolors;-
54};-
55-
56static QColormapPrivate *screenMap = 0;-
57-
58void QColormap::initialize()-
59{-
60 screenMap = new QColormapPrivate;-
61 if (!QGuiApplication::primaryScreen()) {
!QGuiApplicati...rimaryScreen()Description
TRUEnever evaluated
FALSEnever evaluated
0
62 qWarning("no screens available, assuming 24-bit color");-
63 screenMap->depth = 24;-
64 screenMap->mode = QColormap::Direct;-
65 return;
never executed: return;
0
66 }-
67 screenMap->depth = QGuiApplication::primaryScreen()->depth();-
68 if (screenMap->depth < 8) {
screenMap->depth < 8Description
TRUEnever evaluated
FALSEnever evaluated
0
69 screenMap->mode = QColormap::Indexed;-
70 screenMap->numcolors = 256;-
71 } else {
never executed: end of block
0
72 screenMap->mode = QColormap::Direct;-
73 screenMap->numcolors = -1;-
74 }
never executed: end of block
0
75}-
76-
77void QColormap::cleanup()-
78{-
79 delete screenMap;-
80 screenMap = 0;-
81}
never executed: end of block
0
82-
83QColormap QColormap::instance(int /*screen*/)-
84{-
85 return QColormap();
never executed: return QColormap();
0
86}-
87-
88QColormap::QColormap()-
89 : d(screenMap)-
90{
never executed: end of block
d->ref.ref(); }
never executed: end of block
0
91-
92QColormap::QColormap(const QColormap &colormap)-
93 :d (colormap.d)-
94{
never executed: end of block
d->ref.ref(); }
never executed: end of block
0
95-
96QColormap::~QColormap()-
97{-
98 if (!d->ref.deref())
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0
99 delete d;
never executed: delete d;
0
100}
never executed: end of block
0
101-
102QColormap::Mode QColormap::mode() const-
103{
never executed: return d->mode;
return d->mode; }
never executed: return d->mode;
0
104-
105-
106int QColormap::depth() const-
107{
never executed: return d->depth;
return d->depth; }
never executed: return d->depth;
0
108-
109-
110int QColormap::size() const-
111{-
112 return d->numcolors;
never executed: return d->numcolors;
0
113}-
114-
115#ifndef QT_QWS_DEPTH16_RGB-
116#define QT_QWS_DEPTH16_RGB 565-
117#endif-
118static const int qt_rbits = (QT_QWS_DEPTH16_RGB/100);-
119static const int qt_gbits = (QT_QWS_DEPTH16_RGB/10%10);-
120static const int qt_bbits = (QT_QWS_DEPTH16_RGB%10);-
121static const int qt_red_shift = qt_bbits+qt_gbits-(8-qt_rbits);-
122static const int qt_green_shift = qt_bbits-(8-qt_gbits);-
123static const int qt_neg_blue_shift = 8-qt_bbits;-
124static const int qt_blue_mask = (1<<qt_bbits)-1;-
125static const int qt_green_mask = (1<<(qt_gbits+qt_bbits))-(1<<qt_bbits);-
126static const int qt_red_mask = (1<<(qt_rbits+qt_gbits+qt_bbits))-(1<<(qt_gbits+qt_bbits));-
127-
128static const int qt_red_rounding_shift = qt_red_shift + qt_rbits;-
129static const int qt_green_rounding_shift = qt_green_shift + qt_gbits;-
130static const int qt_blue_rounding_shift = qt_bbits - qt_neg_blue_shift;-
131-
132inline ushort qt_convRgbTo16(QRgb c)-
133{-
134 const int tr = qRed(c) << qt_red_shift;-
135 const int tg = qGreen(c) << qt_green_shift;-
136 const int tb = qBlue(c) >> qt_neg_blue_shift;-
137-
138 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
139}-
140-
141inline QRgb qt_conv16ToRgb(ushort c)-
142{-
143 const int r=(c & qt_red_mask);-
144 const int g=(c & qt_green_mask);-
145 const int b=(c & qt_blue_mask);-
146 const int tr = r >> qt_red_shift | r >> qt_red_rounding_shift;-
147 const int tg = g >> qt_green_shift | g >> qt_green_rounding_shift;-
148 const int tb = b << qt_neg_blue_shift | b >> qt_blue_rounding_shift;-
149-
150 return qRgb(tr,tg,tb);
never executed: return qRgb(tr,tg,tb);
0
151}-
152-
153uint QColormap::pixel(const QColor &color) const-
154{-
155 QRgb rgb = color.rgba();-
156 if (d->mode == QColormap::Direct) {
d->mode == QColormap::DirectDescription
TRUEnever evaluated
FALSEnever evaluated
0
157 switch(d->depth) {-
158 case 16:
never executed: case 16:
0
159 return qt_convRgbTo16(rgb);
never executed: return qt_convRgbTo16(rgb);
0
160 case 24:
never executed: case 24:
0
161 case 32:
never executed: case 32:
0
162 {-
163 const int r = qRed(rgb);-
164 const int g = qGreen(rgb);-
165 const int b = qBlue(rgb);-
166 const int red_shift = 16;-
167 const int green_shift = 8;-
168 const int red_mask = 0xff0000;-
169 const int green_mask = 0x00ff00;-
170 const int blue_mask = 0x0000ff;-
171 const int tg = g << green_shift;-
172#ifdef QT_QWS_DEPTH_32_BGR-
173 if (qt_screen->pixelType() == QScreen::BGRPixel) {-
174 const int tb = b << red_shift;-
175 return 0xff000000 | (r & blue_mask) | (tg & green_mask) | (tb & red_mask);-
176 }-
177#endif-
178 const int tr = r << red_shift;-
179 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
180 }-
181 }-
182 }
never executed: end of block
0
183 //XXX-
184 //return qt_screen->alloc(qRed(rgb), qGreen(rgb), qBlue(rgb));-
185 return 0;
never executed: return 0;
0
186}-
187-
188const QColor QColormap::colorAt(uint pixel) const-
189{-
190 if (d->mode == Direct) {
d->mode == DirectDescription
TRUEnever evaluated
FALSEnever evaluated
0
191 if (d->depth == 16) {
d->depth == 16Description
TRUEnever evaluated
FALSEnever evaluated
0
192 pixel = qt_conv16ToRgb(pixel);-
193 }
never executed: end of block
0
194 const int red_shift = 16;-
195 const int green_shift = 8;-
196 const int red_mask = 0xff0000;-
197 const int green_mask = 0x00ff00;-
198 const int blue_mask = 0x0000ff;-
199#ifdef QT_QWS_DEPTH_32_BGR-
200 if (qt_screen->pixelType() == QScreen::BGRPixel) {-
201 return QColor((pixel & blue_mask),-
202 (pixel & green_mask) >> green_shift,-
203 (pixel & red_mask) >> red_shift);-
204 }-
205#endif-
206 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
207 (pixel & green_mask) >> green_shift,
never executed: return QColor((pixel & red_mask) >> red_shift, (pixel & green_mask) >> green_shift, (pixel & blue_mask));
0
208 (pixel & blue_mask));
never executed: return QColor((pixel & red_mask) >> red_shift, (pixel & green_mask) >> green_shift, (pixel & blue_mask));
0
209 }-
210#if 0 // XXX-
211 Q_ASSERT_X(int(pixel) < qt_screen->numCols(), "QColormap::colorAt", "pixel out of bounds of palette");-
212 return QColor(qt_screen->clut()[pixel]);-
213#endif-
214 return QColor();
never executed: return QColor();
0
215}-
216-
217const QVector<QColor> QColormap::colormap() const-
218{-
219 return QVector<QColor>();
never executed: return QVector<QColor>();
0
220}-
221-
222QColormap &QColormap::operator=(const QColormap &colormap)-
223{
never executed: return *this;
qAtomicAssign(d, colormap.d); return *this; }
never executed: return *this;
0
224-
225QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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