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

Last change on this file since 5120 was 4127, checked in by sandervl, 25 years ago

workaround for palette problems in PowerDVD

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