kernel32: GetLongPathName should fail when called with a wildcard.
[wine.git] / dlls / d3dx9_36 / tests / surface.c
blob37c488b5adadebd6dec28de4fd044ac0ce165365
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 #define check_release(obj, exp) _check_release(__LINE__, obj, exp)
28 static inline void _check_release(unsigned int line, IUnknown *obj, int exp)
30 int ref = IUnknown_Release(obj);
31 ok_(__FILE__, line)(ref == exp, "Invalid refcount. Expected %d, got %d\n", exp, ref);
34 /* 1x1 bmp (1 bpp) */
35 static const unsigned char bmp_1bpp[] = {
36 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
37 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
38 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
39 0x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00,
40 0x00,0x00
43 /* 1x1 bmp (2 bpp) */
44 static const unsigned char bmp_2bpp[] = {
45 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
46 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x00,0x00,
47 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
48 0x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00,
49 0x00,0x00
52 /* 1x1 bmp (4 bpp) */
53 static const unsigned char bmp_4bpp[] = {
54 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
55 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00,
56 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
57 0x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00,
58 0x00,0x00
61 /* 1x1 bmp (8 bpp) */
62 static const unsigned char bmp_8bpp[] = {
63 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
64 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x08,0x00,0x00,0x00,
65 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
66 0x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00,
67 0x00,0x00
70 static const unsigned char png_grayscale[] =
72 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49,
73 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00,
74 0x00, 0x00, 0x00, 0x3a, 0x7e, 0x9b, 0x55, 0x00, 0x00, 0x00, 0x0a, 0x49, 0x44,
75 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8, 0x0f, 0x00, 0x01, 0x01, 0x01, 0x00, 0x1b,
76 0xb6, 0xee, 0x56, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42,
77 0x60, 0x82
80 /* 2x2 A8R8G8B8 pixel data */
81 static const unsigned char pixdata[] = {
82 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
85 /* invalid image file */
86 static const unsigned char noimage[4] = {
87 0x11,0x22,0x33,0x44
90 /* 2x2 24-bit dds, 2 mipmaps */
91 static const unsigned char dds_24bit[] = {
92 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00,
93 0x02,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
94 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
95 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
96 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
97 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
98 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
99 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
100 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
103 /* 2x2 16-bit dds, no mipmaps */
104 static const unsigned char dds_16bit[] = {
105 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
106 0x02,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
107 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
108 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
109 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
110 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,
111 0xe0,0x03,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
112 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
113 0xff,0x7f,0xff,0x7f,0xff,0x7f,0xff,0x7f
116 /* 4x4 cube map dds */
117 static const unsigned char dds_cube_map[] = {
118 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00,
119 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
120 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
121 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
122 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
123 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
124 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
125 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
126 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
127 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
128 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
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
134 /* 4x4x2 volume map dds, 2 mipmaps */
135 static const unsigned char dds_volume_map[] = {
136 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
137 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
138 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
139 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
140 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
141 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
142 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
143 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
144 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
145 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
146 0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
147 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
150 static HRESULT create_file(const char *filename, const unsigned char *data, const unsigned int size)
152 DWORD received;
153 HANDLE hfile;
155 hfile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
156 if(hfile == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError());
158 if(WriteFile(hfile, data, size, &received, NULL))
160 CloseHandle(hfile);
161 return D3D_OK;
164 CloseHandle(hfile);
165 return D3DERR_INVALIDCALL;
168 /* dds_header.flags */
169 #define DDS_CAPS 0x00000001
170 #define DDS_HEIGHT 0x00000002
171 #define DDS_WIDTH 0x00000004
172 #define DDS_PITCH 0x00000008
173 #define DDS_PIXELFORMAT 0x00001000
174 #define DDS_MIPMAPCOUNT 0x00020000
175 #define DDS_LINEARSIZE 0x00080000
177 /* dds_header.caps */
178 #define DDSCAPS_ALPHA 0x00000002
179 #define DDS_CAPS_TEXTURE 0x00001000
181 /* dds_pixel_format.flags */
182 #define DDS_PF_ALPHA 0x00000001
183 #define DDS_PF_ALPHA_ONLY 0x00000002
184 #define DDS_PF_FOURCC 0x00000004
185 #define DDS_PF_RGB 0x00000040
186 #define DDS_PF_LUMINANCE 0x00020000
187 #define DDS_PF_BUMPDUDV 0x00080000
189 struct dds_pixel_format
191 DWORD size;
192 DWORD flags;
193 DWORD fourcc;
194 DWORD bpp;
195 DWORD rmask;
196 DWORD gmask;
197 DWORD bmask;
198 DWORD amask;
201 struct dds_header
203 DWORD size;
204 DWORD flags;
205 DWORD height;
206 DWORD width;
207 DWORD pitch_or_linear_size;
208 DWORD depth;
209 DWORD miplevels;
210 DWORD reserved[11];
211 struct dds_pixel_format pixel_format;
212 DWORD caps;
213 DWORD caps2;
214 DWORD caps3;
215 DWORD caps4;
216 DWORD reserved2;
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->size = sizeof(*header);
225 header->flags = DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT;
226 header->height = 4;
227 header->width = 4;
228 header->pixel_format.size = sizeof(header->pixel_format);
229 /* X8R8G8B8 */
230 header->pixel_format.flags = DDS_PF_RGB;
231 header->pixel_format.fourcc = 0;
232 header->pixel_format.bpp = 32;
233 header->pixel_format.rmask = 0xff0000;
234 header->pixel_format.gmask = 0x00ff00;
235 header->pixel_format.bmask = 0x0000ff;
236 header->pixel_format.amask = 0;
237 header->caps = DDS_CAPS_TEXTURE;
240 #define check_dds_pixel_format(flags, fourcc, bpp, rmask, gmask, bmask, amask, format) \
241 check_dds_pixel_format_(__LINE__, flags, fourcc, bpp, rmask, gmask, bmask, amask, format)
242 static void check_dds_pixel_format_(unsigned int line,
243 DWORD flags, DWORD fourcc, DWORD bpp,
244 DWORD rmask, DWORD gmask, DWORD bmask, DWORD amask,
245 D3DFORMAT expected_format)
247 HRESULT hr;
248 D3DXIMAGE_INFO info;
249 struct
251 DWORD magic;
252 struct dds_header header;
253 BYTE data[256];
254 } dds;
256 dds.magic = MAKEFOURCC('D','D','S',' ');
257 fill_dds_header(&dds.header);
258 dds.header.pixel_format.flags = flags;
259 dds.header.pixel_format.fourcc = fourcc;
260 dds.header.pixel_format.bpp = bpp;
261 dds.header.pixel_format.rmask = rmask;
262 dds.header.pixel_format.gmask = gmask;
263 dds.header.pixel_format.bmask = bmask;
264 dds.header.pixel_format.amask = amask;
265 memset(dds.data, 0, sizeof(dds.data));
267 hr = D3DXGetImageInfoFromFileInMemory(&dds, sizeof(dds), &info);
268 ok_(__FILE__, line)(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x for pixel format %#x, expected %#x\n",
269 hr, expected_format, D3D_OK);
270 if (SUCCEEDED(hr))
272 ok_(__FILE__, line)(info.Format == expected_format, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n",
273 info.Format, expected_format);
277 static void test_dds_header_handling(void)
279 int i;
280 HRESULT hr;
281 D3DXIMAGE_INFO info;
282 struct
284 DWORD magic;
285 struct dds_header header;
286 BYTE data[4096 * 1024];
287 } *dds;
289 struct
291 struct dds_pixel_format pixel_format;
292 DWORD flags;
293 DWORD width;
294 DWORD height;
295 DWORD pitch;
296 DWORD miplevels;
297 DWORD pixel_data_size;
298 struct
300 HRESULT hr;
301 UINT miplevels;
303 expected;
304 } tests[] = {
305 /* pitch is ignored */
306 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, 0, 4, 4, 0, 0,
307 63 /* pixel data size */, { D3DXERR_INVALIDDATA, 0 } },
308 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 0 /* pitch */, 0,
309 64, { D3D_OK, 1 } },
310 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1 /* pitch */, 0,
311 64, { D3D_OK, 1 } },
312 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 2 /* pitch */, 0,
313 64, { D3D_OK, 1 } },
314 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 3 /* pitch */, 0,
315 64, { D3D_OK, 1 } },
316 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 4 /* pitch */, 0,
317 64, { D3D_OK, 1 } },
318 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 16 /* pitch */, 0,
319 64, { D3D_OK, 1 } },
320 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1024 /* pitch */, 0,
321 64, { D3D_OK, 1 } },
322 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, -1 /* pitch */, 0,
323 64, { D3D_OK, 1 } },
324 /* linear size is ignored */
325 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, 0, 4, 4, 0, 0,
326 7 /* pixel data size */, { D3DXERR_INVALIDDATA, 1 } },
327 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 0 /* linear size */, 0,
328 8, { D3D_OK, 1 } },
329 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 1 /* linear size */, 0,
330 8, { D3D_OK, 1 } },
331 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 2 /* linear size */, 0,
332 8, { D3D_OK, 1 } },
333 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 9 /* linear size */, 0,
334 8, { D3D_OK, 1 } },
335 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 16 /* linear size */, 0,
336 8, { D3D_OK, 1 } },
337 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, -1 /* linear size */, 0,
338 8, { D3D_OK, 1 } },
339 /* integer overflows */
340 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000000, 0x80000000 /* 0x80000000 * 0x80000000 * 4 = 0 */, 0, 0,
341 64, { D3D_OK, 1 } },
342 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x8000100, 0x800100 /* 0x8000100 * 0x800100 * 4 = 262144 */, 0, 0,
343 64, { D3DXERR_INVALIDDATA, 0 } },
344 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0, 0,
345 4, { D3D_OK, 1 } },
346 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0, 0,
347 3 /* pixel data size */, { D3DXERR_INVALIDDATA, 0 } },
348 /* file size is validated */
349 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 64, 0, 0, 49151, { D3DXERR_INVALIDDATA, 0 } },
350 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 64, 0, 0, 49152, { D3D_OK, 1 } },
351 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 64, 0, 4, 65279, { D3DXERR_INVALIDDATA, 0 } },
352 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 64, 0, 4, 65280, { D3D_OK, 4 } },
353 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 64, 0, 9, 65540, { D3DXERR_INVALIDDATA, 0 } },
354 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 64, 0, 9, 65541, { D3D_OK, 9 } },
355 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196607, { D3DXERR_INVALIDDATA, 0 } },
356 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196608, { D3D_OK, 1 } },
357 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196609, { D3D_OK, 1 } },
358 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 1, 196607, { D3DXERR_INVALIDDATA, 0 } },
359 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 1, 196608, { D3D_OK, 1 } },
360 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 196607, { D3DXERR_INVALIDDATA, 0 } },
361 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 196608, { D3D_OK, 1 } },
362 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 400000, { D3D_OK, 1 } },
363 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 9, 262142, { D3DXERR_INVALIDDATA, 0 } },
364 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 9, 262143, { D3D_OK, 9 } },
365 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 10, 262145, { D3DXERR_INVALIDDATA, 0 } },
366 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 10, 262146, { D3D_OK, 10 } },
367 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 262175, { D3DXERR_INVALIDDATA, 0 } },
368 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 262176, { D3D_OK, 20 } },
369 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 32767, { D3DXERR_INVALIDDATA, 0 } },
370 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 32768, { D3D_OK, 1 } },
371 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 32767, { D3DXERR_INVALIDDATA, 0 } },
372 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 32768, { D3D_OK, 1 } },
373 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 9, 43703, { D3DXERR_INVALIDDATA, 0 } },
374 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 9, 43704, { D3D_OK, 9 } },
375 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 43791, { D3DXERR_INVALIDDATA, 0 } },
376 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 43792, { D3D_OK, 20 } },
377 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 65535, { D3DXERR_INVALIDDATA, 0 } },
378 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 65536, { D3D_OK, 1 } },
379 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 65535, { D3DXERR_INVALIDDATA, 0 } },
380 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 65536, { D3D_OK, 1 } },
381 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 9, 87407, { D3DXERR_INVALIDDATA, 0 } },
382 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 9, 87408, { D3D_OK, 9 } },
383 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 87583, { D3DXERR_INVALIDDATA, 0 } },
384 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 87584, { D3D_OK, 20 } },
385 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 64, 0, 4, 21759, { D3DXERR_INVALIDDATA, 0 } },
386 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 64, 0, 4, 21760, { D3D_OK, 4 } },
387 /* DDS_MIPMAPCOUNT is ignored */
388 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 262146, { D3D_OK, 1 } },
389 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 2, 262146, { D3D_OK, 2 } },
390 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 9, 262146, { D3D_OK, 9 } },
391 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 10, 262146, { D3D_OK, 10 } },
394 dds = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*dds));
395 if (!dds)
397 skip("Failed to allocate memory.\n");
398 return;
401 for (i = 0; i < ARRAY_SIZE(tests); i++)
403 DWORD file_size = sizeof(dds->magic) + sizeof(dds->header) + tests[i].pixel_data_size;
404 assert(file_size <= sizeof(*dds));
406 dds->magic = MAKEFOURCC('D','D','S',' ');
407 fill_dds_header(&dds->header);
408 dds->header.flags |= tests[i].flags;
409 dds->header.width = tests[i].width;
410 dds->header.height = tests[i].height;
411 dds->header.pitch_or_linear_size = tests[i].pitch;
412 dds->header.miplevels = tests[i].miplevels;
413 dds->header.pixel_format = tests[i].pixel_format;
415 hr = D3DXGetImageInfoFromFileInMemory(dds, file_size, &info);
416 ok(hr == tests[i].expected.hr, "%d: D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n",
417 i, hr, tests[i].expected.hr);
418 if (SUCCEEDED(hr))
420 ok(info.MipLevels == tests[i].expected.miplevels, "%d: Got MipLevels %u, expected %u\n",
421 i, info.MipLevels, tests[i].expected.miplevels);
425 HeapFree(GetProcessHeap(), 0, dds);
428 static void test_D3DXGetImageInfo(void)
430 HRESULT hr;
431 D3DXIMAGE_INFO info;
432 BOOL testdummy_ok, testbitmap_ok;
434 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
435 testdummy_ok = SUCCEEDED(hr);
437 hr = create_file("testbitmap.bmp", bmp_1bpp, sizeof(bmp_1bpp)); /* valid image */
438 testbitmap_ok = SUCCEEDED(hr);
440 /* D3DXGetImageInfoFromFile */
441 if(testbitmap_ok) {
442 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", &info);
443 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
445 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL); /* valid image, second parameter is NULL */
446 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
447 } else skip("Couldn't create \"testbitmap.bmp\"\n");
449 if(testdummy_ok) {
450 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", NULL); /* invalid image, second parameter is NULL */
451 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
453 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", &info);
454 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
455 } else skip("Couldn't create \"testdummy.bmp\"\n");
457 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info);
458 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
460 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL);
461 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
463 hr = D3DXGetImageInfoFromFileA("", &info);
464 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
466 hr = D3DXGetImageInfoFromFileA(NULL, &info);
467 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
469 hr = D3DXGetImageInfoFromFileA(NULL, NULL);
470 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
473 /* D3DXGetImageInfoFromResource */
474 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &info); /* RT_BITMAP */
475 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
477 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL);
478 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
480 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &info); /* RT_RCDATA */
481 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
483 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), &info);
484 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
486 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), NULL);
487 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
489 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", &info);
490 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
492 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", NULL);
493 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
495 hr = D3DXGetImageInfoFromResourceA(NULL, NULL, NULL);
496 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
499 /* D3DXGetImageInfoFromFileInMemory */
500 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp), &info);
501 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
503 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp)+5, &info); /* too large size */
504 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
506 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp), NULL);
507 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
509 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), NULL);
510 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
512 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), &info);
513 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
515 todo_wine {
516 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp)-1, &info);
517 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
520 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp+1, sizeof(bmp_1bpp)-1, &info);
521 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
523 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, 0, &info);
524 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
526 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, 0, NULL);
527 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
529 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, &info);
530 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
532 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, NULL);
533 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
535 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, &info);
536 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
538 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, NULL);
539 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
541 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, &info);
542 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
544 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, NULL);
545 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
547 /* test BMP support */
548 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp), &info);
549 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
550 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
551 ok(info.Format == D3DFMT_P8, "Got format %u, expected %u\n", info.Format, D3DFMT_P8);
552 hr = D3DXGetImageInfoFromFileInMemory(bmp_2bpp, sizeof(bmp_2bpp), &info);
553 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
554 hr = D3DXGetImageInfoFromFileInMemory(bmp_4bpp, sizeof(bmp_4bpp), &info);
555 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
556 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
557 ok(info.Format == D3DFMT_P8, "Got format %u, expected %u\n", info.Format, D3DFMT_P8);
558 hr = D3DXGetImageInfoFromFileInMemory(bmp_8bpp, sizeof(bmp_8bpp), &info);
559 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
560 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
561 ok(info.Format == D3DFMT_P8, "Got format %u, expected %u\n", info.Format, D3DFMT_P8);
563 /* Grayscale PNG */
564 hr = D3DXGetImageInfoFromFileInMemory(png_grayscale, sizeof(png_grayscale), &info);
565 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
566 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
567 ok(info.Format == D3DFMT_L8, "Got format %u, expected %u\n", info.Format, D3DFMT_L8);
569 /* test DDS support */
570 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit), &info);
571 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
572 if (hr == D3D_OK) {
573 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
574 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
575 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
576 ok(info.MipLevels == 2, "Got miplevels %u, expected 2\n", info.MipLevels);
577 ok(info.Format == D3DFMT_R8G8B8, "Got format %#x, expected %#x\n", info.Format, D3DFMT_R8G8B8);
578 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
579 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
580 } else skip("Couldn't get image info from 24-bit DDS file in memory\n");
582 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit), &info);
583 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
584 if (hr == D3D_OK) {
585 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
586 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
587 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
588 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
589 ok(info.Format == D3DFMT_X1R5G5B5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_X1R5G5B5);
590 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
591 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
592 } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
594 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map), &info);
595 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
596 if (hr == D3D_OK) {
597 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
598 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
599 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
600 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
601 ok(info.Format == D3DFMT_DXT5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT5);
602 ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
603 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
604 } else skip("Couldn't get image info from cube map in memory\n");
606 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map), &info);
607 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
608 if (hr == D3D_OK) {
609 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
610 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
611 ok(info.Depth == 2, "Got depth %u, expected 2\n", info.Depth);
612 ok(info.MipLevels == 3, "Got miplevels %u, expected 3\n", info.MipLevels);
613 ok(info.Format == D3DFMT_DXT3, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT3);
614 ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
615 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
616 } else skip("Couldn't get image info from volume map in memory\n");
618 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0, D3DFMT_DXT1);
619 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_DXT2, 0, 0, 0, 0, 0, D3DFMT_DXT2);
620 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_DXT3, 0, 0, 0, 0, 0, D3DFMT_DXT3);
621 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0, D3DFMT_DXT4);
622 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_DXT5, 0, 0, 0, 0, 0, D3DFMT_DXT5);
623 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8);
624 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8);
625 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0, D3DFMT_UYVY);
626 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0, D3DFMT_YUY2);
627 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5);
628 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5);
629 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4);
630 check_dds_pixel_format(DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2);
631 check_dds_pixel_format(DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff, D3DFMT_A8);
632 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2);
633 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf00, 0x0f0, 0x00f, 0, D3DFMT_X4R4G4B4);
634 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10);
635 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10);
636 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8);
637 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, D3DFMT_A8B8G8R8);
638 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_X8R8G8B8);
639 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8B8G8R8);
640 check_dds_pixel_format(DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_R8G8B8);
641 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_G16R16);
642 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8);
643 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16);
644 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8);
645 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4);
646 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8);
647 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16);
649 test_dds_header_handling();
651 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit) - 1, &info);
652 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
654 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit) - 1, &info);
655 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
657 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map) - 1, &info);
658 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
660 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map) - 1, &info);
661 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
664 /* cleanup */
665 if(testdummy_ok) DeleteFileA("testdummy.bmp");
666 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
669 #define check_pixel_2bpp(lockrect, x, y, color) _check_pixel_2bpp(__LINE__, lockrect, x, y, color)
670 static inline void _check_pixel_2bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, WORD expected_color)
672 WORD color = ((WORD*)lockrect->pBits)[x + y * lockrect->Pitch / 2];
673 ok_(__FILE__, line)(color == expected_color, "Got color 0x%04x, expected 0x%04x\n", color, expected_color);
676 #define check_pixel_4bpp(lockrect, x, y, color) _check_pixel_4bpp(__LINE__, lockrect, x, y, color)
677 static inline void _check_pixel_4bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, DWORD expected_color)
679 DWORD color = ((DWORD*)lockrect->pBits)[x + y * lockrect->Pitch / 4];
680 ok_(__FILE__, line)(color == expected_color, "Got color 0x%08x, expected 0x%08x\n", color, expected_color);
683 static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
685 HRESULT hr;
686 BOOL testdummy_ok, testbitmap_ok;
687 IDirect3DTexture9 *tex;
688 IDirect3DSurface9 *surf, *newsurf;
689 RECT rect, destrect;
690 D3DLOCKED_RECT lockrect;
691 const WORD pixdata_a8r3g3b2[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
692 const WORD pixdata_a1r5g5b5[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
693 const WORD pixdata_r5g6b5[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
694 const WORD pixdata_a8l8[] = { 0xff00, 0x00ff, 0xff30, 0x7f7f };
695 const DWORD pixdata_g16r16[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
696 const DWORD pixdata_a8b8g8r8[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
697 const DWORD pixdata_a2r10g10b10[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
699 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
700 testdummy_ok = SUCCEEDED(hr);
702 hr = create_file("testbitmap.bmp", bmp_1bpp, sizeof(bmp_1bpp)); /* valid image */
703 testbitmap_ok = SUCCEEDED(hr);
705 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
706 if(FAILED(hr)) {
707 skip("Failed to create a surface (%#x)\n", hr);
708 if(testdummy_ok) DeleteFileA("testdummy.bmp");
709 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
710 return;
713 /* D3DXLoadSurfaceFromFile */
714 if(testbitmap_ok) {
715 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
716 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3D_OK);
718 hr = D3DXLoadSurfaceFromFileA(NULL, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
719 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
720 } else skip("Couldn't create \"testbitmap.bmp\"\n");
722 if(testdummy_ok) {
723 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testdummy.bmp", NULL, D3DX_DEFAULT, 0, NULL);
724 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
725 } else skip("Couldn't create \"testdummy.bmp\"\n");
727 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
728 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
730 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "", NULL, D3DX_DEFAULT, 0, NULL);
731 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
734 /* D3DXLoadSurfaceFromResource */
735 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL,
736 MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
737 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
739 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL,
740 MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL, D3DX_DEFAULT, 0, NULL);
741 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
743 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
744 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
746 hr = D3DXLoadSurfaceFromResourceA(NULL, NULL, NULL, NULL,
747 MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
748 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
750 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL,
751 MAKEINTRESOURCEA(IDS_STRING), NULL, D3DX_DEFAULT, 0, NULL);
752 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
755 /* D3DXLoadSurfaceFromFileInMemory */
756 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp_1bpp, sizeof(bmp_1bpp), NULL, D3DX_DEFAULT, 0, NULL);
757 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
759 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, noimage, sizeof(noimage), NULL, D3DX_DEFAULT, 0, NULL);
760 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
762 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp_1bpp, 0, NULL, D3DX_DEFAULT, 0, NULL);
763 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
765 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, bmp_1bpp, sizeof(bmp_1bpp), NULL, D3DX_DEFAULT, 0, NULL);
766 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
768 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 8, NULL, D3DX_DEFAULT, 0, NULL);
769 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
771 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
772 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
774 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
775 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
778 /* D3DXLoadSurfaceFromMemory */
779 SetRect(&rect, 0, 0, 2, 2);
781 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
782 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
784 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, 0, NULL, &rect, D3DX_FILTER_NONE, 0);
785 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
787 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, NULL, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
788 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
790 hr = D3DXLoadSurfaceFromMemory(NULL, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
791 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
793 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, NULL, D3DX_DEFAULT, 0);
794 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
796 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_UNKNOWN, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
797 ok(hr == E_FAIL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, E_FAIL);
799 SetRect(&destrect, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
800 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
801 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
803 SetRect(&destrect, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
804 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
805 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
807 SetRect(&destrect, 1, 1, 0, 0); /* left > right, top > bottom */
808 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
809 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
811 SetRect(&destrect, 1, 2, 1, 2); /* left = right, top = bottom */
812 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
813 /* fails when debug version of d3d9 is used */
814 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
816 SetRect(&destrect, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
817 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
818 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
821 /* D3DXLoadSurfaceFromSurface */
822 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newsurf, NULL);
823 if(SUCCEEDED(hr)) {
824 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
825 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
827 hr = D3DXLoadSurfaceFromSurface(NULL, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
828 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
830 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0);
831 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
833 check_release((IUnknown*)newsurf, 0);
834 } else skip("Failed to create a second surface\n");
836 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
837 if (SUCCEEDED(hr))
839 IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
841 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
842 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
844 IDirect3DSurface9_Release(newsurf);
845 IDirect3DTexture9_Release(tex);
846 } else skip("Failed to create texture\n");
848 /* non-lockable render target */
849 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &newsurf, NULL);
850 if (SUCCEEDED(hr)) {
851 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
852 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
854 IDirect3DSurface9_Release(newsurf);
855 } else skip("Failed to create render target surface\n");
857 /* non-lockable multisampled render target */
858 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &newsurf, NULL);
859 if (SUCCEEDED(hr)) {
860 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
861 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
863 IDirect3DSurface9_Release(newsurf);
864 } else skip("Failed to create multisampled render target\n");
866 check_release((IUnknown*)surf, 0);
869 /* test color conversion */
870 /* A8R8G8B8 */
871 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
872 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
873 else {
874 PALETTEENTRY palette;
876 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
877 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
878 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
879 check_pixel_4bpp(&lockrect, 0, 0, 0x57dbffff);
880 check_pixel_4bpp(&lockrect, 1, 0, 0x98ffff00);
881 check_pixel_4bpp(&lockrect, 0, 1, 0xacdbff55);
882 check_pixel_4bpp(&lockrect, 1, 1, 0xc8929255);
883 IDirect3DSurface9_UnlockRect(surf);
885 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
886 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
887 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
888 check_pixel_4bpp(&lockrect, 0, 0, 0x008cadad);
889 check_pixel_4bpp(&lockrect, 1, 0, 0xff317342);
890 check_pixel_4bpp(&lockrect, 0, 1, 0x0008ad10);
891 check_pixel_4bpp(&lockrect, 1, 1, 0xff29088c);
892 IDirect3DSurface9_UnlockRect(surf);
894 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
895 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
896 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
897 check_pixel_4bpp(&lockrect, 0, 0, 0xff9cdfb5);
898 check_pixel_4bpp(&lockrect, 1, 0, 0xff63b26b);
899 check_pixel_4bpp(&lockrect, 0, 1, 0xff085d73);
900 check_pixel_4bpp(&lockrect, 1, 1, 0xff425d73);
901 IDirect3DSurface9_UnlockRect(surf);
903 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
904 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
905 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
906 todo_wine {
907 check_pixel_4bpp(&lockrect, 0, 0, 0xff3f08ff);
909 check_pixel_4bpp(&lockrect, 1, 0, 0xff44dcff);
910 check_pixel_4bpp(&lockrect, 0, 1, 0xff97e4ff);
911 check_pixel_4bpp(&lockrect, 1, 1, 0xfffe9aff);
912 IDirect3DSurface9_UnlockRect(surf);
914 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
915 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
916 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
917 check_pixel_4bpp(&lockrect, 0, 0, 0xc3f04c39);
918 check_pixel_4bpp(&lockrect, 1, 0, 0x2392e85a);
919 check_pixel_4bpp(&lockrect, 0, 1, 0x09fd97b1);
920 check_pixel_4bpp(&lockrect, 1, 1, 0x8df62bc3);
921 IDirect3DSurface9_UnlockRect(surf);
923 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
924 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
925 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
926 check_pixel_4bpp(&lockrect, 0, 0, 0x555c95bf);
927 check_pixel_4bpp(&lockrect, 1, 0, 0x556d663f);
928 check_pixel_4bpp(&lockrect, 0, 1, 0xaac385ad);
929 todo_wine {
930 check_pixel_4bpp(&lockrect, 1, 1, 0xfffcc575);
932 IDirect3DSurface9_UnlockRect(surf);
934 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
935 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
936 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
937 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
938 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
939 check_pixel_4bpp(&lockrect, 0, 0, 0xff000000);
940 check_pixel_4bpp(&lockrect, 1, 0, 0x00ffffff);
941 check_pixel_4bpp(&lockrect, 0, 1, 0xff303030);
942 check_pixel_4bpp(&lockrect, 1, 1, 0x7f7f7f7f);
943 hr = IDirect3DSurface9_UnlockRect(surf);
944 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
946 /* Test D3DXLoadSurfaceFromMemory with indexed color image */
947 if (0)
949 /* Crashes on Nvidia Win10. */
950 palette.peRed = bmp_1bpp[56];
951 palette.peGreen = bmp_1bpp[55];
952 palette.peBlue = bmp_1bpp[54];
953 palette.peFlags = bmp_1bpp[57]; /* peFlags is the alpha component in DX8 and higher */
954 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, &bmp_1bpp[62],
955 D3DFMT_P8, 1, (const PALETTEENTRY *)&palette, &rect, D3DX_FILTER_NONE, 0);
956 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
957 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
958 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x\n", hr);
959 ok(*(DWORD*)lockrect.pBits == 0x80f3f2f1, "Pixel color mismatch: got %#x, expected 0x80f3f2f1\n", *(DWORD*)lockrect.pBits);
960 hr = IDirect3DSurface9_UnlockRect(surf);
961 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x\n", hr);
964 /* Test D3DXLoadSurfaceFromFileInMemory with indexed color image (alpha is not taken into account for bmp file) */
965 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp_1bpp, sizeof(bmp_1bpp), NULL, D3DX_FILTER_NONE, 0, NULL);
966 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
967 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
968 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x\n", hr);
969 ok(*(DWORD*)lockrect.pBits == 0xfff3f2f1, "Pixel color mismatch: got %#x, expected 0xfff3f2f1\n", *(DWORD*)lockrect.pBits);
970 hr = IDirect3DSurface9_UnlockRect(surf);
971 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x\n", hr);
973 check_release((IUnknown*)surf, 0);
976 /* A1R5G5B5 */
977 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A1R5G5B5, D3DPOOL_DEFAULT, &surf, NULL);
978 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
979 else {
980 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
981 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
982 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
983 check_pixel_2bpp(&lockrect, 0, 0, 0x6fff);
984 check_pixel_2bpp(&lockrect, 1, 0, 0xffe0);
985 check_pixel_2bpp(&lockrect, 0, 1, 0xefea);
986 check_pixel_2bpp(&lockrect, 1, 1, 0xca4a);
987 IDirect3DSurface9_UnlockRect(surf);
989 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
990 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
991 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
992 check_pixel_2bpp(&lockrect, 0, 0, 0x46b5);
993 check_pixel_2bpp(&lockrect, 1, 0, 0x99c8);
994 check_pixel_2bpp(&lockrect, 0, 1, 0x06a2);
995 check_pixel_2bpp(&lockrect, 1, 1, 0x9431);
996 IDirect3DSurface9_UnlockRect(surf);
998 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
999 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1000 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1001 check_pixel_2bpp(&lockrect, 0, 0, 0xcf76);
1002 check_pixel_2bpp(&lockrect, 1, 0, 0xb2cd);
1003 check_pixel_2bpp(&lockrect, 0, 1, 0x856e);
1004 check_pixel_2bpp(&lockrect, 1, 1, 0xa16e);
1005 IDirect3DSurface9_UnlockRect(surf);
1007 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
1008 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1009 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1010 todo_wine {
1011 check_pixel_2bpp(&lockrect, 0, 0, 0xa03f);
1013 check_pixel_2bpp(&lockrect, 1, 0, 0xa37f);
1014 check_pixel_2bpp(&lockrect, 0, 1, 0xcb9f);
1015 check_pixel_2bpp(&lockrect, 1, 1, 0xfe7f);
1016 IDirect3DSurface9_UnlockRect(surf);
1018 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
1019 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1020 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1021 todo_wine {
1022 check_pixel_2bpp(&lockrect, 0, 0, 0xf527);
1023 check_pixel_2bpp(&lockrect, 1, 0, 0x4b8b);
1025 check_pixel_2bpp(&lockrect, 0, 1, 0x7e56);
1026 check_pixel_2bpp(&lockrect, 1, 1, 0xf8b8);
1027 IDirect3DSurface9_UnlockRect(surf);
1029 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
1030 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1031 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1032 check_pixel_2bpp(&lockrect, 0, 0, 0x2e57);
1033 todo_wine {
1034 check_pixel_2bpp(&lockrect, 1, 0, 0x3588);
1036 check_pixel_2bpp(&lockrect, 0, 1, 0xe215);
1037 check_pixel_2bpp(&lockrect, 1, 1, 0xff0e);
1038 IDirect3DSurface9_UnlockRect(surf);
1040 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
1041 D3DFMT_A8L8, 4, 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, 0x8000);
1046 check_pixel_2bpp(&lockrect, 1, 0, 0x7fff);
1047 check_pixel_2bpp(&lockrect, 0, 1, 0x98c6);
1048 check_pixel_2bpp(&lockrect, 1, 1, 0x3def);
1049 hr = IDirect3DSurface9_UnlockRect(surf);
1050 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1052 check_release((IUnknown*)surf, 0);
1055 /* A8L8 */
1056 hr = IDirect3DDevice9_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8L8, D3DPOOL_MANAGED, &tex, NULL);
1057 if (FAILED(hr))
1058 skip("Failed to create A8L8 texture, hr %#x.\n", hr);
1059 else
1061 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &surf);
1062 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1064 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
1065 D3DFMT_A8R3G3B2, 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, 0x57f7);
1070 check_pixel_2bpp(&lockrect, 1, 0, 0x98ed);
1071 check_pixel_2bpp(&lockrect, 0, 1, 0xaceb);
1072 check_pixel_2bpp(&lockrect, 1, 1, 0xc88d);
1073 hr = IDirect3DSurface9_UnlockRect(surf);
1074 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1076 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
1077 D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
1078 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1079 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1080 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1081 check_pixel_2bpp(&lockrect, 0, 0, 0x00a6);
1082 check_pixel_2bpp(&lockrect, 1, 0, 0xff62);
1083 check_pixel_2bpp(&lockrect, 0, 1, 0x007f);
1084 check_pixel_2bpp(&lockrect, 1, 1, 0xff19);
1085 hr = IDirect3DSurface9_UnlockRect(surf);
1086 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1088 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
1089 D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
1090 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1091 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1092 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1093 check_pixel_2bpp(&lockrect, 0, 0, 0xffce);
1094 check_pixel_2bpp(&lockrect, 1, 0, 0xff9c);
1095 check_pixel_2bpp(&lockrect, 0, 1, 0xff4d);
1096 check_pixel_2bpp(&lockrect, 1, 1, 0xff59);
1097 hr = IDirect3DSurface9_UnlockRect(surf);
1098 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1100 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
1101 D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
1102 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1103 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1104 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1105 check_pixel_2bpp(&lockrect, 0, 0, 0xff25);
1106 check_pixel_2bpp(&lockrect, 1, 0, 0xffbe);
1107 check_pixel_2bpp(&lockrect, 0, 1, 0xffd6);
1108 check_pixel_2bpp(&lockrect, 1, 1, 0xffb6);
1109 hr = IDirect3DSurface9_UnlockRect(surf);
1110 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1112 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
1113 D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
1114 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1115 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1116 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1117 check_pixel_2bpp(&lockrect, 0, 0, 0xc36d);
1118 check_pixel_2bpp(&lockrect, 1, 0, 0x23cb);
1119 check_pixel_2bpp(&lockrect, 0, 1, 0x09af);
1120 check_pixel_2bpp(&lockrect, 1, 1, 0x8d61);
1121 hr = IDirect3DSurface9_UnlockRect(surf);
1122 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1124 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
1125 D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
1126 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1127 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1128 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1129 check_pixel_2bpp(&lockrect, 0, 0, 0x558c);
1130 check_pixel_2bpp(&lockrect, 1, 0, 0x5565);
1131 check_pixel_2bpp(&lockrect, 0, 1, 0xaa95);
1132 check_pixel_2bpp(&lockrect, 1, 1, 0xffcb);
1133 hr = IDirect3DSurface9_UnlockRect(surf);
1134 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1136 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
1137 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
1138 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1139 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
1140 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1141 check_pixel_2bpp(&lockrect, 0, 0, 0xff00);
1142 check_pixel_2bpp(&lockrect, 1, 0, 0x00ff);
1143 check_pixel_2bpp(&lockrect, 0, 1, 0xff30);
1144 check_pixel_2bpp(&lockrect, 1, 1, 0x7f7f);
1145 hr = IDirect3DSurface9_UnlockRect(surf);
1146 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1148 check_release((IUnknown*)surf, 1);
1149 check_release((IUnknown*)tex, 0);
1152 /* DXT1, DXT2, DXT3, DXT4, DXT5 */
1153 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf, NULL);
1154 if (FAILED(hr))
1155 skip("Failed to create R8G8B8 surface, hr %#x.\n", hr);
1156 else
1158 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, dds_24bit, sizeof(dds_24bit), NULL, D3DX_FILTER_NONE, 0, NULL);
1159 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1161 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT2, D3DPOOL_SYSTEMMEM, &tex, NULL);
1162 if (FAILED(hr))
1163 skip("Failed to create DXT2 texture, hr %#x.\n", hr);
1164 else
1166 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1167 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1168 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1169 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT2 format.\n");
1170 check_release((IUnknown*)newsurf, 1);
1171 check_release((IUnknown*)tex, 0);
1174 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT3, D3DPOOL_SYSTEMMEM, &tex, NULL);
1175 if (FAILED(hr))
1176 skip("Failed to create DXT3 texture, hr %#x.\n", hr);
1177 else
1179 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1180 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1181 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1182 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT3 format.\n");
1183 check_release((IUnknown*)newsurf, 1);
1184 check_release((IUnknown*)tex, 0);
1187 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT4, D3DPOOL_SYSTEMMEM, &tex, NULL);
1188 if (FAILED(hr))
1189 skip("Failed to create DXT4 texture, hr %#x.\n", hr);
1190 else
1192 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1193 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1194 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1195 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT4 format.\n");
1196 check_release((IUnknown*)newsurf, 1);
1197 check_release((IUnknown*)tex, 0);
1200 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &tex, NULL);
1201 if (FAILED(hr))
1202 skip("Failed to create DXT5 texture, hr %#x.\n", hr);
1203 else
1205 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1206 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1207 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1208 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT5 format.\n");
1209 check_release((IUnknown*)newsurf, 1);
1210 check_release((IUnknown*)tex, 0);
1213 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &tex, NULL);
1214 if (FAILED(hr))
1215 skip("Failed to create DXT1 texture, hr %#x.\n", hr);
1216 else
1218 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1219 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1220 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0);
1221 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels to DXT1 format.\n");
1223 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0);
1224 todo_wine ok(SUCCEEDED(hr), "Failed to convert pixels from DXT1 format.\n");
1226 check_release((IUnknown*)newsurf, 1);
1227 check_release((IUnknown*)tex, 0);
1230 check_release((IUnknown*)surf, 0);
1233 /* cleanup */
1234 if(testdummy_ok) DeleteFileA("testdummy.bmp");
1235 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
1238 static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9 *device)
1240 HRESULT hr;
1241 RECT rect;
1242 ID3DXBuffer *buffer;
1243 IDirect3DSurface9 *surface;
1244 struct
1246 DWORD magic;
1247 struct dds_header header;
1248 BYTE *data;
1249 } *dds;
1251 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1252 if (FAILED(hr)) {
1253 skip("Couldn't create surface\n");
1254 return;
1257 SetRectEmpty(&rect);
1258 hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_BMP, surface, NULL, &rect);
1259 /* fails with the debug version of d3d9 */
1260 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1261 if (SUCCEEDED(hr)) {
1262 DWORD size = ID3DXBuffer_GetBufferSize(buffer);
1263 ok(size > 0, "ID3DXBuffer_GetBufferSize returned %u, expected > 0\n", size);
1264 ID3DXBuffer_Release(buffer);
1267 SetRectEmpty(&rect);
1268 hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_DDS, surface, NULL, &rect);
1269 todo_wine ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1270 if (SUCCEEDED(hr))
1272 dds = ID3DXBuffer_GetBufferPointer(buffer);
1274 ok(dds->magic == MAKEFOURCC('D','D','S',' '), "Got unexpected DDS signature %#x.\n", dds->magic);
1275 ok(dds->header.size == sizeof(dds->header), "Got unexpected DDS size %u.\n", dds->header.size);
1276 ok(!dds->header.height, "Got unexpected height %u.\n", dds->header.height);
1277 ok(!dds->header.width, "Got unexpected width %u.\n", dds->header.width);
1278 ok(!dds->header.depth, "Got unexpected depth %u.\n", dds->header.depth);
1279 ok(!dds->header.miplevels, "Got unexpected miplevels %u.\n", dds->header.miplevels);
1280 ok(!dds->header.pitch_or_linear_size, "Got unexpected pitch_or_linear_size %u.\n", dds->header.pitch_or_linear_size);
1281 ok(dds->header.caps == (DDS_CAPS_TEXTURE | DDSCAPS_ALPHA), "Got unexpected caps %#x.\n", dds->header.caps);
1282 ok(dds->header.flags == (DDS_CAPS | DDS_HEIGHT | DDS_WIDTH | DDS_PIXELFORMAT),
1283 "Got unexpected flags %#x.\n", dds->header.flags);
1284 ID3DXBuffer_Release(buffer);
1287 hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_DDS, surface, NULL, NULL);
1288 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1290 dds = ID3DXBuffer_GetBufferPointer(buffer);
1291 ok(dds->magic == MAKEFOURCC('D','D','S',' '), "Got unexpected DDS signature %#x.\n", dds->magic);
1292 ok(dds->header.size == sizeof(dds->header), "Got unexpected DDS size %u.\n", dds->header.size);
1293 ok(dds->header.height == 4, "Got unexpected height %u.\n", dds->header.height);
1294 ok(dds->header.width == 4, "Got unexpected width %u.\n", dds->header.width);
1295 ok(!dds->header.depth, "Got unexpected depth %u.\n", dds->header.depth);
1296 ok(!dds->header.miplevels, "Got unexpected miplevels %u.\n", dds->header.miplevels);
1297 ok(!dds->header.pitch_or_linear_size, "Got unexpected pitch_or_linear_size %u.\n", dds->header.pitch_or_linear_size);
1298 todo_wine ok(dds->header.caps == (DDS_CAPS_TEXTURE | DDSCAPS_ALPHA), "Got unexpected caps %#x.\n", dds->header.caps);
1299 ok(dds->header.flags == (DDS_CAPS | DDS_HEIGHT | DDS_WIDTH | DDS_PIXELFORMAT),
1300 "Got unexpected flags %#x.\n", dds->header.flags);
1301 ID3DXBuffer_Release(buffer);
1303 IDirect3DSurface9_Release(surface);
1306 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
1308 HRESULT hr;
1309 IDirect3DSurface9 *surface;
1310 RECT rect;
1311 D3DLOCKED_RECT lock_rect;
1312 D3DXIMAGE_INFO image_info;
1313 const BYTE pixels[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
1314 0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
1315 DWORD pitch = sizeof(pixels) / 2;
1317 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
1318 if (FAILED(hr)) {
1319 skip("Couldn't create surface\n");
1320 return;
1323 SetRect(&rect, 0, 0, 2, 2);
1324 hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, pixels, D3DFMT_R8G8B8, pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
1325 if (SUCCEEDED(hr)) {
1326 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, NULL);
1327 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1329 hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.bmp", NULL, D3DX_FILTER_NONE, 0, &image_info);
1330 ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
1331 if (FAILED(hr)) goto next_tests;
1333 ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
1334 ok(image_info.Height == 2, "Wrong height %u\n", image_info.Height);
1335 ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
1336 ok(image_info.ImageFileFormat == D3DXIFF_BMP, "Wrong file format %u\n", image_info.ImageFileFormat);
1338 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1339 ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
1340 if (FAILED(hr)) goto next_tests;
1342 ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
1343 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
1345 IDirect3DSurface9_UnlockRect(surface);
1346 } else skip("Couldn't fill surface\n");
1348 next_tests:
1349 hr = D3DXSaveSurfaceToFileA(NULL, D3DXIFF_BMP, surface, NULL, NULL);
1350 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1352 /* PPM and TGA are supported, even though MSDN claims they aren't */
1353 todo_wine {
1354 hr = D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM, surface, NULL, NULL);
1355 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1356 hr = D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA, surface, NULL, NULL);
1357 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1360 hr = D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS, surface, NULL, NULL);
1361 ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1362 if (SUCCEEDED(hr)) {
1363 hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.dds", NULL, D3DX_FILTER_NONE, 0, &image_info);
1364 ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
1366 if (SUCCEEDED(hr)) {
1367 ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
1368 ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
1369 ok(image_info.ImageFileFormat == D3DXIFF_DDS, "Wrong file format %u\n", image_info.ImageFileFormat);
1371 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1372 ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
1373 if (SUCCEEDED(hr)) {
1374 ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
1375 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
1376 IDirect3DSurface9_UnlockRect(surface);
1379 } else skip("Couldn't save surface\n");
1381 hr = D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM + 1, surface, NULL, NULL);
1382 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1384 SetRect(&rect, 0, 0, 4, 4);
1385 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1386 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1387 SetRect(&rect, 2, 0, 1, 4);
1388 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1389 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1390 SetRect(&rect, 0, 2, 4, 1);
1391 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1392 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1393 SetRect(&rect, -1, -1, 2, 2);
1394 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1395 ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1396 SetRectEmpty(&rect);
1397 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1398 /* fails when debug version of d3d9 is used */
1399 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
1401 DeleteFileA("saved_surface.bmp");
1402 DeleteFileA("saved_surface.ppm");
1403 DeleteFileA("saved_surface.tga");
1404 DeleteFileA("saved_surface.dds");
1406 IDirect3DSurface9_Release(surface);
1409 START_TEST(surface)
1411 HWND wnd;
1412 IDirect3D9 *d3d;
1413 IDirect3DDevice9 *device;
1414 D3DPRESENT_PARAMETERS d3dpp;
1415 HRESULT hr;
1417 if (!(wnd = CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW, 0, 0,
1418 640, 480, NULL, NULL, NULL, NULL)))
1420 skip("Couldn't create application window\n");
1421 return;
1423 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1424 if (!d3d) {
1425 skip("Couldn't create IDirect3D9 object\n");
1426 DestroyWindow(wnd);
1427 return;
1430 ZeroMemory(&d3dpp, sizeof(d3dpp));
1431 d3dpp.Windowed = TRUE;
1432 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1433 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
1434 if(FAILED(hr)) {
1435 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1436 IDirect3D9_Release(d3d);
1437 DestroyWindow(wnd);
1438 return;
1441 test_D3DXGetImageInfo();
1442 test_D3DXLoadSurface(device);
1443 test_D3DXSaveSurfaceToFileInMemory(device);
1444 test_D3DXSaveSurfaceToFile(device);
1446 check_release((IUnknown*)device, 0);
1447 check_release((IUnknown*)d3d, 0);
1448 DestroyWindow(wnd);