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