ROOT  6.05/03
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gdkcolor-win32.c
Go to the documentation of this file.
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 
20 /*
21  * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
22  * file for a list of people on the GTK+ Team. See the ChangeLog
23  * files for a list of changes. These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
25  */
26 
27 #include "config.h"
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <time.h>
33 
34 #include "gdkcolor.h"
35 #include "gdkwin32.h"
36 
38  GdkColor * color,
39  const gchar * available);
40 static void gdk_colormap_add(GdkColormap * cmap);
41 static void gdk_colormap_remove(GdkColormap * cmap);
42 static guint gdk_colormap_hash(Colormap * cmap);
43 static gint gdk_colormap_cmp(Colormap * a, Colormap * b);
44 
46 
47 static Status
49  gboolean contig,
50  unsigned long plane_masks_return[],
51  unsigned int nplanes,
52  unsigned long pixels_return[], unsigned int npixels)
53 {
54  unsigned int i, nfree, iret;
55 
56  nfree = 0;
57  for (i = 0; i < colormap->size && nfree < npixels; i++)
58  if (!colormap->in_use[i])
59  nfree++;
60 
61  if (colormap->size + npixels - nfree > colormap->sizepalette) {
62  g_warning("alloc_color_cells: too large palette: %d",
63  colormap->size + npixels);
64  return FALSE;
65  }
66 
67  iret = 0;
68  for (i = 0; i < colormap->size && iret < npixels; i++)
69  if (!colormap->in_use[i]) {
70  colormap->in_use[i] = TRUE;
71  pixels_return[iret] = i;
72  iret++;
73  }
74 
75  if (nfree < npixels) {
76  int nmore = npixels - nfree;
77 
78  /* I don't understand why, if the code below in #if 0 is
79  enabled, gdkrgb fails miserably. The palette doesn't get
80  realized correctly. There doesn't seem to be any harm done by
81  keeping this code out, either. */
82 #ifdef SOME_STRANGE_BUG
83  if (!ResizePalette(colormap->palette, colormap->size + nmore)) {
84  WIN32_GDI_FAILED("ResizePalette")
85  return FALSE;
86  }
87  g_print("alloc_color_cells: %#x to %d\n",
88  colormap->palette, colormap->size + nmore);
89 #endif
90  for (i = colormap->size; i < colormap->size + nmore; i++) {
91  pixels_return[iret] = i;
92  iret++;
93  colormap->in_use[i] = TRUE;
94  }
95 #ifdef SOME_STRANGE_BUG
96  colormap->size += nmore;
97 #endif
98  }
99  return TRUE;
100 }
101 
102 /* The following functions are from Tk8.0, but heavily modified.
103  Here are tk's licensing terms. I hope these terms don't conflict
104  with the GNU Library General Public License? They shouldn't, as
105  they are looser that the GLPL, yes? */
106 
107 /*
108 This software is copyrighted by the Regents of the University of
109 California, Sun Microsystems, Inc., and other parties. The following
110 terms apply to all files associated with the software unless explicitly
111 disclaimed in individual files.
112 
113 The authors hereby grant permission to use, copy, modify, distribute,
114 and license this software and its documentation for any purpose, provided
115 that existing copyright notices are retained in all copies and that this
116 notice is included verbatim in any distributions. No written agreement,
117 license, or royalty fee is required for any of the authorized uses.
118 Modifications to this software may be copyrighted by their authors
119 and need not follow the licensing terms described here, provided that
120 the new terms are clearly indicated on the first page of each file where
121 they apply.
122 
123 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
124 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
125 ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
126 DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
127 POSSIBILITY OF SUCH DAMAGE.
128 
129 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
130 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
131 FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
132 IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
133 NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
134 MODIFICATIONS.
135 
136 GOVERNMENT USE: If you are acquiring this software on behalf of the
137 U.S. government, the Government shall have only "Restricted Rights"
138 in the software and related documentation as defined in the Federal
139 Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
140 are acquiring the software on behalf of the Department of Defense, the
141 software shall be classified as "Commercial Computer Software" and the
142 Government shall have only "Restricted Rights" as defined in Clause
143 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
144 authors grant the U.S. Government and others acting in its behalf
145 permission to use and distribute the software in accordance with the
146 terms specified in this license.
147 */
148 /*
149  *----------------------------------------------------------------------
150  *
151  * XAllocColor --
152  *
153  * Find the closest available color to the specified XColor.
154  *
155  * Results:
156  * Updates the color argument and returns 1 on success. Otherwise
157  * returns 0.
158  *
159  * Side effects:
160  * Allocates a new color in the palette.
161  *
162  *----------------------------------------------------------------------
163  */
164 
165 static int alloc_color(Colormap colormap, XColor * color, gulong * pixelp)
166 {
167  PALETTEENTRY entry, closeEntry;
168  unsigned int i;
169 
170  entry = *color;
171  entry.peFlags = 0;
172 
173  if (colormap->rc_palette) {
174  COLORREF newPixel, closePixel;
175  UINT index;
176 
177  /*
178  * Find the nearest existing palette entry.
179  */
180 
181  newPixel = RGB(entry.peRed, entry.peGreen, entry.peBlue);
182  index = GetNearestPaletteIndex(colormap->palette, newPixel);
183  GetPaletteEntries(colormap->palette, index, 1, &closeEntry);
184  closePixel = RGB(closeEntry.peRed, closeEntry.peGreen,
185  closeEntry.peBlue);
186 
187  if (newPixel != closePixel) {
188  /* Not a perfect match. */
189  if (!colormap->in_use[index]) {
190  /* It was a free'd entry anyway, so we can use it, and
191  set it to the correct color. */
192  if (SetPaletteEntries(colormap->palette, index, 1, &entry) ==
193  0)
194  WIN32_GDI_FAILED("SetPaletteEntries");
195  } else {
196  /* The close entry found is in use, so search for a
197  unused slot. */
198 
199  for (i = 0; i < colormap->size; i++)
200  if (!colormap->in_use[i]) {
201  /* A free slot, use it. */
202  if (SetPaletteEntries(colormap->palette,
203  index, 1, &entry) == 0)
204  WIN32_GDI_FAILED("SetPaletteEntries");
205  index = i;
206  break;
207  }
208  if (i == colormap->size) {
209  /* No free slots found. If the palette isn't maximal
210  yet, grow it. */
211  if (colormap->size == colormap->sizepalette) {
212  /* The palette is maximal, and no free slots available,
213  so use the close entry, then, dammit. */
214  *color = closeEntry;
215  } else {
216  /* There is room to grow the palette. */
217  index = colormap->size;
218  colormap->size++;
219  if (!ResizePalette(colormap->palette, colormap->size))
220  WIN32_GDI_FAILED("ResizePalette");
221  if (SetPaletteEntries
222  (colormap->palette, index, 1, &entry) == 0)
223  WIN32_GDI_FAILED("SetPaletteEntries");
224  }
225  }
226  }
227  colormap->stale = TRUE;
228  } else {
229  /* We got a match, so use it. */
230  }
231 
232  *pixelp = index;
233  colormap->in_use[index] = TRUE;
234 #if 0
235  g_print("alloc_color from %#x: index %d for %02x %02x %02x\n",
236  colormap->palette, index,
237  entry.peRed, entry.peGreen, entry.peBlue);
238 #endif
239  } else {
240  /*
241  * Determine what color will actually be used on non-colormap systems.
242  */
243  *pixelp =
244  GetNearestColor(gdk_DC,
245  RGB(entry.peRed, entry.peGreen, entry.peBlue));
246 
247  color->peRed = GetRValue(*pixelp);
248  color->peGreen = GetGValue(*pixelp);
249  color->peBlue = GetBValue(*pixelp);
250  }
251 
252  return 1;
253 }
254 
255 /*
256  *----------------------------------------------------------------------
257  *
258  * XFreeColors --
259  *
260  * Deallocate a block of colors.
261  *
262  * Results:
263  * None.
264  *
265  * Side effects:
266  * Removes entries for the current palette and compacts the
267  * remaining set.
268  *
269  *----------------------------------------------------------------------
270  */
271 
272 static void
274  gulong * pixels, gint npixels, gulong planes)
275 {
276  gint i;
277  PALETTEENTRY entries[256];
278 
279  /*
280  * We don't have to do anything for non-palette devices.
281  */
282 
283  if (colormap->rc_palette) {
284  int npal;
285  int lowestpixel = 256;
286  int highestpixel = -1;
287 
288  npal = GetPaletteEntries(colormap->palette, 0, 256, entries);
289  for (i = 0; i < npixels; i++) {
290  int pixel = pixels[i];
291 
292  if (pixel < lowestpixel)
293  lowestpixel = pixel;
294  if (pixel > highestpixel)
295  highestpixel = pixel;
296 
297  colormap->in_use[pixel] = FALSE;
298 
299  entries[pixel] = entries[0];
300  }
301 #if 0
302  if (SetPaletteEntries(colormap->palette, lowestpixel,
303  highestpixel - lowestpixel + 1,
304  entries + lowestpixel) == 0)
305  WIN32_GDI_FAILED("SetPaletteEntries");
306 #endif
307  colormap->stale = TRUE;
308 #if 0
309  g_print("free_colors %#x lowestpixel = %d, highestpixel = %d\n",
310  colormap->palette, lowestpixel, highestpixel);
311 #endif
312  }
313 }
314 
315 /*
316  *----------------------------------------------------------------------
317  *
318  * XCreateColormap --
319  *
320  * Allocate a new colormap.
321  *
322  * Results:
323  * Returns a newly allocated colormap.
324  *
325  * Side effects:
326  * Allocates an empty palette and color list.
327  *
328  *----------------------------------------------------------------------
329  */
330 
331 static Colormap create_colormap(HWND w, Visual * visual, gboolean alloc)
332 {
333  char logPalBuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
334  LOGPALETTE *logPalettePtr;
335  Colormap colormap;
336  guint i;
337  HPALETTE sysPal;
338  HDC hdc;
339 
340  /* Should the alloc parameter do something? */
341 
342 
343  /* Allocate a starting palette with all of the reserved colors. */
344 
345  logPalettePtr = (LOGPALETTE *) logPalBuf;
346  logPalettePtr->palVersion = 0x300;
347  sysPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
348  logPalettePtr->palNumEntries =
349  GetPaletteEntries(sysPal, 0, 256, logPalettePtr->palPalEntry);
350 
351  colormap = (Colormap) g_new(ColormapStruct, 1);
352  colormap->size = logPalettePtr->palNumEntries;
353  colormap->stale = TRUE;
354  colormap->palette = CreatePalette(logPalettePtr);
355  hdc = GetDC(NULL);
356  colormap->rc_palette =
357  ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) != 0);
358  if (colormap->rc_palette) {
359  colormap->sizepalette = GetDeviceCaps(hdc, SIZEPALETTE);
360  colormap->in_use = g_new(gboolean, colormap->sizepalette);
361  /* Mark static colors in use. */
362  for (i = 0; i < logPalettePtr->palNumEntries; i++)
363  colormap->in_use[i] = TRUE;
364  /* Mark rest not in use */
365  for (i = logPalettePtr->palNumEntries; i < colormap->sizepalette;
366  i++)
367  colormap->in_use[i] = FALSE;
368  }
369  ReleaseDC(NULL, hdc);
370 
371  return colormap;
372 }
373 
374 /*
375  *----------------------------------------------------------------------
376  *
377  * XFreeColormap --
378  *
379  * Frees the resources associated with the given colormap.
380  *
381  * Results:
382  * None.
383  *
384  * Side effects:
385  * Deletes the palette associated with the colormap. Note that
386  * the palette must not be selected into a device context when
387  * this occurs.
388  *
389  *----------------------------------------------------------------------
390  */
391 
392 static void free_colormap(Colormap colormap)
393 {
394  if (!DeleteObject(colormap->palette)) {
395  g_error("Unable to free colormap, palette is still selected.");
396  }
397  g_free(colormap);
398 }
399 
400 typedef struct {
401  char *name;
402  unsigned char red;
403  unsigned char green;
404  unsigned char blue;
405 } XColorEntry;
406 
407 static XColorEntry xColors[] = {
408  {"alice blue", 240, 248, 255},
409  {"AliceBlue", 240, 248, 255},
410  {"antique white", 250, 235, 215},
411  {"AntiqueWhite", 250, 235, 215},
412  {"AntiqueWhite1", 255, 239, 219},
413  {"AntiqueWhite2", 238, 223, 204},
414  {"AntiqueWhite3", 205, 192, 176},
415  {"AntiqueWhite4", 139, 131, 120},
416  {"aquamarine", 127, 255, 212},
417  {"aquamarine1", 127, 255, 212},
418  {"aquamarine2", 118, 238, 198},
419  {"aquamarine3", 102, 205, 170},
420  {"aquamarine4", 69, 139, 116},
421  {"azure", 240, 255, 255},
422  {"azure1", 240, 255, 255},
423  {"azure2", 224, 238, 238},
424  {"azure3", 193, 205, 205},
425  {"azure4", 131, 139, 139},
426  {"beige", 245, 245, 220},
427  {"bisque", 255, 228, 196},
428  {"bisque1", 255, 228, 196},
429  {"bisque2", 238, 213, 183},
430  {"bisque3", 205, 183, 158},
431  {"bisque4", 139, 125, 107},
432  {"black", 0, 0, 0},
433  {"blanched almond", 255, 235, 205},
434  {"BlanchedAlmond", 255, 235, 205},
435  {"blue", 0, 0, 255},
436  {"blue violet", 138, 43, 226},
437  {"blue1", 0, 0, 255},
438  {"blue2", 0, 0, 238},
439  {"blue3", 0, 0, 205},
440  {"blue4", 0, 0, 139},
441  {"BlueViolet", 138, 43, 226},
442  {"brown", 165, 42, 42},
443  {"brown1", 255, 64, 64},
444  {"brown2", 238, 59, 59},
445  {"brown3", 205, 51, 51},
446  {"brown4", 139, 35, 35},
447  {"burlywood", 222, 184, 135},
448  {"burlywood1", 255, 211, 155},
449  {"burlywood2", 238, 197, 145},
450  {"burlywood3", 205, 170, 125},
451  {"burlywood4", 139, 115, 85},
452  {"cadet blue", 95, 158, 160},
453  {"CadetBlue", 95, 158, 160},
454  {"CadetBlue1", 152, 245, 255},
455  {"CadetBlue2", 142, 229, 238},
456  {"CadetBlue3", 122, 197, 205},
457  {"CadetBlue4", 83, 134, 139},
458  {"chartreuse", 127, 255, 0},
459  {"chartreuse1", 127, 255, 0},
460  {"chartreuse2", 118, 238, 0},
461  {"chartreuse3", 102, 205, 0},
462  {"chartreuse4", 69, 139, 0},
463  {"chocolate", 210, 105, 30},
464  {"chocolate1", 255, 127, 36},
465  {"chocolate2", 238, 118, 33},
466  {"chocolate3", 205, 102, 29},
467  {"chocolate4", 139, 69, 19},
468  {"coral", 255, 127, 80},
469  {"coral1", 255, 114, 86},
470  {"coral2", 238, 106, 80},
471  {"coral3", 205, 91, 69},
472  {"coral4", 139, 62, 47},
473  {"cornflower blue", 100, 149, 237},
474  {"CornflowerBlue", 100, 149, 237},
475  {"cornsilk", 255, 248, 220},
476  {"cornsilk1", 255, 248, 220},
477  {"cornsilk2", 238, 232, 205},
478  {"cornsilk3", 205, 200, 177},
479  {"cornsilk4", 139, 136, 120},
480  {"cyan", 0, 255, 255},
481  {"cyan1", 0, 255, 255},
482  {"cyan2", 0, 238, 238},
483  {"cyan3", 0, 205, 205},
484  {"cyan4", 0, 139, 139},
485  {"dark blue", 0, 0, 139},
486  {"dark cyan", 0, 139, 139},
487  {"dark goldenrod", 184, 134, 11},
488  {"dark gray", 169, 169, 169},
489  {"dark green", 0, 100, 0},
490  {"dark grey", 169, 169, 169},
491  {"dark khaki", 189, 183, 107},
492  {"dark magenta", 139, 0, 139},
493  {"dark olive green", 85, 107, 47},
494  {"dark orange", 255, 140, 0},
495  {"dark orchid", 153, 50, 204},
496  {"dark red", 139, 0, 0},
497  {"dark salmon", 233, 150, 122},
498  {"dark sea green", 143, 188, 143},
499  {"dark slate blue", 72, 61, 139},
500  {"dark slate gray", 47, 79, 79},
501  {"dark slate grey", 47, 79, 79},
502  {"dark turquoise", 0, 206, 209},
503  {"dark violet", 148, 0, 211},
504  {"DarkBlue", 0, 0, 139},
505  {"DarkCyan", 0, 139, 139},
506  {"DarkGoldenrod", 184, 134, 11},
507  {"DarkGoldenrod1", 255, 185, 15},
508  {"DarkGoldenrod2", 238, 173, 14},
509  {"DarkGoldenrod3", 205, 149, 12},
510  {"DarkGoldenrod4", 139, 101, 8},
511  {"DarkGray", 169, 169, 169},
512  {"DarkGreen", 0, 100, 0},
513  {"DarkGrey", 169, 169, 169},
514  {"DarkKhaki", 189, 183, 107},
515  {"DarkMagenta", 139, 0, 139},
516  {"DarkOliveGreen", 85, 107, 47},
517  {"DarkOliveGreen1", 202, 255, 112},
518  {"DarkOliveGreen2", 188, 238, 104},
519  {"DarkOliveGreen3", 162, 205, 90},
520  {"DarkOliveGreen4", 110, 139, 61},
521  {"DarkOrange", 255, 140, 0},
522  {"DarkOrange1", 255, 127, 0},
523  {"DarkOrange2", 238, 118, 0},
524  {"DarkOrange3", 205, 102, 0},
525  {"DarkOrange4", 139, 69, 0},
526  {"DarkOrchid", 153, 50, 204},
527  {"DarkOrchid1", 191, 62, 255},
528  {"DarkOrchid2", 178, 58, 238},
529  {"DarkOrchid3", 154, 50, 205},
530  {"DarkOrchid4", 104, 34, 139},
531  {"DarkRed", 139, 0, 0},
532  {"DarkSalmon", 233, 150, 122},
533  {"DarkSeaGreen", 143, 188, 143},
534  {"DarkSeaGreen1", 193, 255, 193},
535  {"DarkSeaGreen2", 180, 238, 180},
536  {"DarkSeaGreen3", 155, 205, 155},
537  {"DarkSeaGreen4", 105, 139, 105},
538  {"DarkSlateBlue", 72, 61, 139},
539  {"DarkSlateGray", 47, 79, 79},
540  {"DarkSlateGray1", 151, 255, 255},
541  {"DarkSlateGray2", 141, 238, 238},
542  {"DarkSlateGray3", 121, 205, 205},
543  {"DarkSlateGray4", 82, 139, 139},
544  {"DarkSlateGrey", 47, 79, 79},
545  {"DarkTurquoise", 0, 206, 209},
546  {"DarkViolet", 148, 0, 211},
547  {"deep pink", 255, 20, 147},
548  {"deep sky blue", 0, 191, 255},
549  {"DeepPink", 255, 20, 147},
550  {"DeepPink1", 255, 20, 147},
551  {"DeepPink2", 238, 18, 137},
552  {"DeepPink3", 205, 16, 118},
553  {"DeepPink4", 139, 10, 80},
554  {"DeepSkyBlue", 0, 191, 255},
555  {"DeepSkyBlue1", 0, 191, 255},
556  {"DeepSkyBlue2", 0, 178, 238},
557  {"DeepSkyBlue3", 0, 154, 205},
558  {"DeepSkyBlue4", 0, 104, 139},
559  {"dim gray", 105, 105, 105},
560  {"dim grey", 105, 105, 105},
561  {"DimGray", 105, 105, 105},
562  {"DimGrey", 105, 105, 105},
563  {"dodger blue", 30, 144, 255},
564  {"DodgerBlue", 30, 144, 255},
565  {"DodgerBlue1", 30, 144, 255},
566  {"DodgerBlue2", 28, 134, 238},
567  {"DodgerBlue3", 24, 116, 205},
568  {"DodgerBlue4", 16, 78, 139},
569  {"firebrick", 178, 34, 34},
570  {"firebrick1", 255, 48, 48},
571  {"firebrick2", 238, 44, 44},
572  {"firebrick3", 205, 38, 38},
573  {"firebrick4", 139, 26, 26},
574  {"floral white", 255, 250, 240},
575  {"FloralWhite", 255, 250, 240},
576  {"forest green", 34, 139, 34},
577  {"ForestGreen", 34, 139, 34},
578  {"gainsboro", 220, 220, 220},
579  {"ghost white", 248, 248, 255},
580  {"GhostWhite", 248, 248, 255},
581  {"gold", 255, 215, 0},
582  {"gold1", 255, 215, 0},
583  {"gold2", 238, 201, 0},
584  {"gold3", 205, 173, 0},
585  {"gold4", 139, 117, 0},
586  {"goldenrod", 218, 165, 32},
587  {"goldenrod1", 255, 193, 37},
588  {"goldenrod2", 238, 180, 34},
589  {"goldenrod3", 205, 155, 29},
590  {"goldenrod4", 139, 105, 20},
591  {"gray", 190, 190, 190},
592  {"gray0", 0, 0, 0},
593  {"gray1", 3, 3, 3},
594  {"gray10", 26, 26, 26},
595  {"gray100", 255, 255, 255},
596  {"gray11", 28, 28, 28},
597  {"gray12", 31, 31, 31},
598  {"gray13", 33, 33, 33},
599  {"gray14", 36, 36, 36},
600  {"gray15", 38, 38, 38},
601  {"gray16", 41, 41, 41},
602  {"gray17", 43, 43, 43},
603  {"gray18", 46, 46, 46},
604  {"gray19", 48, 48, 48},
605  {"gray2", 5, 5, 5},
606  {"gray20", 51, 51, 51},
607  {"gray21", 54, 54, 54},
608  {"gray22", 56, 56, 56},
609  {"gray23", 59, 59, 59},
610  {"gray24", 61, 61, 61},
611  {"gray25", 64, 64, 64},
612  {"gray26", 66, 66, 66},
613  {"gray27", 69, 69, 69},
614  {"gray28", 71, 71, 71},
615  {"gray29", 74, 74, 74},
616  {"gray3", 8, 8, 8},
617  {"gray30", 77, 77, 77},
618  {"gray31", 79, 79, 79},
619  {"gray32", 82, 82, 82},
620  {"gray33", 84, 84, 84},
621  {"gray34", 87, 87, 87},
622  {"gray35", 89, 89, 89},
623  {"gray36", 92, 92, 92},
624  {"gray37", 94, 94, 94},
625  {"gray38", 97, 97, 97},
626  {"gray39", 99, 99, 99},
627  {"gray4", 10, 10, 10},
628  {"gray40", 102, 102, 102},
629  {"gray41", 105, 105, 105},
630  {"gray42", 107, 107, 107},
631  {"gray43", 110, 110, 110},
632  {"gray44", 112, 112, 112},
633  {"gray45", 115, 115, 115},
634  {"gray46", 117, 117, 117},
635  {"gray47", 120, 120, 120},
636  {"gray48", 122, 122, 122},
637  {"gray49", 125, 125, 125},
638  {"gray5", 13, 13, 13},
639  {"gray50", 127, 127, 127},
640  {"gray51", 130, 130, 130},
641  {"gray52", 133, 133, 133},
642  {"gray53", 135, 135, 135},
643  {"gray54", 138, 138, 138},
644  {"gray55", 140, 140, 140},
645  {"gray56", 143, 143, 143},
646  {"gray57", 145, 145, 145},
647  {"gray58", 148, 148, 148},
648  {"gray59", 150, 150, 150},
649  {"gray6", 15, 15, 15},
650  {"gray60", 153, 153, 153},
651  {"gray61", 156, 156, 156},
652  {"gray62", 158, 158, 158},
653  {"gray63", 161, 161, 161},
654  {"gray64", 163, 163, 163},
655  {"gray65", 166, 166, 166},
656  {"gray66", 168, 168, 168},
657  {"gray67", 171, 171, 171},
658  {"gray68", 173, 173, 173},
659  {"gray69", 176, 176, 176},
660  {"gray7", 18, 18, 18},
661  {"gray70", 179, 179, 179},
662  {"gray71", 181, 181, 181},
663  {"gray72", 184, 184, 184},
664  {"gray73", 186, 186, 186},
665  {"gray74", 189, 189, 189},
666  {"gray75", 191, 191, 191},
667  {"gray76", 194, 194, 194},
668  {"gray77", 196, 196, 196},
669  {"gray78", 199, 199, 199},
670  {"gray79", 201, 201, 201},
671  {"gray8", 20, 20, 20},
672  {"gray80", 204, 204, 204},
673  {"gray81", 207, 207, 207},
674  {"gray82", 209, 209, 209},
675  {"gray83", 212, 212, 212},
676  {"gray84", 214, 214, 214},
677  {"gray85", 217, 217, 217},
678  {"gray86", 219, 219, 219},
679  {"gray87", 222, 222, 222},
680  {"gray88", 224, 224, 224},
681  {"gray89", 227, 227, 227},
682  {"gray9", 23, 23, 23},
683  {"gray90", 229, 229, 229},
684  {"gray91", 232, 232, 232},
685  {"gray92", 235, 235, 235},
686  {"gray93", 237, 237, 237},
687  {"gray94", 240, 240, 240},
688  {"gray95", 242, 242, 242},
689  {"gray96", 245, 245, 245},
690  {"gray97", 247, 247, 247},
691  {"gray98", 250, 250, 250},
692  {"gray99", 252, 252, 252},
693  {"green", 0, 255, 0},
694  {"green yellow", 173, 255, 47},
695  {"green1", 0, 255, 0},
696  {"green2", 0, 238, 0},
697  {"green3", 0, 205, 0},
698  {"green4", 0, 139, 0},
699  {"GreenYellow", 173, 255, 47},
700  {"grey", 190, 190, 190},
701  {"grey0", 0, 0, 0},
702  {"grey1", 3, 3, 3},
703  {"grey10", 26, 26, 26},
704  {"grey100", 255, 255, 255},
705  {"grey11", 28, 28, 28},
706  {"grey12", 31, 31, 31},
707  {"grey13", 33, 33, 33},
708  {"grey14", 36, 36, 36},
709  {"grey15", 38, 38, 38},
710  {"grey16", 41, 41, 41},
711  {"grey17", 43, 43, 43},
712  {"grey18", 46, 46, 46},
713  {"grey19", 48, 48, 48},
714  {"grey2", 5, 5, 5},
715  {"grey20", 51, 51, 51},
716  {"grey21", 54, 54, 54},
717  {"grey22", 56, 56, 56},
718  {"grey23", 59, 59, 59},
719  {"grey24", 61, 61, 61},
720  {"grey25", 64, 64, 64},
721  {"grey26", 66, 66, 66},
722  {"grey27", 69, 69, 69},
723  {"grey28", 71, 71, 71},
724  {"grey29", 74, 74, 74},
725  {"grey3", 8, 8, 8},
726  {"grey30", 77, 77, 77},
727  {"grey31", 79, 79, 79},
728  {"grey32", 82, 82, 82},
729  {"grey33", 84, 84, 84},
730  {"grey34", 87, 87, 87},
731  {"grey35", 89, 89, 89},
732  {"grey36", 92, 92, 92},
733  {"grey37", 94, 94, 94},
734  {"grey38", 97, 97, 97},
735  {"grey39", 99, 99, 99},
736  {"grey4", 10, 10, 10},
737  {"grey40", 102, 102, 102},
738  {"grey41", 105, 105, 105},
739  {"grey42", 107, 107, 107},
740  {"grey43", 110, 110, 110},
741  {"grey44", 112, 112, 112},
742  {"grey45", 115, 115, 115},
743  {"grey46", 117, 117, 117},
744  {"grey47", 120, 120, 120},
745  {"grey48", 122, 122, 122},
746  {"grey49", 125, 125, 125},
747  {"grey5", 13, 13, 13},
748  {"grey50", 127, 127, 127},
749  {"grey51", 130, 130, 130},
750  {"grey52", 133, 133, 133},
751  {"grey53", 135, 135, 135},
752  {"grey54", 138, 138, 138},
753  {"grey55", 140, 140, 140},
754  {"grey56", 143, 143, 143},
755  {"grey57", 145, 145, 145},
756  {"grey58", 148, 148, 148},
757  {"grey59", 150, 150, 150},
758  {"grey6", 15, 15, 15},
759  {"grey60", 153, 153, 153},
760  {"grey61", 156, 156, 156},
761  {"grey62", 158, 158, 158},
762  {"grey63", 161, 161, 161},
763  {"grey64", 163, 163, 163},
764  {"grey65", 166, 166, 166},
765  {"grey66", 168, 168, 168},
766  {"grey67", 171, 171, 171},
767  {"grey68", 173, 173, 173},
768  {"grey69", 176, 176, 176},
769  {"grey7", 18, 18, 18},
770  {"grey70", 179, 179, 179},
771  {"grey71", 181, 181, 181},
772  {"grey72", 184, 184, 184},
773  {"grey73", 186, 186, 186},
774  {"grey74", 189, 189, 189},
775  {"grey75", 191, 191, 191},
776  {"grey76", 194, 194, 194},
777  {"grey77", 196, 196, 196},
778  {"grey78", 199, 199, 199},
779  {"grey79", 201, 201, 201},
780  {"grey8", 20, 20, 20},
781  {"grey80", 204, 204, 204},
782  {"grey81", 207, 207, 207},
783  {"grey82", 209, 209, 209},
784  {"grey83", 212, 212, 212},
785  {"grey84", 214, 214, 214},
786  {"grey85", 217, 217, 217},
787  {"grey86", 219, 219, 219},
788  {"grey87", 222, 222, 222},
789  {"grey88", 224, 224, 224},
790  {"grey89", 227, 227, 227},
791  {"grey9", 23, 23, 23},
792  {"grey90", 229, 229, 229},
793  {"grey91", 232, 232, 232},
794  {"grey92", 235, 235, 235},
795  {"grey93", 237, 237, 237},
796  {"grey94", 240, 240, 240},
797  {"grey95", 242, 242, 242},
798  {"grey96", 245, 245, 245},
799  {"grey97", 247, 247, 247},
800  {"grey98", 250, 250, 250},
801  {"grey99", 252, 252, 252},
802  {"honeydew", 240, 255, 240},
803  {"honeydew1", 240, 255, 240},
804  {"honeydew2", 224, 238, 224},
805  {"honeydew3", 193, 205, 193},
806  {"honeydew4", 131, 139, 131},
807  {"hot pink", 255, 105, 180},
808  {"HotPink", 255, 105, 180},
809  {"HotPink1", 255, 110, 180},
810  {"HotPink2", 238, 106, 167},
811  {"HotPink3", 205, 96, 144},
812  {"HotPink4", 139, 58, 98},
813  {"indian red", 205, 92, 92},
814  {"IndianRed", 205, 92, 92},
815  {"IndianRed1", 255, 106, 106},
816  {"IndianRed2", 238, 99, 99},
817  {"IndianRed3", 205, 85, 85},
818  {"IndianRed4", 139, 58, 58},
819  {"ivory", 255, 255, 240},
820  {"ivory1", 255, 255, 240},
821  {"ivory2", 238, 238, 224},
822  {"ivory3", 205, 205, 193},
823  {"ivory4", 139, 139, 131},
824  {"khaki", 240, 230, 140},
825  {"khaki1", 255, 246, 143},
826  {"khaki2", 238, 230, 133},
827  {"khaki3", 205, 198, 115},
828  {"khaki4", 139, 134, 78},
829  {"lavender", 230, 230, 250},
830  {"lavender blush", 255, 240, 245},
831  {"LavenderBlush", 255, 240, 245},
832  {"LavenderBlush1", 255, 240, 245},
833  {"LavenderBlush2", 238, 224, 229},
834  {"LavenderBlush3", 205, 193, 197},
835  {"LavenderBlush4", 139, 131, 134},
836  {"lawn green", 124, 252, 0},
837  {"LawnGreen", 124, 252, 0},
838  {"lemon chiffon", 255, 250, 205},
839  {"LemonChiffon", 255, 250, 205},
840  {"LemonChiffon1", 255, 250, 205},
841  {"LemonChiffon2", 238, 233, 191},
842  {"LemonChiffon3", 205, 201, 165},
843  {"LemonChiffon4", 139, 137, 112},
844  {"light blue", 173, 216, 230},
845  {"light coral", 240, 128, 128},
846  {"light cyan", 224, 255, 255},
847  {"light goldenrod", 238, 221, 130},
848  {"light goldenrod yellow", 250, 250, 210},
849  {"light gray", 211, 211, 211},
850  {"light green", 144, 238, 144},
851  {"light grey", 211, 211, 211},
852  {"light pink", 255, 182, 193},
853  {"light salmon", 255, 160, 122},
854  {"light sea green", 32, 178, 170},
855  {"light sky blue", 135, 206, 250},
856  {"light slate blue", 132, 112, 255},
857  {"light slate gray", 119, 136, 153},
858  {"light slate grey", 119, 136, 153},
859  {"light steel blue", 176, 196, 222},
860  {"light yellow", 255, 255, 224},
861  {"LightBlue", 173, 216, 230},
862  {"LightBlue1", 191, 239, 255},
863  {"LightBlue2", 178, 223, 238},
864  {"LightBlue3", 154, 192, 205},
865  {"LightBlue4", 104, 131, 139},
866  {"LightCoral", 240, 128, 128},
867  {"LightCyan", 224, 255, 255},
868  {"LightCyan1", 224, 255, 255},
869  {"LightCyan2", 209, 238, 238},
870  {"LightCyan3", 180, 205, 205},
871  {"LightCyan4", 122, 139, 139},
872  {"LightGoldenrod", 238, 221, 130},
873  {"LightGoldenrod1", 255, 236, 139},
874  {"LightGoldenrod2", 238, 220, 130},
875  {"LightGoldenrod3", 205, 190, 112},
876  {"LightGoldenrod4", 139, 129, 76},
877  {"LightGoldenrodYellow", 250, 250, 210},
878  {"LightGray", 211, 211, 211},
879  {"LightGreen", 144, 238, 144},
880  {"LightGrey", 211, 211, 211},
881  {"LightPink", 255, 182, 193},
882  {"LightPink1", 255, 174, 185},
883  {"LightPink2", 238, 162, 173},
884  {"LightPink3", 205, 140, 149},
885  {"LightPink4", 139, 95, 101},
886  {"LightSalmon", 255, 160, 122},
887  {"LightSalmon1", 255, 160, 122},
888  {"LightSalmon2", 238, 149, 114},
889  {"LightSalmon3", 205, 129, 98},
890  {"LightSalmon4", 139, 87, 66},
891  {"LightSeaGreen", 32, 178, 170},
892  {"LightSkyBlue", 135, 206, 250},
893  {"LightSkyBlue1", 176, 226, 255},
894  {"LightSkyBlue2", 164, 211, 238},
895  {"LightSkyBlue3", 141, 182, 205},
896  {"LightSkyBlue4", 96, 123, 139},
897  {"LightSlateBlue", 132, 112, 255},
898  {"LightSlateGray", 119, 136, 153},
899  {"LightSlateGrey", 119, 136, 153},
900  {"LightSteelBlue", 176, 196, 222},
901  {"LightSteelBlue1", 202, 225, 255},
902  {"LightSteelBlue2", 188, 210, 238},
903  {"LightSteelBlue3", 162, 181, 205},
904  {"LightSteelBlue4", 110, 123, 139},
905  {"LightYellow", 255, 255, 224},
906  {"LightYellow1", 255, 255, 224},
907  {"LightYellow2", 238, 238, 209},
908  {"LightYellow3", 205, 205, 180},
909  {"LightYellow4", 139, 139, 122},
910  {"lime green", 50, 205, 50},
911  {"LimeGreen", 50, 205, 50},
912  {"linen", 250, 240, 230},
913  {"magenta", 255, 0, 255},
914  {"magenta1", 255, 0, 255},
915  {"magenta2", 238, 0, 238},
916  {"magenta3", 205, 0, 205},
917  {"magenta4", 139, 0, 139},
918  {"maroon", 176, 48, 96},
919  {"maroon1", 255, 52, 179},
920  {"maroon2", 238, 48, 167},
921  {"maroon3", 205, 41, 144},
922  {"maroon4", 139, 28, 98},
923  {"medium aquamarine", 102, 205, 170},
924  {"medium blue", 0, 0, 205},
925  {"medium orchid", 186, 85, 211},
926  {"medium purple", 147, 112, 219},
927  {"medium sea green", 60, 179, 113},
928  {"medium slate blue", 123, 104, 238},
929  {"medium spring green", 0, 250, 154},
930  {"medium turquoise", 72, 209, 204},
931  {"medium violet red", 199, 21, 133},
932  {"MediumAquamarine", 102, 205, 170},
933  {"MediumBlue", 0, 0, 205},
934  {"MediumOrchid", 186, 85, 211},
935  {"MediumOrchid1", 224, 102, 255},
936  {"MediumOrchid2", 209, 95, 238},
937  {"MediumOrchid3", 180, 82, 205},
938  {"MediumOrchid4", 122, 55, 139},
939  {"MediumPurple", 147, 112, 219},
940  {"MediumPurple1", 171, 130, 255},
941  {"MediumPurple2", 159, 121, 238},
942  {"MediumPurple3", 137, 104, 205},
943  {"MediumPurple4", 93, 71, 139},
944  {"MediumSeaGreen", 60, 179, 113},
945  {"MediumSlateBlue", 123, 104, 238},
946  {"MediumSpringGreen", 0, 250, 154},
947  {"MediumTurquoise", 72, 209, 204},
948  {"MediumVioletRed", 199, 21, 133},
949  {"midnight blue", 25, 25, 112},
950  {"MidnightBlue", 25, 25, 112},
951  {"mint cream", 245, 255, 250},
952  {"MintCream", 245, 255, 250},
953  {"misty rose", 255, 228, 225},
954  {"MistyRose", 255, 228, 225},
955  {"MistyRose1", 255, 228, 225},
956  {"MistyRose2", 238, 213, 210},
957  {"MistyRose3", 205, 183, 181},
958  {"MistyRose4", 139, 125, 123},
959  {"moccasin", 255, 228, 181},
960  {"navajo white", 255, 222, 173},
961  {"NavajoWhite", 255, 222, 173},
962  {"NavajoWhite1", 255, 222, 173},
963  {"NavajoWhite2", 238, 207, 161},
964  {"NavajoWhite3", 205, 179, 139},
965  {"NavajoWhite4", 139, 121, 94},
966  {"navy", 0, 0, 128},
967  {"navy blue", 0, 0, 128},
968  {"NavyBlue", 0, 0, 128},
969  {"old lace", 253, 245, 230},
970  {"OldLace", 253, 245, 230},
971  {"olive drab", 107, 142, 35},
972  {"OliveDrab", 107, 142, 35},
973  {"OliveDrab1", 192, 255, 62},
974  {"OliveDrab2", 179, 238, 58},
975  {"OliveDrab3", 154, 205, 50},
976  {"OliveDrab4", 105, 139, 34},
977  {"orange", 255, 165, 0},
978  {"orange red", 255, 69, 0},
979  {"orange1", 255, 165, 0},
980  {"orange2", 238, 154, 0},
981  {"orange3", 205, 133, 0},
982  {"orange4", 139, 90, 0},
983  {"OrangeRed", 255, 69, 0},
984  {"OrangeRed1", 255, 69, 0},
985  {"OrangeRed2", 238, 64, 0},
986  {"OrangeRed3", 205, 55, 0},
987  {"OrangeRed4", 139, 37, 0},
988  {"orchid", 218, 112, 214},
989  {"orchid1", 255, 131, 250},
990  {"orchid2", 238, 122, 233},
991  {"orchid3", 205, 105, 201},
992  {"orchid4", 139, 71, 137},
993  {"pale goldenrod", 238, 232, 170},
994  {"pale green", 152, 251, 152},
995  {"pale turquoise", 175, 238, 238},
996  {"pale violet red", 219, 112, 147},
997  {"PaleGoldenrod", 238, 232, 170},
998  {"PaleGreen", 152, 251, 152},
999  {"PaleGreen1", 154, 255, 154},
1000  {"PaleGreen2", 144, 238, 144},
1001  {"PaleGreen3", 124, 205, 124},
1002  {"PaleGreen4", 84, 139, 84},
1003  {"PaleTurquoise", 175, 238, 238},
1004  {"PaleTurquoise1", 187, 255, 255},
1005  {"PaleTurquoise2", 174, 238, 238},
1006  {"PaleTurquoise3", 150, 205, 205},
1007  {"PaleTurquoise4", 102, 139, 139},
1008  {"PaleVioletRed", 219, 112, 147},
1009  {"PaleVioletRed1", 255, 130, 171},
1010  {"PaleVioletRed2", 238, 121, 159},
1011  {"PaleVioletRed3", 205, 104, 137},
1012  {"PaleVioletRed4", 139, 71, 93},
1013  {"papaya whip", 255, 239, 213},
1014  {"PapayaWhip", 255, 239, 213},
1015  {"peach puff", 255, 218, 185},
1016  {"PeachPuff", 255, 218, 185},
1017  {"PeachPuff1", 255, 218, 185},
1018  {"PeachPuff2", 238, 203, 173},
1019  {"PeachPuff3", 205, 175, 149},
1020  {"PeachPuff4", 139, 119, 101},
1021  {"peru", 205, 133, 63},
1022  {"pink", 255, 192, 203},
1023  {"pink1", 255, 181, 197},
1024  {"pink2", 238, 169, 184},
1025  {"pink3", 205, 145, 158},
1026  {"pink4", 139, 99, 108},
1027  {"plum", 221, 160, 221},
1028  {"plum1", 255, 187, 255},
1029  {"plum2", 238, 174, 238},
1030  {"plum3", 205, 150, 205},
1031  {"plum4", 139, 102, 139},
1032  {"powder blue", 176, 224, 230},
1033  {"PowderBlue", 176, 224, 230},
1034  {"purple", 160, 32, 240},
1035  {"purple1", 155, 48, 255},
1036  {"purple2", 145, 44, 238},
1037  {"purple3", 125, 38, 205},
1038  {"purple4", 85, 26, 139},
1039  {"red", 255, 0, 0},
1040  {"red1", 255, 0, 0},
1041  {"red2", 238, 0, 0},
1042  {"red3", 205, 0, 0},
1043  {"red4", 139, 0, 0},
1044  {"rosy brown", 188, 143, 143},
1045  {"RosyBrown", 188, 143, 143},
1046  {"RosyBrown1", 255, 193, 193},
1047  {"RosyBrown2", 238, 180, 180},
1048  {"RosyBrown3", 205, 155, 155},
1049  {"RosyBrown4", 139, 105, 105},
1050  {"royal blue", 65, 105, 225},
1051  {"RoyalBlue", 65, 105, 225},
1052  {"RoyalBlue1", 72, 118, 255},
1053  {"RoyalBlue2", 67, 110, 238},
1054  {"RoyalBlue3", 58, 95, 205},
1055  {"RoyalBlue4", 39, 64, 139},
1056  {"saddle brown", 139, 69, 19},
1057  {"SaddleBrown", 139, 69, 19},
1058  {"salmon", 250, 128, 114},
1059  {"salmon1", 255, 140, 105},
1060  {"salmon2", 238, 130, 98},
1061  {"salmon3", 205, 112, 84},
1062  {"salmon4", 139, 76, 57},
1063  {"sandy brown", 244, 164, 96},
1064  {"SandyBrown", 244, 164, 96},
1065  {"sea green", 46, 139, 87},
1066  {"SeaGreen", 46, 139, 87},
1067  {"SeaGreen1", 84, 255, 159},
1068  {"SeaGreen2", 78, 238, 148},
1069  {"SeaGreen3", 67, 205, 128},
1070  {"SeaGreen4", 46, 139, 87},
1071  {"seashell", 255, 245, 238},
1072  {"seashell1", 255, 245, 238},
1073  {"seashell2", 238, 229, 222},
1074  {"seashell3", 205, 197, 191},
1075  {"seashell4", 139, 134, 130},
1076  {"sienna", 160, 82, 45},
1077  {"sienna1", 255, 130, 71},
1078  {"sienna2", 238, 121, 66},
1079  {"sienna3", 205, 104, 57},
1080  {"sienna4", 139, 71, 38},
1081  {"sky blue", 135, 206, 235},
1082  {"SkyBlue", 135, 206, 235},
1083  {"SkyBlue1", 135, 206, 255},
1084  {"SkyBlue2", 126, 192, 238},
1085  {"SkyBlue3", 108, 166, 205},
1086  {"SkyBlue4", 74, 112, 139},
1087  {"slate blue", 106, 90, 205},
1088  {"slate gray", 112, 128, 144},
1089  {"slate grey", 112, 128, 144},
1090  {"SlateBlue", 106, 90, 205},
1091  {"SlateBlue1", 131, 111, 255},
1092  {"SlateBlue2", 122, 103, 238},
1093  {"SlateBlue3", 105, 89, 205},
1094  {"SlateBlue4", 71, 60, 139},
1095  {"SlateGray", 112, 128, 144},
1096  {"SlateGray1", 198, 226, 255},
1097  {"SlateGray2", 185, 211, 238},
1098  {"SlateGray3", 159, 182, 205},
1099  {"SlateGray4", 108, 123, 139},
1100  {"SlateGrey", 112, 128, 144},
1101  {"snow", 255, 250, 250},
1102  {"snow1", 255, 250, 250},
1103  {"snow2", 238, 233, 233},
1104  {"snow3", 205, 201, 201},
1105  {"snow4", 139, 137, 137},
1106  {"spring green", 0, 255, 127},
1107  {"SpringGreen", 0, 255, 127},
1108  {"SpringGreen1", 0, 255, 127},
1109  {"SpringGreen2", 0, 238, 118},
1110  {"SpringGreen3", 0, 205, 102},
1111  {"SpringGreen4", 0, 139, 69},
1112  {"steel blue", 70, 130, 180},
1113  {"SteelBlue", 70, 130, 180},
1114  {"SteelBlue1", 99, 184, 255},
1115  {"SteelBlue2", 92, 172, 238},
1116  {"SteelBlue3", 79, 148, 205},
1117  {"SteelBlue4", 54, 100, 139},
1118  {"tan", 210, 180, 140},
1119  {"tan1", 255, 165, 79},
1120  {"tan2", 238, 154, 73},
1121  {"tan3", 205, 133, 63},
1122  {"tan4", 139, 90, 43},
1123  {"thistle", 216, 191, 216},
1124  {"thistle1", 255, 225, 255},
1125  {"thistle2", 238, 210, 238},
1126  {"thistle3", 205, 181, 205},
1127  {"thistle4", 139, 123, 139},
1128  {"tomato", 255, 99, 71},
1129  {"tomato1", 255, 99, 71},
1130  {"tomato2", 238, 92, 66},
1131  {"tomato3", 205, 79, 57},
1132  {"tomato4", 139, 54, 38},
1133  {"turquoise", 64, 224, 208},
1134  {"turquoise1", 0, 245, 255},
1135  {"turquoise2", 0, 229, 238},
1136  {"turquoise3", 0, 197, 205},
1137  {"turquoise4", 0, 134, 139},
1138  {"violet", 238, 130, 238},
1139  {"violet red", 208, 32, 144},
1140  {"VioletRed", 208, 32, 144},
1141  {"VioletRed1", 255, 62, 150},
1142  {"VioletRed2", 238, 58, 140},
1143  {"VioletRed3", 205, 50, 120},
1144  {"VioletRed4", 139, 34, 82},
1145  {"wheat", 245, 222, 179},
1146  {"wheat1", 255, 231, 186},
1147  {"wheat2", 238, 216, 174},
1148  {"wheat3", 205, 186, 150},
1149  {"wheat4", 139, 126, 102},
1150  {"white", 255, 255, 255},
1151  {"white smoke", 245, 245, 245},
1152  {"WhiteSmoke", 245, 245, 245},
1153  {"yellow", 255, 255, 0},
1154  {"yellow green", 154, 205, 50},
1155  {"yellow1", 255, 255, 0},
1156  {"yellow2", 238, 238, 0},
1157  {"yellow3", 205, 205, 0},
1158  {"yellow4", 139, 139, 0},
1159  {"YellowGreen", 154, 205, 50}
1160 };
1161 
1162 #define numXColors (sizeof (xColors) / sizeof (*xColors))
1163 
1164 /*
1165  *----------------------------------------------------------------------
1166  *
1167  * FindColor --
1168  *
1169  * This routine finds the color entry that corresponds to the
1170  * specified color.
1171  *
1172  * Results:
1173  * Returns non-zero on success. The RGB values of the XColor
1174  * will be initialized to the proper values on success.
1175  *
1176  * Side effects:
1177  * None.
1178  *
1179  *----------------------------------------------------------------------
1180  */
1181 
1182 static int compare_xcolor_entries(const void *a, const void *b)
1183 {
1184  return strcasecmp((const char *) a, ((const XColorEntry *) b)->name);
1185 }
1186 
1187 static int FindColor(const char *name, GdkColor * colorPtr)
1188 {
1189  XColorEntry *found;
1190 
1191  found = bsearch(name, xColors, numXColors, sizeof(XColorEntry),
1193  if (found == NULL)
1194  return 0;
1195 
1196  colorPtr->red = (found->red * 65535) / 255;
1197  colorPtr->green = (found->green * 65535) / 255;
1198  colorPtr->blue = (found->blue * 65535) / 255;
1199  return 1;
1200 }
1201 
1202 /*
1203  *----------------------------------------------------------------------
1204  *
1205  * parse_color --
1206  *
1207  * Partial implementation of X color name parsing interface.
1208  *
1209  * Results:
1210  * Returns non-zero on success.
1211  *
1212  * Side effects:
1213  * None.
1214  *
1215  *----------------------------------------------------------------------
1216  */
1217 
1218 gboolean parse_color(Colormap map, const char *spec, GdkColor * colorPtr)
1219 {
1220  if (spec[0] == '#') {
1221  char fmt[16];
1222  int i, red, green, blue;
1223 
1224  if ((i = strlen(spec + 1)) % 3) {
1225  return 0;
1226  }
1227  i /= 3;
1228 
1229  sprintf(fmt, "%%%dx%%%dx%%%dx", i, i, i);
1230  if (sscanf(spec + 1, fmt, &red, &green, &blue) != 3) {
1231  return 0;
1232  }
1233  if (i == 4) {
1234  colorPtr->red = red;
1235  colorPtr->green = green;
1236  colorPtr->blue = blue;
1237  } else if (i == 1) {
1238  colorPtr->red = (red * 65535) / 15;
1239  colorPtr->green = (green * 65535) / 15;
1240  colorPtr->blue = (blue * 65535) / 15;
1241  } else if (i == 2) {
1242  colorPtr->red = (red * 65535) / 255;
1243  colorPtr->green = (green * 65535) / 255;
1244  colorPtr->blue = (blue * 65535) / 255;
1245  } else { /* if (i == 3) */
1246 
1247  colorPtr->red = (red * 65535) / 4095;
1248  colorPtr->green = (green * 65535) / 4095;
1249  colorPtr->blue = (blue * 65535) / 4095;
1250  }
1251  } else {
1252  if (!FindColor(spec, colorPtr)) {
1253  return 0;
1254  }
1255  }
1256  return 1;
1257 }
1258 
1259 /* End of code from Tk8.0 */
1260 
1262 {
1263  static Colormap colormap;
1264 
1265  if (colormap)
1266  return colormap;
1267 
1268  colormap = create_colormap(NULL, NULL, FALSE);
1269  return colormap;
1270 }
1271 
1272 GdkColormap *gdk_colormap_new(GdkVisual * visual, gint private_cmap)
1273 {
1274  GdkColormap *colormap;
1275  GdkColormapPrivateWin32 *private;
1276  Visual *xvisual;
1277  int i;
1278 
1279  g_return_val_if_fail(visual != NULL, NULL);
1280 
1281  private = g_new(GdkColormapPrivateWin32, 1);
1282  colormap = (GdkColormap *) private;
1283 
1284  private->base.visual = visual;
1285  private->base.ref_count = 1;
1286 
1287  private->hash = NULL;
1288  private->last_sync_time = 0;
1289  private->info = NULL;
1290 
1291  xvisual = ((GdkVisualPrivate *) visual)->xvisual;
1292 
1293  colormap->size = visual->colormap_size;
1294  colormap->colors = g_new(GdkColor, colormap->size);
1295 
1296  switch (visual->type) {
1297  case GDK_VISUAL_GRAYSCALE:
1299  private->info = g_new0(GdkColorInfo, colormap->size);
1300 
1301  private->hash = g_hash_table_new((GHashFunc) gdk_color_hash,
1303 
1304  private->private_val = private_cmap;
1305  private->xcolormap = create_colormap(gdk_root_window, xvisual,
1306  private_cmap);
1307 
1308  if (private_cmap) {
1309  PALETTEENTRY pal[256];
1310  guint npal;
1311 
1312  npal =
1313  GetPaletteEntries(private->xcolormap->palette, 0,
1314  colormap->size, pal);
1315  for (i = 0; i < colormap->size; i++) {
1316  colormap->colors[i].pixel = i;
1317  if ((guint)i >= npal) {
1318  colormap->colors[i].red =
1319  colormap->colors[i].green =
1320  colormap->colors[i].blue = 0;
1321  } else {
1322  colormap->colors[i].red = (pal[i].peRed * 65535) / 255;
1323  colormap->colors[i].green = (pal[i].peGreen * 65525) / 255;
1324  colormap->colors[i].blue = (pal[i].peBlue * 65535) / 255;
1325  }
1326  }
1327  gdk_colormap_change(colormap, colormap->size);
1328  }
1329  break;
1330 
1333  case GDK_VISUAL_TRUE_COLOR:
1334  private->private_val = FALSE;
1335  private->xcolormap = create_colormap(gdk_root_window,
1336  xvisual, FALSE);
1337  break;
1338  }
1339 
1340  gdk_colormap_add(colormap);
1341 
1342  return colormap;
1343 }
1344 
1346 {
1347  GdkColormapPrivateWin32 *private = (GdkColormapPrivateWin32 *) colormap;
1348 
1349  g_return_if_fail(colormap != NULL);
1350  g_return_if_fail(private->base.ref_count == 0);
1351 
1352  gdk_colormap_remove(colormap);
1353  free_colormap(private->xcolormap);
1354 
1355  if (private->hash)
1356  g_hash_table_destroy(private->hash);
1357 
1358  g_free(private->info);
1359  g_free(colormap->colors);
1360  g_free(colormap);
1361 }
1362 
1363 #define MIN_SYNC_TIME 2
1364 
1365 void gdk_colormap_sync(GdkColormap * colormap, gboolean force)
1366 {
1367  time_t current_time;
1368  GdkColormapPrivateWin32 *private = (GdkColormapPrivateWin32 *) colormap;
1369  XColor *xpalette;
1370  gint nlookup;
1371  gint i;
1372 
1373  g_return_if_fail(colormap != NULL);
1374 
1375  current_time = time(NULL);
1376  if (!force
1377  && ((current_time - private->last_sync_time) < MIN_SYNC_TIME))
1378  return;
1379 
1380  private->last_sync_time = current_time;
1381 
1382  nlookup = 0;
1383  xpalette = g_new(XColor, colormap->size);
1384 
1385  nlookup = GetPaletteEntries(private->xcolormap->palette,
1386  0, colormap->size, xpalette);
1387 
1388  for (i = 0; i < nlookup; i++) {
1389  colormap->colors[i].pixel = i;
1390  colormap->colors[i].red = (xpalette[i].peRed * 65535) / 255;
1391  colormap->colors[i].green = (xpalette[i].peGreen * 65535) / 255;
1392  colormap->colors[i].blue = (xpalette[i].peBlue * 65535) / 255;
1393  }
1394 
1395  for (; i < colormap->size; i++) {
1396  colormap->colors[i].pixel = i;
1397  colormap->colors[i].red = 0;
1398  colormap->colors[i].green = 0;
1399  colormap->colors[i].blue = 0;
1400  }
1401 
1402  g_free(xpalette);
1403 }
1404 
1406 {
1407  static GdkColormap *colormap = NULL;
1408  GdkColormapPrivateWin32 *private;
1409 
1410  if (!colormap) {
1411  private = g_new(GdkColormapPrivateWin32, 1);
1412  colormap = (GdkColormap *) private;
1413 
1414  private->xcolormap = default_colormap();
1415  private->base.visual = gdk_visual_get_system();
1416  private->private_val = FALSE;
1417  private->base.ref_count = 1;
1418 
1419  private->hash = NULL;
1420  private->last_sync_time = 0;
1421  private->info = NULL;
1422 
1423  colormap->colors = NULL;
1424  colormap->size = private->base.visual->colormap_size;
1425 
1426  if ((private->base.visual->type == GDK_VISUAL_GRAYSCALE) ||
1427  (private->base.visual->type == GDK_VISUAL_PSEUDO_COLOR)) {
1428  private->info = g_new0(GdkColorInfo, colormap->size);
1429  colormap->colors = g_new(GdkColor, colormap->size);
1430 
1431  private->hash = g_hash_table_new((GHashFunc) gdk_color_hash,
1433 
1434  gdk_colormap_sync(colormap, TRUE);
1435  }
1436  gdk_colormap_add(colormap);
1437  }
1438 
1439  return colormap;
1440 }
1441 
1443 {
1444  gint bitspixel;
1445 
1446  bitspixel = GetDeviceCaps(gdk_DC, BITSPIXEL);
1447 
1448  if (bitspixel == 1)
1449  return 2;
1450  else if (bitspixel == 4)
1451  return 16;
1452  else if (bitspixel == 8)
1453  return 256;
1454  else if (bitspixel == 12)
1455  return 32;
1456  else if (bitspixel == 16)
1457  return 64;
1458  else /* if (bitspixel >= 24) */
1459  return 256;
1460 }
1461 
1462 void gdk_colormap_change(GdkColormap * colormap, gint ncolors)
1463 {
1464  GdkColormapPrivateWin32 *private;
1465  XColor *palette;
1466  int i;
1467 
1468  g_return_if_fail(colormap != NULL);
1469 
1470  palette = g_new(XColor, ncolors);
1471 
1472  private = (GdkColormapPrivateWin32 *) colormap;
1473  switch (private->base.visual->type) {
1474  case GDK_VISUAL_GRAYSCALE:
1476  for (i = 0; i < ncolors; i++) {
1477  palette[i].peRed = (colormap->colors[i].red >> 8);
1478  palette[i].peGreen = (colormap->colors[i].green >> 8);
1479  palette[i].peBlue = (colormap->colors[i].blue >> 8);
1480  palette[i].peFlags = 0;
1481  }
1482 
1483  if (SetPaletteEntries(private->xcolormap->palette,
1484  0, ncolors, palette) == 0)
1485  WIN32_GDI_FAILED("SetPaletteEntries");
1486  private->xcolormap->stale = TRUE;
1487  break;
1488 
1489  default:
1490  break;
1491  }
1492 
1493  g_free(palette);
1494 }
1495 
1496 gboolean
1498  gint contiguous,
1499  gulong * planes,
1500  gint nplanes, gulong * pixels, gint npixels)
1501 {
1502  GdkColormapPrivateWin32 *private;
1503  gint return_val;
1504  gint i;
1505 
1506  g_return_val_if_fail(colormap != NULL, 0);
1507 
1508  private = (GdkColormapPrivateWin32 *) colormap;
1509 
1510  return_val = alloc_color_cells(private->xcolormap, contiguous,
1511  planes, nplanes, pixels, npixels);
1512 
1513  if (return_val) {
1514  for (i = 0; i < npixels; i++) {
1515  private->info[pixels[i]].ref_count++;
1516  private->info[pixels[i]].flags |= GDK_COLOR_WRITEABLE;
1517  }
1518  }
1519 
1520  return return_val != 0;
1521 }
1522 
1523 gboolean gdk_color_parse(const gchar * spec, GdkColor * color)
1524 {
1525  Colormap xcolormap;
1526 
1527  g_return_val_if_fail(spec != NULL, FALSE);
1528  g_return_val_if_fail(color != NULL, FALSE);
1529 
1530  xcolormap = default_colormap();
1531 
1532  return parse_color(xcolormap, spec, color);
1533 }
1534 
1535 /* This is almost identical to gdk_colormap_free_colors.
1536  * Keep them in sync!
1537  */
1538 void
1540  gulong * in_pixels, gint in_npixels, gulong planes)
1541 {
1542  GdkColormapPrivateWin32 *private;
1543  gulong *pixels;
1544  gint npixels = 0;
1545  gint i;
1546 
1547  g_return_if_fail(colormap != NULL);
1548  g_return_if_fail(in_pixels != NULL);
1549 
1550  private = (GdkColormapPrivateWin32 *) colormap;
1551 
1552  if ((private->base.visual->type != GDK_VISUAL_PSEUDO_COLOR) &&
1553  (private->base.visual->type != GDK_VISUAL_GRAYSCALE))
1554  return;
1555 
1556  pixels = g_new(gulong, in_npixels);
1557 
1558  for (i = 0; i < in_npixels; i++) {
1559  gulong pixel = in_pixels[i];
1560 
1561  if (private->info[pixel].ref_count) {
1562  private->info[pixel].ref_count--;
1563 
1564  if (private->info[pixel].ref_count == 0) {
1565  pixels[npixels++] = pixel;
1566  if (!(private->info[pixel].flags & GDK_COLOR_WRITEABLE))
1567  g_hash_table_remove(private->hash,
1568  &colormap->colors[pixel]);
1569  private->info[pixel].flags = 0;
1570  }
1571  }
1572  }
1573 
1574  if (npixels)
1575  free_colors(private->xcolormap, pixels, npixels, planes);
1576 
1577  g_free(pixels);
1578 }
1579 
1580 /* This is almost identical to gdk_colors_free.
1581  * Keep them in sync!
1582  */
1583 void
1585  GdkColor * colors, gint ncolors)
1586 {
1587  GdkColormapPrivateWin32 *private;
1588  gulong *pixels;
1589  gint npixels = 0;
1590  gint i;
1591 
1592  g_return_if_fail(colormap != NULL);
1593  g_return_if_fail(colors != NULL);
1594 
1595  private = (GdkColormapPrivateWin32 *) colormap;
1596 
1597  if ((private->base.visual->type != GDK_VISUAL_PSEUDO_COLOR) &&
1598  (private->base.visual->type != GDK_VISUAL_GRAYSCALE))
1599  return;
1600 
1601  pixels = g_new(gulong, ncolors);
1602 
1603  for (i = 0; i < ncolors; i++) {
1604  gulong pixel = colors[i].pixel;
1605 
1606  if (private->info[pixel].ref_count) {
1607  private->info[pixel].ref_count--;
1608 
1609  if (private->info[pixel].ref_count == 0) {
1610  pixels[npixels++] = pixel;
1611  if (!(private->info[pixel].flags & GDK_COLOR_WRITEABLE))
1612  g_hash_table_remove(private->hash,
1613  &colormap->colors[pixel]);
1614  private->info[pixel].flags = 0;
1615  }
1616  }
1617  }
1618  if (npixels)
1619  free_colors(private->xcolormap, pixels, npixels, 0);
1620  g_free(pixels);
1621 }
1622 
1623 /********************
1624  * Color allocation *
1625  ********************/
1626 
1627 /* Try to allocate a single color using alloc_color. If it succeeds,
1628  * cache the result in our colormap, and store in ret.
1629  */
1630 static gboolean
1632  GdkColor * color, GdkColor * ret)
1633 {
1634  GdkColormapPrivateWin32 *private;
1635  XColor xcolor;
1636 
1637  private = (GdkColormapPrivateWin32 *) colormap;
1638 
1639  xcolor.peRed = color->red >> 8;
1640  xcolor.peGreen = color->green >> 8;
1641  xcolor.peBlue = color->blue >> 8;
1642 
1643  if (alloc_color(private->xcolormap, &xcolor, &ret->pixel)) {
1644  ret->red = (xcolor.peRed * 65535) / 255;
1645  ret->green = (xcolor.peGreen * 65535) / 255;
1646  ret->blue = (xcolor.peBlue * 65535) / 255;
1647 
1648  if ((guint)ret->pixel < (guint)colormap->size) {
1649  if (private->info[ret->pixel].ref_count) { /* got a duplicate */
1650  /* XXX */
1651  } else {
1652  colormap->colors[ret->pixel] = *color;
1653  private->info[ret->pixel].ref_count = 1;
1654 
1655  g_hash_table_insert(private->hash,
1656  &colormap->colors[ret->pixel],
1657  &colormap->colors[ret->pixel]);
1658  }
1659  }
1660  return TRUE;
1661  } else {
1662  return FALSE;
1663  }
1664 }
1665 
1666 static gint
1668  GdkColor * colors,
1669  gint ncolors,
1670  gboolean writable,
1671  gboolean best_match,
1672  gboolean * success)
1673 {
1674  GdkColormapPrivateWin32 *private;
1675  gulong *pixels;
1676  Status status;
1677  gint i, index;
1678 
1679  private = (GdkColormapPrivateWin32 *) colormap;
1680 
1681  if (private->private_val) {
1682  index = 0;
1683  for (i = 0; i < ncolors; i++) {
1684  while ((index < colormap->size)
1685  && (private->info[index].ref_count != 0))
1686  index++;
1687 
1688  if (index < colormap->size) {
1689  colors[i].pixel = index;
1690  success[i] = TRUE;
1691  private->info[index].ref_count++;
1692  private->info[i].flags |= GDK_COLOR_WRITEABLE;
1693  } else
1694  break;
1695  }
1696  return i;
1697  } else {
1698  pixels = g_new(gulong, ncolors);
1699  /* Allocation of a writable color cells */
1700 
1701  status = alloc_color_cells(private->xcolormap, FALSE, NULL,
1702  0, pixels, ncolors);
1703  if (status) {
1704  for (i = 0; i < ncolors; i++) {
1705  colors[i].pixel = pixels[i];
1706  private->info[pixels[i]].ref_count++;
1707  private->info[pixels[i]].flags |= GDK_COLOR_WRITEABLE;
1708  }
1709  }
1710 
1711  g_free(pixels);
1712 
1713  return status ? ncolors : 0;
1714  }
1715 }
1716 
1717 static gint
1719  GdkColor * colors,
1720  gint ncolors,
1721  gboolean writable,
1722  gboolean best_match, gboolean * success)
1723 {
1724  GdkColormapPrivateWin32 *private;
1725  gint i, index;
1726  XColor *store = g_new(XColor, ncolors);
1727  gint nstore = 0;
1728  gint nremaining = 0;
1729 
1730  private = (GdkColormapPrivateWin32 *) colormap;
1731  index = -1;
1732 
1733  /* First, store the colors we have room for */
1734 
1735  index = 0;
1736  for (i = 0; i < ncolors; i++) {
1737  if (!success[i]) {
1738  while ((index < colormap->size)
1739  && (private->info[index].ref_count != 0))
1740  index++;
1741 
1742  if (index < colormap->size) {
1743  store[nstore].peRed = colors[i].red >> 8;
1744  store[nstore].peBlue = colors[i].blue >> 8;
1745  store[nstore].peGreen = colors[i].green >> 8;
1746  nstore++;
1747 
1748  success[i] = TRUE;
1749 
1750  colors[i].pixel = index;
1751  private->info[index].ref_count++;
1752  } else
1753  nremaining++;
1754  }
1755  }
1756 
1757  if (SetPaletteEntries(private->xcolormap->palette,
1758  0, nstore, store) == 0)
1759  WIN32_GDI_FAILED("SetPaletteEntries");
1760  private->xcolormap->stale = TRUE;
1761 
1762  g_free(store);
1763 
1764  if (nremaining > 0 && best_match) {
1765  /* Get best matches for remaining colors */
1766 
1767  gchar *available = g_new(gchar, colormap->size);
1768  for (i = 0; i < colormap->size; i++)
1769  available[i] = TRUE;
1770 
1771  for (i = 0; i < ncolors; i++) {
1772  if (!success[i]) {
1773  index = gdk_colormap_match_color(colormap,
1774  &colors[i], available);
1775  if (index != -1) {
1776  colors[i] = colormap->colors[index];
1777  private->info[index].ref_count++;
1778 
1779  success[i] = TRUE;
1780  nremaining--;
1781  }
1782  }
1783  }
1784  g_free(available);
1785  }
1786 
1787  return (ncolors - nremaining);
1788 }
1789 
1790 static gint
1792  GdkColor * colors,
1793  gint ncolors,
1794  gboolean writable,
1795  gboolean best_match, gboolean * success)
1796 {
1797  GdkColormapPrivateWin32 *private;
1798  gint i, index;
1799  gint nremaining = 0;
1800  gint nfailed = 0;
1801 
1802  private = (GdkColormapPrivateWin32 *) colormap;
1803  index = -1;
1804 
1805  for (i = 0; i < ncolors; i++) {
1806  if (!success[i]) {
1807  if (gdk_colormap_alloc1(colormap, &colors[i], &colors[i]))
1808  success[i] = TRUE;
1809  else
1810  nremaining++;
1811  }
1812  }
1813 
1814 
1815  if (nremaining > 0 && best_match) {
1816  gchar *available = g_new(gchar, colormap->size);
1817  for (i = 0; i < colormap->size; i++)
1818  available[i] = ((private->info[i].ref_count == 0) ||
1819  !(private->info[i].flags && GDK_COLOR_WRITEABLE));
1820  gdk_colormap_sync(colormap, FALSE);
1821 
1822  while (nremaining > 0) {
1823  for (i = 0; i < ncolors; i++) {
1824  if (!success[i]) {
1825  index =
1826  gdk_colormap_match_color(colormap, &colors[i],
1827  available);
1828  if (index != -1) {
1829  if (private->info[index].ref_count) {
1830  private->info[index].ref_count++;
1831  colors[i] = colormap->colors[index];
1832  success[i] = TRUE;
1833  nremaining--;
1834  } else {
1835  if (gdk_colormap_alloc1(colormap,
1836  &colormap->colors[index],
1837  &colors[i])) {
1838  success[i] = TRUE;
1839  nremaining--;
1840  break;
1841  } else {
1842  available[index] = FALSE;
1843  }
1844  }
1845  } else {
1846  nfailed++;
1847  nremaining--;
1848  success[i] = 2; /* flag as permanent failure */
1849  }
1850  }
1851  }
1852  }
1853  g_free(available);
1854  }
1855 
1856  /* Change back the values we flagged as permanent failures */
1857  if (nfailed > 0) {
1858  for (i = 0; i < ncolors; i++)
1859  if (success[i] == 2)
1860  success[i] = FALSE;
1861  nremaining = nfailed;
1862  }
1863 
1864  return (ncolors - nremaining);
1865 }
1866 
1867 static gint
1869  GdkColor * colors,
1870  gint ncolors,
1871  gboolean writable,
1872  gboolean best_match,
1873  gboolean * success)
1874 {
1875  GdkColormapPrivateWin32 *private;
1876  GdkColor *lookup_color;
1877  gint i;
1878  gint nremaining = 0;
1879 
1880  private = (GdkColormapPrivateWin32 *) colormap;
1881 
1882  /* Check for an exact match among previously allocated colors */
1883 
1884  for (i = 0; i < ncolors; i++) {
1885  if (!success[i]) {
1886  lookup_color = g_hash_table_lookup(private->hash, &colors[i]);
1887  if (lookup_color) {
1888  private->info[lookup_color->pixel].ref_count++;
1889  colors[i].pixel = lookup_color->pixel;
1890  success[i] = TRUE;
1891  } else
1892  nremaining++;
1893  }
1894  }
1895 
1896  /* If that failed, we try to allocate a new color, or approxmiate
1897  * with what we can get if best_match is TRUE.
1898  */
1899  if (nremaining > 0) {
1900  if (private->private_val)
1901  return gdk_colormap_alloc_colors_private(colormap, colors,
1902  ncolors, writable,
1903  best_match, success);
1904  else
1905  return gdk_colormap_alloc_colors_shared(colormap, colors, ncolors,
1906  writable, best_match,
1907  success);
1908  } else
1909  return 0;
1910 }
1911 
1912 gint
1914  GdkColor * colors,
1915  gint ncolors,
1916  gboolean writable,
1917  gboolean best_match, gboolean * success)
1918 {
1919  GdkColormapPrivateWin32 *private;
1920  GdkVisual *visual;
1921  gint i;
1922  gint nremaining = 0;
1923  XColor xcolor;
1924 
1925  g_return_val_if_fail(colormap != NULL, FALSE);
1926  g_return_val_if_fail(colors != NULL, FALSE);
1927 
1928  private = (GdkColormapPrivateWin32 *) colormap;
1929 
1930  for (i = 0; i < ncolors; i++) {
1931  success[i] = FALSE;
1932  }
1933 
1934  switch (private->base.visual->type) {
1936  case GDK_VISUAL_GRAYSCALE:
1937  if (writable)
1938  return gdk_colormap_alloc_colors_writable(colormap, colors,
1939  ncolors, writable,
1940  best_match, success);
1941  else
1942  return gdk_colormap_alloc_colors_pseudocolor(colormap, colors,
1943  ncolors, writable,
1944  best_match, success);
1945  break;
1946 
1947  case GDK_VISUAL_TRUE_COLOR:
1948  visual = private->base.visual;
1949 
1950  for (i = 0; i < ncolors; i++) {
1951  colors[i].pixel =
1952  (((colors[i].red >> (16 - visual->red_prec)) << visual->
1953  red_shift) +
1954  ((colors[i].green >> (16 - visual->green_prec)) << visual->
1955  green_shift) +
1956  ((colors[i].blue >> (16 - visual->blue_prec)) << visual->
1957  blue_shift));
1958  success[i] = TRUE;
1959  }
1960  break;
1961 
1964  for (i = 0; i < ncolors; i++) {
1965  xcolor.peRed = colors[i].red >> 8;
1966  xcolor.peGreen = colors[i].green >> 8;
1967  xcolor.peBlue = colors[i].blue >> 8;
1968  if (alloc_color(private->xcolormap, &xcolor, &colors[i].pixel))
1969  success[i] = TRUE;
1970  else
1971  nremaining++;
1972  }
1973  break;
1974  }
1975  return nremaining;
1976 }
1977 
1979 {
1980  GdkColormapPrivateWin32 *private;
1981  XColor xcolor;
1982 
1983  g_return_val_if_fail(colormap != NULL, FALSE);
1984  g_return_val_if_fail(color != NULL, FALSE);
1985 
1986  private = (GdkColormapPrivateWin32 *) colormap;
1987 
1988  xcolor.peRed = color->red >> 8;
1989  xcolor.peGreen = color->green >> 8;
1990  xcolor.peBlue = color->blue >> 8;
1991 
1992  if (SetPaletteEntries(private->xcolormap->palette,
1993  color->pixel, 1, &xcolor) == 0)
1994  WIN32_GDI_FAILED("SetPaletteEntries");
1995  private->xcolormap->stale = TRUE;
1996 
1997  return TRUE;
1998 }
1999 
2000 static gint
2002  GdkColor * color, const gchar * available)
2003 {
2004  GdkColor *colors;
2005  guint sum, max;
2006  gint rdiff, gdiff, bdiff;
2007  gint i, index;
2008 
2009  g_return_val_if_fail(cmap != NULL, 0);
2010  g_return_val_if_fail(color != NULL, 0);
2011 
2012  colors = cmap->colors;
2013  max = 3 * (65536);
2014  index = -1;
2015 
2016  for (i = 0; i < cmap->size; i++) {
2017  if ((!available) || (available && available[i])) {
2018  rdiff = (color->red - colors[i].red);
2019  gdiff = (color->green - colors[i].green);
2020  bdiff = (color->blue - colors[i].blue);
2021 
2022  sum = ABS(rdiff) + ABS(gdiff) + ABS(bdiff);
2023 
2024  if (sum < max) {
2025  index = i;
2026  max = sum;
2027  }
2028  }
2029  }
2030 
2031  return index;
2032 }
2033 
2035 {
2036  GdkColormap *cmap;
2037 
2038  if (!colormap_hash)
2039  return NULL;
2040 
2041  cmap = g_hash_table_lookup(colormap_hash, &xcolormap);
2042  return cmap;
2043 }
2044 
2045 static void gdk_colormap_add(GdkColormap * cmap)
2046 {
2047  GdkColormapPrivateWin32 *private;
2048 
2049  if (!colormap_hash)
2052 
2053  private = (GdkColormapPrivateWin32 *) cmap;
2054 
2055  g_hash_table_insert(colormap_hash, &private->xcolormap, cmap);
2056 }
2057 
2059 {
2060  GdkColormapPrivateWin32 *private;
2061 
2062  if (!colormap_hash)
2065 
2066  private = (GdkColormapPrivateWin32 *) cmap;
2067 
2068  g_hash_table_remove(colormap_hash, &private->xcolormap);
2069 }
2070 
2072 {
2073  return (guint) * cmap;
2074 }
2075 
2077 {
2078  return (*a == *b);
2079 }
2080 
2081 #ifdef G_ENABLE_DEBUG
2082 
2083 gchar *gdk_win32_color_to_string(const GdkColor * color)
2084 {
2085  static char buf[100];
2086 
2087  sprintf(buf, "(%.04x,%.04x,%.04x):%.06x",
2088  color->red, color->green, color->blue, color->pixel);
2089 
2090  return buf;
2091 }
2092 
2093 #endif
static void gdk_colormap_remove(GdkColormap *cmap)
for(Int_t i=0;i< n;i++)
Definition: legend1.C:18
static GHashTable * colormap_hash
static Colormap default_colormap()
static gint gdk_colormap_alloc_colors_private(GdkColormap *colormap, GdkColor *colors, gint ncolors, gboolean writable, gboolean best_match, gboolean *success)
struct ColormapStruct * Colormap
gint gdk_colormap_alloc_colors(GdkColormap *colormap, GdkColor *colors, gint ncolors, gboolean writable, gboolean best_match, gboolean *success)
gboolean gdk_color_parse(const gchar *spec, GdkColor *color)
gint blue_prec
Definition: gdkvisual.h:56
unsigned int guint
Definition: g_types.h:51
GHashTable * g_hash_table_new(GHashFunc hash_func, GEqualFunc key_equal_func)
g_hash_table_new: : a function to create a hash value from a key.
Definition: ghash.c:112
#define numXColors
gint red_prec
Definition: gdkvisual.h:48
gint colormap_size
Definition: gdkvisual.h:43
void gdk_colormap_free_colors(GdkColormap *colormap, GdkColor *colors, gint ncolors)
#define g_return_val_if_fail(expr, val)
Definition: gmessages.h:300
void gdk_colormap_sync(GdkColormap *colormap, gboolean force)
void g_hash_table_destroy(GHashTable *hash_table)
g_hash_table_destroy: : a GHashTable.
Definition: ghash.c:171
static int alloc_color(Colormap colormap, XColor *color, gulong *pixelp)
static guint gdk_colormap_hash(Colormap *cmap)
static gint gdk_colormap_alloc_colors_shared(GdkColormap *colormap, GdkColor *colors, gint ncolors, gboolean writable, gboolean best_match, gboolean *success)
guint(* GHashFunc)(gconstpointer key)
Definition: g_types.h:80
TAlienJobStatus * status
Definition: TAlienJob.cxx:51
TArc * a
Definition: textangle.C:12
static XColorEntry xColors[]
static int compare_xcolor_entries(const void *a, const void *b)
void g_hash_table_insert(GHashTable *hash_table, gpointer key, gpointer value)
g_hash_table_insert: : a GHashTable.
Definition: ghash.c:285
static GdkColor red
Definition: testgdk.c:100
GdkColor * colors
Definition: gdkcolor.h:28
G_BEGIN_DECLS typedef char gchar
Definition: g_types.h:41
gboolean gdk_colors_alloc(GdkColormap *colormap, gint contiguous, gulong *planes, gint nplanes, gulong *pixels, gint npixels)
gushort red
Definition: gdkcolor.h:19
gboolean g_hash_table_remove(GHashTable *hash_table, gconstpointer key)
g_hash_table_remove: : a GHashTable.
Definition: ghash.c:377
static int FindColor(const char *name, GdkColor *colorPtr)
static GdkColor blue
Definition: testgdk.c:100
GdkColormap * gdk_colormap_lookup(Colormap xcolormap)
static GdkColor green
Definition: testgdk.c:100
gint gboolean
Definition: g_types.h:45
int Status
gint(* GCompareFunc)(gconstpointer a, gconstpointer b)
Definition: g_types.h:70
static void gdk_colormap_add(GdkColormap *cmap)
gushort green
Definition: gdkcolor.h:20
#define MIN_SYNC_TIME
unsigned long gulong
Definition: g_types.h:50
#define g_return_if_fail(expr)
Definition: gmessages.h:288
static Status alloc_color_cells(Colormap colormap, gboolean contig, unsigned long plane_masks_return[], unsigned int nplanes, unsigned long pixels_return[], unsigned int npixels)
GdkColormap * gdk_colormap_get_system(void)
#define g_new(struct_type, n_structs)
Definition: gmem.h:60
int gint
Definition: g_types.h:44
PALETTEENTRY XColor
#define g_new0(struct_type, n_structs)
Definition: gmem.h:62
typedefG_BEGIN_DECLS struct _GHashTable GHashTable
Definition: ghash.h:34
#define FALSE
Definition: gmacros.h:126
static void g_error(const gchar *format,...)
Definition: gmessages.h:128
gboolean gdk_color_change(GdkColormap *colormap, GdkColor *color)
HWND gdk_root_window
static void free_colors(Colormap colormap, gulong *pixels, gint npixels, gulong planes)
Long64_t entry
#define WIN32_GDI_FAILED(api)
#define ABS(a)
Definition: gmacros.h:140
Color * colors
Definition: X3DBuffer.c:19
void g_free(gpointer mem)
Definition: gmem.c:183
static void free_colormap(Colormap colormap)
GdkVisual * gdk_visual_get_system(void)
static GdkWindow * w
Definition: testgdk.c:96
gint green_prec
Definition: gdkvisual.h:52
GdkColormap * gdk_colormap_new(GdkVisual *visual, gint private_cmap)
void gdk_colors_free(GdkColormap *colormap, gulong *in_pixels, gint in_npixels, gulong planes)
static gboolean gdk_colormap_alloc1(GdkColormap *colormap, GdkColor *color, GdkColor *ret)
gboolean gdk_color_equal(const GdkColor *colora, const GdkColor *colorb)
Definition: gdkcolor.c:202
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
static gint gdk_colormap_alloc_colors_writable(GdkColormap *colormap, GdkColor *colors, gint ncolors, gboolean writable, gboolean best_match, gboolean *success)
#define name(a, b)
Definition: linkTestLib0.cpp:5
GdkVisualType type
Definition: gdkvisual.h:40
static void g_warning(const gchar *format,...)
Definition: gmessages.h:155
static Colormap create_colormap(HWND w, Visual *visual, gboolean alloc)
guint gdk_color_hash(const GdkColor *colora)
Definition: gdkcolor.c:195
gulong pixel
Definition: gdkcolor.h:18
#define TRUE
Definition: gmacros.h:130
HDC gdk_DC
#define NULL
Definition: Rtypes.h:82
gboolean parse_color(Colormap map, const char *spec, GdkColor *colorPtr)
void gdk_colormap_change(GdkColormap *colormap, gint ncolors)
gint gdk_colormap_get_system_size(void)
gushort blue
Definition: gdkcolor.h:21
gpointer g_hash_table_lookup(GHashTable *hash_table, gconstpointer key)
g_hash_table_lookup: : a GHashTable.
Definition: ghash.c:220
static gint gdk_colormap_alloc_colors_pseudocolor(GdkColormap *colormap, GdkColor *colors, gint ncolors, gboolean writable, gboolean best_match, gboolean *success)
void g_print(const gchar *format,...)
Definition: gmessages.c:788
void _gdk_colormap_real_destroy(GdkColormap *colormap)
static gint gdk_colormap_match_color(GdkColormap *cmap, GdkColor *color, const gchar *available)
#define strcasecmp
Definition: config.h:117
gint size
Definition: gdkcolor.h:27
static gint gdk_colormap_cmp(Colormap *a, Colormap *b)