forked from hifi/cnc-ddraw
-
Notifications
You must be signed in to change notification settings - Fork 1
/
palette.c
141 lines (113 loc) · 4.54 KB
/
palette.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Copyright (c) 2010 Toni Spets <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <windows.h>
#include <stdio.h>
#include "palette.h"
#include "surface.h"
HRESULT __stdcall ddraw_palette_GetEntries(IDirectDrawPaletteImpl *This, DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries)
{
int i;
printf("DirectDrawPalette::GetEntries(This=%p, dwFlags=%d, dwBase=%d, dwNumEntries=%d, lpEntries=%p)\n", This, (int)dwFlags, (int)dwBase, (int)dwNumEntries, lpEntries);
for(i=dwBase;i<dwBase+dwNumEntries;i++)
{
if (This->data_rgb)
{
lpEntries[i].peRed = This->data_rgb[i].rgbRed;
lpEntries[i].peGreen = This->data_rgb[i].rgbGreen;
lpEntries[i].peBlue = This->data_rgb[i].rgbBlue;
}
}
return DD_OK;
}
HRESULT __stdcall ddraw_palette_SetEntries(IDirectDrawPaletteImpl *This, DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries)
{
int i;
#if _DEBUG
printf("DirectDrawPalette::SetEntries(This=%p, dwFlags=%d, dwStartingEntry=%d, dwCount=%d, lpEntries=%p)\n", This, (int)dwFlags, (int)dwStartingEntry, (int)dwCount, lpEntries);
#endif
for(i=dwStartingEntry;i<dwStartingEntry+dwCount;i++)
{
This->data_bgr[i] = (lpEntries[i].peBlue<<16)|(lpEntries[i].peGreen<<8)|lpEntries[i].peRed;
if (This->data_rgb)
{
This->data_rgb[i].rgbRed = lpEntries[i].peRed;
This->data_rgb[i].rgbGreen = lpEntries[i].peGreen;
This->data_rgb[i].rgbBlue = lpEntries[i].peBlue;
This->data_rgb[i].rgbReserved = 0;
}
}
/* FIXME: only refresh the screen when the primary palette is changed */
if(ddraw->primary && ddraw->render.run)
{
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
}
return DD_OK;
}
HRESULT __stdcall ddraw_palette_QueryInterface(IDirectDrawPaletteImpl *This, REFIID riid, void **obj)
{
printf("DirectDrawPalette::QueryInterface(This=%p, riid=%08X, obj=%p)\n", This, (unsigned int)riid, obj);
return S_OK;
}
ULONG __stdcall ddraw_palette_AddRef(IDirectDrawPaletteImpl *This)
{
printf("DirectDrawPalette::AddRef(This=%p)\n", This);
This->Ref++;
return This->Ref;
}
ULONG __stdcall ddraw_palette_Release(IDirectDrawPaletteImpl *This)
{
printf("DirectDrawPalette::Release(This=%p)\n", This);
This->Ref--;
if(This->Ref == 0)
{
HeapFree(GetProcessHeap(), 0, This);
return 0;
}
return This->Ref;
}
HRESULT __stdcall ddraw_palette_GetCaps(IDirectDrawPaletteImpl *This, LPDWORD caps)
{
printf("DirectDrawPalette::GetCaps(This=%p, caps=%p)\n", This, caps);
return DD_OK;
}
HRESULT __stdcall ddraw_palette_Initialize(IDirectDrawPaletteImpl *This, LPDIRECTDRAW lpDD, DWORD dw, LPPALETTEENTRY paent)
{
printf("DirectDrawPalette::Initialize(This=%p, ...)\n", This);
return DD_OK;
}
struct IDirectDrawPaletteImplVtbl piface =
{
/* IUnknown */
ddraw_palette_QueryInterface,
ddraw_palette_AddRef,
ddraw_palette_Release,
/* IDirectDrawPalette */
ddraw_palette_GetCaps,
ddraw_palette_GetEntries,
ddraw_palette_Initialize,
ddraw_palette_SetEntries
};
HRESULT __stdcall ddraw_CreatePalette(IDirectDrawImpl *This, DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, LPDIRECTDRAWPALETTE FAR * lpDDPalette, IUnknown FAR * unkOuter)
{
printf("DirectDraw::CreatePalette(This=%p, dwFlags=%d, DDColorArray=%p, DDPalette=%p, unkOuter=%p)\n", This, (int)dwFlags, lpDDColorArray, lpDDPalette, unkOuter);
IDirectDrawPaletteImpl *Palette = (IDirectDrawPaletteImpl *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawPaletteImpl));
Palette->lpVtbl = &piface;
printf(" Palette = %p\n", Palette);
*lpDDPalette = (LPDIRECTDRAWPALETTE)Palette;
ddraw_palette_SetEntries(Palette, dwFlags, 0, 256, lpDDColorArray);
ddraw_palette_AddRef(Palette);
return DD_OK;
}