Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qcolormap.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qcolormap.h"
5#include "qcolor.h"
6#include "qpaintdevice.h"
7#include "qscreen.h"
8#include "qguiapplication.h"
9
11
13{
14public:
16 : ref(1), mode(QColormap::Direct), depth(0), numcolors(0)
17 { }
18
20
22 int depth;
24};
25
26static QColormapPrivate *screenMap = nullptr;
27
29{
32 qWarning("no screens available, assuming 24-bit color");
33 screenMap->depth = 24;
35 return;
36 }
38 if (screenMap->depth < 8) {
40 screenMap->numcolors = 256;
41 } else {
43 screenMap->numcolors = -1;
44 }
45}
46
48{
49 delete screenMap;
50 screenMap = nullptr;
51}
52
54{
55 return QColormap();
56}
57
58QColormap::QColormap()
59 : d(screenMap)
60{ d->ref.ref(); }
61
63 :d (colormap.d)
64{ d->ref.ref(); }
65
67{
68 if (!d->ref.deref())
69 delete d;
70}
71
73{ return d->mode; }
74
75
77{ return d->depth; }
78
79
80int QColormap::size() const
81{
82 return d->numcolors;
83}
84
85#ifndef QT_QWS_DEPTH16_RGB
86#define QT_QWS_DEPTH16_RGB 565
87#endif
88static const int qt_rbits = (QT_QWS_DEPTH16_RGB/100);
89static const int qt_gbits = (QT_QWS_DEPTH16_RGB/10%10);
90static const int qt_bbits = (QT_QWS_DEPTH16_RGB%10);
91static const int qt_red_shift = qt_bbits+qt_gbits-(8-qt_rbits);
92static const int qt_green_shift = qt_bbits-(8-qt_gbits);
93static const int qt_neg_blue_shift = 8-qt_bbits;
94static const int qt_blue_mask = (1<<qt_bbits)-1;
95static const int qt_green_mask = (1<<(qt_gbits+qt_bbits))-(1<<qt_bbits);
96static const int qt_red_mask = (1<<(qt_rbits+qt_gbits+qt_bbits))-(1<<(qt_gbits+qt_bbits));
97
101
103{
104 const int tr = qRed(c) << qt_red_shift;
105 const int tg = qGreen(c) << qt_green_shift;
106 const int tb = qBlue(c) >> qt_neg_blue_shift;
107
108 return (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask);
109}
110
112{
113 const int r=(c & qt_red_mask);
114 const int g=(c & qt_green_mask);
115 const int b=(c & qt_blue_mask);
116 const int tr = r >> qt_red_shift | r >> qt_red_rounding_shift;
117 const int tg = g >> qt_green_shift | g >> qt_green_rounding_shift;
118 const int tb = b << qt_neg_blue_shift | b >> qt_blue_rounding_shift;
119
120 return qRgb(tr,tg,tb);
121}
122
124{
125 QRgb rgb = color.rgba();
126 if (d->mode == QColormap::Direct) {
127 switch(d->depth) {
128 case 16:
129 return qt_convRgbTo16(rgb);
130 case 24:
131 case 32:
132 {
133 const int r = qRed(rgb);
134 const int g = qGreen(rgb);
135 const int b = qBlue(rgb);
136 const int red_shift = 16;
137 const int green_shift = 8;
138 const int red_mask = 0xff0000;
139 const int green_mask = 0x00ff00;
140 const int blue_mask = 0x0000ff;
141 const int tg = g << green_shift;
142 const int tr = r << red_shift;
143 return 0xff000000 | (b & blue_mask) | (tg & green_mask) | (tr & red_mask);
144 }
145 }
146 }
147 //XXX
148 //return qt_screen->alloc(qRed(rgb), qGreen(rgb), qBlue(rgb));
149 return 0;
150}
151
153{
154 if (d->mode == Direct) {
155 if (d->depth == 16) {
157 }
158 const int red_shift = 16;
159 const int green_shift = 8;
160 const int red_mask = 0xff0000;
161 const int green_mask = 0x00ff00;
162 const int blue_mask = 0x0000ff;
163 return QColor((pixel & red_mask) >> red_shift,
164 (pixel & green_mask) >> green_shift,
165 (pixel & blue_mask));
166 }
167#if 0 // XXX
168 Q_ASSERT_X(int(pixel) < qt_screen->numCols(), "QColormap::colorAt", "pixel out of bounds of palette");
169 return QColor(qt_screen->clut()[pixel]);
170#endif
171 return QColor();
172}
173
174const QList<QColor> QColormap::colormap() const
175{
176 return QList<QColor>();
177}
178
180{ qAtomicAssign(d, colormap.d); return *this; }
181
\inmodule QtCore
Definition qatomic.h:112
bool ref() noexcept
bool deref() noexcept
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
QAtomicInt ref
Definition qcolormap.cpp:19
QColormap::Mode mode
Definition qcolormap.cpp:21
Mode mode() const
Definition qcolormap.cpp:72
static void cleanup()
Definition qcolormap.cpp:47
static void initialize()
Definition qcolormap.cpp:28
QColormap & operator=(const QColormap &colormap)
QColormap(const QColormap &colormap)
Definition qcolormap.cpp:62
static QColormap instance(int screen=-1)
Definition qcolormap.cpp:53
int depth() const
Definition qcolormap.cpp:76
const QList< QColor > colormap() const
uint pixel(const QColor &color) const
int size() const
Definition qcolormap.cpp:80
const QColor colorAt(uint pixel) const
QScreen * primaryScreen
the primary (or default) screen of the application.
int depth
the color depth of the screen
Definition qscreen.h:40
Combined button and popup list for selecting options.
QT_WARNING_POP void qAtomicAssign(T *&d, T *x)
This is a helper for the assignment operators of implicitly shared classes.
Definition qatomic.h:180
#define rgb(r, g, b)
Definition qcolor.cpp:124
static const int qt_neg_blue_shift
Definition qcolormap.cpp:93
static const int qt_bbits
Definition qcolormap.cpp:90
static const int qt_green_mask
Definition qcolormap.cpp:95
ushort qt_convRgbTo16(QRgb c)
static const int qt_blue_rounding_shift
#define QT_QWS_DEPTH16_RGB
Definition qcolormap.cpp:86
QRgb qt_conv16ToRgb(ushort c)
static const int qt_green_rounding_shift
Definition qcolormap.cpp:99
static const int qt_red_shift
Definition qcolormap.cpp:91
static const int qt_green_shift
Definition qcolormap.cpp:92
static const int qt_gbits
Definition qcolormap.cpp:89
static QColormapPrivate * screenMap
Definition qcolormap.cpp:26
static const int qt_blue_mask
Definition qcolormap.cpp:94
static const int qt_red_rounding_shift
Definition qcolormap.cpp:98
static const int qt_red_mask
Definition qcolormap.cpp:96
static const int qt_rbits
Definition qcolormap.cpp:88
#define Q_UNLIKELY(x)
#define qWarning
Definition qlogging.h:166
GLboolean GLboolean GLboolean b
GLint GLenum GLsizei GLsizei GLsizei depth
GLenum mode
GLboolean r
[2]
GLuint color
[2]
GLboolean GLboolean g
GLint ref
const GLubyte * c
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
Definition qrgb.h:13
constexpr QRgb qRgb(int r, int g, int b)
Definition qrgb.h:30
constexpr int qRed(QRgb rgb)
Definition qrgb.h:18
constexpr int qGreen(QRgb rgb)
Definition qrgb.h:21
constexpr int qBlue(QRgb rgb)
Definition qrgb.h:24
#define tr(X)
unsigned int uint
Definition qtypes.h:34
unsigned short ushort
Definition qtypes.h:33