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
22 #include "wine/port.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dibdrv
);
28 /* maps a colorref to actual color */
29 COLORREF
_DIBDRV_MapColor(DIBDRVPHYSDEV
*physDev
, COLORREF color
)
34 PALETTEENTRY paletteEntry
;
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
);
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");
58 if (!GetPaletteEntries(hPal
, index
, 1, &paletteEntry
))
60 WARN("PALETTEINDEX(%x) : index %d is out of bounds, assuming black\n", color
, index
);
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);
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
);
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
)
93 else if (color
== 0x00ffffff)
103 /***********************************************************************
104 * DIBDRV_RealizePalette
106 UINT
DIBDRV_RealizePalette( DIBDRVPHYSDEV
*physDev
, HPALETTE hpal
, BOOL primary
)
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"));
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
);
129 /***********************************************************************
130 * DIBDRV_UnrealizePalette
132 BOOL
DIBDRV_UnrealizePalette( HPALETTE hpal
)
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"));
148 /***********************************************************************
149 * DIBDRV_GetSystemPaletteEntries
151 UINT
DIBDRV_GetSystemPaletteEntries( DIBDRVPHYSDEV
*physDev
, UINT start
, UINT count
,
152 LPPALETTEENTRY entries
)
156 MAYBE(TRACE("physDev:%p, start:%d, count:%d, entries:%p\n", physDev
, start
, count
, entries
));
160 /* DIB section selected in, use DIB Engine */
161 ONCE(FIXME("STUB\n"));
166 /* DDB selected in, use X11 driver */
167 res
= _DIBDRV_GetDisplayDriver()->pGetSystemPaletteEntries(physDev
->X11PhysDev
, start
, count
, entries
);
172 /***********************************************************************
173 * DIBDRV_GetNearestColor
175 COLORREF
DIBDRV_GetNearestColor( DIBDRVPHYSDEV
*physDev
, COLORREF color
)
179 MAYBE(TRACE("physDev:%p, color:%x\n", physDev
, color
));
183 /* DIB section selected in, use DIB Engine */
184 ONCE(FIXME("STUB\n"));
189 /* DDB selected in, use X11 driver */
190 res
= _DIBDRV_GetDisplayDriver()->pGetNearestColor(physDev
->X11PhysDev
, color
);
195 /***********************************************************************
196 * DIBDRV_RealizeDefaultPalette
198 UINT
DIBDRV_RealizeDefaultPalette( DIBDRVPHYSDEV
*physDev
)
201 #ifdef DIBDRV_ENABLE_MAYBE
206 MAYBE(TRACE("physDev:%p\n", physDev
));
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
);
228 physDev
->physBitmap
->colorTableGrabbed
= TRUE
;
230 /* for monochrome bitmaps, we need the 'lightest' color */
231 _DIBDRVBITMAP_GetLightestColorIndex(physDev
->physBitmap
);
238 /* DDB selected in, use X11 driver */
239 res
= _DIBDRV_GetDisplayDriver()->pRealizeDefaultPalette(physDev
->X11PhysDev
);
244 BOOL
DIBDRV_GetICMProfile(DIBDRVPHYSDEV
*physDev
, LPDWORD lpcbName
, LPWSTR lpszFilename
)
248 MAYBE(TRACE("physDev:%p, lpcpName:%p, lpszFilename:%p\n", physDev
, lpcbName
, lpszFilename
));
252 /* DIB section selected in, use DIB Engine */
253 ONCE(FIXME("STUB\n"));
259 /* DDB selected in, use X11 driver */
260 res
= _DIBDRV_GetDisplayDriver()->pGetICMProfile(physDev
->X11PhysDev
, lpcbName
, lpszFilename
);