2 * X11DRV OEM bitmap objects
4 * Copyright 1994, 1995 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(palette);
34 /* Palette indexed mode:
35 * logical palette -> mapping -> pixel
38 * Windows needs contiguous color space ( from 0 to n ) but
39 * it is possible only with the private colormap. Otherwise we
40 * have to map DC palette indices to real pixel values. With
41 * private colormaps it boils down to the identity mapping. The
42 * other special case is when we have a fixed color visual with
43 * the screendepth > 8 - we abandon palette mappings altogether
44 * because pixel values can be calculated without X server
48 #define NB_RESERVED_COLORS 20 /* number of fixed colors in system palette */
50 #define PC_SYS_USED 0x80 /* palentry is used (both system and logical) */
51 #define PC_SYS_RESERVED 0x40 /* system palentry is not to be mapped to */
53 static PALETTEENTRY *COLOR_sysPal; /* current system palette */
55 static int COLOR_gapStart = 256;
56 static int COLOR_gapEnd = -1;
57 static int COLOR_gapFilled = 0;
59 Colormap X11DRV_PALETTE_PaletteXColormap = 0;
60 UINT16 X11DRV_PALETTE_PaletteFlags = 0;
62 /* initialize to zero to handle abortive X11DRV_PALETTE_VIRTUAL visuals */
63 ColorShifts X11DRV_PALETTE_default_shifts = { {0,0,0,}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0} };
64 static int X11DRV_PALETTE_Graymax = 0;
66 static int palette_size;
68 /* First free dynamic color cell, 0 = full palette, -1 = fixed palette */
69 static int X11DRV_PALETTE_firstFree = 0;
70 static unsigned char X11DRV_PALETTE_freeList[256];
72 static XContext palette_context; /* X context to associate a color mapping to a palette */
74 static CRITICAL_SECTION palette_cs;
75 static CRITICAL_SECTION_DEBUG critsect_debug =
78 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
79 0, 0, { (DWORD_PTR)(__FILE__ ": palette_cs") }
81 static CRITICAL_SECTION palette_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
83 /**********************************************************************/
85 /* Map an EGA index (0..15) to a pixel value in the system color space. */
87 int X11DRV_PALETTE_mapEGAPixel[16];
89 /**********************************************************************/
91 #define NB_COLORCUBE_START_INDEX 63
92 #define NB_PALETTE_EMPTY_VALUE -1
94 /* Maps entry in the system palette to X pixel value */
95 int *X11DRV_PALETTE_PaletteToXPixel = NULL;
97 /* Maps pixel to the entry in the system palette */
98 int *X11DRV_PALETTE_XPixelToPalette = NULL;
100 /**********************************************************************/
102 static BOOL X11DRV_PALETTE_BuildPrivateMap( const PALETTEENTRY *sys_pal_template );
103 static BOOL X11DRV_PALETTE_BuildSharedMap( const PALETTEENTRY *sys_pal_template );
104 static void X11DRV_PALETTE_ComputeShifts(unsigned long maskbits, ChannelShift *physical, ChannelShift *to_logical);
105 static void X11DRV_PALETTE_FillDefaultColors( const PALETTEENTRY *sys_pal_template );
106 static void X11DRV_PALETTE_FormatSystemPalette(void);
107 static BOOL X11DRV_PALETTE_CheckSysColor( const PALETTEENTRY *sys_pal_template, COLORREF c);
108 static int X11DRV_PALETTE_LookupSystemXPixel(COLORREF col);
111 /***********************************************************************
112 * palette_get_mapping
114 static int *palette_get_mapping( HPALETTE hpal )
119 if (XFindContext( gdi_display, (XID)hpal, palette_context, (char **)&mapping )) mapping = NULL;
125 /***********************************************************************
126 * palette_set_mapping
128 static void palette_set_mapping( HPALETTE hpal, int *mapping )
131 XSaveContext( gdi_display, (XID)hpal, palette_context, (char *)mapping );
136 /***********************************************************************
139 * Initialize color management.
141 int X11DRV_PALETTE_Init(void)
143 int mask, white, black;
146 PALETTEENTRY sys_pal_template[NB_RESERVED_COLORS];
148 TRACE("initializing palette manager...\n");
151 palette_context = XUniqueContext();
153 white = WhitePixel( gdi_display, DefaultScreen(gdi_display) );
154 black = BlackPixel( gdi_display, DefaultScreen(gdi_display) );
156 for( mask = 1; !((white & mask)^(black & mask)); mask <<= 1 )
158 X11DRV_PALETTE_PaletteFlags = (white & mask) ? X11DRV_PALETTE_WHITESET : 0;
159 palette_size = visual->map_entries;
161 switch(visual->class)
164 X11DRV_PALETTE_PaletteFlags |= X11DRV_PALETTE_VIRTUAL;
168 if (private_color_map)
170 XSetWindowAttributes win_attr;
172 X11DRV_PALETTE_PaletteXColormap = XCreateColormap( gdi_display, root_window,
174 if (X11DRV_PALETTE_PaletteXColormap)
176 X11DRV_PALETTE_PaletteFlags |= (X11DRV_PALETTE_PRIVATE | X11DRV_PALETTE_WHITESET);
179 for( white = palette_size - 1; !(white & 1); white >>= 1 )
182 if( root_window != DefaultRootWindow(gdi_display) )
184 win_attr.colormap = X11DRV_PALETTE_PaletteXColormap;
185 XChangeWindowAttributes( gdi_display, root_window, CWColormap, &win_attr );
189 X11DRV_PALETTE_PaletteXColormap = XCreateColormap(gdi_display, root_window,
197 X11DRV_PALETTE_PaletteXColormap = XCreateColormap(gdi_display, root_window,
199 X11DRV_PALETTE_PaletteFlags |= X11DRV_PALETTE_FIXED;
200 X11DRV_PALETTE_Graymax = (1 << screen_depth)-1;
205 X11DRV_PALETTE_PaletteFlags |= X11DRV_PALETTE_VIRTUAL;
207 int *depths,nrofdepths;
208 /* FIXME: hack to detect XFree32 XF_VGA16 ... We just have
212 depths = XListDepths(gdi_display,DefaultScreen(gdi_display),&nrofdepths);
213 if ((nrofdepths==2) && ((depths[0]==4) || depths[1]==4)) {
215 for( white = palette_size - 1; !(white & 1); white >>= 1 )
217 X11DRV_PALETTE_PaletteFlags = (white & mask) ? X11DRV_PALETTE_WHITESET : 0;
218 X11DRV_PALETTE_PaletteXColormap = XCreateColormap(gdi_display, root_window,
223 X11DRV_PALETTE_PaletteXColormap = XCreateColormap(gdi_display, root_window,
225 X11DRV_PALETTE_PaletteFlags |= X11DRV_PALETTE_FIXED;
226 X11DRV_PALETTE_ComputeShifts(visual->red_mask, &X11DRV_PALETTE_default_shifts.physicalRed, &X11DRV_PALETTE_default_shifts.logicalRed);
227 X11DRV_PALETTE_ComputeShifts(visual->green_mask, &X11DRV_PALETTE_default_shifts.physicalGreen, &X11DRV_PALETTE_default_shifts.logicalGreen);
228 X11DRV_PALETTE_ComputeShifts(visual->blue_mask, &X11DRV_PALETTE_default_shifts.physicalBlue, &X11DRV_PALETTE_default_shifts.logicalBlue);
236 TRACE(" visual class %i (%i)\n", visual->class, monoPlane);
238 GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, NB_RESERVED_COLORS, sys_pal_template );
240 if( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL )
246 if ((mapping = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int) * NB_RESERVED_COLORS )))
247 palette_set_mapping( GetStockObject(DEFAULT_PALETTE), mapping );
249 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
250 X11DRV_PALETTE_BuildPrivateMap( sys_pal_template );
252 X11DRV_PALETTE_BuildSharedMap( sys_pal_template );
254 /* Build free list */
256 if( X11DRV_PALETTE_firstFree != -1 )
257 X11DRV_PALETTE_FormatSystemPalette();
259 X11DRV_PALETTE_FillDefaultColors( sys_pal_template );
260 palette_size = visual->map_entries;
266 /***********************************************************************
267 * X11DRV_PALETTE_Cleanup
269 * Free external colors we grabbed in the FillDefaultPalette()
271 void X11DRV_PALETTE_Cleanup(void)
273 if( COLOR_gapFilled )
276 XFreeColors(gdi_display, X11DRV_PALETTE_PaletteXColormap,
277 (unsigned long*)(X11DRV_PALETTE_PaletteToXPixel + COLOR_gapStart),
283 /***********************************************************************
284 * X11DRV_PALETTE_ComputeShifts
286 * Calculate conversion parameters for direct mapped visuals
288 static void X11DRV_PALETTE_ComputeShifts(unsigned long maskbits, ChannelShift *physical, ChannelShift *to_logical)
303 for(i=0;!(maskbits&1);i++)
307 physical->max = maskbits;
309 for(i=0;maskbits!=0;i++)
313 if (physical->scale>8)
315 /* On FreeBSD, VNC's default 32bpp mode is bgrabb (ffc00000,3ff800,7ff)!
316 * So we adjust the shifts to also normalize the color fields to
317 * the Win32 standard of 8 bits per color.
319 to_logical->shift=physical->shift+(physical->scale-8);
321 to_logical->max=0xff;
323 to_logical->shift=physical->shift;
324 to_logical->scale=physical->scale;
325 to_logical->max=physical->max;
329 /***********************************************************************
330 * X11DRV_PALETTE_BuildPrivateMap
332 * Allocate colorcells and initialize mapping tables.
334 static BOOL X11DRV_PALETTE_BuildPrivateMap( const PALETTEENTRY *sys_pal_template )
336 /* Private colormap - identity mapping */
341 if((COLOR_sysPal = HeapAlloc(GetProcessHeap(), 0, sizeof(PALETTEENTRY)*palette_size)) == NULL) {
342 WARN("Unable to allocate the system palette\n");
346 TRACE("Building private map - %i palette entries\n", palette_size);
348 /* Allocate system palette colors */
351 for( i=0; i < palette_size; i++ )
353 if( i < NB_RESERVED_COLORS/2 )
355 color.red = sys_pal_template[i].peRed * 65535 / 255;
356 color.green = sys_pal_template[i].peGreen * 65535 / 255;
357 color.blue = sys_pal_template[i].peBlue * 65535 / 255;
358 COLOR_sysPal[i] = sys_pal_template[i];
359 COLOR_sysPal[i].peFlags |= PC_SYS_USED;
361 else if( i >= palette_size - NB_RESERVED_COLORS/2 )
363 int j = NB_RESERVED_COLORS + i - palette_size;
364 color.red = sys_pal_template[j].peRed * 65535 / 255;
365 color.green = sys_pal_template[j].peGreen * 65535 / 255;
366 color.blue = sys_pal_template[j].peBlue * 65535 / 255;
367 COLOR_sysPal[i] = sys_pal_template[j];
368 COLOR_sysPal[i].peFlags |= PC_SYS_USED;
371 color.flags = DoRed | DoGreen | DoBlue;
373 XStoreColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &color);
375 /* Set EGA mapping if color is from the first or last eight */
378 X11DRV_PALETTE_mapEGAPixel[i] = color.pixel;
379 else if (i >= palette_size - 8 )
380 X11DRV_PALETTE_mapEGAPixel[i - (palette_size - 16)] = color.pixel;
384 X11DRV_PALETTE_XPixelToPalette = X11DRV_PALETTE_PaletteToXPixel = NULL;
386 COLOR_gapStart = 256; COLOR_gapEnd = -1;
388 X11DRV_PALETTE_firstFree = (palette_size > NB_RESERVED_COLORS)?NB_RESERVED_COLORS/2 : -1;
393 /***********************************************************************
394 * X11DRV_PALETTE_BuildSharedMap
396 * Allocate colorcells and initialize mapping tables.
398 static BOOL X11DRV_PALETTE_BuildSharedMap( const PALETTEENTRY *sys_pal_template )
401 unsigned long sysPixel[NB_RESERVED_COLORS];
402 unsigned long* pixDynMapping = NULL;
403 unsigned long plane_masks[1];
405 int diff, r, g, b, bp = 0, wp = 1;
407 unsigned int max = 256;
409 XColor defaultColors[256];
411 /* Copy the first bunch of colors out of the default colormap to prevent
412 * colormap flashing as much as possible. We're likely to get the most
413 * important Window Manager colors, etc in the first 128 colors */
414 defaultCM = DefaultColormap( gdi_display, DefaultScreen(gdi_display) );
416 if (copy_default_colors > 256) copy_default_colors = 256;
417 for (i = 0; i < copy_default_colors; i++)
418 defaultColors[i].pixel = (long) i;
420 XQueryColors(gdi_display, defaultCM, &defaultColors[0], copy_default_colors);
421 for (i = 0; i < copy_default_colors; i++)
422 XAllocColor( gdi_display, X11DRV_PALETTE_PaletteXColormap, &defaultColors[i] );
424 if (alloc_system_colors > 256) alloc_system_colors = 256;
425 else if (alloc_system_colors < 20) alloc_system_colors = 20;
426 TRACE("%d colors configured.\n", alloc_system_colors);
428 TRACE("Building shared map - %i palette entries\n", palette_size);
430 /* Be nice and allocate system colors as read-only */
432 for( i = 0; i < NB_RESERVED_COLORS; i++ )
434 color.red = sys_pal_template[i].peRed * 65535 / 255;
435 color.green = sys_pal_template[i].peGreen * 65535 / 255;
436 color.blue = sys_pal_template[i].peBlue * 65535 / 255;
437 color.flags = DoRed | DoGreen | DoBlue;
439 if (!XAllocColor( gdi_display, X11DRV_PALETTE_PaletteXColormap, &color ))
445 WARN("Not enough colors for the full system palette.\n");
447 bp = BlackPixel(gdi_display, DefaultScreen(gdi_display));
448 wp = WhitePixel(gdi_display, DefaultScreen(gdi_display));
450 max = (0xffffffff)>>(32 - screen_depth);
458 /* reinit color (XAllocColor() may change it)
459 * and map to the best shared colorcell */
461 color.red = sys_pal_template[i].peRed * 65535 / 255;
462 color.green = sys_pal_template[i].peGreen * 65535 / 255;
463 color.blue = sys_pal_template[i].peBlue * 65535 / 255;
465 best.pixel = best.red = best.green = best.blue = 0;
466 for( c.pixel = 0, diff = 0x7fffffff; c.pixel < max; c.pixel += step )
468 XQueryColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &c);
469 r = (c.red - color.red)>>8;
470 g = (c.green - color.green)>>8;
471 b = (c.blue - color.blue)>>8;
473 if( r < diff ) { best = c; diff = r; }
476 if( XAllocColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &best) )
477 color.pixel = best.pixel;
478 else color.pixel = (i < NB_RESERVED_COLORS/2)? bp : wp;
481 sysPixel[i] = color.pixel;
483 TRACE("syscolor(%x) -> pixel %i\n", *(const COLORREF*)(sys_pal_template+i),
486 /* Set EGA mapping if color in the first or last eight */
489 X11DRV_PALETTE_mapEGAPixel[i] = color.pixel;
490 else if (i >= NB_RESERVED_COLORS - 8 )
491 X11DRV_PALETTE_mapEGAPixel[i - (NB_RESERVED_COLORS-16)] = color.pixel;
495 /* now allocate changeable set */
497 if( !(X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED) )
499 int c_min = 0, c_max = palette_size, c_val;
501 TRACE("Dynamic colormap...\n");
503 /* let's become the first client that actually follows
504 * X guidelines and does binary search...
507 if((pixDynMapping = HeapAlloc(GetProcessHeap(), 0, sizeof(long)*palette_size)) == NULL) {
508 WARN("Out of memory while building system palette.\n");
513 /* comment this out if you want to debug palette init */
514 XGrabServer(gdi_display);
516 while( c_max - c_min > 0 )
518 c_val = (c_max + c_min)/2 + (c_max + c_min)%2;
520 if( !XAllocColorCells(gdi_display, X11DRV_PALETTE_PaletteXColormap, False,
521 plane_masks, 0, pixDynMapping, c_val) )
525 XFreeColors(gdi_display, X11DRV_PALETTE_PaletteXColormap, pixDynMapping, c_val, 0);
530 if( c_min > alloc_system_colors - NB_RESERVED_COLORS)
531 c_min = alloc_system_colors - NB_RESERVED_COLORS;
533 c_min = (c_min/2) + (c_min/2); /* need even set for split palette */
536 if( !XAllocColorCells(gdi_display, X11DRV_PALETTE_PaletteXColormap, False,
537 plane_masks, 0, pixDynMapping, c_min) )
539 WARN("Inexplicable failure during colorcell allocation.\n");
543 palette_size = c_min + NB_RESERVED_COLORS;
545 XUngrabServer(gdi_display);
548 TRACE("adjusted size %i colorcells\n", palette_size);
550 else if( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL )
552 /* virtual colorspace - ToPhysical takes care of
553 * color translations but we have to allocate full palette
554 * to maintain compatibility
557 TRACE("Virtual colorspace - screendepth %i\n", screen_depth);
559 else palette_size = NB_RESERVED_COLORS; /* system palette only - however we can alloc a bunch
560 * of colors and map to them */
562 TRACE("Shared system palette uses %i colors.\n", palette_size);
564 /* set gap to account for pixel shortage. It has to be right in the center
565 * of the system palette because otherwise raster ops get screwed. */
567 if( palette_size >= 256 )
568 { COLOR_gapStart = 256; COLOR_gapEnd = -1; }
570 { COLOR_gapStart = palette_size/2; COLOR_gapEnd = 255 - palette_size/2; }
572 X11DRV_PALETTE_firstFree = ( palette_size > NB_RESERVED_COLORS &&
573 (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL || !(X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED)) )
574 ? NB_RESERVED_COLORS/2 : -1;
576 COLOR_sysPal = HeapAlloc(GetProcessHeap(),0,sizeof(PALETTEENTRY)*256);
577 if(COLOR_sysPal == NULL) {
578 ERR("Unable to allocate the system palette!\n");
579 HeapFree(GetProcessHeap(), 0, pixDynMapping);
583 /* setup system palette entry <-> pixel mappings and fill in 20 fixed entries */
585 if (screen_depth <= 8)
587 X11DRV_PALETTE_XPixelToPalette = HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(int) );
588 if(X11DRV_PALETTE_XPixelToPalette == NULL) {
589 ERR("Out of memory: XPixelToPalette!\n");
590 HeapFree(GetProcessHeap(), 0, pixDynMapping);
593 for( i = 0; i < 256; i++ )
594 X11DRV_PALETTE_XPixelToPalette[i] = NB_PALETTE_EMPTY_VALUE;
597 /* for hicolor visuals PaletteToPixel mapping is used to skip
598 * RGB->pixel calculation in X11DRV_PALETTE_ToPhysical().
601 X11DRV_PALETTE_PaletteToXPixel = HeapAlloc(GetProcessHeap(),0,sizeof(int)*256);
602 if(X11DRV_PALETTE_PaletteToXPixel == NULL) {
603 ERR("Out of memory: PaletteToXPixel!\n");
604 HeapFree(GetProcessHeap(), 0, pixDynMapping);
608 for( i = j = 0; i < 256; i++ )
610 if( i >= COLOR_gapStart && i <= COLOR_gapEnd )
612 X11DRV_PALETTE_PaletteToXPixel[i] = NB_PALETTE_EMPTY_VALUE;
613 COLOR_sysPal[i].peFlags = 0; /* mark as unused */
617 if( i < NB_RESERVED_COLORS/2 )
619 X11DRV_PALETTE_PaletteToXPixel[i] = sysPixel[i];
620 COLOR_sysPal[i] = sys_pal_template[i];
621 COLOR_sysPal[i].peFlags |= PC_SYS_USED;
623 else if( i >= 256 - NB_RESERVED_COLORS/2 )
625 X11DRV_PALETTE_PaletteToXPixel[i] = sysPixel[(i + NB_RESERVED_COLORS) - 256];
626 COLOR_sysPal[i] = sys_pal_template[(i + NB_RESERVED_COLORS) - 256];
627 COLOR_sysPal[i].peFlags |= PC_SYS_USED;
629 else if( pixDynMapping )
630 X11DRV_PALETTE_PaletteToXPixel[i] = pixDynMapping[j++];
632 X11DRV_PALETTE_PaletteToXPixel[i] = i;
634 TRACE("index %i -> pixel %i\n", i, X11DRV_PALETTE_PaletteToXPixel[i]);
636 if( X11DRV_PALETTE_XPixelToPalette )
637 X11DRV_PALETTE_XPixelToPalette[X11DRV_PALETTE_PaletteToXPixel[i]] = i;
640 HeapFree(GetProcessHeap(), 0, pixDynMapping);
645 /***********************************************************************
646 * Colormap Initialization
648 static void X11DRV_PALETTE_FillDefaultColors( const PALETTEENTRY *sys_pal_template )
650 /* initialize unused entries to what Windows uses as a color
651 * cube - based on Greg Kreider's code.
655 int red, no_r, inc_r;
656 int green, no_g, inc_g;
657 int blue, no_b, inc_b;
659 if (palette_size <= NB_RESERVED_COLORS)
661 while (i*i*i < (palette_size - NB_RESERVED_COLORS)) i++;
662 no_r = no_g = no_b = --i;
663 if ((no_r * (no_g+1) * no_b) < (palette_size - NB_RESERVED_COLORS)) no_g++;
664 if ((no_r * no_g * (no_b+1)) < (palette_size - NB_RESERVED_COLORS)) no_b++;
665 inc_r = (255 - NB_COLORCUBE_START_INDEX)/no_r;
666 inc_g = (255 - NB_COLORCUBE_START_INDEX)/no_g;
667 inc_b = (255 - NB_COLORCUBE_START_INDEX)/no_b;
671 idx = X11DRV_PALETTE_firstFree;
674 for (blue = NB_COLORCUBE_START_INDEX; blue < 256 && idx; blue += inc_b )
675 for (green = NB_COLORCUBE_START_INDEX; green < 256 && idx; green += inc_g )
676 for (red = NB_COLORCUBE_START_INDEX; red < 256 && idx; red += inc_r )
680 if( red == NB_COLORCUBE_START_INDEX && green == red && blue == green ) continue;
682 COLOR_sysPal[idx].peRed = red;
683 COLOR_sysPal[idx].peGreen = green;
684 COLOR_sysPal[idx].peBlue = blue;
688 if( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL )
690 ColorShifts *shifts = &X11DRV_PALETTE_default_shifts;
691 if (shifts->physicalRed.max != 255) no_r = (red * shifts->physicalRed.max) / 255;
692 if (shifts->physicalGreen.max != 255) no_g = (green * shifts->physicalGreen.max) / 255;
693 if (shifts->physicalBlue.max != 255) no_b = (blue * shifts->physicalBlue.max) / 255;
695 X11DRV_PALETTE_PaletteToXPixel[idx] = (no_r << shifts->physicalRed.shift) | (no_g << shifts->physicalGreen.shift) | (no_b << shifts->physicalBlue.shift);
697 else if( !(X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED) )
700 color.pixel = (X11DRV_PALETTE_PaletteToXPixel)? X11DRV_PALETTE_PaletteToXPixel[idx] : idx;
701 color.red = COLOR_sysPal[idx].peRed << 8;
702 color.green = COLOR_sysPal[idx].peGreen << 8;
703 color.blue = COLOR_sysPal[idx].peBlue << 8;
704 color.flags = DoRed | DoGreen | DoBlue;
705 XStoreColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &color);
707 idx = X11DRV_PALETTE_freeList[idx];
710 /* try to fill some entries in the "gap" with
711 * what's already in the colormap - they will be
712 * mappable to but not changeable. */
714 if( COLOR_gapStart < COLOR_gapEnd && X11DRV_PALETTE_XPixelToPalette )
719 max = alloc_system_colors - (256 - (COLOR_gapEnd - COLOR_gapStart));
720 for ( i = 0, idx = COLOR_gapStart; i < 256 && idx <= COLOR_gapEnd; i++ )
721 if( X11DRV_PALETTE_XPixelToPalette[i] == NB_PALETTE_EMPTY_VALUE )
725 XQueryColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &xc);
726 r = xc.red>>8; g = xc.green>>8; b = xc.blue>>8;
728 if( xc.pixel < 256 && X11DRV_PALETTE_CheckSysColor( sys_pal_template, RGB(r, g, b)) &&
729 XAllocColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &xc) )
731 X11DRV_PALETTE_XPixelToPalette[xc.pixel] = idx;
732 X11DRV_PALETTE_PaletteToXPixel[idx] = xc.pixel;
733 *(COLORREF*)(COLOR_sysPal + idx) = RGB(r, g, b);
734 COLOR_sysPal[idx++].peFlags |= PC_SYS_USED;
735 if( --max <= 0 ) break;
738 COLOR_gapFilled = idx - COLOR_gapStart;
744 /***********************************************************************
745 * X11DRV_IsSolidColor
747 * Check whether 'color' can be represented with a solid color.
749 BOOL X11DRV_IsSolidColor( COLORREF color )
752 const PALETTEENTRY *pEntry = COLOR_sysPal;
754 if (color & 0xff000000) return TRUE; /* indexed color */
756 if (!color || (color == 0xffffff)) return TRUE; /* black or white */
758 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL) return TRUE; /* no palette */
760 EnterCriticalSection( &palette_cs );
761 for (i = 0; i < palette_size ; i++, pEntry++)
763 if( i < COLOR_gapStart || i > COLOR_gapEnd )
764 if ((GetRValue(color) == pEntry->peRed) &&
765 (GetGValue(color) == pEntry->peGreen) &&
766 (GetBValue(color) == pEntry->peBlue))
768 LeaveCriticalSection( &palette_cs );
772 LeaveCriticalSection( &palette_cs );
777 /***********************************************************************
778 * X11DRV_PALETTE_ToLogical
780 * Return RGB color for given X pixel.
782 COLORREF X11DRV_PALETTE_ToLogical(X11DRV_PDEVICE *physDev, int pixel)
785 ColorShifts *shifts = &X11DRV_PALETTE_default_shifts;
787 if(physDev->color_shifts)
788 shifts = physDev->color_shifts;
791 /* truecolor visual */
793 if (screen_depth >= 24) return pixel;
796 /* check for hicolor visuals first */
798 if ( (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED) && !X11DRV_PALETTE_Graymax )
800 color.red = (pixel >> shifts->logicalRed.shift) & shifts->logicalRed.max;
801 if (shifts->logicalRed.scale<8)
802 color.red= color.red << (8-shifts->logicalRed.scale) |
803 color.red >> (2*shifts->logicalRed.scale-8);
804 color.green = (pixel >> shifts->logicalGreen.shift) & shifts->logicalGreen.max;
805 if (shifts->logicalGreen.scale<8)
806 color.green=color.green << (8-shifts->logicalGreen.scale) |
807 color.green >> (2*shifts->logicalGreen.scale-8);
808 color.blue = (pixel >> shifts->logicalBlue.shift) & shifts->logicalBlue.max;
809 if (shifts->logicalBlue.scale<8)
810 color.blue= color.blue << (8-shifts->logicalBlue.scale) |
811 color.blue >> (2*shifts->logicalBlue.scale-8);
812 return RGB(color.red,color.green,color.blue);
815 /* check if we can bypass X */
817 if ((screen_depth <= 8) && (pixel < 256) &&
818 !(X11DRV_PALETTE_PaletteFlags & (X11DRV_PALETTE_VIRTUAL | X11DRV_PALETTE_FIXED)) ) {
820 EnterCriticalSection( &palette_cs );
821 ret = *(COLORREF *)(COLOR_sysPal + (X11DRV_PALETTE_XPixelToPalette ? X11DRV_PALETTE_XPixelToPalette[pixel]: pixel)) & 0x00ffffff;
822 LeaveCriticalSection( &palette_cs );
828 XQueryColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &color);
830 return RGB(color.red >> 8, color.green >> 8, color.blue >> 8);
834 /***********************************************************************
835 * X11DRV_SysPaletteLookupPixel
837 static int X11DRV_SysPaletteLookupPixel( COLORREF col, BOOL skipReserved )
839 int i, best = 0, diff = 0x7fffffff;
842 for( i = 0; i < palette_size && diff ; i++ )
844 if( !(COLOR_sysPal[i].peFlags & PC_SYS_USED) ||
845 (skipReserved && COLOR_sysPal[i].peFlags & PC_SYS_RESERVED) )
848 r = COLOR_sysPal[i].peRed - GetRValue(col);
849 g = COLOR_sysPal[i].peGreen - GetGValue(col);
850 b = COLOR_sysPal[i].peBlue - GetBValue(col);
854 if( r < diff ) { best = i; diff = r; }
860 static inline BOOL colour_is_brighter(RGBQUAD c1, RGBQUAD c2)
862 return (c1.rgbRed * c1.rgbRed + c1.rgbGreen * c1.rgbGreen + c1.rgbBlue * c1.rgbBlue) >
863 (c2.rgbRed * c2.rgbRed + c2.rgbGreen * c2.rgbGreen + c2.rgbBlue * c2.rgbBlue);
866 /***********************************************************************
867 * X11DRV_PALETTE_ToPhysical
869 * Return the physical color closest to 'color'.
871 int X11DRV_PALETTE_ToPhysical( X11DRV_PDEVICE *physDev, COLORREF color )
874 HPALETTE hPal = physDev ? GetCurrentObject(physDev->hdc, OBJ_PAL ) : GetStockObject(DEFAULT_PALETTE);
875 unsigned char spec_type = color >> 24;
876 int *mapping = palette_get_mapping( hPal );
878 ColorShifts *shifts = &X11DRV_PALETTE_default_shifts;
880 if(physDev->color_shifts)
881 shifts = physDev->color_shifts;
883 if ( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED )
885 /* there is no colormap limitation; we are going to have to compute
886 * the pixel value from the visual information stored earlier
889 unsigned long red, green, blue;
890 unsigned idx = color & 0xffff;
895 case 0x10: /* DIBINDEX */
896 if( GetDIBColorTable( physDev->hdc, idx, 1, &quad ) != 1 ) {
897 WARN("DIBINDEX(%x) : idx %d is out of bounds, assuming black\n", color , idx);
900 color = RGB( quad.rgbRed, quad.rgbGreen, quad.rgbBlue );
903 case 1: /* PALETTEINDEX */
904 if (!GetPaletteEntries( hPal, idx, 1, &entry ))
906 WARN("PALETTEINDEX(%x) : idx %d is out of bounds, assuming black\n", color, idx);
909 if (mapping) return mapping[idx];
910 color = RGB( entry.peRed, entry.peGreen, entry.peBlue );
915 /* fall through to RGB */
918 if (physDev && (physDev->depth == 1) )
923 if (GetDIBColorTable( physDev->hdc, 0, 2, table ) == 2)
925 if(!colour_is_brighter(table[1], table[0])) white = 0;
927 return (((color >> 16) & 0xff) +
928 ((color >> 8) & 0xff) + (color & 0xff) > 255*3/2) ? white : 1 - white;
933 red = GetRValue(color); green = GetGValue(color); blue = GetBValue(color);
935 if (X11DRV_PALETTE_Graymax)
937 /* grayscale only; return scaled value */
938 return ( (red * 30 + green * 59 + blue * 11) * X11DRV_PALETTE_Graymax) / 25500;
942 /* scale each individually and construct the TrueColor pixel value */
943 if (shifts->physicalRed.scale < 8)
944 red = red >> (8-shifts->physicalRed.scale);
945 else if (shifts->physicalRed.scale > 8)
946 red = red << (shifts->physicalRed.scale-8) |
947 red >> (16-shifts->physicalRed.scale);
948 if (shifts->physicalGreen.scale < 8)
949 green = green >> (8-shifts->physicalGreen.scale);
950 else if (shifts->physicalGreen.scale > 8)
951 green = green << (shifts->physicalGreen.scale-8) |
952 green >> (16-shifts->physicalGreen.scale);
953 if (shifts->physicalBlue.scale < 8)
954 blue = blue >> (8-shifts->physicalBlue.scale);
955 else if (shifts->physicalBlue.scale > 8)
956 blue = blue << (shifts->physicalBlue.scale-8) |
957 blue >> (16-shifts->physicalBlue.scale);
959 return (red << shifts->physicalRed.shift) | (green << shifts->physicalGreen.shift) | (blue << shifts->physicalBlue.shift);
965 WARN("Palette %p is not realized\n", hPal);
967 switch(spec_type) /* we have to peruse DC and system palette */
971 /* fall through to RGB */
974 if (physDev && (physDev->depth == 1) )
979 if (GetDIBColorTable( physDev->hdc, 0, 2, table ) == 2)
981 if(!colour_is_brighter(table[1], table[0]))
984 return (((color >> 16) & 0xff) +
985 ((color >> 8) & 0xff) + (color & 0xff) > 255*3/2) ? white : 1 - white;
988 EnterCriticalSection( &palette_cs );
989 index = X11DRV_SysPaletteLookupPixel( color, FALSE);
990 if (X11DRV_PALETTE_PaletteToXPixel) index = X11DRV_PALETTE_PaletteToXPixel[index];
991 LeaveCriticalSection( &palette_cs );
993 /* TRACE(palette,"RGB(%lx) -> pixel %i\n", color, index);
996 case 1: /* PALETTEINDEX */
997 index = color & 0xffff;
998 if (!GetPaletteEntries( hPal, index, 1, &entry ))
999 WARN("PALETTEINDEX(%x) : index %i is out of bounds\n", color, index);
1000 else if (mapping) index = mapping[index];
1002 /* TRACE(palette,"PALETTEINDEX(%04x) -> pixel %i\n", (WORD)color, index);
1005 case 2: /* PALETTERGB */
1006 index = GetNearestPaletteIndex( hPal, color );
1007 if (mapping) index = mapping[index];
1008 /* TRACE(palette,"PALETTERGB(%lx) -> pixel %i\n", color, index);
1016 /***********************************************************************
1017 * X11DRV_PALETTE_LookupPixel
1019 int X11DRV_PALETTE_LookupPixel(COLORREF color )
1021 unsigned char spec_type = color >> 24;
1023 /* Only accept RGB which has spec_type = 0 */
1029 if ( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED )
1031 unsigned long red, green, blue;
1032 red = GetRValue(color); green = GetGValue(color); blue = GetBValue(color);
1034 if (X11DRV_PALETTE_Graymax)
1036 /* grayscale only; return scaled value */
1037 return ( (red * 30 + green * 59 + blue * 11) * X11DRV_PALETTE_Graymax) / 25500;
1041 ColorShifts *shifts = &X11DRV_PALETTE_default_shifts;
1042 /* scale each individually and construct the TrueColor pixel value */
1043 if (shifts->physicalRed.scale < 8)
1044 red = red >> (8-shifts->physicalRed.scale);
1045 else if (shifts->physicalRed.scale > 8)
1046 red = red << (shifts->physicalRed.scale-8) |
1047 red >> (16-shifts->physicalRed.scale);
1048 if (shifts->physicalGreen.scale < 8)
1049 green = green >> (8-shifts->physicalGreen.scale);
1050 else if (shifts->physicalGreen.scale > 8)
1051 green = green << (shifts->physicalGreen.scale-8) |
1052 green >> (16-shifts->physicalGreen.scale);
1053 if (shifts->physicalBlue.scale < 8)
1054 blue = blue >> (8-shifts->physicalBlue.scale);
1055 else if (shifts->physicalBlue.scale > 8)
1056 blue = blue << (shifts->physicalBlue.scale-8) |
1057 blue >> (16-shifts->physicalBlue.scale);
1059 return (red << shifts->physicalRed.shift) | (green << shifts->physicalGreen.shift) | (blue << shifts->physicalBlue.shift);
1065 HPALETTE hPal = GetStockObject(DEFAULT_PALETTE);
1066 int *mapping = palette_get_mapping( hPal );
1069 WARN("Palette %p is not realized\n", hPal);
1071 EnterCriticalSection( &palette_cs );
1072 index = X11DRV_SysPaletteLookupPixel( color, FALSE);
1073 if (X11DRV_PALETTE_PaletteToXPixel)
1074 index = X11DRV_PALETTE_PaletteToXPixel[index];
1075 LeaveCriticalSection( &palette_cs );
1081 /***********************************************************************
1082 * X11DRV_PALETTE_LookupSystemXPixel
1084 static int X11DRV_PALETTE_LookupSystemXPixel(COLORREF col)
1086 int i, best = 0, diff = 0x7fffffff;
1087 int size = palette_size;
1090 for( i = 0; i < size && diff ; i++ )
1092 if( i == NB_RESERVED_COLORS/2 )
1094 int newi = size - NB_RESERVED_COLORS/2;
1098 r = COLOR_sysPal[i].peRed - GetRValue(col);
1099 g = COLOR_sysPal[i].peGreen - GetGValue(col);
1100 b = COLOR_sysPal[i].peBlue - GetBValue(col);
1102 r = r*r + g*g + b*b;
1104 if( r < diff ) { best = i; diff = r; }
1107 return (X11DRV_PALETTE_PaletteToXPixel)? X11DRV_PALETTE_PaletteToXPixel[best] : best;
1110 /***********************************************************************
1111 * X11DRV_PALETTE_FormatSystemPalette
1113 static void X11DRV_PALETTE_FormatSystemPalette(void)
1115 /* Build free list so we'd have an easy way to find
1116 * out if there are any available colorcells.
1119 int i, j = X11DRV_PALETTE_firstFree = NB_RESERVED_COLORS/2;
1121 COLOR_sysPal[j].peFlags = 0;
1122 for( i = NB_RESERVED_COLORS/2 + 1 ; i < 256 - NB_RESERVED_COLORS/2 ; i++ )
1123 if( i < COLOR_gapStart || i > COLOR_gapEnd )
1125 COLOR_sysPal[i].peFlags = 0; /* unused tag */
1126 X11DRV_PALETTE_freeList[j] = i; /* next */
1129 X11DRV_PALETTE_freeList[j] = 0;
1132 /***********************************************************************
1133 * X11DRV_PALETTE_CheckSysColor
1135 static BOOL X11DRV_PALETTE_CheckSysColor( const PALETTEENTRY *sys_pal_template, COLORREF c)
1138 for( i = 0; i < NB_RESERVED_COLORS; i++ )
1139 if( c == (*(const COLORREF*)(sys_pal_template + i) & 0x00ffffff) )
1145 /***********************************************************************
1146 * X11DRV_LookupSysPaletteExact
1148 static int X11DRV_LookupSysPaletteExact( BYTE r, BYTE g, BYTE b )
1151 for( i = 0; i < palette_size; i++ )
1153 if( COLOR_sysPal[i].peFlags & PC_SYS_USED ) /* skips gap */
1154 if( COLOR_sysPal[i].peRed == r &&
1155 COLOR_sysPal[i].peGreen == g &&
1156 COLOR_sysPal[i].peBlue == b )
1163 /***********************************************************************
1164 * RealizePalette (X11DRV.@)
1166 UINT X11DRV_RealizePalette( X11DRV_PDEVICE *physDev, HPALETTE hpal, BOOL primary )
1170 UINT i, iRemapped = 0;
1171 int *prev_mapping, *mapping;
1172 PALETTEENTRY entries[256];
1175 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL) return 0;
1177 if (!GetObjectW( hpal, sizeof(num_entries), &num_entries )) return 0;
1179 /* initialize palette mapping table */
1180 prev_mapping = palette_get_mapping( hpal );
1182 mapping = HeapReAlloc( GetProcessHeap(), 0, prev_mapping, sizeof(int)*num_entries);
1184 mapping = HeapAlloc( GetProcessHeap(), 0, sizeof(int)*num_entries);
1186 if(mapping == NULL) {
1187 ERR("Unable to allocate new mapping -- memory exhausted!\n");
1190 palette_set_mapping( hpal, mapping );
1192 if (num_entries > 256)
1194 FIXME( "more than 256 entries not supported\n" );
1197 if (!(num_entries = GetPaletteEntries( hpal, 0, num_entries, entries ))) return 0;
1199 /* reset dynamic system palette entries */
1201 EnterCriticalSection( &palette_cs );
1202 if( primary && X11DRV_PALETTE_firstFree != -1)
1203 X11DRV_PALETTE_FormatSystemPalette();
1205 for (i = 0; i < num_entries; i++)
1210 /* Even though the docs say that only one flag is to be set,
1211 * they are a bitmask. At least one app sets more than one at
1213 if ( entries[i].peFlags & PC_EXPLICIT ) {
1214 /* palette entries are indices into system palette */
1215 index = *(WORD*)&entries[i];
1216 if( index > 255 || (index >= COLOR_gapStart && index <= COLOR_gapEnd) )
1218 WARN("PC_EXPLICIT: idx %d out of system palette, assuming black.\n", index);
1221 if( X11DRV_PALETTE_PaletteToXPixel ) index = X11DRV_PALETTE_PaletteToXPixel[index];
1223 if ( entries[i].peFlags & PC_RESERVED ) {
1224 /* forbid future mappings to this entry */
1225 flag |= PC_SYS_RESERVED;
1228 if (! (entries[i].peFlags & PC_NOCOLLAPSE) ) {
1229 /* try to collapse identical colors */
1230 index = X11DRV_LookupSysPaletteExact( entries[i].peRed, entries[i].peGreen, entries[i].peBlue );
1235 if( X11DRV_PALETTE_firstFree > 0 )
1238 index = X11DRV_PALETTE_firstFree; /* ought to be available */
1239 X11DRV_PALETTE_firstFree = X11DRV_PALETTE_freeList[index];
1241 color.pixel = (X11DRV_PALETTE_PaletteToXPixel) ? X11DRV_PALETTE_PaletteToXPixel[index] : index;
1242 color.red = entries[i].peRed << 8;
1243 color.green = entries[i].peGreen << 8;
1244 color.blue = entries[i].peBlue << 8;
1245 color.flags = DoRed | DoGreen | DoBlue;
1247 XStoreColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &color);
1248 wine_tsx11_unlock();
1250 COLOR_sysPal[index] = entries[i];
1251 COLOR_sysPal[index].peFlags = flag;
1252 X11DRV_PALETTE_freeList[index] = 0;
1254 if( X11DRV_PALETTE_PaletteToXPixel ) index = X11DRV_PALETTE_PaletteToXPixel[index];
1256 else if ( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL )
1258 index = X11DRV_PALETTE_LookupPixel( RGB( entries[i].peRed, entries[i].peGreen, entries[i].peBlue ));
1261 /* we have to map to existing entry in the system palette */
1263 index = X11DRV_SysPaletteLookupPixel( RGB( entries[i].peRed, entries[i].peGreen, entries[i].peBlue ),
1267 if( X11DRV_PALETTE_PaletteToXPixel ) index = X11DRV_PALETTE_PaletteToXPixel[index];
1270 if( !prev_mapping || mapping[i] != index ) iRemapped++;
1273 TRACE("entry %i (%x) -> pixel %i\n", i, *(COLORREF*)&entries[i], index);
1276 LeaveCriticalSection( &palette_cs );
1281 /***********************************************************************
1282 * UnrealizePalette (X11DRV.@)
1284 BOOL X11DRV_UnrealizePalette( HPALETTE hpal )
1286 int *mapping = palette_get_mapping( hpal );
1291 XDeleteContext( gdi_display, (XID)hpal, palette_context );
1292 wine_tsx11_unlock();
1293 HeapFree( GetProcessHeap(), 0, mapping );
1299 /***********************************************************************
1300 * GetSystemPaletteEntries (X11DRV.@)
1302 UINT X11DRV_GetSystemPaletteEntries( X11DRV_PDEVICE *physDev, UINT start, UINT count,
1303 LPPALETTEENTRY entries )
1307 if (!entries) return palette_size;
1308 if (start >= palette_size) return 0;
1309 if (start + count >= palette_size) count = palette_size - start;
1311 EnterCriticalSection( &palette_cs );
1312 for (i = 0; i < count; i++)
1314 entries[i].peRed = COLOR_sysPal[start + i].peRed;
1315 entries[i].peGreen = COLOR_sysPal[start + i].peGreen;
1316 entries[i].peBlue = COLOR_sysPal[start + i].peBlue;
1317 entries[i].peFlags = 0;
1318 TRACE("\tidx(%02x) -> RGB(%08x)\n", start + i, *(COLORREF*)(entries + i) );
1320 LeaveCriticalSection( &palette_cs );
1325 /***********************************************************************
1326 * GetNearestColor (X11DRV.@)
1328 COLORREF X11DRV_GetNearestColor( X11DRV_PDEVICE *physDev, COLORREF color )
1330 unsigned char spec_type = color >> 24;
1333 if (!palette_size) return color;
1335 if (spec_type == 1 || spec_type == 2)
1337 /* we need logical palette for PALETTERGB and PALETTEINDEX colorrefs */
1341 HPALETTE hpal = GetCurrentObject( physDev->hdc, OBJ_PAL );
1343 if (!hpal) hpal = GetStockObject( DEFAULT_PALETTE );
1345 if (spec_type == 2) /* PALETTERGB */
1346 index = GetNearestPaletteIndex( hpal, color );
1347 else /* PALETTEINDEX */
1348 index = LOWORD(color);
1350 if (!GetPaletteEntries( hpal, index, 1, &entry ))
1352 WARN("RGB(%x) : idx %d is out of bounds, assuming NULL\n", color, index );
1353 if (!GetPaletteEntries( hpal, 0, 1, &entry )) return CLR_INVALID;
1355 color = RGB( entry.peRed, entry.peGreen, entry.peBlue );
1357 color &= 0x00ffffff;
1358 EnterCriticalSection( &palette_cs );
1359 nearest = (0x00ffffff & *(COLORREF*)(COLOR_sysPal + X11DRV_SysPaletteLookupPixel(color, FALSE)));
1360 LeaveCriticalSection( &palette_cs );
1362 TRACE("(%06x): returning %06x\n", color, nearest );
1367 /***********************************************************************
1368 * RealizeDefaultPalette (X11DRV.@)
1370 UINT X11DRV_RealizeDefaultPalette( X11DRV_PDEVICE *physDev )
1374 if (palette_size && GetObjectType(physDev->hdc) != OBJ_MEMDC)
1376 /* lookup is needed to account for SetSystemPaletteUse() stuff */
1377 int i, index, *mapping = palette_get_mapping( GetStockObject(DEFAULT_PALETTE) );
1378 PALETTEENTRY entries[NB_RESERVED_COLORS];
1380 GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, NB_RESERVED_COLORS, entries );
1381 EnterCriticalSection( &palette_cs );
1382 for( i = 0; i < NB_RESERVED_COLORS; i++ )
1384 index = X11DRV_PALETTE_LookupSystemXPixel( RGB(entries[i].peRed,
1386 entries[i].peBlue) );
1387 /* mapping is allocated in COLOR_InitPalette() */
1388 if( index != mapping[i] )
1394 LeaveCriticalSection( &palette_cs );