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

Last change on this file since 4 was 4, checked in by ktk, 26 years ago

Import

File size: 9.2 KB
Line 
1/* $Id: OS2PALETTE.CPP,v 1.1 1999-05-24 20:19:36 ktk Exp $ */
2
3/*
4 * DirectDraw Palette class
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12/*@Const************************************************************************
13* Defined Constants *
14*******************************************************************************/
15#define INCL_GUID
16#define WIN32SDK_NOPOSTWRAPPER
17
18/*@Header***********************************************************************
19* Header Files *
20*******************************************************************************/
21#include <os2win.h>
22#include <dive.h>
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <memory.h>
28
29#include "no.h"
30#include <w_windows.h>
31#include <ddraw.h>
32#include <d3d.h>
33#include <Win32SDKPostWrapper.h>
34
35#include "os2ddraw.h"
36#include "os2palette.h"
37#include "misc.h"
38#include "os2palset.h"
39
40extern DIVE_CAPS dcaps;
41
42//******************************************************************************
43//******************************************************************************
44OS2IDirectDrawPalette::OS2IDirectDrawPalette(OS2IDirectDraw *lpDirectDraw,
45 int palsize,
46 W32_LPPALETTEENTRY lpColorTable) :
47 Referenced(0), os2pal(NULL),
48 lastError(DD_OK), lpDraw(NULL)
49{
50 lpVtbl = &Vtbl;
51 Vtbl.AddRef = PalAddRef;
52 Vtbl.Release = PalRelease;
53 Vtbl.QueryInterface = PalQueryInterface;
54 Vtbl.GetCaps = PalGetCaps;
55 Vtbl.GetEntries = PalGetEntries;
56 Vtbl.Initialize = PalInitialize;
57 Vtbl.SetEntries = PalSetEntries;
58
59 lpDraw = lpDirectDraw;
60 lpDraw->Vtbl.AddRef((IDirectDraw2*)lpDraw);
61 hDive = lpDirectDraw->GetDiveInstance();
62 nrColors = palsize;
63
64 dprintf(("OS2IDirectDrawPalette::OS2IDirectDrawPalette nr colors %d", palsize));
65 os2pal = (W32_LPPALETTEENTRY)malloc(palsize*sizeof(PALETTEENTRY));
66 memcpy((char *)os2pal, (char *)lpColorTable, palsize*sizeof(PALETTEENTRY));
67}
68//******************************************************************************
69//******************************************************************************
70OS2IDirectDrawPalette::~OS2IDirectDrawPalette()
71{
72 if(os2pal) free(os2pal);
73 lpDraw->Vtbl.Release((IDirectDraw2*)lpDraw);
74 RestorePhysPalette();
75}
76//******************************************************************************
77//******************************************************************************
78HRESULT __stdcall PalQueryInterface(THIS, REFIID riid, LPVOID FAR * ppvObj)
79{
80 dprintf(("OS2IDirectDrawPalette::PalQueryInterface\n"));
81 *ppvObj = NULL;
82
83 if(!IsEqualGUID(riid, IID_IDirectDrawPalette))
84//&& !IsEqualGUID(riid, IID_IUnknown))
85 return E_NOINTERFACE;
86
87 *ppvObj = This;
88
89 PalAddRef(This);
90 return(DD_OK);
91}
92//******************************************************************************
93//******************************************************************************
94ULONG __stdcall PalAddRef(THIS)
95{
96 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
97
98 dprintf(("OS2IDirectDrawPalette::PalAddRef %d\n", me->Referenced+1));
99 return ++me->Referenced;
100}
101//******************************************************************************
102//******************************************************************************
103ULONG __stdcall PalRelease(THIS)
104{
105 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
106
107 dprintf(("OS2IDirectDrawPalette::PalRelease %d\n", me->Referenced-1));
108 if(me->Referenced) {
109 me->Referenced--;
110 if(me->Referenced == 0) {
111 delete me;
112 return(0);
113 }
114 else return me->Referenced;
115 }
116 else return(0);
117}
118//******************************************************************************
119//******************************************************************************
120HRESULT __stdcall PalGetCaps(THIS_ LPDWORD)
121{
122 dprintf(("OS2IDirectDrawPalette::GetCaps\n"));
123 return(DD_OK);
124}
125//******************************************************************************
126//******************************************************************************
127HRESULT __stdcall PalGetEntries(THIS_ DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries,
128 W32_LPPALETTEENTRY lpEntries)
129{
130 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
131
132 dprintf(("OS2IDirectDrawPalette::PalGetEntries %d %d\n", dwBase, dwNumEntries));
133
134 if(dwBase + dwNumEntries > 256)
135 return(DDERR_UNSUPPORTED);
136
137 memcpy((char *)lpEntries, (char *)(me->os2pal + dwBase), dwNumEntries*sizeof(PALETTEENTRY));
138 return(DD_OK);
139}
140//******************************************************************************
141//******************************************************************************
142HRESULT __stdcall PalInitialize(THIS_ LPDIRECTDRAW, DWORD, W32_LPPALETTEENTRY)
143{
144 dprintf(("OS2IDirectDrawPalette::PalInitialize\n"));
145 return(DD_OK);
146}
147//******************************************************************************
148 #pragma pack(1) /* pack on wordboundary */
149
150 typedef struct _RGB2 /* rgb2 */
151 {
152 BYTE bBlue; /* Blue component of the color definition */
153 BYTE bGreen; /* Green component of the color definition*/
154 BYTE bRed; /* Red component of the color definition */
155 BYTE fcOptions; /* Reserved, must be zero */
156 } RGB2;
157 typedef RGB2 *PRGB2;
158 #pragma pack()
159//******************************************************************************
160HRESULT __stdcall PalSetEntries(THIS_ DWORD dwFlags, DWORD dwStartingEntry,
161 DWORD dwCount, W32_LPPALETTEENTRY lpEntries)
162{
163 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
164 int i, rc;
165 RGB2 os2rgb[256];
166
167 dprintf(("OS2IDirectDrawPalette::PalSetEntries %X %X %d %d\n", me, dwFlags, dwStartingEntry, dwCount));
168 memcpy(&me->os2pal[dwStartingEntry], lpEntries, sizeof(PALETTEENTRY)*dwCount);
169
170 for(i=0;i<256;i++) {
171 os2rgb[i].bBlue = me->os2pal[i].peBlue;
172 os2rgb[i].bGreen = me->os2pal[i].peGreen;
173 os2rgb[i].bRed = me->os2pal[i].peRed;
174 os2rgb[i].fcOptions = 0;
175// dprintf(("pal (%3d,%3d,%3d) %d\n", me->os2pal[i].peBlue, me->os2pal[i].peGreen, me->os2pal[i].peRed, me->os2pal[i].peFlags));
176 }
177#if 0
178 rc = DiveSetSourcePalette(me->hDive, dwStartingEntry, dwCount, (PBYTE)os2rgb);
179 if(rc != DIVE_SUCCESS) {
180 dprintf(("DiveSetSourcePalette returned %d\n", rc));
181 return(DDERR_INVALIDPARAMS);
182 }
183 if(dcaps.ulDepth == 8) {
184 rc = DiveSetDestinationPalette(me->hDive, dwStartingEntry, dwCount, (PBYTE)os2rgb);
185 if(rc != DIVE_SUCCESS) {
186 dprintf(("DiveSetDestinationPalette returned %d\n", rc));
187 return(DDERR_INVALIDPARAMS);
188 }
189 }
190#else
191 if(dcaps.ulDepth == 8) {
192 OS2SetPhysPalette((HWND)me->lpDraw->GetWindowHandle(), me->os2pal);
193 rc = DiveSetDestinationPalette(me->hDive, 0, 0, 0);
194 if(rc != DIVE_SUCCESS) {
195 dprintf(("DiveSetDestinationPalette returned %d\n", rc));
196 return(DDERR_INVALIDPARAMS);
197 }
198 }
199 else {
200 rc = DiveSetSourcePalette(me->hDive, 0, me->nrColors, (PBYTE)os2rgb);
201 if(rc != DIVE_SUCCESS) {
202 dprintf(("DiveSetSourcePalette returned %d\n", rc));
203 return(DDERR_INVALIDPARAMS);
204 }
205 }
206#endif
207 return(DD_OK);
208}
209//******************************************************************************
210//******************************************************************************
211void OS2IDirectDrawPalette::SetPhysPalette()
212{
213 int i, rc;
214 RGB2 os2rgb[256];
215
216 for(i=0;i<nrColors;i++) {
217 os2rgb[i].bBlue = os2pal[i].peBlue;
218 os2rgb[i].bGreen = os2pal[i].peGreen;
219 os2rgb[i].bRed = os2pal[i].peRed;
220 os2rgb[i].fcOptions = 0;
221 dprintf(("pal (%3d,%3d,%3d) %d\n", os2pal[i].peBlue, os2pal[i].peGreen, os2pal[i].peRed, os2pal[i].peFlags));
222 }
223#if 0
224 rc = DiveSetSourcePalette(hDive, 0, nrColors, (PBYTE)os2rgb);
225 if(rc != DIVE_SUCCESS) {
226 dprintf(("DiveSetSourcePalette returned %d\n", rc));
227 return;
228 }
229 if(dcaps.ulDepth == 8) {
230 rc = DiveSetDestinationPalette(hDive, 0, nrColors, (PBYTE)os2rgb);
231 if(rc != DIVE_SUCCESS) {
232 dprintf(("DiveSetDestinationPalette returned %d\n", rc));
233 return;
234 }
235 }
236#else
237 if(dcaps.ulDepth == 8) {
238 OS2SetPhysPalette((HWND)lpDraw->GetWindowHandle(), os2pal);
239 rc = DiveSetDestinationPalette(hDive, 0, 0, 0);
240 if(rc != DIVE_SUCCESS) {
241 dprintf(("DiveSetDestinationPalette returned %d\n", rc));
242 return;
243 }
244 }
245 else {
246 rc = DiveSetSourcePalette(hDive, 0, nrColors, (PBYTE)os2rgb);
247 if(rc != DIVE_SUCCESS) {
248 dprintf(("DiveSetSourcePalette returned %d\n", rc));
249 return;
250 }
251 }
252#endif
253}
254//******************************************************************************
255//******************************************************************************
256void OS2IDirectDrawPalette::RestorePhysPalette()
257{
258 if(dcaps.ulDepth == 8) {
259 OS2ResetPhysPalette();
260 }
261}
262//******************************************************************************
263//******************************************************************************
264
Note: See TracBrowser for help on using the repository browser.