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 out of range\n");
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 if(fore
->rgbRed
* fore
->rgbRed
+ fore
->rgbGreen
* fore
->rgbGreen
+ fore
->rgbBlue
* fore
->rgbBlue
<
76 back
->rgbRed
* back
->rgbRed
+ back
->rgbGreen
* back
->rgbGreen
+ back
->rgbBlue
* back
->rgbBlue
)
81 if ( ((color
>> 16) & 0xff) + ((color
>> 8) & 0xff) + (color
& 0xff) > 255*3/2)
82 return RGB(fore
->rgbRed
, fore
->rgbGreen
, fore
->rgbBlue
);
84 return RGB(back
->rgbRed
, back
->rgbGreen
, back
->rgbBlue
);
91 /***********************************************************************
92 * DIBDRV_RealizePalette
94 UINT
DIBDRV_RealizePalette( DIBDRVPHYSDEV
*physDev
, HPALETTE hpal
, BOOL primary
)
98 MAYBE(TRACE("physDev:%p, hpal:%p, primary:%s\n", physDev
, hpal
, (primary
? "TRUE" : "FALSE")));
100 if(physDev
&& physDev
->hasDIB
)
102 /* DIB section selected in, additional (if needed) engine code */
103 ONCE(FIXME("STUB\n"));
108 /* we should in any case call X11 function, as UnrealizePalette() doesn't
109 * take a physDev parameter */
110 res
= _DIBDRV_GetDisplayDriver()->pRealizePalette(physDev
? physDev
->X11PhysDev
: NULL
, hpal
, primary
);
117 /***********************************************************************
118 * DIBDRV_UnrealizePalette
120 BOOL
DIBDRV_UnrealizePalette( HPALETTE hpal
)
124 MAYBE(TRACE("hpal:%p\n", hpal
));
126 /* we should in any case call X11 function, as UnrealizePalette() doesn't
127 * take a physDev parameter */
128 res
= _DIBDRV_GetDisplayDriver()->pUnrealizePalette(hpal
);
130 /* additional Engine code here, if needed */
131 ONCE(FIXME("STUB\n"));
136 /***********************************************************************
137 * DIBDRV_GetSystemPaletteEntries
139 UINT
DIBDRV_GetSystemPaletteEntries( DIBDRVPHYSDEV
*physDev
, UINT start
, UINT count
,
140 LPPALETTEENTRY entries
)
144 MAYBE(TRACE("physDev:%p, start:%d, count:%d, entries:%p\n", physDev
, start
, count
, entries
));
148 /* DIB section selected in, use DIB Engine */
149 ONCE(FIXME("STUB\n"));
154 /* DDB selected in, use X11 driver */
155 res
= _DIBDRV_GetDisplayDriver()->pGetSystemPaletteEntries(physDev
->X11PhysDev
, start
, count
, entries
);
160 /***********************************************************************
161 * DIBDRV_GetNearestColor
163 COLORREF
DIBDRV_GetNearestColor( DIBDRVPHYSDEV
*physDev
, COLORREF color
)
167 MAYBE(TRACE("physDev:%p, color:%x\n", physDev
, color
));
171 /* DIB section selected in, use DIB Engine */
172 ONCE(FIXME("STUB\n"));
177 /* DDB selected in, use X11 driver */
178 res
= _DIBDRV_GetDisplayDriver()->pGetNearestColor(physDev
->X11PhysDev
, color
);
183 /***********************************************************************
184 * DIBDRV_RealizeDefaultPalette
186 UINT
DIBDRV_RealizeDefaultPalette( DIBDRVPHYSDEV
*physDev
)
189 #ifdef DIBDRV_ENABLE_MAYBE
194 MAYBE(TRACE("physDev:%p\n", physDev
));
198 /* DIB section selected in, use DIB Engine */
199 ONCE(FIXME("STUB\n"));
200 /* HACK - we can't get the dib color table during SelectBitmap since it hasn't
201 been initialized yet. This is called from DC_InitDC so it's a convenient place
202 to grab the color table. */
203 MAYBE(TRACE("Color table size = %d, Color table = %p\n", physDev
->physBitmap
.colorTableSize
, physDev
->physBitmap
.colorTable
));
204 if(!physDev
->physBitmap
.colorTableGrabbed
)
206 MAYBE(TRACE("Grabbing palette\n"));
207 physDev
->physBitmap
.colorTable
= HeapAlloc(GetProcessHeap(), 0, sizeof(physDev
->physBitmap
.colorTable
[0]) * physDev
->physBitmap
.colorTableSize
);
208 GetDIBColorTable(physDev
->hdc
, 0, physDev
->physBitmap
.colorTableSize
, physDev
->physBitmap
.colorTable
);
209 #ifdef DIBDRV_ENABLE_MAYBE
210 for(i
= 0; i
< physDev
->physBitmap
.colorTableSize
; i
++)
212 q
= physDev
->physBitmap
.colorTable
+ i
;
213 TRACE(" %03d : R%03d G%03d B%03d\n", i
, q
->rgbRed
, q
->rgbGreen
, q
->rgbBlue
);
216 physDev
->physBitmap
.colorTableGrabbed
= TRUE
;
222 /* DDB selected in, use X11 driver */
223 res
= _DIBDRV_GetDisplayDriver()->pRealizeDefaultPalette(physDev
->X11PhysDev
);
228 BOOL
DIBDRV_GetICMProfile(DIBDRVPHYSDEV
*physDev
, LPDWORD lpcbName
, LPWSTR lpszFilename
)
232 MAYBE(TRACE("physDev:%p, lpcpName:%p, lpszFilename:%p\n", physDev
, lpcbName
, lpszFilename
));
236 /* DIB section selected in, use DIB Engine */
237 ONCE(FIXME("STUB\n"));
243 /* DDB selected in, use X11 driver */
244 res
= _DIBDRV_GetDisplayDriver()->pGetICMProfile(physDev
->X11PhysDev
, lpcbName
, lpszFilename
);