1 | /* $Id: OS2PALETTE.CPP,v 1.1 2000-04-07 18:21:04 mike Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * DX palette class implementation
|
---|
5 | *
|
---|
6 | * Copyright 1998 Sander va 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 | #ifdef DEBUG
|
---|
95 | dprintf(("DDRAW: OS2IDirectDrawPalette::PalQueryInterface\n"));
|
---|
96 | #endif
|
---|
97 |
|
---|
98 | *ppvObj = NULL;
|
---|
99 |
|
---|
100 | if(!IsEqualGUID(riid, IID_IDirectDrawPalette))
|
---|
101 | //&& !IsEqualGUID(riid, IID_IUnknown))
|
---|
102 | return E_NOINTERFACE;
|
---|
103 |
|
---|
104 | *ppvObj = This;
|
---|
105 |
|
---|
106 | PalAddRef(This);
|
---|
107 | return(DD_OK);
|
---|
108 | }
|
---|
109 | //******************************************************************************
|
---|
110 | //******************************************************************************
|
---|
111 | ULONG __stdcall PalAddRef(THIS This)
|
---|
112 | {
|
---|
113 | OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
|
---|
114 |
|
---|
115 | #ifdef DEBUG
|
---|
116 | dprintf(("DDRAW: OS2IDirectDrawPalette::PalAddRef %d\n", me->Referenced+1));
|
---|
117 | #endif
|
---|
118 |
|
---|
119 | return (++me->Referenced);
|
---|
120 | }
|
---|
121 | //******************************************************************************
|
---|
122 | //******************************************************************************
|
---|
123 | ULONG __stdcall PalRelease(THIS This)
|
---|
124 | {
|
---|
125 | OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
|
---|
126 |
|
---|
127 | #ifdef DEBUG
|
---|
128 | dprintf(("DDRAW: OS2IDirectDrawPalette::PalRelease %d\n", me->Referenced-1));
|
---|
129 | #endif
|
---|
130 |
|
---|
131 | if(me->Referenced)
|
---|
132 | {
|
---|
133 | me->Referenced--;
|
---|
134 | if(me->Referenced == 0)
|
---|
135 | {
|
---|
136 | delete(me);
|
---|
137 | return(0);
|
---|
138 | }
|
---|
139 | else
|
---|
140 | return (me->Referenced);
|
---|
141 | }
|
---|
142 | else
|
---|
143 | return(0);
|
---|
144 | }
|
---|
145 | //******************************************************************************
|
---|
146 | //******************************************************************************
|
---|
147 | HRESULT __stdcall PalGetCaps(THIS This, LPDWORD lpdwCaps)
|
---|
148 | {
|
---|
149 | OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
|
---|
150 |
|
---|
151 | #ifdef DEBUG
|
---|
152 | dprintf(("DDRAW: OS2IDirectDrawPalette::GetCaps\n"));
|
---|
153 | #endif
|
---|
154 |
|
---|
155 | if(NULL== lpdwCaps)
|
---|
156 | return(DDERR_INVALIDPARAMS);
|
---|
157 |
|
---|
158 | *lpdwCaps = me->dwCaps;
|
---|
159 |
|
---|
160 | if(me->fAttachedToPrimary)
|
---|
161 | *lpdwCaps |= DDPCAPS_PRIMARYSURFACE;
|
---|
162 |
|
---|
163 | return(DD_OK);
|
---|
164 | }
|
---|
165 | //******************************************************************************
|
---|
166 | //******************************************************************************
|
---|
167 | HRESULT __stdcall PalGetEntries(THIS This, DWORD dwFlags,
|
---|
168 | DWORD dwBase,
|
---|
169 | DWORD dwNumEntries,
|
---|
170 | LPPALETTEENTRY lpEntries)
|
---|
171 | {
|
---|
172 | OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
|
---|
173 |
|
---|
174 | #ifdef DEBUG
|
---|
175 | dprintf(("DDRAW: OS2IDirectDrawPalette::PalGetEntries\n"));
|
---|
176 | #endif
|
---|
177 |
|
---|
178 | if( (NULL== lpEntries) ||(0!=dwFlags) ||(dwBase<0) ||((dwBase + dwNumEntries)>me->dwSize) )
|
---|
179 | return(DDERR_INVALIDPARAMS);
|
---|
180 |
|
---|
181 | memcpy( (char *)lpEntries,
|
---|
182 | (char *)(me->os2pal + dwBase),
|
---|
183 | dwNumEntries*sizeof(PALETTEENTRY));
|
---|
184 |
|
---|
185 | return(DD_OK);
|
---|
186 | }
|
---|
187 | //******************************************************************************
|
---|
188 | //******************************************************************************
|
---|
189 | HRESULT __stdcall PalInitialize(THIS, LPDIRECTDRAW, DWORD, LPPALETTEENTRY)
|
---|
190 | {
|
---|
191 | #ifdef DEBUG
|
---|
192 | dprintf(("DDRAW: OS2IDirectDrawPalette::PalInitialize\n"));
|
---|
193 | #endif
|
---|
194 | return(DDERR_ALREADYINITIALIZED);
|
---|
195 | }
|
---|
196 | //******************************************************************************
|
---|
197 | //******************************************************************************
|
---|
198 | HRESULT __stdcall PalSetEntries(THIS This, DWORD dwFlags,
|
---|
199 | DWORD dwBase,
|
---|
200 | DWORD dwNumEntries,
|
---|
201 | LPPALETTEENTRY lpNewEntries)
|
---|
202 | {
|
---|
203 | OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
|
---|
204 |
|
---|
205 | #ifdef DEBUG
|
---|
206 | dprintf(("DDRAW: OS2IDirectDrawPalette::PalSetEntries\n"));
|
---|
207 | #endif
|
---|
208 | if( (NULL== lpNewEntries) ||(0!=dwFlags) ||(dwBase<0) ||((dwBase + dwNumEntries)>me->dwSize) )
|
---|
209 | return(DDERR_INVALIDPARAMS);
|
---|
210 |
|
---|
211 | memcpy((char *)(me->os2pal + dwBase),
|
---|
212 | (char *)lpNewEntries,
|
---|
213 | dwNumEntries*sizeof(PALETTEENTRY));
|
---|
214 |
|
---|
215 | dprintf(("DDRAW: Setting up CC Palentries:\n"));
|
---|
216 | for(DWORD i=0;i<dwNumEntries;i++)
|
---|
217 | {
|
---|
218 | me->aPal16[dwBase+i] = (lpNewEntries[i].peBlue>>3) +
|
---|
219 | ((lpNewEntries[i].peGreen>>2) <<5) +
|
---|
220 | ((lpNewEntries[i].peRed>>3) << 11);
|
---|
221 | dprintf(( " # %d : RGB=%02X/%02X/%02X => %04X\n",
|
---|
222 | dwBase+i,
|
---|
223 | lpNewEntries[i].peRed,
|
---|
224 | lpNewEntries[i].peGreen,
|
---|
225 | lpNewEntries[i].peBlue,
|
---|
226 | me->aPal16[dwBase+i]));
|
---|
227 | me->aPal24[dwBase+i] = (lpNewEntries[i].peBlue <<8) +
|
---|
228 | (lpNewEntries[i].peGreen<<16) +
|
---|
229 | (lpNewEntries[i].peRed<<24);
|
---|
230 | }
|
---|
231 |
|
---|
232 | if(8==((OS2IDirectDraw*)me->lpDraw)->dCaps.ulDepth)
|
---|
233 | {
|
---|
234 | if(me->fAttachedToPrimary)
|
---|
235 | me->SetPhysPalette();
|
---|
236 | }
|
---|
237 | else
|
---|
238 | {
|
---|
239 | if(NULL!=((OS2IDirectDraw*)me->lpDraw)->pPrimSurf)
|
---|
240 | ((OS2IDirectDrawSurface*)((OS2IDirectDraw*)me->lpDraw)->pPrimSurf)->ColorConversion(NULL);
|
---|
241 | }
|
---|
242 | return(DD_OK);
|
---|
243 | }
|
---|
244 | //******************************************************************************
|
---|
245 | //******************************************************************************
|
---|
246 | void OS2IDirectDrawPalette::SetPhysPalette()
|
---|
247 | {
|
---|
248 | #if 0
|
---|
249 | OS2SetPhysPalette(os2pal);
|
---|
250 | #else
|
---|
251 | SetSVGAPalette(os2pal);
|
---|
252 | #endif
|
---|
253 | }
|
---|
254 | //******************************************************************************
|
---|
255 | //******************************************************************************
|
---|
256 | void OS2IDirectDrawPalette::RestorePhysPalette()
|
---|
257 | {
|
---|
258 | OS2ResetPhysPalette();
|
---|
259 | }
|
---|
260 | //******************************************************************************
|
---|
261 | //******************************************************************************
|
---|
262 | void OS2IDirectDrawPalette::SetIsPrimary(BOOL fNewVal)
|
---|
263 | {
|
---|
264 | if(fNewVal==fAttachedToPrimary)
|
---|
265 | return;
|
---|
266 | fAttachedToPrimary = fNewVal;
|
---|
267 |
|
---|
268 | /*
|
---|
269 | if(fAttachedToPrimary)
|
---|
270 | {
|
---|
271 | if(NULL!=hDiveCC)
|
---|
272 | DiveSetSourcePalette( hDiveCC,
|
---|
273 | 0,
|
---|
274 | 255,
|
---|
275 | (PBYTE)os2pal);
|
---|
276 | else
|
---|
277 | SetPhysPalette();
|
---|
278 | }
|
---|
279 | */
|
---|
280 | }
|
---|
281 | //******************************************************************************
|
---|
282 | //******************************************************************************
|
---|
283 |
|
---|