Qt 4.8
qcolormap_qws.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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_qws.h"
46 #include "qwsdisplay_qws.h"
47 
49 
50 class QColormapPrivate
51 {
52 public:
54  : ref(1), mode(QColormap::Direct), depth(0), numcolors(0)
55  { }
56 
58 
60  int depth;
61  int numcolors;
62 };
63 
65 
67 {
68  screenMap = new QColormapPrivate;
69 
70  screenMap->depth = QPaintDevice::qwsDisplay()->depth();
71  if (screenMap->depth < 8) {
72  screenMap->mode = QColormap::Indexed;
73  screenMap->numcolors = 256;
74  } else {
75  screenMap->mode = QColormap::Direct;
76  screenMap->numcolors = -1;
77  }
78 }
79 
80 void QColormap::cleanup()
81 {
82  delete screenMap;
83  screenMap = 0;
84 }
85 
86 QColormap QColormap::instance(int /*screen*/)
87 {
88  return QColormap();
89 }
90 
92  : d(screenMap)
93 { d->ref.ref(); }
94 
96  :d (colormap.d)
97 { d->ref.ref(); }
98 
100 {
101  if (!d->ref.deref())
102  delete d;
103 }
104 
106 { return d->mode; }
107 
108 
109 int QColormap::depth() const
110 { return d->depth; }
111 
112 
113 int QColormap::size() const
114 {
115  return d->numcolors;
116 }
117 
118 uint QColormap::pixel(const QColor &color) const
119 {
120  QRgb rgb = color.rgba();
121  if (d->mode == QColormap::Direct) {
122  switch(d->depth) {
123  case 16:
124  return qt_convRgbTo16(rgb);
125  case 24:
126  case 32:
127  {
128  const int r = qRed(rgb);
129  const int g = qGreen(rgb);
130  const int b = qBlue(rgb);
131  const int red_shift = 16;
132  const int green_shift = 8;
133  const int red_mask = 0xff0000;
134  const int green_mask = 0x00ff00;
135  const int blue_mask = 0x0000ff;
136  const int tg = g << green_shift;
137 #ifdef QT_QWS_DEPTH_32_BGR
139  const int tb = b << red_shift;
140  return 0xff000000 | (r & blue_mask) | (tg & green_mask) | (tb & red_mask);
141  }
142 #endif
143  const int tr = r << red_shift;
144  return 0xff000000 | (b & blue_mask) | (tg & green_mask) | (tr & red_mask);
145  }
146  }
147  }
148  return qt_screen->alloc(qRed(rgb), qGreen(rgb), qBlue(rgb));
149 }
150 
151 const QColor QColormap::colorAt(uint pixel) const
152 {
153  if (d->mode == Direct) {
154  if (d->depth == 16) {
155  pixel = qt_conv16ToRgb(pixel);
156  }
157  const int red_shift = 16;
158  const int green_shift = 8;
159  const int red_mask = 0xff0000;
160  const int green_mask = 0x00ff00;
161  const int blue_mask = 0x0000ff;
162 #ifdef QT_QWS_DEPTH_32_BGR
164  return QColor((pixel & blue_mask),
165  (pixel & green_mask) >> green_shift,
166  (pixel & red_mask) >> red_shift);
167  }
168 #endif
169  return QColor((pixel & red_mask) >> red_shift,
170  (pixel & green_mask) >> green_shift,
171  (pixel & blue_mask));
172  }
173  Q_ASSERT_X(int(pixel) < qt_screen->colorCount(), "QColormap::colorAt", "pixel out of bounds of palette");
174  return QColor(qt_screen->clut()[pixel]);
175 }
176 
178 {
179  return QVector<QColor>();
180 }
181 
182 QColormap &QColormap::operator=(const QColormap &colormap)
183 { qAtomicAssign(d, colormap.d); return *this; }
184 
Q_GUI_EXPORT QScreen * qt_screen
Definition: qscreen_qws.cpp:69
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
static QColormap instance(int screen=-1)
unsigned int QRgb
Definition: qrgb.h:53
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static QWSDisplay * qwsDisplay()
The QAtomicInt class provides platform-independent atomic operations on integers. ...
Definition: qatomic.h:55
int size() const
ushort qt_convRgbTo16(const int r, const int g, const int b)
Definition: qscreen_qws.h:86
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
Definition: qrgb.h:57
virtual int alloc(unsigned int, unsigned int, unsigned int)
Returns the index in the screen&#39;s palette which is the closest match to the given RGB value (red...
QColormap::Mode mode
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
PixelType pixelType() const
Returns the pixel storage format of the screen.
Definition: qscreen_qws.h:231
const QColor colorAt(uint pixel) const
int depth() const
QColormapPrivate * d
Definition: qcolormap.h:90
unsigned int uint
Definition: qglobal.h:996
QColormap & operator=(const QColormap &colormap)
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
Definition: qrgb.h:63
uint pixel(const QColor &color) const
QRgb qt_conv16ToRgb(ushort c)
Definition: qscreen_qws.h:104
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
int depth() const
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
int colorCount()
Returns the number of entries in the screen&#39;s color lookup table (i.
Definition: qscreen_qws.h:249
const QVector< QColor > colormap() const
static void initialize()
QRgb * clut()
Returns a pointer to the screen&#39;s color lookup table (i.
Definition: qscreen_qws.h:245
void qAtomicAssign(T *&d, T *x)
This is a helper for the assignment operators of implicitly shared classes.
Definition: qatomic.h:195
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
Definition: qrgb.h:60
Mode mode() const
QColormap()
Constructs a new colormap.
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
static QColormapPrivate * screenMap
static void cleanup()