2 * Tests for the D3DX9 surface functions
4 * Copyright 2009 Tony Wasserka
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.
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.
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
22 #include "wine/test.h"
24 #include "resources.h"
26 static inline int get_ref(IUnknown *obj)
29 return IUnknown_Release(obj);
32 static inline void check_ref(IUnknown *obj, int exp)
34 int ref = get_ref(obj);
35 ok (exp == ref, "Invalid refcount. Expected %d, got %d\n", exp, ref);
38 static inline void check_release(IUnknown *obj, int exp)
40 int ref = IUnknown_Release(obj);
41 ok (ref == exp, "Invalid refcount. Expected %d, got %d\n", exp, ref);
45 static const unsigned char bmp01[66] = {
46 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
47 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
48 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
49 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
53 /* 2x2 A8R8G8B8 pixel data */
54 static const unsigned char pixdata[] = {
55 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
58 /* invalid image file */
59 static const unsigned char noimage[4] = {
63 /* 2x2 24-bit dds, 2 mipmaps */
64 static const unsigned char dds_24bit[] = {
65 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00,
66 0x02,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
67 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
68 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
69 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
70 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
71 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
72 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
73 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
76 /* 2x2 16-bit dds, no mipmaps */
77 static const unsigned char dds_16bit[] = {
78 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
79 0x02,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
80 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
81 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
82 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
83 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,
84 0xe0,0x03,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
85 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
86 0xff,0x7f,0xff,0x7f,0xff,0x7f,0xff,0x7f
89 /* 4x4 cube map dds */
90 static const unsigned char dds_cube_map[] = {
91 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00,
92 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
93 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
94 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
95 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
96 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
97 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
98 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
99 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
100 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
101 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
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
107 /* 4x4x2 volume map dds, 2 mipmaps */
108 static const unsigned char dds_volume_map[] = {
109 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
110 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
111 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
112 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
113 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
114 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
115 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
116 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
117 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
118 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
119 0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
120 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
123 static HRESULT create_file(const char *filename, const unsigned char *data, const unsigned int size)
128 hfile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
129 if(hfile == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError());
131 if(WriteFile(hfile, data, size, &received, NULL))
138 return D3DERR_INVALIDCALL;
141 #define DDS_CAPS 0x00000001
142 #define DDS_HEIGHT 0x00000002
143 #define DDS_WIDTH 0x00000004
144 #define DDS_PIXELFORMAT 0x00001000
146 #define DDS_CAPS_TEXTURE 0x00001000
148 #define DDS_PF_ALPHA 0x00000001
149 #define DDS_PF_ALPHA_ONLY 0x00000002
150 #define DDS_PF_FOURCC 0x00000004
151 #define DDS_PF_RGB 0x00000040
152 #define DDS_PF_LUMINANCE 0x00020000
153 #define DDS_PF_BUMPDUDV 0x00080000
155 static void check_dds_pixel_format(DWORD flags, DWORD fourcc, DWORD bpp,
156 DWORD rmask, DWORD gmask, DWORD bmask, DWORD amask,
157 D3DFORMAT expected_format)
185 memset(&dds, 0, sizeof(dds));
187 dds.magic = MAKEFOURCC('D','D','S',' ');
189 dds.flags = DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT;
192 dds.pixel_format.size = sizeof(dds.pixel_format);
193 dds.pixel_format.flags = flags;
194 dds.pixel_format.fourcc = fourcc;
195 dds.pixel_format.bpp = bpp;
196 dds.pixel_format.rmask = rmask;
197 dds.pixel_format.gmask = gmask;
198 dds.pixel_format.bmask = bmask;
199 dds.pixel_format.amask = amask;
200 dds.caps = DDS_CAPS_TEXTURE;
202 hr = D3DXGetImageInfoFromFileInMemory(&dds, sizeof(dds), &info);
203 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x for pixel format %#x, expected %#x\n", hr, expected_format, D3D_OK);
205 ok(info.Format == expected_format, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n", info.Format, expected_format);
208 static void test_D3DXGetImageInfo(void)
212 BOOL testdummy_ok, testbitmap_ok;
214 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
215 testdummy_ok = SUCCEEDED(hr);
217 hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01)); /* valid image */
218 testbitmap_ok = SUCCEEDED(hr);
220 /* D3DXGetImageInfoFromFile */
222 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", &info);
223 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
225 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL); /* valid image, second parameter is NULL */
226 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
227 } else skip("Couldn't create \"testbitmap.bmp\"\n");
230 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", NULL); /* invalid image, second parameter is NULL */
231 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
233 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", &info);
234 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
235 } else skip("Couldn't create \"testdummy.bmp\"\n");
237 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info);
238 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
240 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL);
241 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
243 hr = D3DXGetImageInfoFromFileA("", &info);
244 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
246 hr = D3DXGetImageInfoFromFileA(NULL, &info);
247 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
249 hr = D3DXGetImageInfoFromFileA(NULL, NULL);
250 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
253 /* D3DXGetImageInfoFromResource */
255 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &info); /* RT_BITMAP */
256 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
258 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL);
259 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
262 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &info); /* RT_RCDATA */
263 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
265 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), &info);
266 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
268 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), NULL);
269 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
271 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", &info);
272 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
274 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", NULL);
275 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
277 hr = D3DXGetImageInfoFromResourceA(NULL, NULL, NULL);
278 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
281 /* D3DXGetImageInfoFromFileInMemory */
282 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01), &info);
283 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
285 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01)+5, &info); /* too large size */
286 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
288 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01), NULL);
289 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
291 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), NULL);
292 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
294 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), &info);
295 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
298 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01)-1, &info);
299 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
302 hr = D3DXGetImageInfoFromFileInMemory(bmp01+1, sizeof(bmp01)-1, &info);
303 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
305 hr = D3DXGetImageInfoFromFileInMemory(bmp01, 0, &info);
306 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
308 hr = D3DXGetImageInfoFromFileInMemory(bmp01, 0, NULL);
309 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
311 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, &info);
312 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
314 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, NULL);
315 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
317 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, &info);
318 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
320 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, NULL);
321 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
323 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, &info);
324 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
326 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, NULL);
327 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
330 /* test DDS support */
331 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit), &info);
332 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
334 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
335 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
336 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
337 ok(info.MipLevels == 2, "Got miplevels %u, expected 2\n", info.MipLevels);
338 ok(info.Format == D3DFMT_R8G8B8, "Got format %#x, expected %#x\n", info.Format, D3DFMT_R8G8B8);
339 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
340 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
341 } else skip("Couldn't get image info from 24-bit DDS file in memory\n");
343 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit), &info);
344 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
346 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
347 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
348 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
349 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
350 ok(info.Format == D3DFMT_X1R5G5B5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_X1R5G5B5);
351 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
352 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
353 } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
355 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map), &info);
356 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
358 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
359 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
360 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
361 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
362 ok(info.Format == D3DFMT_DXT5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT5);
363 ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
364 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
365 } else skip("Couldn't get image info from cube map in memory\n");
367 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map), &info);
368 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
370 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
371 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
372 ok(info.Depth == 2, "Got depth %u, expected 2\n", info.Depth);
373 ok(info.MipLevels == 3, "Got miplevels %u, expected 3\n", info.MipLevels);
374 ok(info.Format == D3DFMT_DXT3, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT3);
375 ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
376 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
377 } else skip("Couldn't get image info from volume map in memory\n");
379 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0, D3DFMT_DXT1);
380 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0, D3DFMT_DXT2);
381 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0, D3DFMT_DXT3);
382 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0, D3DFMT_DXT4);
383 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0, D3DFMT_DXT5);
384 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8);
385 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8);
386 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0, D3DFMT_UYVY);
387 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0, D3DFMT_YUY2);
388 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5);
389 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5);
390 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4);
391 check_dds_pixel_format(DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2);
392 check_dds_pixel_format(DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff, D3DFMT_A8);
393 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2);
394 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf00, 0x0f0, 0x00f, 0, D3DFMT_X4R4G4B4);
395 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10);
396 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10);
397 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8);
398 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_X8R8G8B8);
399 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_G16R16);
400 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8);
401 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16);
402 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8);
403 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4);
404 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8);
405 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16);
407 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit) - 1, &info);
408 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
410 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit) - 1, &info);
411 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
413 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map) - 1, &info);
414 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
416 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map) - 1, &info);
417 todo_wine ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
421 if(testdummy_ok) DeleteFileA("testdummy.bmp");
422 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
425 #define check_pixel_1bpp(lockrect, x, y, color) \
426 ok(((BYTE*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch] == color, "Got color 0x%02x, expected 0x%02x.\n", \
427 ((BYTE*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch], color)
429 #define check_pixel_2bpp(lockrect, x, y, color) \
430 ok(((WORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 2] == color, "Got color 0x%04x, expected 0x%04x.\n", \
431 ((WORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 2], color)
433 #define check_pixel_4bpp(lockrect, x, y, color) \
434 ok(((DWORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 4] == color, "Got color 0x%08x, expected 0x%08x.\n", \
435 ((DWORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 4], color)
436 static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
439 BOOL testdummy_ok, testbitmap_ok;
440 IDirect3DTexture9 *tex;
441 IDirect3DSurface9 *surf, *newsurf;
443 D3DLOCKED_RECT lockrect;
444 const WORD pixdata_a8r3g3b2[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
445 const WORD pixdata_a1r5g5b5[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
446 const WORD pixdata_r5g6b5[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
447 const WORD pixdata_a8l8[] = { 0xff00, 0x00ff, 0xff30, 0x7f7f };
448 const DWORD pixdata_g16r16[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
449 const DWORD pixdata_a8b8g8r8[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
450 const DWORD pixdata_a2r10g10b10[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
452 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
453 testdummy_ok = SUCCEEDED(hr);
455 hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01)); /* valid image */
456 testbitmap_ok = SUCCEEDED(hr);
458 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
460 skip("Failed to create a surface (%#x)\n", hr);
461 if(testdummy_ok) DeleteFileA("testdummy.bmp");
462 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
466 /* D3DXLoadSurfaceFromFile */
469 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
470 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3D_OK);
473 hr = D3DXLoadSurfaceFromFileA(NULL, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
474 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
475 } else skip("Couldn't create \"testbitmap.bmp\"\n");
478 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testdummy.bmp", NULL, D3DX_DEFAULT, 0, NULL);
479 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
480 } else skip("Couldn't create \"testdummy.bmp\"\n");
482 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
483 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
485 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "", NULL, D3DX_DEFAULT, 0, NULL);
486 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
489 /* D3DXLoadSurfaceFromResource */
491 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
492 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
495 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDD_BITMAPDATA_1x1), NULL, D3DX_DEFAULT, 0, NULL);
496 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
498 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
499 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
501 hr = D3DXLoadSurfaceFromResourceA(NULL, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
502 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
504 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDS_STRING), NULL, D3DX_DEFAULT, 0, NULL);
505 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
508 /* D3DXLoadSurfaceFromFileInMemory */
510 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
511 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
514 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, noimage, sizeof(noimage), NULL, D3DX_DEFAULT, 0, NULL);
515 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
517 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, 0, NULL, D3DX_DEFAULT, 0, NULL);
518 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
520 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
521 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
523 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 8, NULL, D3DX_DEFAULT, 0, NULL);
524 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
526 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
527 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
529 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
530 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
533 /* D3DXLoadSurfaceFromMemory */
534 SetRect(&rect, 0, 0, 2, 2);
536 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
537 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
539 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, 0, NULL, &rect, D3DX_FILTER_NONE, 0);
540 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
542 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, NULL, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
543 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
545 hr = D3DXLoadSurfaceFromMemory(NULL, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
546 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
548 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, NULL, D3DX_DEFAULT, 0);
549 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
551 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_UNKNOWN, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
552 ok(hr == E_FAIL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, E_FAIL);
554 SetRect(&destrect, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
555 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
556 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
558 SetRect(&destrect, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
559 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
560 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
562 SetRect(&destrect, 1, 1, 0, 0); /* left > right, top > bottom */
563 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
564 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
566 SetRect(&destrect, 0, 0, 0, 0); /* left = right, top = bottom */
567 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
568 /* fails when debug version of d3d9 is used */
569 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
571 SetRect(&destrect, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
572 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
573 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
576 /* D3DXLoadSurfaceFromSurface */
577 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newsurf, NULL);
579 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
580 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
582 hr = D3DXLoadSurfaceFromSurface(NULL, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
583 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
585 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0);
586 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
588 check_release((IUnknown*)newsurf, 0);
589 } else skip("Failed to create a second surface\n");
591 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
594 IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
596 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
597 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
599 IDirect3DSurface9_Release(newsurf);
600 IDirect3DTexture9_Release(tex);
601 } else skip("Failed to create texture\n");
603 check_release((IUnknown*)surf, 0);
606 /* test color conversion */
608 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
609 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
611 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
612 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
613 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
614 check_pixel_4bpp(lockrect, 0, 0, 0x57dbffff);
615 check_pixel_4bpp(lockrect, 1, 0, 0x98ffff00);
616 check_pixel_4bpp(lockrect, 0, 1, 0xacdbff55);
617 check_pixel_4bpp(lockrect, 1, 1, 0xc8929255);
618 IDirect3DSurface9_UnlockRect(surf);
620 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
621 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
622 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
623 check_pixel_4bpp(lockrect, 0, 0, 0x008cadad);
624 check_pixel_4bpp(lockrect, 1, 0, 0xff317342);
625 check_pixel_4bpp(lockrect, 0, 1, 0x0008ad10);
626 check_pixel_4bpp(lockrect, 1, 1, 0xff29088c);
627 IDirect3DSurface9_UnlockRect(surf);
629 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
630 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
631 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
632 check_pixel_4bpp(lockrect, 0, 0, 0xff9cdfb5);
633 check_pixel_4bpp(lockrect, 1, 0, 0xff63b26b);
634 check_pixel_4bpp(lockrect, 0, 1, 0xff085d73);
635 check_pixel_4bpp(lockrect, 1, 1, 0xff425d73);
636 IDirect3DSurface9_UnlockRect(surf);
638 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
639 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
640 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
642 check_pixel_4bpp(lockrect, 0, 0, 0xff3f08ff);
644 check_pixel_4bpp(lockrect, 1, 0, 0xff44dcff);
645 check_pixel_4bpp(lockrect, 0, 1, 0xff97e4ff);
646 check_pixel_4bpp(lockrect, 1, 1, 0xfffe9aff);
647 IDirect3DSurface9_UnlockRect(surf);
649 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
650 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
651 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
652 check_pixel_4bpp(lockrect, 0, 0, 0xc3f04c39);
653 check_pixel_4bpp(lockrect, 1, 0, 0x2392e85a);
654 check_pixel_4bpp(lockrect, 0, 1, 0x09fd97b1);
655 check_pixel_4bpp(lockrect, 1, 1, 0x8df62bc3);
656 IDirect3DSurface9_UnlockRect(surf);
658 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
659 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
660 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
661 check_pixel_4bpp(lockrect, 0, 0, 0x555c95bf);
662 check_pixel_4bpp(lockrect, 1, 0, 0x556d663f);
663 check_pixel_4bpp(lockrect, 0, 1, 0xaac385ad);
665 check_pixel_4bpp(lockrect, 1, 1, 0xfffcc575);
667 IDirect3DSurface9_UnlockRect(surf);
669 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
670 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
671 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
672 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
673 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
674 check_pixel_4bpp(lockrect, 0, 0, 0xff000000);
675 check_pixel_4bpp(lockrect, 1, 0, 0x00ffffff);
676 check_pixel_4bpp(lockrect, 0, 1, 0xff303030);
677 check_pixel_4bpp(lockrect, 1, 1, 0x7f7f7f7f);
678 hr = IDirect3DSurface9_UnlockRect(surf);
679 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
681 check_release((IUnknown*)surf, 0);
685 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A1R5G5B5, D3DPOOL_DEFAULT, &surf, NULL);
686 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
688 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
689 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
690 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
691 check_pixel_2bpp(lockrect, 0, 0, 0x6fff);
692 check_pixel_2bpp(lockrect, 1, 0, 0xffe0);
693 check_pixel_2bpp(lockrect, 0, 1, 0xefea);
694 check_pixel_2bpp(lockrect, 1, 1, 0xca4a);
695 IDirect3DSurface9_UnlockRect(surf);
697 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
698 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
699 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
700 check_pixel_2bpp(lockrect, 0, 0, 0x46b5);
701 check_pixel_2bpp(lockrect, 1, 0, 0x99c8);
702 check_pixel_2bpp(lockrect, 0, 1, 0x06a2);
703 check_pixel_2bpp(lockrect, 1, 1, 0x9431);
704 IDirect3DSurface9_UnlockRect(surf);
706 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
707 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
708 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
709 check_pixel_2bpp(lockrect, 0, 0, 0xcf76);
710 check_pixel_2bpp(lockrect, 1, 0, 0xb2cd);
711 check_pixel_2bpp(lockrect, 0, 1, 0x856e);
712 check_pixel_2bpp(lockrect, 1, 1, 0xa16e);
713 IDirect3DSurface9_UnlockRect(surf);
715 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
716 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
717 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
719 check_pixel_2bpp(lockrect, 0, 0, 0xa03f);
721 check_pixel_2bpp(lockrect, 1, 0, 0xa37f);
722 check_pixel_2bpp(lockrect, 0, 1, 0xcb9f);
723 check_pixel_2bpp(lockrect, 1, 1, 0xfe7f);
724 IDirect3DSurface9_UnlockRect(surf);
726 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
727 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
728 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
730 check_pixel_2bpp(lockrect, 0, 0, 0xf527);
731 check_pixel_2bpp(lockrect, 1, 0, 0x4b8b);
733 check_pixel_2bpp(lockrect, 0, 1, 0x7e56);
734 check_pixel_2bpp(lockrect, 1, 1, 0xf8b8);
735 IDirect3DSurface9_UnlockRect(surf);
737 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
738 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
739 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
740 check_pixel_2bpp(lockrect, 0, 0, 0x2e57);
742 check_pixel_2bpp(lockrect, 1, 0, 0x3588);
744 check_pixel_2bpp(lockrect, 0, 1, 0xe215);
745 check_pixel_2bpp(lockrect, 1, 1, 0xff0e);
746 IDirect3DSurface9_UnlockRect(surf);
748 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
749 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
750 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
751 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
752 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
753 check_pixel_2bpp(lockrect, 0, 0, 0x8000);
754 check_pixel_2bpp(lockrect, 1, 0, 0x7fff);
755 check_pixel_2bpp(lockrect, 0, 1, 0x98c6);
756 check_pixel_2bpp(lockrect, 1, 1, 0x3def);
757 hr = IDirect3DSurface9_UnlockRect(surf);
758 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
760 check_release((IUnknown*)surf, 0);
764 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8L8, D3DPOOL_DEFAULT, &surf, NULL);
766 skip("Failed to create A8L8 surface, hr %#x.\n", hr);
769 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
770 D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
771 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
772 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
773 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
774 check_pixel_2bpp(lockrect, 0, 0, 0x57f7);
775 check_pixel_2bpp(lockrect, 1, 0, 0x98ed);
776 check_pixel_2bpp(lockrect, 0, 1, 0xaceb);
777 check_pixel_2bpp(lockrect, 1, 1, 0xc88d);
778 hr = IDirect3DSurface9_UnlockRect(surf);
779 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
781 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
782 D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
783 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
784 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
785 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
786 check_pixel_2bpp(lockrect, 0, 0, 0x00a6);
787 check_pixel_2bpp(lockrect, 1, 0, 0xff62);
788 check_pixel_2bpp(lockrect, 0, 1, 0x007f);
789 check_pixel_2bpp(lockrect, 1, 1, 0xff19);
790 hr = IDirect3DSurface9_UnlockRect(surf);
791 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
793 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
794 D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
795 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
796 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
797 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
798 check_pixel_2bpp(lockrect, 0, 0, 0xffce);
799 check_pixel_2bpp(lockrect, 1, 0, 0xff9c);
800 check_pixel_2bpp(lockrect, 0, 1, 0xff4d);
801 check_pixel_2bpp(lockrect, 1, 1, 0xff59);
802 hr = IDirect3DSurface9_UnlockRect(surf);
803 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
805 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
806 D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
807 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
808 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
809 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
810 check_pixel_2bpp(lockrect, 0, 0, 0xff25);
811 check_pixel_2bpp(lockrect, 1, 0, 0xffbe);
812 check_pixel_2bpp(lockrect, 0, 1, 0xffd6);
813 check_pixel_2bpp(lockrect, 1, 1, 0xffb6);
814 hr = IDirect3DSurface9_UnlockRect(surf);
815 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
817 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
818 D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
819 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
820 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
821 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
822 check_pixel_2bpp(lockrect, 0, 0, 0xc36d);
823 check_pixel_2bpp(lockrect, 1, 0, 0x23cb);
824 check_pixel_2bpp(lockrect, 0, 1, 0x09af);
825 check_pixel_2bpp(lockrect, 1, 1, 0x8d61);
826 hr = IDirect3DSurface9_UnlockRect(surf);
827 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
829 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
830 D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
831 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
832 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
833 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
834 check_pixel_2bpp(lockrect, 0, 0, 0x558c);
835 check_pixel_2bpp(lockrect, 1, 0, 0x5565);
836 check_pixel_2bpp(lockrect, 0, 1, 0xaa95);
837 check_pixel_2bpp(lockrect, 1, 1, 0xffcb);
838 hr = IDirect3DSurface9_UnlockRect(surf);
839 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
841 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
842 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
843 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
844 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
845 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
846 check_pixel_2bpp(lockrect, 0, 0, 0xff00);
847 check_pixel_2bpp(lockrect, 1, 0, 0x00ff);
848 check_pixel_2bpp(lockrect, 0, 1, 0xff30);
849 check_pixel_2bpp(lockrect, 1, 1, 0x7f7f);
850 hr = IDirect3DSurface9_UnlockRect(surf);
851 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
853 check_release((IUnknown*)surf, 0);
856 /* DXT1, DXT2, DXT3, DXT4, DXT5 */
857 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf, NULL);
859 skip("Failed to create R8G8B8 surface, hr %#x.\n", hr);
862 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, dds_24bit, sizeof(dds_24bit), NULL, D3DX_FILTER_NONE, 0, NULL);
863 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
865 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT2, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
867 skip("Failed to create DXT2 surface, hr %#x.\n", hr);
870 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
871 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT2 format.\n");
872 check_release((IUnknown*)newsurf, 0);
875 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT3, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
877 skip("Failed to create DXT3 surface, hr %#x.\n", hr);
880 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
881 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT3 format.\n");
882 check_release((IUnknown*)newsurf, 0);
885 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT4, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
887 skip("Failed to create DXT4 surface, hr %#x.\n", hr);
890 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
891 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT4 format.\n");
892 check_release((IUnknown*)newsurf, 0);
895 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
897 skip("Failed to create DXT5 surface, hr %#x.\n", hr);
900 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
901 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT5 format.\n");
902 check_release((IUnknown*)newsurf, 0);
905 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
907 skip("Failed to create DXT1 surface, hr %#x.\n", hr);
910 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
911 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT1 format.\n");
913 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
914 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels from DXT1 format.\n");
916 check_release((IUnknown*)newsurf, 0);
919 check_release((IUnknown*)surf, 0);
923 if(testdummy_ok) DeleteFileA("testdummy.bmp");
924 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
927 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
930 IDirect3DSurface9 *surface;
932 D3DLOCKED_RECT lock_rect;
933 D3DXIMAGE_INFO image_info;
934 const BYTE pixels[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
935 0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
936 DWORD pitch = sizeof(pixels) / 2;
938 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
940 skip("Couldn't create surface\n");
944 SetRect(&rect, 0, 0, 2, 2);
945 hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, pixels, D3DFMT_R8G8B8, pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
947 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, NULL);
948 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
950 hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.bmp", NULL, D3DX_FILTER_NONE, 0, &image_info);
951 ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
952 if (FAILED(hr)) goto next_tests;
954 ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
955 ok(image_info.Height == 2, "Wrong height %u\n", image_info.Height);
956 ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
957 ok(image_info.ImageFileFormat == D3DXIFF_BMP, "Wrong file format %u\n", image_info.ImageFileFormat);
959 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
960 ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
961 if (FAILED(hr)) goto next_tests;
963 ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
964 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
966 IDirect3DSurface9_UnlockRect(surface);
967 } else skip("Couldn't fill surface\n");
970 hr = D3DXSaveSurfaceToFileA(NULL, D3DXIFF_BMP, surface, NULL, NULL);
971 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
973 /* PPM and TGA are supported, even though MSDN claims they aren't */
975 hr = D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM, surface, NULL, NULL);
976 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
977 hr = D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA, surface, NULL, NULL);
978 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
979 hr = D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS, surface, NULL, NULL);
980 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
983 hr = D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM + 1, surface, NULL, NULL);
984 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
986 SetRect(&rect, 0, 0, 4, 4);
987 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
988 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
989 SetRect(&rect, 2, 0, 1, 4);
990 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
991 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
992 SetRect(&rect, 0, 2, 4, 1);
993 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
994 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
995 SetRect(&rect, -1, -1, 2, 2);
996 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
997 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
998 SetRect(&rect, 0, 0, 0, 0);
999 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1000 /* fails when debug version of d3d9 is used */
1001 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1003 DeleteFileA("saved_surface.bmp");
1004 DeleteFileA("saved_surface.ppm");
1005 DeleteFileA("saved_surface.tga");
1006 DeleteFileA("saved_surface.dds");
1008 IDirect3DSurface9_Release(surface);
1015 IDirect3DDevice9 *device;
1016 D3DPRESENT_PARAMETERS d3dpp;
1019 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1021 skip("Couldn't create application window\n");
1024 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1026 skip("Couldn't create IDirect3D9 object\n");
1031 ZeroMemory(&d3dpp, sizeof(d3dpp));
1032 d3dpp.Windowed = TRUE;
1033 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1034 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1036 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1037 IDirect3D9_Release(d3d);
1042 test_D3DXGetImageInfo();
1043 test_D3DXLoadSurface(device);
1044 test_D3DXSaveSurfaceToFile(device);
1046 check_release((IUnknown*)device, 0);
1047 check_release((IUnknown*)d3d, 0);