advapi32/tests: Don't use locale dependent string for testing.
[wine/multimedia.git] / dlls / wined3d / palette.c
bloba1dcc9f95f7d3da7db8e0d1834dcdd0625cd2c41
1 /* DirectDraw - IDirectPalette base interface
3 * Copyright 1997-2000 Marcus Meissner
4 * Copyright 2000-2001 TransGaming Technologies Inc.
5 * Copyright 2006 Stefan Dösinger for CodeWeavers
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.
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.
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
21 #include "config.h"
22 #include "winerror.h"
23 #include "wine/debug.h"
25 #include <assert.h>
26 #include <string.h>
28 #include "wined3d_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
32 #define SIZE_BITS (WINEDDPCAPS_1BIT | WINEDDPCAPS_2BIT | WINEDDPCAPS_4BIT | WINEDDPCAPS_8BIT)
34 static HRESULT WINAPI IWineD3DPaletteImpl_QueryInterface(IWineD3DPalette *iface, REFIID refiid, void **obj) {
35 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
36 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj);
38 if (IsEqualGUID(refiid, &IID_IUnknown)
39 || IsEqualGUID(refiid, &IID_IWineD3DPalette)) {
40 *obj = iface;
41 IWineD3DPalette_AddRef(iface);
42 return S_OK;
44 else {
45 *obj = NULL;
46 return E_NOINTERFACE;
50 static ULONG WINAPI IWineD3DPaletteImpl_AddRef(IWineD3DPalette *iface) {
51 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
52 ULONG ref = InterlockedIncrement(&This->ref);
54 TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
56 return ref;
59 static ULONG WINAPI IWineD3DPaletteImpl_Release(IWineD3DPalette *iface) {
60 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
61 ULONG ref = InterlockedDecrement(&This->ref);
63 TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
65 if (!ref) {
66 HeapFree(GetProcessHeap(), 0, This);
67 return 0;
70 return ref;
73 /* Not called from the vtable */
74 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags) {
75 switch (dwFlags & SIZE_BITS) {
76 case WINEDDPCAPS_1BIT: return 2;
77 case WINEDDPCAPS_2BIT: return 4;
78 case WINEDDPCAPS_4BIT: return 16;
79 case WINEDDPCAPS_8BIT: return 256;
80 default: assert(0); return 256;
84 static HRESULT WINAPI IWineD3DPaletteImpl_GetEntries(IWineD3DPalette *iface, DWORD Flags, DWORD Start, DWORD Count, PALETTEENTRY *PalEnt) {
85 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
87 TRACE("(%p)->(%08x,%d,%d,%p)\n",This,Flags,Start,Count,PalEnt);
89 if (Flags != 0) return WINED3DERR_INVALIDCALL; /* unchecked */
90 if (Start + Count > IWineD3DPaletteImpl_Size(This->Flags))
91 return WINED3DERR_INVALIDCALL;
93 if (This->Flags & WINEDDPCAPS_8BITENTRIES)
95 unsigned int i;
96 LPBYTE entry = (LPBYTE)PalEnt;
98 for (i=Start; i < Count+Start; i++)
99 *entry++ = This->palents[i].peRed;
101 else
102 memcpy(PalEnt, This->palents+Start, Count * sizeof(PALETTEENTRY));
104 return WINED3D_OK;
107 static HRESULT WINAPI IWineD3DPaletteImpl_SetEntries(IWineD3DPalette *iface, DWORD Flags, DWORD Start, DWORD Count, PALETTEENTRY *PalEnt)
109 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
110 ResourceList *res;
112 TRACE("(%p)->(%08x,%d,%d,%p)\n",This,Flags,Start,Count,PalEnt);
114 if (This->Flags & WINEDDPCAPS_8BITENTRIES) {
115 unsigned int i;
116 const BYTE* entry = (const BYTE*)PalEnt;
118 for (i=Start; i < Count+Start; i++)
119 This->palents[i].peRed = *entry++;
121 else {
122 memcpy(This->palents+Start, PalEnt, Count * sizeof(PALETTEENTRY));
124 if (This->hpal)
125 SetPaletteEntries(This->hpal, Start, Count, This->palents+Start);
128 #if 0
129 /* Now, if we are in 'depth conversion mode', update the screen palette */
130 /* FIXME: we need to update the image or we won't get palette fading. */
131 if (This->ddraw->d->palette_convert != NULL)
132 This->ddraw->d->palette_convert(palent,This->screen_palents,start,count);
133 #endif
135 /* If the palette is attached to the render target, update all render targets */
137 for(res = This->wineD3DDevice->resources; res != NULL; res=res->next) {
138 if(IWineD3DResource_GetType(res->resource) == WINED3DRTYPE_SURFACE) {
139 IWineD3DSurfaceImpl *impl = (IWineD3DSurfaceImpl *) res->resource;
140 if(impl->palette == This)
141 IWineD3DSurface_RealizePalette( (IWineD3DSurface *) res->resource);
145 /* If the palette is the primary palette, set the entries to the device */
146 if(This->Flags & WINEDDPCAPS_PRIMARYSURFACE) {
147 unsigned int i;
148 IWineD3DDeviceImpl *device = This->wineD3DDevice;
149 PALETTEENTRY *entry = PalEnt;
151 for(i = Start; i < Start+Count; i++) {
152 device->palettes[device->currentPalette][i] = *entry++;
156 return WINED3D_OK;
159 static HRESULT WINAPI IWineD3DPaletteImpl_GetCaps(IWineD3DPalette *iface, DWORD *Caps) {
160 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
161 TRACE("(%p)->(%p)\n", This, Caps);
163 *Caps = This->Flags;
164 return WINED3D_OK;
167 static HRESULT WINAPI IWineD3DPaletteImpl_GetParent(IWineD3DPalette *iface, IUnknown **Parent) {
168 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
169 TRACE("(%p)->(%p)\n", This, Parent);
171 *Parent = (IUnknown *) This->parent;
172 IUnknown_AddRef( (IUnknown *) This->parent);
173 return WINED3D_OK;
176 const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl =
178 /*** IUnknown ***/
179 IWineD3DPaletteImpl_QueryInterface,
180 IWineD3DPaletteImpl_AddRef,
181 IWineD3DPaletteImpl_Release,
182 /*** IWineD3DPalette ***/
183 IWineD3DPaletteImpl_GetParent,
184 IWineD3DPaletteImpl_GetEntries,
185 IWineD3DPaletteImpl_GetCaps,
186 IWineD3DPaletteImpl_SetEntries