d3dx9: Implement D3DXLoadSurfaceFromFile.
[wine/multimedia.git] / dlls / d3dx9_36 / surface.c
blobac619c627595cdce60d03b6a78f84e83a994659e
1 /*
2 * Copyright (C) 2009 Tony Wasserka
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/debug.h"
21 #include "wine/unicode.h"
22 #include "d3dx9_36_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
27 /************************************************************
28 * D3DXGetImageInfoFromFileInMemory
30 * Fills a D3DXIMAGE_INFO structure with info about an image
32 * PARAMS
33 * data [I] pointer to the image file data
34 * datasize [I] size of the passed data
35 * info [O] pointer to the destination structure
37 * RETURNS
38 * Success: D3D_OK, if info is not NULL and data and datasize make up a valid image file or
39 * if info is NULL and data and datasize are not NULL
40 * Failure: D3DXERR_INVALIDDATA, if data is no valid image file and datasize and info are not NULL
41 * D3DERR_INVALIDCALL, if data is NULL or
42 * if datasize is 0
44 * NOTES
45 * datasize may be bigger than the actual file size
48 HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(LPCVOID data, UINT datasize, D3DXIMAGE_INFO *info)
50 FIXME("stub\n");
52 if(data && datasize && !info) return D3D_OK;
53 if( !data || !datasize ) return D3DERR_INVALIDCALL;
55 return E_NOTIMPL;
58 /************************************************************
59 * D3DXGetImageInfoFromFile
61 * RETURNS
62 * Success: D3D_OK, if we successfully load a valid image file or
63 * if we successfully load a file which is no valid image and info is NULL
64 * Failure: D3DXERR_INVALIDDATA, if we fail to load file or
65 * if file is not a valid image file and info is not NULL
66 * D3DERR_INVALIDCALL, if file is NULL
69 HRESULT WINAPI D3DXGetImageInfoFromFileA(LPCSTR file, D3DXIMAGE_INFO *info)
71 LPWSTR widename;
72 HRESULT hr;
73 int strlength;
74 TRACE("(void): relay\n");
76 if( !file ) return D3DERR_INVALIDCALL;
78 strlength = MultiByteToWideChar(CP_ACP, 0, file, -1, NULL, 0);
79 widename = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, strlength * sizeof(WCHAR));
80 MultiByteToWideChar(CP_ACP, 0, file, -1, widename, strlength);
82 hr = D3DXGetImageInfoFromFileW(widename, info);
83 HeapFree(GetProcessHeap(), 0, widename);
85 return hr;
88 HRESULT WINAPI D3DXGetImageInfoFromFileW(LPCWSTR file, D3DXIMAGE_INFO *info)
90 HRESULT hr;
91 DWORD size;
92 LPVOID buffer;
93 TRACE("(void): relay\n");
95 if( !file ) return D3DERR_INVALIDCALL;
97 hr = map_view_of_file(file, &buffer, &size);
98 if(FAILED(hr)) return D3DXERR_INVALIDDATA;
100 hr = D3DXGetImageInfoFromFileInMemory(buffer, size, info);
101 UnmapViewOfFile(buffer);
103 return hr;
106 /************************************************************
107 * D3DXGetImageInfoFromResource
109 * RETURNS
110 * Success: D3D_OK, if resource is a valid image file
111 * Failure: D3DXERR_INVALIDDATA, if resource is no valid image file or NULL or
112 * if we fail to load resource
115 HRESULT WINAPI D3DXGetImageInfoFromResourceA(HMODULE module, LPCSTR resource, D3DXIMAGE_INFO *info)
117 HRSRC resinfo;
118 TRACE("(void)\n");
120 resinfo = FindResourceA(module, resource, (LPCSTR)RT_RCDATA);
121 if(resinfo) {
122 LPVOID buffer;
123 HRESULT hr;
124 DWORD size;
126 hr = load_resource_into_memory(module, resinfo, &buffer, &size);
127 if(FAILED(hr)) return D3DXERR_INVALIDDATA;
128 return D3DXGetImageInfoFromFileInMemory(buffer, size, info);
131 resinfo = FindResourceA(module, resource, (LPCSTR)RT_BITMAP);
132 if(resinfo) {
133 FIXME("Implement loading bitmaps from resource type RT_BITMAP\n");
134 return E_NOTIMPL;
136 return D3DXERR_INVALIDDATA;
139 HRESULT WINAPI D3DXGetImageInfoFromResourceW(HMODULE module, LPCWSTR resource, D3DXIMAGE_INFO *info)
141 HRSRC resinfo;
142 TRACE("(void)\n");
144 resinfo = FindResourceW(module, resource, (LPCWSTR)RT_RCDATA);
145 if(resinfo) {
146 LPVOID buffer;
147 HRESULT hr;
148 DWORD size;
150 hr = load_resource_into_memory(module, resinfo, &buffer, &size);
151 if(FAILED(hr)) return D3DXERR_INVALIDDATA;
152 return D3DXGetImageInfoFromFileInMemory(buffer, size, info);
155 resinfo = FindResourceW(module, resource, (LPCWSTR)RT_BITMAP);
156 if(resinfo) {
157 FIXME("Implement loading bitmaps from resource type RT_BITMAP\n");
158 return E_NOTIMPL;
160 return D3DXERR_INVALIDDATA;
163 /************************************************************
164 * D3DXLoadSurfaceFromFileInMemory
166 * Loads data from a given buffer into a surface and fills a given
167 * D3DXIMAGE_INFO structure with info about the source data.
169 * PARAMS
170 * pDestSurface [I] pointer to the surface
171 * pDestPalette [I] palette to use
172 * pDestRect [I] to be filled area of the surface
173 * pSrcData [I] pointer to the source data
174 * SrcDataSize [I] size of the source data in bytes
175 * pSrcRect [I] area of the source data to load
176 * dwFilter [I] filter to apply on stretching
177 * Colorkey [I] colorkey
178 * pSrcInfo [O] pointer to a D3DXIMAGE_INFO structure
180 * RETURNS
181 * Success: D3D_OK
182 * Failure: D3DERR_INVALIDCALL, if pDestSurface or pSrcData or SrcDataSize are NULL
183 * D3DXERR_INVALIDDATA, if pSrcData is no valid image file
186 HRESULT WINAPI D3DXLoadSurfaceFromFileInMemory(LPDIRECT3DSURFACE9 pDestSurface,
187 CONST PALETTEENTRY *pDestPalette,
188 CONST RECT *pDestRect,
189 LPCVOID pSrcData,
190 UINT SrcDataSize,
191 CONST RECT *pSrcRect,
192 DWORD dwFilter,
193 D3DCOLOR Colorkey,
194 D3DXIMAGE_INFO *pSrcInfo)
196 FIXME("stub\n");
197 if( !pDestSurface || !pSrcData | !SrcDataSize ) return D3DERR_INVALIDCALL;
198 return E_NOTIMPL;
201 /************************************************************
202 * D3DXLoadSurfaceFromFile
204 HRESULT WINAPI D3DXLoadSurfaceFromFileA(LPDIRECT3DSURFACE9 pDestSurface,
205 CONST PALETTEENTRY *pDestPalette,
206 CONST RECT *pDestRect,
207 LPCSTR pSrcFile,
208 CONST RECT *pSrcRect,
209 DWORD dwFilter,
210 D3DCOLOR Colorkey,
211 D3DXIMAGE_INFO *pSrcInfo)
213 LPWSTR pWidename;
214 HRESULT hr;
215 int strlength;
216 TRACE("(void): relay\n");
218 if( !pSrcFile || !pDestSurface ) return D3DERR_INVALIDCALL;
220 strlength = MultiByteToWideChar(CP_ACP, 0, pSrcFile, -1, NULL, 0);
221 pWidename = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, strlength * sizeof(WCHAR));
222 MultiByteToWideChar(CP_ACP, 0, pSrcFile, -1, pWidename, strlength);
224 hr = D3DXLoadSurfaceFromFileW(pDestSurface, pDestPalette, pDestRect, pWidename, pSrcRect, dwFilter, Colorkey, pSrcInfo);
225 HeapFree(GetProcessHeap(), 0, pWidename);
227 return hr;
230 HRESULT WINAPI D3DXLoadSurfaceFromFileW(LPDIRECT3DSURFACE9 pDestSurface,
231 CONST PALETTEENTRY *pDestPalette,
232 CONST RECT *pDestRect,
233 LPCWSTR pSrcFile,
234 CONST RECT *pSrcRect,
235 DWORD Filter,
236 D3DCOLOR Colorkey,
237 D3DXIMAGE_INFO *pSrcInfo)
239 HRESULT hr;
240 DWORD dwSize;
241 LPVOID pBuffer;
242 TRACE("(void): relay\n");
244 if( !pSrcFile || !pDestSurface ) return D3DERR_INVALIDCALL;
246 hr = map_view_of_file(pSrcFile, &pBuffer, &dwSize);
247 if(FAILED(hr)) return D3DXERR_INVALIDDATA;
249 hr = D3DXLoadSurfaceFromFileInMemory(pDestSurface, pDestPalette, pDestRect, pBuffer, dwSize, pSrcRect, Filter, Colorkey, pSrcInfo);
250 UnmapViewOfFile(pBuffer);
252 return hr;