2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-04-01 10:16:08 +02:00
|
|
|
* X11DRV OEM bitmap objects
|
|
|
|
*
|
|
|
|
* Copyright 1994, 1995 Alexandre Julliard
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-04-01 10:16:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2006-11-17 14:38:43 +01:00
|
|
|
#include <stdarg.h>
|
1999-04-01 10:16:08 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
2006-11-17 14:38:43 +01:00
|
|
|
#include "winbase.h"
|
1999-04-01 10:16:08 +02:00
|
|
|
#include "x11drv.h"
|
2002-06-02 23:40:24 +02:00
|
|
|
#include "wine/debug.h"
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(palette);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
/* Palette indexed mode:
|
|
|
|
* logical palette -> mapping -> pixel
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
|
|
|
* Windows needs contiguous color space ( from 0 to n ) but
|
1999-04-01 10:16:08 +02:00
|
|
|
* it is possible only with the private colormap. Otherwise we
|
2002-06-01 01:06:46 +02:00
|
|
|
* have to map DC palette indices to real pixel values. With
|
1999-04-01 10:16:08 +02:00
|
|
|
* private colormaps it boils down to the identity mapping. The
|
2002-06-01 01:06:46 +02:00
|
|
|
* other special case is when we have a fixed color visual with
|
|
|
|
* the screendepth > 8 - we abandon palette mappings altogether
|
|
|
|
* because pixel values can be calculated without X server
|
1999-04-01 10:16:08 +02:00
|
|
|
* assistance.
|
|
|
|
*
|
|
|
|
* Windows palette manager is described in the
|
|
|
|
* http://premium.microsoft.com/msdn/library/techart/f30/f34/f40/d4d/sa942.htm
|
|
|
|
*/
|
|
|
|
|
2006-11-17 14:38:43 +01:00
|
|
|
#define NB_RESERVED_COLORS 20 /* number of fixed colors in system palette */
|
|
|
|
|
2006-11-17 13:13:34 +01:00
|
|
|
#define PC_SYS_USED 0x80 /* palentry is used (both system and logical) */
|
|
|
|
#define PC_SYS_RESERVED 0x40 /* system palentry is not to be mapped to */
|
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
static PALETTEENTRY *COLOR_sysPal; /* current system palette */
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2002-05-02 23:49:50 +02:00
|
|
|
static int COLOR_gapStart = 256;
|
|
|
|
static int COLOR_gapEnd = -1;
|
|
|
|
static int COLOR_gapFilled = 0;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
Colormap X11DRV_PALETTE_PaletteXColormap = 0;
|
|
|
|
UINT16 X11DRV_PALETTE_PaletteFlags = 0;
|
|
|
|
|
2001-12-21 20:18:48 +01:00
|
|
|
typedef struct {
|
|
|
|
int shift;
|
|
|
|
int scale;
|
|
|
|
int max;
|
|
|
|
} ColorShifts;
|
|
|
|
|
|
|
|
/* initialize to zero to handle abortive X11DRV_PALETTE_VIRTUAL visuals */
|
|
|
|
static ColorShifts X11DRV_PALETTE_PRed = {0,0,0};
|
|
|
|
static ColorShifts X11DRV_PALETTE_LRed = {0,0,0};
|
|
|
|
static ColorShifts X11DRV_PALETTE_PGreen = {0,0,0};
|
|
|
|
static ColorShifts X11DRV_PALETTE_LGreen = {0,0,0};
|
|
|
|
static ColorShifts X11DRV_PALETTE_PBlue = {0,0,0};
|
|
|
|
static ColorShifts X11DRV_PALETTE_LBlue = {0,0,0};
|
|
|
|
static int X11DRV_PALETTE_Graymax = 0;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2001-07-28 02:18:02 +02:00
|
|
|
static int palette_size;
|
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
/* First free dynamic color cell, 0 = full palette, -1 = fixed palette */
|
2002-06-01 01:06:46 +02:00
|
|
|
static int X11DRV_PALETTE_firstFree = 0;
|
1999-04-01 10:16:08 +02:00
|
|
|
static unsigned char X11DRV_PALETTE_freeList[256];
|
|
|
|
|
2006-11-17 14:38:43 +01:00
|
|
|
static XContext palette_context; /* X context to associate a color mapping to a palette */
|
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
/**********************************************************************/
|
|
|
|
|
|
|
|
/* Map an EGA index (0..15) to a pixel value in the system color space. */
|
|
|
|
|
|
|
|
int X11DRV_PALETTE_mapEGAPixel[16];
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
|
|
|
#define NB_COLORCUBE_START_INDEX 63
|
2002-05-29 02:33:44 +02:00
|
|
|
#define NB_PALETTE_EMPTY_VALUE -1
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
/* Maps entry in the system palette to X pixel value */
|
|
|
|
int *X11DRV_PALETTE_PaletteToXPixel = NULL;
|
|
|
|
|
|
|
|
/* Maps pixel to the entry in the system palette */
|
|
|
|
int *X11DRV_PALETTE_XPixelToPalette = NULL;
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
static BOOL X11DRV_PALETTE_BuildPrivateMap( const PALETTEENTRY *sys_pal_template );
|
|
|
|
static BOOL X11DRV_PALETTE_BuildSharedMap( const PALETTEENTRY *sys_pal_template );
|
2001-12-21 20:18:48 +01:00
|
|
|
static void X11DRV_PALETTE_ComputeShifts(unsigned long maskbits, ColorShifts *physical, ColorShifts *to_logical);
|
2002-06-02 23:40:24 +02:00
|
|
|
static void X11DRV_PALETTE_FillDefaultColors( const PALETTEENTRY *sys_pal_template );
|
1999-04-01 10:16:08 +02:00
|
|
|
static void X11DRV_PALETTE_FormatSystemPalette(void);
|
2002-06-02 23:40:24 +02:00
|
|
|
static BOOL X11DRV_PALETTE_CheckSysColor( const PALETTEENTRY *sys_pal_template, COLORREF c);
|
1999-04-15 17:52:59 +02:00
|
|
|
static int X11DRV_PALETTE_LookupSystemXPixel(COLORREF col);
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2001-06-19 05:32:44 +02:00
|
|
|
|
2006-11-17 14:36:34 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* palette_get_mapping
|
|
|
|
*/
|
|
|
|
static int *palette_get_mapping( HPALETTE hpal )
|
|
|
|
{
|
2006-11-17 14:38:43 +01:00
|
|
|
int *mapping;
|
2006-11-17 14:36:34 +01:00
|
|
|
|
2006-11-17 14:38:43 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
if (XFindContext( gdi_display, (XID)hpal, palette_context, (char **)&mapping )) mapping = NULL;
|
|
|
|
wine_tsx11_unlock();
|
2006-11-17 14:36:34 +01:00
|
|
|
return mapping;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* palette_set_mapping
|
|
|
|
*/
|
2006-11-17 14:38:43 +01:00
|
|
|
static void palette_set_mapping( HPALETTE hpal, int *mapping )
|
2006-11-17 14:36:34 +01:00
|
|
|
{
|
2006-11-17 14:38:43 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
XSaveContext( gdi_display, (XID)hpal, palette_context, (char *)mapping );
|
|
|
|
wine_tsx11_unlock();
|
2006-11-17 14:36:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* COLOR_Init
|
|
|
|
*
|
|
|
|
* Initialize color management.
|
|
|
|
*/
|
2001-07-28 02:18:02 +02:00
|
|
|
int X11DRV_PALETTE_Init(void)
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
int mask, white, black;
|
|
|
|
int monoPlane;
|
2006-11-17 14:38:43 +01:00
|
|
|
int *mapping;
|
2002-06-02 23:40:24 +02:00
|
|
|
PALETTEENTRY sys_pal_template[NB_RESERVED_COLORS];
|
1999-04-01 10:16:08 +02:00
|
|
|
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("initializing palette manager...\n");
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2006-11-17 14:38:43 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
palette_context = XUniqueContext();
|
|
|
|
wine_tsx11_unlock();
|
2001-05-11 02:17:47 +02:00
|
|
|
white = WhitePixel( gdi_display, DefaultScreen(gdi_display) );
|
|
|
|
black = BlackPixel( gdi_display, DefaultScreen(gdi_display) );
|
1999-04-01 10:16:08 +02:00
|
|
|
monoPlane = 1;
|
|
|
|
for( mask = 1; !((white & mask)^(black & mask)); mask <<= 1 )
|
|
|
|
monoPlane++;
|
|
|
|
X11DRV_PALETTE_PaletteFlags = (white & mask) ? X11DRV_PALETTE_WHITESET : 0;
|
2001-07-28 02:18:02 +02:00
|
|
|
palette_size = visual->map_entries;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
switch(visual->class)
|
|
|
|
{
|
|
|
|
case DirectColor:
|
|
|
|
X11DRV_PALETTE_PaletteFlags |= X11DRV_PALETTE_VIRTUAL;
|
|
|
|
case GrayScale:
|
|
|
|
case PseudoColor:
|
2003-11-21 01:17:33 +01:00
|
|
|
wine_tsx11_lock();
|
2001-06-19 05:32:44 +02:00
|
|
|
if (private_color_map)
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
XSetWindowAttributes win_attr;
|
|
|
|
|
2003-11-21 01:17:33 +01:00
|
|
|
X11DRV_PALETTE_PaletteXColormap = XCreateColormap( gdi_display, root_window,
|
|
|
|
visual, AllocAll );
|
1999-04-01 10:16:08 +02:00
|
|
|
if (X11DRV_PALETTE_PaletteXColormap)
|
|
|
|
{
|
|
|
|
X11DRV_PALETTE_PaletteFlags |= (X11DRV_PALETTE_PRIVATE | X11DRV_PALETTE_WHITESET);
|
|
|
|
|
|
|
|
monoPlane = 1;
|
2001-07-28 02:18:02 +02:00
|
|
|
for( white = palette_size - 1; !(white & 1); white >>= 1 )
|
1999-04-01 10:16:08 +02:00
|
|
|
monoPlane++;
|
|
|
|
|
2001-05-11 02:17:47 +02:00
|
|
|
if( root_window != DefaultRootWindow(gdi_display) )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
win_attr.colormap = X11DRV_PALETTE_PaletteXColormap;
|
2003-11-21 01:17:33 +01:00
|
|
|
XChangeWindowAttributes( gdi_display, root_window, CWColormap, &win_attr );
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
}
|
2004-02-20 02:04:51 +01:00
|
|
|
} else {
|
|
|
|
X11DRV_PALETTE_PaletteXColormap = XCreateColormap(gdi_display, root_window,
|
|
|
|
visual, AllocNone);
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
2003-11-21 01:17:33 +01:00
|
|
|
wine_tsx11_unlock();
|
1999-04-01 10:16:08 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case StaticGray:
|
2003-11-21 01:17:33 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
X11DRV_PALETTE_PaletteXColormap = XCreateColormap(gdi_display, root_window,
|
|
|
|
visual, AllocNone);
|
1999-04-01 10:16:08 +02:00
|
|
|
X11DRV_PALETTE_PaletteFlags |= X11DRV_PALETTE_FIXED;
|
2001-05-11 02:17:47 +02:00
|
|
|
X11DRV_PALETTE_Graymax = (1 << screen_depth)-1;
|
2003-11-21 01:17:33 +01:00
|
|
|
wine_tsx11_unlock();
|
1999-04-01 10:16:08 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TrueColor:
|
|
|
|
X11DRV_PALETTE_PaletteFlags |= X11DRV_PALETTE_VIRTUAL;
|
|
|
|
case StaticColor: {
|
|
|
|
int *depths,nrofdepths;
|
|
|
|
/* FIXME: hack to detect XFree32 XF_VGA16 ... We just have
|
|
|
|
* depths 1 and 4
|
|
|
|
*/
|
2003-11-21 01:17:33 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
depths = XListDepths(gdi_display,DefaultScreen(gdi_display),&nrofdepths);
|
1999-04-01 10:16:08 +02:00
|
|
|
if ((nrofdepths==2) && ((depths[0]==4) || depths[1]==4)) {
|
|
|
|
monoPlane = 1;
|
2001-07-28 02:18:02 +02:00
|
|
|
for( white = palette_size - 1; !(white & 1); white >>= 1 )
|
1999-04-01 10:16:08 +02:00
|
|
|
monoPlane++;
|
|
|
|
X11DRV_PALETTE_PaletteFlags = (white & mask) ? X11DRV_PALETTE_WHITESET : 0;
|
2003-11-21 01:17:33 +01:00
|
|
|
X11DRV_PALETTE_PaletteXColormap = XCreateColormap(gdi_display, root_window,
|
|
|
|
visual, AllocNone);
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
2003-11-21 01:17:33 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
X11DRV_PALETTE_PaletteXColormap = XCreateColormap(gdi_display, root_window,
|
|
|
|
visual, AllocNone);
|
|
|
|
X11DRV_PALETTE_PaletteFlags |= X11DRV_PALETTE_FIXED;
|
|
|
|
X11DRV_PALETTE_ComputeShifts(visual->red_mask, &X11DRV_PALETTE_PRed, &X11DRV_PALETTE_LRed);
|
|
|
|
X11DRV_PALETTE_ComputeShifts(visual->green_mask, &X11DRV_PALETTE_PGreen, &X11DRV_PALETTE_LGreen);
|
|
|
|
X11DRV_PALETTE_ComputeShifts(visual->blue_mask, &X11DRV_PALETTE_PBlue, &X11DRV_PALETTE_LBlue);
|
|
|
|
}
|
|
|
|
XFree(depths);
|
|
|
|
wine_tsx11_unlock();
|
2001-12-21 20:18:48 +01:00
|
|
|
break;
|
2001-03-28 03:45:08 +02:00
|
|
|
}
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE(" visual class %i (%i)\n", visual->class, monoPlane);
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, NB_RESERVED_COLORS, sys_pal_template );
|
|
|
|
|
2006-11-17 14:38:43 +01:00
|
|
|
if ((mapping = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int) * NB_RESERVED_COLORS )))
|
|
|
|
palette_set_mapping( GetStockObject(DEFAULT_PALETTE), mapping );
|
|
|
|
|
2003-11-09 01:35:29 +01:00
|
|
|
if( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL )
|
|
|
|
{
|
|
|
|
palette_size = 0;
|
|
|
|
}
|
1999-04-01 10:16:08 +02:00
|
|
|
else
|
2003-11-09 01:35:29 +01:00
|
|
|
{
|
|
|
|
if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
|
|
|
|
X11DRV_PALETTE_BuildPrivateMap( sys_pal_template );
|
|
|
|
else
|
|
|
|
X11DRV_PALETTE_BuildSharedMap( sys_pal_template );
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2003-11-09 01:35:29 +01:00
|
|
|
/* Build free list */
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2003-11-09 01:35:29 +01:00
|
|
|
if( X11DRV_PALETTE_firstFree != -1 )
|
|
|
|
X11DRV_PALETTE_FormatSystemPalette();
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2003-11-09 01:35:29 +01:00
|
|
|
X11DRV_PALETTE_FillDefaultColors( sys_pal_template );
|
2001-07-28 02:18:02 +02:00
|
|
|
palette_size = visual->map_entries;
|
2003-11-09 01:35:29 +01:00
|
|
|
}
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2001-07-28 02:18:02 +02:00
|
|
|
return palette_size;
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_PALETTE_Cleanup
|
|
|
|
*
|
|
|
|
* Free external colors we grabbed in the FillDefaultPalette()
|
|
|
|
*/
|
|
|
|
void X11DRV_PALETTE_Cleanup(void)
|
|
|
|
{
|
|
|
|
if( COLOR_gapFilled )
|
2003-11-21 01:17:33 +01:00
|
|
|
{
|
|
|
|
wine_tsx11_lock();
|
|
|
|
XFreeColors(gdi_display, X11DRV_PALETTE_PaletteXColormap,
|
2002-06-01 01:06:46 +02:00
|
|
|
(unsigned long*)(X11DRV_PALETTE_PaletteToXPixel + COLOR_gapStart),
|
1999-04-01 10:16:08 +02:00
|
|
|
COLOR_gapFilled, 0);
|
2003-11-21 01:17:33 +01:00
|
|
|
wine_tsx11_unlock();
|
|
|
|
}
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_PALETTE_ComputeShifts
|
|
|
|
*
|
|
|
|
* Calculate conversion parameters for direct mapped visuals
|
|
|
|
*/
|
2001-12-21 20:18:48 +01:00
|
|
|
static void X11DRV_PALETTE_ComputeShifts(unsigned long maskbits, ColorShifts *physical, ColorShifts *to_logical)
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (maskbits==0)
|
|
|
|
{
|
2001-12-21 20:18:48 +01:00
|
|
|
physical->shift=0;
|
|
|
|
physical->scale=0;
|
|
|
|
physical->max=0;
|
|
|
|
to_logical->shift=0;
|
|
|
|
to_logical->scale=0;
|
|
|
|
to_logical->max=0;
|
1999-04-01 10:16:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;!(maskbits&1);i++)
|
|
|
|
maskbits >>= 1;
|
|
|
|
|
2001-12-21 20:18:48 +01:00
|
|
|
physical->shift = i;
|
|
|
|
physical->max = maskbits;
|
2001-10-17 19:45:33 +02:00
|
|
|
|
|
|
|
for(i=0;maskbits!=0;i++)
|
|
|
|
maskbits >>= 1;
|
2001-12-21 20:18:48 +01:00
|
|
|
physical->scale = i;
|
|
|
|
|
|
|
|
if (physical->scale>8)
|
|
|
|
{
|
|
|
|
/* On FreeBSD, VNC's default 32bpp mode is bgrabb (ffc00000,3ff800,7ff)!
|
|
|
|
* So we adjust the shifts to also normalize the color fields to
|
|
|
|
* the Win32 standard of 8 bits per color.
|
|
|
|
*/
|
|
|
|
to_logical->shift=physical->shift+(physical->scale-8);
|
|
|
|
to_logical->scale=8;
|
|
|
|
to_logical->max=0xff;
|
|
|
|
} else {
|
|
|
|
to_logical->shift=physical->shift;
|
|
|
|
to_logical->scale=physical->scale;
|
|
|
|
to_logical->max=physical->max;
|
|
|
|
}
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_PALETTE_BuildPrivateMap
|
|
|
|
*
|
|
|
|
* Allocate colorcells and initialize mapping tables.
|
|
|
|
*/
|
2002-06-02 23:40:24 +02:00
|
|
|
static BOOL X11DRV_PALETTE_BuildPrivateMap( const PALETTEENTRY *sys_pal_template )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
/* Private colormap - identity mapping */
|
|
|
|
|
|
|
|
XColor color;
|
2002-06-01 01:06:46 +02:00
|
|
|
int i;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2005-03-24 22:01:35 +01:00
|
|
|
if((COLOR_sysPal = HeapAlloc(GetProcessHeap(), 0, sizeof(PALETTEENTRY)*palette_size)) == NULL) {
|
2005-05-06 17:44:31 +02:00
|
|
|
WARN("Unable to allocate the system palette\n");
|
2000-04-09 20:41:15 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2001-07-28 02:18:02 +02:00
|
|
|
TRACE("Building private map - %i palette entries\n", palette_size);
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* Allocate system palette colors */
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2003-11-21 06:41:56 +01:00
|
|
|
wine_tsx11_lock();
|
2001-07-28 02:18:02 +02:00
|
|
|
for( i=0; i < palette_size; i++ )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
if( i < NB_RESERVED_COLORS/2 )
|
|
|
|
{
|
2002-06-02 23:40:24 +02:00
|
|
|
color.red = sys_pal_template[i].peRed * 65535 / 255;
|
|
|
|
color.green = sys_pal_template[i].peGreen * 65535 / 255;
|
|
|
|
color.blue = sys_pal_template[i].peBlue * 65535 / 255;
|
|
|
|
COLOR_sysPal[i] = sys_pal_template[i];
|
|
|
|
COLOR_sysPal[i].peFlags |= PC_SYS_USED;
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
2001-07-28 02:18:02 +02:00
|
|
|
else if( i >= palette_size - NB_RESERVED_COLORS/2 )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2001-07-28 02:18:02 +02:00
|
|
|
int j = NB_RESERVED_COLORS + i - palette_size;
|
2002-06-02 23:40:24 +02:00
|
|
|
color.red = sys_pal_template[j].peRed * 65535 / 255;
|
|
|
|
color.green = sys_pal_template[j].peGreen * 65535 / 255;
|
|
|
|
color.blue = sys_pal_template[j].peBlue * 65535 / 255;
|
|
|
|
COLOR_sysPal[i] = sys_pal_template[j];
|
|
|
|
COLOR_sysPal[i].peFlags |= PC_SYS_USED;
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
color.flags = DoRed | DoGreen | DoBlue;
|
|
|
|
color.pixel = i;
|
2003-11-21 06:41:56 +01:00
|
|
|
XStoreColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &color);
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
/* Set EGA mapping if color is from the first or last eight */
|
|
|
|
|
|
|
|
if (i < 8)
|
|
|
|
X11DRV_PALETTE_mapEGAPixel[i] = color.pixel;
|
2001-07-28 02:18:02 +02:00
|
|
|
else if (i >= palette_size - 8 )
|
|
|
|
X11DRV_PALETTE_mapEGAPixel[i - (palette_size - 16)] = color.pixel;
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
2003-11-21 06:41:56 +01:00
|
|
|
wine_tsx11_unlock();
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
X11DRV_PALETTE_XPixelToPalette = X11DRV_PALETTE_PaletteToXPixel = NULL;
|
|
|
|
|
|
|
|
COLOR_gapStart = 256; COLOR_gapEnd = -1;
|
|
|
|
|
2001-07-28 02:18:02 +02:00
|
|
|
X11DRV_PALETTE_firstFree = (palette_size > NB_RESERVED_COLORS)?NB_RESERVED_COLORS/2 : -1;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_PALETTE_BuildSharedMap
|
|
|
|
*
|
|
|
|
* Allocate colorcells and initialize mapping tables.
|
|
|
|
*/
|
2002-06-02 23:40:24 +02:00
|
|
|
static BOOL X11DRV_PALETTE_BuildSharedMap( const PALETTEENTRY *sys_pal_template )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
XColor color;
|
|
|
|
unsigned long sysPixel[NB_RESERVED_COLORS];
|
|
|
|
unsigned long* pixDynMapping = NULL;
|
|
|
|
unsigned long plane_masks[1];
|
|
|
|
int i, j, warn = 0;
|
2004-08-12 01:45:34 +02:00
|
|
|
int diff, r, g, b, bp = 0, wp = 1;
|
1999-04-01 10:16:08 +02:00
|
|
|
int step = 1;
|
2004-08-12 01:45:34 +02:00
|
|
|
unsigned int max = 256;
|
2001-04-16 21:33:25 +02:00
|
|
|
Colormap defaultCM;
|
|
|
|
XColor defaultColors[256];
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* Copy the first bunch of colors out of the default colormap to prevent
|
2001-04-16 21:33:25 +02:00
|
|
|
* colormap flashing as much as possible. We're likely to get the most
|
|
|
|
* important Window Manager colors, etc in the first 128 colors */
|
2001-05-11 02:17:47 +02:00
|
|
|
defaultCM = DefaultColormap( gdi_display, DefaultScreen(gdi_display) );
|
2001-06-19 05:32:44 +02:00
|
|
|
|
2005-06-14 20:12:15 +02:00
|
|
|
if (copy_default_colors > 256) copy_default_colors = 256;
|
|
|
|
for (i = 0; i < copy_default_colors; i++)
|
2001-04-16 21:33:25 +02:00
|
|
|
defaultColors[i].pixel = (long) i;
|
2003-11-09 01:35:29 +01:00
|
|
|
wine_tsx11_lock();
|
2005-06-14 20:12:15 +02:00
|
|
|
XQueryColors(gdi_display, defaultCM, &defaultColors[0], copy_default_colors);
|
|
|
|
for (i = 0; i < copy_default_colors; i++)
|
2003-11-09 01:35:29 +01:00
|
|
|
XAllocColor( gdi_display, X11DRV_PALETTE_PaletteXColormap, &defaultColors[i] );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-06-14 20:12:15 +02:00
|
|
|
if (alloc_system_colors > 256) alloc_system_colors = 256;
|
|
|
|
else if (alloc_system_colors < 20) alloc_system_colors = 20;
|
|
|
|
TRACE("%d colors configured.\n", alloc_system_colors);
|
2001-04-16 21:33:25 +02:00
|
|
|
|
2001-07-28 02:18:02 +02:00
|
|
|
TRACE("Building shared map - %i palette entries\n", palette_size);
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
/* Be nice and allocate system colors as read-only */
|
|
|
|
|
|
|
|
for( i = 0; i < NB_RESERVED_COLORS; i++ )
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2002-06-02 23:40:24 +02:00
|
|
|
color.red = sys_pal_template[i].peRed * 65535 / 255;
|
|
|
|
color.green = sys_pal_template[i].peGreen * 65535 / 255;
|
|
|
|
color.blue = sys_pal_template[i].peBlue * 65535 / 255;
|
1999-04-01 10:16:08 +02:00
|
|
|
color.flags = DoRed | DoGreen | DoBlue;
|
|
|
|
|
2003-11-09 01:35:29 +01:00
|
|
|
if (!XAllocColor( gdi_display, X11DRV_PALETTE_PaletteXColormap, &color ))
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
1999-04-01 10:16:08 +02:00
|
|
|
XColor best, c;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
if( !warn++ )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
1999-06-26 21:09:08 +02:00
|
|
|
WARN("Not enough colors for the full system palette.\n");
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2001-05-11 02:17:47 +02:00
|
|
|
bp = BlackPixel(gdi_display, DefaultScreen(gdi_display));
|
|
|
|
wp = WhitePixel(gdi_display, DefaultScreen(gdi_display));
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2001-05-11 02:17:47 +02:00
|
|
|
max = (0xffffffff)>>(32 - screen_depth);
|
2002-06-01 01:06:46 +02:00
|
|
|
if( max > 256 )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
step = max/256;
|
|
|
|
max = 256;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reinit color (XAllocColor() may change it)
|
|
|
|
* and map to the best shared colorcell */
|
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
color.red = sys_pal_template[i].peRed * 65535 / 255;
|
|
|
|
color.green = sys_pal_template[i].peGreen * 65535 / 255;
|
|
|
|
color.blue = sys_pal_template[i].peBlue * 65535 / 255;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
best.pixel = best.red = best.green = best.blue = 0;
|
|
|
|
for( c.pixel = 0, diff = 0x7fffffff; c.pixel < max; c.pixel += step )
|
|
|
|
{
|
2003-11-09 01:35:29 +01:00
|
|
|
XQueryColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &c);
|
2002-06-01 01:06:46 +02:00
|
|
|
r = (c.red - color.red)>>8;
|
|
|
|
g = (c.green - color.green)>>8;
|
1999-04-01 10:16:08 +02:00
|
|
|
b = (c.blue - color.blue)>>8;
|
|
|
|
r = r*r + g*g + b*b;
|
|
|
|
if( r < diff ) { best = c; diff = r; }
|
|
|
|
}
|
|
|
|
|
2003-11-09 01:35:29 +01:00
|
|
|
if( XAllocColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &best) )
|
1999-04-01 10:16:08 +02:00
|
|
|
color.pixel = best.pixel;
|
|
|
|
else color.pixel = (i < NB_RESERVED_COLORS/2)? bp : wp;
|
|
|
|
}
|
|
|
|
|
|
|
|
sysPixel[i] = color.pixel;
|
|
|
|
|
2006-10-08 01:34:01 +02:00
|
|
|
TRACE("syscolor(%x) -> pixel %i\n", *(const COLORREF*)(sys_pal_template+i),
|
|
|
|
(int)color.pixel);
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
/* Set EGA mapping if color in the first or last eight */
|
|
|
|
|
|
|
|
if (i < 8)
|
|
|
|
X11DRV_PALETTE_mapEGAPixel[i] = color.pixel;
|
|
|
|
else if (i >= NB_RESERVED_COLORS - 8 )
|
|
|
|
X11DRV_PALETTE_mapEGAPixel[i - (NB_RESERVED_COLORS-16)] = color.pixel;
|
|
|
|
}
|
2003-11-09 01:35:29 +01:00
|
|
|
wine_tsx11_unlock();
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
/* now allocate changeable set */
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if( !(X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED) )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2001-07-28 02:18:02 +02:00
|
|
|
int c_min = 0, c_max = palette_size, c_val;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("Dynamic colormap...\n");
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* let's become the first client that actually follows
|
1999-04-01 10:16:08 +02:00
|
|
|
* X guidelines and does binary search...
|
|
|
|
*/
|
|
|
|
|
2005-03-24 22:01:35 +01:00
|
|
|
if((pixDynMapping = HeapAlloc(GetProcessHeap(), 0, sizeof(long)*palette_size)) == NULL) {
|
2000-04-09 20:41:15 +02:00
|
|
|
WARN("Out of memory while building system palette.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-02-12 19:10:27 +01:00
|
|
|
|
2003-11-09 01:35:29 +01:00
|
|
|
wine_tsx11_lock();
|
2001-02-12 19:10:27 +01:00
|
|
|
/* comment this out if you want to debug palette init */
|
2003-11-09 01:35:29 +01:00
|
|
|
XGrabServer(gdi_display);
|
2001-02-12 19:10:27 +01:00
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
while( c_max - c_min > 0 )
|
|
|
|
{
|
|
|
|
c_val = (c_max + c_min)/2 + (c_max + c_min)%2;
|
|
|
|
|
2003-11-09 01:35:29 +01:00
|
|
|
if( !XAllocColorCells(gdi_display, X11DRV_PALETTE_PaletteXColormap, False,
|
1999-04-01 10:16:08 +02:00
|
|
|
plane_masks, 0, pixDynMapping, c_val) )
|
|
|
|
c_max = c_val - 1;
|
|
|
|
else
|
|
|
|
{
|
2003-11-09 01:35:29 +01:00
|
|
|
XFreeColors(gdi_display, X11DRV_PALETTE_PaletteXColormap, pixDynMapping, c_val, 0);
|
1999-04-01 10:16:08 +02:00
|
|
|
c_min = c_val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-14 20:12:15 +02:00
|
|
|
if( c_min > alloc_system_colors - NB_RESERVED_COLORS)
|
|
|
|
c_min = alloc_system_colors - NB_RESERVED_COLORS;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
c_min = (c_min/2) + (c_min/2); /* need even set for split palette */
|
|
|
|
|
|
|
|
if( c_min > 0 )
|
2003-11-09 01:35:29 +01:00
|
|
|
if( !XAllocColorCells(gdi_display, X11DRV_PALETTE_PaletteXColormap, False,
|
1999-04-01 10:16:08 +02:00
|
|
|
plane_masks, 0, pixDynMapping, c_min) )
|
|
|
|
{
|
1999-06-26 21:09:08 +02:00
|
|
|
WARN("Inexplicable failure during colorcell allocation.\n");
|
1999-04-01 10:16:08 +02:00
|
|
|
c_min = 0;
|
|
|
|
}
|
|
|
|
|
2001-07-28 02:18:02 +02:00
|
|
|
palette_size = c_min + NB_RESERVED_COLORS;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2003-11-09 01:35:29 +01:00
|
|
|
XUngrabServer(gdi_display);
|
|
|
|
wine_tsx11_unlock();
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2001-07-28 02:18:02 +02:00
|
|
|
TRACE("adjusted size %i colorcells\n", palette_size);
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
else if( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/* virtual colorspace - ToPhysical takes care of
|
|
|
|
* color translations but we have to allocate full palette
|
1999-04-01 10:16:08 +02:00
|
|
|
* to maintain compatibility
|
|
|
|
*/
|
2001-07-28 02:18:02 +02:00
|
|
|
palette_size = 256;
|
2001-05-11 02:17:47 +02:00
|
|
|
TRACE("Virtual colorspace - screendepth %i\n", screen_depth);
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
2001-07-28 02:18:02 +02:00
|
|
|
else palette_size = NB_RESERVED_COLORS; /* system palette only - however we can alloc a bunch
|
1999-04-01 10:16:08 +02:00
|
|
|
* of colors and map to them */
|
|
|
|
|
2001-07-28 02:18:02 +02:00
|
|
|
TRACE("Shared system palette uses %i colors.\n", palette_size);
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
/* set gap to account for pixel shortage. It has to be right in the center
|
|
|
|
* of the system palette because otherwise raster ops get screwed. */
|
|
|
|
|
2001-07-28 02:18:02 +02:00
|
|
|
if( palette_size >= 256 )
|
1999-04-01 10:16:08 +02:00
|
|
|
{ COLOR_gapStart = 256; COLOR_gapEnd = -1; }
|
|
|
|
else
|
2001-07-28 02:18:02 +02:00
|
|
|
{ COLOR_gapStart = palette_size/2; COLOR_gapEnd = 255 - palette_size/2; }
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
X11DRV_PALETTE_firstFree = ( palette_size > NB_RESERVED_COLORS &&
|
|
|
|
(X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL || !(X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED)) )
|
1999-04-01 10:16:08 +02:00
|
|
|
? NB_RESERVED_COLORS/2 : -1;
|
|
|
|
|
2005-03-24 22:01:35 +01:00
|
|
|
COLOR_sysPal = HeapAlloc(GetProcessHeap(),0,sizeof(PALETTEENTRY)*256);
|
2000-03-19 15:29:50 +01:00
|
|
|
if(COLOR_sysPal == NULL) {
|
2005-05-06 17:44:31 +02:00
|
|
|
ERR("Unable to allocate the system palette!\n");
|
2004-12-14 12:38:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pixDynMapping);
|
2000-03-19 15:29:50 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
/* setup system palette entry <-> pixel mappings and fill in 20 fixed entries */
|
|
|
|
|
2001-05-11 02:17:47 +02:00
|
|
|
if (screen_depth <= 8)
|
2000-03-19 15:29:50 +01:00
|
|
|
{
|
2002-05-29 02:33:44 +02:00
|
|
|
X11DRV_PALETTE_XPixelToPalette = HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(int) );
|
2000-03-19 15:29:50 +01:00
|
|
|
if(X11DRV_PALETTE_XPixelToPalette == NULL) {
|
|
|
|
ERR("Out of memory: XPixelToPalette!\n");
|
2004-12-14 12:38:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pixDynMapping);
|
2000-03-19 15:29:50 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-05-29 02:33:44 +02:00
|
|
|
for( i = 0; i < 256; i++ )
|
|
|
|
X11DRV_PALETTE_XPixelToPalette[i] = NB_PALETTE_EMPTY_VALUE;
|
2000-03-19 15:29:50 +01:00
|
|
|
}
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
/* for hicolor visuals PaletteToPixel mapping is used to skip
|
2002-06-01 01:06:46 +02:00
|
|
|
* RGB->pixel calculation in X11DRV_PALETTE_ToPhysical().
|
1999-04-01 10:16:08 +02:00
|
|
|
*/
|
|
|
|
|
2005-03-24 22:01:35 +01:00
|
|
|
X11DRV_PALETTE_PaletteToXPixel = HeapAlloc(GetProcessHeap(),0,sizeof(int)*256);
|
2000-03-19 15:29:50 +01:00
|
|
|
if(X11DRV_PALETTE_PaletteToXPixel == NULL) {
|
|
|
|
ERR("Out of memory: PaletteToXPixel!\n");
|
2004-12-14 12:38:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pixDynMapping);
|
2000-03-19 15:29:50 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
for( i = j = 0; i < 256; i++ )
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
if( i >= COLOR_gapStart && i <= COLOR_gapEnd )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2002-05-29 02:33:44 +02:00
|
|
|
X11DRV_PALETTE_PaletteToXPixel[i] = NB_PALETTE_EMPTY_VALUE;
|
1999-04-01 10:16:08 +02:00
|
|
|
COLOR_sysPal[i].peFlags = 0; /* mark as unused */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( i < NB_RESERVED_COLORS/2 )
|
|
|
|
{
|
|
|
|
X11DRV_PALETTE_PaletteToXPixel[i] = sysPixel[i];
|
2002-06-02 23:40:24 +02:00
|
|
|
COLOR_sysPal[i] = sys_pal_template[i];
|
|
|
|
COLOR_sysPal[i].peFlags |= PC_SYS_USED;
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
else if( i >= 256 - NB_RESERVED_COLORS/2 )
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
X11DRV_PALETTE_PaletteToXPixel[i] = sysPixel[(i + NB_RESERVED_COLORS) - 256];
|
2002-06-02 23:40:24 +02:00
|
|
|
COLOR_sysPal[i] = sys_pal_template[(i + NB_RESERVED_COLORS) - 256];
|
|
|
|
COLOR_sysPal[i].peFlags |= PC_SYS_USED;
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
else if( pixDynMapping )
|
|
|
|
X11DRV_PALETTE_PaletteToXPixel[i] = pixDynMapping[j++];
|
|
|
|
else
|
|
|
|
X11DRV_PALETTE_PaletteToXPixel[i] = i;
|
|
|
|
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("index %i -> pixel %i\n", i, X11DRV_PALETTE_PaletteToXPixel[i]);
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
if( X11DRV_PALETTE_XPixelToPalette )
|
|
|
|
X11DRV_PALETTE_XPixelToPalette[X11DRV_PALETTE_PaletteToXPixel[i]] = i;
|
|
|
|
}
|
|
|
|
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pixDynMapping);
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Colormap Initialization
|
|
|
|
*/
|
2002-06-02 23:40:24 +02:00
|
|
|
static void X11DRV_PALETTE_FillDefaultColors( const PALETTEENTRY *sys_pal_template )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/* initialize unused entries to what Windows uses as a color
|
|
|
|
* cube - based on Greg Kreider's code.
|
1999-04-01 10:16:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
int i = 0, idx = 0;
|
|
|
|
int red, no_r, inc_r;
|
2002-06-01 01:06:46 +02:00
|
|
|
int green, no_g, inc_g;
|
1999-04-01 10:16:08 +02:00
|
|
|
int blue, no_b, inc_b;
|
2001-05-11 02:17:47 +02:00
|
|
|
|
2001-07-28 02:18:02 +02:00
|
|
|
if (palette_size <= NB_RESERVED_COLORS)
|
1999-04-01 10:16:08 +02:00
|
|
|
return;
|
2001-07-28 02:18:02 +02:00
|
|
|
while (i*i*i < (palette_size - NB_RESERVED_COLORS)) i++;
|
1999-04-01 10:16:08 +02:00
|
|
|
no_r = no_g = no_b = --i;
|
2001-07-28 02:18:02 +02:00
|
|
|
if ((no_r * (no_g+1) * no_b) < (palette_size - NB_RESERVED_COLORS)) no_g++;
|
|
|
|
if ((no_r * no_g * (no_b+1)) < (palette_size - NB_RESERVED_COLORS)) no_b++;
|
1999-04-01 10:16:08 +02:00
|
|
|
inc_r = (255 - NB_COLORCUBE_START_INDEX)/no_r;
|
|
|
|
inc_g = (255 - NB_COLORCUBE_START_INDEX)/no_g;
|
|
|
|
inc_b = (255 - NB_COLORCUBE_START_INDEX)/no_b;
|
|
|
|
|
2003-11-09 01:35:29 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
idx = X11DRV_PALETTE_firstFree;
|
|
|
|
|
|
|
|
if( idx != -1 )
|
|
|
|
for (blue = NB_COLORCUBE_START_INDEX; blue < 256 && idx; blue += inc_b )
|
|
|
|
for (green = NB_COLORCUBE_START_INDEX; green < 256 && idx; green += inc_g )
|
|
|
|
for (red = NB_COLORCUBE_START_INDEX; red < 256 && idx; red += inc_r )
|
|
|
|
{
|
|
|
|
/* weird but true */
|
|
|
|
|
|
|
|
if( red == NB_COLORCUBE_START_INDEX && green == red && blue == green ) continue;
|
|
|
|
|
|
|
|
COLOR_sysPal[idx].peRed = red;
|
|
|
|
COLOR_sysPal[idx].peGreen = green;
|
|
|
|
COLOR_sysPal[idx].peBlue = blue;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
/* set X color */
|
|
|
|
|
|
|
|
if( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL )
|
|
|
|
{
|
2001-12-21 20:18:48 +01:00
|
|
|
if (X11DRV_PALETTE_PRed.max != 255) no_r = (red * X11DRV_PALETTE_PRed.max) / 255;
|
|
|
|
if (X11DRV_PALETTE_PGreen.max != 255) no_g = (green * X11DRV_PALETTE_PGreen.max) / 255;
|
|
|
|
if (X11DRV_PALETTE_PBlue.max != 255) no_b = (blue * X11DRV_PALETTE_PBlue.max) / 255;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2001-12-21 20:18:48 +01:00
|
|
|
X11DRV_PALETTE_PaletteToXPixel[idx] = (no_r << X11DRV_PALETTE_PRed.shift) | (no_g << X11DRV_PALETTE_PGreen.shift) | (no_b << X11DRV_PALETTE_PBlue.shift);
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
else if( !(X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED) )
|
|
|
|
{
|
1999-04-25 21:01:52 +02:00
|
|
|
XColor color;
|
|
|
|
color.pixel = (X11DRV_PALETTE_PaletteToXPixel)? X11DRV_PALETTE_PaletteToXPixel[idx] : idx;
|
|
|
|
color.red = COLOR_sysPal[idx].peRed << 8;
|
|
|
|
color.green = COLOR_sysPal[idx].peGreen << 8;
|
|
|
|
color.blue = COLOR_sysPal[idx].peBlue << 8;
|
|
|
|
color.flags = DoRed | DoGreen | DoBlue;
|
2003-11-09 01:35:29 +01:00
|
|
|
XStoreColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &color);
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
idx = X11DRV_PALETTE_freeList[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to fill some entries in the "gap" with
|
|
|
|
* what's already in the colormap - they will be
|
|
|
|
* mappable to but not changeable. */
|
|
|
|
|
|
|
|
if( COLOR_gapStart < COLOR_gapEnd && X11DRV_PALETTE_XPixelToPalette )
|
|
|
|
{
|
|
|
|
XColor xc;
|
|
|
|
int r, g, b, max;
|
|
|
|
|
2005-06-14 20:12:15 +02:00
|
|
|
max = alloc_system_colors - (256 - (COLOR_gapEnd - COLOR_gapStart));
|
1999-04-01 10:16:08 +02:00
|
|
|
for ( i = 0, idx = COLOR_gapStart; i < 256 && idx <= COLOR_gapEnd; i++ )
|
2002-05-29 02:33:44 +02:00
|
|
|
if( X11DRV_PALETTE_XPixelToPalette[i] == NB_PALETTE_EMPTY_VALUE )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
xc.pixel = i;
|
|
|
|
|
2003-11-09 01:35:29 +01:00
|
|
|
XQueryColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &xc);
|
1999-04-01 10:16:08 +02:00
|
|
|
r = xc.red>>8; g = xc.green>>8; b = xc.blue>>8;
|
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
if( xc.pixel < 256 && X11DRV_PALETTE_CheckSysColor( sys_pal_template, RGB(r, g, b)) &&
|
2003-11-09 01:35:29 +01:00
|
|
|
XAllocColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &xc) )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
X11DRV_PALETTE_XPixelToPalette[xc.pixel] = idx;
|
|
|
|
X11DRV_PALETTE_PaletteToXPixel[idx] = xc.pixel;
|
|
|
|
*(COLORREF*)(COLOR_sysPal + idx) = RGB(r, g, b);
|
|
|
|
COLOR_sysPal[idx++].peFlags |= PC_SYS_USED;
|
|
|
|
if( --max <= 0 ) break;
|
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
COLOR_gapFilled = idx - COLOR_gapStart;
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
2003-11-09 01:35:29 +01:00
|
|
|
wine_tsx11_unlock();
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-02 23:49:50 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_IsSolidColor
|
|
|
|
*
|
|
|
|
* Check whether 'color' can be represented with a solid color.
|
|
|
|
*/
|
|
|
|
BOOL X11DRV_IsSolidColor( COLORREF color )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const PALETTEENTRY *pEntry = COLOR_sysPal;
|
|
|
|
|
|
|
|
if (color & 0xff000000) return TRUE; /* indexed color */
|
|
|
|
|
|
|
|
if (!color || (color == 0xffffff)) return TRUE; /* black or white */
|
|
|
|
|
2004-03-27 02:37:32 +01:00
|
|
|
if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL) return TRUE; /* no palette */
|
|
|
|
|
|
|
|
for (i = 0; i < palette_size ; i++, pEntry++)
|
2002-05-02 23:49:50 +02:00
|
|
|
{
|
|
|
|
if( i < COLOR_gapStart || i > COLOR_gapEnd )
|
|
|
|
if ((GetRValue(color) == pEntry->peRed) &&
|
|
|
|
(GetGValue(color) == pEntry->peGreen) &&
|
|
|
|
(GetBValue(color) == pEntry->peBlue)) return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_PALETTE_ToLogical
|
|
|
|
*
|
|
|
|
* Return RGB color for given X pixel.
|
|
|
|
*/
|
|
|
|
COLORREF X11DRV_PALETTE_ToLogical(int pixel)
|
|
|
|
{
|
|
|
|
XColor color;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* truecolor visual */
|
|
|
|
|
2001-05-11 02:17:47 +02:00
|
|
|
if (screen_depth >= 24) return pixel;
|
1999-04-01 10:16:08 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* check for hicolor visuals first */
|
|
|
|
|
2001-10-17 19:45:33 +02:00
|
|
|
if ( (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED) && !X11DRV_PALETTE_Graymax )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2001-12-21 20:18:48 +01:00
|
|
|
color.red = (pixel >> X11DRV_PALETTE_LRed.shift) & X11DRV_PALETTE_LRed.max;
|
|
|
|
if (X11DRV_PALETTE_LRed.scale<8)
|
|
|
|
color.red= color.red << (8-X11DRV_PALETTE_LRed.scale) |
|
|
|
|
color.red >> (2*X11DRV_PALETTE_LRed.scale-8);
|
|
|
|
color.green = (pixel >> X11DRV_PALETTE_LGreen.shift) & X11DRV_PALETTE_LGreen.max;
|
|
|
|
if (X11DRV_PALETTE_LGreen.scale<8)
|
|
|
|
color.green=color.green << (8-X11DRV_PALETTE_LGreen.scale) |
|
|
|
|
color.green >> (2*X11DRV_PALETTE_LGreen.scale-8);
|
|
|
|
color.blue = (pixel >> X11DRV_PALETTE_LBlue.shift) & X11DRV_PALETTE_LBlue.max;
|
|
|
|
if (X11DRV_PALETTE_LBlue.scale<8)
|
|
|
|
color.blue= color.blue << (8-X11DRV_PALETTE_LBlue.scale) |
|
|
|
|
color.blue >> (2*X11DRV_PALETTE_LBlue.scale-8);
|
|
|
|
return RGB(color.red,color.green,color.blue);
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check if we can bypass X */
|
|
|
|
|
2001-05-11 02:17:47 +02:00
|
|
|
if ((screen_depth <= 8) && (pixel < 256) &&
|
2001-10-17 19:45:33 +02:00
|
|
|
!(X11DRV_PALETTE_PaletteFlags & (X11DRV_PALETTE_VIRTUAL | X11DRV_PALETTE_FIXED)) ) {
|
2002-06-01 01:06:46 +02:00
|
|
|
return ( *(COLORREF*)(COLOR_sysPal +
|
1999-04-01 10:16:08 +02:00
|
|
|
((X11DRV_PALETTE_XPixelToPalette)?X11DRV_PALETTE_XPixelToPalette[pixel]:pixel)) ) & 0x00ffffff;
|
2001-10-17 19:45:33 +02:00
|
|
|
}
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2003-11-21 01:17:33 +01:00
|
|
|
wine_tsx11_lock();
|
1999-04-01 10:16:08 +02:00
|
|
|
color.pixel = pixel;
|
2003-11-21 01:17:33 +01:00
|
|
|
XQueryColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &color);
|
|
|
|
wine_tsx11_unlock();
|
1999-04-01 10:16:08 +02:00
|
|
|
return RGB(color.red >> 8, color.green >> 8, color.blue >> 8);
|
|
|
|
}
|
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_SysPaletteLookupPixel
|
|
|
|
*/
|
|
|
|
static int X11DRV_SysPaletteLookupPixel( COLORREF col, BOOL skipReserved )
|
|
|
|
{
|
|
|
|
int i, best = 0, diff = 0x7fffffff;
|
|
|
|
int r,g,b;
|
|
|
|
|
|
|
|
for( i = 0; i < palette_size && diff ; i++ )
|
|
|
|
{
|
|
|
|
if( !(COLOR_sysPal[i].peFlags & PC_SYS_USED) ||
|
|
|
|
(skipReserved && COLOR_sysPal[i].peFlags & PC_SYS_RESERVED) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
r = COLOR_sysPal[i].peRed - GetRValue(col);
|
|
|
|
g = COLOR_sysPal[i].peGreen - GetGValue(col);
|
|
|
|
b = COLOR_sysPal[i].peBlue - GetBValue(col);
|
|
|
|
|
|
|
|
r = r*r + g*g + b*b;
|
|
|
|
|
|
|
|
if( r < diff ) { best = i; diff = r; }
|
|
|
|
}
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
2006-03-02 13:13:28 +01:00
|
|
|
|
|
|
|
static inline BOOL colour_is_brighter(RGBQUAD c1, RGBQUAD c2)
|
|
|
|
{
|
|
|
|
return (c1.rgbRed * c1.rgbRed + c1.rgbGreen * c1.rgbGreen + c1.rgbBlue * c1.rgbBlue) >
|
|
|
|
(c2.rgbRed * c2.rgbRed + c2.rgbGreen * c2.rgbGreen + c2.rgbBlue * c2.rgbBlue);
|
|
|
|
}
|
2002-06-02 23:40:24 +02:00
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_PALETTE_ToPhysical
|
|
|
|
*
|
|
|
|
* Return the physical color closest to 'color'.
|
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
int X11DRV_PALETTE_ToPhysical( X11DRV_PDEVICE *physDev, COLORREF color )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
WORD index = 0;
|
2004-01-20 23:04:00 +01:00
|
|
|
HPALETTE hPal = physDev ? GetCurrentObject(physDev->hdc, OBJ_PAL ) : GetStockObject(DEFAULT_PALETTE);
|
1999-04-01 10:16:08 +02:00
|
|
|
unsigned char spec_type = color >> 24;
|
2006-11-17 14:36:34 +01:00
|
|
|
int *mapping = palette_get_mapping( hPal );
|
|
|
|
PALETTEENTRY entry;
|
1999-07-10 12:10:43 +02:00
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
if ( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED )
|
|
|
|
{
|
|
|
|
/* there is no colormap limitation; we are going to have to compute
|
2002-06-01 01:06:46 +02:00
|
|
|
* the pixel value from the visual information stored earlier
|
1999-04-01 10:16:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
unsigned long red, green, blue;
|
2005-06-10 21:31:20 +02:00
|
|
|
unsigned idx = color & 0xffff;
|
|
|
|
RGBQUAD quad;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
switch(spec_type)
|
|
|
|
{
|
2005-06-10 21:31:20 +02:00
|
|
|
case 0x10: /* DIBINDEX */
|
2006-11-08 19:57:37 +01:00
|
|
|
if( GetDIBColorTable( physDev->hdc, idx, 1, &quad ) != 1 ) {
|
2006-10-08 01:34:01 +02:00
|
|
|
WARN("DIBINDEX(%x) : idx %d is out of bounds, assuming black\n", color , idx);
|
2005-06-10 21:31:20 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
color = RGB( quad.rgbRed, quad.rgbGreen, quad.rgbBlue );
|
|
|
|
break;
|
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
case 1: /* PALETTEINDEX */
|
2006-11-17 13:47:39 +01:00
|
|
|
if (!GetPaletteEntries( hPal, idx, 1, &entry ))
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2006-10-08 01:34:01 +02:00
|
|
|
WARN("PALETTEINDEX(%x) : idx %d is out of bounds, assuming black\n", color, idx);
|
1999-04-01 10:16:08 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2006-11-17 14:36:34 +01:00
|
|
|
if (mapping) return mapping[idx];
|
2006-11-17 13:47:39 +01:00
|
|
|
color = RGB( entry.peRed, entry.peGreen, entry.peBlue );
|
1999-04-01 10:16:08 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
color &= 0xffffff;
|
|
|
|
/* fall through to RGB */
|
|
|
|
|
|
|
|
case 0: /* RGB */
|
2004-01-18 23:20:17 +01:00
|
|
|
if (physDev && (physDev->depth == 1) )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2006-03-02 13:13:28 +01:00
|
|
|
int white = 1;
|
2006-11-08 19:57:37 +01:00
|
|
|
RGBQUAD table[2];
|
2006-03-02 13:13:28 +01:00
|
|
|
|
2006-11-08 19:57:37 +01:00
|
|
|
if (GetDIBColorTable( physDev->hdc, 0, 2, table ) == 2)
|
2006-03-02 13:13:28 +01:00
|
|
|
{
|
2006-11-08 19:57:37 +01:00
|
|
|
if(!colour_is_brighter(table[1], table[0])) white = 0;
|
2006-03-02 13:13:28 +01:00
|
|
|
}
|
1999-04-01 10:16:08 +02:00
|
|
|
return (((color >> 16) & 0xff) +
|
2006-03-02 13:13:28 +01:00
|
|
|
((color >> 8) & 0xff) + (color & 0xff) > 255*3/2) ? white : 1 - white;
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
red = GetRValue(color); green = GetGValue(color); blue = GetBValue(color);
|
|
|
|
|
|
|
|
if (X11DRV_PALETTE_Graymax)
|
|
|
|
{
|
|
|
|
/* grayscale only; return scaled value */
|
2001-10-17 19:45:33 +02:00
|
|
|
return ( (red * 30 + green * 59 + blue * 11) * X11DRV_PALETTE_Graymax) / 25500;
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* scale each individually and construct the TrueColor pixel value */
|
2001-12-21 20:18:48 +01:00
|
|
|
if (X11DRV_PALETTE_PRed.scale < 8)
|
|
|
|
red = red >> (8-X11DRV_PALETTE_PRed.scale);
|
|
|
|
else if (X11DRV_PALETTE_PRed.scale > 8)
|
|
|
|
red = red << (X11DRV_PALETTE_PRed.scale-8) |
|
|
|
|
red >> (16-X11DRV_PALETTE_PRed.scale);
|
|
|
|
if (X11DRV_PALETTE_PGreen.scale < 8)
|
|
|
|
green = green >> (8-X11DRV_PALETTE_PGreen.scale);
|
|
|
|
else if (X11DRV_PALETTE_PGreen.scale > 8)
|
|
|
|
green = green << (X11DRV_PALETTE_PGreen.scale-8) |
|
|
|
|
green >> (16-X11DRV_PALETTE_PGreen.scale);
|
|
|
|
if (X11DRV_PALETTE_PBlue.scale < 8)
|
|
|
|
blue = blue >> (8-X11DRV_PALETTE_PBlue.scale);
|
|
|
|
else if (X11DRV_PALETTE_PBlue.scale > 8)
|
|
|
|
blue = blue << (X11DRV_PALETTE_PBlue.scale-8) |
|
|
|
|
blue >> (16-X11DRV_PALETTE_PBlue.scale);
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2001-12-21 20:18:48 +01:00
|
|
|
return (red << X11DRV_PALETTE_PRed.shift) | (green << X11DRV_PALETTE_PGreen.shift) | (blue << X11DRV_PALETTE_PBlue.shift);
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
else
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2006-11-17 14:36:34 +01:00
|
|
|
if (!mapping)
|
2004-01-20 23:04:00 +01:00
|
|
|
WARN("Palette %p is not realized\n", hPal);
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
switch(spec_type) /* we have to peruse DC and system palette */
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
color &= 0xffffff;
|
|
|
|
/* fall through to RGB */
|
|
|
|
|
|
|
|
case 0: /* RGB */
|
2004-01-18 23:20:17 +01:00
|
|
|
if (physDev && (physDev->depth == 1) )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2006-03-02 13:13:28 +01:00
|
|
|
int white = 1;
|
2006-11-08 19:57:37 +01:00
|
|
|
RGBQUAD table[2];
|
2006-03-02 13:13:28 +01:00
|
|
|
|
2006-11-08 19:57:37 +01:00
|
|
|
if (GetDIBColorTable( physDev->hdc, 0, 2, table ) == 2)
|
2006-03-02 13:13:28 +01:00
|
|
|
{
|
2006-11-08 19:57:37 +01:00
|
|
|
if(!colour_is_brighter(table[1], table[0]))
|
2006-03-02 13:13:28 +01:00
|
|
|
white = 0;
|
|
|
|
}
|
|
|
|
return (((color >> 16) & 0xff) +
|
|
|
|
((color >> 8) & 0xff) + (color & 0xff) > 255*3/2) ? white : 1 - white;
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
index = X11DRV_SysPaletteLookupPixel( color, FALSE);
|
|
|
|
if (X11DRV_PALETTE_PaletteToXPixel) index = X11DRV_PALETTE_PaletteToXPixel[index];
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
/* TRACE(palette,"RGB(%lx) -> pixel %i\n", color, index);
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
case 1: /* PALETTEINDEX */
|
|
|
|
index = color & 0xffff;
|
2006-11-17 14:36:34 +01:00
|
|
|
if (!GetPaletteEntries( hPal, index, 1, &entry ))
|
2006-10-08 01:34:01 +02:00
|
|
|
WARN("PALETTEINDEX(%x) : index %i is out of bounds\n", color, index);
|
2006-11-17 14:36:34 +01:00
|
|
|
else if (mapping) index = mapping[index];
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
/* TRACE(palette,"PALETTEINDEX(%04x) -> pixel %i\n", (WORD)color, index);
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
case 2: /* PALETTERGB */
|
2002-06-02 23:40:24 +02:00
|
|
|
index = GetNearestPaletteIndex( hPal, color );
|
2006-11-17 14:36:34 +01:00
|
|
|
if (mapping) index = mapping[index];
|
1999-04-01 10:16:08 +02:00
|
|
|
/* TRACE(palette,"PALETTERGB(%lx) -> pixel %i\n", color, index);
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_PALETTE_LookupSystemXPixel
|
|
|
|
*/
|
1999-04-15 17:52:59 +02:00
|
|
|
static int X11DRV_PALETTE_LookupSystemXPixel(COLORREF col)
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
int i, best = 0, diff = 0x7fffffff;
|
2001-07-28 02:18:02 +02:00
|
|
|
int size = palette_size;
|
1999-04-01 10:16:08 +02:00
|
|
|
int r,g,b;
|
|
|
|
|
|
|
|
for( i = 0; i < size && diff ; i++ )
|
|
|
|
{
|
|
|
|
if( i == NB_RESERVED_COLORS/2 )
|
|
|
|
{
|
|
|
|
int newi = size - NB_RESERVED_COLORS/2;
|
|
|
|
if (newi>i) i=newi;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = COLOR_sysPal[i].peRed - GetRValue(col);
|
|
|
|
g = COLOR_sysPal[i].peGreen - GetGValue(col);
|
|
|
|
b = COLOR_sysPal[i].peBlue - GetBValue(col);
|
|
|
|
|
|
|
|
r = r*r + g*g + b*b;
|
|
|
|
|
|
|
|
if( r < diff ) { best = i; diff = r; }
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
return (X11DRV_PALETTE_PaletteToXPixel)? X11DRV_PALETTE_PaletteToXPixel[best] : best;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_PALETTE_FormatSystemPalette
|
|
|
|
*/
|
|
|
|
static void X11DRV_PALETTE_FormatSystemPalette(void)
|
|
|
|
{
|
|
|
|
/* Build free list so we'd have an easy way to find
|
2002-06-01 01:06:46 +02:00
|
|
|
* out if there are any available colorcells.
|
1999-04-01 10:16:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
int i, j = X11DRV_PALETTE_firstFree = NB_RESERVED_COLORS/2;
|
|
|
|
|
|
|
|
COLOR_sysPal[j].peFlags = 0;
|
|
|
|
for( i = NB_RESERVED_COLORS/2 + 1 ; i < 256 - NB_RESERVED_COLORS/2 ; i++ )
|
|
|
|
if( i < COLOR_gapStart || i > COLOR_gapEnd )
|
|
|
|
{
|
|
|
|
COLOR_sysPal[i].peFlags = 0; /* unused tag */
|
|
|
|
X11DRV_PALETTE_freeList[j] = i; /* next */
|
|
|
|
j = i;
|
|
|
|
}
|
|
|
|
X11DRV_PALETTE_freeList[j] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_PALETTE_CheckSysColor
|
|
|
|
*/
|
2002-06-02 23:40:24 +02:00
|
|
|
static BOOL X11DRV_PALETTE_CheckSysColor( const PALETTEENTRY *sys_pal_template, COLORREF c)
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for( i = 0; i < NB_RESERVED_COLORS; i++ )
|
2004-11-30 22:38:57 +01:00
|
|
|
if( c == (*(const COLORREF*)(sys_pal_template + i) & 0x00ffffff) )
|
1999-04-01 10:16:08 +02:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_LookupSysPaletteExact
|
|
|
|
*/
|
2006-11-17 13:47:39 +01:00
|
|
|
static int X11DRV_LookupSysPaletteExact( BYTE r, BYTE g, BYTE b )
|
2002-06-02 23:40:24 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for( i = 0; i < palette_size; i++ )
|
|
|
|
{
|
|
|
|
if( COLOR_sysPal[i].peFlags & PC_SYS_USED ) /* skips gap */
|
|
|
|
if( COLOR_sysPal[i].peRed == r &&
|
|
|
|
COLOR_sysPal[i].peGreen == g &&
|
|
|
|
COLOR_sysPal[i].peBlue == b )
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
/***********************************************************************
|
2006-11-17 14:36:34 +01:00
|
|
|
* RealizePalette (X11DRV.@)
|
1999-04-01 10:16:08 +02:00
|
|
|
*/
|
2006-11-17 14:36:34 +01:00
|
|
|
UINT X11DRV_RealizePalette( X11DRV_PDEVICE *physDev, HPALETTE hpal, BOOL primary )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
char flag;
|
2002-06-02 23:40:24 +02:00
|
|
|
int index;
|
2006-11-17 13:47:39 +01:00
|
|
|
UINT i, iRemapped = 0;
|
2006-11-17 14:36:34 +01:00
|
|
|
int *prev_mapping, *mapping;
|
2006-11-17 13:47:39 +01:00
|
|
|
PALETTEENTRY entries[256];
|
|
|
|
WORD num_entries;
|
|
|
|
|
2006-11-17 14:36:34 +01:00
|
|
|
if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL) return 0;
|
|
|
|
|
2006-11-17 13:47:39 +01:00
|
|
|
if (!GetObjectW( hpal, sizeof(num_entries), &num_entries )) return 0;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
/* reset dynamic system palette entries */
|
|
|
|
|
2006-11-17 14:36:34 +01:00
|
|
|
if( primary && X11DRV_PALETTE_firstFree != -1)
|
1999-04-01 10:16:08 +02:00
|
|
|
X11DRV_PALETTE_FormatSystemPalette();
|
|
|
|
|
|
|
|
/* initialize palette mapping table */
|
2006-11-17 14:36:34 +01:00
|
|
|
prev_mapping = palette_get_mapping( hpal );
|
|
|
|
if (prev_mapping)
|
|
|
|
mapping = HeapReAlloc( GetProcessHeap(), 0, prev_mapping, sizeof(int)*num_entries);
|
2003-10-15 23:01:05 +02:00
|
|
|
else
|
2006-11-17 13:47:39 +01:00
|
|
|
mapping = HeapAlloc( GetProcessHeap(), 0, sizeof(int)*num_entries);
|
2003-10-15 23:01:05 +02:00
|
|
|
|
2000-03-19 15:29:50 +01:00
|
|
|
if(mapping == NULL) {
|
2005-05-06 17:44:31 +02:00
|
|
|
ERR("Unable to allocate new mapping -- memory exhausted!\n");
|
2000-03-19 15:29:50 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2006-11-17 14:36:34 +01:00
|
|
|
palette_set_mapping( hpal, mapping );
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2006-11-17 13:47:39 +01:00
|
|
|
if (num_entries > 256)
|
|
|
|
{
|
|
|
|
FIXME( "more than 256 entries not supported\n" );
|
|
|
|
num_entries = 256;
|
|
|
|
}
|
|
|
|
if (!(num_entries = GetPaletteEntries( hpal, 0, num_entries, entries ))) return 0;
|
2002-06-02 23:40:24 +02:00
|
|
|
|
2006-11-17 13:47:39 +01:00
|
|
|
for (i = 0; i < num_entries; i++)
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
index = -1;
|
|
|
|
flag = PC_SYS_USED;
|
|
|
|
|
2004-10-18 23:18:30 +02:00
|
|
|
/* Even though the docs say that only one flag is to be set,
|
|
|
|
* they are a bitmask. At least one app sets more than one at
|
|
|
|
* the same time. */
|
2006-11-17 13:47:39 +01:00
|
|
|
if ( entries[i].peFlags & PC_EXPLICIT ) {
|
2004-10-18 23:18:30 +02:00
|
|
|
/* palette entries are indices into system palette */
|
2006-11-17 13:47:39 +01:00
|
|
|
index = *(WORD*)&entries[i];
|
2002-06-01 01:06:46 +02:00
|
|
|
if( index > 255 || (index >= COLOR_gapStart && index <= COLOR_gapEnd) )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
WARN("PC_EXPLICIT: idx %d out of system palette, assuming black.\n", index);
|
1999-04-01 10:16:08 +02:00
|
|
|
index = 0;
|
|
|
|
}
|
2004-10-18 23:18:30 +02:00
|
|
|
if( X11DRV_PALETTE_PaletteToXPixel ) index = X11DRV_PALETTE_PaletteToXPixel[index];
|
|
|
|
} else {
|
2006-11-17 13:47:39 +01:00
|
|
|
if ( entries[i].peFlags & PC_RESERVED ) {
|
2004-10-18 23:18:30 +02:00
|
|
|
/* forbid future mappings to this entry */
|
|
|
|
flag |= PC_SYS_RESERVED;
|
|
|
|
}
|
|
|
|
|
2006-11-17 13:47:39 +01:00
|
|
|
if (! (entries[i].peFlags & PC_NOCOLLAPSE) ) {
|
2004-10-18 23:18:30 +02:00
|
|
|
/* try to collapse identical colors */
|
2006-11-17 13:47:39 +01:00
|
|
|
index = X11DRV_LookupSysPaletteExact( entries[i].peRed, entries[i].peGreen, entries[i].peBlue );
|
2004-10-18 23:18:30 +02:00
|
|
|
}
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
if( index < 0 )
|
|
|
|
{
|
2004-10-18 23:18:30 +02:00
|
|
|
if( X11DRV_PALETTE_firstFree > 0 )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
XColor color;
|
|
|
|
index = X11DRV_PALETTE_firstFree; /* ought to be available */
|
|
|
|
X11DRV_PALETTE_firstFree = X11DRV_PALETTE_freeList[index];
|
|
|
|
|
|
|
|
color.pixel = (X11DRV_PALETTE_PaletteToXPixel) ? X11DRV_PALETTE_PaletteToXPixel[index] : index;
|
2006-11-17 13:47:39 +01:00
|
|
|
color.red = entries[i].peRed << 8;
|
|
|
|
color.green = entries[i].peGreen << 8;
|
|
|
|
color.blue = entries[i].peBlue << 8;
|
1999-04-01 10:16:08 +02:00
|
|
|
color.flags = DoRed | DoGreen | DoBlue;
|
2003-11-21 06:41:56 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
XStoreColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &color);
|
|
|
|
wine_tsx11_unlock();
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2006-11-17 13:47:39 +01:00
|
|
|
COLOR_sysPal[index] = entries[i];
|
1999-04-01 10:16:08 +02:00
|
|
|
COLOR_sysPal[index].peFlags = flag;
|
|
|
|
X11DRV_PALETTE_freeList[index] = 0;
|
|
|
|
|
|
|
|
if( X11DRV_PALETTE_PaletteToXPixel ) index = X11DRV_PALETTE_PaletteToXPixel[index];
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
else if ( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2006-11-17 13:47:39 +01:00
|
|
|
index = X11DRV_PALETTE_ToPhysical( NULL,
|
|
|
|
RGB( entries[i].peRed, entries[i].peGreen, entries[i].peBlue ));
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we have to map to existing entry in the system palette */
|
|
|
|
|
2006-11-17 13:47:39 +01:00
|
|
|
index = X11DRV_SysPaletteLookupPixel( RGB( entries[i].peRed, entries[i].peGreen, entries[i].peBlue ),
|
|
|
|
TRUE );
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( X11DRV_PALETTE_PaletteToXPixel ) index = X11DRV_PALETTE_PaletteToXPixel[index];
|
|
|
|
}
|
|
|
|
|
2006-11-17 14:36:34 +01:00
|
|
|
if( !prev_mapping || mapping[i] != index ) iRemapped++;
|
|
|
|
mapping[i] = index;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2006-11-17 13:47:39 +01:00
|
|
|
TRACE("entry %i (%x) -> pixel %i\n", i, *(COLORREF*)&entries[i], index);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
return iRemapped;
|
|
|
|
}
|
|
|
|
|
2006-11-17 14:38:43 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UnrealizePalette (X11DRV.@)
|
|
|
|
*/
|
|
|
|
BOOL X11DRV_UnrealizePalette( HPALETTE hpal )
|
|
|
|
{
|
|
|
|
int *mapping = palette_get_mapping( hpal );
|
|
|
|
|
|
|
|
if (mapping)
|
|
|
|
{
|
|
|
|
wine_tsx11_lock();
|
|
|
|
XDeleteContext( gdi_display, (XID)hpal, palette_context );
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
HeapFree( GetProcessHeap(), 0, mapping );
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
/***********************************************************************
|
2002-06-02 23:40:24 +02:00
|
|
|
* GetSystemPaletteEntries (X11DRV.@)
|
1999-04-01 10:16:08 +02:00
|
|
|
*/
|
2002-06-02 23:40:24 +02:00
|
|
|
UINT X11DRV_GetSystemPaletteEntries( X11DRV_PDEVICE *physDev, UINT start, UINT count,
|
|
|
|
LPPALETTEENTRY entries )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2002-06-02 23:40:24 +02:00
|
|
|
UINT i;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
if (!entries) return palette_size;
|
|
|
|
if (start >= palette_size) return 0;
|
|
|
|
if (start + count >= palette_size) count = palette_size - start;
|
1999-04-15 17:52:59 +02:00
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
for (i = 0; i < count; i++)
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2002-06-02 23:40:24 +02:00
|
|
|
entries[i].peRed = COLOR_sysPal[start + i].peRed;
|
|
|
|
entries[i].peGreen = COLOR_sysPal[start + i].peGreen;
|
|
|
|
entries[i].peBlue = COLOR_sysPal[start + i].peBlue;
|
|
|
|
entries[i].peFlags = 0;
|
2006-10-08 01:34:01 +02:00
|
|
|
TRACE("\tidx(%02x) -> RGB(%08x)\n", start + i, *(COLORREF*)(entries + i) );
|
2002-06-02 23:40:24 +02:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetNearestColor (X11DRV.@)
|
|
|
|
*/
|
|
|
|
COLORREF X11DRV_GetNearestColor( X11DRV_PDEVICE *physDev, COLORREF color )
|
|
|
|
{
|
|
|
|
unsigned char spec_type = color >> 24;
|
|
|
|
COLORREF nearest;
|
|
|
|
|
|
|
|
if (!palette_size) return color;
|
|
|
|
|
|
|
|
if (spec_type == 1 || spec_type == 2)
|
|
|
|
{
|
|
|
|
/* we need logical palette for PALETTERGB and PALETTEINDEX colorrefs */
|
|
|
|
|
|
|
|
UINT index;
|
|
|
|
PALETTEENTRY entry;
|
|
|
|
HPALETTE hpal = GetCurrentObject( physDev->hdc, OBJ_PAL );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
if (!hpal) hpal = GetStockObject( DEFAULT_PALETTE );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
if (spec_type == 2) /* PALETTERGB */
|
|
|
|
index = GetNearestPaletteIndex( hpal, color );
|
|
|
|
else /* PALETTEINDEX */
|
|
|
|
index = LOWORD(color);
|
|
|
|
|
|
|
|
if (!GetPaletteEntries( hpal, index, 1, &entry ))
|
|
|
|
{
|
2006-10-08 01:34:01 +02:00
|
|
|
WARN("RGB(%x) : idx %d is out of bounds, assuming NULL\n", color, index );
|
2002-06-02 23:40:24 +02:00
|
|
|
if (!GetPaletteEntries( hpal, 0, 1, &entry )) return CLR_INVALID;
|
|
|
|
}
|
|
|
|
color = RGB( entry.peRed, entry.peGreen, entry.peBlue );
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
2002-06-02 23:40:24 +02:00
|
|
|
color &= 0x00ffffff;
|
|
|
|
nearest = (0x00ffffff & *(COLORREF*)(COLOR_sysPal + X11DRV_SysPaletteLookupPixel(color, FALSE)));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-10-08 01:34:01 +02:00
|
|
|
TRACE("(%06x): returning %06x\n", color, nearest );
|
2002-06-02 23:40:24 +02:00
|
|
|
return nearest;
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RealizeDefaultPalette (X11DRV.@)
|
|
|
|
*/
|
|
|
|
UINT X11DRV_RealizeDefaultPalette( X11DRV_PDEVICE *physDev )
|
|
|
|
{
|
|
|
|
UINT ret = 0;
|
|
|
|
|
2003-05-14 01:56:12 +02:00
|
|
|
if (palette_size && GetObjectType(physDev->hdc) != OBJ_MEMDC)
|
2002-06-02 23:40:24 +02:00
|
|
|
{
|
2006-11-17 14:36:34 +01:00
|
|
|
/* lookup is needed to account for SetSystemPaletteUse() stuff */
|
|
|
|
int i, index, *mapping = palette_get_mapping( GetStockObject(DEFAULT_PALETTE) );
|
|
|
|
PALETTEENTRY entries[NB_RESERVED_COLORS];
|
2002-06-02 23:40:24 +02:00
|
|
|
|
2006-11-17 14:36:34 +01:00
|
|
|
GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, NB_RESERVED_COLORS, entries );
|
|
|
|
for( i = 0; i < NB_RESERVED_COLORS; i++ )
|
|
|
|
{
|
|
|
|
index = X11DRV_PALETTE_LookupSystemXPixel( RGB(entries[i].peRed,
|
|
|
|
entries[i].peGreen,
|
|
|
|
entries[i].peBlue) );
|
|
|
|
/* mapping is allocated in COLOR_InitPalette() */
|
|
|
|
if( index != mapping[i] )
|
2002-06-02 23:40:24 +02:00
|
|
|
{
|
2006-11-17 14:36:34 +01:00
|
|
|
mapping[i]=index;
|
|
|
|
ret++;
|
2002-06-02 23:40:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|