4#include <QVarLengthArray>
6#include <private/qguiapplication_p.h>
62 const int b =
i *
i *
i;
86 if (visual_class != -1) {
87 rvi.c_class = visual_class;
88 mask |= VisualClassMask;
90 if (visual_id != -1) {
91 rvi.visualid = visual_id;
96 *defaultVisual =
true;
106 if (best >= 0 && best <=
count && vi[best].visualid != XVisualIDFromVisual(visual)) {
107 visual = vi[best].visual;
109 *
depth = vi[best].depth;
122 int q_colors = (((1u <<
d->depth) > 256u) ? 256u : (1u <<
d->depth));
124 memset(queried, 0,
sizeof(queried));
125 for (
int x = 0;
x < q_colors; ++
x)
126 queried[
x].pixel =
x;
127 XQueryColors(
display,
d->colormap, queried, q_colors);
129 d->colors.resize(q_colors);
130 for (
int x = 0;
x < q_colors; ++
x) {
131 if (queried[
x].
red == 0
133 && queried[
x].
blue == 0
140 queried[
x].
green /
float(USHRT_MAX),
141 queried[
x].
blue /
float(USHRT_MAX));
146 for (
int x = 0;
x <
d->pixels.size(); ++
x) {
147 if (
d->pixels.at(
x) != -1)
152 const int r = (
x / (
d->g_max *
d->b_max)) %
d->r_max;
153 const int g = (
x /
d->b_max) %
d->g_max;
154 const int b =
x %
d->b_max;
155 rgb =
qRgb((
r * 0xff + (
d->r_max - 1) / 2) / (
d->r_max - 1),
156 (
g * 0xff + (
d->g_max - 1) / 2) / (
d->g_max - 1),
157 (
b * 0xff + (
d->b_max - 1) / 2) / (
d->b_max - 1));
163 int mindist = INT_MAX, best = -1;
164 for (
int y = 0;
y < q_colors; ++
y) {
165 int r =
qRed(
rgb) - (queried[
y].red >> 8);
169 if (
dist < mindist) {
175 Q_ASSERT(best >= 0 && best < q_colors);
176 if (
d->visual->c_class & 1) {
178 xcolor.red = queried[best].red;
179 xcolor.green = queried[best].green;
180 xcolor.blue = queried[best].blue;
181 xcolor.pixel = queried[best].pixel;
183 if (XAllocColor(
display,
d->colormap, &xcolor)) {
184 d->pixels[
x] = xcolor.pixel;
199 d->pixels.resize(
d->r_max);
201 for (
int g = 0;
g <
d->g_max; ++
g) {
202 const int gray = (
g * 0xff + (
d->r_max - 1) / 2) / (
d->r_max - 1);
207 if (
d->visual->c_class & 1) {
209 xcolor.red =
qRed(
rgb) * 0x101;
214 if (XAllocColor(
X11->display,
d->colormap, &xcolor))
215 d->pixels[
g] = xcolor.pixel;
224 d->pixels.resize(
d->r_max *
d->g_max *
d->b_max);
227 for (
int x = 0,
r = 0;
r <
d->r_max; ++
r) {
228 for (
int g = 0;
g <
d->g_max; ++
g) {
229 for (
int b = 0;
b <
d->b_max; ++
b, ++
x) {
230 const QRgb rgb =
qRgb((
r * 0xff + (
d->r_max - 1) / 2) / (
d->r_max - 1),
231 (
g * 0xff + (
d->g_max - 1) / 2) / (
d->g_max - 1),
232 (
b * 0xff + (
d->b_max - 1) / 2) / (
d->b_max - 1));
236 if (
d->visual->c_class & 1) {
238 xcolor.red =
qRed(
rgb) * 0x101;
243 if (XAllocColor(
X11->display,
d->colormap, &xcolor))
244 d->pixels[
x] = xcolor.pixel;
255 if (
d->visual->c_class != DirectColor || !ownColormap)
263 for (
int r = 0;
r <
d->r_max; ++
r) {
264 colorTable[
i].red =
r << 8 |
r;
265 colorTable[
i].pixel =
r <<
d->r_shift;
266 colorTable[
i].flags = DoRed;
270 for (
int g = 0;
g <
d->g_max; ++
g) {
271 colorTable[
i].green =
g << 8 |
g;
272 colorTable[
i].pixel =
g <<
d->g_shift;
273 colorTable[
i].flags = DoGreen;
277 for (
int b = 0;
b <
d->b_max; ++
b) {
278 colorTable[
i].blue = (
b << 8 |
b);
279 colorTable[
i].pixel =
b <<
d->b_shift;
280 colorTable[
i].flags = DoBlue;
284 XStoreColors(
X11->display,
d->colormap, colorTable.
data(), colorTable.
count());
292 const int screens = ScreenCount(
display);
296 for (
int i = 0;
i < screens; ++
i) {
300 bool use_stdcmap =
false;
301 int color_count =
X11->color_count;
305 d->colormap = DefaultColormap(
display,
i);
306 d->defaultColormap =
true;
308 d->defaultVisual =
true;
310 Visual *argbVisual =
nullptr;
315 XVisualIDFromVisual(
X11->visual),
316 &
d->depth, &
d->defaultVisual);
317 }
else if ((
X11->visual_class != -1 &&
X11->visual_class >= 0 &&
X11->visual_class < 6)
318 || (
X11->visual_id != -1)) {
321 &
d->depth, &
d->defaultVisual);
322 }
else if (!
X11->custom_cmap) {
323 XStandardColormap *stdcmap =
nullptr;
326#if QT_CONFIG(xrender)
327 if (
X11->use_xrender) {
332 templ.c_class = TrueColor;
333 XVisualInfo *xvi = XGetVisualInfo(
X11->display, VisualScreenMask |
335 VisualClassMask, &templ, &nvi);
336 for (
int idx = 0; idx < nvi; ++idx) {
337 XRenderPictFormat *
format = XRenderFindVisualFormat(
X11->display,
339 if (
format->type == PictTypeDirect &&
format->direct.alphaMask) {
340 argbVisual = xvi[idx].visual;
348 &stdcmap, &ncmaps, XA_RGB_DEFAULT_MAP)) {
350 for (
int c = 0;
c < ncmaps; ++
c) {
351 if (!stdcmap[
c].red_max ||
352 !stdcmap[
c].green_max ||
353 !stdcmap[
c].blue_max ||
354 !stdcmap[
c].red_mult ||
355 !stdcmap[
c].green_mult ||
356 !stdcmap[
c].blue_mult)
360 proto.visualid = stdcmap[
c].visualid;
364 XVisualInfo *vi = XGetVisualInfo(
display, VisualIDMask | VisualScreenMask,
370 d->mode = ((vi[0].visual->c_class < StaticColor)
372 : ((vi[0].visual->c_class < TrueColor)
376 d->depth = vi[0].depth;
377 d->colormap = stdcmap[
c].colormap;
378 d->defaultColormap =
true;
379 d->visual = vi[0].visual;
380 d->defaultVisual = (
d->visual == DefaultVisual(
display,
i));
382 d->r_max = stdcmap[
c].red_max + 1;
383 d->g_max = stdcmap[
c].green_max + 1;
384 d->b_max = stdcmap[
c].blue_max + 1;
406 switch (
d->visual->c_class) {
410 d->r_max =
d->g_max =
d->b_max =
d->visual->map_entries;
417 if (color_count != 0)
418 d->r_max =
d->g_max =
d->b_max = color_count;
419 else if (
d->visual->map_entries > 65000)
420 d->r_max =
d->g_max =
d->b_max = 4096;
421 else if (
d->visual->map_entries > 4000)
422 d->r_max =
d->g_max =
d->b_max = 512;
423 else if (
d->visual->map_entries > 250)
424 d->r_max =
d->g_max =
d->b_max = 12;
426 d->r_max =
d->g_max =
d->b_max = 4;
441 if (color_count != 0)
442 d->r_max =
d->g_max =
d->b_max =
cube_root(color_count);
443 else if (
d->visual->map_entries > 65000)
444 d->r_max =
d->g_max =
d->b_max = 27;
445 else if (
d->visual->map_entries > 4000)
446 d->r_max =
d->g_max =
d->b_max = 12;
447 else if (
d->visual->map_entries > 250)
448 d->r_max =
d->g_max =
d->b_max =
cube_root(
d->visual->map_entries - 125);
450 d->r_max =
d->g_max =
d->b_max =
cube_root(
d->visual->map_entries);
468 bool ownColormap =
false;
469 if (
X11->colormap &&
i == DefaultScreen(
display)) {
471 d->colormap =
X11->colormap;
472 d->defaultColormap = (
d->colormap == DefaultColormap(
display,
i));
473 }
else if ((!use_stdcmap
474 && (((
d->visual->c_class & 1) &&
X11->custom_cmap)
475 ||
d->visual != DefaultVisual(
display,
i)))
476 ||
d->visual->c_class == DirectColor) {
480 d->visual->c_class == DirectColor ? AllocAll : AllocNone);
481 d->defaultColormap =
false;
500 screen->defaultVisual =
d->defaultVisual;
501 screen->colormap =
d->colormap;
502 screen->defaultColormap =
d->defaultColormap;
506 X11->argbVisuals[
i] = argbVisual;
507 X11->argbColormaps[
i] = XCreateColormap(
display, RootWindow(
display,
i), argbVisual, AllocNone);
523 const int screens = ScreenCount(
display);
525 for (
int i = 0;
i < screens; ++
i)
543QXcbColormap::QXcbColormap()
586 return d->
pixels.
at((
r * 30 +
g * 59 +
b * 11) / 100);
The QColor class provides colors based on RGB, HSV or CMYK values.
static QColor fromRgbF(float r, float g, float b, float a=1.0)
Static convenience function that returns a QColor constructed from the RGB color values,...
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
constexpr quint8 blue8() const
constexpr quint8 red8() const
constexpr quint8 green8() const
int depth
the color depth of the screen
const QList< QColor > colormap() const
static QXcbColormap instance(int screen=-1)
const QColor colorAt(uint pixel) const
QXcbColormap & operator=(const QXcbColormap &colormap)
uint pixel(const QColor &color) const
QXcbColormap(const QXcbColormap &colormap)
struct wl_display * display
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.
static void query_colormap(QXcbColormapPrivate *d, int screen)
static Visual * find_visual(Display *display, int screen, int visual_class, int visual_id, int *depth, bool *defaultVisual)
static void init_direct(QXcbColormapPrivate *d, bool ownColormap)
static void init_indexed(QXcbColormapPrivate *d, int screen)
static int cube_root(int v)
static uint right_align(uint v)
static QXcbColormap ** cmaps
static void init_gray(QXcbColormapPrivate *d, int screen)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLint GLenum GLsizei GLsizei GLsizei depth
GLenum GLenum GLsizei count
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint GLsizei GLsizei GLenum format
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
constexpr QRgb qRgb(int r, int g, int b)
constexpr int qRed(QRgb rgb)
constexpr int qGreen(QRgb rgb)
constexpr int qGray(int r, int g, int b)
constexpr int qBlue(QRgb rgb)
constexpr int lowest_bit(T v) noexcept
std::uniform_real_distribution dist(1, 2.5)
[2]