source: trunk/src/ddraw/OS2PALETTE.CPP@ 587

Last change on this file since 587 was 587, checked in by hugh, 26 years ago

Implemented new colorconversion routine and fixed bug in fastblt function.
Changed the palettehandling code

File size: 8.5 KB
Line 
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//******************************************************************************
21OS2IDirectDrawPalette::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 for(DWORD i=0;i<dwSize;i++)
53 {
54 aPal16[i] = (lpColorTable[i].peBlue>>3) +
55 ((lpColorTable[i].peGreen>>2) <<5) +
56 ((lpColorTable[i].peRed>>3) << 11);
57 aPal24[i] = (lpColorTable[i].peBlue <<8) +
58 (lpColorTable[i].peGreen<<16) +
59 (lpColorTable[i].peRed<<24);
60 }
61}
62//******************************************************************************
63//******************************************************************************
64OS2IDirectDrawPalette::~OS2IDirectDrawPalette()
65{
66 if(os2pal)
67 free(os2pal);
68 ((OS2IDirectDraw*)lpDraw)->Vtbl.Release((OS2IDirectDraw*)lpDraw);
69}
70//******************************************************************************
71//******************************************************************************
72HRESULT __stdcall PalQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
73{
74 #ifdef DEBUG
75 WriteLog("OS2IDirectDrawPalette::PalQueryInterface\n");
76 #endif
77
78 *ppvObj = NULL;
79
80 if(!IsEqualGUID(riid, IID_IDirectDrawPalette))
81//&& !IsEqualGUID(riid, IID_IUnknown))
82 return E_NOINTERFACE;
83
84 *ppvObj = This;
85
86 PalAddRef(This);
87 return(DD_OK);
88}
89//******************************************************************************
90//******************************************************************************
91ULONG __stdcall PalAddRef(THIS This)
92{
93 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
94
95 #ifdef DEBUG
96 WriteLog("OS2IDirectDrawPalette::PalAddRef %d\n", me->Referenced+1);
97 #endif
98
99 return (++me->Referenced);
100}
101//******************************************************************************
102//******************************************************************************
103ULONG __stdcall PalRelease(THIS This)
104{
105 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
106
107 #ifdef DEBUG
108 WriteLog("OS2IDirectDrawPalette::PalRelease %d\n", me->Referenced-1);
109 #endif
110
111 if(me->Referenced)
112 {
113 me->Referenced--;
114 if(me->Referenced == 0)
115 {
116 delete(me);
117 return(0);
118 }
119 else
120 return (me->Referenced);
121 }
122 else
123 return(0);
124}
125//******************************************************************************
126//******************************************************************************
127HRESULT __stdcall PalGetCaps(THIS This, LPDWORD lpdwCaps)
128{
129 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
130
131 #ifdef DEBUG
132 WriteLog("OS2IDirectDrawPalette::GetCaps\n");
133 #endif
134
135 if(NULL== lpdwCaps)
136 return(DDERR_INVALIDPARAMS);
137
138 *lpdwCaps = me->dwCaps;
139
140 if(me->fAttachedToPrimary)
141 *lpdwCaps |= DDPCAPS_PRIMARYSURFACE;
142
143 return(DD_OK);
144}
145//******************************************************************************
146//******************************************************************************
147HRESULT __stdcall PalGetEntries(THIS This, DWORD dwFlags,
148 DWORD dwBase,
149 DWORD dwNumEntries,
150 LPPALETTEENTRY lpEntries)
151{
152 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
153
154 #ifdef DEBUG
155 WriteLog("OS2IDirectDrawPalette::PalGetEntries\n");
156 #endif
157
158 if( (NULL== lpEntries) ||(0!=dwFlags) ||(dwBase<0) ||((dwBase + dwNumEntries)>me->dwSize) )
159 return(DDERR_INVALIDPARAMS);
160
161 memcpy( (char *)lpEntries,
162 (char *)(me->os2pal + dwBase),
163 dwNumEntries*sizeof(PALETTEENTRY));
164
165 return(DD_OK);
166}
167//******************************************************************************
168//******************************************************************************
169HRESULT __stdcall PalInitialize(THIS, LPDIRECTDRAW, DWORD, LPPALETTEENTRY)
170{
171 #ifdef DEBUG
172 WriteLog("OS2IDirectDrawPalette::PalInitialize\n");
173 #endif
174 return(DDERR_ALREADYINITIALIZED);
175}
176//******************************************************************************
177//******************************************************************************
178HRESULT __stdcall PalSetEntries(THIS This, DWORD dwFlags,
179 DWORD dwBase,
180 DWORD dwNumEntries,
181 LPPALETTEENTRY lpNewEntries)
182{
183 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
184
185 #ifdef DEBUG
186 WriteLog("OS2IDirectDrawPalette::PalSetEntries\n");
187 #endif
188 if( (NULL== lpNewEntries) ||(0!=dwFlags) ||(dwBase<0) ||((dwBase + dwNumEntries)>me->dwSize) )
189 return(DDERR_INVALIDPARAMS);
190
191 memcpy((char *)(me->os2pal + dwBase),
192 (char *)lpNewEntries,
193 dwNumEntries*sizeof(PALETTEENTRY));
194
195 for(DWORD i=0;i<dwNumEntries;i++)
196 {
197 me->aPal16[dwBase+i] = (lpNewEntries[i].peBlue>>3) +
198 ((lpNewEntries[i].peGreen>>2) <<5) +
199 ((lpNewEntries[i].peRed>>3) << 11);
200 me->aPal24[dwBase+i] = (lpNewEntries[i].peBlue <<8) +
201 (lpNewEntries[i].peGreen<<16) +
202 (lpNewEntries[i].peRed<<24);
203 }
204
205 if(8==((OS2IDirectDraw*)me->lpDraw)->dCaps.ulDepth)
206 {
207 if(me->fAttachedToPrimary)
208 me->SetPhysPalette();
209 }
210 else
211 {
212 if(NULL!=((OS2IDirectDraw*)me->lpDraw)->pPrimSurf)
213 ((OS2IDirectDrawSurface*)((OS2IDirectDraw*)me->lpDraw)->pPrimSurf)->ColorConversion(NULL);;
214 }
215 /*
216 if(NULL!=me->hDiveCC)
217 {
218 DiveSetSourcePalette( me->hDiveCC,
219 dwBase,
220 dwNumEntries,
221 (PBYTE)lpNewEntries);
222
223 }
224 else
225 {
226 // Only usefull if system and game are in 8bit mode
227 // 16bit games don't use palettes and setting the Phys palette
228 // in >8Bit Modes has no effect.
229
230 if(me->fAttachedToPrimary)
231 me->SetPhysPalette();
232 }
233 */
234 return(DD_OK);
235}
236//******************************************************************************
237//******************************************************************************
238void OS2IDirectDrawPalette::SetPhysPalette()
239{
240 OS2SetPhysPalette(os2pal);
241}
242//******************************************************************************
243//******************************************************************************
244void OS2IDirectDrawPalette::RestorePhysPalette()
245{
246 OS2ResetPhysPalette();
247}
248//******************************************************************************
249//******************************************************************************
250void OS2IDirectDrawPalette::SetIsPrimary(BOOL fNewVal)
251{
252 if(fNewVal==fAttachedToPrimary)
253 return;
254 fAttachedToPrimary = fNewVal;
255
256 /*
257 if(fAttachedToPrimary)
258 {
259 if(NULL!=hDiveCC)
260 DiveSetSourcePalette( hDiveCC,
261 0,
262 255,
263 (PBYTE)os2pal);
264 else
265 SetPhysPalette();
266 }
267 */
268}
269//******************************************************************************
270//******************************************************************************
271
Note: See TracBrowser for help on using the repository browser.