VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/palette.c@ 16477

Last change on this file since 16477 was 16477, checked in by vboxsync, 16 years ago

LGPL disclaimer by filemuncher

  • Property svn:eol-style set to native
File size: 6.8 KB
Line 
1/* DirectDraw - IDirectPalette base interface
2 *
3 * Copyright 1997-2000 Marcus Meissner
4 * Copyright 2000-2001 TransGaming Technologies Inc.
5 * Copyright 2006 Stefan Dösinger for CodeWeavers
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22/*
23 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
24 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
25 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
26 * a choice of LGPL license versions is made available with the language indicating
27 * that LGPLv2 or any later version may be used, or where a choice of which version
28 * of the LGPL is applied is otherwise unspecified.
29 */
30#include "config.h"
31#include "winerror.h"
32#include "wine/debug.h"
33
34#include <assert.h>
35#include <string.h>
36
37#include "wined3d_private.h"
38
39WINE_DEFAULT_DEBUG_CHANNEL(d3d);
40
41#define SIZE_BITS (WINEDDPCAPS_1BIT | WINEDDPCAPS_2BIT | WINEDDPCAPS_4BIT | WINEDDPCAPS_8BIT)
42
43static HRESULT WINAPI IWineD3DPaletteImpl_QueryInterface(IWineD3DPalette *iface, REFIID refiid, void **obj) {
44 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
45 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj);
46
47 if (IsEqualGUID(refiid, &IID_IUnknown)
48 || IsEqualGUID(refiid, &IID_IWineD3DPalette)) {
49 *obj = iface;
50 IWineD3DPalette_AddRef(iface);
51 return S_OK;
52 }
53 else {
54 *obj = NULL;
55 return E_NOINTERFACE;
56 }
57}
58
59static ULONG WINAPI IWineD3DPaletteImpl_AddRef(IWineD3DPalette *iface) {
60 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
61 ULONG ref = InterlockedIncrement(&This->ref);
62
63 TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
64
65 return ref;
66}
67
68static ULONG WINAPI IWineD3DPaletteImpl_Release(IWineD3DPalette *iface) {
69 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
70 ULONG ref = InterlockedDecrement(&This->ref);
71
72 TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
73
74 if (!ref) {
75 DeleteObject(This->hpal);
76 HeapFree(GetProcessHeap(), 0, This);
77 return 0;
78 }
79
80 return ref;
81}
82
83/* Not called from the vtable */
84DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags) {
85 switch (dwFlags & SIZE_BITS) {
86 case WINEDDPCAPS_1BIT: return 2;
87 case WINEDDPCAPS_2BIT: return 4;
88 case WINEDDPCAPS_4BIT: return 16;
89 case WINEDDPCAPS_8BIT: return 256;
90 default: assert(0); return 256;
91 }
92}
93
94static HRESULT WINAPI IWineD3DPaletteImpl_GetEntries(IWineD3DPalette *iface, DWORD Flags, DWORD Start, DWORD Count, PALETTEENTRY *PalEnt) {
95 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
96
97 TRACE("(%p)->(%08x,%d,%d,%p)\n",This,Flags,Start,Count,PalEnt);
98
99 if (Flags != 0) return WINED3DERR_INVALIDCALL; /* unchecked */
100 if (Start + Count > IWineD3DPaletteImpl_Size(This->Flags))
101 return WINED3DERR_INVALIDCALL;
102
103 if (This->Flags & WINEDDPCAPS_8BITENTRIES)
104 {
105 unsigned int i;
106 LPBYTE entry = (LPBYTE)PalEnt;
107
108 for (i=Start; i < Count+Start; i++)
109 *entry++ = This->palents[i].peRed;
110 }
111 else
112 memcpy(PalEnt, This->palents+Start, Count * sizeof(PALETTEENTRY));
113
114 return WINED3D_OK;
115}
116
117static HRESULT WINAPI IWineD3DPaletteImpl_SetEntries(IWineD3DPalette *iface,
118 DWORD Flags, DWORD Start, DWORD Count, const PALETTEENTRY *PalEnt)
119{
120 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
121 IWineD3DResourceImpl *res;
122
123 TRACE("(%p)->(%08x,%d,%d,%p)\n",This,Flags,Start,Count,PalEnt);
124 TRACE("Palette flags: %#x\n", This->Flags);
125
126 if (This->Flags & WINEDDPCAPS_8BITENTRIES) {
127 unsigned int i;
128 const BYTE* entry = (const BYTE*)PalEnt;
129
130 for (i=Start; i < Count+Start; i++)
131 This->palents[i].peRed = *entry++;
132 }
133 else {
134 memcpy(This->palents+Start, PalEnt, Count * sizeof(PALETTEENTRY));
135
136 /* When WINEDDCAPS_ALLOW256 isn't set we need to override entry 0 with black and 255 with white */
137 if(!(This->Flags & WINEDDPCAPS_ALLOW256))
138 {
139 TRACE("WINEDDPCAPS_ALLOW256 set, overriding palette entry 0 with black and 255 with white\n");
140 This->palents[0].peRed = 0;
141 This->palents[0].peGreen = 0;
142 This->palents[0].peBlue = 0;
143
144 This->palents[255].peRed = 255;
145 This->palents[255].peGreen = 255;
146 This->palents[255].peBlue = 255;
147 }
148
149 if (This->hpal)
150 SetPaletteEntries(This->hpal, Start, Count, This->palents+Start);
151 }
152
153#if 0
154 /* Now, if we are in 'depth conversion mode', update the screen palette */
155 /* FIXME: we need to update the image or we won't get palette fading. */
156 if (This->ddraw->d->palette_convert != NULL)
157 This->ddraw->d->palette_convert(palent,This->screen_palents,start,count);
158#endif
159
160 /* If the palette is attached to the render target, update all render targets */
161
162 LIST_FOR_EACH_ENTRY(res, &This->wineD3DDevice->resources, IWineD3DResourceImpl, resource.resource_list_entry) {
163 if(IWineD3DResource_GetType((IWineD3DResource *) res) == WINED3DRTYPE_SURFACE) {
164 IWineD3DSurfaceImpl *impl = (IWineD3DSurfaceImpl *) res;
165 if(impl->palette == This)
166 IWineD3DSurface_RealizePalette((IWineD3DSurface *) res);
167 }
168 }
169
170 return WINED3D_OK;
171}
172
173static HRESULT WINAPI IWineD3DPaletteImpl_GetCaps(IWineD3DPalette *iface, DWORD *Caps) {
174 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
175 TRACE("(%p)->(%p)\n", This, Caps);
176
177 *Caps = This->Flags;
178 return WINED3D_OK;
179}
180
181static HRESULT WINAPI IWineD3DPaletteImpl_GetParent(IWineD3DPalette *iface, IUnknown **Parent) {
182 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
183 TRACE("(%p)->(%p)\n", This, Parent);
184
185 *Parent = This->parent;
186 IUnknown_AddRef(This->parent);
187 return WINED3D_OK;
188}
189
190const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl =
191{
192 /*** IUnknown ***/
193 IWineD3DPaletteImpl_QueryInterface,
194 IWineD3DPaletteImpl_AddRef,
195 IWineD3DPaletteImpl_Release,
196 /*** IWineD3DPalette ***/
197 IWineD3DPaletteImpl_GetParent,
198 IWineD3DPaletteImpl_GetEntries,
199 IWineD3DPaletteImpl_GetCaps,
200 IWineD3DPaletteImpl_SetEntries
201};
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette