2 * Tests for the D3DX9 surface functions
4 * Copyright 2009 Tony Wasserka
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
25 #include "resources.h"
27 static inline int get_ref(IUnknown
*obj
)
30 return IUnknown_Release(obj
);
33 #define check_ref(obj, exp) _check_ref(__LINE__, obj, exp)
34 static inline void _check_ref(unsigned int line
, IUnknown
*obj
, int exp
)
36 int ref
= get_ref(obj
);
37 ok_(__FILE__
, line
)(exp
== ref
, "Invalid refcount. Expected %d, got %d\n", exp
, ref
);
40 #define check_release(obj, exp) _check_release(__LINE__, obj, exp)
41 static inline void _check_release(unsigned int line
, IUnknown
*obj
, int exp
)
43 int ref
= IUnknown_Release(obj
);
44 ok_(__FILE__
, line
)(ref
== exp
, "Invalid refcount. Expected %d, got %d\n", exp
, ref
);
48 static const unsigned char 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,
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,
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,
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,
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] = {
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
)
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
))
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
209 DWORD pitch_or_linear_size
;
213 struct dds_pixel_format pixel_format
;
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
;
229 header
->pixel_format
.size
= sizeof(header
->pixel_format
);
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
)
252 struct dds_header header
;
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
);
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)
283 struct dds_header header
;
289 struct dds_pixel_format pixel_format
;
294 DWORD pixel_data_size
;
295 HRESULT expected_result
;
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 */,
302 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 1 /* pitch */,
304 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 2 /* pitch */,
306 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 3 /* pitch */,
308 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 4 /* pitch */,
310 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 16 /* pitch */,
312 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 1024 /* pitch */,
314 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, -1 /* pitch */,
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 */,
321 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 1 /* linear size */,
323 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 2 /* linear size */,
325 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 9 /* linear size */,
327 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 16 /* linear size */,
329 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, -1 /* linear size */,
331 /* integer overflows */
332 { { 32, DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000000, 0x80000000 /* 0x80000000 * 0x80000000 * 4 = 0 */, 0,
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,
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)
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 */
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");
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
);
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
);
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
);
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
);
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
);
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
);
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
)
619 BOOL testdummy_ok
, testbitmap_ok
;
620 IDirect3DTexture9
*tex
;
621 IDirect3DSurface9
*surf
, *newsurf
;
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
);
640 skip("Failed to create a surface (%#x)\n", hr
);
641 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
642 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
646 /* D3DXLoadSurfaceFromFile */
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");
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
, MAKEINTRESOURCE(IDB_BITMAP_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
669 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
671 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, MAKEINTRESOURCE(IDD_BITMAPDATA_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
672 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
674 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0, NULL
);
675 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
677 hr
= D3DXLoadSurfaceFromResourceA(NULL
, NULL
, NULL
, NULL
, MAKEINTRESOURCE(IDB_BITMAP_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
678 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
680 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, MAKEINTRESOURCE(IDS_STRING
), NULL
, D3DX_DEFAULT
, 0, NULL
);
681 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
684 /* D3DXLoadSurfaceFromFileInMemory */
685 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, bmp_1bpp
, sizeof(bmp_1bpp
), NULL
, D3DX_DEFAULT
, 0, NULL
);
686 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
688 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, noimage
, sizeof(noimage
), NULL
, D3DX_DEFAULT
, 0, NULL
);
689 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
691 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, bmp_1bpp
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
692 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
694 hr
= D3DXLoadSurfaceFromFileInMemory(NULL
, NULL
, NULL
, bmp_1bpp
, sizeof(bmp_1bpp
), NULL
, D3DX_DEFAULT
, 0, NULL
);
695 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
697 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, NULL
, 8, NULL
, D3DX_DEFAULT
, 0, NULL
);
698 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
700 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, NULL
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
701 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
703 hr
= D3DXLoadSurfaceFromFileInMemory(NULL
, NULL
, NULL
, NULL
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
704 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
707 /* D3DXLoadSurfaceFromMemory */
708 SetRect(&rect
, 0, 0, 2, 2);
710 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
711 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
713 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, 0, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
714 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
716 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, NULL
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
717 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
719 hr
= D3DXLoadSurfaceFromMemory(NULL
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
720 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
722 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, NULL
, D3DX_DEFAULT
, 0);
723 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
725 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_UNKNOWN
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
726 ok(hr
== E_FAIL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, E_FAIL
);
728 SetRect(&destrect
, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
729 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
730 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
732 SetRect(&destrect
, 255, 255, 257, 257); /* 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
, 1, 1, 0, 0); /* left > right, top > bottom */
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
, 0, 0, 0, 0); /* left = right, top = bottom */
741 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
742 /* fails when debug version of d3d9 is used */
743 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
), "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
745 SetRect(&destrect
, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
746 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
747 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
750 /* D3DXLoadSurfaceFromSurface */
751 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &newsurf
, NULL
);
753 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
754 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
756 hr
= D3DXLoadSurfaceFromSurface(NULL
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
757 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
759 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0);
760 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
762 check_release((IUnknown
*)newsurf
, 0);
763 } else skip("Failed to create a second surface\n");
765 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
768 IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
770 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
771 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
773 IDirect3DSurface9_Release(newsurf
);
774 IDirect3DTexture9_Release(tex
);
775 } else skip("Failed to create texture\n");
777 /* non-lockable render target */
778 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &newsurf
, NULL
);
780 hr
= D3DXLoadSurfaceFromSurface(surf
, NULL
, NULL
, newsurf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
781 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
783 IDirect3DSurface9_Release(newsurf
);
784 } else skip("Failed to create render target surface\n");
786 /* non-lockable multisampled render target */
787 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_2_SAMPLES
, 0, FALSE
, &newsurf
, NULL
);
789 hr
= D3DXLoadSurfaceFromSurface(surf
, NULL
, NULL
, newsurf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
790 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
792 IDirect3DSurface9_Release(newsurf
);
793 } else skip("Failed to create multisampled render target\n");
795 check_release((IUnknown
*)surf
, 0);
798 /* test color conversion */
800 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf
, NULL
);
801 if(FAILED(hr
)) skip("Failed to create a surface (%#x)\n", hr
);
803 PALETTEENTRY palette
;
805 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
, D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
806 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
807 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
808 check_pixel_4bpp(&lockrect
, 0, 0, 0x57dbffff);
809 check_pixel_4bpp(&lockrect
, 1, 0, 0x98ffff00);
810 check_pixel_4bpp(&lockrect
, 0, 1, 0xacdbff55);
811 check_pixel_4bpp(&lockrect
, 1, 1, 0xc8929255);
812 IDirect3DSurface9_UnlockRect(surf
);
814 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
, D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
815 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
816 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
817 check_pixel_4bpp(&lockrect
, 0, 0, 0x008cadad);
818 check_pixel_4bpp(&lockrect
, 1, 0, 0xff317342);
819 check_pixel_4bpp(&lockrect
, 0, 1, 0x0008ad10);
820 check_pixel_4bpp(&lockrect
, 1, 1, 0xff29088c);
821 IDirect3DSurface9_UnlockRect(surf
);
823 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
, D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
824 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
825 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
826 check_pixel_4bpp(&lockrect
, 0, 0, 0xff9cdfb5);
827 check_pixel_4bpp(&lockrect
, 1, 0, 0xff63b26b);
828 check_pixel_4bpp(&lockrect
, 0, 1, 0xff085d73);
829 check_pixel_4bpp(&lockrect
, 1, 1, 0xff425d73);
830 IDirect3DSurface9_UnlockRect(surf
);
832 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
, D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
833 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
834 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
836 check_pixel_4bpp(&lockrect
, 0, 0, 0xff3f08ff);
838 check_pixel_4bpp(&lockrect
, 1, 0, 0xff44dcff);
839 check_pixel_4bpp(&lockrect
, 0, 1, 0xff97e4ff);
840 check_pixel_4bpp(&lockrect
, 1, 1, 0xfffe9aff);
841 IDirect3DSurface9_UnlockRect(surf
);
843 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
, D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
844 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
845 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
846 check_pixel_4bpp(&lockrect
, 0, 0, 0xc3f04c39);
847 check_pixel_4bpp(&lockrect
, 1, 0, 0x2392e85a);
848 check_pixel_4bpp(&lockrect
, 0, 1, 0x09fd97b1);
849 check_pixel_4bpp(&lockrect
, 1, 1, 0x8df62bc3);
850 IDirect3DSurface9_UnlockRect(surf
);
852 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
, D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
853 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
854 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
855 check_pixel_4bpp(&lockrect
, 0, 0, 0x555c95bf);
856 check_pixel_4bpp(&lockrect
, 1, 0, 0x556d663f);
857 check_pixel_4bpp(&lockrect
, 0, 1, 0xaac385ad);
859 check_pixel_4bpp(&lockrect
, 1, 1, 0xfffcc575);
861 IDirect3DSurface9_UnlockRect(surf
);
863 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8l8
,
864 D3DFMT_A8L8
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
865 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
866 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
867 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
868 check_pixel_4bpp(&lockrect
, 0, 0, 0xff000000);
869 check_pixel_4bpp(&lockrect
, 1, 0, 0x00ffffff);
870 check_pixel_4bpp(&lockrect
, 0, 1, 0xff303030);
871 check_pixel_4bpp(&lockrect
, 1, 1, 0x7f7f7f7f);
872 hr
= IDirect3DSurface9_UnlockRect(surf
);
873 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
875 /* Test D3DXLoadSurfaceFromMemory with indexed color image */
876 palette
.peRed
= bmp_1bpp
[56];
877 palette
.peGreen
= bmp_1bpp
[55];
878 palette
.peBlue
= bmp_1bpp
[54];
879 palette
.peFlags
= bmp_1bpp
[57]; /* peFlags is the alpha component in DX8 and higher */
880 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, &bmp_1bpp
[62], D3DFMT_P8
, 4, (const PALETTEENTRY
*)&palette
, &rect
, D3DX_FILTER_NONE
, 0);
881 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
882 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
883 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x\n", hr
);
884 ok(*(DWORD
*)lockrect
.pBits
== 0x80f3f2f1, "Pixel color mismatch: got %#x, expected 0x80f3f2f1\n", *(DWORD
*)lockrect
.pBits
);
885 hr
= IDirect3DSurface9_UnlockRect(surf
);
886 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x\n", hr
);
888 /* Test D3DXLoadSurfaceFromFileInMemory with indexed color image (alpha is not taken into account for bmp file) */
889 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, bmp_1bpp
, sizeof(bmp_1bpp
), NULL
, D3DX_FILTER_NONE
, 0, NULL
);
890 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
891 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
892 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x\n", hr
);
893 ok(*(DWORD
*)lockrect
.pBits
== 0xfff3f2f1, "Pixel color mismatch: got %#x, expected 0xfff3f2f1\n", *(DWORD
*)lockrect
.pBits
);
894 hr
= IDirect3DSurface9_UnlockRect(surf
);
895 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x\n", hr
);
897 check_release((IUnknown
*)surf
, 0);
901 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A1R5G5B5
, D3DPOOL_DEFAULT
, &surf
, NULL
);
902 if(FAILED(hr
)) skip("Failed to create a surface (%#x)\n", hr
);
904 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
, D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
905 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
906 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
907 check_pixel_2bpp(&lockrect
, 0, 0, 0x6fff);
908 check_pixel_2bpp(&lockrect
, 1, 0, 0xffe0);
909 check_pixel_2bpp(&lockrect
, 0, 1, 0xefea);
910 check_pixel_2bpp(&lockrect
, 1, 1, 0xca4a);
911 IDirect3DSurface9_UnlockRect(surf
);
913 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
, D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
914 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
915 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
916 check_pixel_2bpp(&lockrect
, 0, 0, 0x46b5);
917 check_pixel_2bpp(&lockrect
, 1, 0, 0x99c8);
918 check_pixel_2bpp(&lockrect
, 0, 1, 0x06a2);
919 check_pixel_2bpp(&lockrect
, 1, 1, 0x9431);
920 IDirect3DSurface9_UnlockRect(surf
);
922 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
, D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
923 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
924 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
925 check_pixel_2bpp(&lockrect
, 0, 0, 0xcf76);
926 check_pixel_2bpp(&lockrect
, 1, 0, 0xb2cd);
927 check_pixel_2bpp(&lockrect
, 0, 1, 0x856e);
928 check_pixel_2bpp(&lockrect
, 1, 1, 0xa16e);
929 IDirect3DSurface9_UnlockRect(surf
);
931 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
, D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
932 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
933 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
935 check_pixel_2bpp(&lockrect
, 0, 0, 0xa03f);
937 check_pixel_2bpp(&lockrect
, 1, 0, 0xa37f);
938 check_pixel_2bpp(&lockrect
, 0, 1, 0xcb9f);
939 check_pixel_2bpp(&lockrect
, 1, 1, 0xfe7f);
940 IDirect3DSurface9_UnlockRect(surf
);
942 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
, D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
943 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
944 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
946 check_pixel_2bpp(&lockrect
, 0, 0, 0xf527);
947 check_pixel_2bpp(&lockrect
, 1, 0, 0x4b8b);
949 check_pixel_2bpp(&lockrect
, 0, 1, 0x7e56);
950 check_pixel_2bpp(&lockrect
, 1, 1, 0xf8b8);
951 IDirect3DSurface9_UnlockRect(surf
);
953 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
, D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
954 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
955 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
956 check_pixel_2bpp(&lockrect
, 0, 0, 0x2e57);
958 check_pixel_2bpp(&lockrect
, 1, 0, 0x3588);
960 check_pixel_2bpp(&lockrect
, 0, 1, 0xe215);
961 check_pixel_2bpp(&lockrect
, 1, 1, 0xff0e);
962 IDirect3DSurface9_UnlockRect(surf
);
964 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8l8
,
965 D3DFMT_A8L8
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
966 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
967 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
968 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
969 check_pixel_2bpp(&lockrect
, 0, 0, 0x8000);
970 check_pixel_2bpp(&lockrect
, 1, 0, 0x7fff);
971 check_pixel_2bpp(&lockrect
, 0, 1, 0x98c6);
972 check_pixel_2bpp(&lockrect
, 1, 1, 0x3def);
973 hr
= IDirect3DSurface9_UnlockRect(surf
);
974 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
976 check_release((IUnknown
*)surf
, 0);
980 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A8L8
, D3DPOOL_DEFAULT
, &surf
, NULL
);
982 skip("Failed to create A8L8 surface, hr %#x.\n", hr
);
985 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
,
986 D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
987 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
988 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
989 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
990 check_pixel_2bpp(&lockrect
, 0, 0, 0x57f7);
991 check_pixel_2bpp(&lockrect
, 1, 0, 0x98ed);
992 check_pixel_2bpp(&lockrect
, 0, 1, 0xaceb);
993 check_pixel_2bpp(&lockrect
, 1, 1, 0xc88d);
994 hr
= IDirect3DSurface9_UnlockRect(surf
);
995 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
997 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
,
998 D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
999 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1000 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1001 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1002 check_pixel_2bpp(&lockrect
, 0, 0, 0x00a6);
1003 check_pixel_2bpp(&lockrect
, 1, 0, 0xff62);
1004 check_pixel_2bpp(&lockrect
, 0, 1, 0x007f);
1005 check_pixel_2bpp(&lockrect
, 1, 1, 0xff19);
1006 hr
= IDirect3DSurface9_UnlockRect(surf
);
1007 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1009 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
,
1010 D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1011 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1012 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1013 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1014 check_pixel_2bpp(&lockrect
, 0, 0, 0xffce);
1015 check_pixel_2bpp(&lockrect
, 1, 0, 0xff9c);
1016 check_pixel_2bpp(&lockrect
, 0, 1, 0xff4d);
1017 check_pixel_2bpp(&lockrect
, 1, 1, 0xff59);
1018 hr
= IDirect3DSurface9_UnlockRect(surf
);
1019 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1021 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
,
1022 D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1023 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1024 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1025 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1026 check_pixel_2bpp(&lockrect
, 0, 0, 0xff25);
1027 check_pixel_2bpp(&lockrect
, 1, 0, 0xffbe);
1028 check_pixel_2bpp(&lockrect
, 0, 1, 0xffd6);
1029 check_pixel_2bpp(&lockrect
, 1, 1, 0xffb6);
1030 hr
= IDirect3DSurface9_UnlockRect(surf
);
1031 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1033 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
,
1034 D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1035 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1036 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1037 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1038 check_pixel_2bpp(&lockrect
, 0, 0, 0xc36d);
1039 check_pixel_2bpp(&lockrect
, 1, 0, 0x23cb);
1040 check_pixel_2bpp(&lockrect
, 0, 1, 0x09af);
1041 check_pixel_2bpp(&lockrect
, 1, 1, 0x8d61);
1042 hr
= IDirect3DSurface9_UnlockRect(surf
);
1043 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1045 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
,
1046 D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1047 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1048 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1049 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1050 check_pixel_2bpp(&lockrect
, 0, 0, 0x558c);
1051 check_pixel_2bpp(&lockrect
, 1, 0, 0x5565);
1052 check_pixel_2bpp(&lockrect
, 0, 1, 0xaa95);
1053 check_pixel_2bpp(&lockrect
, 1, 1, 0xffcb);
1054 hr
= IDirect3DSurface9_UnlockRect(surf
);
1055 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1057 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8l8
,
1058 D3DFMT_A8L8
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1059 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1060 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1061 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1062 check_pixel_2bpp(&lockrect
, 0, 0, 0xff00);
1063 check_pixel_2bpp(&lockrect
, 1, 0, 0x00ff);
1064 check_pixel_2bpp(&lockrect
, 0, 1, 0xff30);
1065 check_pixel_2bpp(&lockrect
, 1, 1, 0x7f7f);
1066 hr
= IDirect3DSurface9_UnlockRect(surf
);
1067 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1069 check_release((IUnknown
*)surf
, 0);
1072 /* DXT1, DXT2, DXT3, DXT4, DXT5 */
1073 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surf
, NULL
);
1075 skip("Failed to create R8G8B8 surface, hr %#x.\n", hr
);
1078 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, dds_24bit
, sizeof(dds_24bit
), NULL
, D3DX_FILTER_NONE
, 0, NULL
);
1079 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1081 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_DXT2
, D3DPOOL_SYSTEMMEM
, &newsurf
, NULL
);
1083 skip("Failed to create DXT2 surface, hr %#x.\n", hr
);
1086 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1087 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT2 format.\n");
1088 check_release((IUnknown
*)newsurf
, 0);
1091 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_DXT3
, D3DPOOL_SYSTEMMEM
, &newsurf
, NULL
);
1093 skip("Failed to create DXT3 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 DXT3 format.\n");
1098 check_release((IUnknown
*)newsurf
, 0);
1101 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_DXT4
, D3DPOOL_SYSTEMMEM
, &newsurf
, NULL
);
1103 skip("Failed to create DXT4 surface, hr %#x.\n", hr
);
1106 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1107 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT4 format.\n");
1108 check_release((IUnknown
*)newsurf
, 0);
1111 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_DXT5
, D3DPOOL_SYSTEMMEM
, &newsurf
, NULL
);
1113 skip("Failed to create DXT5 surface, hr %#x.\n", hr
);
1116 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1117 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT5 format.\n");
1118 check_release((IUnknown
*)newsurf
, 0);
1121 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_DXT1
, D3DPOOL_SYSTEMMEM
, &newsurf
, NULL
);
1123 skip("Failed to create DXT1 surface, hr %#x.\n", hr
);
1126 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1127 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT1 format.\n");
1129 hr
= D3DXLoadSurfaceFromSurface(surf
, NULL
, NULL
, newsurf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1130 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels from DXT1 format.\n");
1132 check_release((IUnknown
*)newsurf
, 0);
1135 check_release((IUnknown
*)surf
, 0);
1139 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
1140 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
1143 static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9
*device
)
1147 ID3DXBuffer
*buffer
;
1148 IDirect3DSurface9
*surface
;
1150 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &surface
, NULL
);
1152 skip("Couldn't create surface\n");
1156 SetRect(&rect
, 0, 0, 0, 0);
1157 hr
= D3DXSaveSurfaceToFileInMemory(&buffer
, D3DXIFF_BMP
, surface
, NULL
, &rect
);
1158 /* fails with the debug version of d3d9 */
1159 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
), "D3DXSaveSurfaceToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1160 if (SUCCEEDED(hr
)) {
1161 DWORD size
= ID3DXBuffer_GetBufferSize(buffer
);
1162 ok(size
> 0, "ID3DXBuffer_GetBufferSize returned %u, expected > 0\n", size
);
1163 ID3DXBuffer_Release(buffer
);
1166 IDirect3DSurface9_Release(surface
);
1169 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9
*device
)
1172 IDirect3DSurface9
*surface
;
1174 D3DLOCKED_RECT lock_rect
;
1175 D3DXIMAGE_INFO image_info
;
1176 const BYTE pixels
[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
1177 0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
1178 DWORD pitch
= sizeof(pixels
) / 2;
1180 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_R8G8B8
, D3DPOOL_SCRATCH
, &surface
, NULL
);
1182 skip("Couldn't create surface\n");
1186 SetRect(&rect
, 0, 0, 2, 2);
1187 hr
= D3DXLoadSurfaceFromMemory(surface
, NULL
, NULL
, pixels
, D3DFMT_R8G8B8
, pitch
, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1188 if (SUCCEEDED(hr
)) {
1189 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, NULL
);
1190 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1192 hr
= D3DXLoadSurfaceFromFileA(surface
, NULL
, NULL
, "saved_surface.bmp", NULL
, D3DX_FILTER_NONE
, 0, &image_info
);
1193 ok(hr
== D3D_OK
, "Couldn't load saved surface %#x\n", hr
);
1194 if (FAILED(hr
)) goto next_tests
;
1196 ok(image_info
.Width
== 2, "Wrong width %u\n", image_info
.Width
);
1197 ok(image_info
.Height
== 2, "Wrong height %u\n", image_info
.Height
);
1198 ok(image_info
.Format
== D3DFMT_R8G8B8
, "Wrong format %#x\n", image_info
.Format
);
1199 ok(image_info
.ImageFileFormat
== D3DXIFF_BMP
, "Wrong file format %u\n", image_info
.ImageFileFormat
);
1201 hr
= IDirect3DSurface9_LockRect(surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1202 ok(hr
== D3D_OK
, "Couldn't lock surface %#x\n", hr
);
1203 if (FAILED(hr
)) goto next_tests
;
1205 ok(!memcmp(lock_rect
.pBits
, pixels
, pitch
), "Pixel data mismatch in first row\n");
1206 ok(!memcmp((BYTE
*)lock_rect
.pBits
+ lock_rect
.Pitch
, pixels
+ pitch
, pitch
), "Pixel data mismatch in second row\n");
1208 IDirect3DSurface9_UnlockRect(surface
);
1209 } else skip("Couldn't fill surface\n");
1212 hr
= D3DXSaveSurfaceToFileA(NULL
, D3DXIFF_BMP
, surface
, NULL
, NULL
);
1213 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1215 /* PPM and TGA are supported, even though MSDN claims they aren't */
1217 hr
= D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM
, surface
, NULL
, NULL
);
1218 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1219 hr
= D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA
, surface
, NULL
, NULL
);
1220 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1223 hr
= D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS
, surface
, NULL
, NULL
);
1224 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1225 if (SUCCEEDED(hr
)) {
1226 hr
= D3DXLoadSurfaceFromFileA(surface
, NULL
, NULL
, "saved_surface.dds", NULL
, D3DX_FILTER_NONE
, 0, &image_info
);
1227 ok(hr
== D3D_OK
, "Couldn't load saved surface %#x\n", hr
);
1229 if (SUCCEEDED(hr
)) {
1230 ok(image_info
.Width
== 2, "Wrong width %u\n", image_info
.Width
);
1231 ok(image_info
.Format
== D3DFMT_R8G8B8
, "Wrong format %#x\n", image_info
.Format
);
1232 ok(image_info
.ImageFileFormat
== D3DXIFF_DDS
, "Wrong file format %u\n", image_info
.ImageFileFormat
);
1234 hr
= IDirect3DSurface9_LockRect(surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1235 ok(hr
== D3D_OK
, "Couldn't lock surface %#x\n", hr
);
1236 if (SUCCEEDED(hr
)) {
1237 ok(!memcmp(lock_rect
.pBits
, pixels
, pitch
), "Pixel data mismatch in first row\n");
1238 ok(!memcmp((BYTE
*)lock_rect
.pBits
+ lock_rect
.Pitch
, pixels
+ pitch
, pitch
), "Pixel data mismatch in second row\n");
1239 IDirect3DSurface9_UnlockRect(surface
);
1242 } else skip("Couldn't save surface\n");
1244 hr
= D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM
+ 1, surface
, NULL
, NULL
);
1245 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1247 SetRect(&rect
, 0, 0, 4, 4);
1248 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1249 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1250 SetRect(&rect
, 2, 0, 1, 4);
1251 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1252 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1253 SetRect(&rect
, 0, 2, 4, 1);
1254 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1255 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1256 SetRect(&rect
, -1, -1, 2, 2);
1257 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1258 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1259 SetRect(&rect
, 0, 0, 0, 0);
1260 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1261 /* fails when debug version of d3d9 is used */
1262 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
), "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1264 DeleteFileA("saved_surface.bmp");
1265 DeleteFileA("saved_surface.ppm");
1266 DeleteFileA("saved_surface.tga");
1267 DeleteFileA("saved_surface.dds");
1269 IDirect3DSurface9_Release(surface
);
1276 IDirect3DDevice9
*device
;
1277 D3DPRESENT_PARAMETERS d3dpp
;
1280 wnd
= CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
1282 skip("Couldn't create application window\n");
1285 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
1287 skip("Couldn't create IDirect3D9 object\n");
1292 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
1293 d3dpp
.Windowed
= TRUE
;
1294 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1295 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, wnd
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device
);
1297 skip("Failed to create IDirect3DDevice9 object %#x\n", hr
);
1298 IDirect3D9_Release(d3d
);
1303 test_D3DXGetImageInfo();
1304 test_D3DXLoadSurface(device
);
1305 test_D3DXSaveSurfaceToFileInMemory(device
);
1306 test_D3DXSaveSurfaceToFile(device
);
1308 check_release((IUnknown
*)device
, 0);
1309 check_release((IUnknown
*)d3d
, 0);