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));
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
void resize(int size)
Sets the size of the vector to size.
Q_GUI_EXPORT EGLDisplay display()
int qGray(int r, int g, int b)
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.
const T & at(int i) const
Returns the item at index position i in the vector.
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
int size() const
Returns the number of items in the vector.
static Display * display()
Returns the default display for the application.