source: trunk/src/gdi32/palette.cpp@ 5890

Last change on this file since 5890 was 5825, checked in by sandervl, 24 years ago

Set/GetDIBColorTable fixes + SelectPalette hack

File size: 6.4 KB
Line 
1/* $Id: palette.cpp,v 1.9 2001-05-29 09:45:21 sandervl Exp $ */
2
3/*
4 * GDI32 palette apis
5 *
6 * Based on Wine code (991031) (objects\palette.c)
7 *
8 * Copyright 1993,1994 Alexandre Julliard
9 * Copyright 1996 Alex Korobka
10 *
11 * Project Odin Software License can be found in LICENSE.TXT
12 *
13 */
14#include <os2win.h>
15#include <stdlib.h>
16#include <misc.h>
17#include <string.h>
18#include "dibsect.h"
19
20#define DBG_LOCALLOG DBG_palette
21#include "dbglocal.h"
22
23static UINT SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */
24
25/***********************************************************************
26 * SetSystemPaletteUse32 [GDI32.335]
27 *
28 * RETURNS
29 * Success: Previous system palette
30 * Failure: SYSPAL_ERROR
31 */
32UINT WINAPI SetSystemPaletteUse(
33 HDC hdc, /* [in] Handle of device context */
34 UINT use) /* [in] Palette-usage flag */
35{
36 UINT old = SystemPaletteUse;
37 dprintf(("SetSystemPaletteUse: (%04x,%04x): stub\n", hdc, use ));
38 SystemPaletteUse = use;
39 return old;
40}
41/***********************************************************************
42 * GetSystemPaletteUse32 [GDI32.223] Gets state of system palette
43 *
44 * RETURNS
45 * Current state of system palette
46 */
47UINT WINAPI GetSystemPaletteUse(HDC hdc) /* [in] Handle of device context */
48{
49 dprintf(("GetSystemPaletteUse %x", hdc));
50 return SystemPaletteUse;
51}
52//******************************************************************************
53//******************************************************************************
54UINT WIN32API RealizePalette( HDC hdc)
55{
56 UINT rc;
57
58 rc = O32_RealizePalette(hdc);
59 dprintf(("GDI32: RealizePalette %x returned %d", hdc, rc));
60 return rc;
61}
62//******************************************************************************
63//******************************************************************************
64HPALETTE WIN32API CreatePalette( const LOGPALETTE * arg1)
65{
66 HPALETTE rc;
67
68#ifdef DEBUG_PALETTE
69 for(int i=0; i<arg1->palNumEntries;i++)
70 {
71 dprintf2(("Index %d : 0x%08X\n",i, *((DWORD*)(&arg1->palPalEntry[i])) ));
72 }
73#endif
74 rc = O32_CreatePalette(arg1);
75 dprintf(("GDI32: CreatePalette %x %d returns 0x%08X\n", arg1, arg1->palNumEntries, rc));
76
77 return rc;
78}
79//******************************************************************************
80//******************************************************************************
81HPALETTE WIN32API SelectPalette(HDC hdc, HPALETTE hPalette, BOOL bForceBackground)
82{
83 HPALETTE hPal;
84
85 dprintf(("GDI32: SelectPalette (0x%08X, 0x%08X, 0x%08X)", hdc, hPalette, bForceBackground));
86 hPal = O32_SelectPalette(hdc, hPalette, bForceBackground);
87
88 //hack for beyond compare buttons (+ other apps)
89 //seems to select old palette into dc before unselecting dib section
90 if(bForceBackground != -1 && DIBSection::getSection() != NULL)
91 {
92 DIBSection *dsect = DIBSection::findHDC(hdc);
93 if(dsect)
94 {
95 dsect->sync(hdc, 0, dsect->GetHeight());
96 }
97 }
98 return hPal;
99}
100//******************************************************************************
101//******************************************************************************
102BOOL WIN32API AnimatePalette( HPALETTE arg1, UINT arg2, UINT arg3, const PALETTEENTRY * arg4)
103{
104 dprintf(("GDI32: AnimatePalette"));
105 return O32_AnimatePalette(arg1, arg2, arg3, arg4);
106}
107//******************************************************************************
108//******************************************************************************
109UINT WIN32API GetNearestPaletteIndex( HPALETTE arg1, COLORREF arg2)
110{
111 UINT rc;
112 dprintf(("GDI32: GetNearestPaletteIndex (0x%08X ,0x%08X) ",arg1,arg2));
113 rc = O32_GetNearestPaletteIndex(arg1, arg2);
114 dprintf(("Returns %d\n",rc));
115 return rc;
116}
117//******************************************************************************
118//******************************************************************************
119UINT WIN32API GetPaletteEntries(HPALETTE hPalette, UINT iStart, UINT count, PPALETTEENTRY entries)
120{
121 UINT rc;
122
123 rc = O32_GetPaletteEntries(hPalette, iStart, count, entries);
124 dprintf(("GDI32: GetPaletteEntries %x %d-%d %x returned %d", hPalette, iStart, count, entries, rc));
125 return rc;
126}
127//******************************************************************************
128//******************************************************************************
129UINT WIN32API GetSystemPaletteEntries( HDC arg1, UINT arg2, UINT arg3, PPALETTEENTRY arg4)
130{
131 UINT rc;
132
133 dprintf(("GDI32: GetSystemPaletteEntries start %d nr %d pal ptr %X", arg2, arg3, arg4));
134 rc = O32_GetSystemPaletteEntries(arg1, arg2, arg3, arg4);
135 dprintf((" GetSystemPaletteEntries returned %d", rc));
136 return(rc);
137}
138//******************************************************************************
139//******************************************************************************
140BOOL WIN32API ResizePalette( HPALETTE arg1, UINT arg2)
141{
142 dprintf(("GDI32: ResizePalette\n"));
143 return O32_ResizePalette(arg1, arg2);
144}
145//******************************************************************************
146//******************************************************************************
147UINT WIN32API SetPaletteEntries( HPALETTE hPalette, UINT arg2, UINT arg3, PALETTEENTRY * arg4)
148{
149 dprintf(("GDI32: SetPaletteEntries %x %d-%d %x", hPalette, arg2, arg3, arg4));
150 return O32_SetPaletteEntries(hPalette, arg2, arg3, (const PALETTEENTRY *)arg4);
151}
152//******************************************************************************
153//******************************************************************************
154HPALETTE WIN32API CreateHalftonePalette(HDC hdc)
155{
156 int i, r, g, b;
157 struct {
158 WORD Version;
159 WORD NumberOfEntries;
160 PALETTEENTRY aEntries[256];
161 } Palette = {
162 0x300, 256
163 };
164
165 dprintf(("GDI32: CreateHalftonePalette %x", hdc));
166 GetSystemPaletteEntries(hdc, 0, 256, Palette.aEntries);
167 return CreatePalette((LOGPALETTE *)&Palette);
168
169 for (r = 0; r < 6; r++) {
170 for (g = 0; g < 6; g++) {
171 for (b = 0; b < 6; b++) {
172 i = r + g*6 + b*36 + 10;
173 Palette.aEntries[i].peRed = r * 51;
174 Palette.aEntries[i].peGreen = g * 51;
175 Palette.aEntries[i].peBlue = b * 51;
176 }
177 }
178 }
179
180 for (i = 216; i < 246; i++) {
181 int v = (i - 216) * 8;
182 Palette.aEntries[i].peRed = v;
183 Palette.aEntries[i].peGreen = v;
184 Palette.aEntries[i].peBlue = v;
185 }
186
187 return CreatePalette((LOGPALETTE *)&Palette);
188}
189//******************************************************************************
190//******************************************************************************
Note: See TracBrowser for help on using the repository browser.