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

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

dib section sync, setdibits & setpalette bugfixes

File size: 6.3 KB
Line 
1/* $Id: palette.cpp,v 1.8 2001-05-25 10:05:29 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 if(DIBSection::getSection() != NULL)
88 {
89 DIBSection *dsect = DIBSection::findHDC(hdc);
90 if(dsect)
91 {
92 dsect->sync(hdc, 0, dsect->GetHeight());
93 }
94 }
95 return hPal;
96}
97//******************************************************************************
98//******************************************************************************
99BOOL WIN32API AnimatePalette( HPALETTE arg1, UINT arg2, UINT arg3, const PALETTEENTRY * arg4)
100{
101 dprintf(("GDI32: AnimatePalette"));
102 return O32_AnimatePalette(arg1, arg2, arg3, arg4);
103}
104//******************************************************************************
105//******************************************************************************
106UINT WIN32API GetNearestPaletteIndex( HPALETTE arg1, COLORREF arg2)
107{
108 UINT rc;
109 dprintf(("GDI32: GetNearestPaletteIndex (0x%08X ,0x%08X) ",arg1,arg2));
110 rc = O32_GetNearestPaletteIndex(arg1, arg2);
111 dprintf(("Returns %d\n",rc));
112 return rc;
113}
114//******************************************************************************
115//******************************************************************************
116UINT WIN32API GetPaletteEntries(HPALETTE hPalette, UINT iStart, UINT count, PPALETTEENTRY entries)
117{
118 UINT rc;
119
120 rc = O32_GetPaletteEntries(hPalette, iStart, count, entries);
121 dprintf(("GDI32: GetPaletteEntries %x %d-%d %x returned %d", hPalette, iStart, count, entries, rc));
122 return rc;
123}
124//******************************************************************************
125//******************************************************************************
126UINT WIN32API GetSystemPaletteEntries( HDC arg1, UINT arg2, UINT arg3, PPALETTEENTRY arg4)
127{
128 UINT rc;
129
130 dprintf(("GDI32: GetSystemPaletteEntries start %d nr %d pal ptr %X", arg2, arg3, arg4));
131 rc = O32_GetSystemPaletteEntries(arg1, arg2, arg3, arg4);
132 dprintf((" GetSystemPaletteEntries returned %d", rc));
133 return(rc);
134}
135//******************************************************************************
136//******************************************************************************
137BOOL WIN32API ResizePalette( HPALETTE arg1, UINT arg2)
138{
139 dprintf(("GDI32: ResizePalette\n"));
140 return O32_ResizePalette(arg1, arg2);
141}
142//******************************************************************************
143//******************************************************************************
144UINT WIN32API SetPaletteEntries( HPALETTE hPalette, UINT arg2, UINT arg3, PALETTEENTRY * arg4)
145{
146 dprintf(("GDI32: SetPaletteEntries %x %d-%d %x", hPalette, arg2, arg3, arg4));
147 return O32_SetPaletteEntries(hPalette, arg2, arg3, (const PALETTEENTRY *)arg4);
148}
149//******************************************************************************
150//******************************************************************************
151HPALETTE WIN32API CreateHalftonePalette(HDC hdc)
152{
153 int i, r, g, b;
154 struct {
155 WORD Version;
156 WORD NumberOfEntries;
157 PALETTEENTRY aEntries[256];
158 } Palette = {
159 0x300, 256
160 };
161
162 dprintf(("GDI32: CreateHalftonePalette %x", hdc));
163 GetSystemPaletteEntries(hdc, 0, 256, Palette.aEntries);
164 return CreatePalette((LOGPALETTE *)&Palette);
165
166 for (r = 0; r < 6; r++) {
167 for (g = 0; g < 6; g++) {
168 for (b = 0; b < 6; b++) {
169 i = r + g*6 + b*36 + 10;
170 Palette.aEntries[i].peRed = r * 51;
171 Palette.aEntries[i].peGreen = g * 51;
172 Palette.aEntries[i].peBlue = b * 51;
173 }
174 }
175 }
176
177 for (i = 216; i < 246; i++) {
178 int v = (i - 216) * 8;
179 Palette.aEntries[i].peRed = v;
180 Palette.aEntries[i].peGreen = v;
181 Palette.aEntries[i].peBlue = v;
182 }
183
184 return CreatePalette((LOGPALETTE *)&Palette);
185}
186//******************************************************************************
187//******************************************************************************
Note: See TracBrowser for help on using the repository browser.