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 #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
);
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,
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,
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,
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,
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,
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] = {
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
)
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
))
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_LINEARSIZE 0x00080000
176 /* dds_header.caps */
177 #define DDS_CAPS_TEXTURE 0x00001000
179 /* dds_pixel_format.flags */
180 #define DDS_PF_ALPHA 0x00000001
181 #define DDS_PF_ALPHA_ONLY 0x00000002
182 #define DDS_PF_FOURCC 0x00000004
183 #define DDS_PF_RGB 0x00000040
184 #define DDS_PF_LUMINANCE 0x00020000
185 #define DDS_PF_BUMPDUDV 0x00080000
187 struct dds_pixel_format
206 DWORD pitch_or_linear_size
;
210 struct dds_pixel_format pixel_format
;
216 /* fills dds_header with reasonable default values */
217 static void fill_dds_header(struct dds_header
*header
)
219 memset(header
, 0, sizeof(*header
));
221 header
->magic
= MAKEFOURCC('D','D','S',' ');
222 header
->size
= sizeof(*header
);
223 header
->flags
= DDS_CAPS
| DDS_WIDTH
| DDS_HEIGHT
| DDS_PIXELFORMAT
;
226 header
->pixel_format
.size
= sizeof(header
->pixel_format
);
228 header
->pixel_format
.flags
= DDS_PF_RGB
;
229 header
->pixel_format
.fourcc
= 0;
230 header
->pixel_format
.bpp
= 32;
231 header
->pixel_format
.rmask
= 0xff0000;
232 header
->pixel_format
.gmask
= 0x00ff00;
233 header
->pixel_format
.bmask
= 0x0000ff;
234 header
->pixel_format
.amask
= 0;
235 header
->caps
= DDS_CAPS_TEXTURE
;
238 #define check_dds_pixel_format(flags, fourcc, bpp, rmask, gmask, bmask, amask, format) \
239 check_dds_pixel_format_(__LINE__, flags, fourcc, bpp, rmask, gmask, bmask, amask, format)
240 static void check_dds_pixel_format_(unsigned int line
,
241 DWORD flags
, DWORD fourcc
, DWORD bpp
,
242 DWORD rmask
, DWORD gmask
, DWORD bmask
, DWORD amask
,
243 D3DFORMAT expected_format
)
249 struct dds_header header
;
253 fill_dds_header(&dds
.header
);
254 dds
.header
.pixel_format
.flags
= flags
;
255 dds
.header
.pixel_format
.fourcc
= fourcc
;
256 dds
.header
.pixel_format
.bpp
= bpp
;
257 dds
.header
.pixel_format
.rmask
= rmask
;
258 dds
.header
.pixel_format
.gmask
= gmask
;
259 dds
.header
.pixel_format
.bmask
= bmask
;
260 dds
.header
.pixel_format
.amask
= amask
;
261 memset(dds
.data
, 0, sizeof(dds
.data
));
263 hr
= D3DXGetImageInfoFromFileInMemory(&dds
, sizeof(dds
), &info
);
264 ok_(__FILE__
, line
)(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x for pixel format %#x, expected %#x\n",
265 hr
, expected_format
, D3D_OK
);
268 ok_(__FILE__
, line
)(info
.Format
== expected_format
, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n",
269 info
.Format
, expected_format
);
273 static void test_dds_header_handling(void)
280 struct dds_header header
;
286 struct dds_pixel_format pixel_format
;
291 DWORD pixel_data_size
;
292 HRESULT expected_result
;
294 /* pitch is ignored */
295 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, 0, 4, 4, 0,
296 63 /* pixel data size */, D3DXERR_INVALIDDATA
},
297 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 0 /* pitch */,
299 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 1 /* pitch */,
301 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 2 /* pitch */,
303 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 3 /* pitch */,
305 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 4 /* pitch */,
307 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 16 /* pitch */,
309 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 1024 /* pitch */,
311 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, -1 /* pitch */,
313 /* linear size is ignored */
314 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, 0, 4, 4, 0,
315 7 /* pixel data size */, D3DXERR_INVALIDDATA
},
316 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 0 /* linear size */,
318 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 1 /* linear size */,
320 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 2 /* linear size */,
322 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 9 /* linear size */,
324 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 16 /* linear size */,
326 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, -1 /* linear size */,
328 /* integer overflows */
329 { { 32, DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000000, 0x80000000 /* 0x80000000 * 0x80000000 * 4 = 0 */, 0,
331 { { 32, DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x8000100, 0x800100 /* 0x8000100 * 0x800100 * 4 = 262144 */, 0,
332 64, D3DXERR_INVALIDDATA
},
333 { { 32, DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
335 { { 32, DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
336 3 /* pixel data size */, D3DXERR_INVALIDDATA
}
339 memset(&dds
, 0, sizeof(dds
));
341 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
343 DWORD file_size
= sizeof(dds
.header
) + tests
[i
].pixel_data_size
;
344 assert(file_size
<= sizeof(dds
));
346 fill_dds_header(&dds
.header
);
347 dds
.header
.flags
|= tests
[i
].flags
;
348 dds
.header
.width
= tests
[i
].width
;
349 dds
.header
.height
= tests
[i
].height
;
350 dds
.header
.pitch_or_linear_size
= tests
[i
].pitch
;
351 dds
.header
.pixel_format
= tests
[i
].pixel_format
;
353 hr
= D3DXGetImageInfoFromFileInMemory(&dds
, file_size
, &info
);
354 ok(hr
== tests
[i
].expected_result
, "%d: D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", i
, hr
, tests
[i
].expected_result
);
358 static void test_D3DXGetImageInfo(void)
362 BOOL testdummy_ok
, testbitmap_ok
;
364 hr
= create_file("testdummy.bmp", noimage
, sizeof(noimage
)); /* invalid image */
365 testdummy_ok
= SUCCEEDED(hr
);
367 hr
= create_file("testbitmap.bmp", bmp_1bpp
, sizeof(bmp_1bpp
)); /* valid image */
368 testbitmap_ok
= SUCCEEDED(hr
);
370 /* D3DXGetImageInfoFromFile */
372 hr
= D3DXGetImageInfoFromFileA("testbitmap.bmp", &info
);
373 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
375 hr
= D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL
); /* valid image, second parameter is NULL */
376 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
377 } else skip("Couldn't create \"testbitmap.bmp\"\n");
380 hr
= D3DXGetImageInfoFromFileA("testdummy.bmp", NULL
); /* invalid image, second parameter is NULL */
381 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
383 hr
= D3DXGetImageInfoFromFileA("testdummy.bmp", &info
);
384 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
385 } else skip("Couldn't create \"testdummy.bmp\"\n");
387 hr
= D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info
);
388 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
390 hr
= D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL
);
391 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
393 hr
= D3DXGetImageInfoFromFileA("", &info
);
394 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
396 hr
= D3DXGetImageInfoFromFileA(NULL
, &info
);
397 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
399 hr
= D3DXGetImageInfoFromFileA(NULL
, NULL
);
400 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
403 /* D3DXGetImageInfoFromResource */
404 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDB_BITMAP_1x1
), &info
); /* RT_BITMAP */
405 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
407 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDB_BITMAP_1x1
), NULL
);
408 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
410 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), &info
); /* RT_RCDATA */
411 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
413 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDS_STRING
), &info
);
414 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
416 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDS_STRING
), NULL
);
417 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
419 hr
= D3DXGetImageInfoFromResourceA(NULL
, "resourcedoesnotexist", &info
);
420 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
422 hr
= D3DXGetImageInfoFromResourceA(NULL
, "resourcedoesnotexist", NULL
);
423 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
425 hr
= D3DXGetImageInfoFromResourceA(NULL
, NULL
, NULL
);
426 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
429 /* D3DXGetImageInfoFromFileInMemory */
430 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
), &info
);
431 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
433 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
)+5, &info
); /* too large size */
434 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
436 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
), NULL
);
437 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
439 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, sizeof(noimage
), NULL
);
440 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
442 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, sizeof(noimage
), &info
);
443 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
446 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
)-1, &info
);
447 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
450 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
+1, sizeof(bmp_1bpp
)-1, &info
);
451 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
453 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, 0, &info
);
454 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
456 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, 0, NULL
);
457 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
459 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, 0, &info
);
460 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
462 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, 0, NULL
);
463 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
465 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 0, &info
);
466 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
468 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 4, NULL
);
469 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
471 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 4, &info
);
472 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
474 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 0, NULL
);
475 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
477 /* test BMP support */
478 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
), &info
);
479 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
480 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
481 ok(info
.Format
== D3DFMT_P8
, "Got format %u, expected %u\n", info
.Format
, D3DFMT_P8
);
482 hr
= D3DXGetImageInfoFromFileInMemory(bmp_2bpp
, sizeof(bmp_2bpp
), &info
);
483 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
484 hr
= D3DXGetImageInfoFromFileInMemory(bmp_4bpp
, sizeof(bmp_4bpp
), &info
);
485 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
486 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
487 ok(info
.Format
== D3DFMT_P8
, "Got format %u, expected %u\n", info
.Format
, D3DFMT_P8
);
488 hr
= D3DXGetImageInfoFromFileInMemory(bmp_8bpp
, sizeof(bmp_8bpp
), &info
);
489 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
490 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
491 ok(info
.Format
== D3DFMT_P8
, "Got format %u, expected %u\n", info
.Format
, D3DFMT_P8
);
494 hr
= D3DXGetImageInfoFromFileInMemory(png_grayscale
, sizeof(png_grayscale
), &info
);
495 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
496 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
497 ok(info
.Format
== D3DFMT_L8
, "Got format %u, expected %u\n", info
.Format
, D3DFMT_L8
);
499 /* test DDS support */
500 hr
= D3DXGetImageInfoFromFileInMemory(dds_24bit
, sizeof(dds_24bit
), &info
);
501 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
503 ok(info
.Width
== 2, "Got width %u, expected 2\n", info
.Width
);
504 ok(info
.Height
== 2, "Got height %u, expected 2\n", info
.Height
);
505 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
506 ok(info
.MipLevels
== 2, "Got miplevels %u, expected 2\n", info
.MipLevels
);
507 ok(info
.Format
== D3DFMT_R8G8B8
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_R8G8B8
);
508 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
509 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
510 } else skip("Couldn't get image info from 24-bit DDS file in memory\n");
512 hr
= D3DXGetImageInfoFromFileInMemory(dds_16bit
, sizeof(dds_16bit
), &info
);
513 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
515 ok(info
.Width
== 2, "Got width %u, expected 2\n", info
.Width
);
516 ok(info
.Height
== 2, "Got height %u, expected 2\n", info
.Height
);
517 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
518 ok(info
.MipLevels
== 1, "Got miplevels %u, expected 1\n", info
.MipLevels
);
519 ok(info
.Format
== D3DFMT_X1R5G5B5
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_X1R5G5B5
);
520 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
521 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
522 } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
524 hr
= D3DXGetImageInfoFromFileInMemory(dds_cube_map
, sizeof(dds_cube_map
), &info
);
525 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
527 ok(info
.Width
== 4, "Got width %u, expected 4\n", info
.Width
);
528 ok(info
.Height
== 4, "Got height %u, expected 4\n", info
.Height
);
529 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
530 ok(info
.MipLevels
== 1, "Got miplevels %u, expected 1\n", info
.MipLevels
);
531 ok(info
.Format
== D3DFMT_DXT5
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_DXT5
);
532 ok(info
.ResourceType
== D3DRTYPE_CUBETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_CUBETEXTURE
);
533 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
534 } else skip("Couldn't get image info from cube map in memory\n");
536 hr
= D3DXGetImageInfoFromFileInMemory(dds_volume_map
, sizeof(dds_volume_map
), &info
);
537 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
539 ok(info
.Width
== 4, "Got width %u, expected 4\n", info
.Width
);
540 ok(info
.Height
== 4, "Got height %u, expected 4\n", info
.Height
);
541 ok(info
.Depth
== 2, "Got depth %u, expected 2\n", info
.Depth
);
542 ok(info
.MipLevels
== 3, "Got miplevels %u, expected 3\n", info
.MipLevels
);
543 ok(info
.Format
== D3DFMT_DXT3
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_DXT3
);
544 ok(info
.ResourceType
== D3DRTYPE_VOLUMETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_VOLUMETEXTURE
);
545 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
546 } else skip("Couldn't get image info from volume map in memory\n");
548 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0, D3DFMT_DXT1
);
549 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0, D3DFMT_DXT2
);
550 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0, D3DFMT_DXT3
);
551 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0, D3DFMT_DXT4
);
552 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0, D3DFMT_DXT5
);
553 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8
);
554 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8
);
555 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0, D3DFMT_UYVY
);
556 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0, D3DFMT_YUY2
);
557 check_dds_pixel_format(DDS_PF_RGB
, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5
);
558 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5
);
559 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4
);
560 check_dds_pixel_format(DDS_PF_RGB
, 0, 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2
);
561 check_dds_pixel_format(DDS_PF_ALPHA_ONLY
, 0, 8, 0, 0, 0, 0xff, D3DFMT_A8
);
562 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2
);
563 check_dds_pixel_format(DDS_PF_RGB
, 0, 16, 0xf00, 0x0f0, 0x00f, 0, D3DFMT_X4R4G4B4
);
564 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10
);
565 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10
);
566 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8
);
567 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, D3DFMT_A8B8G8R8
);
568 check_dds_pixel_format(DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_X8R8G8B8
);
569 check_dds_pixel_format(DDS_PF_RGB
, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8B8G8R8
);
570 check_dds_pixel_format(DDS_PF_RGB
, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_G16R16
);
571 check_dds_pixel_format(DDS_PF_LUMINANCE
, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8
);
572 check_dds_pixel_format(DDS_PF_LUMINANCE
, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16
);
573 check_dds_pixel_format(DDS_PF_LUMINANCE
| DDS_PF_ALPHA
, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8
);
574 check_dds_pixel_format(DDS_PF_LUMINANCE
| DDS_PF_ALPHA
, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4
);
575 check_dds_pixel_format(DDS_PF_BUMPDUDV
, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8
);
576 check_dds_pixel_format(DDS_PF_BUMPDUDV
, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16
);
578 test_dds_header_handling();
580 hr
= D3DXGetImageInfoFromFileInMemory(dds_16bit
, sizeof(dds_16bit
) - 1, &info
);
581 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
583 hr
= D3DXGetImageInfoFromFileInMemory(dds_24bit
, sizeof(dds_24bit
) - 1, &info
);
584 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
586 hr
= D3DXGetImageInfoFromFileInMemory(dds_cube_map
, sizeof(dds_cube_map
) - 1, &info
);
587 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
589 hr
= D3DXGetImageInfoFromFileInMemory(dds_volume_map
, sizeof(dds_volume_map
) - 1, &info
);
590 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
594 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
595 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
598 #define check_pixel_2bpp(lockrect, x, y, color) _check_pixel_2bpp(__LINE__, lockrect, x, y, color)
599 static inline void _check_pixel_2bpp(unsigned int line
, const D3DLOCKED_RECT
*lockrect
, int x
, int y
, WORD expected_color
)
601 WORD color
= ((WORD
*)lockrect
->pBits
)[x
+ y
* lockrect
->Pitch
/ 2];
602 ok_(__FILE__
, line
)(color
== expected_color
, "Got color 0x%04x, expected 0x%04x\n", color
, expected_color
);
605 #define check_pixel_4bpp(lockrect, x, y, color) _check_pixel_4bpp(__LINE__, lockrect, x, y, color)
606 static inline void _check_pixel_4bpp(unsigned int line
, const D3DLOCKED_RECT
*lockrect
, int x
, int y
, DWORD expected_color
)
608 DWORD color
= ((DWORD
*)lockrect
->pBits
)[x
+ y
* lockrect
->Pitch
/ 4];
609 ok_(__FILE__
, line
)(color
== expected_color
, "Got color 0x%08x, expected 0x%08x\n", color
, expected_color
);
612 static void test_D3DXLoadSurface(IDirect3DDevice9
*device
)
615 BOOL testdummy_ok
, testbitmap_ok
;
616 IDirect3DTexture9
*tex
;
617 IDirect3DSurface9
*surf
, *newsurf
;
619 D3DLOCKED_RECT lockrect
;
620 const WORD pixdata_a8r3g3b2
[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
621 const WORD pixdata_a1r5g5b5
[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
622 const WORD pixdata_r5g6b5
[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
623 const WORD pixdata_a8l8
[] = { 0xff00, 0x00ff, 0xff30, 0x7f7f };
624 const DWORD pixdata_g16r16
[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
625 const DWORD pixdata_a8b8g8r8
[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
626 const DWORD pixdata_a2r10g10b10
[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
628 hr
= create_file("testdummy.bmp", noimage
, sizeof(noimage
)); /* invalid image */
629 testdummy_ok
= SUCCEEDED(hr
);
631 hr
= create_file("testbitmap.bmp", bmp_1bpp
, sizeof(bmp_1bpp
)); /* valid image */
632 testbitmap_ok
= SUCCEEDED(hr
);
634 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf
, NULL
);
636 skip("Failed to create a surface (%#x)\n", hr
);
637 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
638 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
642 /* D3DXLoadSurfaceFromFile */
644 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "testbitmap.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
645 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
647 hr
= D3DXLoadSurfaceFromFileA(NULL
, NULL
, NULL
, "testbitmap.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
648 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
649 } else skip("Couldn't create \"testbitmap.bmp\"\n");
652 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "testdummy.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
653 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
654 } else skip("Couldn't create \"testdummy.bmp\"\n");
656 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0, NULL
);
657 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
659 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "", NULL
, D3DX_DEFAULT
, 0, NULL
);
660 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
663 /* D3DXLoadSurfaceFromResource */
664 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
,
665 MAKEINTRESOURCEA(IDB_BITMAP_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
666 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
668 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
,
669 MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
670 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
672 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0, NULL
);
673 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
675 hr
= D3DXLoadSurfaceFromResourceA(NULL
, NULL
, NULL
, NULL
,
676 MAKEINTRESOURCEA(IDB_BITMAP_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
677 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
679 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
,
680 MAKEINTRESOURCEA(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_CreateTexture(device
, 2, 2, 1, 0, D3DFMT_A8L8
, D3DPOOL_MANAGED
, &tex
, NULL
);
982 skip("Failed to create A8L8 texture, hr %#x.\n", hr
);
985 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &surf
);
986 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
988 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
,
989 D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
990 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
991 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
992 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
993 check_pixel_2bpp(&lockrect
, 0, 0, 0x57f7);
994 check_pixel_2bpp(&lockrect
, 1, 0, 0x98ed);
995 check_pixel_2bpp(&lockrect
, 0, 1, 0xaceb);
996 check_pixel_2bpp(&lockrect
, 1, 1, 0xc88d);
997 hr
= IDirect3DSurface9_UnlockRect(surf
);
998 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1000 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
,
1001 D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1002 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1003 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1004 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1005 check_pixel_2bpp(&lockrect
, 0, 0, 0x00a6);
1006 check_pixel_2bpp(&lockrect
, 1, 0, 0xff62);
1007 check_pixel_2bpp(&lockrect
, 0, 1, 0x007f);
1008 check_pixel_2bpp(&lockrect
, 1, 1, 0xff19);
1009 hr
= IDirect3DSurface9_UnlockRect(surf
);
1010 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1012 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
,
1013 D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1014 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1015 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1016 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1017 check_pixel_2bpp(&lockrect
, 0, 0, 0xffce);
1018 check_pixel_2bpp(&lockrect
, 1, 0, 0xff9c);
1019 check_pixel_2bpp(&lockrect
, 0, 1, 0xff4d);
1020 check_pixel_2bpp(&lockrect
, 1, 1, 0xff59);
1021 hr
= IDirect3DSurface9_UnlockRect(surf
);
1022 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1024 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
,
1025 D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1026 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1027 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1028 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1029 check_pixel_2bpp(&lockrect
, 0, 0, 0xff25);
1030 check_pixel_2bpp(&lockrect
, 1, 0, 0xffbe);
1031 check_pixel_2bpp(&lockrect
, 0, 1, 0xffd6);
1032 check_pixel_2bpp(&lockrect
, 1, 1, 0xffb6);
1033 hr
= IDirect3DSurface9_UnlockRect(surf
);
1034 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1036 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
,
1037 D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1038 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1039 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1040 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1041 check_pixel_2bpp(&lockrect
, 0, 0, 0xc36d);
1042 check_pixel_2bpp(&lockrect
, 1, 0, 0x23cb);
1043 check_pixel_2bpp(&lockrect
, 0, 1, 0x09af);
1044 check_pixel_2bpp(&lockrect
, 1, 1, 0x8d61);
1045 hr
= IDirect3DSurface9_UnlockRect(surf
);
1046 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1048 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
,
1049 D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1050 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1051 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1052 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1053 check_pixel_2bpp(&lockrect
, 0, 0, 0x558c);
1054 check_pixel_2bpp(&lockrect
, 1, 0, 0x5565);
1055 check_pixel_2bpp(&lockrect
, 0, 1, 0xaa95);
1056 check_pixel_2bpp(&lockrect
, 1, 1, 0xffcb);
1057 hr
= IDirect3DSurface9_UnlockRect(surf
);
1058 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1060 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8l8
,
1061 D3DFMT_A8L8
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1062 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1063 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1064 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1065 check_pixel_2bpp(&lockrect
, 0, 0, 0xff00);
1066 check_pixel_2bpp(&lockrect
, 1, 0, 0x00ff);
1067 check_pixel_2bpp(&lockrect
, 0, 1, 0xff30);
1068 check_pixel_2bpp(&lockrect
, 1, 1, 0x7f7f);
1069 hr
= IDirect3DSurface9_UnlockRect(surf
);
1070 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1072 check_release((IUnknown
*)surf
, 1);
1073 check_release((IUnknown
*)tex
, 0);
1076 /* DXT1, DXT2, DXT3, DXT4, DXT5 */
1077 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surf
, NULL
);
1079 skip("Failed to create R8G8B8 surface, hr %#x.\n", hr
);
1082 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, dds_24bit
, sizeof(dds_24bit
), NULL
, D3DX_FILTER_NONE
, 0, NULL
);
1083 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1085 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT2
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1087 skip("Failed to create DXT2 texture, hr %#x.\n", hr
);
1090 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1091 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1092 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1093 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT2 format.\n");
1094 check_release((IUnknown
*)newsurf
, 1);
1095 check_release((IUnknown
*)tex
, 0);
1098 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT3
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1100 skip("Failed to create DXT3 texture, hr %#x.\n", hr
);
1103 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1104 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1105 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1106 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT3 format.\n");
1107 check_release((IUnknown
*)newsurf
, 1);
1108 check_release((IUnknown
*)tex
, 0);
1111 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT4
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1113 skip("Failed to create DXT4 texture, hr %#x.\n", hr
);
1116 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1117 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1118 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1119 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT4 format.\n");
1120 check_release((IUnknown
*)newsurf
, 1);
1121 check_release((IUnknown
*)tex
, 0);
1124 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT5
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1126 skip("Failed to create DXT5 texture, hr %#x.\n", hr
);
1129 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1130 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1131 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1132 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT5 format.\n");
1133 check_release((IUnknown
*)newsurf
, 1);
1134 check_release((IUnknown
*)tex
, 0);
1137 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT1
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1139 skip("Failed to create DXT1 texture, hr %#x.\n", hr
);
1142 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1143 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1144 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1145 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT1 format.\n");
1147 hr
= D3DXLoadSurfaceFromSurface(surf
, NULL
, NULL
, newsurf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1148 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels from DXT1 format.\n");
1150 check_release((IUnknown
*)newsurf
, 1);
1151 check_release((IUnknown
*)tex
, 0);
1154 check_release((IUnknown
*)surf
, 0);
1158 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
1159 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
1162 static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9
*device
)
1166 ID3DXBuffer
*buffer
;
1167 IDirect3DSurface9
*surface
;
1169 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &surface
, NULL
);
1171 skip("Couldn't create surface\n");
1175 SetRect(&rect
, 0, 0, 0, 0);
1176 hr
= D3DXSaveSurfaceToFileInMemory(&buffer
, D3DXIFF_BMP
, surface
, NULL
, &rect
);
1177 /* fails with the debug version of d3d9 */
1178 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
), "D3DXSaveSurfaceToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1179 if (SUCCEEDED(hr
)) {
1180 DWORD size
= ID3DXBuffer_GetBufferSize(buffer
);
1181 ok(size
> 0, "ID3DXBuffer_GetBufferSize returned %u, expected > 0\n", size
);
1182 ID3DXBuffer_Release(buffer
);
1185 IDirect3DSurface9_Release(surface
);
1188 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9
*device
)
1191 IDirect3DSurface9
*surface
;
1193 D3DLOCKED_RECT lock_rect
;
1194 D3DXIMAGE_INFO image_info
;
1195 const BYTE pixels
[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
1196 0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
1197 DWORD pitch
= sizeof(pixels
) / 2;
1199 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_R8G8B8
, D3DPOOL_SCRATCH
, &surface
, NULL
);
1201 skip("Couldn't create surface\n");
1205 SetRect(&rect
, 0, 0, 2, 2);
1206 hr
= D3DXLoadSurfaceFromMemory(surface
, NULL
, NULL
, pixels
, D3DFMT_R8G8B8
, pitch
, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1207 if (SUCCEEDED(hr
)) {
1208 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, NULL
);
1209 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1211 hr
= D3DXLoadSurfaceFromFileA(surface
, NULL
, NULL
, "saved_surface.bmp", NULL
, D3DX_FILTER_NONE
, 0, &image_info
);
1212 ok(hr
== D3D_OK
, "Couldn't load saved surface %#x\n", hr
);
1213 if (FAILED(hr
)) goto next_tests
;
1215 ok(image_info
.Width
== 2, "Wrong width %u\n", image_info
.Width
);
1216 ok(image_info
.Height
== 2, "Wrong height %u\n", image_info
.Height
);
1217 ok(image_info
.Format
== D3DFMT_R8G8B8
, "Wrong format %#x\n", image_info
.Format
);
1218 ok(image_info
.ImageFileFormat
== D3DXIFF_BMP
, "Wrong file format %u\n", image_info
.ImageFileFormat
);
1220 hr
= IDirect3DSurface9_LockRect(surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1221 ok(hr
== D3D_OK
, "Couldn't lock surface %#x\n", hr
);
1222 if (FAILED(hr
)) goto next_tests
;
1224 ok(!memcmp(lock_rect
.pBits
, pixels
, pitch
), "Pixel data mismatch in first row\n");
1225 ok(!memcmp((BYTE
*)lock_rect
.pBits
+ lock_rect
.Pitch
, pixels
+ pitch
, pitch
), "Pixel data mismatch in second row\n");
1227 IDirect3DSurface9_UnlockRect(surface
);
1228 } else skip("Couldn't fill surface\n");
1231 hr
= D3DXSaveSurfaceToFileA(NULL
, D3DXIFF_BMP
, surface
, NULL
, NULL
);
1232 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1234 /* PPM and TGA are supported, even though MSDN claims they aren't */
1236 hr
= D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM
, surface
, NULL
, NULL
);
1237 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1238 hr
= D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA
, surface
, NULL
, NULL
);
1239 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1242 hr
= D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS
, surface
, NULL
, NULL
);
1243 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1244 if (SUCCEEDED(hr
)) {
1245 hr
= D3DXLoadSurfaceFromFileA(surface
, NULL
, NULL
, "saved_surface.dds", NULL
, D3DX_FILTER_NONE
, 0, &image_info
);
1246 ok(hr
== D3D_OK
, "Couldn't load saved surface %#x\n", hr
);
1248 if (SUCCEEDED(hr
)) {
1249 ok(image_info
.Width
== 2, "Wrong width %u\n", image_info
.Width
);
1250 ok(image_info
.Format
== D3DFMT_R8G8B8
, "Wrong format %#x\n", image_info
.Format
);
1251 ok(image_info
.ImageFileFormat
== D3DXIFF_DDS
, "Wrong file format %u\n", image_info
.ImageFileFormat
);
1253 hr
= IDirect3DSurface9_LockRect(surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1254 ok(hr
== D3D_OK
, "Couldn't lock surface %#x\n", hr
);
1255 if (SUCCEEDED(hr
)) {
1256 ok(!memcmp(lock_rect
.pBits
, pixels
, pitch
), "Pixel data mismatch in first row\n");
1257 ok(!memcmp((BYTE
*)lock_rect
.pBits
+ lock_rect
.Pitch
, pixels
+ pitch
, pitch
), "Pixel data mismatch in second row\n");
1258 IDirect3DSurface9_UnlockRect(surface
);
1261 } else skip("Couldn't save surface\n");
1263 hr
= D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM
+ 1, surface
, NULL
, NULL
);
1264 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1266 SetRect(&rect
, 0, 0, 4, 4);
1267 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1268 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1269 SetRect(&rect
, 2, 0, 1, 4);
1270 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1271 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1272 SetRect(&rect
, 0, 2, 4, 1);
1273 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1274 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1275 SetRect(&rect
, -1, -1, 2, 2);
1276 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1277 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1278 SetRect(&rect
, 0, 0, 0, 0);
1279 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1280 /* fails when debug version of d3d9 is used */
1281 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
), "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1283 DeleteFileA("saved_surface.bmp");
1284 DeleteFileA("saved_surface.ppm");
1285 DeleteFileA("saved_surface.tga");
1286 DeleteFileA("saved_surface.dds");
1288 IDirect3DSurface9_Release(surface
);
1295 IDirect3DDevice9
*device
;
1296 D3DPRESENT_PARAMETERS d3dpp
;
1299 if (!(wnd
= CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW
, 0, 0,
1300 640, 480, NULL
, NULL
, NULL
, NULL
)))
1302 skip("Couldn't create application window\n");
1305 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
1307 skip("Couldn't create IDirect3D9 object\n");
1312 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
1313 d3dpp
.Windowed
= TRUE
;
1314 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1315 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, wnd
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device
);
1317 skip("Failed to create IDirect3DDevice9 object %#x\n", hr
);
1318 IDirect3D9_Release(d3d
);
1323 test_D3DXGetImageInfo();
1324 test_D3DXLoadSurface(device
);
1325 test_D3DXSaveSurfaceToFileInMemory(device
);
1326 test_D3DXSaveSurfaceToFile(device
);
1328 check_release((IUnknown
*)device
, 0);
1329 check_release((IUnknown
*)d3d
, 0);