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 #define check_ref(obj, exp) _check_ref(__LINE__, obj, exp)
34 static inline void _check_ref(unsigned int line, IUnknown *obj, int exp)
36 int ref = get_ref(obj);
37 ok_(__FILE__, line)(exp == ref, "Invalid refcount. Expected %d, got %d\n", exp, ref);
40 #define check_release(obj, exp) _check_release(__LINE__, obj, exp)
41 static inline void _check_release(unsigned int line, IUnknown *obj, int exp)
43 int ref = IUnknown_Release(obj);
44 ok_(__FILE__, line)(ref == exp, "Invalid refcount. Expected %d, got %d\n", exp, ref);
48 static const unsigned char bmp01[66] = {
49 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
50 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
51 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
52 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
56 /* 2x2 A8R8G8B8 pixel data */
57 static const unsigned char pixdata[] = {
58 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
61 /* invalid image file */
62 static const unsigned char noimage[4] = {
66 /* 2x2 24-bit dds, 2 mipmaps */
67 static const unsigned char dds_24bit[] = {
68 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00,
69 0x02,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
70 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
71 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
72 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
73 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
74 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
75 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
76 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
79 /* 2x2 16-bit dds, no mipmaps */
80 static const unsigned char dds_16bit[] = {
81 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
82 0x02,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
83 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
84 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
85 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
86 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,
87 0xe0,0x03,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
88 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
89 0xff,0x7f,0xff,0x7f,0xff,0x7f,0xff,0x7f
92 /* 4x4 cube map dds */
93 static const unsigned char dds_cube_map[] = {
94 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00,
95 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
96 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
97 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
98 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
99 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
100 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
101 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
102 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
103 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
104 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
105 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
106 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
107 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50
110 /* 4x4x2 volume map dds, 2 mipmaps */
111 static const unsigned char dds_volume_map[] = {
112 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
113 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
114 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
115 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
116 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
117 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
118 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
119 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
120 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
121 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
122 0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
123 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
126 static HRESULT create_file(const char *filename, const unsigned char *data, const unsigned int size)
131 hfile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
132 if(hfile == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError());
134 if(WriteFile(hfile, data, size, &received, NULL))
141 return D3DERR_INVALIDCALL;
144 /* dds_header.flags */
145 #define DDS_CAPS 0x00000001
146 #define DDS_HEIGHT 0x00000002
147 #define DDS_WIDTH 0x00000004
148 #define DDS_PITCH 0x00000008
149 #define DDS_PIXELFORMAT 0x00001000
150 #define DDS_LINEARSIZE 0x00080000
152 /* dds_header.caps */
153 #define DDS_CAPS_TEXTURE 0x00001000
155 /* dds_pixel_format.flags */
156 #define DDS_PF_ALPHA 0x00000001
157 #define DDS_PF_ALPHA_ONLY 0x00000002
158 #define DDS_PF_FOURCC 0x00000004
159 #define DDS_PF_RGB 0x00000040
160 #define DDS_PF_LUMINANCE 0x00020000
161 #define DDS_PF_BUMPDUDV 0x00080000
163 struct dds_pixel_format
182 DWORD pitch_or_linear_size;
186 struct dds_pixel_format pixel_format;
192 /* fills dds_header with reasonable default values */
193 static void fill_dds_header(struct dds_header *header)
195 memset(header, 0, sizeof(*header));
197 header->magic = MAKEFOURCC('D','D','S',' ');
198 header->size = sizeof(*header);
199 header->flags = DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT;
202 header->pixel_format.size = sizeof(header->pixel_format);
204 header->pixel_format.flags = DDS_PF_RGB;
205 header->pixel_format.fourcc = 0;
206 header->pixel_format.bpp = 32;
207 header->pixel_format.rmask = 0xff0000;
208 header->pixel_format.gmask = 0x00ff00;
209 header->pixel_format.bmask = 0x0000ff;
210 header->pixel_format.amask = 0;
211 header->caps = DDS_CAPS_TEXTURE;
214 #define check_dds_pixel_format(flags, fourcc, bpp, rmask, gmask, bmask, amask, format) \
215 check_dds_pixel_format_(__LINE__, flags, fourcc, bpp, rmask, gmask, bmask, amask, format)
216 static void check_dds_pixel_format_(unsigned int line,
217 DWORD flags, DWORD fourcc, DWORD bpp,
218 DWORD rmask, DWORD gmask, DWORD bmask, DWORD amask,
219 D3DFORMAT expected_format)
225 struct dds_header header;
229 fill_dds_header(&dds.header);
230 dds.header.pixel_format.flags = flags;
231 dds.header.pixel_format.fourcc = fourcc;
232 dds.header.pixel_format.bpp = bpp;
233 dds.header.pixel_format.rmask = rmask;
234 dds.header.pixel_format.gmask = gmask;
235 dds.header.pixel_format.bmask = bmask;
236 dds.header.pixel_format.amask = amask;
237 memset(dds.data, 0, sizeof(dds.data));
239 hr = D3DXGetImageInfoFromFileInMemory(&dds, sizeof(dds), &info);
240 ok_(__FILE__, line)(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x for pixel format %#x, expected %#x\n",
241 hr, expected_format, D3D_OK);
244 ok_(__FILE__, line)(info.Format == expected_format, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n",
245 info.Format, expected_format);
249 static void test_dds_header_handling(void)
256 struct dds_header header;
262 struct dds_pixel_format pixel_format;
267 DWORD pixel_data_size;
268 HRESULT expected_result;
270 /* pitch is ignored */
271 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, 0, 4, 4, 0,
272 63 /* pixel data size */, D3DXERR_INVALIDDATA },
273 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 0 /* pitch */,
275 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1 /* pitch */,
277 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 2 /* pitch */,
279 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 3 /* pitch */,
281 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 4 /* pitch */,
283 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 16 /* pitch */,
285 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1024 /* pitch */,
287 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, -1 /* pitch */,
289 /* linear size is ignored */
290 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, 0, 4, 4, 0,
291 7 /* pixel data size */, D3DXERR_INVALIDDATA },
292 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 0 /* linear size */,
294 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 1 /* linear size */,
296 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 2 /* linear size */,
298 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 9 /* linear size */,
300 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 16 /* linear size */,
302 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, -1 /* linear size */,
304 /* integer overflows */
305 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000000, 0x80000000 /* 0x80000000 * 0x80000000 * 4 = 0 */, 0,
307 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x8000100, 0x800100 /* 0x8000100 * 0x800100 * 4 = 262144 */, 0,
308 64, D3DXERR_INVALIDDATA },
309 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
311 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
312 3 /* pixel data size */, D3DXERR_INVALIDDATA }
315 memset(&dds, 0, sizeof(dds));
317 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
319 DWORD file_size = sizeof(dds.header) + tests[i].pixel_data_size;
320 assert(file_size <= sizeof(dds));
322 fill_dds_header(&dds.header);
323 dds.header.flags |= tests[i].flags;
324 dds.header.width = tests[i].width;
325 dds.header.height = tests[i].height;
326 dds.header.pitch_or_linear_size = tests[i].pitch;
327 dds.header.pixel_format = tests[i].pixel_format;
329 hr = D3DXGetImageInfoFromFileInMemory(&dds, file_size, &info);
330 ok(hr == tests[i].expected_result, "%d: D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", i, hr, tests[i].expected_result);
334 static void test_D3DXGetImageInfo(void)
338 BOOL testdummy_ok, testbitmap_ok;
340 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
341 testdummy_ok = SUCCEEDED(hr);
343 hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01)); /* valid image */
344 testbitmap_ok = SUCCEEDED(hr);
346 /* D3DXGetImageInfoFromFile */
348 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", &info);
349 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
351 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL); /* valid image, second parameter is NULL */
352 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
353 } else skip("Couldn't create \"testbitmap.bmp\"\n");
356 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", NULL); /* invalid image, second parameter is NULL */
357 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
359 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", &info);
360 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
361 } else skip("Couldn't create \"testdummy.bmp\"\n");
363 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info);
364 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
366 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL);
367 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
369 hr = D3DXGetImageInfoFromFileA("", &info);
370 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
372 hr = D3DXGetImageInfoFromFileA(NULL, &info);
373 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
375 hr = D3DXGetImageInfoFromFileA(NULL, NULL);
376 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
379 /* D3DXGetImageInfoFromResource */
380 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &info); /* RT_BITMAP */
381 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
383 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL);
384 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
386 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &info); /* RT_RCDATA */
387 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
389 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), &info);
390 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
392 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), NULL);
393 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
395 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", &info);
396 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
398 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", NULL);
399 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
401 hr = D3DXGetImageInfoFromResourceA(NULL, NULL, NULL);
402 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
405 /* D3DXGetImageInfoFromFileInMemory */
406 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01), &info);
407 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
409 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01)+5, &info); /* too large size */
410 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
412 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01), NULL);
413 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
415 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), NULL);
416 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
418 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), &info);
419 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
422 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01)-1, &info);
423 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
426 hr = D3DXGetImageInfoFromFileInMemory(bmp01+1, sizeof(bmp01)-1, &info);
427 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
429 hr = D3DXGetImageInfoFromFileInMemory(bmp01, 0, &info);
430 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
432 hr = D3DXGetImageInfoFromFileInMemory(bmp01, 0, NULL);
433 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
435 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, &info);
436 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
438 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, NULL);
439 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
441 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, &info);
442 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
444 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, NULL);
445 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
447 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, &info);
448 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
450 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, NULL);
451 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
454 /* test DDS support */
455 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit), &info);
456 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
458 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
459 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
460 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
461 ok(info.MipLevels == 2, "Got miplevels %u, expected 2\n", info.MipLevels);
462 ok(info.Format == D3DFMT_R8G8B8, "Got format %#x, expected %#x\n", info.Format, D3DFMT_R8G8B8);
463 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
464 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
465 } else skip("Couldn't get image info from 24-bit DDS file in memory\n");
467 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit), &info);
468 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
470 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
471 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
472 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
473 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
474 ok(info.Format == D3DFMT_X1R5G5B5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_X1R5G5B5);
475 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
476 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
477 } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
479 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map), &info);
480 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
482 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
483 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
484 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
485 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
486 ok(info.Format == D3DFMT_DXT5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT5);
487 ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
488 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
489 } else skip("Couldn't get image info from cube map in memory\n");
491 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map), &info);
492 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
494 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
495 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
496 ok(info.Depth == 2, "Got depth %u, expected 2\n", info.Depth);
497 ok(info.MipLevels == 3, "Got miplevels %u, expected 3\n", info.MipLevels);
498 ok(info.Format == D3DFMT_DXT3, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT3);
499 ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
500 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
501 } else skip("Couldn't get image info from volume map in memory\n");
503 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0, D3DFMT_DXT1);
504 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0, D3DFMT_DXT2);
505 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0, D3DFMT_DXT3);
506 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0, D3DFMT_DXT4);
507 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0, D3DFMT_DXT5);
508 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8);
509 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8);
510 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0, D3DFMT_UYVY);
511 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0, D3DFMT_YUY2);
512 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5);
513 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5);
514 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4);
515 check_dds_pixel_format(DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2);
516 check_dds_pixel_format(DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff, D3DFMT_A8);
517 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2);
518 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf00, 0x0f0, 0x00f, 0, D3DFMT_X4R4G4B4);
519 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10);
520 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10);
521 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8);
522 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, D3DFMT_A8B8G8R8);
523 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_X8R8G8B8);
524 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8B8G8R8);
525 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_G16R16);
526 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8);
527 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16);
528 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8);
529 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4);
530 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8);
531 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16);
533 test_dds_header_handling();
535 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit) - 1, &info);
536 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
538 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit) - 1, &info);
539 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
541 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map) - 1, &info);
542 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
544 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map) - 1, &info);
545 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
549 if(testdummy_ok) DeleteFileA("testdummy.bmp");
550 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
553 #define check_pixel_1bpp(lockrect, x, y, color) _check_pixel_1bpp(__LINE__, lockrect, x, y, color)
554 static inline void _check_pixel_1bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, BYTE expected_color)
556 BYTE color = ((BYTE*)lockrect->pBits)[x + y * lockrect->Pitch];
557 ok_(__FILE__, line)(color == expected_color, "Got color 0x%02x, expected 0x%02x\n", color, expected_color);
560 #define check_pixel_2bpp(lockrect, x, y, color) _check_pixel_2bpp(__LINE__, lockrect, x, y, color)
561 static inline void _check_pixel_2bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, WORD expected_color)
563 WORD color = ((WORD*)lockrect->pBits)[x + y * lockrect->Pitch / 2];
564 ok_(__FILE__, line)(color == expected_color, "Got color 0x%04x, expected 0x%04x\n", color, expected_color);
567 #define check_pixel_4bpp(lockrect, x, y, color) _check_pixel_4bpp(__LINE__, lockrect, x, y, color)
568 static inline void _check_pixel_4bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, DWORD expected_color)
570 DWORD color = ((DWORD*)lockrect->pBits)[x + y * lockrect->Pitch / 4];
571 ok_(__FILE__, line)(color == expected_color, "Got color 0x%08x, expected 0x%08x\n", color, expected_color);
574 static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
577 BOOL testdummy_ok, testbitmap_ok;
578 IDirect3DTexture9 *tex;
579 IDirect3DSurface9 *surf, *newsurf;
581 D3DLOCKED_RECT lockrect;
582 const WORD pixdata_a8r3g3b2[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
583 const WORD pixdata_a1r5g5b5[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
584 const WORD pixdata_r5g6b5[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
585 const WORD pixdata_a8l8[] = { 0xff00, 0x00ff, 0xff30, 0x7f7f };
586 const DWORD pixdata_g16r16[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
587 const DWORD pixdata_a8b8g8r8[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
588 const DWORD pixdata_a2r10g10b10[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
590 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
591 testdummy_ok = SUCCEEDED(hr);
593 hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01)); /* valid image */
594 testbitmap_ok = SUCCEEDED(hr);
596 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
598 skip("Failed to create a surface (%#x)\n", hr);
599 if(testdummy_ok) DeleteFileA("testdummy.bmp");
600 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
604 /* D3DXLoadSurfaceFromFile */
606 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
607 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3D_OK);
609 hr = D3DXLoadSurfaceFromFileA(NULL, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
610 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
611 } else skip("Couldn't create \"testbitmap.bmp\"\n");
614 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testdummy.bmp", NULL, D3DX_DEFAULT, 0, NULL);
615 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
616 } else skip("Couldn't create \"testdummy.bmp\"\n");
618 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
619 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
621 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "", NULL, D3DX_DEFAULT, 0, NULL);
622 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
625 /* D3DXLoadSurfaceFromResource */
627 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
628 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
631 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDD_BITMAPDATA_1x1), NULL, D3DX_DEFAULT, 0, NULL);
632 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
634 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
635 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
637 hr = D3DXLoadSurfaceFromResourceA(NULL, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
638 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
640 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDS_STRING), NULL, D3DX_DEFAULT, 0, NULL);
641 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
644 /* D3DXLoadSurfaceFromFileInMemory */
645 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
646 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
648 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, noimage, sizeof(noimage), NULL, D3DX_DEFAULT, 0, NULL);
649 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
651 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, 0, NULL, D3DX_DEFAULT, 0, NULL);
652 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
654 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
655 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
657 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 8, NULL, D3DX_DEFAULT, 0, NULL);
658 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
660 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
661 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
663 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
664 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
667 /* D3DXLoadSurfaceFromMemory */
668 SetRect(&rect, 0, 0, 2, 2);
670 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
671 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
673 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, 0, NULL, &rect, D3DX_FILTER_NONE, 0);
674 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
676 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, NULL, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
677 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
679 hr = D3DXLoadSurfaceFromMemory(NULL, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
680 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
682 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, NULL, D3DX_DEFAULT, 0);
683 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
685 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_UNKNOWN, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
686 ok(hr == E_FAIL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, E_FAIL);
688 SetRect(&destrect, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
689 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
690 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
692 SetRect(&destrect, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
693 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
694 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
696 SetRect(&destrect, 1, 1, 0, 0); /* left > right, top > bottom */
697 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
698 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
700 SetRect(&destrect, 0, 0, 0, 0); /* left = right, top = bottom */
701 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
702 /* fails when debug version of d3d9 is used */
703 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
705 SetRect(&destrect, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
706 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
707 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
710 /* D3DXLoadSurfaceFromSurface */
711 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newsurf, NULL);
713 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
714 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
716 hr = D3DXLoadSurfaceFromSurface(NULL, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
717 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
719 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0);
720 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
722 check_release((IUnknown*)newsurf, 0);
723 } else skip("Failed to create a second surface\n");
725 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
728 IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
730 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
731 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
733 IDirect3DSurface9_Release(newsurf);
734 IDirect3DTexture9_Release(tex);
735 } else skip("Failed to create texture\n");
737 /* non-lockable render target */
738 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &newsurf, NULL);
740 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
741 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
743 IDirect3DSurface9_Release(newsurf);
744 } else skip("Failed to create render target surface\n");
746 /* non-lockable multisampled render target */
747 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &newsurf, NULL);
749 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
750 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
752 IDirect3DSurface9_Release(newsurf);
753 } else skip("Failed to create multisampled render target\n");
755 check_release((IUnknown*)surf, 0);
758 /* test color conversion */
760 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
761 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
763 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
764 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
765 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
766 check_pixel_4bpp(&lockrect, 0, 0, 0x57dbffff);
767 check_pixel_4bpp(&lockrect, 1, 0, 0x98ffff00);
768 check_pixel_4bpp(&lockrect, 0, 1, 0xacdbff55);
769 check_pixel_4bpp(&lockrect, 1, 1, 0xc8929255);
770 IDirect3DSurface9_UnlockRect(surf);
772 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
773 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
774 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
775 check_pixel_4bpp(&lockrect, 0, 0, 0x008cadad);
776 check_pixel_4bpp(&lockrect, 1, 0, 0xff317342);
777 check_pixel_4bpp(&lockrect, 0, 1, 0x0008ad10);
778 check_pixel_4bpp(&lockrect, 1, 1, 0xff29088c);
779 IDirect3DSurface9_UnlockRect(surf);
781 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
782 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
783 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
784 check_pixel_4bpp(&lockrect, 0, 0, 0xff9cdfb5);
785 check_pixel_4bpp(&lockrect, 1, 0, 0xff63b26b);
786 check_pixel_4bpp(&lockrect, 0, 1, 0xff085d73);
787 check_pixel_4bpp(&lockrect, 1, 1, 0xff425d73);
788 IDirect3DSurface9_UnlockRect(surf);
790 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
791 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
792 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
794 check_pixel_4bpp(&lockrect, 0, 0, 0xff3f08ff);
796 check_pixel_4bpp(&lockrect, 1, 0, 0xff44dcff);
797 check_pixel_4bpp(&lockrect, 0, 1, 0xff97e4ff);
798 check_pixel_4bpp(&lockrect, 1, 1, 0xfffe9aff);
799 IDirect3DSurface9_UnlockRect(surf);
801 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
802 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
803 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
804 check_pixel_4bpp(&lockrect, 0, 0, 0xc3f04c39);
805 check_pixel_4bpp(&lockrect, 1, 0, 0x2392e85a);
806 check_pixel_4bpp(&lockrect, 0, 1, 0x09fd97b1);
807 check_pixel_4bpp(&lockrect, 1, 1, 0x8df62bc3);
808 IDirect3DSurface9_UnlockRect(surf);
810 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
811 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
812 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
813 check_pixel_4bpp(&lockrect, 0, 0, 0x555c95bf);
814 check_pixel_4bpp(&lockrect, 1, 0, 0x556d663f);
815 check_pixel_4bpp(&lockrect, 0, 1, 0xaac385ad);
817 check_pixel_4bpp(&lockrect, 1, 1, 0xfffcc575);
819 IDirect3DSurface9_UnlockRect(surf);
821 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
822 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
823 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
824 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
825 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
826 check_pixel_4bpp(&lockrect, 0, 0, 0xff000000);
827 check_pixel_4bpp(&lockrect, 1, 0, 0x00ffffff);
828 check_pixel_4bpp(&lockrect, 0, 1, 0xff303030);
829 check_pixel_4bpp(&lockrect, 1, 1, 0x7f7f7f7f);
830 hr = IDirect3DSurface9_UnlockRect(surf);
831 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
833 check_release((IUnknown*)surf, 0);
837 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A1R5G5B5, D3DPOOL_DEFAULT, &surf, NULL);
838 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
840 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
841 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
842 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
843 check_pixel_2bpp(&lockrect, 0, 0, 0x6fff);
844 check_pixel_2bpp(&lockrect, 1, 0, 0xffe0);
845 check_pixel_2bpp(&lockrect, 0, 1, 0xefea);
846 check_pixel_2bpp(&lockrect, 1, 1, 0xca4a);
847 IDirect3DSurface9_UnlockRect(surf);
849 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
850 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
851 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
852 check_pixel_2bpp(&lockrect, 0, 0, 0x46b5);
853 check_pixel_2bpp(&lockrect, 1, 0, 0x99c8);
854 check_pixel_2bpp(&lockrect, 0, 1, 0x06a2);
855 check_pixel_2bpp(&lockrect, 1, 1, 0x9431);
856 IDirect3DSurface9_UnlockRect(surf);
858 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
859 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
860 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
861 check_pixel_2bpp(&lockrect, 0, 0, 0xcf76);
862 check_pixel_2bpp(&lockrect, 1, 0, 0xb2cd);
863 check_pixel_2bpp(&lockrect, 0, 1, 0x856e);
864 check_pixel_2bpp(&lockrect, 1, 1, 0xa16e);
865 IDirect3DSurface9_UnlockRect(surf);
867 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
868 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
869 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
871 check_pixel_2bpp(&lockrect, 0, 0, 0xa03f);
873 check_pixel_2bpp(&lockrect, 1, 0, 0xa37f);
874 check_pixel_2bpp(&lockrect, 0, 1, 0xcb9f);
875 check_pixel_2bpp(&lockrect, 1, 1, 0xfe7f);
876 IDirect3DSurface9_UnlockRect(surf);
878 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
879 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
880 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
882 check_pixel_2bpp(&lockrect, 0, 0, 0xf527);
883 check_pixel_2bpp(&lockrect, 1, 0, 0x4b8b);
885 check_pixel_2bpp(&lockrect, 0, 1, 0x7e56);
886 check_pixel_2bpp(&lockrect, 1, 1, 0xf8b8);
887 IDirect3DSurface9_UnlockRect(surf);
889 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
890 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
891 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
892 check_pixel_2bpp(&lockrect, 0, 0, 0x2e57);
894 check_pixel_2bpp(&lockrect, 1, 0, 0x3588);
896 check_pixel_2bpp(&lockrect, 0, 1, 0xe215);
897 check_pixel_2bpp(&lockrect, 1, 1, 0xff0e);
898 IDirect3DSurface9_UnlockRect(surf);
900 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
901 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
902 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
903 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
904 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
905 check_pixel_2bpp(&lockrect, 0, 0, 0x8000);
906 check_pixel_2bpp(&lockrect, 1, 0, 0x7fff);
907 check_pixel_2bpp(&lockrect, 0, 1, 0x98c6);
908 check_pixel_2bpp(&lockrect, 1, 1, 0x3def);
909 hr = IDirect3DSurface9_UnlockRect(surf);
910 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
912 check_release((IUnknown*)surf, 0);
916 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8L8, D3DPOOL_DEFAULT, &surf, NULL);
918 skip("Failed to create A8L8 surface, hr %#x.\n", hr);
921 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
922 D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
923 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
924 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
925 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
926 check_pixel_2bpp(&lockrect, 0, 0, 0x57f7);
927 check_pixel_2bpp(&lockrect, 1, 0, 0x98ed);
928 check_pixel_2bpp(&lockrect, 0, 1, 0xaceb);
929 check_pixel_2bpp(&lockrect, 1, 1, 0xc88d);
930 hr = IDirect3DSurface9_UnlockRect(surf);
931 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
933 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
934 D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
935 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
936 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
937 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
938 check_pixel_2bpp(&lockrect, 0, 0, 0x00a6);
939 check_pixel_2bpp(&lockrect, 1, 0, 0xff62);
940 check_pixel_2bpp(&lockrect, 0, 1, 0x007f);
941 check_pixel_2bpp(&lockrect, 1, 1, 0xff19);
942 hr = IDirect3DSurface9_UnlockRect(surf);
943 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
945 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
946 D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
947 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
948 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
949 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
950 check_pixel_2bpp(&lockrect, 0, 0, 0xffce);
951 check_pixel_2bpp(&lockrect, 1, 0, 0xff9c);
952 check_pixel_2bpp(&lockrect, 0, 1, 0xff4d);
953 check_pixel_2bpp(&lockrect, 1, 1, 0xff59);
954 hr = IDirect3DSurface9_UnlockRect(surf);
955 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
957 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
958 D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
959 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
960 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
961 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
962 check_pixel_2bpp(&lockrect, 0, 0, 0xff25);
963 check_pixel_2bpp(&lockrect, 1, 0, 0xffbe);
964 check_pixel_2bpp(&lockrect, 0, 1, 0xffd6);
965 check_pixel_2bpp(&lockrect, 1, 1, 0xffb6);
966 hr = IDirect3DSurface9_UnlockRect(surf);
967 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
969 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
970 D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
971 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
972 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
973 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
974 check_pixel_2bpp(&lockrect, 0, 0, 0xc36d);
975 check_pixel_2bpp(&lockrect, 1, 0, 0x23cb);
976 check_pixel_2bpp(&lockrect, 0, 1, 0x09af);
977 check_pixel_2bpp(&lockrect, 1, 1, 0x8d61);
978 hr = IDirect3DSurface9_UnlockRect(surf);
979 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
981 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
982 D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
983 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
984 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
985 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
986 check_pixel_2bpp(&lockrect, 0, 0, 0x558c);
987 check_pixel_2bpp(&lockrect, 1, 0, 0x5565);
988 check_pixel_2bpp(&lockrect, 0, 1, 0xaa95);
989 check_pixel_2bpp(&lockrect, 1, 1, 0xffcb);
990 hr = IDirect3DSurface9_UnlockRect(surf);
991 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
993 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
994 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
995 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
996 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
997 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
998 check_pixel_2bpp(&lockrect, 0, 0, 0xff00);
999 check_pixel_2bpp(&lockrect, 1, 0, 0x00ff);
1000 check_pixel_2bpp(&lockrect, 0, 1, 0xff30);
1001 check_pixel_2bpp(&lockrect, 1, 1, 0x7f7f);
1002 hr = IDirect3DSurface9_UnlockRect(surf);
1003 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1005 check_release((IUnknown*)surf, 0);
1008 /* DXT1, DXT2, DXT3, DXT4, DXT5 */
1009 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf, NULL);
1011 skip("Failed to create R8G8B8 surface, hr %#x.\n", hr);
1014 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, dds_24bit, sizeof(dds_24bit), NULL, D3DX_FILTER_NONE, 0, NULL);
1015 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1017 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT2, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1019 skip("Failed to create DXT2 surface, hr %#x.\n", hr);
1022 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1023 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT2 format.\n");
1024 check_release((IUnknown*)newsurf, 0);
1027 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT3, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1029 skip("Failed to create DXT3 surface, hr %#x.\n", hr);
1032 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1033 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT3 format.\n");
1034 check_release((IUnknown*)newsurf, 0);
1037 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT4, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1039 skip("Failed to create DXT4 surface, hr %#x.\n", hr);
1042 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1043 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT4 format.\n");
1044 check_release((IUnknown*)newsurf, 0);
1047 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1049 skip("Failed to create DXT5 surface, hr %#x.\n", hr);
1052 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1053 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT5 format.\n");
1054 check_release((IUnknown*)newsurf, 0);
1057 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1059 skip("Failed to create DXT1 surface, hr %#x.\n", hr);
1062 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1063 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT1 format.\n");
1065 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
1066 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels from DXT1 format.\n");
1068 check_release((IUnknown*)newsurf, 0);
1071 check_release((IUnknown*)surf, 0);
1075 if(testdummy_ok) DeleteFileA("testdummy.bmp");
1076 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
1079 static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9 *device)
1083 ID3DXBuffer *buffer;
1084 IDirect3DSurface9 *surface;
1086 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1088 skip("Couldn't create surface\n");
1092 SetRect(&rect, 0, 0, 0, 0);
1093 hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_BMP, surface, NULL, &rect);
1094 /* fails with the debug version of d3d9 */
1095 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1096 if (SUCCEEDED(hr)) {
1097 DWORD size = ID3DXBuffer_GetBufferSize(buffer);
1098 ok(size > 0, "ID3DXBuffer_GetBufferSize returned %u, expected > 0\n", size);
1099 ID3DXBuffer_Release(buffer);
1102 IDirect3DSurface9_Release(surface);
1105 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
1108 IDirect3DSurface9 *surface;
1110 D3DLOCKED_RECT lock_rect;
1111 D3DXIMAGE_INFO image_info;
1112 const BYTE pixels[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
1113 0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
1114 DWORD pitch = sizeof(pixels) / 2;
1116 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1118 skip("Couldn't create surface\n");
1122 SetRect(&rect, 0, 0, 2, 2);
1123 hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, pixels, D3DFMT_R8G8B8, pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
1124 if (SUCCEEDED(hr)) {
1125 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, NULL);
1126 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1128 hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.bmp", NULL, D3DX_FILTER_NONE, 0, &image_info);
1129 ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
1130 if (FAILED(hr)) goto next_tests;
1132 ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
1133 ok(image_info.Height == 2, "Wrong height %u\n", image_info.Height);
1134 ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
1135 ok(image_info.ImageFileFormat == D3DXIFF_BMP, "Wrong file format %u\n", image_info.ImageFileFormat);
1137 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1138 ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
1139 if (FAILED(hr)) goto next_tests;
1141 ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
1142 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
1144 IDirect3DSurface9_UnlockRect(surface);
1145 } else skip("Couldn't fill surface\n");
1148 hr = D3DXSaveSurfaceToFileA(NULL, D3DXIFF_BMP, surface, NULL, NULL);
1149 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1151 /* PPM and TGA are supported, even though MSDN claims they aren't */
1153 hr = D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM, surface, NULL, NULL);
1154 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1155 hr = D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA, surface, NULL, NULL);
1156 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1159 hr = D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS, surface, NULL, NULL);
1160 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1161 if (SUCCEEDED(hr)) {
1162 hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.dds", NULL, D3DX_FILTER_NONE, 0, &image_info);
1163 ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
1165 if (SUCCEEDED(hr)) {
1166 ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
1167 ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
1168 ok(image_info.ImageFileFormat == D3DXIFF_DDS, "Wrong file format %u\n", image_info.ImageFileFormat);
1170 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1171 ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
1172 if (SUCCEEDED(hr)) {
1173 ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
1174 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
1175 IDirect3DSurface9_UnlockRect(surface);
1178 } else skip("Couldn't save surface\n");
1180 hr = D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM + 1, surface, NULL, NULL);
1181 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1183 SetRect(&rect, 0, 0, 4, 4);
1184 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1185 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1186 SetRect(&rect, 2, 0, 1, 4);
1187 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1188 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1189 SetRect(&rect, 0, 2, 4, 1);
1190 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1191 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1192 SetRect(&rect, -1, -1, 2, 2);
1193 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1194 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1195 SetRect(&rect, 0, 0, 0, 0);
1196 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1197 /* fails when debug version of d3d9 is used */
1198 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1200 DeleteFileA("saved_surface.bmp");
1201 DeleteFileA("saved_surface.ppm");
1202 DeleteFileA("saved_surface.tga");
1203 DeleteFileA("saved_surface.dds");
1205 IDirect3DSurface9_Release(surface);
1212 IDirect3DDevice9 *device;
1213 D3DPRESENT_PARAMETERS d3dpp;
1216 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1218 skip("Couldn't create application window\n");
1221 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1223 skip("Couldn't create IDirect3D9 object\n");
1228 ZeroMemory(&d3dpp, sizeof(d3dpp));
1229 d3dpp.Windowed = TRUE;
1230 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1231 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
1233 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1234 IDirect3D9_Release(d3d);
1239 test_D3DXGetImageInfo();
1240 test_D3DXLoadSurface(device);
1241 test_D3DXSaveSurfaceToFileInMemory(device);
1242 test_D3DXSaveSurfaceToFile(device);
1244 check_release((IUnknown*)device, 0);
1245 check_release((IUnknown*)d3d, 0);