Commit 376e6509 authored by Alexandre Julliard's avatar Alexandre Julliard

Better separation of the palette functions.

Removed the palette driver.
parent 0d588a4a
......@@ -21,7 +21,6 @@ C_SRCS = \
$(TOPOBJDIR)/objects/bitmap.c \
$(TOPOBJDIR)/objects/brush.c \
$(TOPOBJDIR)/objects/clipping.c \
$(TOPOBJDIR)/objects/color.c \
$(TOPOBJDIR)/objects/dc.c \
$(TOPOBJDIR)/objects/dcvalues.c \
$(TOPOBJDIR)/objects/dib.c \
......
......@@ -101,8 +101,10 @@ static struct graphics_driver *create_driver( HMODULE module )
GET_FUNC(GetDIBits);
GET_FUNC(GetDeviceCaps);
GET_FUNC(GetDeviceGammaRamp);
GET_FUNC(GetNearestColor);
GET_FUNC(GetPixel);
GET_FUNC(GetPixelFormat);
GET_FUNC(GetSystemPaletteEntries);
GET_FUNC(GetTextExtentPoint);
GET_FUNC(GetTextMetrics);
GET_FUNC(IntersectClipRect);
......@@ -123,6 +125,7 @@ static struct graphics_driver *create_driver( HMODULE module )
GET_FUNC(Polygon);
GET_FUNC(Polyline);
GET_FUNC(PolylineTo);
GET_FUNC(RealizeDefaultPalette);
GET_FUNC(RealizePalette);
GET_FUNC(Rectangle);
GET_FUNC(ResetDC);
......
......@@ -69,8 +69,10 @@ static const DC_FUNCTIONS EMFDRV_Funcs =
NULL, /* pGetDIBits */
NULL, /* pGetDeviceCaps */
NULL, /* pGetDeviceGammaRamp */
NULL, /* pGetNearestColor */
NULL, /* pGetPixel */
NULL, /* pGetPixelFormat */
NULL, /* pGetSystemPaletteEntries */
NULL, /* pGetTextExtentPoint */
NULL, /* pGetTextMetrics */
EMFDRV_IntersectClipRect, /* pIntersectClipRect */
......@@ -91,6 +93,7 @@ static const DC_FUNCTIONS EMFDRV_Funcs =
EMFDRV_Polygon, /* pPolygon */
EMFDRV_Polyline, /* pPolyline */
NULL, /* pPolylineTo */
NULL, /* pRealizeDefaultPalette */
NULL, /* pRealizePalette */
EMFDRV_Rectangle, /* pRectangle */
NULL, /* pResetDC */
......
......@@ -70,8 +70,10 @@ static const DC_FUNCTIONS MFDRV_Funcs =
NULL, /* pGetDIBits */
NULL, /* pGetDeviceCaps */
NULL, /* pGetDeviceGammaRamp */
NULL, /* pGetNearestColor */
NULL, /* pGetPixel */
NULL, /* pGetPixelFormat */
NULL, /* pGetSystemPaletteEntries */
NULL, /* pGetTextExtentPoint */
NULL, /* pGetTextMetrics */
MFDRV_IntersectClipRect, /* pIntersectClipRect */
......@@ -92,6 +94,7 @@ static const DC_FUNCTIONS MFDRV_Funcs =
MFDRV_Polygon, /* pPolygon */
MFDRV_Polyline, /* pPolyline */
NULL, /* pPolylineTo */
NULL, /* pRealizeDefaultPalette */
NULL, /* pRealizePalette */
MFDRV_Rectangle, /* pRectangle */
NULL, /* pResetDC */
......
......@@ -97,8 +97,10 @@ static const DC_FUNCTIONS WIN16DRV_Funcs =
NULL, /* pGetDIBits */
WIN16DRV_GetDeviceCaps, /* pGetDeviceCaps */
NULL, /* pGetDeviceGammaRamp */
NULL, /* pGetNearestColor */
NULL, /* pGetPixel */
NULL, /* pGetPixelFormat */
NULL, /* pGetSystemPaletteEntries */
WIN16DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
WIN16DRV_GetTextMetrics, /* pGetTextMetrics */
NULL, /* pIntersectClipRect */
......@@ -119,6 +121,7 @@ static const DC_FUNCTIONS WIN16DRV_Funcs =
WIN16DRV_Polygon, /* pPolygon */
WIN16DRV_Polyline, /* pPolyline */
NULL, /* pPolylineTo */
NULL, /* pRealizeDefaultPalette */
NULL, /* pRealizePalette */
WIN16DRV_Rectangle, /* pRectangle */
NULL, /* pResetDC */
......@@ -444,5 +447,3 @@ static INT WIN16DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in
FIXME("temporarily broken, please fix\n");
return 0;
}
......@@ -22,28 +22,26 @@
#include <stdlib.h>
#include "color.h"
#include "wine/debug.h"
#include "palette.h"
#include "winbase.h"
#include "ttydrv.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(ttydrv);
/**********************************************************************/
extern PALETTEENTRY *COLOR_sysPal;
static PALETTEENTRY *COLOR_sysPal;
static int palette_size = 256; /* FIXME */
extern const PALETTEENTRY COLOR_sysPalTemplate[NB_RESERVED_COLORS];
/***********************************************************************
* TTYDRV_PALETTE_Initialize
*/
BOOL TTYDRV_PALETTE_Initialize(void)
{
int i;
PALETTEENTRY sys_pal_template[NB_RESERVED_COLORS];
TRACE("(void)\n");
......@@ -53,14 +51,16 @@ BOOL TTYDRV_PALETTE_Initialize(void)
return FALSE;
}
GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, NB_RESERVED_COLORS, sys_pal_template );
for(i=0; i < palette_size; i++ ) {
const PALETTEENTRY *src;
PALETTEENTRY *dst = &COLOR_sysPal[i];
if(i < NB_RESERVED_COLORS/2) {
src = &COLOR_sysPalTemplate[i];
src = &sys_pal_template[i];
} else if(i >= palette_size - NB_RESERVED_COLORS/2) {
src = &COLOR_sysPalTemplate[NB_RESERVED_COLORS + i - palette_size];
src = &sys_pal_template[NB_RESERVED_COLORS + i - palette_size];
} else {
PALETTEENTRY pe = { 0, 0, 0, 0 };
src = &pe;
......@@ -81,3 +81,27 @@ BOOL TTYDRV_PALETTE_Initialize(void)
return TRUE;
}
/***********************************************************************
* GetSystemPaletteEntries (TTYDRV.@)
*/
UINT TTYDRV_GetSystemPaletteEntries( TTYDRV_PDEVICE *dev, UINT start, UINT count,
LPPALETTEENTRY entries )
{
UINT i;
if (!entries) return palette_size;
if (start >= palette_size) return 0;
if (start + count >= palette_size) count = palette_size - start;
for (i = 0; i < count; i++)
{
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;
}
......@@ -15,6 +15,7 @@ init TTYDRV_Init
@ cdecl GetCharWidth(ptr long long ptr) TTYDRV_DC_GetCharWidth
@ cdecl GetDeviceCaps(ptr long) TTYDRV_GetDeviceCaps
@ cdecl GetPixel(ptr long long) TTYDRV_DC_GetPixel
@ cdecl GetSystemPaletteEntries(ptr long long ptr) TTYDRV_GetSystemPaletteEntries
@ cdecl GetTextExtentPoint(ptr ptr long ptr) TTYDRV_DC_GetTextExtentPoint
@ cdecl GetTextMetrics(ptr ptr) TTYDRV_DC_GetTextMetrics
@ cdecl LineTo(ptr long long) TTYDRV_DC_LineTo
......
......@@ -25,8 +25,10 @@ init X11DRV_Init
@ cdecl GetDIBits(ptr long long long ptr ptr long) X11DRV_GetDIBits
@ cdecl GetDeviceCaps(ptr long) X11DRV_GetDeviceCaps
@ cdecl GetDeviceGammaRamp(ptr ptr) X11DRV_GetDeviceGammaRamp
@ cdecl GetNearestColor(ptr long) X11DRV_GetNearestColor
@ cdecl GetPixel(ptr long long) X11DRV_GetPixel
@ cdecl GetPixelFormat(ptr) X11DRV_GetPixelFormat
@ cdecl GetSystemPaletteEntries(ptr long long ptr) X11DRV_GetSystemPaletteEntries
@ cdecl GetTextExtentPoint(ptr ptr long ptr) X11DRV_GetTextExtentPoint
@ cdecl GetTextMetrics(ptr ptr) X11DRV_GetTextMetrics
@ cdecl LineTo(ptr long long) X11DRV_LineTo
......@@ -37,6 +39,8 @@ init X11DRV_Init
@ cdecl PolyPolyline(ptr ptr ptr long) X11DRV_PolyPolyline
@ cdecl Polygon(ptr ptr long) X11DRV_Polygon
@ cdecl Polyline(ptr ptr long) X11DRV_Polyline
@ cdecl RealizeDefaultPalette(ptr) X11DRV_RealizeDefaultPalette
@ cdecl RealizePalette(ptr long long) X11DRV_RealizePalette
@ cdecl Rectangle(ptr long long long long) X11DRV_Rectangle
@ cdecl RoundRect(ptr long long long long long long) X11DRV_RoundRect
@ cdecl SelectBitmap(ptr long) X11DRV_SelectBitmap
......
......@@ -24,7 +24,6 @@
#include <stdlib.h>
#include "bitmap.h"
#include "color.h"
#include "x11drv.h"
#include "wine/debug.h"
......
......@@ -25,25 +25,16 @@
#include <string.h>
#include "bitmap.h"
#include "palette.h"
#include "wine/debug.h"
#include "winnt.h"
#include "x11drv.h"
#include "x11font.h"
#include "ddrawi.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
const DC_FUNCTIONS *X11DRV_DC_Funcs = NULL; /* hack */
PALETTE_DRIVER X11DRV_PALETTE_Driver =
{
X11DRV_PALETTE_SetMapping,
X11DRV_PALETTE_UpdateMapping,
X11DRV_PALETTE_IsDark
};
Display *gdi_display; /* display to use for all GDI functions */
/* a few dynamic device caps */
......@@ -65,7 +56,6 @@ BOOL X11DRV_GDI_Initialize( Display *display )
Screen *screen = DefaultScreenOfDisplay(display);
gdi_display = display;
PALETTE_Driver = &X11DRV_PALETTE_Driver;
palette_size = X11DRV_PALETTE_Init();
......
/*
* Copyright 1993 Alexandre Julliard
* Copyright 1996 Alex Korobka
*
* 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
*/
#ifndef __WINE_COLOR_H
#define __WINE_COLOR_H
#include "windef.h"
#include "wingdi.h"
#include "palette.h"
#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 */
#define PC_SYS_MAPPED 0x10 /* logical palentry is a direct alias for system palentry */
extern COLORREF COLOR_GetSystemPaletteEntry(UINT);
extern const PALETTEENTRY *COLOR_GetSystemPaletteTemplate(void);
extern COLORREF COLOR_LookupNearestColor(PALETTEENTRY *, int, COLORREF);
extern int COLOR_PaletteLookupExactIndex(PALETTEENTRY *palPalEntry, int size, COLORREF col);
extern int COLOR_PaletteLookupPixel(PALETTEENTRY *, int, int * , COLORREF, BOOL);
#endif /* __WINE_COLOR_H */
......@@ -190,8 +190,10 @@ typedef struct tagDC_FUNCS
INT (*pGetDIBits)(PHYSDEV,HBITMAP,UINT,UINT,LPVOID,BITMAPINFO*,UINT);
INT (*pGetDeviceCaps)(PHYSDEV,INT);
BOOL (*pGetDeviceGammaRamp)(PHYSDEV,LPVOID);
COLORREF (*pGetNearestColor)(PHYSDEV,COLORREF);
COLORREF (*pGetPixel)(PHYSDEV,INT,INT);
INT (*pGetPixelFormat)(PHYSDEV);
UINT (*pGetSystemPaletteEntries)(PHYSDEV,UINT,UINT,LPPALETTEENTRY);
BOOL (*pGetTextExtentPoint)(PHYSDEV,LPCWSTR,INT,LPSIZE);
BOOL (*pGetTextMetrics)(PHYSDEV,TEXTMETRICW*);
INT (*pIntersectClipRect)(PHYSDEV,INT,INT,INT,INT);
......@@ -212,7 +214,8 @@ typedef struct tagDC_FUNCS
BOOL (*pPolygon)(PHYSDEV,const POINT*,INT);
BOOL (*pPolyline)(PHYSDEV,const POINT*,INT);
BOOL (*pPolylineTo)(PHYSDEV,const POINT*,INT);
UINT (*pRealizePalette)(PHYSDEV);
UINT (*pRealizeDefaultPalette)(PHYSDEV);
UINT (*pRealizePalette)(PHYSDEV,HPALETTE,BOOL);
BOOL (*pRectangle)(PHYSDEV,INT,INT,INT,INT);
HDC (*pResetDC)(PHYSDEV,const DEVMODEA*);
BOOL (*pRestoreDC)(PHYSDEV,INT);
......
......@@ -23,7 +23,11 @@
#include "gdi.h"
#define NB_RESERVED_COLORS 20 /* number of fixed colors in system palette */
#define NB_RESERVED_COLORS 20 /* number of fixed colors in system palette */
#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 */
#define PC_SYS_MAPPED 0x10 /* logical palentry is a direct alias for system palentry */
/* GDI logical palette object */
typedef struct tagPALETTEOBJ
......@@ -33,15 +37,6 @@ typedef struct tagPALETTEOBJ
LOGPALETTE logpalette; /* _MUST_ be the last field */
} PALETTEOBJ;
typedef struct tagPALETTE_DRIVER
{
int (*pSetMapping)(struct tagPALETTEOBJ *, UINT, UINT, BOOL);
int (*pUpdateMapping)(struct tagPALETTEOBJ *);
BOOL (*pIsDark)(int pixel);
} PALETTE_DRIVER;
extern PALETTE_DRIVER *PALETTE_Driver;
extern HPALETTE16 PALETTE_Init(void);
#endif /* __WINE_PALETTE_H */
......@@ -548,7 +548,7 @@ WORD WINAPI SetHookFlags16(HDC16,WORD);
INT16 WINAPI SetMapMode16(HDC16,INT16);
DWORD WINAPI SetMapperFlags16(HDC16,DWORD);
HMETAFILE16 WINAPI SetMetaFileBits16(HGLOBAL16);
UINT16 WINAPI SetPaletteEntries16(HPALETTE16,UINT16,UINT16,LPPALETTEENTRY);
UINT16 WINAPI SetPaletteEntries16(HPALETTE16,UINT16,UINT16,const PALETTEENTRY*);
COLORREF WINAPI SetPixel16(HDC16,INT16,INT16,COLORREF);
INT16 WINAPI SetPolyFillMode16(HDC16,INT16);
VOID WINAPI SetRectRgn16(HRGN16,INT16,INT16,INT16,INT16);
......
......@@ -3368,7 +3368,7 @@ DWORD WINAPI SetMapperFlags(HDC,DWORD);
HMETAFILE WINAPI SetMetaFileBitsEx(UINT,const BYTE*);
INT WINAPI SetMetaRgn(HDC);
BOOL WINAPI SetMiterLimit(HDC, FLOAT, PFLOAT);
UINT WINAPI SetPaletteEntries(HPALETTE,UINT,UINT,LPPALETTEENTRY);
UINT WINAPI SetPaletteEntries(HPALETTE,UINT,UINT,const PALETTEENTRY*);
COLORREF WINAPI SetPixel(HDC,INT,INT,COLORREF);
BOOL WINAPI SetPixelV(HDC,INT,INT,COLORREF);
BOOL WINAPI SetPixelFormat(HDC,int,const PIXELFORMATDESCRIPTOR*);
......
......@@ -302,12 +302,6 @@ extern BOOL X11DRV_IsSolidColor(COLORREF color);
extern COLORREF X11DRV_PALETTE_ToLogical(int pixel);
extern int X11DRV_PALETTE_ToPhysical(X11DRV_PDEVICE *physDev, COLORREF color);
extern struct tagPALETTE_DRIVER X11DRV_PALETTE_Driver;
extern int X11DRV_PALETTE_SetMapping(struct tagPALETTEOBJ *palPtr, UINT uStart, UINT uNum, BOOL mapOnly);
extern int X11DRV_PALETTE_UpdateMapping(struct tagPALETTEOBJ *palPtr);
extern BOOL X11DRV_PALETTE_IsDark(int pixel);
/* GDI escapes */
#define X11DRV_ESCAPE 6789
......
/*
* Color functions
*
* Copyright 1993 Alexandre Julliard
* Copyright 1996 Alex Korobka
*
* 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
*/
#include "color.h"
#include "wine/debug.h"
#include "palette.h"
#include "windef.h"
WINE_DEFAULT_DEBUG_CHANNEL(palette);
/***********************************************************************
* System color space.
*
* First 10 and last 10 colors in COLOR_sysPalette are
* "guarded". RealizePalette changes only the rest of colorcells. For
* currently inactive window it changes only DC palette mappings.
*/
PALETTEENTRY *COLOR_sysPal = NULL; /* current system palette */
const PALETTEENTRY COLOR_sysPalTemplate[NB_RESERVED_COLORS] =
{
/* first 10 entries in the system palette */
/* red green blue flags */
{ 0x00, 0x00, 0x00, PC_SYS_USED },
{ 0x80, 0x00, 0x00, PC_SYS_USED },
{ 0x00, 0x80, 0x00, PC_SYS_USED },
{ 0x80, 0x80, 0x00, PC_SYS_USED },
{ 0x00, 0x00, 0x80, PC_SYS_USED },
{ 0x80, 0x00, 0x80, PC_SYS_USED },
{ 0x00, 0x80, 0x80, PC_SYS_USED },
{ 0xc0, 0xc0, 0xc0, PC_SYS_USED },
{ 0xc0, 0xdc, 0xc0, PC_SYS_USED },
{ 0xa6, 0xca, 0xf0, PC_SYS_USED },
/* ... c_min/2 dynamic colorcells */
/* ... gap (for sparse palettes) */
/* ... c_min/2 dynamic colorcells */
{ 0xff, 0xfb, 0xf0, PC_SYS_USED },
{ 0xa0, 0xa0, 0xa4, PC_SYS_USED },
{ 0x80, 0x80, 0x80, PC_SYS_USED },
{ 0xff, 0x00, 0x00, PC_SYS_USED },
{ 0x00, 0xff, 0x00, PC_SYS_USED },
{ 0xff, 0xff, 0x00, PC_SYS_USED },
{ 0x00, 0x00, 0xff, PC_SYS_USED },
{ 0xff, 0x00, 0xff, PC_SYS_USED },
{ 0x00, 0xff, 0xff, PC_SYS_USED },
{ 0xff, 0xff, 0xff, PC_SYS_USED } /* last 10 */
};
/***********************************************************************
* COLOR_GetSystemPaletteTemplate
*/
const PALETTEENTRY* COLOR_GetSystemPaletteTemplate(void)
{
return COLOR_sysPalTemplate;
}
/***********************************************************************
* COLOR_GetSystemPaletteEntry
*/
COLORREF COLOR_GetSystemPaletteEntry(UINT i)
{
return *(COLORREF*)(COLOR_sysPal + i) & 0x00ffffff;
}
/***********************************************************************
* COLOR_PaletteLookupPixel
*/
int COLOR_PaletteLookupPixel( PALETTEENTRY* palPalEntry, int size,
int* mapping, COLORREF col, BOOL skipReserved )
{
int i, best = 0, diff = 0x7fffffff;
int r,g,b;
for( i = 0; i < size && diff ; i++ )
{
if( !(palPalEntry[i].peFlags & PC_SYS_USED) ||
(skipReserved && palPalEntry[i].peFlags & PC_SYS_RESERVED) )
continue;
r = palPalEntry[i].peRed - GetRValue(col);
g = palPalEntry[i].peGreen - GetGValue(col);
b = palPalEntry[i].peBlue - GetBValue(col);
r = r*r + g*g + b*b;
if( r < diff ) { best = i; diff = r; }
}
return (mapping) ? mapping[best] : best;
}
/***********************************************************************
* COLOR_PaletteLookupExactIndex
*/
int COLOR_PaletteLookupExactIndex( PALETTEENTRY* palPalEntry, int size,
COLORREF col )
{
int i;
BYTE r = GetRValue(col), g = GetGValue(col), b = GetBValue(col);
for( i = 0; i < size; i++ )
{
if( palPalEntry[i].peFlags & PC_SYS_USED ) /* skips gap */
if( palPalEntry[i].peRed == r &&
palPalEntry[i].peGreen == g &&
palPalEntry[i].peBlue == b )
return i;
}
return -1;
}
/***********************************************************************
* COLOR_LookupNearestColor
*/
COLORREF COLOR_LookupNearestColor( PALETTEENTRY* palPalEntry, int size, COLORREF color )
{
unsigned char spec_type = color >> 24;
int i;
/* we need logical palette for PALETTERGB and PALETTEINDEX colorrefs */
if( spec_type == 2 ) /* PALETTERGB */
color = *(COLORREF*)
(palPalEntry + COLOR_PaletteLookupPixel(palPalEntry,size,NULL,color,FALSE));
else if( spec_type == 1 ) /* PALETTEINDEX */
{
if( (i = color & 0x0000ffff) >= size )
{
WARN("RGB(%lx) : idx %d is out of bounds, assuming NULL\n", color, i);
color = *(COLORREF*)palPalEntry;
}
else color = *(COLORREF*)(palPalEntry + i);
}
color &= 0x00ffffff;
return (0x00ffffff & *(COLORREF*)
(COLOR_sysPal + COLOR_PaletteLookupPixel(COLOR_sysPal, 256, NULL, color, FALSE)));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment