dpnet/tests: Add a trailing '\n' to some ok() calls.
[wine.git] / dlls / d3dx9_36 / tests / surface.c
blob2ddc704ba29d0f8b66e7aebe9f514bb4bf71d9b7
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 bmp_1bpp[] = {
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,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00,
53 0x00,0x00
56 /* 1x1 bmp (2 bpp) */
57 static const unsigned char bmp_2bpp[] = {
58 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
59 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x00,0x00,
60 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
61 0x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00,
62 0x00,0x00
65 /* 1x1 bmp (4 bpp) */
66 static const unsigned char bmp_4bpp[] = {
67 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
68 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00,
69 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
70 0x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00,
71 0x00,0x00
74 /* 1x1 bmp (8 bpp) */
75 static const unsigned char bmp_8bpp[] = {
76 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
77 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x08,0x00,0x00,0x00,
78 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
79 0x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00,
80 0x00,0x00
83 /* 2x2 A8R8G8B8 pixel data */
84 static const unsigned char pixdata[] = {
85 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
88 /* invalid image file */
89 static const unsigned char noimage[4] = {
90 0x11,0x22,0x33,0x44
93 /* 2x2 24-bit dds, 2 mipmaps */
94 static const unsigned char dds_24bit[] = {
95 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00,
96 0x02,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,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,0x00,0x00,0x00,0x00,
99 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
100 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
101 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
102 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
103 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
106 /* 2x2 16-bit dds, no mipmaps */
107 static const unsigned char dds_16bit[] = {
108 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
109 0x02,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
110 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
111 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
112 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
113 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,
114 0xe0,0x03,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
115 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
116 0xff,0x7f,0xff,0x7f,0xff,0x7f,0xff,0x7f
119 /* 4x4 cube map dds */
120 static const unsigned char dds_cube_map[] = {
121 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00,
122 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
123 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
124 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
125 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
126 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
127 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
128 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
129 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
130 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
131 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
132 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
133 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
134 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50
137 /* 4x4x2 volume map dds, 2 mipmaps */
138 static const unsigned char dds_volume_map[] = {
139 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
140 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
141 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
142 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
143 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
144 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
145 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
146 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
147 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
148 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
149 0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
150 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
153 static HRESULT create_file(const char *filename, const unsigned char *data, const unsigned int size)
155 DWORD received;
156 HANDLE hfile;
158 hfile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
159 if(hfile == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError());
161 if(WriteFile(hfile, data, size, &received, NULL))
163 CloseHandle(hfile);
164 return D3D_OK;
167 CloseHandle(hfile);
168 return D3DERR_INVALIDCALL;
171 /* dds_header.flags */
172 #define DDS_CAPS 0x00000001
173 #define DDS_HEIGHT 0x00000002
174 #define DDS_WIDTH 0x00000004
175 #define DDS_PITCH 0x00000008
176 #define DDS_PIXELFORMAT 0x00001000
177 #define DDS_LINEARSIZE 0x00080000
179 /* dds_header.caps */
180 #define DDS_CAPS_TEXTURE 0x00001000
182 /* dds_pixel_format.flags */
183 #define DDS_PF_ALPHA 0x00000001
184 #define DDS_PF_ALPHA_ONLY 0x00000002
185 #define DDS_PF_FOURCC 0x00000004
186 #define DDS_PF_RGB 0x00000040
187 #define DDS_PF_LUMINANCE 0x00020000
188 #define DDS_PF_BUMPDUDV 0x00080000
190 struct dds_pixel_format
192 DWORD size;
193 DWORD flags;
194 DWORD fourcc;
195 DWORD bpp;
196 DWORD rmask;
197 DWORD gmask;
198 DWORD bmask;
199 DWORD amask;
202 struct dds_header
204 DWORD magic;
205 DWORD size;
206 DWORD flags;
207 DWORD height;
208 DWORD width;
209 DWORD pitch_or_linear_size;
210 DWORD depth;
211 DWORD miplevels;
212 DWORD reserved[11];
213 struct dds_pixel_format pixel_format;
214 DWORD caps;
215 DWORD caps2;
216 DWORD reserved2[3];
219 /* fills dds_header with reasonable default values */
220 static void fill_dds_header(struct dds_header *header)
222 memset(header, 0, sizeof(*header));
224 header->magic = MAKEFOURCC('D','D','S',' ');
225 header->size = sizeof(*header);
226 header->flags = DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT;
227 header->height = 4;
228 header->width = 4;
229 header->pixel_format.size = sizeof(header->pixel_format);
230 /* X8R8G8B8 */
231 header->pixel_format.flags = DDS_PF_RGB;
232 header->pixel_format.fourcc = 0;
233 header->pixel_format.bpp = 32;
234 header->pixel_format.rmask = 0xff0000;
235 header->pixel_format.gmask = 0x00ff00;
236 header->pixel_format.bmask = 0x0000ff;
237 header->pixel_format.amask = 0;
238 header->caps = DDS_CAPS_TEXTURE;
241 #define check_dds_pixel_format(flags, fourcc, bpp, rmask, gmask, bmask, amask, format) \
242 check_dds_pixel_format_(__LINE__, flags, fourcc, bpp, rmask, gmask, bmask, amask, format)
243 static void check_dds_pixel_format_(unsigned int line,
244 DWORD flags, DWORD fourcc, DWORD bpp,
245 DWORD rmask, DWORD gmask, DWORD bmask, DWORD amask,
246 D3DFORMAT expected_format)
248 HRESULT hr;
249 D3DXIMAGE_INFO info;
250 struct
252 struct dds_header header;
253 BYTE data[256];
254 } dds;
256 fill_dds_header(&dds.header);
257 dds.header.pixel_format.flags = flags;
258 dds.header.pixel_format.fourcc = fourcc;
259 dds.header.pixel_format.bpp = bpp;
260 dds.header.pixel_format.rmask = rmask;
261 dds.header.pixel_format.gmask = gmask;
262 dds.header.pixel_format.bmask = bmask;
263 dds.header.pixel_format.amask = amask;
264 memset(dds.data, 0, sizeof(dds.data));
266 hr = D3DXGetImageInfoFromFileInMemory(&dds, sizeof(dds), &info);
267 ok_(__FILE__, line)(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x for pixel format %#x, expected %#x\n",
268 hr, expected_format, D3D_OK);
269 if (SUCCEEDED(hr))
271 ok_(__FILE__, line)(info.Format == expected_format, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n",
272 info.Format, expected_format);
276 static void test_dds_header_handling(void)
278 int i;
279 HRESULT hr;
280 D3DXIMAGE_INFO info;
281 struct
283 struct dds_header header;
284 BYTE data[256];
285 } dds;
287 struct
289 struct dds_pixel_format pixel_format;
290 DWORD flags;
291 DWORD width;
292 DWORD height;
293 DWORD pitch;
294 DWORD pixel_data_size;
295 HRESULT expected_result;
296 } tests[] = {
297 /* pitch is ignored */
298 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, 0, 4, 4, 0,
299 63 /* pixel data size */, D3DXERR_INVALIDDATA },
300 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 0 /* pitch */,
301 64, D3D_OK },
302 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1 /* pitch */,
303 64, D3D_OK },
304 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 2 /* pitch */,
305 64, D3D_OK },
306 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 3 /* pitch */,
307 64, D3D_OK },
308 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 4 /* pitch */,
309 64, D3D_OK },
310 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 16 /* pitch */,
311 64, D3D_OK },
312 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1024 /* pitch */,
313 64, D3D_OK },
314 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, -1 /* pitch */,
315 64, D3D_OK },
316 /* linear size is ignored */
317 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, 0, 4, 4, 0,
318 7 /* pixel data size */, D3DXERR_INVALIDDATA },
319 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 0 /* linear size */,
320 8, D3D_OK },
321 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 1 /* linear size */,
322 8, D3D_OK },
323 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 2 /* linear size */,
324 8, D3D_OK },
325 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 9 /* linear size */,
326 8, D3D_OK },
327 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 16 /* linear size */,
328 8, D3D_OK },
329 { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, -1 /* linear size */,
330 8, D3D_OK },
331 /* integer overflows */
332 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000000, 0x80000000 /* 0x80000000 * 0x80000000 * 4 = 0 */, 0,
333 64, D3D_OK },
334 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x8000100, 0x800100 /* 0x8000100 * 0x800100 * 4 = 262144 */, 0,
335 64, D3DXERR_INVALIDDATA },
336 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
337 4, D3D_OK },
338 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
339 3 /* pixel data size */, D3DXERR_INVALIDDATA }
342 memset(&dds, 0, sizeof(dds));
344 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
346 DWORD file_size = sizeof(dds.header) + tests[i].pixel_data_size;
347 assert(file_size <= sizeof(dds));
349 fill_dds_header(&dds.header);
350 dds.header.flags |= tests[i].flags;
351 dds.header.width = tests[i].width;
352 dds.header.height = tests[i].height;
353 dds.header.pitch_or_linear_size = tests[i].pitch;
354 dds.header.pixel_format = tests[i].pixel_format;
356 hr = D3DXGetImageInfoFromFileInMemory(&dds, file_size, &info);
357 ok(hr == tests[i].expected_result, "%d: D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", i, hr, tests[i].expected_result);
361 static void test_D3DXGetImageInfo(void)
363 HRESULT hr;
364 D3DXIMAGE_INFO info;
365 BOOL testdummy_ok, testbitmap_ok;
367 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
368 testdummy_ok = SUCCEEDED(hr);
370 hr = create_file("testbitmap.bmp", bmp_1bpp, sizeof(bmp_1bpp)); /* valid image */
371 testbitmap_ok = SUCCEEDED(hr);
373 /* D3DXGetImageInfoFromFile */
374 if(testbitmap_ok) {
375 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", &info);
376 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
378 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL); /* valid image, second parameter is NULL */
379 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
380 } else skip("Couldn't create \"testbitmap.bmp\"\n");
382 if(testdummy_ok) {
383 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", NULL); /* invalid image, second parameter is NULL */
384 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
386 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", &info);
387 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
388 } else skip("Couldn't create \"testdummy.bmp\"\n");
390 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info);
391 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
393 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL);
394 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
396 hr = D3DXGetImageInfoFromFileA("", &info);
397 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
399 hr = D3DXGetImageInfoFromFileA(NULL, &info);
400 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
402 hr = D3DXGetImageInfoFromFileA(NULL, NULL);
403 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
406 /* D3DXGetImageInfoFromResource */
407 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &info); /* RT_BITMAP */
408 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
410 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL);
411 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
413 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &info); /* RT_RCDATA */
414 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
416 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), &info);
417 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
419 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), NULL);
420 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
422 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", &info);
423 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
425 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", NULL);
426 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
428 hr = D3DXGetImageInfoFromResourceA(NULL, NULL, NULL);
429 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
432 /* D3DXGetImageInfoFromFileInMemory */
433 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp), &info);
434 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
436 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp)+5, &info); /* too large size */
437 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
439 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp), NULL);
440 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
442 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), NULL);
443 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
445 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), &info);
446 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
448 todo_wine {
449 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp)-1, &info);
450 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
453 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp+1, sizeof(bmp_1bpp)-1, &info);
454 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
456 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, 0, &info);
457 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
459 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, 0, NULL);
460 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
462 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, &info);
463 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
465 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, NULL);
466 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
468 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, &info);
469 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
471 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, NULL);
472 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
474 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, &info);
475 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
477 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, NULL);
478 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
480 /* test BMP support */
481 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp), &info);
482 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
483 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
484 ok(info.Format == D3DFMT_P8, "Got format %u, expected %u\n", info.Format, D3DFMT_P8);
485 hr = D3DXGetImageInfoFromFileInMemory(bmp_2bpp, sizeof(bmp_2bpp), &info);
486 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
487 hr = D3DXGetImageInfoFromFileInMemory(bmp_4bpp, sizeof(bmp_4bpp), &info);
488 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
489 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
490 ok(info.Format == D3DFMT_P8, "Got format %u, expected %u\n", info.Format, D3DFMT_P8);
491 hr = D3DXGetImageInfoFromFileInMemory(bmp_8bpp, sizeof(bmp_8bpp), &info);
492 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
493 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
494 ok(info.Format == D3DFMT_P8, "Got format %u, expected %u\n", info.Format, D3DFMT_P8);
496 /* test DDS support */
497 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit), &info);
498 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
499 if (hr == D3D_OK) {
500 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
501 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
502 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
503 ok(info.MipLevels == 2, "Got miplevels %u, expected 2\n", info.MipLevels);
504 ok(info.Format == D3DFMT_R8G8B8, "Got format %#x, expected %#x\n", info.Format, D3DFMT_R8G8B8);
505 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
506 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
507 } else skip("Couldn't get image info from 24-bit DDS file in memory\n");
509 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit), &info);
510 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
511 if (hr == D3D_OK) {
512 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
513 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
514 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
515 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
516 ok(info.Format == D3DFMT_X1R5G5B5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_X1R5G5B5);
517 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
518 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
519 } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
521 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map), &info);
522 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
523 if (hr == D3D_OK) {
524 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
525 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
526 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
527 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
528 ok(info.Format == D3DFMT_DXT5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT5);
529 ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
530 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
531 } else skip("Couldn't get image info from cube map in memory\n");
533 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map), &info);
534 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
535 if (hr == D3D_OK) {
536 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
537 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
538 ok(info.Depth == 2, "Got depth %u, expected 2\n", info.Depth);
539 ok(info.MipLevels == 3, "Got miplevels %u, expected 3\n", info.MipLevels);
540 ok(info.Format == D3DFMT_DXT3, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT3);
541 ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
542 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
543 } else skip("Couldn't get image info from volume map in memory\n");
545 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0, D3DFMT_DXT1);
546 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0, D3DFMT_DXT2);
547 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0, D3DFMT_DXT3);
548 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0, D3DFMT_DXT4);
549 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0, D3DFMT_DXT5);
550 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8);
551 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8);
552 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0, D3DFMT_UYVY);
553 check_dds_pixel_format(DDS_PF_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0, D3DFMT_YUY2);
554 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5);
555 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5);
556 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4);
557 check_dds_pixel_format(DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2);
558 check_dds_pixel_format(DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff, D3DFMT_A8);
559 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2);
560 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf00, 0x0f0, 0x00f, 0, D3DFMT_X4R4G4B4);
561 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10);
562 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10);
563 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8);
564 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, D3DFMT_A8B8G8R8);
565 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_X8R8G8B8);
566 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8B8G8R8);
567 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_G16R16);
568 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8);
569 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16);
570 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8);
571 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4);
572 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8);
573 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16);
575 test_dds_header_handling();
577 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit) - 1, &info);
578 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
580 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit) - 1, &info);
581 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
583 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map) - 1, &info);
584 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
586 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map) - 1, &info);
587 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
590 /* cleanup */
591 if(testdummy_ok) DeleteFileA("testdummy.bmp");
592 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
595 #define check_pixel_1bpp(lockrect, x, y, color) _check_pixel_1bpp(__LINE__, lockrect, x, y, color)
596 static inline void _check_pixel_1bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, BYTE expected_color)
598 BYTE color = ((BYTE*)lockrect->pBits)[x + y * lockrect->Pitch];
599 ok_(__FILE__, line)(color == expected_color, "Got color 0x%02x, expected 0x%02x\n", color, expected_color);
602 #define check_pixel_2bpp(lockrect, x, y, color) _check_pixel_2bpp(__LINE__, lockrect, x, y, color)
603 static inline void _check_pixel_2bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, WORD expected_color)
605 WORD color = ((WORD*)lockrect->pBits)[x + y * lockrect->Pitch / 2];
606 ok_(__FILE__, line)(color == expected_color, "Got color 0x%04x, expected 0x%04x\n", color, expected_color);
609 #define check_pixel_4bpp(lockrect, x, y, color) _check_pixel_4bpp(__LINE__, lockrect, x, y, color)
610 static inline void _check_pixel_4bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, DWORD expected_color)
612 DWORD color = ((DWORD*)lockrect->pBits)[x + y * lockrect->Pitch / 4];
613 ok_(__FILE__, line)(color == expected_color, "Got color 0x%08x, expected 0x%08x\n", color, expected_color);
616 static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
618 HRESULT hr;
619 BOOL testdummy_ok, testbitmap_ok;
620 IDirect3DTexture9 *tex;
621 IDirect3DSurface9 *surf, *newsurf;
622 RECT rect, destrect;
623 D3DLOCKED_RECT lockrect;
624 const WORD pixdata_a8r3g3b2[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
625 const WORD pixdata_a1r5g5b5[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
626 const WORD pixdata_r5g6b5[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
627 const WORD pixdata_a8l8[] = { 0xff00, 0x00ff, 0xff30, 0x7f7f };
628 const DWORD pixdata_g16r16[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
629 const DWORD pixdata_a8b8g8r8[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
630 const DWORD pixdata_a2r10g10b10[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
632 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
633 testdummy_ok = SUCCEEDED(hr);
635 hr = create_file("testbitmap.bmp", bmp_1bpp, sizeof(bmp_1bpp)); /* valid image */
636 testbitmap_ok = SUCCEEDED(hr);
638 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
639 if(FAILED(hr)) {
640 skip("Failed to create a surface (%#x)\n", hr);
641 if(testdummy_ok) DeleteFileA("testdummy.bmp");
642 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
643 return;
646 /* D3DXLoadSurfaceFromFile */
647 if(testbitmap_ok) {
648 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
649 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3D_OK);
651 hr = D3DXLoadSurfaceFromFileA(NULL, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
652 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
653 } else skip("Couldn't create \"testbitmap.bmp\"\n");
655 if(testdummy_ok) {
656 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testdummy.bmp", NULL, D3DX_DEFAULT, 0, NULL);
657 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
658 } else skip("Couldn't create \"testdummy.bmp\"\n");
660 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
661 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
663 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "", NULL, D3DX_DEFAULT, 0, NULL);
664 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
667 /* D3DXLoadSurfaceFromResource */
668 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL,
669 MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
670 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
672 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL,
673 MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL, D3DX_DEFAULT, 0, NULL);
674 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
676 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
677 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
679 hr = D3DXLoadSurfaceFromResourceA(NULL, NULL, NULL, NULL,
680 MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
681 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
683 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL,
684 MAKEINTRESOURCEA(IDS_STRING), NULL, D3DX_DEFAULT, 0, NULL);
685 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
688 /* D3DXLoadSurfaceFromFileInMemory */
689 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp_1bpp, sizeof(bmp_1bpp), NULL, D3DX_DEFAULT, 0, NULL);
690 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
692 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, noimage, sizeof(noimage), NULL, D3DX_DEFAULT, 0, NULL);
693 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
695 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp_1bpp, 0, NULL, D3DX_DEFAULT, 0, NULL);
696 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
698 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, bmp_1bpp, sizeof(bmp_1bpp), NULL, D3DX_DEFAULT, 0, NULL);
699 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
701 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 8, NULL, D3DX_DEFAULT, 0, NULL);
702 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
704 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
705 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
707 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
708 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
711 /* D3DXLoadSurfaceFromMemory */
712 SetRect(&rect, 0, 0, 2, 2);
714 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
715 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
717 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, 0, NULL, &rect, D3DX_FILTER_NONE, 0);
718 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
720 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, NULL, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
721 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
723 hr = D3DXLoadSurfaceFromMemory(NULL, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
724 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
726 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, NULL, D3DX_DEFAULT, 0);
727 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
729 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_UNKNOWN, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
730 ok(hr == E_FAIL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, E_FAIL);
732 SetRect(&destrect, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
733 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
734 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
736 SetRect(&destrect, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
737 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
738 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
740 SetRect(&destrect, 1, 1, 0, 0); /* left > right, top > bottom */
741 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
742 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
744 SetRect(&destrect, 0, 0, 0, 0); /* left = right, top = bottom */
745 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
746 /* fails when debug version of d3d9 is used */
747 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
749 SetRect(&destrect, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
750 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
751 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
754 /* D3DXLoadSurfaceFromSurface */
755 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newsurf, NULL);
756 if(SUCCEEDED(hr)) {
757 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
758 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
760 hr = D3DXLoadSurfaceFromSurface(NULL, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
761 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
763 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0);
764 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
766 check_release((IUnknown*)newsurf, 0);
767 } else skip("Failed to create a second surface\n");
769 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
770 if (SUCCEEDED(hr))
772 IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
774 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
775 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
777 IDirect3DSurface9_Release(newsurf);
778 IDirect3DTexture9_Release(tex);
779 } else skip("Failed to create texture\n");
781 /* non-lockable render target */
782 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &newsurf, NULL);
783 if (SUCCEEDED(hr)) {
784 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
785 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
787 IDirect3DSurface9_Release(newsurf);
788 } else skip("Failed to create render target surface\n");
790 /* non-lockable multisampled render target */
791 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &newsurf, NULL);
792 if (SUCCEEDED(hr)) {
793 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
794 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
796 IDirect3DSurface9_Release(newsurf);
797 } else skip("Failed to create multisampled render target\n");
799 check_release((IUnknown*)surf, 0);
802 /* test color conversion */
803 /* A8R8G8B8 */
804 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
805 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
806 else {
807 PALETTEENTRY palette;
809 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
810 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
811 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
812 check_pixel_4bpp(&lockrect, 0, 0, 0x57dbffff);
813 check_pixel_4bpp(&lockrect, 1, 0, 0x98ffff00);
814 check_pixel_4bpp(&lockrect, 0, 1, 0xacdbff55);
815 check_pixel_4bpp(&lockrect, 1, 1, 0xc8929255);
816 IDirect3DSurface9_UnlockRect(surf);
818 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
819 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
820 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
821 check_pixel_4bpp(&lockrect, 0, 0, 0x008cadad);
822 check_pixel_4bpp(&lockrect, 1, 0, 0xff317342);
823 check_pixel_4bpp(&lockrect, 0, 1, 0x0008ad10);
824 check_pixel_4bpp(&lockrect, 1, 1, 0xff29088c);
825 IDirect3DSurface9_UnlockRect(surf);
827 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
828 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
829 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
830 check_pixel_4bpp(&lockrect, 0, 0, 0xff9cdfb5);
831 check_pixel_4bpp(&lockrect, 1, 0, 0xff63b26b);
832 check_pixel_4bpp(&lockrect, 0, 1, 0xff085d73);
833 check_pixel_4bpp(&lockrect, 1, 1, 0xff425d73);
834 IDirect3DSurface9_UnlockRect(surf);
836 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
837 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
838 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
839 todo_wine {
840 check_pixel_4bpp(&lockrect, 0, 0, 0xff3f08ff);
842 check_pixel_4bpp(&lockrect, 1, 0, 0xff44dcff);
843 check_pixel_4bpp(&lockrect, 0, 1, 0xff97e4ff);
844 check_pixel_4bpp(&lockrect, 1, 1, 0xfffe9aff);
845 IDirect3DSurface9_UnlockRect(surf);
847 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
848 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
849 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
850 check_pixel_4bpp(&lockrect, 0, 0, 0xc3f04c39);
851 check_pixel_4bpp(&lockrect, 1, 0, 0x2392e85a);
852 check_pixel_4bpp(&lockrect, 0, 1, 0x09fd97b1);
853 check_pixel_4bpp(&lockrect, 1, 1, 0x8df62bc3);
854 IDirect3DSurface9_UnlockRect(surf);
856 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
857 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
858 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
859 check_pixel_4bpp(&lockrect, 0, 0, 0x555c95bf);
860 check_pixel_4bpp(&lockrect, 1, 0, 0x556d663f);
861 check_pixel_4bpp(&lockrect, 0, 1, 0xaac385ad);
862 todo_wine {
863 check_pixel_4bpp(&lockrect, 1, 1, 0xfffcc575);
865 IDirect3DSurface9_UnlockRect(surf);
867 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
868 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
869 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
870 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
871 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
872 check_pixel_4bpp(&lockrect, 0, 0, 0xff000000);
873 check_pixel_4bpp(&lockrect, 1, 0, 0x00ffffff);
874 check_pixel_4bpp(&lockrect, 0, 1, 0xff303030);
875 check_pixel_4bpp(&lockrect, 1, 1, 0x7f7f7f7f);
876 hr = IDirect3DSurface9_UnlockRect(surf);
877 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
879 /* Test D3DXLoadSurfaceFromMemory with indexed color image */
880 palette.peRed = bmp_1bpp[56];
881 palette.peGreen = bmp_1bpp[55];
882 palette.peBlue = bmp_1bpp[54];
883 palette.peFlags = bmp_1bpp[57]; /* peFlags is the alpha component in DX8 and higher */
884 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, &bmp_1bpp[62], D3DFMT_P8, 4, (const PALETTEENTRY*)&palette, &rect, D3DX_FILTER_NONE, 0);
885 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
886 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
887 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x\n", hr);
888 ok(*(DWORD*)lockrect.pBits == 0x80f3f2f1, "Pixel color mismatch: got %#x, expected 0x80f3f2f1\n", *(DWORD*)lockrect.pBits);
889 hr = IDirect3DSurface9_UnlockRect(surf);
890 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x\n", hr);
892 /* Test D3DXLoadSurfaceFromFileInMemory with indexed color image (alpha is not taken into account for bmp file) */
893 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp_1bpp, sizeof(bmp_1bpp), NULL, D3DX_FILTER_NONE, 0, NULL);
894 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
895 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
896 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x\n", hr);
897 ok(*(DWORD*)lockrect.pBits == 0xfff3f2f1, "Pixel color mismatch: got %#x, expected 0xfff3f2f1\n", *(DWORD*)lockrect.pBits);
898 hr = IDirect3DSurface9_UnlockRect(surf);
899 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x\n", hr);
901 check_release((IUnknown*)surf, 0);
904 /* A1R5G5B5 */
905 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A1R5G5B5, D3DPOOL_DEFAULT, &surf, NULL);
906 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
907 else {
908 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
909 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
910 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
911 check_pixel_2bpp(&lockrect, 0, 0, 0x6fff);
912 check_pixel_2bpp(&lockrect, 1, 0, 0xffe0);
913 check_pixel_2bpp(&lockrect, 0, 1, 0xefea);
914 check_pixel_2bpp(&lockrect, 1, 1, 0xca4a);
915 IDirect3DSurface9_UnlockRect(surf);
917 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
918 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
919 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
920 check_pixel_2bpp(&lockrect, 0, 0, 0x46b5);
921 check_pixel_2bpp(&lockrect, 1, 0, 0x99c8);
922 check_pixel_2bpp(&lockrect, 0, 1, 0x06a2);
923 check_pixel_2bpp(&lockrect, 1, 1, 0x9431);
924 IDirect3DSurface9_UnlockRect(surf);
926 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
927 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
928 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
929 check_pixel_2bpp(&lockrect, 0, 0, 0xcf76);
930 check_pixel_2bpp(&lockrect, 1, 0, 0xb2cd);
931 check_pixel_2bpp(&lockrect, 0, 1, 0x856e);
932 check_pixel_2bpp(&lockrect, 1, 1, 0xa16e);
933 IDirect3DSurface9_UnlockRect(surf);
935 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
936 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
937 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
938 todo_wine {
939 check_pixel_2bpp(&lockrect, 0, 0, 0xa03f);
941 check_pixel_2bpp(&lockrect, 1, 0, 0xa37f);
942 check_pixel_2bpp(&lockrect, 0, 1, 0xcb9f);
943 check_pixel_2bpp(&lockrect, 1, 1, 0xfe7f);
944 IDirect3DSurface9_UnlockRect(surf);
946 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
947 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
948 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
949 todo_wine {
950 check_pixel_2bpp(&lockrect, 0, 0, 0xf527);
951 check_pixel_2bpp(&lockrect, 1, 0, 0x4b8b);
953 check_pixel_2bpp(&lockrect, 0, 1, 0x7e56);
954 check_pixel_2bpp(&lockrect, 1, 1, 0xf8b8);
955 IDirect3DSurface9_UnlockRect(surf);
957 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
958 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
959 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
960 check_pixel_2bpp(&lockrect, 0, 0, 0x2e57);
961 todo_wine {
962 check_pixel_2bpp(&lockrect, 1, 0, 0x3588);
964 check_pixel_2bpp(&lockrect, 0, 1, 0xe215);
965 check_pixel_2bpp(&lockrect, 1, 1, 0xff0e);
966 IDirect3DSurface9_UnlockRect(surf);
968 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
969 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
970 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
971 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
972 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
973 check_pixel_2bpp(&lockrect, 0, 0, 0x8000);
974 check_pixel_2bpp(&lockrect, 1, 0, 0x7fff);
975 check_pixel_2bpp(&lockrect, 0, 1, 0x98c6);
976 check_pixel_2bpp(&lockrect, 1, 1, 0x3def);
977 hr = IDirect3DSurface9_UnlockRect(surf);
978 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
980 check_release((IUnknown*)surf, 0);
983 /* A8L8 */
984 hr = IDirect3DDevice9_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8L8, D3DPOOL_MANAGED, &tex, NULL);
985 if (FAILED(hr))
986 skip("Failed to create A8L8 texture, hr %#x.\n", hr);
987 else
989 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &surf);
990 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
992 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
993 D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
994 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
995 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
996 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
997 check_pixel_2bpp(&lockrect, 0, 0, 0x57f7);
998 check_pixel_2bpp(&lockrect, 1, 0, 0x98ed);
999 check_pixel_2bpp(&lockrect, 0, 1, 0xaceb);
1000 check_pixel_2bpp(&lockrect, 1, 1, 0xc88d);
1001 hr = IDirect3DSurface9_UnlockRect(surf);
1002 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1004 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
1005 D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
1006 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1007 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1008 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1009 check_pixel_2bpp(&lockrect, 0, 0, 0x00a6);
1010 check_pixel_2bpp(&lockrect, 1, 0, 0xff62);
1011 check_pixel_2bpp(&lockrect, 0, 1, 0x007f);
1012 check_pixel_2bpp(&lockrect, 1, 1, 0xff19);
1013 hr = IDirect3DSurface9_UnlockRect(surf);
1014 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1016 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
1017 D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
1018 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1019 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1020 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1021 check_pixel_2bpp(&lockrect, 0, 0, 0xffce);
1022 check_pixel_2bpp(&lockrect, 1, 0, 0xff9c);
1023 check_pixel_2bpp(&lockrect, 0, 1, 0xff4d);
1024 check_pixel_2bpp(&lockrect, 1, 1, 0xff59);
1025 hr = IDirect3DSurface9_UnlockRect(surf);
1026 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1028 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
1029 D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
1030 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1031 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1032 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1033 check_pixel_2bpp(&lockrect, 0, 0, 0xff25);
1034 check_pixel_2bpp(&lockrect, 1, 0, 0xffbe);
1035 check_pixel_2bpp(&lockrect, 0, 1, 0xffd6);
1036 check_pixel_2bpp(&lockrect, 1, 1, 0xffb6);
1037 hr = IDirect3DSurface9_UnlockRect(surf);
1038 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1040 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
1041 D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
1042 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1043 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1044 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1045 check_pixel_2bpp(&lockrect, 0, 0, 0xc36d);
1046 check_pixel_2bpp(&lockrect, 1, 0, 0x23cb);
1047 check_pixel_2bpp(&lockrect, 0, 1, 0x09af);
1048 check_pixel_2bpp(&lockrect, 1, 1, 0x8d61);
1049 hr = IDirect3DSurface9_UnlockRect(surf);
1050 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1052 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
1053 D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
1054 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1055 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1056 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1057 check_pixel_2bpp(&lockrect, 0, 0, 0x558c);
1058 check_pixel_2bpp(&lockrect, 1, 0, 0x5565);
1059 check_pixel_2bpp(&lockrect, 0, 1, 0xaa95);
1060 check_pixel_2bpp(&lockrect, 1, 1, 0xffcb);
1061 hr = IDirect3DSurface9_UnlockRect(surf);
1062 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1064 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
1065 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
1066 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1067 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1068 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1069 check_pixel_2bpp(&lockrect, 0, 0, 0xff00);
1070 check_pixel_2bpp(&lockrect, 1, 0, 0x00ff);
1071 check_pixel_2bpp(&lockrect, 0, 1, 0xff30);
1072 check_pixel_2bpp(&lockrect, 1, 1, 0x7f7f);
1073 hr = IDirect3DSurface9_UnlockRect(surf);
1074 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1076 check_release((IUnknown*)surf, 1);
1077 check_release((IUnknown*)tex, 0);
1080 /* DXT1, DXT2, DXT3, DXT4, DXT5 */
1081 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf, NULL);
1082 if (FAILED(hr))
1083 skip("Failed to create R8G8B8 surface, hr %#x.\n", hr);
1084 else
1086 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, dds_24bit, sizeof(dds_24bit), NULL, D3DX_FILTER_NONE, 0, NULL);
1087 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1089 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT2, D3DPOOL_SYSTEMMEM, &tex, NULL);
1090 if (FAILED(hr))
1091 skip("Failed to create DXT2 texture, hr %#x.\n", hr);
1092 else
1094 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1095 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1096 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1097 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT2 format.\n");
1098 check_release((IUnknown*)newsurf, 1);
1099 check_release((IUnknown*)tex, 0);
1102 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT3, D3DPOOL_SYSTEMMEM, &tex, NULL);
1103 if (FAILED(hr))
1104 skip("Failed to create DXT3 texture, hr %#x.\n", hr);
1105 else
1107 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1108 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1109 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1110 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT3 format.\n");
1111 check_release((IUnknown*)newsurf, 1);
1112 check_release((IUnknown*)tex, 0);
1115 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT4, D3DPOOL_SYSTEMMEM, &tex, NULL);
1116 if (FAILED(hr))
1117 skip("Failed to create DXT4 texture, hr %#x.\n", hr);
1118 else
1120 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1121 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1122 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1123 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT4 format.\n");
1124 check_release((IUnknown*)newsurf, 1);
1125 check_release((IUnknown*)tex, 0);
1128 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &tex, NULL);
1129 if (FAILED(hr))
1130 skip("Failed to create DXT5 texture, hr %#x.\n", hr);
1131 else
1133 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1134 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1135 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1136 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT5 format.\n");
1137 check_release((IUnknown*)newsurf, 1);
1138 check_release((IUnknown*)tex, 0);
1141 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &tex, NULL);
1142 if (FAILED(hr))
1143 skip("Failed to create DXT1 texture, hr %#x.\n", hr);
1144 else
1146 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1147 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1148 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1149 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT1 format.\n");
1151 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
1152 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels from DXT1 format.\n");
1154 check_release((IUnknown*)newsurf, 1);
1155 check_release((IUnknown*)tex, 0);
1158 check_release((IUnknown*)surf, 0);
1161 /* cleanup */
1162 if(testdummy_ok) DeleteFileA("testdummy.bmp");
1163 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
1166 static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9 *device)
1168 HRESULT hr;
1169 RECT rect;
1170 ID3DXBuffer *buffer;
1171 IDirect3DSurface9 *surface;
1173 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1174 if (FAILED(hr)) {
1175 skip("Couldn't create surface\n");
1176 return;
1179 SetRect(&rect, 0, 0, 0, 0);
1180 hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_BMP, surface, NULL, &rect);
1181 /* fails with the debug version of d3d9 */
1182 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1183 if (SUCCEEDED(hr)) {
1184 DWORD size = ID3DXBuffer_GetBufferSize(buffer);
1185 ok(size > 0, "ID3DXBuffer_GetBufferSize returned %u, expected > 0\n", size);
1186 ID3DXBuffer_Release(buffer);
1189 IDirect3DSurface9_Release(surface);
1192 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
1194 HRESULT hr;
1195 IDirect3DSurface9 *surface;
1196 RECT rect;
1197 D3DLOCKED_RECT lock_rect;
1198 D3DXIMAGE_INFO image_info;
1199 const BYTE pixels[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
1200 0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
1201 DWORD pitch = sizeof(pixels) / 2;
1203 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1204 if (FAILED(hr)) {
1205 skip("Couldn't create surface\n");
1206 return;
1209 SetRect(&rect, 0, 0, 2, 2);
1210 hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, pixels, D3DFMT_R8G8B8, pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
1211 if (SUCCEEDED(hr)) {
1212 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, NULL);
1213 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1215 hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.bmp", NULL, D3DX_FILTER_NONE, 0, &image_info);
1216 ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
1217 if (FAILED(hr)) goto next_tests;
1219 ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
1220 ok(image_info.Height == 2, "Wrong height %u\n", image_info.Height);
1221 ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
1222 ok(image_info.ImageFileFormat == D3DXIFF_BMP, "Wrong file format %u\n", image_info.ImageFileFormat);
1224 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1225 ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
1226 if (FAILED(hr)) goto next_tests;
1228 ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
1229 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
1231 IDirect3DSurface9_UnlockRect(surface);
1232 } else skip("Couldn't fill surface\n");
1234 next_tests:
1235 hr = D3DXSaveSurfaceToFileA(NULL, D3DXIFF_BMP, surface, NULL, NULL);
1236 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1238 /* PPM and TGA are supported, even though MSDN claims they aren't */
1239 todo_wine {
1240 hr = D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM, surface, NULL, NULL);
1241 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1242 hr = D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA, surface, NULL, NULL);
1243 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1246 hr = D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS, surface, NULL, NULL);
1247 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1248 if (SUCCEEDED(hr)) {
1249 hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.dds", NULL, D3DX_FILTER_NONE, 0, &image_info);
1250 ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
1252 if (SUCCEEDED(hr)) {
1253 ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
1254 ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
1255 ok(image_info.ImageFileFormat == D3DXIFF_DDS, "Wrong file format %u\n", image_info.ImageFileFormat);
1257 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1258 ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
1259 if (SUCCEEDED(hr)) {
1260 ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
1261 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
1262 IDirect3DSurface9_UnlockRect(surface);
1265 } else skip("Couldn't save surface\n");
1267 hr = D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM + 1, surface, NULL, NULL);
1268 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1270 SetRect(&rect, 0, 0, 4, 4);
1271 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1272 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1273 SetRect(&rect, 2, 0, 1, 4);
1274 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1275 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1276 SetRect(&rect, 0, 2, 4, 1);
1277 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1278 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1279 SetRect(&rect, -1, -1, 2, 2);
1280 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1281 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1282 SetRect(&rect, 0, 0, 0, 0);
1283 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1284 /* fails when debug version of d3d9 is used */
1285 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1287 DeleteFileA("saved_surface.bmp");
1288 DeleteFileA("saved_surface.ppm");
1289 DeleteFileA("saved_surface.tga");
1290 DeleteFileA("saved_surface.dds");
1292 IDirect3DSurface9_Release(surface);
1295 START_TEST(surface)
1297 HWND wnd;
1298 IDirect3D9 *d3d;
1299 IDirect3DDevice9 *device;
1300 D3DPRESENT_PARAMETERS d3dpp;
1301 HRESULT hr;
1303 if (!(wnd = CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW, 0, 0,
1304 640, 480, NULL, NULL, NULL, NULL)))
1306 skip("Couldn't create application window\n");
1307 return;
1309 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1310 if (!d3d) {
1311 skip("Couldn't create IDirect3D9 object\n");
1312 DestroyWindow(wnd);
1313 return;
1316 ZeroMemory(&d3dpp, sizeof(d3dpp));
1317 d3dpp.Windowed = TRUE;
1318 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1319 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
1320 if(FAILED(hr)) {
1321 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1322 IDirect3D9_Release(d3d);
1323 DestroyWindow(wnd);
1324 return;
1327 test_D3DXGetImageInfo();
1328 test_D3DXLoadSurface(device);
1329 test_D3DXSaveSurfaceToFileInMemory(device);
1330 test_D3DXSaveSurfaceToFile(device);
1332 check_release((IUnknown*)device, 0);
1333 check_release((IUnknown*)d3d, 0);
1334 DestroyWindow(wnd);