configure: Changes from running autconf after previous patch.
[wine/hacks.git] / dlls / winedib.drv / palette.c
blob301cf1dec43e9fc0ac5dab0445714721fcb5f5db
1 /*
2 * DIBDRV palette objects
4 * Copyright 2009 Massimo Del Fedele
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include "dibdrv.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
28 /* maps a colorref to actual color */
29 COLORREF _DIBDRV_MapColor(DIBDRVPHYSDEV *physDev, COLORREF color)
31 WORD index;
32 RGBQUAD *palColor;
33 HPALETTE hPal;
34 PALETTEENTRY paletteEntry;
36 switch(color >> 24)
38 case 0x10 : /* DIBINDEX */
39 MAYBE(TRACE("DIBINDEX Color is %08x\n", color));
40 index = color & 0xffff;
41 if(index >= physDev->physBitmap->colorTableSize)
43 WARN("DIBINDEX color %d out of range, color table size is %d\n", index, physDev->physBitmap->colorTableSize);
44 return 0;
46 palColor = physDev->physBitmap->colorTable + index;
47 MAYBE(TRACE("Returning color %08x\n", RGB(palColor->rgbRed, palColor->rgbGreen, palColor->rgbBlue)));
48 return RGB(palColor->rgbRed, palColor->rgbGreen, palColor->rgbBlue);
50 case 0x01: /* PALETTEINDEX */
51 MAYBE(TRACE("PALETTEINDEX Color is %08x\n", color));
52 index = color & 0xffff;
53 if(!(hPal = GetCurrentObject(physDev->hdc, OBJ_PAL)))
55 ERR("Couldn't get palette\n");
56 return 0;
58 if (!GetPaletteEntries(hPal, index, 1, &paletteEntry))
60 WARN("PALETTEINDEX(%x) : index %d is out of bounds, assuming black\n", color, index);
61 return 0;
63 MAYBE(TRACE("Returning color %08x\n", RGB(paletteEntry.peRed, paletteEntry.peGreen, paletteEntry.peBlue)));
64 return RGB(paletteEntry.peRed, paletteEntry.peGreen, paletteEntry.peBlue);
66 case 0x02: /* PALETTERGB */
67 return _DIBDRV_GetNearestColor(physDev->physBitmap, color & 0xffffff);
69 default:
70 /* RGB color -- we must process special case for monochrome bitmaps */
71 if(physDev->physBitmap->bitCount == 1)
73 RGBQUAD *back = physDev->physBitmap->colorTable;
74 RGBQUAD *fore = back+1;
75 COLORREF lightColorref, darkColorref;
77 /* lightest color is considered to be 'foreground' one, i.e. associated to white color */
78 if(physDev->physBitmap->lightColor == 1)
80 darkColorref = RGB(back->rgbRed, back->rgbGreen, back->rgbBlue);
81 lightColorref = RGB(fore->rgbRed, fore->rgbGreen, fore->rgbBlue);
83 else
85 darkColorref = RGB(fore->rgbRed, fore->rgbGreen, fore->rgbBlue);
86 lightColorref = RGB(back->rgbRed, back->rgbGreen, back->rgbBlue);
89 /* tested on Windows XP -- if present in colortable, maps to corresponding color
90 if not, if white maps to the lightest color, otherwise darkest one. */
91 if(color == lightColorref || color == darkColorref)
92 return color;
93 else if (color == 0x00ffffff)
94 return lightColorref;
95 else
96 return darkColorref;
98 else
99 return color;
103 /***********************************************************************
104 * DIBDRV_RealizePalette
106 UINT DIBDRV_RealizePalette( DIBDRVPHYSDEV *physDev, HPALETTE hpal, BOOL primary )
108 UINT res = 0;
110 MAYBE(TRACE("physDev:%p, hpal:%p, primary:%s\n", physDev, hpal, (primary ? "TRUE" : "FALSE")));
112 if(physDev && physDev->hasDIB)
114 /* DIB section selected in, additional (if needed) engine code */
115 ONCE(FIXME("STUB\n"));
116 res = 0;
118 else
120 /* we should in any case call X11 function, as UnrealizePalette() doesn't
121 * take a physDev parameter */
122 res = _DIBDRV_GetDisplayDriver()->pRealizePalette(physDev ? physDev->X11PhysDev : NULL, hpal, primary);
126 return res;
129 /***********************************************************************
130 * DIBDRV_UnrealizePalette
132 BOOL DIBDRV_UnrealizePalette( HPALETTE hpal )
134 BOOL res;
136 MAYBE(TRACE("hpal:%p\n", hpal));
138 /* we should in any case call X11 function, as UnrealizePalette() doesn't
139 * take a physDev parameter */
140 res = _DIBDRV_GetDisplayDriver()->pUnrealizePalette(hpal);
142 /* additional Engine code here, if needed */
143 ONCE(FIXME("STUB\n"));
145 return res;
148 /***********************************************************************
149 * DIBDRV_GetSystemPaletteEntries
151 UINT DIBDRV_GetSystemPaletteEntries( DIBDRVPHYSDEV *physDev, UINT start, UINT count,
152 LPPALETTEENTRY entries )
154 UINT res;
156 MAYBE(TRACE("physDev:%p, start:%d, count:%d, entries:%p\n", physDev, start, count, entries));
158 if(physDev->hasDIB)
160 /* DIB section selected in, use DIB Engine */
161 ONCE(FIXME("STUB\n"));
162 res = 0;
164 else
166 /* DDB selected in, use X11 driver */
167 res = _DIBDRV_GetDisplayDriver()->pGetSystemPaletteEntries(physDev->X11PhysDev, start, count, entries);
169 return res;
172 /***********************************************************************
173 * DIBDRV_GetNearestColor
175 COLORREF DIBDRV_GetNearestColor( DIBDRVPHYSDEV *physDev, COLORREF color )
177 COLORREF res;
179 MAYBE(TRACE("physDev:%p, color:%x\n", physDev, color));
181 if(physDev->hasDIB)
183 /* DIB section selected in, use DIB Engine */
184 ONCE(FIXME("STUB\n"));
185 res = 0;
187 else
189 /* DDB selected in, use X11 driver */
190 res = _DIBDRV_GetDisplayDriver()->pGetNearestColor(physDev->X11PhysDev, color);
192 return res;
195 /***********************************************************************
196 * DIBDRV_RealizeDefaultPalette
198 UINT DIBDRV_RealizeDefaultPalette( DIBDRVPHYSDEV *physDev )
200 UINT res;
201 #ifdef DIBDRV_ENABLE_MAYBE
202 int i;
203 RGBQUAD *q;
204 #endif
206 MAYBE(TRACE("physDev:%p\n", physDev));
208 if(physDev->hasDIB)
210 /* DIB section selected in, use DIB Engine */
211 ONCE(FIXME("STUB\n"));
212 /* HACK - we can't get the dib color table during SelectBitmap since it hasn't
213 been initialized yet. This is called from DC_InitDC so it's a convenient place
214 to grab the color table. */
215 MAYBE(TRACE("Color table size = %d, Color table = %p\n", physDev->physBitmap->colorTableSize, physDev->physBitmap->colorTable));
216 if(!physDev->physBitmap->colorTableGrabbed)
218 MAYBE(TRACE("Grabbing palette\n"));
219 physDev->physBitmap->colorTable = HeapAlloc(GetProcessHeap(), 0, sizeof(physDev->physBitmap->colorTable[0]) * physDev->physBitmap->colorTableSize);
220 GetDIBColorTable(physDev->hdc, 0, physDev->physBitmap->colorTableSize, physDev->physBitmap->colorTable);
221 #ifdef DIBDRV_ENABLE_MAYBE
222 for(i = 0; i < physDev->physBitmap->colorTableSize; i++)
224 q = physDev->physBitmap->colorTable + i;
225 TRACE(" %03d : R%03d G%03d B%03d\n", i, q->rgbRed, q->rgbGreen, q->rgbBlue);
227 #endif
228 physDev->physBitmap->colorTableGrabbed = TRUE;
230 /* for monochrome bitmaps, we need the 'lightest' color */
231 _DIBDRVBITMAP_GetLightestColorIndex(physDev->physBitmap);
234 res = 0;
236 else
238 /* DDB selected in, use X11 driver */
239 res = _DIBDRV_GetDisplayDriver()->pRealizeDefaultPalette(physDev->X11PhysDev);
241 return res;
244 BOOL DIBDRV_GetICMProfile(DIBDRVPHYSDEV *physDev, LPDWORD lpcbName, LPWSTR lpszFilename)
246 BOOL res;
248 MAYBE(TRACE("physDev:%p, lpcpName:%p, lpszFilename:%p\n", physDev, lpcbName, lpszFilename));
250 if(physDev->hasDIB)
252 /* DIB section selected in, use DIB Engine */
253 ONCE(FIXME("STUB\n"));
255 res = 0;
257 else
259 /* DDB selected in, use X11 driver */
260 res = _DIBDRV_GetDisplayDriver()->pGetICMProfile(physDev->X11PhysDev, lpcbName, lpszFilename);
262 return res;