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

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

lots of small changes; CreateHalftonePalette + rgb 565 -> rgb 555 conversion

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