50 #include <private/qt_x11_p.h> 101 for (i = 0; ((v & b) == 0
u) && i < 32; ++i)
103 return i == 32 ? -1 : i;
113 const int b = i * i * i;
131 XVisualInfo *vi, rvi;
134 uint mask = VisualScreenMask;
137 if (visual_class != -1) {
138 rvi.c_class = visual_class;
139 mask |= VisualClassMask;
141 if (visual_id != -1) {
142 rvi.visualid = visual_id;
143 mask |= VisualIDMask;
146 Visual *
visual = DefaultVisual(display, screen);
147 *defaultVisual =
true;
148 *depth = DefaultDepth(display, screen);
150 vi = XGetVisualInfo(display, mask, &rvi, &count);
153 for (
int x = 0; x < count; ++x) {
154 if (vi[x].depth > vi[best].depth)
157 if (best >= 0 && best <= count && vi[best].visualid != XVisualIDFromVisual(visual)) {
158 visual = vi[best].visual;
159 *defaultVisual = (visual == DefaultVisual(display, screen));
160 *depth = vi[best].depth;
173 int q_colors = (((1
u << d->
depth) > 256
u) ? 256
u : (1
u << d->
depth));
175 memset(queried, 0,
sizeof(queried));
176 for (
int x = 0; x < q_colors; ++x)
177 queried[x].pixel = x;
178 XQueryColors(display, d->
colormap, queried, q_colors);
181 for (
int x = 0; x < q_colors; ++x) {
182 if (queried[x].
red == 0
183 && queried[x].
green == 0
184 && queried[x].
blue == 0
185 && queried[x].pixel != BlackPixel(display, screen)) {
191 queried[x].
green /
float(USHRT_MAX),
192 queried[x].
blue /
float(USHRT_MAX));
205 const int b = x % d->
b_max;
207 (g * 0xff + (d->
g_max - 1) / 2) / (d->
g_max - 1),
208 (b * 0xff + (d->
b_max - 1) / 2) / (d->
b_max - 1));
214 int mindist =
INT_MAX, best = -1;
215 for (
int y = 0; y < q_colors; ++y) {
216 int r =
qRed(rgb) - (queried[y].red >> 8);
217 int g =
qGreen(rgb) - (queried[y].green >> 8);
218 int b =
qBlue(rgb) - (queried[y].blue >> 8);
219 int dist = (r * r) + (g * g) + (b * b);
220 if (dist < mindist) {
226 Q_ASSERT(best >= 0 && best < q_colors);
227 if (d->
visual->c_class & 1) {
229 xcolor.red = queried[best].red;
230 xcolor.green = queried[best].green;
231 xcolor.blue = queried[best].blue;
232 xcolor.pixel = queried[best].pixel;
234 if (XAllocColor(display, d->
colormap, &xcolor)) {
235 d->
pixels[x] = xcolor.pixel;
239 ? BlackPixel(display, screen)
240 : WhitePixel(display, screen));
252 for (
int g = 0; g < d->
g_max; ++g) {
253 const int gray = (g * 0xff + (d->
r_max - 1) / 2) / (d->
r_max - 1);
258 if (d->
visual->c_class & 1) {
260 xcolor.red =
qRed(rgb) * 0x101;
261 xcolor.green =
qGreen(rgb) * 0x101;
262 xcolor.blue =
qBlue(rgb) * 0x101;
266 d->
pixels[g] = xcolor.pixel;
278 for (
int x = 0, r = 0; r < d->
r_max; ++r) {
279 for (
int g = 0; g < d->
g_max; ++g) {
280 for (
int b = 0; b < d->
b_max; ++b, ++x) {
282 (g * 0xff + (d->
g_max - 1) / 2) / (d->
g_max - 1),
283 (b * 0xff + (d->
b_max - 1) / 2) / (d->
b_max - 1));
287 if (d->
visual->c_class & 1) {
289 xcolor.red =
qRed(rgb) * 0x101;
290 xcolor.green =
qGreen(rgb) * 0x101;
291 xcolor.blue =
qBlue(rgb) * 0x101;
295 d->
pixels[x] = xcolor.pixel;
306 if (d->
visual->c_class != DirectColor || !ownColormap)
314 for (
int r = 0; r < d->
r_max; ++r) {
315 colorTable[i].red = r << 8 | r;
316 colorTable[i].pixel = r << d->
r_shift;
317 colorTable[i].flags = DoRed;
321 for (
int g = 0; g < d->
g_max; ++g) {
322 colorTable[i].green = g << 8 | g;
323 colorTable[i].pixel = g << d->
g_shift;
324 colorTable[i].flags = DoGreen;
328 for (
int b = 0; b < d->
b_max; ++b) {
329 colorTable[i].blue = (b << 8 | b);
330 colorTable[i].pixel = b << d->
b_shift;
331 colorTable[i].flags = DoBlue;
343 const int screens = ScreenCount(display);
347 for (
int i = 0; i < screens; ++i) {
351 bool use_stdcmap =
false;
352 int color_count =
X11->color_count;
355 d->
depth = DefaultDepth(display, i);
356 d->
colormap = DefaultColormap(display, i);
358 d->
visual = DefaultVisual(display, i);
361 Visual *argbVisual = 0;
363 if (
X11->visual && i == DefaultScreen(display)) {
366 XVisualIDFromVisual(
X11->visual),
368 }
else if ((
X11->visual_class != -1 &&
X11->visual_class >= 0 &&
X11->visual_class < 6)
369 || (
X11->visual_id != -1)) {
377 d->
visual = DefaultVisual(display, i);
381 }
else if (!
X11->custom_cmap) {
382 XStandardColormap *stdcmap = 0;
385 #ifndef QT_NO_XRENDER 386 if (
X11->use_xrender) {
391 templ.c_class = TrueColor;
392 XVisualInfo *xvi = XGetVisualInfo(
X11->display, VisualScreenMask |
394 VisualClassMask, &templ, &nvi);
395 for (
int idx = 0; idx < nvi; ++idx) {
396 XRenderPictFormat *
format = XRenderFindVisualFormat(
X11->display,
398 if (format->type == PictTypeDirect && format->direct.alphaMask) {
399 argbVisual = xvi[idx].visual;
406 if (XGetRGBColormaps(display, RootWindow(display, i),
407 &stdcmap, &ncmaps, XA_RGB_DEFAULT_MAP)) {
409 for (
int c = 0;
c < ncmaps; ++
c) {
410 if (!stdcmap[
c].red_max ||
411 !stdcmap[
c].green_max ||
412 !stdcmap[
c].blue_max ||
413 !stdcmap[
c].red_mult ||
414 !stdcmap[
c].green_mult ||
415 !stdcmap[
c].blue_mult)
419 proto.visualid = stdcmap[
c].visualid;
423 XVisualInfo *vi = XGetVisualInfo(display, VisualIDMask | VisualScreenMask,
429 d->
mode = ((vi[0].visual->c_class < StaticColor)
431 : ((vi[0].
visual->c_class < TrueColor)
435 d->
depth = vi[0].depth;
441 d->
r_max = stdcmap[
c].red_max + 1;
442 d->
g_max = stdcmap[
c].green_max + 1;
443 d->
b_max = stdcmap[
c].blue_max + 1;
445 if (d->
mode == Direct) {
465 switch (d->
visual->c_class) {
476 if (color_count != 0)
478 else if (d->
visual->map_entries > 65000)
480 else if (d->
visual->map_entries > 4000)
482 else if (d->
visual->map_entries > 250)
500 if (color_count != 0)
502 else if (d->
visual->map_entries > 65000)
504 else if (d->
visual->map_entries > 4000)
506 else if (d->
visual->map_entries > 250)
527 bool ownColormap =
false;
528 if (
X11->colormap && i == DefaultScreen(display)) {
532 }
else if ((!use_stdcmap
533 && (((d->
visual->c_class & 1) &&
X11->custom_cmap)
534 || d->
visual != DefaultVisual(display, i)))
535 || d->
visual->c_class == DirectColor) {
538 XCreateColormap(display, RootWindow(display, i), d->
visual,
539 d->
visual->c_class == DirectColor ? AllocAll : AllocNone);
565 X11->argbVisuals[i] = argbVisual;
566 X11->argbColormaps[i] = XCreateColormap(display, RootWindow(display, i), argbVisual, AllocNone);
574 if (screen->
visual->c_class == TrueColor && screen->
depth == 8 && screen->
cells == 8)
582 const int screens = ScreenCount(display);
584 for (
int i = 0; i < screens; ++i)
596 return *cmaps[screen];
615 if (!
d->ref.deref()) {
616 if (!
d->defaultColormap)
630 return (
d->mode == Gray
632 : (
d->mode == Indexed
633 ?
d->r_max *
d->g_max *
d->b_max
643 if (
d->mode != Direct) {
645 return d->pixels.at((r * 30 + g * 59 + b * 11) / 100);
646 return d->pixels.at(r *
d->g_max *
d->b_max + g *
d->b_max + b);
648 return (r <<
d->r_shift) + (g <<
d->g_shift) + (b <<
d->b_shift);
653 if (
d->mode != Direct) {
655 return d->colors.at(pixel);
658 const int r = (((pixel &
d->visual->red_mask) >>
d->r_shift) << 8) /
d->r_max;
659 const int g = (((pixel &
d->visual->green_mask) >>
d->g_shift) << 8) /
d->g_max;
660 const int b = (((pixel &
d->visual->blue_mask) >>
d->b_shift) << 8) /
d->b_max;
665 {
return d->colors; }
The QColor class provides colors based on RGB, HSV or CMYK values.
static QColormap instance(int screen=-1)
#define QT_END_NAMESPACE
This macro expands to.
static int appScreen()
Returns the number of the screen where the application is being displayed.
The QAtomicInt class provides platform-independent atomic operations on integers. ...
static int colorSpec()
Returns the color specification.
struct QColor::@220::@221 argb
static QColormap ** cmaps
static void init_gray(QColormapPrivate *d, int screen)
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
void resize(int size)
Sets the size of the vector to size.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Q_GUI_EXPORT EGLDisplay display()
const QColor colorAt(uint pixel) const
static uint right_align(uint v)
QColormap & operator=(const QColormap &colormap)
static void query_colormap(QColormapPrivate *d, int screen)
static QColor fromRgbF(qreal r, qreal g, qreal b, qreal a=1.0)
Static convenience function that returns a QColor constructed from the RGB color values, r (red), g (green), b (blue), and a (alpha-channel, i.e.
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
uint pixel(const QColor &color) const
const T & at(int i) const
Returns the item at index position i in the vector.
QColor toRgb() const
Create and returns an RGB QColor based on this color.
static int lowest_bit(uint v)
Q_GUI_EXPORT_INLINE int qGray(int r, int g, int b)
const QVector< QColor > colormap() const
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
static void init_indexed(QColormapPrivate *d, int screen)
void qAtomicAssign(T *&d, T *x)
This is a helper for the assignment operators of implicitly shared classes.
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
QColormap()
Constructs a new colormap.
static void init_direct(QColormapPrivate *d, bool ownColormap)
static int cube_root(int v)
int size() const
Returns the number of items in the vector.
static Display * display()
Returns the default display for the application.
static Visual * find_visual(Display *display, int screen, int visual_class, int visual_id, int *depth, bool *defaultVisual)