d3dx9/tests: Use inline functions instead of check_pixel_{1bpp, 2bpp, 4bpp} macros.
[wine/multimedia.git] / dlls / d3dx9_36 / tests / surface.c
blob64bb7a393333e9951885e2c5dcd81b915992c7cb
1 /*
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
21 #define COBJMACROS
22 #include <assert.h>
23 #include "wine/test.h"
24 #include "d3dx9tex.h"
25 #include "resources.h"
27 static inline int get_ref(IUnknown *obj)
29 IUnknown_AddRef(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);
47 /* 1x1 bmp (1 bpp) */
48 static const unsigned char bmp01[66] = {
49 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
50 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
51 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
52 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
53 0x00,0x00
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] = {
63 0x11,0x22,0x33,0x44
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)
128 DWORD received;
129 HANDLE hfile;
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))
136 CloseHandle(hfile);
137 return D3D_OK;
140 CloseHandle(hfile);
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
165 DWORD size;
166 DWORD flags;
167 DWORD fourcc;
168 DWORD bpp;
169 DWORD rmask;
170 DWORD gmask;
171 DWORD bmask;
172 DWORD amask;
175 struct dds_header
177 DWORD magic;
178 DWORD size;
179 DWORD flags;
180 DWORD height;
181 DWORD width;
182 DWORD pitch_or_linear_size;
183 DWORD depth;
184 DWORD miplevels;
185 DWORD reserved[11];
186 struct dds_pixel_format pixel_format;
187 DWORD caps;
188 DWORD caps2;
189 DWORD reserved2[3];
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;
200 header->height = 4;
201 header->width = 4;
202 header->pixel_format.size = sizeof(header->pixel_format);
203 /* X8R8G8B8 */
204 header->pixel_format.flags = DDS_PF_RGB;
205 header->pixel_format.fourcc = 0;
206 header->pixel_format.bpp = 32;
207 header->pixel_format.rmask = 0xff0000;
208 header->pixel_format.gmask = 0x00ff00;
209 header->pixel_format.bmask = 0x0000ff;
210 header->pixel_format.amask = 0;
211 header->caps = DDS_CAPS_TEXTURE;
214 static void check_dds_pixel_format(DWORD flags, DWORD fourcc, DWORD bpp,
215 DWORD rmask, DWORD gmask, DWORD bmask, DWORD amask,
216 D3DFORMAT expected_format)
218 HRESULT hr;
219 D3DXIMAGE_INFO info;
220 struct
222 struct dds_header header;
223 BYTE data[256];
224 } dds;
226 fill_dds_header(&dds.header);
227 dds.header.pixel_format.flags = flags;
228 dds.header.pixel_format.fourcc = fourcc;
229 dds.header.pixel_format.bpp = bpp;
230 dds.header.pixel_format.rmask = rmask;
231 dds.header.pixel_format.gmask = gmask;
232 dds.header.pixel_format.bmask = bmask;
233 dds.header.pixel_format.amask = amask;
234 memset(dds.data, 0, sizeof(dds.data));
236 hr = D3DXGetImageInfoFromFileInMemory(&dds, sizeof(dds), &info);
237 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x for pixel format %#x, expected %#x\n", hr, expected_format, D3D_OK);
238 if (SUCCEEDED(hr))
239 ok(info.Format == expected_format, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n", info.Format, expected_format);
242 static void test_dds_header_handling(void)
244 int i;
245 HRESULT hr;
246 D3DXIMAGE_INFO info;
247 struct
249 struct dds_header header;
250 BYTE data[256];
251 } dds;
253 struct
255 struct dds_pixel_format pixel_format;
256 DWORD flags;
257 DWORD width;
258 DWORD height;
259 DWORD pitch;
260 DWORD pixel_data_size;
261 HRESULT expected_result;
262 } tests[] = {
263 /* pitch is ignored */
264 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, 0, 4, 4, 0,
265 63 /* pixel data size */, D3DXERR_INVALIDDATA },
266 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 0 /* pitch */,
267 64, D3D_OK },
268 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1 /* pitch */,
269 64, D3D_OK },
270 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 2 /* pitch */,
271 64, D3D_OK },
272 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 3 /* pitch */,
273 64, D3D_OK },
274 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 4 /* pitch */,
275 64, D3D_OK },
276 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 16 /* pitch */,
277 64, D3D_OK },
278 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1024 /* pitch */,
279 64, D3D_OK },
280 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, -1 /* pitch */,
281 64, D3D_OK },
282 /* linear size is ignored */
283 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, 0, 4, 4, 0,
284 7 /* pixel data size */, D3DXERR_INVALIDDATA },
285 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 0 /* linear size */,
286 8, D3D_OK },
287 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 1 /* linear size */,
288 8, D3D_OK },
289 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 2 /* linear size */,
290 8, D3D_OK },
291 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 9 /* linear size */,
292 8, D3D_OK },
293 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 16 /* linear size */,
294 8, D3D_OK },
295 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, -1 /* linear size */,
296 8, D3D_OK },
297 /* integer overflows */
298 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000000, 0x80000000 /* 0x80000000 * 0x80000000 * 4 = 0 */, 0,
299 64, D3D_OK },
300 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x8000100, 0x800100 /* 0x8000100 * 0x800100 * 4 = 262144 */, 0,
301 64, D3DXERR_INVALIDDATA },
302 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
303 4, D3D_OK },
304 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
305 3 /* pixel data size */, D3DXERR_INVALIDDATA }
308 memset(&dds, 0, sizeof(dds));
310 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
312 DWORD file_size = sizeof(dds.header) + tests[i].pixel_data_size;
313 assert(file_size <= sizeof(dds));
315 fill_dds_header(&dds.header);
316 dds.header.flags |= tests[i].flags;
317 dds.header.width = tests[i].width;
318 dds.header.height = tests[i].height;
319 dds.header.pitch_or_linear_size = tests[i].pitch;
320 memcpy(&dds.header.pixel_format, &tests[i].pixel_format, sizeof(struct dds_pixel_format));
322 hr = D3DXGetImageInfoFromFileInMemory(&dds, file_size, &info);
323 ok(hr == tests[i].expected_result, "%d: D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", i, hr, tests[i].expected_result);
327 static void test_D3DXGetImageInfo(void)
329 HRESULT hr;
330 D3DXIMAGE_INFO info;
331 BOOL testdummy_ok, testbitmap_ok;
333 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
334 testdummy_ok = SUCCEEDED(hr);
336 hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01)); /* valid image */
337 testbitmap_ok = SUCCEEDED(hr);
339 /* D3DXGetImageInfoFromFile */
340 if(testbitmap_ok) {
341 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", &info);
342 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
344 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL); /* valid image, second parameter is NULL */
345 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
346 } else skip("Couldn't create \"testbitmap.bmp\"\n");
348 if(testdummy_ok) {
349 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", NULL); /* invalid image, second parameter is NULL */
350 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
352 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", &info);
353 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
354 } else skip("Couldn't create \"testdummy.bmp\"\n");
356 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info);
357 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
359 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL);
360 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
362 hr = D3DXGetImageInfoFromFileA("", &info);
363 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
365 hr = D3DXGetImageInfoFromFileA(NULL, &info);
366 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
368 hr = D3DXGetImageInfoFromFileA(NULL, NULL);
369 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
372 /* D3DXGetImageInfoFromResource */
373 todo_wine {
374 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &info); /* RT_BITMAP */
375 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
377 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL);
378 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
381 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &info); /* RT_RCDATA */
382 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
384 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), &info);
385 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
387 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), NULL);
388 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
390 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", &info);
391 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
393 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", NULL);
394 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
396 hr = D3DXGetImageInfoFromResourceA(NULL, NULL, NULL);
397 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
400 /* D3DXGetImageInfoFromFileInMemory */
401 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01), &info);
402 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
404 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01)+5, &info); /* too large size */
405 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
407 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01), NULL);
408 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
410 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), NULL);
411 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
413 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), &info);
414 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
416 todo_wine {
417 hr = D3DXGetImageInfoFromFileInMemory(bmp01, sizeof(bmp01)-1, &info);
418 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
421 hr = D3DXGetImageInfoFromFileInMemory(bmp01+1, sizeof(bmp01)-1, &info);
422 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
424 hr = D3DXGetImageInfoFromFileInMemory(bmp01, 0, &info);
425 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
427 hr = D3DXGetImageInfoFromFileInMemory(bmp01, 0, NULL);
428 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
430 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, &info);
431 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
433 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, NULL);
434 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
436 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, &info);
437 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
439 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, NULL);
440 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
442 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, &info);
443 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
445 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, NULL);
446 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
449 /* test DDS support */
450 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit), &info);
451 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
452 if (hr == D3D_OK) {
453 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
454 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
455 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
456 ok(info.MipLevels == 2, "Got miplevels %u, expected 2\n", info.MipLevels);
457 ok(info.Format == D3DFMT_R8G8B8, "Got format %#x, expected %#x\n", info.Format, D3DFMT_R8G8B8);
458 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
459 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
460 } else skip("Couldn't get image info from 24-bit DDS file in memory\n");
462 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit), &info);
463 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
464 if (hr == D3D_OK) {
465 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
466 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
467 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
468 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
469 ok(info.Format == D3DFMT_X1R5G5B5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_X1R5G5B5);
470 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
471 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
472 } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
474 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map), &info);
475 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
476 if (hr == D3D_OK) {
477 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
478 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
479 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
480 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
481 ok(info.Format == D3DFMT_DXT5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT5);
482 ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
483 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
484 } else skip("Couldn't get image info from cube map in memory\n");
486 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map), &info);
487 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
488 if (hr == D3D_OK) {
489 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
490 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
491 ok(info.Depth == 2, "Got depth %u, expected 2\n", info.Depth);
492 ok(info.MipLevels == 3, "Got miplevels %u, expected 3\n", info.MipLevels);
493 ok(info.Format == D3DFMT_DXT3, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT3);
494 ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
495 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
496 } else skip("Couldn't get image info from volume map in memory\n");
498 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0, D3DFMT_DXT1);
499 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0, D3DFMT_DXT2);
500 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0, D3DFMT_DXT3);
501 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0, D3DFMT_DXT4);
502 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0, D3DFMT_DXT5);
503 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8);
504 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8);
505 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0, D3DFMT_UYVY);
506 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0, D3DFMT_YUY2);
507 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5);
508 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5);
509 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4);
510 check_dds_pixel_format(DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2);
511 check_dds_pixel_format(DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff, D3DFMT_A8);
512 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2);
513 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf00, 0x0f0, 0x00f, 0, D3DFMT_X4R4G4B4);
514 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10);
515 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10);
516 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8);
517 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_X8R8G8B8);
518 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_G16R16);
519 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8);
520 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16);
521 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8);
522 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4);
523 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8);
524 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16);
526 test_dds_header_handling();
528 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit) - 1, &info);
529 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
531 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit) - 1, &info);
532 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
534 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map) - 1, &info);
535 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
537 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map) - 1, &info);
538 todo_wine ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
541 /* cleanup */
542 if(testdummy_ok) DeleteFileA("testdummy.bmp");
543 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
546 #define check_pixel_1bpp(lockrect, x, y, color) _check_pixel_1bpp(__LINE__, lockrect, x, y, color)
547 static inline void _check_pixel_1bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, BYTE expected_color)
549 BYTE color = ((BYTE*)lockrect->pBits)[x + y * lockrect->Pitch];
550 ok_(__FILE__, line)(color == expected_color, "Got color 0x%02x, expected 0x%02x\n", color, expected_color);
553 #define check_pixel_2bpp(lockrect, x, y, color) _check_pixel_2bpp(__LINE__, lockrect, x, y, color)
554 static inline void _check_pixel_2bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, WORD expected_color)
556 WORD color = ((WORD*)lockrect->pBits)[x + y * lockrect->Pitch / 2];
557 ok_(__FILE__, line)(color == expected_color, "Got color 0x%04x, expected 0x%04x\n", color, expected_color);
560 #define check_pixel_4bpp(lockrect, x, y, color) _check_pixel_4bpp(__LINE__, lockrect, x, y, color)
561 static inline void _check_pixel_4bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, DWORD expected_color)
563 DWORD color = ((DWORD*)lockrect->pBits)[x + y * lockrect->Pitch / 4];
564 ok_(__FILE__, line)(color == expected_color, "Got color 0x%08x, expected 0x%08x\n", color, expected_color);
567 static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
569 HRESULT hr;
570 BOOL testdummy_ok, testbitmap_ok;
571 IDirect3DTexture9 *tex;
572 IDirect3DSurface9 *surf, *newsurf;
573 RECT rect, destrect;
574 D3DLOCKED_RECT lockrect;
575 const WORD pixdata_a8r3g3b2[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
576 const WORD pixdata_a1r5g5b5[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
577 const WORD pixdata_r5g6b5[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
578 const WORD pixdata_a8l8[] = { 0xff00, 0x00ff, 0xff30, 0x7f7f };
579 const DWORD pixdata_g16r16[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
580 const DWORD pixdata_a8b8g8r8[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
581 const DWORD pixdata_a2r10g10b10[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
583 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
584 testdummy_ok = SUCCEEDED(hr);
586 hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01)); /* valid image */
587 testbitmap_ok = SUCCEEDED(hr);
589 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
590 if(FAILED(hr)) {
591 skip("Failed to create a surface (%#x)\n", hr);
592 if(testdummy_ok) DeleteFileA("testdummy.bmp");
593 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
594 return;
597 /* D3DXLoadSurfaceFromFile */
598 if(testbitmap_ok) {
599 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
600 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3D_OK);
602 hr = D3DXLoadSurfaceFromFileA(NULL, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
603 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
604 } else skip("Couldn't create \"testbitmap.bmp\"\n");
606 if(testdummy_ok) {
607 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testdummy.bmp", NULL, D3DX_DEFAULT, 0, NULL);
608 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
609 } else skip("Couldn't create \"testdummy.bmp\"\n");
611 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
612 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
614 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "", NULL, D3DX_DEFAULT, 0, NULL);
615 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
618 /* D3DXLoadSurfaceFromResource */
619 todo_wine {
620 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
621 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
624 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDD_BITMAPDATA_1x1), NULL, D3DX_DEFAULT, 0, NULL);
625 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
627 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
628 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
630 hr = D3DXLoadSurfaceFromResourceA(NULL, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
631 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
633 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDS_STRING), NULL, D3DX_DEFAULT, 0, NULL);
634 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
637 /* D3DXLoadSurfaceFromFileInMemory */
638 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
639 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
641 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, noimage, sizeof(noimage), NULL, D3DX_DEFAULT, 0, NULL);
642 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
644 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, 0, NULL, D3DX_DEFAULT, 0, NULL);
645 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
647 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
648 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
650 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 8, NULL, D3DX_DEFAULT, 0, NULL);
651 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
653 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
654 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
656 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
657 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
660 /* D3DXLoadSurfaceFromMemory */
661 SetRect(&rect, 0, 0, 2, 2);
663 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
664 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
666 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, 0, NULL, &rect, D3DX_FILTER_NONE, 0);
667 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
669 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, NULL, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
670 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
672 hr = D3DXLoadSurfaceFromMemory(NULL, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
673 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
675 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, NULL, D3DX_DEFAULT, 0);
676 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
678 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_UNKNOWN, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
679 ok(hr == E_FAIL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, E_FAIL);
681 SetRect(&destrect, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
682 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
683 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
685 SetRect(&destrect, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
686 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
687 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
689 SetRect(&destrect, 1, 1, 0, 0); /* left > right, top > bottom */
690 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
691 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
693 SetRect(&destrect, 0, 0, 0, 0); /* left = right, top = bottom */
694 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
695 /* fails when debug version of d3d9 is used */
696 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
698 SetRect(&destrect, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
699 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
700 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
703 /* D3DXLoadSurfaceFromSurface */
704 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newsurf, NULL);
705 if(SUCCEEDED(hr)) {
706 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
707 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
709 hr = D3DXLoadSurfaceFromSurface(NULL, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
710 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
712 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0);
713 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
715 check_release((IUnknown*)newsurf, 0);
716 } else skip("Failed to create a second surface\n");
718 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
719 if (SUCCEEDED(hr))
721 IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
723 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
724 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
726 IDirect3DSurface9_Release(newsurf);
727 IDirect3DTexture9_Release(tex);
728 } else skip("Failed to create texture\n");
730 /* non-lockable render target */
731 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &newsurf, NULL);
732 if (SUCCEEDED(hr)) {
733 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
734 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
736 IDirect3DSurface9_Release(newsurf);
737 } else skip("Failed to create render target surface\n");
739 /* non-lockable multisampled render target */
740 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &newsurf, NULL);
741 if (SUCCEEDED(hr)) {
742 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
743 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
745 IDirect3DSurface9_Release(newsurf);
746 } else skip("Failed to create multisampled render target\n");
748 check_release((IUnknown*)surf, 0);
751 /* test color conversion */
752 /* A8R8G8B8 */
753 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
754 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
755 else {
756 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
757 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
758 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
759 check_pixel_4bpp(&lockrect, 0, 0, 0x57dbffff);
760 check_pixel_4bpp(&lockrect, 1, 0, 0x98ffff00);
761 check_pixel_4bpp(&lockrect, 0, 1, 0xacdbff55);
762 check_pixel_4bpp(&lockrect, 1, 1, 0xc8929255);
763 IDirect3DSurface9_UnlockRect(surf);
765 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
766 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
767 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
768 check_pixel_4bpp(&lockrect, 0, 0, 0x008cadad);
769 check_pixel_4bpp(&lockrect, 1, 0, 0xff317342);
770 check_pixel_4bpp(&lockrect, 0, 1, 0x0008ad10);
771 check_pixel_4bpp(&lockrect, 1, 1, 0xff29088c);
772 IDirect3DSurface9_UnlockRect(surf);
774 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
775 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
776 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
777 check_pixel_4bpp(&lockrect, 0, 0, 0xff9cdfb5);
778 check_pixel_4bpp(&lockrect, 1, 0, 0xff63b26b);
779 check_pixel_4bpp(&lockrect, 0, 1, 0xff085d73);
780 check_pixel_4bpp(&lockrect, 1, 1, 0xff425d73);
781 IDirect3DSurface9_UnlockRect(surf);
783 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
784 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
785 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
786 todo_wine {
787 check_pixel_4bpp(&lockrect, 0, 0, 0xff3f08ff);
789 check_pixel_4bpp(&lockrect, 1, 0, 0xff44dcff);
790 check_pixel_4bpp(&lockrect, 0, 1, 0xff97e4ff);
791 check_pixel_4bpp(&lockrect, 1, 1, 0xfffe9aff);
792 IDirect3DSurface9_UnlockRect(surf);
794 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
795 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
796 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
797 check_pixel_4bpp(&lockrect, 0, 0, 0xc3f04c39);
798 check_pixel_4bpp(&lockrect, 1, 0, 0x2392e85a);
799 check_pixel_4bpp(&lockrect, 0, 1, 0x09fd97b1);
800 check_pixel_4bpp(&lockrect, 1, 1, 0x8df62bc3);
801 IDirect3DSurface9_UnlockRect(surf);
803 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
804 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
805 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
806 check_pixel_4bpp(&lockrect, 0, 0, 0x555c95bf);
807 check_pixel_4bpp(&lockrect, 1, 0, 0x556d663f);
808 check_pixel_4bpp(&lockrect, 0, 1, 0xaac385ad);
809 todo_wine {
810 check_pixel_4bpp(&lockrect, 1, 1, 0xfffcc575);
812 IDirect3DSurface9_UnlockRect(surf);
814 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
815 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
816 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
817 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
818 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
819 check_pixel_4bpp(&lockrect, 0, 0, 0xff000000);
820 check_pixel_4bpp(&lockrect, 1, 0, 0x00ffffff);
821 check_pixel_4bpp(&lockrect, 0, 1, 0xff303030);
822 check_pixel_4bpp(&lockrect, 1, 1, 0x7f7f7f7f);
823 hr = IDirect3DSurface9_UnlockRect(surf);
824 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
826 check_release((IUnknown*)surf, 0);
829 /* A1R5G5B5 */
830 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A1R5G5B5, D3DPOOL_DEFAULT, &surf, NULL);
831 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
832 else {
833 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
834 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
835 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
836 check_pixel_2bpp(&lockrect, 0, 0, 0x6fff);
837 check_pixel_2bpp(&lockrect, 1, 0, 0xffe0);
838 check_pixel_2bpp(&lockrect, 0, 1, 0xefea);
839 check_pixel_2bpp(&lockrect, 1, 1, 0xca4a);
840 IDirect3DSurface9_UnlockRect(surf);
842 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
843 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
844 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
845 check_pixel_2bpp(&lockrect, 0, 0, 0x46b5);
846 check_pixel_2bpp(&lockrect, 1, 0, 0x99c8);
847 check_pixel_2bpp(&lockrect, 0, 1, 0x06a2);
848 check_pixel_2bpp(&lockrect, 1, 1, 0x9431);
849 IDirect3DSurface9_UnlockRect(surf);
851 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
852 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
853 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
854 check_pixel_2bpp(&lockrect, 0, 0, 0xcf76);
855 check_pixel_2bpp(&lockrect, 1, 0, 0xb2cd);
856 check_pixel_2bpp(&lockrect, 0, 1, 0x856e);
857 check_pixel_2bpp(&lockrect, 1, 1, 0xa16e);
858 IDirect3DSurface9_UnlockRect(surf);
860 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
861 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
862 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
863 todo_wine {
864 check_pixel_2bpp(&lockrect, 0, 0, 0xa03f);
866 check_pixel_2bpp(&lockrect, 1, 0, 0xa37f);
867 check_pixel_2bpp(&lockrect, 0, 1, 0xcb9f);
868 check_pixel_2bpp(&lockrect, 1, 1, 0xfe7f);
869 IDirect3DSurface9_UnlockRect(surf);
871 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
872 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
873 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
874 todo_wine {
875 check_pixel_2bpp(&lockrect, 0, 0, 0xf527);
876 check_pixel_2bpp(&lockrect, 1, 0, 0x4b8b);
878 check_pixel_2bpp(&lockrect, 0, 1, 0x7e56);
879 check_pixel_2bpp(&lockrect, 1, 1, 0xf8b8);
880 IDirect3DSurface9_UnlockRect(surf);
882 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
883 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
884 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
885 check_pixel_2bpp(&lockrect, 0, 0, 0x2e57);
886 todo_wine {
887 check_pixel_2bpp(&lockrect, 1, 0, 0x3588);
889 check_pixel_2bpp(&lockrect, 0, 1, 0xe215);
890 check_pixel_2bpp(&lockrect, 1, 1, 0xff0e);
891 IDirect3DSurface9_UnlockRect(surf);
893 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
894 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
895 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
896 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
897 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
898 check_pixel_2bpp(&lockrect, 0, 0, 0x8000);
899 check_pixel_2bpp(&lockrect, 1, 0, 0x7fff);
900 check_pixel_2bpp(&lockrect, 0, 1, 0x98c6);
901 check_pixel_2bpp(&lockrect, 1, 1, 0x3def);
902 hr = IDirect3DSurface9_UnlockRect(surf);
903 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
905 check_release((IUnknown*)surf, 0);
908 /* A8L8 */
909 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8L8, D3DPOOL_DEFAULT, &surf, NULL);
910 if (FAILED(hr))
911 skip("Failed to create A8L8 surface, hr %#x.\n", hr);
912 else
914 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
915 D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
916 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
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, 0x57f7);
920 check_pixel_2bpp(&lockrect, 1, 0, 0x98ed);
921 check_pixel_2bpp(&lockrect, 0, 1, 0xaceb);
922 check_pixel_2bpp(&lockrect, 1, 1, 0xc88d);
923 hr = IDirect3DSurface9_UnlockRect(surf);
924 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
926 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
927 D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
928 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
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, 0x00a6);
932 check_pixel_2bpp(&lockrect, 1, 0, 0xff62);
933 check_pixel_2bpp(&lockrect, 0, 1, 0x007f);
934 check_pixel_2bpp(&lockrect, 1, 1, 0xff19);
935 hr = IDirect3DSurface9_UnlockRect(surf);
936 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
938 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
939 D3DFMT_R5G6B5, 4, 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, 0xffce);
944 check_pixel_2bpp(&lockrect, 1, 0, 0xff9c);
945 check_pixel_2bpp(&lockrect, 0, 1, 0xff4d);
946 check_pixel_2bpp(&lockrect, 1, 1, 0xff59);
947 hr = IDirect3DSurface9_UnlockRect(surf);
948 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
950 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
951 D3DFMT_G16R16, 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, 0xff25);
956 check_pixel_2bpp(&lockrect, 1, 0, 0xffbe);
957 check_pixel_2bpp(&lockrect, 0, 1, 0xffd6);
958 check_pixel_2bpp(&lockrect, 1, 1, 0xffb6);
959 hr = IDirect3DSurface9_UnlockRect(surf);
960 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
962 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
963 D3DFMT_A8B8G8R8, 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, 0xc36d);
968 check_pixel_2bpp(&lockrect, 1, 0, 0x23cb);
969 check_pixel_2bpp(&lockrect, 0, 1, 0x09af);
970 check_pixel_2bpp(&lockrect, 1, 1, 0x8d61);
971 hr = IDirect3DSurface9_UnlockRect(surf);
972 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
974 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
975 D3DFMT_A2R10G10B10, 8, 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, 0x558c);
980 check_pixel_2bpp(&lockrect, 1, 0, 0x5565);
981 check_pixel_2bpp(&lockrect, 0, 1, 0xaa95);
982 check_pixel_2bpp(&lockrect, 1, 1, 0xffcb);
983 hr = IDirect3DSurface9_UnlockRect(surf);
984 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
986 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
987 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
988 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
989 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
990 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
991 check_pixel_2bpp(&lockrect, 0, 0, 0xff00);
992 check_pixel_2bpp(&lockrect, 1, 0, 0x00ff);
993 check_pixel_2bpp(&lockrect, 0, 1, 0xff30);
994 check_pixel_2bpp(&lockrect, 1, 1, 0x7f7f);
995 hr = IDirect3DSurface9_UnlockRect(surf);
996 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
998 check_release((IUnknown*)surf, 0);
1001 /* DXT1, DXT2, DXT3, DXT4, DXT5 */
1002 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf, NULL);
1003 if (FAILED(hr))
1004 skip("Failed to create R8G8B8 surface, hr %#x.\n", hr);
1005 else
1007 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, dds_24bit, sizeof(dds_24bit), NULL, D3DX_FILTER_NONE, 0, NULL);
1008 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1010 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT2, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1011 if (FAILED(hr))
1012 skip("Failed to create DXT2 surface, hr %#x.\n", hr);
1013 else
1015 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1016 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT2 format.\n");
1017 check_release((IUnknown*)newsurf, 0);
1020 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT3, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1021 if (FAILED(hr))
1022 skip("Failed to create DXT3 surface, hr %#x.\n", hr);
1023 else
1025 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1026 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT3 format.\n");
1027 check_release((IUnknown*)newsurf, 0);
1030 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT4, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1031 if (FAILED(hr))
1032 skip("Failed to create DXT4 surface, hr %#x.\n", hr);
1033 else
1035 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1036 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT4 format.\n");
1037 check_release((IUnknown*)newsurf, 0);
1040 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1041 if (FAILED(hr))
1042 skip("Failed to create DXT5 surface, hr %#x.\n", hr);
1043 else
1045 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1046 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT5 format.\n");
1047 check_release((IUnknown*)newsurf, 0);
1050 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &newsurf, NULL);
1051 if (FAILED(hr))
1052 skip("Failed to create DXT1 surface, hr %#x.\n", hr);
1053 else
1055 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1056 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT1 format.\n");
1058 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
1059 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels from DXT1 format.\n");
1061 check_release((IUnknown*)newsurf, 0);
1064 check_release((IUnknown*)surf, 0);
1067 /* cleanup */
1068 if(testdummy_ok) DeleteFileA("testdummy.bmp");
1069 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
1072 static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9 *device)
1074 HRESULT hr;
1075 RECT rect;
1076 ID3DXBuffer *buffer;
1077 IDirect3DSurface9 *surface;
1079 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1080 if (FAILED(hr)) {
1081 skip("Couldn't create surface\n");
1082 return;
1085 SetRect(&rect, 0, 0, 0, 0);
1086 hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_BMP, surface, NULL, &rect);
1087 /* fails with the debug version of d3d9 */
1088 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1089 if (SUCCEEDED(hr)) {
1090 DWORD size = ID3DXBuffer_GetBufferSize(buffer);
1091 ok(size > 0, "ID3DXBuffer_GetBufferSize returned %u, expected > 0\n", size);
1092 ID3DXBuffer_Release(buffer);
1095 IDirect3DSurface9_Release(surface);
1098 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
1100 HRESULT hr;
1101 IDirect3DSurface9 *surface;
1102 RECT rect;
1103 D3DLOCKED_RECT lock_rect;
1104 D3DXIMAGE_INFO image_info;
1105 const BYTE pixels[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
1106 0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
1107 DWORD pitch = sizeof(pixels) / 2;
1109 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1110 if (FAILED(hr)) {
1111 skip("Couldn't create surface\n");
1112 return;
1115 SetRect(&rect, 0, 0, 2, 2);
1116 hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, pixels, D3DFMT_R8G8B8, pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
1117 if (SUCCEEDED(hr)) {
1118 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, NULL);
1119 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1121 hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.bmp", NULL, D3DX_FILTER_NONE, 0, &image_info);
1122 ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
1123 if (FAILED(hr)) goto next_tests;
1125 ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
1126 ok(image_info.Height == 2, "Wrong height %u\n", image_info.Height);
1127 ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
1128 ok(image_info.ImageFileFormat == D3DXIFF_BMP, "Wrong file format %u\n", image_info.ImageFileFormat);
1130 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1131 ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
1132 if (FAILED(hr)) goto next_tests;
1134 ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
1135 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
1137 IDirect3DSurface9_UnlockRect(surface);
1138 } else skip("Couldn't fill surface\n");
1140 next_tests:
1141 hr = D3DXSaveSurfaceToFileA(NULL, D3DXIFF_BMP, surface, NULL, NULL);
1142 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1144 /* PPM and TGA are supported, even though MSDN claims they aren't */
1145 todo_wine {
1146 hr = D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM, surface, NULL, NULL);
1147 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1148 hr = D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA, surface, NULL, NULL);
1149 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1150 hr = D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS, surface, NULL, NULL);
1151 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1154 hr = D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM + 1, surface, NULL, NULL);
1155 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1157 SetRect(&rect, 0, 0, 4, 4);
1158 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1159 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1160 SetRect(&rect, 2, 0, 1, 4);
1161 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1162 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1163 SetRect(&rect, 0, 2, 4, 1);
1164 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1165 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1166 SetRect(&rect, -1, -1, 2, 2);
1167 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1168 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1169 SetRect(&rect, 0, 0, 0, 0);
1170 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1171 /* fails when debug version of d3d9 is used */
1172 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1174 DeleteFileA("saved_surface.bmp");
1175 DeleteFileA("saved_surface.ppm");
1176 DeleteFileA("saved_surface.tga");
1177 DeleteFileA("saved_surface.dds");
1179 IDirect3DSurface9_Release(surface);
1182 START_TEST(surface)
1184 HWND wnd;
1185 IDirect3D9 *d3d;
1186 IDirect3DDevice9 *device;
1187 D3DPRESENT_PARAMETERS d3dpp;
1188 HRESULT hr;
1190 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1191 if (!wnd) {
1192 skip("Couldn't create application window\n");
1193 return;
1195 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1196 if (!d3d) {
1197 skip("Couldn't create IDirect3D9 object\n");
1198 DestroyWindow(wnd);
1199 return;
1202 ZeroMemory(&d3dpp, sizeof(d3dpp));
1203 d3dpp.Windowed = TRUE;
1204 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1205 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1206 if(FAILED(hr)) {
1207 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1208 IDirect3D9_Release(d3d);
1209 DestroyWindow(wnd);
1210 return;
1213 test_D3DXGetImageInfo();
1214 test_D3DXLoadSurface(device);
1215 test_D3DXSaveSurfaceToFileInMemory(device);
1216 test_D3DXSaveSurfaceToFile(device);
1218 check_release((IUnknown*)device, 0);
1219 check_release((IUnknown*)d3d, 0);
1220 DestroyWindow(wnd);