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
23 #include "wine/test.h"
25 #include "resources.h"
27 static inline int get_ref(IUnknown *obj)
30 return IUnknown_Release(obj);
33 static inline void check_ref(IUnknown *obj, int exp)
35 int ref = get_ref(obj);
36 ok (exp == ref, "Invalid refcount. Expected %d, got %d\n", exp, ref);
39 static inline void check_release(IUnknown *obj, int exp)
41 int ref = IUnknown_Release(obj);
42 ok (ref == exp, "Invalid refcount. Expected %d, got %d\n", exp, ref);
46 static const unsigned char bmp01[66] = {
47 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
48 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
49 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
50 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
54 /* 2x2 A8R8G8B8 pixel data */
55 static const unsigned char pixdata[] = {
56 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
59 /* invalid image file */
60 static const unsigned char noimage[4] = {
64 /* 2x2 24-bit dds, 2 mipmaps */
65 static const unsigned char dds_24bit[] = {
66 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00,
67 0x02,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,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,0x00,0x00,0x00,0x00,
70 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
71 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
72 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
73 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
74 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
77 /* 2x2 16-bit dds, no mipmaps */
78 static const unsigned char dds_16bit[] = {
79 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
80 0x02,0x00,0x00,0x00,0x08,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,0x00,0x00,0x00,0x00,
83 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
84 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,
85 0xe0,0x03,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
86 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
87 0xff,0x7f,0xff,0x7f,0xff,0x7f,0xff,0x7f
90 /* 4x4 cube map dds */
91 static const unsigned char dds_cube_map[] = {
92 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00,
93 0x04,0x00,0x00,0x00,0x10,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,0x00,0x00,0x00,0x00,
96 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
97 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
98 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
99 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
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,
105 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50
108 /* 4x4x2 volume map dds, 2 mipmaps */
109 static const unsigned char dds_volume_map[] = {
110 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
111 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,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,0x00,0x00,0x00,0x00,
114 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
115 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
116 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
117 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
118 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
119 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
120 0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
121 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
124 static HRESULT create_file(const char *filename, const unsigned char *data, const unsigned int size)
129 hfile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
130 if(hfile == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError());
132 if(WriteFile(hfile, data, size, &received, NULL))
139 return D3DERR_INVALIDCALL;
142 /* dds_header.flags */
143 #define DDS_CAPS 0x00000001
144 #define DDS_HEIGHT 0x00000002
145 #define DDS_WIDTH 0x00000004
146 #define DDS_PITCH 0x00000008
147 #define DDS_PIXELFORMAT 0x00001000
148 #define DDS_LINEARSIZE 0x00080000
150 /* dds_header.caps */
151 #define DDS_CAPS_TEXTURE 0x00001000
153 /* dds_pixel_format.flags */
154 #define DDS_PF_ALPHA 0x00000001
155 #define DDS_PF_ALPHA_ONLY 0x00000002
156 #define DDS_PF_FOURCC 0x00000004
157 #define DDS_PF_RGB 0x00000040
158 #define DDS_PF_LUMINANCE 0x00020000
159 #define DDS_PF_BUMPDUDV 0x00080000
161 struct dds_pixel_format
180 DWORD pitch_or_linear_size;
184 struct dds_pixel_format pixel_format;
190 /* fills dds_header with reasonable default values */
191 static void fill_dds_header(struct dds_header *header)
193 memset(header, 0, sizeof(*header));
195 header->magic = MAKEFOURCC('D','D','S',' ');
196 header->size = sizeof(*header);
197 header->flags = DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT;
200 header->pixel_format.size = sizeof(header->pixel_format);
202 header->pixel_format.flags = DDS_PF_RGB;
203 header->pixel_format.fourcc = 0;
204 header->pixel_format.bpp = 32;
205 header->pixel_format.rmask = 0xff0000;
206 header->pixel_format.gmask = 0x00ff00;
207 header->pixel_format.bmask = 0x0000ff;
208 header->pixel_format.amask = 0;
209 header->caps = DDS_CAPS_TEXTURE;
212 static void check_dds_pixel_format(DWORD flags, DWORD fourcc, DWORD bpp,
213 DWORD rmask, DWORD gmask, DWORD bmask, DWORD amask,
214 D3DFORMAT expected_format)
220 struct dds_header header;
224 fill_dds_header(&dds.header);
225 dds.header.pixel_format.flags = flags;
226 dds.header.pixel_format.fourcc = fourcc;
227 dds.header.pixel_format.bpp = bpp;
228 dds.header.pixel_format.rmask = rmask;
229 dds.header.pixel_format.gmask = gmask;
230 dds.header.pixel_format.bmask = bmask;
231 dds.header.pixel_format.amask = amask;
232 memset(dds.data, 0, sizeof(dds.data));
234 hr = D3DXGetImageInfoFromFileInMemory(&dds, sizeof(dds), &info);
235 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x for pixel format %#x, expected %#x\n", hr, expected_format, D3D_OK);
237 ok(info.Format == expected_format, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n", info.Format, expected_format);
240 static void test_dds_header_handling(void)
247 struct dds_header header;
253 struct dds_pixel_format pixel_format;
258 DWORD pixel_data_size;
259 HRESULT expected_result;
261 /* pitch is ignored */
262 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, 0, 4, 4, 0,
263 63 /* pixel data size */, D3DXERR_INVALIDDATA },
264 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 0 /* pitch */,
266 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1 /* pitch */,
268 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 2 /* pitch */,
270 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 3 /* pitch */,
272 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 4 /* pitch */,
274 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 16 /* pitch */,
276 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1024 /* pitch */,
278 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, -1 /* pitch */,
280 /* linear size is ignored */
281 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, 0, 4, 4, 0,
282 7 /* pixel data size */, D3DXERR_INVALIDDATA },
283 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 0 /* linear size */,
285 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 1 /* linear size */,
287 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 2 /* linear size */,
289 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 9 /* linear size */,
291 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 16 /* linear size */,
293 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, -1 /* linear size */,
295 /* integer overflows */
296 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000000, 0x80000000 /* 0x80000000 * 0x80000000 * 4 = 0 */, 0,
298 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x8000100, 0x800100 /* 0x8000100 * 0x800100 * 4 = 262144 */, 0,
299 64, D3DXERR_INVALIDDATA },
300 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
302 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
303 3 /* pixel data size */, D3DXERR_INVALIDDATA }
306 memset(&dds, 0, sizeof(dds));
308 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
310 DWORD file_size = sizeof(dds.header) + tests[i].pixel_data_size;
311 assert(file_size <= sizeof(dds));
313 fill_dds_header(&dds.header);
314 dds.header.flags |= tests[i].flags;
315 dds.header.width = tests[i].width;
316 dds.header.height = tests[i].height;
317 dds.header.pitch_or_linear_size = tests[i].pitch;
318 memcpy(&dds.header.pixel_format, &tests[i].pixel_format, sizeof(struct dds_pixel_format));
320 hr = D3DXGetImageInfoFromFileInMemory(&dds, file_size, &info);
321 ok(hr == tests[i].expected_result, "%d: D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", i, hr, tests[i].expected_result);
325 static void test_D3DXGetImageInfo(void)
329 BOOL testdummy_ok, testbitmap_ok;
331 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
332 testdummy_ok = SUCCEEDED(hr);
334 hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01)); /* valid image */
335 testbitmap_ok = SUCCEEDED(hr);
337 /* D3DXGetImageInfoFromFile */
339 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", &info);
340 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
342 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL); /* valid image, second parameter is NULL */
343 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
344 } else skip("Couldn't create \"testbitmap.bmp\"\n");
347 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", NULL); /* invalid image, second parameter is NULL */
348 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
350 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", &info);
351 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
352 } else skip("Couldn't create \"testdummy.bmp\"\n");
354 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info);
355 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
357 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL);
358 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
360 hr = D3DXGetImageInfoFromFileA("", &info);
361 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
363 hr = D3DXGetImageInfoFromFileA(NULL, &info);
364 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
366 hr = D3DXGetImageInfoFromFileA(NULL, NULL);
367 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
370 /* D3DXGetImageInfoFromResource */
372 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &info); /* RT_BITMAP */
373 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
375 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL);
376 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
379 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &info); /* RT_RCDATA */
380 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
382 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), &info);
383 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
385 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), NULL);
386 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
388 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", &info);
389 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
391 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", NULL);
392 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
394 hr = D3DXGetImageInfoFromResourceA(NULL, NULL, NULL);
395 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
398 /* D3DXGetImageInfoFromFileInMemory */
399 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01), &info);
400 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
402 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01)+5, &info); /* too large size */
403 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
405 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01), NULL);
406 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
408 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), NULL);
409 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
411 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), &info);
412 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
415 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01)-1, &info);
416 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
419 hr = D3DXGetImageInfoFromFileInMemory(bmp01+1, sizeof(bmp01)-1, &info);
420 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
422 hr = D3DXGetImageInfoFromFileInMemory(bmp01, 0, &info);
423 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
425 hr = D3DXGetImageInfoFromFileInMemory(bmp01, 0, NULL);
426 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
428 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, &info);
429 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
431 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, NULL);
432 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
434 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, &info);
435 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
437 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, NULL);
438 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
440 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, &info);
441 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
443 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, NULL);
444 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
447 /* test DDS support */
448 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit), &info);
449 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
451 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
452 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
453 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
454 ok(info.MipLevels == 2, "Got miplevels %u, expected 2\n", info.MipLevels);
455 ok(info.Format == D3DFMT_R8G8B8, "Got format %#x, expected %#x\n", info.Format, D3DFMT_R8G8B8);
456 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
457 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
458 } else skip("Couldn't get image info from 24-bit DDS file in memory\n");
460 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit), &info);
461 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
463 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
464 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
465 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
466 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
467 ok(info.Format == D3DFMT_X1R5G5B5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_X1R5G5B5);
468 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
469 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
470 } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
472 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map), &info);
473 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
475 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
476 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
477 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
478 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
479 ok(info.Format == D3DFMT_DXT5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT5);
480 ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
481 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
482 } else skip("Couldn't get image info from cube map in memory\n");
484 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map), &info);
485 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
487 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
488 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
489 ok(info.Depth == 2, "Got depth %u, expected 2\n", info.Depth);
490 ok(info.MipLevels == 3, "Got miplevels %u, expected 3\n", info.MipLevels);
491 ok(info.Format == D3DFMT_DXT3, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT3);
492 ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
493 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
494 } else skip("Couldn't get image info from volume map in memory\n");
496 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0, D3DFMT_DXT1);
497 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0, D3DFMT_DXT2);
498 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0, D3DFMT_DXT3);
499 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0, D3DFMT_DXT4);
500 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0, D3DFMT_DXT5);
501 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8);
502 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8);
503 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0, D3DFMT_UYVY);
504 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0, D3DFMT_YUY2);
505 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5);
506 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5);
507 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4);
508 check_dds_pixel_format(DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2);
509 check_dds_pixel_format(DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff, D3DFMT_A8);
510 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2);
511 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf00, 0x0f0, 0x00f, 0, D3DFMT_X4R4G4B4);
512 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10);
513 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10);
514 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8);
515 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_X8R8G8B8);
516 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_G16R16);
517 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8);
518 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16);
519 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8);
520 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4);
521 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8);
522 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16);
524 test_dds_header_handling();
526 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit) - 1, &info);
527 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
529 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit) - 1, &info);
530 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
532 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map) - 1, &info);
533 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
535 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map) - 1, &info);
536 todo_wine ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
540 if(testdummy_ok) DeleteFileA("testdummy.bmp");
541 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
544 #define check_pixel_1bpp(lockrect, x, y, color) \
545 ok(((BYTE*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch] == color, "Got color 0x%02x, expected 0x%02x.\n", \
546 ((BYTE*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch], color)
548 #define check_pixel_2bpp(lockrect, x, y, color) \
549 ok(((WORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 2] == color, "Got color 0x%04x, expected 0x%04x.\n", \
550 ((WORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 2], color)
552 #define check_pixel_4bpp(lockrect, x, y, color) \
553 ok(((DWORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 4] == color, "Got color 0x%08x, expected 0x%08x.\n", \
554 ((DWORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 4], color)
555 static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
558 BOOL testdummy_ok, testbitmap_ok;
559 IDirect3DTexture9 *tex;
560 IDirect3DSurface9 *surf, *newsurf;
562 D3DLOCKED_RECT lockrect;
563 const WORD pixdata_a8r3g3b2[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
564 const WORD pixdata_a1r5g5b5[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
565 const WORD pixdata_r5g6b5[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
566 const WORD pixdata_a8l8[] = { 0xff00, 0x00ff, 0xff30, 0x7f7f };
567 const DWORD pixdata_g16r16[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
568 const DWORD pixdata_a8b8g8r8[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
569 const DWORD pixdata_a2r10g10b10[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
571 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
572 testdummy_ok = SUCCEEDED(hr);
574 hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01)); /* valid image */
575 testbitmap_ok = SUCCEEDED(hr);
577 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
579 skip("Failed to create a surface (%#x)\n", hr);
580 if(testdummy_ok) DeleteFileA("testdummy.bmp");
581 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
585 /* D3DXLoadSurfaceFromFile */
587 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
588 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3D_OK);
590 hr = D3DXLoadSurfaceFromFileA(NULL, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
591 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
592 } else skip("Couldn't create \"testbitmap.bmp\"\n");
595 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testdummy.bmp", NULL, D3DX_DEFAULT, 0, NULL);
596 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
597 } else skip("Couldn't create \"testdummy.bmp\"\n");
599 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
600 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
602 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "", NULL, D3DX_DEFAULT, 0, NULL);
603 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
606 /* D3DXLoadSurfaceFromResource */
608 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
609 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
612 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDD_BITMAPDATA_1x1), NULL, D3DX_DEFAULT, 0, NULL);
613 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
615 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
616 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
618 hr = D3DXLoadSurfaceFromResourceA(NULL, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
619 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
621 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDS_STRING), NULL, D3DX_DEFAULT, 0, NULL);
622 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
625 /* D3DXLoadSurfaceFromFileInMemory */
626 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
627 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
629 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, noimage, sizeof(noimage), NULL, D3DX_DEFAULT, 0, NULL);
630 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
632 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, 0, NULL, D3DX_DEFAULT, 0, NULL);
633 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
635 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
636 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
638 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 8, NULL, D3DX_DEFAULT, 0, NULL);
639 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
641 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
642 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
644 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
645 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
648 /* D3DXLoadSurfaceFromMemory */
649 SetRect(&rect, 0, 0, 2, 2);
651 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
652 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
654 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, 0, NULL, &rect, D3DX_FILTER_NONE, 0);
655 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
657 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, NULL, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
658 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
660 hr = D3DXLoadSurfaceFromMemory(NULL, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
661 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
663 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, NULL, D3DX_DEFAULT, 0);
664 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
666 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_UNKNOWN, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
667 ok(hr == E_FAIL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, E_FAIL);
669 SetRect(&destrect, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
670 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
671 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
673 SetRect(&destrect, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
674 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
675 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
677 SetRect(&destrect, 1, 1, 0, 0); /* left > right, top > bottom */
678 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
679 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
681 SetRect(&destrect, 0, 0, 0, 0); /* left = right, top = bottom */
682 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
683 /* fails when debug version of d3d9 is used */
684 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
686 SetRect(&destrect, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
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);
691 /* D3DXLoadSurfaceFromSurface */
692 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newsurf, NULL);
694 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
695 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
697 hr = D3DXLoadSurfaceFromSurface(NULL, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
698 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
700 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0);
701 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
703 check_release((IUnknown*)newsurf, 0);
704 } else skip("Failed to create a second surface\n");
706 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
709 IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
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);
714 IDirect3DSurface9_Release(newsurf);
715 IDirect3DTexture9_Release(tex);
716 } else skip("Failed to create texture\n");
718 /* non-lockable render target */
719 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &newsurf, NULL);
721 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
722 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
724 IDirect3DSurface9_Release(newsurf);
725 } else skip("Failed to create render target surface\n");
727 /* non-lockable multisampled render target */
728 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &newsurf, NULL);
730 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
731 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
733 IDirect3DSurface9_Release(newsurf);
734 } else skip("Failed to create multisampled render target\n");
736 check_release((IUnknown*)surf, 0);
739 /* test color conversion */
741 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
742 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
744 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
745 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
746 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
747 check_pixel_4bpp(lockrect, 0, 0, 0x57dbffff);
748 check_pixel_4bpp(lockrect, 1, 0, 0x98ffff00);
749 check_pixel_4bpp(lockrect, 0, 1, 0xacdbff55);
750 check_pixel_4bpp(lockrect, 1, 1, 0xc8929255);
751 IDirect3DSurface9_UnlockRect(surf);
753 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
754 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
755 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
756 check_pixel_4bpp(lockrect, 0, 0, 0x008cadad);
757 check_pixel_4bpp(lockrect, 1, 0, 0xff317342);
758 check_pixel_4bpp(lockrect, 0, 1, 0x0008ad10);
759 check_pixel_4bpp(lockrect, 1, 1, 0xff29088c);
760 IDirect3DSurface9_UnlockRect(surf);
762 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
763 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
764 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
765 check_pixel_4bpp(lockrect, 0, 0, 0xff9cdfb5);
766 check_pixel_4bpp(lockrect, 1, 0, 0xff63b26b);
767 check_pixel_4bpp(lockrect, 0, 1, 0xff085d73);
768 check_pixel_4bpp(lockrect, 1, 1, 0xff425d73);
769 IDirect3DSurface9_UnlockRect(surf);
771 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
772 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
773 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
775 check_pixel_4bpp(lockrect, 0, 0, 0xff3f08ff);
777 check_pixel_4bpp(lockrect, 1, 0, 0xff44dcff);
778 check_pixel_4bpp(lockrect, 0, 1, 0xff97e4ff);
779 check_pixel_4bpp(lockrect, 1, 1, 0xfffe9aff);
780 IDirect3DSurface9_UnlockRect(surf);
782 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
783 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
784 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
785 check_pixel_4bpp(lockrect, 0, 0, 0xc3f04c39);
786 check_pixel_4bpp(lockrect, 1, 0, 0x2392e85a);
787 check_pixel_4bpp(lockrect, 0, 1, 0x09fd97b1);
788 check_pixel_4bpp(lockrect, 1, 1, 0x8df62bc3);
789 IDirect3DSurface9_UnlockRect(surf);
791 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
792 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
793 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
794 check_pixel_4bpp(lockrect, 0, 0, 0x555c95bf);
795 check_pixel_4bpp(lockrect, 1, 0, 0x556d663f);
796 check_pixel_4bpp(lockrect, 0, 1, 0xaac385ad);
798 check_pixel_4bpp(lockrect, 1, 1, 0xfffcc575);
800 IDirect3DSurface9_UnlockRect(surf);
802 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
803 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
804 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
805 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
806 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
807 check_pixel_4bpp(lockrect, 0, 0, 0xff000000);
808 check_pixel_4bpp(lockrect, 1, 0, 0x00ffffff);
809 check_pixel_4bpp(lockrect, 0, 1, 0xff303030);
810 check_pixel_4bpp(lockrect, 1, 1, 0x7f7f7f7f);
811 hr = IDirect3DSurface9_UnlockRect(surf);
812 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
814 check_release((IUnknown*)surf, 0);
818 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A1R5G5B5, D3DPOOL_DEFAULT, &surf, NULL);
819 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
821 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
822 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
823 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
824 check_pixel_2bpp(lockrect, 0, 0, 0x6fff);
825 check_pixel_2bpp(lockrect, 1, 0, 0xffe0);
826 check_pixel_2bpp(lockrect, 0, 1, 0xefea);
827 check_pixel_2bpp(lockrect, 1, 1, 0xca4a);
828 IDirect3DSurface9_UnlockRect(surf);
830 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
831 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
832 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
833 check_pixel_2bpp(lockrect, 0, 0, 0x46b5);
834 check_pixel_2bpp(lockrect, 1, 0, 0x99c8);
835 check_pixel_2bpp(lockrect, 0, 1, 0x06a2);
836 check_pixel_2bpp(lockrect, 1, 1, 0x9431);
837 IDirect3DSurface9_UnlockRect(surf);
839 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
840 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
841 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
842 check_pixel_2bpp(lockrect, 0, 0, 0xcf76);
843 check_pixel_2bpp(lockrect, 1, 0, 0xb2cd);
844 check_pixel_2bpp(lockrect, 0, 1, 0x856e);
845 check_pixel_2bpp(lockrect, 1, 1, 0xa16e);
846 IDirect3DSurface9_UnlockRect(surf);
848 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
849 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
850 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
852 check_pixel_2bpp(lockrect, 0, 0, 0xa03f);
854 check_pixel_2bpp(lockrect, 1, 0, 0xa37f);
855 check_pixel_2bpp(lockrect, 0, 1, 0xcb9f);
856 check_pixel_2bpp(lockrect, 1, 1, 0xfe7f);
857 IDirect3DSurface9_UnlockRect(surf);
859 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
860 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
861 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
863 check_pixel_2bpp(lockrect, 0, 0, 0xf527);
864 check_pixel_2bpp(lockrect, 1, 0, 0x4b8b);
866 check_pixel_2bpp(lockrect, 0, 1, 0x7e56);
867 check_pixel_2bpp(lockrect, 1, 1, 0xf8b8);
868 IDirect3DSurface9_UnlockRect(surf);
870 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
871 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
872 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
873 check_pixel_2bpp(lockrect, 0, 0, 0x2e57);
875 check_pixel_2bpp(lockrect, 1, 0, 0x3588);
877 check_pixel_2bpp(lockrect, 0, 1, 0xe215);
878 check_pixel_2bpp(lockrect, 1, 1, 0xff0e);
879 IDirect3DSurface9_UnlockRect(surf);
881 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
882 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
883 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
884 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
885 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
886 check_pixel_2bpp(lockrect, 0, 0, 0x8000);
887 check_pixel_2bpp(lockrect, 1, 0, 0x7fff);
888 check_pixel_2bpp(lockrect, 0, 1, 0x98c6);
889 check_pixel_2bpp(lockrect, 1, 1, 0x3def);
890 hr = IDirect3DSurface9_UnlockRect(surf);
891 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
893 check_release((IUnknown*)surf, 0);
897 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8L8, D3DPOOL_DEFAULT, &surf, NULL);
899 skip("Failed to create A8L8 surface, hr %#x.\n", hr);
902 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
903 D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
904 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
905 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
906 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
907 check_pixel_2bpp(lockrect, 0, 0, 0x57f7);
908 check_pixel_2bpp(lockrect, 1, 0, 0x98ed);
909 check_pixel_2bpp(lockrect, 0, 1, 0xaceb);
910 check_pixel_2bpp(lockrect, 1, 1, 0xc88d);
911 hr = IDirect3DSurface9_UnlockRect(surf);
912 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
914 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
915 D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
916 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
917 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
918 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
919 check_pixel_2bpp(lockrect, 0, 0, 0x00a6);
920 check_pixel_2bpp(lockrect, 1, 0, 0xff62);
921 check_pixel_2bpp(lockrect, 0, 1, 0x007f);
922 check_pixel_2bpp(lockrect, 1, 1, 0xff19);
923 hr = IDirect3DSurface9_UnlockRect(surf);
924 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
926 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
927 D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
928 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
929 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
930 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
931 check_pixel_2bpp(lockrect, 0, 0, 0xffce);
932 check_pixel_2bpp(lockrect, 1, 0, 0xff9c);
933 check_pixel_2bpp(lockrect, 0, 1, 0xff4d);
934 check_pixel_2bpp(lockrect, 1, 1, 0xff59);
935 hr = IDirect3DSurface9_UnlockRect(surf);
936 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
938 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
939 D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
940 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
941 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
942 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
943 check_pixel_2bpp(lockrect, 0, 0, 0xff25);
944 check_pixel_2bpp(lockrect, 1, 0, 0xffbe);
945 check_pixel_2bpp(lockrect, 0, 1, 0xffd6);
946 check_pixel_2bpp(lockrect, 1, 1, 0xffb6);
947 hr = IDirect3DSurface9_UnlockRect(surf);
948 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
950 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
951 D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
952 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
953 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
954 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
955 check_pixel_2bpp(lockrect, 0, 0, 0xc36d);
956 check_pixel_2bpp(lockrect, 1, 0, 0x23cb);
957 check_pixel_2bpp(lockrect, 0, 1, 0x09af);
958 check_pixel_2bpp(lockrect, 1, 1, 0x8d61);
959 hr = IDirect3DSurface9_UnlockRect(surf);
960 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
962 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
963 D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
964 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
965 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
966 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
967 check_pixel_2bpp(lockrect, 0, 0, 0x558c);
968 check_pixel_2bpp(lockrect, 1, 0, 0x5565);
969 check_pixel_2bpp(lockrect, 0, 1, 0xaa95);
970 check_pixel_2bpp(lockrect, 1, 1, 0xffcb);
971 hr = IDirect3DSurface9_UnlockRect(surf);
972 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
974 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
975 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
976 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
977 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
978 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
979 check_pixel_2bpp(lockrect, 0, 0, 0xff00);
980 check_pixel_2bpp(lockrect, 1, 0, 0x00ff);
981 check_pixel_2bpp(lockrect, 0, 1, 0xff30);
982 check_pixel_2bpp(lockrect, 1, 1, 0x7f7f);
983 hr = IDirect3DSurface9_UnlockRect(surf);
984 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
986 check_release((IUnknown*)surf, 0);
989 /* DXT1, DXT2, DXT3, DXT4, DXT5 */
990 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf, NULL);
992 skip("Failed to create R8G8B8 surface, hr %#x.\n", hr);
995 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, dds_24bit, sizeof(dds_24bit), NULL, D3DX_FILTER_NONE, 0, NULL);
996 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
998 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT2, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1000 skip("Failed to create DXT2 surface, hr %#x.\n", hr);
1003 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1004 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT2 format.\n");
1005 check_release((IUnknown*)newsurf, 0);
1008 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT3, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1010 skip("Failed to create DXT3 surface, hr %#x.\n", hr);
1013 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1014 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT3 format.\n");
1015 check_release((IUnknown*)newsurf, 0);
1018 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT4, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1020 skip("Failed to create DXT4 surface, hr %#x.\n", hr);
1023 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1024 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT4 format.\n");
1025 check_release((IUnknown*)newsurf, 0);
1028 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1030 skip("Failed to create DXT5 surface, hr %#x.\n", hr);
1033 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1034 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT5 format.\n");
1035 check_release((IUnknown*)newsurf, 0);
1038 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1040 skip("Failed to create DXT1 surface, hr %#x.\n", hr);
1043 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1044 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT1 format.\n");
1046 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
1047 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels from DXT1 format.\n");
1049 check_release((IUnknown*)newsurf, 0);
1052 check_release((IUnknown*)surf, 0);
1056 if(testdummy_ok) DeleteFileA("testdummy.bmp");
1057 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
1060 static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9 *device)
1064 ID3DXBuffer *buffer;
1065 IDirect3DSurface9 *surface;
1067 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1069 skip("Couldn't create surface\n");
1073 SetRect(&rect, 0, 0, 0, 0);
1074 hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_BMP, surface, NULL, &rect);
1075 /* fails with the debug version of d3d9 */
1076 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1077 if (SUCCEEDED(hr)) {
1078 DWORD size = ID3DXBuffer_GetBufferSize(buffer);
1079 ok(size > 0, "ID3DXBuffer_GetBufferSize returned %u, expected > 0\n", size);
1080 ID3DXBuffer_Release(buffer);
1083 IDirect3DSurface9_Release(surface);
1086 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
1089 IDirect3DSurface9 *surface;
1091 D3DLOCKED_RECT lock_rect;
1092 D3DXIMAGE_INFO image_info;
1093 const BYTE pixels[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
1094 0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
1095 DWORD pitch = sizeof(pixels) / 2;
1097 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1099 skip("Couldn't create surface\n");
1103 SetRect(&rect, 0, 0, 2, 2);
1104 hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, pixels, D3DFMT_R8G8B8, pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
1105 if (SUCCEEDED(hr)) {
1106 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, NULL);
1107 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1109 hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.bmp", NULL, D3DX_FILTER_NONE, 0, &image_info);
1110 ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
1111 if (FAILED(hr)) goto next_tests;
1113 ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
1114 ok(image_info.Height == 2, "Wrong height %u\n", image_info.Height);
1115 ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
1116 ok(image_info.ImageFileFormat == D3DXIFF_BMP, "Wrong file format %u\n", image_info.ImageFileFormat);
1118 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1119 ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
1120 if (FAILED(hr)) goto next_tests;
1122 ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
1123 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
1125 IDirect3DSurface9_UnlockRect(surface);
1126 } else skip("Couldn't fill surface\n");
1129 hr = D3DXSaveSurfaceToFileA(NULL, D3DXIFF_BMP, surface, NULL, NULL);
1130 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1132 /* PPM and TGA are supported, even though MSDN claims they aren't */
1134 hr = D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM, surface, NULL, NULL);
1135 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1136 hr = D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA, surface, NULL, NULL);
1137 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1138 hr = D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS, surface, NULL, NULL);
1139 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1142 hr = D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM + 1, surface, NULL, NULL);
1143 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1145 SetRect(&rect, 0, 0, 4, 4);
1146 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1147 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1148 SetRect(&rect, 2, 0, 1, 4);
1149 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1150 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1151 SetRect(&rect, 0, 2, 4, 1);
1152 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1153 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1154 SetRect(&rect, -1, -1, 2, 2);
1155 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1156 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1157 SetRect(&rect, 0, 0, 0, 0);
1158 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1159 /* fails when debug version of d3d9 is used */
1160 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1162 DeleteFileA("saved_surface.bmp");
1163 DeleteFileA("saved_surface.ppm");
1164 DeleteFileA("saved_surface.tga");
1165 DeleteFileA("saved_surface.dds");
1167 IDirect3DSurface9_Release(surface);
1174 IDirect3DDevice9 *device;
1175 D3DPRESENT_PARAMETERS d3dpp;
1178 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1180 skip("Couldn't create application window\n");
1183 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1185 skip("Couldn't create IDirect3D9 object\n");
1190 ZeroMemory(&d3dpp, sizeof(d3dpp));
1191 d3dpp.Windowed = TRUE;
1192 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1193 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1195 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1196 IDirect3D9_Release(d3d);
1201 test_D3DXGetImageInfo();
1202 test_D3DXLoadSurface(device);
1203 test_D3DXSaveSurfaceToFileInMemory(device);
1204 test_D3DXSaveSurfaceToFile(device);
1206 check_release((IUnknown*)device, 0);
1207 check_release((IUnknown*)d3d, 0);