d3dx9_36: Add support for DIB file in D3DXGetImageInfoFromFileInMemory.
[wine] / dlls / d3dx9_36 / tests / surface.c
1 /*
2  * Tests for the D3DX9 surface functions
3  *
4  * Copyright 2009 Tony Wasserka
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define COBJMACROS
22 #include <assert.h>
23 #include "wine/test.h"
24 #include "d3dx9tex.h"
25 #include "resources.h"
26
27 static inline int get_ref(IUnknown *obj)
28 {
29     IUnknown_AddRef(obj);
30     return IUnknown_Release(obj);
31 }
32
33 #define check_ref(obj, exp) _check_ref(__LINE__, obj, exp)
34 static inline void _check_ref(unsigned int line, IUnknown *obj, int exp)
35 {
36     int ref = get_ref(obj);
37     ok_(__FILE__, line)(exp == ref, "Invalid refcount. Expected %d, got %d\n", exp, ref);
38 }
39
40 #define check_release(obj, exp) _check_release(__LINE__, obj, exp)
41 static inline void _check_release(unsigned int line, IUnknown *obj, int exp)
42 {
43     int ref = IUnknown_Release(obj);
44     ok_(__FILE__, line)(ref == exp, "Invalid refcount. Expected %d, got %d\n", exp, ref);
45 }
46
47 /* 1x1 bmp (1 bpp) */
48 static const unsigned char bmp01[66] = {
49 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
50 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
51 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
52 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
53 0x00,0x00
54 };
55
56 /* 2x2 A8R8G8B8 pixel data */
57 static const unsigned char pixdata[] = {
58 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
59 };
60
61 /* invalid image file */
62 static const unsigned char noimage[4] = {
63 0x11,0x22,0x33,0x44
64 };
65
66 /* 2x2 24-bit dds, 2 mipmaps */
67 static const unsigned char dds_24bit[] = {
68 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00,
69 0x02,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
70 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
71 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
72 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
73 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
74 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
75 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
76 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
77 };
78
79 /* 2x2 16-bit dds, no mipmaps */
80 static const unsigned char dds_16bit[] = {
81 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
82 0x02,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
83 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
84 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
85 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
86 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,
87 0xe0,0x03,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
88 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
89 0xff,0x7f,0xff,0x7f,0xff,0x7f,0xff,0x7f
90 };
91
92 /* 4x4 cube map dds */
93 static const unsigned char dds_cube_map[] = {
94 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00,
95 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
96 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
97 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
98 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
99 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
100 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
101 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
102 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
103 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
104 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
105 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
106 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
107 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50
108 };
109
110 /* 4x4x2 volume map dds, 2 mipmaps */
111 static const unsigned char dds_volume_map[] = {
112 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
113 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
114 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
115 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
116 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
117 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
118 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
119 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
120 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
121 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
122 0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
123 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
124 };
125
126 static HRESULT create_file(const char *filename, const unsigned char *data, const unsigned int size)
127 {
128     DWORD received;
129     HANDLE hfile;
130
131     hfile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
132     if(hfile == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError());
133
134     if(WriteFile(hfile, data, size, &received, NULL))
135     {
136         CloseHandle(hfile);
137         return D3D_OK;
138     }
139
140     CloseHandle(hfile);
141     return D3DERR_INVALIDCALL;
142 }
143
144 /* dds_header.flags */
145 #define DDS_CAPS 0x00000001
146 #define DDS_HEIGHT 0x00000002
147 #define DDS_WIDTH 0x00000004
148 #define DDS_PITCH 0x00000008
149 #define DDS_PIXELFORMAT 0x00001000
150 #define DDS_LINEARSIZE 0x00080000
151
152 /* dds_header.caps */
153 #define DDS_CAPS_TEXTURE 0x00001000
154
155 /* dds_pixel_format.flags */
156 #define DDS_PF_ALPHA 0x00000001
157 #define DDS_PF_ALPHA_ONLY 0x00000002
158 #define DDS_PF_FOURCC 0x00000004
159 #define DDS_PF_RGB 0x00000040
160 #define DDS_PF_LUMINANCE 0x00020000
161 #define DDS_PF_BUMPDUDV 0x00080000
162
163 struct dds_pixel_format
164 {
165     DWORD size;
166     DWORD flags;
167     DWORD fourcc;
168     DWORD bpp;
169     DWORD rmask;
170     DWORD gmask;
171     DWORD bmask;
172     DWORD amask;
173 };
174
175 struct dds_header
176 {
177     DWORD magic;
178     DWORD size;
179     DWORD flags;
180     DWORD height;
181     DWORD width;
182     DWORD pitch_or_linear_size;
183     DWORD depth;
184     DWORD miplevels;
185     DWORD reserved[11];
186     struct dds_pixel_format pixel_format;
187     DWORD caps;
188     DWORD caps2;
189     DWORD reserved2[3];
190 };
191
192 /* fills dds_header with reasonable default values */
193 static void fill_dds_header(struct dds_header *header)
194 {
195     memset(header, 0, sizeof(*header));
196
197     header->magic = MAKEFOURCC('D','D','S',' ');
198     header->size = sizeof(*header);
199     header->flags = DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT;
200     header->height = 4;
201     header->width = 4;
202     header->pixel_format.size = sizeof(header->pixel_format);
203     /* X8R8G8B8 */
204     header->pixel_format.flags = DDS_PF_RGB;
205     header->pixel_format.fourcc = 0;
206     header->pixel_format.bpp = 32;
207     header->pixel_format.rmask = 0xff0000;
208     header->pixel_format.gmask = 0x00ff00;
209     header->pixel_format.bmask = 0x0000ff;
210     header->pixel_format.amask = 0;
211     header->caps = DDS_CAPS_TEXTURE;
212 }
213
214 #define check_dds_pixel_format(flags, fourcc, bpp, rmask, gmask, bmask, amask, format) \
215         check_dds_pixel_format_(__LINE__, flags, fourcc, bpp, rmask, gmask, bmask, amask, format)
216 static void check_dds_pixel_format_(unsigned int line,
217                                     DWORD flags, DWORD fourcc, DWORD bpp,
218                                     DWORD rmask, DWORD gmask, DWORD bmask, DWORD amask,
219                                     D3DFORMAT expected_format)
220 {
221     HRESULT hr;
222     D3DXIMAGE_INFO info;
223     struct
224     {
225         struct dds_header header;
226         BYTE data[256];
227     } dds;
228
229     fill_dds_header(&dds.header);
230     dds.header.pixel_format.flags = flags;
231     dds.header.pixel_format.fourcc = fourcc;
232     dds.header.pixel_format.bpp = bpp;
233     dds.header.pixel_format.rmask = rmask;
234     dds.header.pixel_format.gmask = gmask;
235     dds.header.pixel_format.bmask = bmask;
236     dds.header.pixel_format.amask = amask;
237     memset(dds.data, 0, sizeof(dds.data));
238
239     hr = D3DXGetImageInfoFromFileInMemory(&dds, sizeof(dds), &info);
240     ok_(__FILE__, line)(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x for pixel format %#x, expected %#x\n",
241             hr, expected_format, D3D_OK);
242     if (SUCCEEDED(hr))
243     {
244         ok_(__FILE__, line)(info.Format == expected_format, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n",
245                 info.Format, expected_format);
246     }
247 }
248
249 static void test_dds_header_handling(void)
250 {
251     int i;
252     HRESULT hr;
253     D3DXIMAGE_INFO info;
254     struct
255     {
256         struct dds_header header;
257         BYTE data[256];
258     } dds;
259
260     struct
261     {
262         struct dds_pixel_format pixel_format;
263         DWORD flags;
264         DWORD width;
265         DWORD height;
266         DWORD pitch;
267         DWORD pixel_data_size;
268         HRESULT expected_result;
269     } tests[] = {
270         /* pitch is ignored */
271         { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, 0, 4, 4, 0,
272           63 /* pixel data size */, D3DXERR_INVALIDDATA },
273         { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 0 /* pitch */,
274           64, D3D_OK },
275         { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1 /* pitch */,
276           64, D3D_OK },
277         { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 2 /* pitch */,
278           64, D3D_OK },
279         { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 3 /* pitch */,
280           64, D3D_OK },
281         { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 4 /* pitch */,
282           64, D3D_OK },
283         { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 16 /* pitch */,
284           64, D3D_OK },
285         { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1024 /* pitch */,
286           64, D3D_OK },
287         { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, -1 /* pitch */,
288           64, D3D_OK },
289         /* linear size is ignored */
290         { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, 0, 4, 4, 0,
291           7 /* pixel data size */, D3DXERR_INVALIDDATA },
292         { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 0 /* linear size */,
293           8, D3D_OK },
294         { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 1 /* linear size */,
295           8, D3D_OK },
296         { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 2 /* linear size */,
297           8, D3D_OK },
298         { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 9 /* linear size */,
299           8, D3D_OK },
300         { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 16 /* linear size */,
301           8, D3D_OK },
302         { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, -1 /* linear size */,
303           8, D3D_OK },
304         /* integer overflows */
305         { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000000, 0x80000000 /* 0x80000000 * 0x80000000 * 4 = 0 */, 0,
306           64, D3D_OK },
307         { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x8000100, 0x800100 /* 0x8000100 * 0x800100 * 4 = 262144 */, 0,
308           64, D3DXERR_INVALIDDATA },
309         { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
310           4, D3D_OK },
311         { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
312           3 /* pixel data size */, D3DXERR_INVALIDDATA }
313     };
314
315     memset(&dds, 0, sizeof(dds));
316
317     for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
318     {
319         DWORD file_size = sizeof(dds.header) + tests[i].pixel_data_size;
320         assert(file_size <= sizeof(dds));
321
322         fill_dds_header(&dds.header);
323         dds.header.flags |= tests[i].flags;
324         dds.header.width = tests[i].width;
325         dds.header.height = tests[i].height;
326         dds.header.pitch_or_linear_size = tests[i].pitch;
327         dds.header.pixel_format = tests[i].pixel_format;
328
329         hr = D3DXGetImageInfoFromFileInMemory(&dds, file_size, &info);
330         ok(hr == tests[i].expected_result, "%d: D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", i, hr, tests[i].expected_result);
331     }
332 }
333
334 static void test_D3DXGetImageInfo(void)
335 {
336     HRESULT hr;
337     D3DXIMAGE_INFO info;
338     BOOL testdummy_ok, testbitmap_ok;
339
340     hr = create_file("testdummy.bmp", noimage, sizeof(noimage));  /* invalid image */
341     testdummy_ok = SUCCEEDED(hr);
342
343     hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01));  /* valid image */
344     testbitmap_ok = SUCCEEDED(hr);
345
346     /* D3DXGetImageInfoFromFile */
347     if(testbitmap_ok) {
348         hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", &info);
349         ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
350
351         hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL); /* valid image, second parameter is NULL */
352         ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
353     } else skip("Couldn't create \"testbitmap.bmp\"\n");
354
355     if(testdummy_ok) {
356         hr = D3DXGetImageInfoFromFileA("testdummy.bmp", NULL); /* invalid image, second parameter is NULL */
357         ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
358
359         hr = D3DXGetImageInfoFromFileA("testdummy.bmp", &info);
360         ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
361     } else skip("Couldn't create \"testdummy.bmp\"\n");
362
363     hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info);
364     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
365
366     hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL);
367     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
368
369     hr = D3DXGetImageInfoFromFileA("", &info);
370     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
371
372     hr = D3DXGetImageInfoFromFileA(NULL, &info);
373     ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
374
375     hr = D3DXGetImageInfoFromFileA(NULL, NULL);
376     ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
377
378
379     /* D3DXGetImageInfoFromResource */
380     hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &info); /* RT_BITMAP */
381     ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
382
383     hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL);
384     ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
385
386     hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &info); /* RT_RCDATA */
387     ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
388
389     hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), &info);
390     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
391
392     hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), NULL);
393     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
394
395     hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", &info);
396     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
397
398     hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", NULL);
399     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
400
401     hr = D3DXGetImageInfoFromResourceA(NULL, NULL, NULL);
402     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
403
404
405     /* D3DXGetImageInfoFromFileInMemory */
406     hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01), &info);
407     ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
408
409     hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01)+5, &info); /* too large size */
410     ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
411
412     hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01), NULL);
413     ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
414
415     hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), NULL);
416     ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
417
418     hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), &info);
419     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
420
421     todo_wine {
422         hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01)-1, &info);
423         ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
424     }
425
426     hr = D3DXGetImageInfoFromFileInMemory(bmp01+1, sizeof(bmp01)-1, &info);
427     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
428
429     hr = D3DXGetImageInfoFromFileInMemory(bmp01, 0, &info);
430     ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
431
432     hr = D3DXGetImageInfoFromFileInMemory(bmp01, 0, NULL);
433     ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
434
435     hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, &info);
436     ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
437
438     hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, NULL);
439     ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
440
441     hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, &info);
442     ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
443
444     hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, NULL);
445     ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
446
447     hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, &info);
448     ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
449
450     hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, NULL);
451     ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
452
453
454     /* test DDS support */
455     hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit), &info);
456     ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
457     if (hr == D3D_OK) {
458         ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
459         ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
460         ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
461         ok(info.MipLevels == 2, "Got miplevels %u, expected 2\n", info.MipLevels);
462         ok(info.Format == D3DFMT_R8G8B8, "Got format %#x, expected %#x\n", info.Format, D3DFMT_R8G8B8);
463         ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
464         ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
465     } else skip("Couldn't get image info from 24-bit DDS file in memory\n");
466
467     hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit), &info);
468     ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
469     if (hr == D3D_OK) {
470         ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
471         ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
472         ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
473         ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
474         ok(info.Format == D3DFMT_X1R5G5B5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_X1R5G5B5);
475         ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
476         ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
477     } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
478
479     hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map), &info);
480     ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
481     if (hr == D3D_OK) {
482         ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
483         ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
484         ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
485         ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
486         ok(info.Format == D3DFMT_DXT5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT5);
487         ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
488         ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
489     } else skip("Couldn't get image info from cube map in memory\n");
490
491     hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map), &info);
492     ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
493     if (hr == D3D_OK) {
494         ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
495         ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
496         ok(info.Depth == 2, "Got depth %u, expected 2\n", info.Depth);
497         ok(info.MipLevels == 3, "Got miplevels %u, expected 3\n", info.MipLevels);
498         ok(info.Format == D3DFMT_DXT3, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT3);
499         ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
500         ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
501     } else skip("Couldn't get image info from volume map in memory\n");
502
503     check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0, D3DFMT_DXT1);
504     check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0, D3DFMT_DXT2);
505     check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0, D3DFMT_DXT3);
506     check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0, D3DFMT_DXT4);
507     check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0, D3DFMT_DXT5);
508     check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8);
509     check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8);
510     check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0, D3DFMT_UYVY);
511     check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0, D3DFMT_YUY2);
512     check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5);
513     check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5);
514     check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4);
515     check_dds_pixel_format(DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2);
516     check_dds_pixel_format(DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff, D3DFMT_A8);
517     check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2);
518     check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf00, 0x0f0, 0x00f, 0, D3DFMT_X4R4G4B4);
519     check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10);
520     check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10);
521     check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8);
522     check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, D3DFMT_A8B8G8R8);
523     check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_X8R8G8B8);
524     check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8B8G8R8);
525     check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_G16R16);
526     check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8);
527     check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16);
528     check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8);
529     check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4);
530     check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8);
531     check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16);
532
533     test_dds_header_handling();
534
535     hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit) - 1, &info);
536     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
537
538     hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit) - 1, &info);
539     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
540
541     hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map) - 1, &info);
542     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
543
544     hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map) - 1, &info);
545     ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
546
547
548     /* cleanup */
549     if(testdummy_ok) DeleteFileA("testdummy.bmp");
550     if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
551 }
552
553 #define check_pixel_1bpp(lockrect, x, y, color) _check_pixel_1bpp(__LINE__, lockrect, x, y, color)
554 static inline void _check_pixel_1bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, BYTE expected_color)
555 {
556     BYTE color = ((BYTE*)lockrect->pBits)[x + y * lockrect->Pitch];
557     ok_(__FILE__, line)(color == expected_color, "Got color 0x%02x, expected 0x%02x\n", color, expected_color);
558 }
559
560 #define check_pixel_2bpp(lockrect, x, y, color) _check_pixel_2bpp(__LINE__, lockrect, x, y, color)
561 static inline void _check_pixel_2bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, WORD expected_color)
562 {
563     WORD color = ((WORD*)lockrect->pBits)[x + y * lockrect->Pitch / 2];
564     ok_(__FILE__, line)(color == expected_color, "Got color 0x%04x, expected 0x%04x\n", color, expected_color);
565 }
566
567 #define check_pixel_4bpp(lockrect, x, y, color) _check_pixel_4bpp(__LINE__, lockrect, x, y, color)
568 static inline void _check_pixel_4bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, DWORD expected_color)
569 {
570    DWORD color = ((DWORD*)lockrect->pBits)[x + y * lockrect->Pitch / 4];
571    ok_(__FILE__, line)(color == expected_color, "Got color 0x%08x, expected 0x%08x\n", color, expected_color);
572 }
573
574 static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
575 {
576     HRESULT hr;
577     BOOL testdummy_ok, testbitmap_ok;
578     IDirect3DTexture9 *tex;
579     IDirect3DSurface9 *surf, *newsurf;
580     RECT rect, destrect;
581     D3DLOCKED_RECT lockrect;
582     const WORD pixdata_a8r3g3b2[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
583     const WORD pixdata_a1r5g5b5[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
584     const WORD pixdata_r5g6b5[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
585     const WORD pixdata_a8l8[] = { 0xff00, 0x00ff, 0xff30, 0x7f7f };
586     const DWORD pixdata_g16r16[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
587     const DWORD pixdata_a8b8g8r8[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
588     const DWORD pixdata_a2r10g10b10[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
589
590     hr = create_file("testdummy.bmp", noimage, sizeof(noimage));  /* invalid image */
591     testdummy_ok = SUCCEEDED(hr);
592
593     hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01));  /* valid image */
594     testbitmap_ok = SUCCEEDED(hr);
595
596     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
597     if(FAILED(hr)) {
598         skip("Failed to create a surface (%#x)\n", hr);
599         if(testdummy_ok) DeleteFileA("testdummy.bmp");
600         if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
601         return;
602     }
603
604     /* D3DXLoadSurfaceFromFile */
605     if(testbitmap_ok) {
606         hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
607         ok(hr == D3D_OK, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3D_OK);
608
609         hr = D3DXLoadSurfaceFromFileA(NULL, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
610         ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
611     } else skip("Couldn't create \"testbitmap.bmp\"\n");
612
613     if(testdummy_ok) {
614         hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testdummy.bmp", NULL, D3DX_DEFAULT, 0, NULL);
615         ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
616     } else skip("Couldn't create \"testdummy.bmp\"\n");
617
618     hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
619     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
620
621     hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "", NULL, D3DX_DEFAULT, 0, NULL);
622     ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
623
624
625     /* D3DXLoadSurfaceFromResource */
626     todo_wine {
627         hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
628         ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
629     }
630
631     hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDD_BITMAPDATA_1x1), NULL, D3DX_DEFAULT, 0, NULL);
632     ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
633
634     hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
635     ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
636
637     hr = D3DXLoadSurfaceFromResourceA(NULL, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
638     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
639
640     hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDS_STRING), NULL, D3DX_DEFAULT, 0, NULL);
641     ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
642
643
644     /* D3DXLoadSurfaceFromFileInMemory */
645     hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
646     ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
647
648     hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, noimage, sizeof(noimage), NULL, D3DX_DEFAULT, 0, NULL);
649     ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
650
651     hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, 0, NULL, D3DX_DEFAULT, 0, NULL);
652     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
653
654     hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
655     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
656
657     hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 8, NULL, D3DX_DEFAULT, 0, NULL);
658     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
659
660     hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
661     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
662
663     hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
664     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
665
666
667     /* D3DXLoadSurfaceFromMemory */
668     SetRect(&rect, 0, 0, 2, 2);
669
670     hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
671     ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
672
673     hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, 0, NULL, &rect, D3DX_FILTER_NONE, 0);
674     ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
675
676     hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, NULL, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
677     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
678
679     hr = D3DXLoadSurfaceFromMemory(NULL, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
680     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
681
682     hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, NULL, D3DX_DEFAULT, 0);
683     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
684
685     hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_UNKNOWN, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
686     ok(hr == E_FAIL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, E_FAIL);
687
688     SetRect(&destrect, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
689     hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
690     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
691
692     SetRect(&destrect, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
693     hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
694     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
695
696     SetRect(&destrect, 1, 1, 0, 0); /* left > right, top > bottom */
697     hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
698     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
699
700     SetRect(&destrect, 0, 0, 0, 0); /* left = right, top = bottom */
701     hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
702     /* fails when debug version of d3d9 is used */
703     ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
704
705     SetRect(&destrect, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
706     hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
707     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
708
709
710     /* D3DXLoadSurfaceFromSurface */
711     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newsurf, NULL);
712     if(SUCCEEDED(hr)) {
713         hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
714         ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
715
716         hr = D3DXLoadSurfaceFromSurface(NULL, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
717         ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
718
719         hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0);
720         ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
721
722         check_release((IUnknown*)newsurf, 0);
723     } else skip("Failed to create a second surface\n");
724
725     hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
726     if (SUCCEEDED(hr))
727     {
728         IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
729
730         hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
731         ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
732
733         IDirect3DSurface9_Release(newsurf);
734         IDirect3DTexture9_Release(tex);
735     } else skip("Failed to create texture\n");
736
737     /* non-lockable render target */
738     hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &newsurf, NULL);
739     if (SUCCEEDED(hr)) {
740         hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
741         ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
742
743         IDirect3DSurface9_Release(newsurf);
744     } else skip("Failed to create render target surface\n");
745
746     /* non-lockable multisampled render target */
747     hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &newsurf, NULL);
748     if (SUCCEEDED(hr)) {
749        hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
750        ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
751
752        IDirect3DSurface9_Release(newsurf);
753     } else skip("Failed to create multisampled render target\n");
754
755     check_release((IUnknown*)surf, 0);
756
757
758     /* test color conversion */
759     /* A8R8G8B8 */
760     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
761     if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
762     else {
763         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
764         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
765         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
766         check_pixel_4bpp(&lockrect, 0, 0, 0x57dbffff);
767         check_pixel_4bpp(&lockrect, 1, 0, 0x98ffff00);
768         check_pixel_4bpp(&lockrect, 0, 1, 0xacdbff55);
769         check_pixel_4bpp(&lockrect, 1, 1, 0xc8929255);
770         IDirect3DSurface9_UnlockRect(surf);
771
772         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
773         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
774         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
775         check_pixel_4bpp(&lockrect, 0, 0, 0x008cadad);
776         check_pixel_4bpp(&lockrect, 1, 0, 0xff317342);
777         check_pixel_4bpp(&lockrect, 0, 1, 0x0008ad10);
778         check_pixel_4bpp(&lockrect, 1, 1, 0xff29088c);
779         IDirect3DSurface9_UnlockRect(surf);
780
781         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
782         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
783         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
784         check_pixel_4bpp(&lockrect, 0, 0, 0xff9cdfb5);
785         check_pixel_4bpp(&lockrect, 1, 0, 0xff63b26b);
786         check_pixel_4bpp(&lockrect, 0, 1, 0xff085d73);
787         check_pixel_4bpp(&lockrect, 1, 1, 0xff425d73);
788         IDirect3DSurface9_UnlockRect(surf);
789
790         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
791         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
792         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
793         todo_wine {
794             check_pixel_4bpp(&lockrect, 0, 0, 0xff3f08ff);
795         }
796         check_pixel_4bpp(&lockrect, 1, 0, 0xff44dcff);
797         check_pixel_4bpp(&lockrect, 0, 1, 0xff97e4ff);
798         check_pixel_4bpp(&lockrect, 1, 1, 0xfffe9aff);
799         IDirect3DSurface9_UnlockRect(surf);
800
801         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
802         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
803         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
804         check_pixel_4bpp(&lockrect, 0, 0, 0xc3f04c39);
805         check_pixel_4bpp(&lockrect, 1, 0, 0x2392e85a);
806         check_pixel_4bpp(&lockrect, 0, 1, 0x09fd97b1);
807         check_pixel_4bpp(&lockrect, 1, 1, 0x8df62bc3);
808         IDirect3DSurface9_UnlockRect(surf);
809
810         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
811         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
812         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
813         check_pixel_4bpp(&lockrect, 0, 0, 0x555c95bf);
814         check_pixel_4bpp(&lockrect, 1, 0, 0x556d663f);
815         check_pixel_4bpp(&lockrect, 0, 1, 0xaac385ad);
816         todo_wine {
817             check_pixel_4bpp(&lockrect, 1, 1, 0xfffcc575);
818         }
819         IDirect3DSurface9_UnlockRect(surf);
820
821         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
822                 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
823         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
824         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
825         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
826         check_pixel_4bpp(&lockrect, 0, 0, 0xff000000);
827         check_pixel_4bpp(&lockrect, 1, 0, 0x00ffffff);
828         check_pixel_4bpp(&lockrect, 0, 1, 0xff303030);
829         check_pixel_4bpp(&lockrect, 1, 1, 0x7f7f7f7f);
830         hr = IDirect3DSurface9_UnlockRect(surf);
831         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
832
833         check_release((IUnknown*)surf, 0);
834     }
835
836     /* A1R5G5B5 */
837     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A1R5G5B5, D3DPOOL_DEFAULT, &surf, NULL);
838     if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
839     else {
840         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
841         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
842         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
843         check_pixel_2bpp(&lockrect, 0, 0, 0x6fff);
844         check_pixel_2bpp(&lockrect, 1, 0, 0xffe0);
845         check_pixel_2bpp(&lockrect, 0, 1, 0xefea);
846         check_pixel_2bpp(&lockrect, 1, 1, 0xca4a);
847         IDirect3DSurface9_UnlockRect(surf);
848
849         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
850         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
851         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
852         check_pixel_2bpp(&lockrect, 0, 0, 0x46b5);
853         check_pixel_2bpp(&lockrect, 1, 0, 0x99c8);
854         check_pixel_2bpp(&lockrect, 0, 1, 0x06a2);
855         check_pixel_2bpp(&lockrect, 1, 1, 0x9431);
856         IDirect3DSurface9_UnlockRect(surf);
857
858         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
859         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
860         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
861         check_pixel_2bpp(&lockrect, 0, 0, 0xcf76);
862         check_pixel_2bpp(&lockrect, 1, 0, 0xb2cd);
863         check_pixel_2bpp(&lockrect, 0, 1, 0x856e);
864         check_pixel_2bpp(&lockrect, 1, 1, 0xa16e);
865         IDirect3DSurface9_UnlockRect(surf);
866
867         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
868         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
869         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
870         todo_wine {
871             check_pixel_2bpp(&lockrect, 0, 0, 0xa03f);
872         }
873         check_pixel_2bpp(&lockrect, 1, 0, 0xa37f);
874         check_pixel_2bpp(&lockrect, 0, 1, 0xcb9f);
875         check_pixel_2bpp(&lockrect, 1, 1, 0xfe7f);
876         IDirect3DSurface9_UnlockRect(surf);
877
878         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
879         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
880         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
881         todo_wine {
882             check_pixel_2bpp(&lockrect, 0, 0, 0xf527);
883             check_pixel_2bpp(&lockrect, 1, 0, 0x4b8b);
884         }
885         check_pixel_2bpp(&lockrect, 0, 1, 0x7e56);
886         check_pixel_2bpp(&lockrect, 1, 1, 0xf8b8);
887         IDirect3DSurface9_UnlockRect(surf);
888
889         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
890         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
891         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
892         check_pixel_2bpp(&lockrect, 0, 0, 0x2e57);
893         todo_wine {
894             check_pixel_2bpp(&lockrect, 1, 0, 0x3588);
895         }
896         check_pixel_2bpp(&lockrect, 0, 1, 0xe215);
897         check_pixel_2bpp(&lockrect, 1, 1, 0xff0e);
898         IDirect3DSurface9_UnlockRect(surf);
899
900         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
901                 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
902         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
903         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
904         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
905         check_pixel_2bpp(&lockrect, 0, 0, 0x8000);
906         check_pixel_2bpp(&lockrect, 1, 0, 0x7fff);
907         check_pixel_2bpp(&lockrect, 0, 1, 0x98c6);
908         check_pixel_2bpp(&lockrect, 1, 1, 0x3def);
909         hr = IDirect3DSurface9_UnlockRect(surf);
910         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
911
912         check_release((IUnknown*)surf, 0);
913     }
914
915     /* A8L8 */
916     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8L8, D3DPOOL_DEFAULT, &surf, NULL);
917     if (FAILED(hr))
918         skip("Failed to create A8L8 surface, hr %#x.\n", hr);
919     else
920     {
921         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
922                 D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
923         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
924         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
925         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
926         check_pixel_2bpp(&lockrect, 0, 0, 0x57f7);
927         check_pixel_2bpp(&lockrect, 1, 0, 0x98ed);
928         check_pixel_2bpp(&lockrect, 0, 1, 0xaceb);
929         check_pixel_2bpp(&lockrect, 1, 1, 0xc88d);
930         hr = IDirect3DSurface9_UnlockRect(surf);
931         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
932
933         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
934                 D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
935         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
936         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
937         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
938         check_pixel_2bpp(&lockrect, 0, 0, 0x00a6);
939         check_pixel_2bpp(&lockrect, 1, 0, 0xff62);
940         check_pixel_2bpp(&lockrect, 0, 1, 0x007f);
941         check_pixel_2bpp(&lockrect, 1, 1, 0xff19);
942         hr = IDirect3DSurface9_UnlockRect(surf);
943         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
944
945         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
946                 D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
947         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
948         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
949         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
950         check_pixel_2bpp(&lockrect, 0, 0, 0xffce);
951         check_pixel_2bpp(&lockrect, 1, 0, 0xff9c);
952         check_pixel_2bpp(&lockrect, 0, 1, 0xff4d);
953         check_pixel_2bpp(&lockrect, 1, 1, 0xff59);
954         hr = IDirect3DSurface9_UnlockRect(surf);
955         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
956
957         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
958                 D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
959         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
960         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
961         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
962         check_pixel_2bpp(&lockrect, 0, 0, 0xff25);
963         check_pixel_2bpp(&lockrect, 1, 0, 0xffbe);
964         check_pixel_2bpp(&lockrect, 0, 1, 0xffd6);
965         check_pixel_2bpp(&lockrect, 1, 1, 0xffb6);
966         hr = IDirect3DSurface9_UnlockRect(surf);
967         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
968
969         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
970                 D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
971         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
972         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
973         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
974         check_pixel_2bpp(&lockrect, 0, 0, 0xc36d);
975         check_pixel_2bpp(&lockrect, 1, 0, 0x23cb);
976         check_pixel_2bpp(&lockrect, 0, 1, 0x09af);
977         check_pixel_2bpp(&lockrect, 1, 1, 0x8d61);
978         hr = IDirect3DSurface9_UnlockRect(surf);
979         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
980
981         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
982                 D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
983         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
984         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
985         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
986         check_pixel_2bpp(&lockrect, 0, 0, 0x558c);
987         check_pixel_2bpp(&lockrect, 1, 0, 0x5565);
988         check_pixel_2bpp(&lockrect, 0, 1, 0xaa95);
989         check_pixel_2bpp(&lockrect, 1, 1, 0xffcb);
990         hr = IDirect3DSurface9_UnlockRect(surf);
991         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
992
993         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
994                 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
995         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
996         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
997         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
998         check_pixel_2bpp(&lockrect, 0, 0, 0xff00);
999         check_pixel_2bpp(&lockrect, 1, 0, 0x00ff);
1000         check_pixel_2bpp(&lockrect, 0, 1, 0xff30);
1001         check_pixel_2bpp(&lockrect, 1, 1, 0x7f7f);
1002         hr = IDirect3DSurface9_UnlockRect(surf);
1003         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1004
1005         check_release((IUnknown*)surf, 0);
1006     }
1007
1008     /* DXT1, DXT2, DXT3, DXT4, DXT5 */
1009     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf, NULL);
1010     if (FAILED(hr))
1011         skip("Failed to create R8G8B8 surface, hr %#x.\n", hr);
1012     else
1013     {
1014         hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, dds_24bit, sizeof(dds_24bit), NULL, D3DX_FILTER_NONE, 0, NULL);
1015         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1016
1017         hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT2, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1018         if (FAILED(hr))
1019             skip("Failed to create DXT2 surface, hr %#x.\n", hr);
1020         else
1021         {
1022             hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1023             todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT2 format.\n");
1024             check_release((IUnknown*)newsurf, 0);
1025         }
1026
1027         hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT3, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1028         if (FAILED(hr))
1029             skip("Failed to create DXT3 surface, hr %#x.\n", hr);
1030         else
1031         {
1032             hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1033             todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT3 format.\n");
1034             check_release((IUnknown*)newsurf, 0);
1035         }
1036
1037         hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT4, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1038         if (FAILED(hr))
1039             skip("Failed to create DXT4 surface, hr %#x.\n", hr);
1040         else
1041         {
1042             hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1043             todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT4 format.\n");
1044             check_release((IUnknown*)newsurf, 0);
1045         }
1046
1047         hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1048         if (FAILED(hr))
1049             skip("Failed to create DXT5 surface, hr %#x.\n", hr);
1050         else
1051         {
1052             hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1053             todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT5 format.\n");
1054             check_release((IUnknown*)newsurf, 0);
1055         }
1056
1057         hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1058         if (FAILED(hr))
1059             skip("Failed to create DXT1 surface, hr %#x.\n", hr);
1060         else
1061         {
1062             hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1063             todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT1 format.\n");
1064
1065             hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
1066             todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels from DXT1 format.\n");
1067
1068             check_release((IUnknown*)newsurf, 0);
1069         }
1070
1071         check_release((IUnknown*)surf, 0);
1072     }
1073
1074     /* cleanup */
1075     if(testdummy_ok) DeleteFileA("testdummy.bmp");
1076     if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
1077 }
1078
1079 static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9 *device)
1080 {
1081     HRESULT hr;
1082     RECT rect;
1083     ID3DXBuffer *buffer;
1084     IDirect3DSurface9 *surface;
1085
1086     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1087     if (FAILED(hr)) {
1088        skip("Couldn't create surface\n");
1089        return;
1090     }
1091
1092     SetRect(&rect, 0, 0, 0, 0);
1093     hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_BMP, surface, NULL, &rect);
1094     /* fails with the debug version of d3d9 */
1095     ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1096     if (SUCCEEDED(hr)) {
1097         DWORD size = ID3DXBuffer_GetBufferSize(buffer);
1098         ok(size > 0, "ID3DXBuffer_GetBufferSize returned %u, expected > 0\n", size);
1099         ID3DXBuffer_Release(buffer);
1100     }
1101
1102     IDirect3DSurface9_Release(surface);
1103 }
1104
1105 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
1106 {
1107     HRESULT hr;
1108     IDirect3DSurface9 *surface;
1109     RECT rect;
1110     D3DLOCKED_RECT lock_rect;
1111     D3DXIMAGE_INFO image_info;
1112     const BYTE pixels[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
1113                             0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
1114     DWORD pitch = sizeof(pixels) / 2;
1115
1116     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1117     if (FAILED(hr)) {
1118        skip("Couldn't create surface\n");
1119        return;
1120     }
1121
1122     SetRect(&rect, 0, 0, 2, 2);
1123     hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, pixels, D3DFMT_R8G8B8, pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
1124     if (SUCCEEDED(hr)) {
1125         hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, NULL);
1126         ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1127
1128         hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.bmp", NULL, D3DX_FILTER_NONE, 0, &image_info);
1129         ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
1130         if (FAILED(hr)) goto next_tests;
1131
1132         ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
1133         ok(image_info.Height == 2, "Wrong height %u\n", image_info.Height);
1134         ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
1135         ok(image_info.ImageFileFormat == D3DXIFF_BMP, "Wrong file format %u\n", image_info.ImageFileFormat);
1136
1137         hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1138         ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
1139         if (FAILED(hr)) goto next_tests;
1140
1141         ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
1142         ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
1143
1144         IDirect3DSurface9_UnlockRect(surface);
1145     } else skip("Couldn't fill surface\n");
1146
1147 next_tests:
1148     hr = D3DXSaveSurfaceToFileA(NULL, D3DXIFF_BMP, surface, NULL, NULL);
1149     ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1150
1151     /* PPM and TGA are supported, even though MSDN claims they aren't */
1152     todo_wine {
1153     hr = D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM, surface, NULL, NULL);
1154     ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1155     hr = D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA, surface, NULL, NULL);
1156     ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1157     }
1158
1159     hr = D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS, surface, NULL, NULL);
1160     ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1161     if (SUCCEEDED(hr)) {
1162         hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.dds", NULL, D3DX_FILTER_NONE, 0, &image_info);
1163         ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
1164
1165         if (SUCCEEDED(hr)) {
1166             ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
1167             ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
1168             ok(image_info.ImageFileFormat == D3DXIFF_DDS, "Wrong file format %u\n", image_info.ImageFileFormat);
1169
1170             hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1171             ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
1172             if (SUCCEEDED(hr)) {
1173                 ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
1174                 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
1175                 IDirect3DSurface9_UnlockRect(surface);
1176             }
1177         }
1178     } else skip("Couldn't save surface\n");
1179
1180     hr = D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM + 1, surface, NULL, NULL);
1181     ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1182
1183     SetRect(&rect, 0, 0, 4, 4);
1184     hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1185     ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1186     SetRect(&rect, 2, 0, 1, 4);
1187     hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1188     ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1189     SetRect(&rect, 0, 2, 4, 1);
1190     hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1191     ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1192     SetRect(&rect, -1, -1, 2, 2);
1193     hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1194     ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1195     SetRect(&rect, 0, 0, 0, 0);
1196     hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1197     /* fails when debug version of d3d9 is used */
1198     ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1199
1200     DeleteFileA("saved_surface.bmp");
1201     DeleteFileA("saved_surface.ppm");
1202     DeleteFileA("saved_surface.tga");
1203     DeleteFileA("saved_surface.dds");
1204
1205     IDirect3DSurface9_Release(surface);
1206 }
1207
1208 START_TEST(surface)
1209 {
1210     HWND wnd;
1211     IDirect3D9 *d3d;
1212     IDirect3DDevice9 *device;
1213     D3DPRESENT_PARAMETERS d3dpp;
1214     HRESULT hr;
1215
1216     wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1217     if (!wnd) {
1218         skip("Couldn't create application window\n");
1219         return;
1220     }
1221     d3d = Direct3DCreate9(D3D_SDK_VERSION);
1222     if (!d3d) {
1223         skip("Couldn't create IDirect3D9 object\n");
1224         DestroyWindow(wnd);
1225         return;
1226     }
1227
1228     ZeroMemory(&d3dpp, sizeof(d3dpp));
1229     d3dpp.Windowed   = TRUE;
1230     d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1231     hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
1232     if(FAILED(hr)) {
1233         skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1234         IDirect3D9_Release(d3d);
1235         DestroyWindow(wnd);
1236         return;
1237     }
1238
1239     test_D3DXGetImageInfo();
1240     test_D3DXLoadSurface(device);
1241     test_D3DXSaveSurfaceToFileInMemory(device);
1242     test_D3DXSaveSurfaceToFile(device);
1243
1244     check_release((IUnknown*)device, 0);
1245     check_release((IUnknown*)d3d, 0);
1246     DestroyWindow(wnd);
1247 }