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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-04-01 10:16:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gdi.h"
|
|
|
|
#include "windef.h"
|
2001-06-19 05:32:44 +02:00
|
|
|
#include "winreg.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
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
static int COLOR_max = 256;
|
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];
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
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;
|
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
|
|
|
|
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:
|
2001-06-19 05:32:44 +02:00
|
|
|
{
|
|
|
|
HKEY hkey;
|
|
|
|
BOOL private_color_map = FALSE;
|
|
|
|
if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\x11drv", &hkey))
|
|
|
|
{
|
|
|
|
char buffer[20];
|
|
|
|
DWORD type, count = sizeof(buffer);
|
|
|
|
if(!RegQueryValueExA(hkey, "PrivateColorMap", 0, &type, buffer, &count))
|
2001-07-23 02:04:00 +02:00
|
|
|
{
|
|
|
|
char ch = buffer[0];
|
|
|
|
private_color_map = (ch == 'y' || ch == 'Y' || ch == 't' || ch == 'T' || ch == '1');
|
|
|
|
}
|
2001-06-19 05:32:44 +02:00
|
|
|
RegCloseKey(hkey);
|
|
|
|
}
|
|
|
|
|
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;
|
2001-06-19 05:32:44 +02:00
|
|
|
}
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
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 );
|
|
|
|
|
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;
|
2001-04-16 21:33:25 +02:00
|
|
|
int defaultCM_max_copy;
|
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];
|
2001-06-19 05:32:44 +02:00
|
|
|
HKEY hkey;
|
|
|
|
|
|
|
|
defaultCM_max_copy = 128;
|
|
|
|
COLOR_max = 256;
|
|
|
|
|
|
|
|
if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\x11drv", &hkey))
|
|
|
|
{
|
|
|
|
char buffer[20];
|
|
|
|
DWORD type, count;
|
|
|
|
|
|
|
|
count = sizeof(buffer);
|
|
|
|
if(!RegQueryValueExA(hkey, "CopyDefaultColors", 0, &type, buffer, &count))
|
|
|
|
defaultCM_max_copy = atoi(buffer);
|
|
|
|
|
|
|
|
count = sizeof(buffer);
|
|
|
|
if(!RegQueryValueExA(hkey, "AllocSystemColors", 0, &type, buffer, &count))
|
|
|
|
COLOR_max = atoi(buffer);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-19 05:32:44 +02:00
|
|
|
RegCloseKey(hkey);
|
|
|
|
}
|
2001-04-16 21:33:25 +02:00
|
|
|
|
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
|
|
|
|
2001-04-16 21:33:25 +02:00
|
|
|
for (i = 0; i < defaultCM_max_copy; i++)
|
|
|
|
defaultColors[i].pixel = (long) i;
|
2003-11-09 01:35:29 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
XQueryColors(gdi_display, defaultCM, &defaultColors[0], defaultCM_max_copy);
|
2001-04-16 21:33:25 +02:00
|
|
|
for (i = 0; i < defaultCM_max_copy; 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
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
if (COLOR_max > 256) COLOR_max = 256;
|
|
|
|
else if (COLOR_max < 20) COLOR_max = 20;
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("%d colors configured.\n", COLOR_max);
|
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;
|
|
|
|
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("syscolor(%lx) -> pixel %i\n",
|
2004-11-30 22:38:57 +01:00
|
|
|
*(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
|
|
|
|
1999-06-26 21:09:08 +02: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if( c_min > COLOR_max - NB_RESERVED_COLORS)
|
1999-04-01 10:16:08 +02:00
|
|
|
c_min = COLOR_max - NB_RESERVED_COLORS;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
max = COLOR_max - (256 - (COLOR_gapEnd - COLOR_gapStart));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
PALETTEOBJ* palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
|
|
|
|
|
1999-07-10 12:10:43 +02:00
|
|
|
/* palPtr can be NULL when DC is being destroyed */
|
|
|
|
if( !palPtr ) return 0;
|
|
|
|
|
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;
|
|
|
|
unsigned idx = 0;
|
|
|
|
|
|
|
|
switch(spec_type)
|
|
|
|
{
|
|
|
|
case 1: /* PALETTEINDEX */
|
|
|
|
|
|
|
|
if( (idx = color & 0xffff) >= palPtr->logpalette.palNumEntries)
|
|
|
|
{
|
1999-06-26 21:09:08 +02:00
|
|
|
WARN("RGB(%lx) : idx %d is out of bounds, assuming black\n", color, idx);
|
2000-08-19 23:38:55 +02:00
|
|
|
GDI_ReleaseObj( hPal );
|
1999-04-01 10:16:08 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if( palPtr->mapping )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2000-08-19 23:38:55 +02:00
|
|
|
int ret = palPtr->mapping[idx];
|
|
|
|
GDI_ReleaseObj( hPal );
|
|
|
|
return ret;
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
color = *(COLORREF*)(palPtr->logpalette.palPalEntry + idx);
|
|
|
|
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
|
|
|
{
|
2000-08-19 23:38:55 +02:00
|
|
|
GDI_ReleaseObj( hPal );
|
1999-04-01 10:16:08 +02:00
|
|
|
return (((color >> 16) & 0xff) +
|
|
|
|
((color >> 8) & 0xff) + (color & 0xff) > 255*3/2) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
red = GetRValue(color); green = GetGValue(color); blue = GetBValue(color);
|
|
|
|
|
|
|
|
if (X11DRV_PALETTE_Graymax)
|
|
|
|
{
|
|
|
|
/* grayscale only; return scaled value */
|
2000-08-19 23:38:55 +02:00
|
|
|
GDI_ReleaseObj( hPal );
|
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
|
|
|
|
2000-08-19 23:38:55 +02:00
|
|
|
GDI_ReleaseObj( hPal );
|
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
|
|
|
{
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if( !palPtr->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
|
|
|
{
|
2000-08-19 23:38:55 +02:00
|
|
|
GDI_ReleaseObj( hPal );
|
1999-04-01 10:16:08 +02:00
|
|
|
return (((color >> 16) & 0xff) +
|
|
|
|
((color >> 8) & 0xff) + (color & 0xff) > 255*3/2) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if( index >= palPtr->logpalette.palNumEntries )
|
2002-06-01 01:06:46 +02:00
|
|
|
WARN("RGB(%lx) : index %i is out of bounds\n", color, index);
|
1999-04-01 10:16:08 +02:00
|
|
|
else if( palPtr->mapping ) index = palPtr->mapping[index];
|
|
|
|
|
|
|
|
/* 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 );
|
|
|
|
if (palPtr->mapping) index = palPtr->mapping[index];
|
1999-04-01 10:16:08 +02:00
|
|
|
/* TRACE(palette,"PALETTERGB(%lx) -> pixel %i\n", color, index);
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-19 23:38:55 +02:00
|
|
|
GDI_ReleaseObj( hPal );
|
1999-04-01 10:16:08 +02:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
static int X11DRV_LookupSysPaletteExact( COLORREF col )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BYTE r = GetRValue(col), g = GetGValue(col), b = GetBValue(col);
|
|
|
|
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
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_PALETTE_SetMapping
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Set the color-mapping table for selected palette.
|
1999-04-01 10:16:08 +02:00
|
|
|
* Return number of entries which mapping has changed.
|
|
|
|
*/
|
2002-06-02 23:40:24 +02:00
|
|
|
static UINT X11DRV_PALETTE_SetMapping( PALETTEOBJ* palPtr, UINT uStart, UINT uNum, BOOL mapOnly )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
|
|
|
char flag;
|
|
|
|
int prevMapping = (palPtr->mapping) ? 1 : 0;
|
2002-06-02 23:40:24 +02:00
|
|
|
int index;
|
|
|
|
UINT iRemapped = 0;
|
2000-03-19 15:29:50 +01:00
|
|
|
int* mapping;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
|
|
|
/* reset dynamic system palette entries */
|
|
|
|
|
|
|
|
if( !mapOnly && X11DRV_PALETTE_firstFree != -1)
|
|
|
|
X11DRV_PALETTE_FormatSystemPalette();
|
|
|
|
|
|
|
|
/* initialize palette mapping table */
|
2003-10-15 23:01:05 +02:00
|
|
|
if (palPtr->mapping)
|
|
|
|
mapping = HeapReAlloc( GetProcessHeap(), 0, palPtr->mapping,
|
|
|
|
sizeof(int)*palPtr->logpalette.palNumEntries);
|
|
|
|
else
|
|
|
|
mapping = HeapAlloc( GetProcessHeap(), 0,
|
2000-03-28 22:02:37 +02:00
|
|
|
sizeof(int)*palPtr->logpalette.palNumEntries);
|
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;
|
|
|
|
}
|
|
|
|
palPtr->mapping = mapping;
|
1999-04-01 10:16:08 +02:00
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
if (uStart >= palPtr->logpalette.palNumEntries) return 0;
|
|
|
|
|
|
|
|
if (uStart + uNum > palPtr->logpalette.palNumEntries)
|
|
|
|
uNum = palPtr->logpalette.palNumEntries - uStart;
|
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
for( uNum += uStart; uStart < uNum; uStart++ )
|
|
|
|
{
|
|
|
|
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. */
|
|
|
|
if ( palPtr->logpalette.palPalEntry[uStart].peFlags & PC_EXPLICIT ) {
|
|
|
|
/* palette entries are indices into system palette */
|
1999-04-01 10:16:08 +02:00
|
|
|
index = *(WORD*)(palPtr->logpalette.palPalEntry + uStart);
|
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 {
|
|
|
|
if ( palPtr->logpalette.palPalEntry[uStart].peFlags & PC_RESERVED ) {
|
|
|
|
/* forbid future mappings to this entry */
|
|
|
|
flag |= PC_SYS_RESERVED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! (palPtr->logpalette.palPalEntry[uStart].peFlags & PC_NOCOLLAPSE) ) {
|
|
|
|
/* try to collapse identical colors */
|
|
|
|
index = X11DRV_LookupSysPaletteExact(*(COLORREF*)(palPtr->logpalette.palPalEntry + uStart));
|
|
|
|
}
|
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;
|
|
|
|
color.red = palPtr->logpalette.palPalEntry[uStart].peRed << 8;
|
|
|
|
color.green = palPtr->logpalette.palPalEntry[uStart].peGreen << 8;
|
|
|
|
color.blue = palPtr->logpalette.palPalEntry[uStart].peBlue << 8;
|
|
|
|
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
|
|
|
|
|
|
|
COLOR_sysPal[index] = palPtr->logpalette.palPalEntry[uStart];
|
|
|
|
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
|
|
|
{
|
|
|
|
index = X11DRV_PALETTE_ToPhysical( NULL, 0x00ffffff &
|
|
|
|
*(COLORREF*)(palPtr->logpalette.palPalEntry + uStart));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have to map to existing entry in the system palette */
|
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
index = X11DRV_SysPaletteLookupPixel( *(COLORREF*)(palPtr->logpalette.palPalEntry + uStart), TRUE);
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
palPtr->logpalette.palPalEntry[uStart].peFlags |= PC_SYS_USED;
|
|
|
|
|
|
|
|
if( X11DRV_PALETTE_PaletteToXPixel ) index = X11DRV_PALETTE_PaletteToXPixel[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !prevMapping || palPtr->mapping[uStart] != index ) iRemapped++;
|
|
|
|
palPtr->mapping[uStart] = index;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("entry %i (%lx) -> pixel %i\n", uStart,
|
1999-04-01 10:16:08 +02:00
|
|
|
*(COLORREF*)(palPtr->logpalette.palPalEntry + uStart), index);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
return iRemapped;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
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;
|
|
|
|
TRACE("\tidx(%02x) -> RGB(%08lx)\n", start + i, *(COLORREF*)(entries + i) );
|
|
|
|
}
|
|
|
|
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 ))
|
|
|
|
{
|
|
|
|
WARN("RGB(%lx) : idx %d is out of bounds, assuming NULL\n", color, index );
|
|
|
|
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
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
TRACE("(%06lx): returning %06lx\n", color, nearest );
|
|
|
|
return nearest;
|
1999-04-01 10:16:08 +02:00
|
|
|
}
|
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RealizePalette (X11DRV.@)
|
1999-04-01 10:16:08 +02:00
|
|
|
*/
|
2002-06-02 23:40:24 +02:00
|
|
|
UINT X11DRV_RealizePalette( X11DRV_PDEVICE *physDev, HPALETTE hpal, BOOL primary )
|
1999-04-01 10:16:08 +02:00
|
|
|
{
|
2002-06-02 23:40:24 +02:00
|
|
|
UINT ret;
|
|
|
|
PALETTEOBJ *palPtr;
|
|
|
|
|
2003-06-04 22:19:33 +02:00
|
|
|
if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL) return 0;
|
|
|
|
|
2002-06-02 23:40:24 +02:00
|
|
|
if (!(palPtr = GDI_GetObjPtr( hpal, PALETTE_MAGIC ))) return 0;
|
|
|
|
ret = X11DRV_PALETTE_SetMapping( palPtr, 0, palPtr->logpalette.palNumEntries, !primary );
|
|
|
|
GDI_ReleaseObj( hpal );
|
|
|
|
return ret;
|
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
|
|
|
{
|
|
|
|
PALETTEOBJ* palPtr = GDI_GetObjPtr( GetStockObject(DEFAULT_PALETTE), PALETTE_MAGIC );
|
|
|
|
if (palPtr)
|
|
|
|
{
|
|
|
|
/* lookup is needed to account for SetSystemPaletteUse() stuff */
|
|
|
|
int i, index;
|
|
|
|
|
|
|
|
for( i = 0; i < 20; i++ )
|
|
|
|
{
|
|
|
|
index = X11DRV_PALETTE_LookupSystemXPixel(*(COLORREF*)(palPtr->logpalette.palPalEntry + i));
|
|
|
|
/* mapping is allocated in COLOR_InitPalette() */
|
|
|
|
if( index != palPtr->mapping[i] )
|
|
|
|
{
|
|
|
|
palPtr->mapping[i]=index;
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GDI_ReleaseObj( GetStockObject(DEFAULT_PALETTE) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|