1 | /* $Id: OS2PALETTE.CPP,v 1.15 2001-10-03 13:49:40 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * DX palette class implementation
|
---|
5 | *
|
---|
6 | * Copyright 1998 Sander van Leeuwen
|
---|
7 | * Copyright 1999 Markus Montkowski
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 |
|
---|
13 | #include <stdio.h>
|
---|
14 | #include <stdlib.h>
|
---|
15 | #include <string.h>
|
---|
16 | #include <memory.h>
|
---|
17 | #define INITGUID
|
---|
18 | #include "os2ddraw.h"
|
---|
19 | #include "os2clipper.h"
|
---|
20 | #include "os2palette.h"
|
---|
21 | #include "os2surface.h"
|
---|
22 | #define _OS2WIN_H
|
---|
23 | #define FAR
|
---|
24 | #include <misc.h>
|
---|
25 | #include "os2palset.h"
|
---|
26 | #include "os2fsdd.h"
|
---|
27 | #include <winerror.h>
|
---|
28 |
|
---|
29 | #undef THIS
|
---|
30 | #define THIS IDirectDrawPalette*
|
---|
31 |
|
---|
32 | //******************************************************************************
|
---|
33 | //******************************************************************************
|
---|
34 | OS2IDirectDrawPalette::OS2IDirectDrawPalette( VOID *lpDirectDraw,
|
---|
35 | int palsize,
|
---|
36 | LPPALETTEENTRY lpColorTable,
|
---|
37 | DWORD dwPalFlags) :
|
---|
38 | Referenced(0), os2pal(NULL),
|
---|
39 | lastError(DD_OK), lpDraw(NULL)
|
---|
40 |
|
---|
41 | {
|
---|
42 | lpVtbl = &Vtbl;
|
---|
43 | Vtbl.AddRef = PalAddRef;
|
---|
44 | Vtbl.Release = PalRelease;
|
---|
45 | Vtbl.QueryInterface = PalQueryInterface;
|
---|
46 | Vtbl.GetCaps = PalGetCaps;
|
---|
47 | Vtbl.GetEntries = PalGetEntries;
|
---|
48 | Vtbl.Initialize = PalInitialize;
|
---|
49 | Vtbl.SetEntries = PalSetEntries;
|
---|
50 |
|
---|
51 | lpDraw = lpDirectDraw;
|
---|
52 | ((OS2IDirectDraw*)lpDraw)->Vtbl.AddRef(lpDraw);
|
---|
53 | hDive = ((OS2IDirectDraw*)lpDirectDraw)->GetDiveInstance();
|
---|
54 | dwCaps = dwPalFlags;
|
---|
55 | hDiveCC = ((OS2IDirectDraw*)lpDirectDraw)->GetCCDiveInstance();
|
---|
56 |
|
---|
57 | dwSize = palsize;
|
---|
58 | if(256==dwSize)
|
---|
59 | dwCaps |= DDPCAPS_ALLOW256;
|
---|
60 | dwCaps &= ~DDPCAPS_VSYNC; // No sync change
|
---|
61 |
|
---|
62 | os2pal = (LPPALETTEENTRY)malloc(palsize*sizeof(PALETTEENTRY));
|
---|
63 | memcpy((char *)os2pal, (char *)lpColorTable, palsize*sizeof(PALETTEENTRY));
|
---|
64 |
|
---|
65 | dprintf(("DDRAW: Init CC PalTable"));
|
---|
66 | for(DWORD i=0;i<dwSize;i++)
|
---|
67 | {
|
---|
68 | aPal16[i] = (lpColorTable[i].peBlue>>3) +
|
---|
69 | ((lpColorTable[i].peGreen>>2) <<5) +
|
---|
70 | ((lpColorTable[i].peRed>>3) << 11);
|
---|
71 | dprintf(( " # %d : RGB=%02X/%02X/%02X => %04X\n",
|
---|
72 | i,
|
---|
73 | lpColorTable[i].peRed,
|
---|
74 | lpColorTable[i].peGreen,
|
---|
75 | lpColorTable[i].peBlue,
|
---|
76 | aPal16[i]));
|
---|
77 | aPal24[i] = (lpColorTable[i].peBlue <<8) +
|
---|
78 | (lpColorTable[i].peGreen<<16) +
|
---|
79 | (lpColorTable[i].peRed<<24);
|
---|
80 | }
|
---|
81 | }
|
---|
82 | //******************************************************************************
|
---|
83 | //******************************************************************************
|
---|
84 | OS2IDirectDrawPalette::~OS2IDirectDrawPalette()
|
---|
85 | {
|
---|
86 | if(os2pal)
|
---|
87 | free(os2pal);
|
---|
88 | ((OS2IDirectDraw*)lpDraw)->Vtbl.Release((OS2IDirectDraw*)lpDraw);
|
---|
89 | }
|
---|
90 | //******************************************************************************
|
---|
91 | //******************************************************************************
|
---|
92 | HRESULT __stdcall PalQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
|
---|
93 | {
|
---|
94 | dprintf(("DDRAW: OS2IDirectDrawPalette::PalQueryInterface"));
|
---|
95 |
|
---|
96 | *ppvObj = NULL;
|
---|
97 |
|
---|
98 | if(!IsEqualGUID(riid, IID_IDirectDrawPalette))
|
---|
99 | //&& !IsEqualGUID(riid, IID_IUnknown))
|
---|
100 | return E_NOINTERFACE;
|
---|
101 |
|
---|
102 | *ppvObj = This;
|
---|
103 |
|
---|
104 | PalAddRef(This);
|
---|
105 | return(DD_OK);
|
---|
106 | }
|
---|
107 | //******************************************************************************
|
---|
108 | //******************************************************************************
|
---|
109 | ULONG __stdcall PalAddRef(THIS This)
|
---|
110 | {
|
---|
111 | OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
|
---|
112 |
|
---|
113 | dprintf(("DDRAW: OS2IDirectDrawPalette::PalAddRef %d", me->Referenced+1));
|
---|
114 |
|
---|
115 | return (++me->Referenced);
|
---|
116 | }
|
---|
117 | //******************************************************************************
|
---|
118 | //******************************************************************************
|
---|
119 | ULONG __stdcall PalRelease(THIS This)
|
---|
120 | {
|
---|
121 | OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
|
---|
122 |
|
---|
123 | dprintf(("DDRAW: OS2IDirectDrawPalette::PalRelease %d", me->Referenced-1));
|
---|
124 |
|
---|
125 | if(me->Referenced)
|
---|
126 | {
|
---|
127 | me->Referenced--;
|
---|
128 | if(me->Referenced == 0)
|
---|
129 | {
|
---|
130 | delete(me);
|
---|
131 | return(0);
|
---|
132 | }
|
---|
133 | else
|
---|
134 | return (me->Referenced);
|
---|
135 | }
|
---|
136 | else
|
---|
137 | return(0);
|
---|
138 | }
|
---|
139 | //******************************************************************************
|
---|
140 | //******************************************************************************
|
---|
141 | HRESULT __stdcall PalGetCaps(THIS This, LPDWORD lpdwCaps)
|
---|
142 | {
|
---|
143 | OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
|
---|
144 |
|
---|
145 | dprintf(("DDRAW: OS2IDirectDrawPalette::GetCaps"));
|
---|
146 |
|
---|
147 | if(NULL== lpdwCaps)
|
---|
148 | return(DDERR_INVALIDPARAMS);
|
---|
149 |
|
---|
150 | *lpdwCaps = me->dwCaps;
|
---|
151 |
|
---|
152 | if(me->fAttachedToPrimary)
|
---|
153 | *lpdwCaps |= DDPCAPS_PRIMARYSURFACE;
|
---|
154 |
|
---|
155 | return(DD_OK);
|
---|
156 | }
|
---|
157 |
|
---|
158 | //******************************************************************************
|
---|
159 | //******************************************************************************
|
---|
160 | HRESULT __stdcall PalGetEntries(THIS This, DWORD dwFlags,
|
---|
161 | DWORD dwBase,
|
---|
162 | DWORD dwNumEntries,
|
---|
163 | LPPALETTEENTRY lpEntries)
|
---|
164 | {
|
---|
165 | OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
|
---|
166 |
|
---|
167 | dprintf(("DDRAW: OS2IDirectDrawPalette::PalGetEntries"));
|
---|
168 |
|
---|
169 | if ((NULL == lpEntries) || (0 != dwFlags) || (dwBase > 0xFFFF) ||
|
---|
170 | ((dwBase + dwNumEntries) > me->dwSize))
|
---|
171 | return(DDERR_INVALIDPARAMS);
|
---|
172 |
|
---|
173 | memcpy( (char *)lpEntries,
|
---|
174 | (char *)(me->os2pal + dwBase),
|
---|
175 | dwNumEntries*sizeof(PALETTEENTRY));
|
---|
176 |
|
---|
177 | return(DD_OK);
|
---|
178 | }
|
---|
179 |
|
---|
180 | //******************************************************************************
|
---|
181 | //******************************************************************************
|
---|
182 | HRESULT __stdcall PalInitialize(THIS, LPDIRECTDRAW, DWORD, LPPALETTEENTRY)
|
---|
183 | {
|
---|
184 | dprintf(("DDRAW: OS2IDirectDrawPalette::PalInitialize"));
|
---|
185 | return(DDERR_ALREADYINITIALIZED);
|
---|
186 | }
|
---|
187 | //******************************************************************************
|
---|
188 | //******************************************************************************
|
---|
189 | HRESULT __stdcall PalSetEntries(THIS This, DWORD dwFlags,
|
---|
190 | DWORD dwBase,
|
---|
191 | DWORD dwNumEntries,
|
---|
192 | LPPALETTEENTRY lpNewEntries)
|
---|
193 | {
|
---|
194 | OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
|
---|
195 |
|
---|
196 | dprintf(("DDRAW: OS2IDirectDrawPalette::PalSetEntries\n"));
|
---|
197 | if ((NULL == lpNewEntries) || (0 != dwFlags) || (dwBase > 0xFFFF) ||
|
---|
198 | ((dwBase + dwNumEntries) > me->dwSize))
|
---|
199 | return(DDERR_INVALIDPARAMS);
|
---|
200 |
|
---|
201 | memcpy((char *)(me->os2pal + dwBase),
|
---|
202 | (char *)lpNewEntries,
|
---|
203 | dwNumEntries*sizeof(PALETTEENTRY));
|
---|
204 |
|
---|
205 | dprintf(("DDRAW: Setting up CC Palentries:\n"));
|
---|
206 | for(DWORD i=0;i<dwNumEntries;i++)
|
---|
207 | {
|
---|
208 | me->aPal16[dwBase+i] = (lpNewEntries[i].peBlue>>3) +
|
---|
209 | ((lpNewEntries[i].peGreen>>2) <<5) +
|
---|
210 | ((lpNewEntries[i].peRed>>3) << 11);
|
---|
211 | dprintf(( " # %d : RGB=%02X/%02X/%02X => %04X\n",
|
---|
212 | dwBase+i,
|
---|
213 | lpNewEntries[i].peRed,
|
---|
214 | lpNewEntries[i].peGreen,
|
---|
215 | lpNewEntries[i].peBlue,
|
---|
216 | me->aPal16[dwBase+i]));
|
---|
217 | me->aPal24[dwBase+i] = (lpNewEntries[i].peBlue <<8) +
|
---|
218 | (lpNewEntries[i].peGreen<<16) +
|
---|
219 | (lpNewEntries[i].peRed<<24);
|
---|
220 | }
|
---|
221 |
|
---|
222 | if (8==((OS2IDirectDraw*)me->lpDraw)->dCaps.ulDepth)
|
---|
223 | {
|
---|
224 | if(me->fAttachedToPrimary)
|
---|
225 | me->SetPhysPalette();
|
---|
226 | }
|
---|
227 | else
|
---|
228 | {
|
---|
229 | if(NULL!=((OS2IDirectDraw*)me->lpDraw)->pPrimSurf)
|
---|
230 | ((OS2IDirectDrawSurface*)((OS2IDirectDraw*)me->lpDraw)->pPrimSurf)->ColorConversion(NULL);
|
---|
231 | }
|
---|
232 | return(DD_OK);
|
---|
233 | }
|
---|
234 | //******************************************************************************
|
---|
235 | //******************************************************************************
|
---|
236 | void OS2IDirectDrawPalette::SetPhysPalette()
|
---|
237 | {
|
---|
238 | // Run appropriate code depening on whether FS DDraw is enabled
|
---|
239 | if (bUseFSDD)
|
---|
240 | SetSVGAPalette(os2pal);
|
---|
241 | else
|
---|
242 | OS2SetPhysPalette(os2pal);
|
---|
243 | }
|
---|
244 | //******************************************************************************
|
---|
245 | //******************************************************************************
|
---|
246 | void OS2IDirectDrawPalette::RestorePhysPalette()
|
---|
247 | {
|
---|
248 | OS2ResetPhysPalette();
|
---|
249 | }
|
---|
250 | //******************************************************************************
|
---|
251 | //******************************************************************************
|
---|
252 | void OS2IDirectDrawPalette::SetIsPrimary(BOOL fNewVal)
|
---|
253 | {
|
---|
254 | if(fNewVal==fAttachedToPrimary)
|
---|
255 | return;
|
---|
256 | fAttachedToPrimary = fNewVal;
|
---|
257 |
|
---|
258 | /*
|
---|
259 | if(fAttachedToPrimary)
|
---|
260 | {
|
---|
261 | if(NULL!=hDiveCC)
|
---|
262 | DiveSetSourcePalette( hDiveCC,
|
---|
263 | 0,
|
---|
264 | 255,
|
---|
265 | (PBYTE)os2pal);
|
---|
266 | else
|
---|
267 | SetPhysPalette();
|
---|
268 | }
|
---|
269 | */
|
---|
270 | }
|
---|
271 | //******************************************************************************
|
---|
272 | //******************************************************************************
|
---|
273 |
|
---|