Release 1.5.29.
[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     hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
627     ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
628
629     hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDD_BITMAPDATA_1x1), NULL, D3DX_DEFAULT, 0, NULL);
630     ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
631
632     hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
633     ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
634
635     hr = D3DXLoadSurfaceFromResourceA(NULL, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
636     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
637
638     hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDS_STRING), NULL, D3DX_DEFAULT, 0, NULL);
639     ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
640
641
642     /* D3DXLoadSurfaceFromFileInMemory */
643     hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
644     ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
645
646     hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, noimage, sizeof(noimage), NULL, D3DX_DEFAULT, 0, NULL);
647     ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
648
649     hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, 0, NULL, D3DX_DEFAULT, 0, NULL);
650     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
651
652     hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
653     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
654
655     hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 8, NULL, D3DX_DEFAULT, 0, NULL);
656     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
657
658     hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
659     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
660
661     hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
662     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
663
664
665     /* D3DXLoadSurfaceFromMemory */
666     SetRect(&rect, 0, 0, 2, 2);
667
668     hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
669     ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
670
671     hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, 0, NULL, &rect, D3DX_FILTER_NONE, 0);
672     ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
673
674     hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, NULL, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
675     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
676
677     hr = D3DXLoadSurfaceFromMemory(NULL, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
678     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
679
680     hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, NULL, D3DX_DEFAULT, 0);
681     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
682
683     hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_UNKNOWN, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
684     ok(hr == E_FAIL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, E_FAIL);
685
686     SetRect(&destrect, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
687     hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
688     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
689
690     SetRect(&destrect, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
691     hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
692     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
693
694     SetRect(&destrect, 1, 1, 0, 0); /* left > right, top > bottom */
695     hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
696     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
697
698     SetRect(&destrect, 0, 0, 0, 0); /* left = right, top = bottom */
699     hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
700     /* fails when debug version of d3d9 is used */
701     ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
702
703     SetRect(&destrect, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
704     hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
705     ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
706
707
708     /* D3DXLoadSurfaceFromSurface */
709     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newsurf, NULL);
710     if(SUCCEEDED(hr)) {
711         hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
712         ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
713
714         hr = D3DXLoadSurfaceFromSurface(NULL, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
715         ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
716
717         hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0);
718         ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
719
720         check_release((IUnknown*)newsurf, 0);
721     } else skip("Failed to create a second surface\n");
722
723     hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
724     if (SUCCEEDED(hr))
725     {
726         IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
727
728         hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
729         ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
730
731         IDirect3DSurface9_Release(newsurf);
732         IDirect3DTexture9_Release(tex);
733     } else skip("Failed to create texture\n");
734
735     /* non-lockable render target */
736     hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &newsurf, NULL);
737     if (SUCCEEDED(hr)) {
738         hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
739         ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
740
741         IDirect3DSurface9_Release(newsurf);
742     } else skip("Failed to create render target surface\n");
743
744     /* non-lockable multisampled render target */
745     hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &newsurf, NULL);
746     if (SUCCEEDED(hr)) {
747        hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
748        ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
749
750        IDirect3DSurface9_Release(newsurf);
751     } else skip("Failed to create multisampled render target\n");
752
753     check_release((IUnknown*)surf, 0);
754
755
756     /* test color conversion */
757     /* A8R8G8B8 */
758     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
759     if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
760     else {
761         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
762         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
763         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
764         check_pixel_4bpp(&lockrect, 0, 0, 0x57dbffff);
765         check_pixel_4bpp(&lockrect, 1, 0, 0x98ffff00);
766         check_pixel_4bpp(&lockrect, 0, 1, 0xacdbff55);
767         check_pixel_4bpp(&lockrect, 1, 1, 0xc8929255);
768         IDirect3DSurface9_UnlockRect(surf);
769
770         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
771         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
772         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
773         check_pixel_4bpp(&lockrect, 0, 0, 0x008cadad);
774         check_pixel_4bpp(&lockrect, 1, 0, 0xff317342);
775         check_pixel_4bpp(&lockrect, 0, 1, 0x0008ad10);
776         check_pixel_4bpp(&lockrect, 1, 1, 0xff29088c);
777         IDirect3DSurface9_UnlockRect(surf);
778
779         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
780         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
781         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
782         check_pixel_4bpp(&lockrect, 0, 0, 0xff9cdfb5);
783         check_pixel_4bpp(&lockrect, 1, 0, 0xff63b26b);
784         check_pixel_4bpp(&lockrect, 0, 1, 0xff085d73);
785         check_pixel_4bpp(&lockrect, 1, 1, 0xff425d73);
786         IDirect3DSurface9_UnlockRect(surf);
787
788         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
789         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
790         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
791         todo_wine {
792             check_pixel_4bpp(&lockrect, 0, 0, 0xff3f08ff);
793         }
794         check_pixel_4bpp(&lockrect, 1, 0, 0xff44dcff);
795         check_pixel_4bpp(&lockrect, 0, 1, 0xff97e4ff);
796         check_pixel_4bpp(&lockrect, 1, 1, 0xfffe9aff);
797         IDirect3DSurface9_UnlockRect(surf);
798
799         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
800         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
801         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
802         check_pixel_4bpp(&lockrect, 0, 0, 0xc3f04c39);
803         check_pixel_4bpp(&lockrect, 1, 0, 0x2392e85a);
804         check_pixel_4bpp(&lockrect, 0, 1, 0x09fd97b1);
805         check_pixel_4bpp(&lockrect, 1, 1, 0x8df62bc3);
806         IDirect3DSurface9_UnlockRect(surf);
807
808         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
809         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
810         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
811         check_pixel_4bpp(&lockrect, 0, 0, 0x555c95bf);
812         check_pixel_4bpp(&lockrect, 1, 0, 0x556d663f);
813         check_pixel_4bpp(&lockrect, 0, 1, 0xaac385ad);
814         todo_wine {
815             check_pixel_4bpp(&lockrect, 1, 1, 0xfffcc575);
816         }
817         IDirect3DSurface9_UnlockRect(surf);
818
819         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
820                 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
821         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
822         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
823         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
824         check_pixel_4bpp(&lockrect, 0, 0, 0xff000000);
825         check_pixel_4bpp(&lockrect, 1, 0, 0x00ffffff);
826         check_pixel_4bpp(&lockrect, 0, 1, 0xff303030);
827         check_pixel_4bpp(&lockrect, 1, 1, 0x7f7f7f7f);
828         hr = IDirect3DSurface9_UnlockRect(surf);
829         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
830
831         check_release((IUnknown*)surf, 0);
832     }
833
834     /* A1R5G5B5 */
835     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A1R5G5B5, D3DPOOL_DEFAULT, &surf, NULL);
836     if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
837     else {
838         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
839         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
840         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
841         check_pixel_2bpp(&lockrect, 0, 0, 0x6fff);
842         check_pixel_2bpp(&lockrect, 1, 0, 0xffe0);
843         check_pixel_2bpp(&lockrect, 0, 1, 0xefea);
844         check_pixel_2bpp(&lockrect, 1, 1, 0xca4a);
845         IDirect3DSurface9_UnlockRect(surf);
846
847         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
848         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
849         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
850         check_pixel_2bpp(&lockrect, 0, 0, 0x46b5);
851         check_pixel_2bpp(&lockrect, 1, 0, 0x99c8);
852         check_pixel_2bpp(&lockrect, 0, 1, 0x06a2);
853         check_pixel_2bpp(&lockrect, 1, 1, 0x9431);
854         IDirect3DSurface9_UnlockRect(surf);
855
856         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
857         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
858         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
859         check_pixel_2bpp(&lockrect, 0, 0, 0xcf76);
860         check_pixel_2bpp(&lockrect, 1, 0, 0xb2cd);
861         check_pixel_2bpp(&lockrect, 0, 1, 0x856e);
862         check_pixel_2bpp(&lockrect, 1, 1, 0xa16e);
863         IDirect3DSurface9_UnlockRect(surf);
864
865         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
866         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
867         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
868         todo_wine {
869             check_pixel_2bpp(&lockrect, 0, 0, 0xa03f);
870         }
871         check_pixel_2bpp(&lockrect, 1, 0, 0xa37f);
872         check_pixel_2bpp(&lockrect, 0, 1, 0xcb9f);
873         check_pixel_2bpp(&lockrect, 1, 1, 0xfe7f);
874         IDirect3DSurface9_UnlockRect(surf);
875
876         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
877         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
878         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
879         todo_wine {
880             check_pixel_2bpp(&lockrect, 0, 0, 0xf527);
881             check_pixel_2bpp(&lockrect, 1, 0, 0x4b8b);
882         }
883         check_pixel_2bpp(&lockrect, 0, 1, 0x7e56);
884         check_pixel_2bpp(&lockrect, 1, 1, 0xf8b8);
885         IDirect3DSurface9_UnlockRect(surf);
886
887         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
888         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
889         IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
890         check_pixel_2bpp(&lockrect, 0, 0, 0x2e57);
891         todo_wine {
892             check_pixel_2bpp(&lockrect, 1, 0, 0x3588);
893         }
894         check_pixel_2bpp(&lockrect, 0, 1, 0xe215);
895         check_pixel_2bpp(&lockrect, 1, 1, 0xff0e);
896         IDirect3DSurface9_UnlockRect(surf);
897
898         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
899                 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
900         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
901         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
902         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
903         check_pixel_2bpp(&lockrect, 0, 0, 0x8000);
904         check_pixel_2bpp(&lockrect, 1, 0, 0x7fff);
905         check_pixel_2bpp(&lockrect, 0, 1, 0x98c6);
906         check_pixel_2bpp(&lockrect, 1, 1, 0x3def);
907         hr = IDirect3DSurface9_UnlockRect(surf);
908         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
909
910         check_release((IUnknown*)surf, 0);
911     }
912
913     /* A8L8 */
914     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8L8, D3DPOOL_DEFAULT, &surf, NULL);
915     if (FAILED(hr))
916         skip("Failed to create A8L8 surface, hr %#x.\n", hr);
917     else
918     {
919         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
920                 D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
921         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
922         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
923         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
924         check_pixel_2bpp(&lockrect, 0, 0, 0x57f7);
925         check_pixel_2bpp(&lockrect, 1, 0, 0x98ed);
926         check_pixel_2bpp(&lockrect, 0, 1, 0xaceb);
927         check_pixel_2bpp(&lockrect, 1, 1, 0xc88d);
928         hr = IDirect3DSurface9_UnlockRect(surf);
929         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
930
931         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
932                 D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
933         ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
934         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
935         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
936         check_pixel_2bpp(&lockrect, 0, 0, 0x00a6);
937         check_pixel_2bpp(&lockrect, 1, 0, 0xff62);
938         check_pixel_2bpp(&lockrect, 0, 1, 0x007f);
939         check_pixel_2bpp(&lockrect, 1, 1, 0xff19);
940         hr = IDirect3DSurface9_UnlockRect(surf);
941         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
942
943         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
944                 D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
945         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
946         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
947         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
948         check_pixel_2bpp(&lockrect, 0, 0, 0xffce);
949         check_pixel_2bpp(&lockrect, 1, 0, 0xff9c);
950         check_pixel_2bpp(&lockrect, 0, 1, 0xff4d);
951         check_pixel_2bpp(&lockrect, 1, 1, 0xff59);
952         hr = IDirect3DSurface9_UnlockRect(surf);
953         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
954
955         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
956                 D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
957         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
958         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
959         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
960         check_pixel_2bpp(&lockrect, 0, 0, 0xff25);
961         check_pixel_2bpp(&lockrect, 1, 0, 0xffbe);
962         check_pixel_2bpp(&lockrect, 0, 1, 0xffd6);
963         check_pixel_2bpp(&lockrect, 1, 1, 0xffb6);
964         hr = IDirect3DSurface9_UnlockRect(surf);
965         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
966
967         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
968                 D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
969         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
970         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
971         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
972         check_pixel_2bpp(&lockrect, 0, 0, 0xc36d);
973         check_pixel_2bpp(&lockrect, 1, 0, 0x23cb);
974         check_pixel_2bpp(&lockrect, 0, 1, 0x09af);
975         check_pixel_2bpp(&lockrect, 1, 1, 0x8d61);
976         hr = IDirect3DSurface9_UnlockRect(surf);
977         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
978
979         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
980                 D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
981         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
982         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
983         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
984         check_pixel_2bpp(&lockrect, 0, 0, 0x558c);
985         check_pixel_2bpp(&lockrect, 1, 0, 0x5565);
986         check_pixel_2bpp(&lockrect, 0, 1, 0xaa95);
987         check_pixel_2bpp(&lockrect, 1, 1, 0xffcb);
988         hr = IDirect3DSurface9_UnlockRect(surf);
989         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
990
991         hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
992                 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
993         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
994         hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
995         ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
996         check_pixel_2bpp(&lockrect, 0, 0, 0xff00);
997         check_pixel_2bpp(&lockrect, 1, 0, 0x00ff);
998         check_pixel_2bpp(&lockrect, 0, 1, 0xff30);
999         check_pixel_2bpp(&lockrect, 1, 1, 0x7f7f);
1000         hr = IDirect3DSurface9_UnlockRect(surf);
1001         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1002
1003         check_release((IUnknown*)surf, 0);
1004     }
1005
1006     /* DXT1, DXT2, DXT3, DXT4, DXT5 */
1007     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf, NULL);
1008     if (FAILED(hr))
1009         skip("Failed to create R8G8B8 surface, hr %#x.\n", hr);
1010     else
1011     {
1012         hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, dds_24bit, sizeof(dds_24bit), NULL, D3DX_FILTER_NONE, 0, NULL);
1013         ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1014
1015         hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT2, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1016         if (FAILED(hr))
1017             skip("Failed to create DXT2 surface, hr %#x.\n", hr);
1018         else
1019         {
1020             hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1021             todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT2 format.\n");
1022             check_release((IUnknown*)newsurf, 0);
1023         }
1024
1025         hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT3, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1026         if (FAILED(hr))
1027             skip("Failed to create DXT3 surface, hr %#x.\n", hr);
1028         else
1029         {
1030             hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1031             todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT3 format.\n");
1032             check_release((IUnknown*)newsurf, 0);
1033         }
1034
1035         hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT4, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1036         if (FAILED(hr))
1037             skip("Failed to create DXT4 surface, hr %#x.\n", hr);
1038         else
1039         {
1040             hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1041             todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT4 format.\n");
1042             check_release((IUnknown*)newsurf, 0);
1043         }
1044
1045         hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1046         if (FAILED(hr))
1047             skip("Failed to create DXT5 surface, hr %#x.\n", hr);
1048         else
1049         {
1050             hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1051             todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT5 format.\n");
1052             check_release((IUnknown*)newsurf, 0);
1053         }
1054
1055         hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1056         if (FAILED(hr))
1057             skip("Failed to create DXT1 surface, hr %#x.\n", hr);
1058         else
1059         {
1060             hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1061             todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT1 format.\n");
1062
1063             hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
1064             todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels from DXT1 format.\n");
1065
1066             check_release((IUnknown*)newsurf, 0);
1067         }
1068
1069         check_release((IUnknown*)surf, 0);
1070     }
1071
1072     /* cleanup */
1073     if(testdummy_ok) DeleteFileA("testdummy.bmp");
1074     if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
1075 }
1076
1077 static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9 *device)
1078 {
1079     HRESULT hr;
1080     RECT rect;
1081     ID3DXBuffer *buffer;
1082     IDirect3DSurface9 *surface;
1083
1084     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1085     if (FAILED(hr)) {
1086        skip("Couldn't create surface\n");
1087        return;
1088     }
1089
1090     SetRect(&rect, 0, 0, 0, 0);
1091     hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_BMP, surface, NULL, &rect);
1092     /* fails with the debug version of d3d9 */
1093     ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1094     if (SUCCEEDED(hr)) {
1095         DWORD size = ID3DXBuffer_GetBufferSize(buffer);
1096         ok(size > 0, "ID3DXBuffer_GetBufferSize returned %u, expected > 0\n", size);
1097         ID3DXBuffer_Release(buffer);
1098     }
1099
1100     IDirect3DSurface9_Release(surface);
1101 }
1102
1103 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
1104 {
1105     HRESULT hr;
1106     IDirect3DSurface9 *surface;
1107     RECT rect;
1108     D3DLOCKED_RECT lock_rect;
1109     D3DXIMAGE_INFO image_info;
1110     const BYTE pixels[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
1111                             0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
1112     DWORD pitch = sizeof(pixels) / 2;
1113
1114     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1115     if (FAILED(hr)) {
1116        skip("Couldn't create surface\n");
1117        return;
1118     }
1119
1120     SetRect(&rect, 0, 0, 2, 2);
1121     hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, pixels, D3DFMT_R8G8B8, pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
1122     if (SUCCEEDED(hr)) {
1123         hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, NULL);
1124         ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1125
1126         hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.bmp", NULL, D3DX_FILTER_NONE, 0, &image_info);
1127         ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
1128         if (FAILED(hr)) goto next_tests;
1129
1130         ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
1131         ok(image_info.Height == 2, "Wrong height %u\n", image_info.Height);
1132         ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
1133         ok(image_info.ImageFileFormat == D3DXIFF_BMP, "Wrong file format %u\n", image_info.ImageFileFormat);
1134
1135         hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1136         ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
1137         if (FAILED(hr)) goto next_tests;
1138
1139         ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
1140         ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
1141
1142         IDirect3DSurface9_UnlockRect(surface);
1143     } else skip("Couldn't fill surface\n");
1144
1145 next_tests:
1146     hr = D3DXSaveSurfaceToFileA(NULL, D3DXIFF_BMP, surface, NULL, NULL);
1147     ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1148
1149     /* PPM and TGA are supported, even though MSDN claims they aren't */
1150     todo_wine {
1151     hr = D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM, surface, NULL, NULL);
1152     ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1153     hr = D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA, surface, NULL, NULL);
1154     ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1155     }
1156
1157     hr = D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS, surface, NULL, NULL);
1158     ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1159     if (SUCCEEDED(hr)) {
1160         hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.dds", NULL, D3DX_FILTER_NONE, 0, &image_info);
1161         ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
1162
1163         if (SUCCEEDED(hr)) {
1164             ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
1165             ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
1166             ok(image_info.ImageFileFormat == D3DXIFF_DDS, "Wrong file format %u\n", image_info.ImageFileFormat);
1167
1168             hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1169             ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
1170             if (SUCCEEDED(hr)) {
1171                 ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
1172                 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
1173                 IDirect3DSurface9_UnlockRect(surface);
1174             }
1175         }
1176     } else skip("Couldn't save surface\n");
1177
1178     hr = D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM + 1, surface, NULL, NULL);
1179     ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1180
1181     SetRect(&rect, 0, 0, 4, 4);
1182     hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1183     ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1184     SetRect(&rect, 2, 0, 1, 4);
1185     hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1186     ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1187     SetRect(&rect, 0, 2, 4, 1);
1188     hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1189     ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1190     SetRect(&rect, -1, -1, 2, 2);
1191     hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1192     ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1193     SetRect(&rect, 0, 0, 0, 0);
1194     hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1195     /* fails when debug version of d3d9 is used */
1196     ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1197
1198     DeleteFileA("saved_surface.bmp");
1199     DeleteFileA("saved_surface.ppm");
1200     DeleteFileA("saved_surface.tga");
1201     DeleteFileA("saved_surface.dds");
1202
1203     IDirect3DSurface9_Release(surface);
1204 }
1205
1206 START_TEST(surface)
1207 {
1208     HWND wnd;
1209     IDirect3D9 *d3d;
1210     IDirect3DDevice9 *device;
1211     D3DPRESENT_PARAMETERS d3dpp;
1212     HRESULT hr;
1213
1214     wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1215     if (!wnd) {
1216         skip("Couldn't create application window\n");
1217         return;
1218     }
1219     d3d = Direct3DCreate9(D3D_SDK_VERSION);
1220     if (!d3d) {
1221         skip("Couldn't create IDirect3D9 object\n");
1222         DestroyWindow(wnd);
1223         return;
1224     }
1225
1226     ZeroMemory(&d3dpp, sizeof(d3dpp));
1227     d3dpp.Windowed   = TRUE;
1228     d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1229     hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
1230     if(FAILED(hr)) {
1231         skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1232         IDirect3D9_Release(d3d);
1233         DestroyWindow(wnd);
1234         return;
1235     }
1236
1237     test_D3DXGetImageInfo();
1238     test_D3DXLoadSurface(device);
1239     test_D3DXSaveSurfaceToFileInMemory(device);
1240     test_D3DXSaveSurfaceToFile(device);
1241
1242     check_release((IUnknown*)device, 0);
1243     check_release((IUnknown*)d3d, 0);
1244     DestroyWindow(wnd);
1245 }