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 static const unsigned char png_grayscale
[] =
85 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49,
86 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00,
87 0x00, 0x00, 0x00, 0x3a, 0x7e, 0x9b, 0x55, 0x00, 0x00, 0x00, 0x0a, 0x49, 0x44,
88 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8, 0x0f, 0x00, 0x01, 0x01, 0x01, 0x00, 0x1b,
89 0xb6, 0xee, 0x56, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42,
93 /* 2x2 A8R8G8B8 pixel data */
94 static const unsigned char pixdata
[] = {
95 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
98 /* invalid image file */
99 static const unsigned char noimage
[4] = {
103 /* 2x2 24-bit dds, 2 mipmaps */
104 static const unsigned char dds_24bit
[] = {
105 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00,
106 0x02,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,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,0x18,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
111 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
112 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
113 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
116 /* 2x2 16-bit dds, no mipmaps */
117 static const unsigned char dds_16bit
[] = {
118 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
119 0x02,0x00,0x00,0x00,0x08,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 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,
124 0xe0,0x03,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
125 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
126 0xff,0x7f,0xff,0x7f,0xff,0x7f,0xff,0x7f
129 /* 4x4 cube map dds */
130 static const unsigned char dds_cube_map
[] = {
131 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00,
132 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
133 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
134 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
135 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
136 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
137 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
138 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
139 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
140 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
141 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
142 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
143 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
144 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50
147 /* 4x4x2 volume map dds, 2 mipmaps */
148 static const unsigned char dds_volume_map
[] = {
149 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
150 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
151 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
152 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
153 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
154 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
155 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
156 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
157 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
158 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
159 0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
160 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
163 static HRESULT
create_file(const char *filename
, const unsigned char *data
, const unsigned int size
)
168 hfile
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
169 if(hfile
== INVALID_HANDLE_VALUE
) return HRESULT_FROM_WIN32(GetLastError());
171 if(WriteFile(hfile
, data
, size
, &received
, NULL
))
178 return D3DERR_INVALIDCALL
;
181 /* dds_header.flags */
182 #define DDS_CAPS 0x00000001
183 #define DDS_HEIGHT 0x00000002
184 #define DDS_WIDTH 0x00000004
185 #define DDS_PITCH 0x00000008
186 #define DDS_PIXELFORMAT 0x00001000
187 #define DDS_LINEARSIZE 0x00080000
189 /* dds_header.caps */
190 #define DDS_CAPS_TEXTURE 0x00001000
192 /* dds_pixel_format.flags */
193 #define DDS_PF_ALPHA 0x00000001
194 #define DDS_PF_ALPHA_ONLY 0x00000002
195 #define DDS_PF_FOURCC 0x00000004
196 #define DDS_PF_RGB 0x00000040
197 #define DDS_PF_LUMINANCE 0x00020000
198 #define DDS_PF_BUMPDUDV 0x00080000
200 struct dds_pixel_format
219 DWORD pitch_or_linear_size
;
223 struct dds_pixel_format pixel_format
;
229 /* fills dds_header with reasonable default values */
230 static void fill_dds_header(struct dds_header
*header
)
232 memset(header
, 0, sizeof(*header
));
234 header
->magic
= MAKEFOURCC('D','D','S',' ');
235 header
->size
= sizeof(*header
);
236 header
->flags
= DDS_CAPS
| DDS_WIDTH
| DDS_HEIGHT
| DDS_PIXELFORMAT
;
239 header
->pixel_format
.size
= sizeof(header
->pixel_format
);
241 header
->pixel_format
.flags
= DDS_PF_RGB
;
242 header
->pixel_format
.fourcc
= 0;
243 header
->pixel_format
.bpp
= 32;
244 header
->pixel_format
.rmask
= 0xff0000;
245 header
->pixel_format
.gmask
= 0x00ff00;
246 header
->pixel_format
.bmask
= 0x0000ff;
247 header
->pixel_format
.amask
= 0;
248 header
->caps
= DDS_CAPS_TEXTURE
;
251 #define check_dds_pixel_format(flags, fourcc, bpp, rmask, gmask, bmask, amask, format) \
252 check_dds_pixel_format_(__LINE__, flags, fourcc, bpp, rmask, gmask, bmask, amask, format)
253 static void check_dds_pixel_format_(unsigned int line
,
254 DWORD flags
, DWORD fourcc
, DWORD bpp
,
255 DWORD rmask
, DWORD gmask
, DWORD bmask
, DWORD amask
,
256 D3DFORMAT expected_format
)
262 struct dds_header header
;
266 fill_dds_header(&dds
.header
);
267 dds
.header
.pixel_format
.flags
= flags
;
268 dds
.header
.pixel_format
.fourcc
= fourcc
;
269 dds
.header
.pixel_format
.bpp
= bpp
;
270 dds
.header
.pixel_format
.rmask
= rmask
;
271 dds
.header
.pixel_format
.gmask
= gmask
;
272 dds
.header
.pixel_format
.bmask
= bmask
;
273 dds
.header
.pixel_format
.amask
= amask
;
274 memset(dds
.data
, 0, sizeof(dds
.data
));
276 hr
= D3DXGetImageInfoFromFileInMemory(&dds
, sizeof(dds
), &info
);
277 ok_(__FILE__
, line
)(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x for pixel format %#x, expected %#x\n",
278 hr
, expected_format
, D3D_OK
);
281 ok_(__FILE__
, line
)(info
.Format
== expected_format
, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n",
282 info
.Format
, expected_format
);
286 static void test_dds_header_handling(void)
293 struct dds_header header
;
299 struct dds_pixel_format pixel_format
;
304 DWORD pixel_data_size
;
305 HRESULT expected_result
;
307 /* pitch is ignored */
308 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, 0, 4, 4, 0,
309 63 /* pixel data size */, D3DXERR_INVALIDDATA
},
310 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 0 /* pitch */,
312 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 1 /* pitch */,
314 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 2 /* pitch */,
316 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 3 /* pitch */,
318 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 4 /* pitch */,
320 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 16 /* pitch */,
322 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 1024 /* pitch */,
324 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, -1 /* pitch */,
326 /* linear size is ignored */
327 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, 0, 4, 4, 0,
328 7 /* pixel data size */, D3DXERR_INVALIDDATA
},
329 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 0 /* linear size */,
331 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 1 /* linear size */,
333 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 2 /* linear size */,
335 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 9 /* linear size */,
337 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 16 /* linear size */,
339 { { 32, DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, -1 /* linear size */,
341 /* integer overflows */
342 { { 32, DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000000, 0x80000000 /* 0x80000000 * 0x80000000 * 4 = 0 */, 0,
344 { { 32, DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x8000100, 0x800100 /* 0x8000100 * 0x800100 * 4 = 262144 */, 0,
345 64, D3DXERR_INVALIDDATA
},
346 { { 32, DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
348 { { 32, DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0,
349 3 /* pixel data size */, D3DXERR_INVALIDDATA
}
352 memset(&dds
, 0, sizeof(dds
));
354 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
356 DWORD file_size
= sizeof(dds
.header
) + tests
[i
].pixel_data_size
;
357 assert(file_size
<= sizeof(dds
));
359 fill_dds_header(&dds
.header
);
360 dds
.header
.flags
|= tests
[i
].flags
;
361 dds
.header
.width
= tests
[i
].width
;
362 dds
.header
.height
= tests
[i
].height
;
363 dds
.header
.pitch_or_linear_size
= tests
[i
].pitch
;
364 dds
.header
.pixel_format
= tests
[i
].pixel_format
;
366 hr
= D3DXGetImageInfoFromFileInMemory(&dds
, file_size
, &info
);
367 ok(hr
== tests
[i
].expected_result
, "%d: D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", i
, hr
, tests
[i
].expected_result
);
371 static void test_D3DXGetImageInfo(void)
375 BOOL testdummy_ok
, testbitmap_ok
;
377 hr
= create_file("testdummy.bmp", noimage
, sizeof(noimage
)); /* invalid image */
378 testdummy_ok
= SUCCEEDED(hr
);
380 hr
= create_file("testbitmap.bmp", bmp_1bpp
, sizeof(bmp_1bpp
)); /* valid image */
381 testbitmap_ok
= SUCCEEDED(hr
);
383 /* D3DXGetImageInfoFromFile */
385 hr
= D3DXGetImageInfoFromFileA("testbitmap.bmp", &info
);
386 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
388 hr
= D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL
); /* valid image, second parameter is NULL */
389 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
390 } else skip("Couldn't create \"testbitmap.bmp\"\n");
393 hr
= D3DXGetImageInfoFromFileA("testdummy.bmp", NULL
); /* invalid image, second parameter is NULL */
394 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
396 hr
= D3DXGetImageInfoFromFileA("testdummy.bmp", &info
);
397 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
398 } else skip("Couldn't create \"testdummy.bmp\"\n");
400 hr
= D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info
);
401 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
403 hr
= D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL
);
404 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
406 hr
= D3DXGetImageInfoFromFileA("", &info
);
407 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
409 hr
= D3DXGetImageInfoFromFileA(NULL
, &info
);
410 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
412 hr
= D3DXGetImageInfoFromFileA(NULL
, NULL
);
413 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
416 /* D3DXGetImageInfoFromResource */
417 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDB_BITMAP_1x1
), &info
); /* RT_BITMAP */
418 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
420 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDB_BITMAP_1x1
), NULL
);
421 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
423 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), &info
); /* RT_RCDATA */
424 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
426 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDS_STRING
), &info
);
427 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
429 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDS_STRING
), NULL
);
430 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
432 hr
= D3DXGetImageInfoFromResourceA(NULL
, "resourcedoesnotexist", &info
);
433 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
435 hr
= D3DXGetImageInfoFromResourceA(NULL
, "resourcedoesnotexist", NULL
);
436 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
438 hr
= D3DXGetImageInfoFromResourceA(NULL
, NULL
, NULL
);
439 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
442 /* D3DXGetImageInfoFromFileInMemory */
443 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
), &info
);
444 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
446 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
)+5, &info
); /* too large size */
447 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
449 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
), NULL
);
450 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
452 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, sizeof(noimage
), NULL
);
453 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
455 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, sizeof(noimage
), &info
);
456 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
459 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
)-1, &info
);
460 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
463 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
+1, sizeof(bmp_1bpp
)-1, &info
);
464 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
466 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, 0, &info
);
467 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
469 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, 0, NULL
);
470 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
472 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, 0, &info
);
473 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
475 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, 0, NULL
);
476 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
478 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 0, &info
);
479 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
481 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 4, NULL
);
482 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
484 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 4, &info
);
485 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
487 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 0, NULL
);
488 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
490 /* test BMP support */
491 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
), &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
);
495 hr
= D3DXGetImageInfoFromFileInMemory(bmp_2bpp
, sizeof(bmp_2bpp
), &info
);
496 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
497 hr
= D3DXGetImageInfoFromFileInMemory(bmp_4bpp
, sizeof(bmp_4bpp
), &info
);
498 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
499 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
500 ok(info
.Format
== D3DFMT_P8
, "Got format %u, expected %u\n", info
.Format
, D3DFMT_P8
);
501 hr
= D3DXGetImageInfoFromFileInMemory(bmp_8bpp
, sizeof(bmp_8bpp
), &info
);
502 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
503 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
504 ok(info
.Format
== D3DFMT_P8
, "Got format %u, expected %u\n", info
.Format
, D3DFMT_P8
);
507 hr
= D3DXGetImageInfoFromFileInMemory(png_grayscale
, sizeof(png_grayscale
), &info
);
508 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
509 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
510 ok(info
.Format
== D3DFMT_L8
, "Got format %u, expected %u\n", info
.Format
, D3DFMT_L8
);
512 /* test DDS support */
513 hr
= D3DXGetImageInfoFromFileInMemory(dds_24bit
, sizeof(dds_24bit
), &info
);
514 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
516 ok(info
.Width
== 2, "Got width %u, expected 2\n", info
.Width
);
517 ok(info
.Height
== 2, "Got height %u, expected 2\n", info
.Height
);
518 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
519 ok(info
.MipLevels
== 2, "Got miplevels %u, expected 2\n", info
.MipLevels
);
520 ok(info
.Format
== D3DFMT_R8G8B8
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_R8G8B8
);
521 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
522 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
523 } else skip("Couldn't get image info from 24-bit DDS file in memory\n");
525 hr
= D3DXGetImageInfoFromFileInMemory(dds_16bit
, sizeof(dds_16bit
), &info
);
526 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
528 ok(info
.Width
== 2, "Got width %u, expected 2\n", info
.Width
);
529 ok(info
.Height
== 2, "Got height %u, expected 2\n", info
.Height
);
530 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
531 ok(info
.MipLevels
== 1, "Got miplevels %u, expected 1\n", info
.MipLevels
);
532 ok(info
.Format
== D3DFMT_X1R5G5B5
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_X1R5G5B5
);
533 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
534 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
535 } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
537 hr
= D3DXGetImageInfoFromFileInMemory(dds_cube_map
, sizeof(dds_cube_map
), &info
);
538 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
540 ok(info
.Width
== 4, "Got width %u, expected 4\n", info
.Width
);
541 ok(info
.Height
== 4, "Got height %u, expected 4\n", info
.Height
);
542 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
543 ok(info
.MipLevels
== 1, "Got miplevels %u, expected 1\n", info
.MipLevels
);
544 ok(info
.Format
== D3DFMT_DXT5
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_DXT5
);
545 ok(info
.ResourceType
== D3DRTYPE_CUBETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_CUBETEXTURE
);
546 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
547 } else skip("Couldn't get image info from cube map in memory\n");
549 hr
= D3DXGetImageInfoFromFileInMemory(dds_volume_map
, sizeof(dds_volume_map
), &info
);
550 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
552 ok(info
.Width
== 4, "Got width %u, expected 4\n", info
.Width
);
553 ok(info
.Height
== 4, "Got height %u, expected 4\n", info
.Height
);
554 ok(info
.Depth
== 2, "Got depth %u, expected 2\n", info
.Depth
);
555 ok(info
.MipLevels
== 3, "Got miplevels %u, expected 3\n", info
.MipLevels
);
556 ok(info
.Format
== D3DFMT_DXT3
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_DXT3
);
557 ok(info
.ResourceType
== D3DRTYPE_VOLUMETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_VOLUMETEXTURE
);
558 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
559 } else skip("Couldn't get image info from volume map in memory\n");
561 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0, D3DFMT_DXT1
);
562 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0, D3DFMT_DXT2
);
563 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0, D3DFMT_DXT3
);
564 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0, D3DFMT_DXT4
);
565 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0, D3DFMT_DXT5
);
566 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8
);
567 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8
);
568 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0, D3DFMT_UYVY
);
569 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0, D3DFMT_YUY2
);
570 check_dds_pixel_format(DDS_PF_RGB
, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5
);
571 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5
);
572 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4
);
573 check_dds_pixel_format(DDS_PF_RGB
, 0, 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2
);
574 check_dds_pixel_format(DDS_PF_ALPHA_ONLY
, 0, 8, 0, 0, 0, 0xff, D3DFMT_A8
);
575 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2
);
576 check_dds_pixel_format(DDS_PF_RGB
, 0, 16, 0xf00, 0x0f0, 0x00f, 0, D3DFMT_X4R4G4B4
);
577 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10
);
578 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10
);
579 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8
);
580 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, D3DFMT_A8B8G8R8
);
581 check_dds_pixel_format(DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_X8R8G8B8
);
582 check_dds_pixel_format(DDS_PF_RGB
, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8B8G8R8
);
583 check_dds_pixel_format(DDS_PF_RGB
, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_G16R16
);
584 check_dds_pixel_format(DDS_PF_LUMINANCE
, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8
);
585 check_dds_pixel_format(DDS_PF_LUMINANCE
, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16
);
586 check_dds_pixel_format(DDS_PF_LUMINANCE
| DDS_PF_ALPHA
, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8
);
587 check_dds_pixel_format(DDS_PF_LUMINANCE
| DDS_PF_ALPHA
, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4
);
588 check_dds_pixel_format(DDS_PF_BUMPDUDV
, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8
);
589 check_dds_pixel_format(DDS_PF_BUMPDUDV
, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16
);
591 test_dds_header_handling();
593 hr
= D3DXGetImageInfoFromFileInMemory(dds_16bit
, sizeof(dds_16bit
) - 1, &info
);
594 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
596 hr
= D3DXGetImageInfoFromFileInMemory(dds_24bit
, sizeof(dds_24bit
) - 1, &info
);
597 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
599 hr
= D3DXGetImageInfoFromFileInMemory(dds_cube_map
, sizeof(dds_cube_map
) - 1, &info
);
600 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
602 hr
= D3DXGetImageInfoFromFileInMemory(dds_volume_map
, sizeof(dds_volume_map
) - 1, &info
);
603 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
607 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
608 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
611 #define check_pixel_1bpp(lockrect, x, y, color) _check_pixel_1bpp(__LINE__, lockrect, x, y, color)
612 static inline void _check_pixel_1bpp(unsigned int line
, const D3DLOCKED_RECT
*lockrect
, int x
, int y
, BYTE expected_color
)
614 BYTE color
= ((BYTE
*)lockrect
->pBits
)[x
+ y
* lockrect
->Pitch
];
615 ok_(__FILE__
, line
)(color
== expected_color
, "Got color 0x%02x, expected 0x%02x\n", color
, expected_color
);
618 #define check_pixel_2bpp(lockrect, x, y, color) _check_pixel_2bpp(__LINE__, lockrect, x, y, color)
619 static inline void _check_pixel_2bpp(unsigned int line
, const D3DLOCKED_RECT
*lockrect
, int x
, int y
, WORD expected_color
)
621 WORD color
= ((WORD
*)lockrect
->pBits
)[x
+ y
* lockrect
->Pitch
/ 2];
622 ok_(__FILE__
, line
)(color
== expected_color
, "Got color 0x%04x, expected 0x%04x\n", color
, expected_color
);
625 #define check_pixel_4bpp(lockrect, x, y, color) _check_pixel_4bpp(__LINE__, lockrect, x, y, color)
626 static inline void _check_pixel_4bpp(unsigned int line
, const D3DLOCKED_RECT
*lockrect
, int x
, int y
, DWORD expected_color
)
628 DWORD color
= ((DWORD
*)lockrect
->pBits
)[x
+ y
* lockrect
->Pitch
/ 4];
629 ok_(__FILE__
, line
)(color
== expected_color
, "Got color 0x%08x, expected 0x%08x\n", color
, expected_color
);
632 static void test_D3DXLoadSurface(IDirect3DDevice9
*device
)
635 BOOL testdummy_ok
, testbitmap_ok
;
636 IDirect3DTexture9
*tex
;
637 IDirect3DSurface9
*surf
, *newsurf
;
639 D3DLOCKED_RECT lockrect
;
640 const WORD pixdata_a8r3g3b2
[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
641 const WORD pixdata_a1r5g5b5
[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
642 const WORD pixdata_r5g6b5
[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
643 const WORD pixdata_a8l8
[] = { 0xff00, 0x00ff, 0xff30, 0x7f7f };
644 const DWORD pixdata_g16r16
[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
645 const DWORD pixdata_a8b8g8r8
[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
646 const DWORD pixdata_a2r10g10b10
[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
648 hr
= create_file("testdummy.bmp", noimage
, sizeof(noimage
)); /* invalid image */
649 testdummy_ok
= SUCCEEDED(hr
);
651 hr
= create_file("testbitmap.bmp", bmp_1bpp
, sizeof(bmp_1bpp
)); /* valid image */
652 testbitmap_ok
= SUCCEEDED(hr
);
654 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf
, NULL
);
656 skip("Failed to create a surface (%#x)\n", hr
);
657 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
658 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
662 /* D3DXLoadSurfaceFromFile */
664 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "testbitmap.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
665 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
667 hr
= D3DXLoadSurfaceFromFileA(NULL
, NULL
, NULL
, "testbitmap.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
668 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
669 } else skip("Couldn't create \"testbitmap.bmp\"\n");
672 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "testdummy.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
673 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
674 } else skip("Couldn't create \"testdummy.bmp\"\n");
676 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0, NULL
);
677 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
679 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "", NULL
, D3DX_DEFAULT
, 0, NULL
);
680 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
683 /* D3DXLoadSurfaceFromResource */
684 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
,
685 MAKEINTRESOURCEA(IDB_BITMAP_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
686 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
688 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
,
689 MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
690 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
692 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0, NULL
);
693 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
695 hr
= D3DXLoadSurfaceFromResourceA(NULL
, NULL
, NULL
, NULL
,
696 MAKEINTRESOURCEA(IDB_BITMAP_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
697 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
699 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
,
700 MAKEINTRESOURCEA(IDS_STRING
), NULL
, D3DX_DEFAULT
, 0, NULL
);
701 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
704 /* D3DXLoadSurfaceFromFileInMemory */
705 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, bmp_1bpp
, sizeof(bmp_1bpp
), NULL
, D3DX_DEFAULT
, 0, NULL
);
706 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
708 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, noimage
, sizeof(noimage
), NULL
, D3DX_DEFAULT
, 0, NULL
);
709 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
711 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, bmp_1bpp
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
712 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
714 hr
= D3DXLoadSurfaceFromFileInMemory(NULL
, NULL
, NULL
, bmp_1bpp
, sizeof(bmp_1bpp
), NULL
, D3DX_DEFAULT
, 0, NULL
);
715 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
717 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, NULL
, 8, NULL
, D3DX_DEFAULT
, 0, NULL
);
718 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
720 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, NULL
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
721 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
723 hr
= D3DXLoadSurfaceFromFileInMemory(NULL
, NULL
, NULL
, NULL
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
724 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
727 /* D3DXLoadSurfaceFromMemory */
728 SetRect(&rect
, 0, 0, 2, 2);
730 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
731 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
733 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, 0, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
734 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
736 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, NULL
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
737 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
739 hr
= D3DXLoadSurfaceFromMemory(NULL
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
740 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
742 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, NULL
, D3DX_DEFAULT
, 0);
743 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
745 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_UNKNOWN
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
746 ok(hr
== E_FAIL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, E_FAIL
);
748 SetRect(&destrect
, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
749 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
750 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
752 SetRect(&destrect
, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
753 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
754 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
756 SetRect(&destrect
, 1, 1, 0, 0); /* left > right, top > bottom */
757 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
758 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
760 SetRect(&destrect
, 0, 0, 0, 0); /* left = right, top = bottom */
761 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
762 /* fails when debug version of d3d9 is used */
763 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
), "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
765 SetRect(&destrect
, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
766 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
767 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
770 /* D3DXLoadSurfaceFromSurface */
771 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &newsurf
, NULL
);
773 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
774 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
776 hr
= D3DXLoadSurfaceFromSurface(NULL
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
777 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
779 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0);
780 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
782 check_release((IUnknown
*)newsurf
, 0);
783 } else skip("Failed to create a second surface\n");
785 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
788 IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
790 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
791 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
793 IDirect3DSurface9_Release(newsurf
);
794 IDirect3DTexture9_Release(tex
);
795 } else skip("Failed to create texture\n");
797 /* non-lockable render target */
798 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &newsurf
, NULL
);
800 hr
= D3DXLoadSurfaceFromSurface(surf
, NULL
, NULL
, newsurf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
801 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
803 IDirect3DSurface9_Release(newsurf
);
804 } else skip("Failed to create render target surface\n");
806 /* non-lockable multisampled render target */
807 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_2_SAMPLES
, 0, FALSE
, &newsurf
, NULL
);
809 hr
= D3DXLoadSurfaceFromSurface(surf
, NULL
, NULL
, newsurf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
810 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
812 IDirect3DSurface9_Release(newsurf
);
813 } else skip("Failed to create multisampled render target\n");
815 check_release((IUnknown
*)surf
, 0);
818 /* test color conversion */
820 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf
, NULL
);
821 if(FAILED(hr
)) skip("Failed to create a surface (%#x)\n", hr
);
823 PALETTEENTRY palette
;
825 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
, D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
826 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
827 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
828 check_pixel_4bpp(&lockrect
, 0, 0, 0x57dbffff);
829 check_pixel_4bpp(&lockrect
, 1, 0, 0x98ffff00);
830 check_pixel_4bpp(&lockrect
, 0, 1, 0xacdbff55);
831 check_pixel_4bpp(&lockrect
, 1, 1, 0xc8929255);
832 IDirect3DSurface9_UnlockRect(surf
);
834 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
, D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
835 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
836 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
837 check_pixel_4bpp(&lockrect
, 0, 0, 0x008cadad);
838 check_pixel_4bpp(&lockrect
, 1, 0, 0xff317342);
839 check_pixel_4bpp(&lockrect
, 0, 1, 0x0008ad10);
840 check_pixel_4bpp(&lockrect
, 1, 1, 0xff29088c);
841 IDirect3DSurface9_UnlockRect(surf
);
843 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
, D3DFMT_R5G6B5
, 4, 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, 0xff9cdfb5);
847 check_pixel_4bpp(&lockrect
, 1, 0, 0xff63b26b);
848 check_pixel_4bpp(&lockrect
, 0, 1, 0xff085d73);
849 check_pixel_4bpp(&lockrect
, 1, 1, 0xff425d73);
850 IDirect3DSurface9_UnlockRect(surf
);
852 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
, D3DFMT_G16R16
, 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
);
856 check_pixel_4bpp(&lockrect
, 0, 0, 0xff3f08ff);
858 check_pixel_4bpp(&lockrect
, 1, 0, 0xff44dcff);
859 check_pixel_4bpp(&lockrect
, 0, 1, 0xff97e4ff);
860 check_pixel_4bpp(&lockrect
, 1, 1, 0xfffe9aff);
861 IDirect3DSurface9_UnlockRect(surf
);
863 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
, D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
864 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
865 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
866 check_pixel_4bpp(&lockrect
, 0, 0, 0xc3f04c39);
867 check_pixel_4bpp(&lockrect
, 1, 0, 0x2392e85a);
868 check_pixel_4bpp(&lockrect
, 0, 1, 0x09fd97b1);
869 check_pixel_4bpp(&lockrect
, 1, 1, 0x8df62bc3);
870 IDirect3DSurface9_UnlockRect(surf
);
872 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
, D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
873 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
874 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
875 check_pixel_4bpp(&lockrect
, 0, 0, 0x555c95bf);
876 check_pixel_4bpp(&lockrect
, 1, 0, 0x556d663f);
877 check_pixel_4bpp(&lockrect
, 0, 1, 0xaac385ad);
879 check_pixel_4bpp(&lockrect
, 1, 1, 0xfffcc575);
881 IDirect3DSurface9_UnlockRect(surf
);
883 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8l8
,
884 D3DFMT_A8L8
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
885 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
886 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
887 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
888 check_pixel_4bpp(&lockrect
, 0, 0, 0xff000000);
889 check_pixel_4bpp(&lockrect
, 1, 0, 0x00ffffff);
890 check_pixel_4bpp(&lockrect
, 0, 1, 0xff303030);
891 check_pixel_4bpp(&lockrect
, 1, 1, 0x7f7f7f7f);
892 hr
= IDirect3DSurface9_UnlockRect(surf
);
893 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
895 /* Test D3DXLoadSurfaceFromMemory with indexed color image */
896 palette
.peRed
= bmp_1bpp
[56];
897 palette
.peGreen
= bmp_1bpp
[55];
898 palette
.peBlue
= bmp_1bpp
[54];
899 palette
.peFlags
= bmp_1bpp
[57]; /* peFlags is the alpha component in DX8 and higher */
900 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, &bmp_1bpp
[62], D3DFMT_P8
, 4, (const PALETTEENTRY
*)&palette
, &rect
, D3DX_FILTER_NONE
, 0);
901 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
902 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
903 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x\n", hr
);
904 ok(*(DWORD
*)lockrect
.pBits
== 0x80f3f2f1, "Pixel color mismatch: got %#x, expected 0x80f3f2f1\n", *(DWORD
*)lockrect
.pBits
);
905 hr
= IDirect3DSurface9_UnlockRect(surf
);
906 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x\n", hr
);
908 /* Test D3DXLoadSurfaceFromFileInMemory with indexed color image (alpha is not taken into account for bmp file) */
909 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, bmp_1bpp
, sizeof(bmp_1bpp
), NULL
, D3DX_FILTER_NONE
, 0, NULL
);
910 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
911 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
912 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x\n", hr
);
913 ok(*(DWORD
*)lockrect
.pBits
== 0xfff3f2f1, "Pixel color mismatch: got %#x, expected 0xfff3f2f1\n", *(DWORD
*)lockrect
.pBits
);
914 hr
= IDirect3DSurface9_UnlockRect(surf
);
915 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x\n", hr
);
917 check_release((IUnknown
*)surf
, 0);
921 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A1R5G5B5
, D3DPOOL_DEFAULT
, &surf
, NULL
);
922 if(FAILED(hr
)) skip("Failed to create a surface (%#x)\n", hr
);
924 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
, D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
925 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
926 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
927 check_pixel_2bpp(&lockrect
, 0, 0, 0x6fff);
928 check_pixel_2bpp(&lockrect
, 1, 0, 0xffe0);
929 check_pixel_2bpp(&lockrect
, 0, 1, 0xefea);
930 check_pixel_2bpp(&lockrect
, 1, 1, 0xca4a);
931 IDirect3DSurface9_UnlockRect(surf
);
933 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
, D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
934 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
935 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
936 check_pixel_2bpp(&lockrect
, 0, 0, 0x46b5);
937 check_pixel_2bpp(&lockrect
, 1, 0, 0x99c8);
938 check_pixel_2bpp(&lockrect
, 0, 1, 0x06a2);
939 check_pixel_2bpp(&lockrect
, 1, 1, 0x9431);
940 IDirect3DSurface9_UnlockRect(surf
);
942 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
, D3DFMT_R5G6B5
, 4, 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
);
945 check_pixel_2bpp(&lockrect
, 0, 0, 0xcf76);
946 check_pixel_2bpp(&lockrect
, 1, 0, 0xb2cd);
947 check_pixel_2bpp(&lockrect
, 0, 1, 0x856e);
948 check_pixel_2bpp(&lockrect
, 1, 1, 0xa16e);
949 IDirect3DSurface9_UnlockRect(surf
);
951 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
, D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
952 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
953 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
955 check_pixel_2bpp(&lockrect
, 0, 0, 0xa03f);
957 check_pixel_2bpp(&lockrect
, 1, 0, 0xa37f);
958 check_pixel_2bpp(&lockrect
, 0, 1, 0xcb9f);
959 check_pixel_2bpp(&lockrect
, 1, 1, 0xfe7f);
960 IDirect3DSurface9_UnlockRect(surf
);
962 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
, D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
963 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
964 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
966 check_pixel_2bpp(&lockrect
, 0, 0, 0xf527);
967 check_pixel_2bpp(&lockrect
, 1, 0, 0x4b8b);
969 check_pixel_2bpp(&lockrect
, 0, 1, 0x7e56);
970 check_pixel_2bpp(&lockrect
, 1, 1, 0xf8b8);
971 IDirect3DSurface9_UnlockRect(surf
);
973 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
, D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
974 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
975 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
976 check_pixel_2bpp(&lockrect
, 0, 0, 0x2e57);
978 check_pixel_2bpp(&lockrect
, 1, 0, 0x3588);
980 check_pixel_2bpp(&lockrect
, 0, 1, 0xe215);
981 check_pixel_2bpp(&lockrect
, 1, 1, 0xff0e);
982 IDirect3DSurface9_UnlockRect(surf
);
984 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8l8
,
985 D3DFMT_A8L8
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
986 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
987 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
988 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
989 check_pixel_2bpp(&lockrect
, 0, 0, 0x8000);
990 check_pixel_2bpp(&lockrect
, 1, 0, 0x7fff);
991 check_pixel_2bpp(&lockrect
, 0, 1, 0x98c6);
992 check_pixel_2bpp(&lockrect
, 1, 1, 0x3def);
993 hr
= IDirect3DSurface9_UnlockRect(surf
);
994 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
996 check_release((IUnknown
*)surf
, 0);
1000 hr
= IDirect3DDevice9_CreateTexture(device
, 2, 2, 1, 0, D3DFMT_A8L8
, D3DPOOL_MANAGED
, &tex
, NULL
);
1002 skip("Failed to create A8L8 texture, hr %#x.\n", hr
);
1005 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &surf
);
1006 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1008 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
,
1009 D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1010 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1011 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1012 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1013 check_pixel_2bpp(&lockrect
, 0, 0, 0x57f7);
1014 check_pixel_2bpp(&lockrect
, 1, 0, 0x98ed);
1015 check_pixel_2bpp(&lockrect
, 0, 1, 0xaceb);
1016 check_pixel_2bpp(&lockrect
, 1, 1, 0xc88d);
1017 hr
= IDirect3DSurface9_UnlockRect(surf
);
1018 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1020 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
,
1021 D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1022 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1023 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1024 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1025 check_pixel_2bpp(&lockrect
, 0, 0, 0x00a6);
1026 check_pixel_2bpp(&lockrect
, 1, 0, 0xff62);
1027 check_pixel_2bpp(&lockrect
, 0, 1, 0x007f);
1028 check_pixel_2bpp(&lockrect
, 1, 1, 0xff19);
1029 hr
= IDirect3DSurface9_UnlockRect(surf
);
1030 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1032 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
,
1033 D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1034 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1035 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1036 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1037 check_pixel_2bpp(&lockrect
, 0, 0, 0xffce);
1038 check_pixel_2bpp(&lockrect
, 1, 0, 0xff9c);
1039 check_pixel_2bpp(&lockrect
, 0, 1, 0xff4d);
1040 check_pixel_2bpp(&lockrect
, 1, 1, 0xff59);
1041 hr
= IDirect3DSurface9_UnlockRect(surf
);
1042 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1044 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
,
1045 D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1046 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1047 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1048 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1049 check_pixel_2bpp(&lockrect
, 0, 0, 0xff25);
1050 check_pixel_2bpp(&lockrect
, 1, 0, 0xffbe);
1051 check_pixel_2bpp(&lockrect
, 0, 1, 0xffd6);
1052 check_pixel_2bpp(&lockrect
, 1, 1, 0xffb6);
1053 hr
= IDirect3DSurface9_UnlockRect(surf
);
1054 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1056 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
,
1057 D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1058 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1059 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1060 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1061 check_pixel_2bpp(&lockrect
, 0, 0, 0xc36d);
1062 check_pixel_2bpp(&lockrect
, 1, 0, 0x23cb);
1063 check_pixel_2bpp(&lockrect
, 0, 1, 0x09af);
1064 check_pixel_2bpp(&lockrect
, 1, 1, 0x8d61);
1065 hr
= IDirect3DSurface9_UnlockRect(surf
);
1066 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1068 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
,
1069 D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1070 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1071 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1072 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1073 check_pixel_2bpp(&lockrect
, 0, 0, 0x558c);
1074 check_pixel_2bpp(&lockrect
, 1, 0, 0x5565);
1075 check_pixel_2bpp(&lockrect
, 0, 1, 0xaa95);
1076 check_pixel_2bpp(&lockrect
, 1, 1, 0xffcb);
1077 hr
= IDirect3DSurface9_UnlockRect(surf
);
1078 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1080 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8l8
,
1081 D3DFMT_A8L8
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1082 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1083 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1084 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1085 check_pixel_2bpp(&lockrect
, 0, 0, 0xff00);
1086 check_pixel_2bpp(&lockrect
, 1, 0, 0x00ff);
1087 check_pixel_2bpp(&lockrect
, 0, 1, 0xff30);
1088 check_pixel_2bpp(&lockrect
, 1, 1, 0x7f7f);
1089 hr
= IDirect3DSurface9_UnlockRect(surf
);
1090 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1092 check_release((IUnknown
*)surf
, 1);
1093 check_release((IUnknown
*)tex
, 0);
1096 /* DXT1, DXT2, DXT3, DXT4, DXT5 */
1097 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surf
, NULL
);
1099 skip("Failed to create R8G8B8 surface, hr %#x.\n", hr
);
1102 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, dds_24bit
, sizeof(dds_24bit
), NULL
, D3DX_FILTER_NONE
, 0, NULL
);
1103 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1105 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT2
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1107 skip("Failed to create DXT2 texture, hr %#x.\n", hr
);
1110 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1111 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1112 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1113 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT2 format.\n");
1114 check_release((IUnknown
*)newsurf
, 1);
1115 check_release((IUnknown
*)tex
, 0);
1118 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT3
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1120 skip("Failed to create DXT3 texture, hr %#x.\n", hr
);
1123 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1124 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1125 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1126 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT3 format.\n");
1127 check_release((IUnknown
*)newsurf
, 1);
1128 check_release((IUnknown
*)tex
, 0);
1131 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT4
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1133 skip("Failed to create DXT4 texture, hr %#x.\n", hr
);
1136 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1137 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1138 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1139 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT4 format.\n");
1140 check_release((IUnknown
*)newsurf
, 1);
1141 check_release((IUnknown
*)tex
, 0);
1144 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT5
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1146 skip("Failed to create DXT5 texture, hr %#x.\n", hr
);
1149 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1150 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1151 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1152 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT5 format.\n");
1153 check_release((IUnknown
*)newsurf
, 1);
1154 check_release((IUnknown
*)tex
, 0);
1157 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT1
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1159 skip("Failed to create DXT1 texture, hr %#x.\n", hr
);
1162 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1163 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1164 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1165 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT1 format.\n");
1167 hr
= D3DXLoadSurfaceFromSurface(surf
, NULL
, NULL
, newsurf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1168 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels from DXT1 format.\n");
1170 check_release((IUnknown
*)newsurf
, 1);
1171 check_release((IUnknown
*)tex
, 0);
1174 check_release((IUnknown
*)surf
, 0);
1178 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
1179 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
1182 static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9
*device
)
1186 ID3DXBuffer
*buffer
;
1187 IDirect3DSurface9
*surface
;
1189 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &surface
, NULL
);
1191 skip("Couldn't create surface\n");
1195 SetRect(&rect
, 0, 0, 0, 0);
1196 hr
= D3DXSaveSurfaceToFileInMemory(&buffer
, D3DXIFF_BMP
, surface
, NULL
, &rect
);
1197 /* fails with the debug version of d3d9 */
1198 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
), "D3DXSaveSurfaceToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1199 if (SUCCEEDED(hr
)) {
1200 DWORD size
= ID3DXBuffer_GetBufferSize(buffer
);
1201 ok(size
> 0, "ID3DXBuffer_GetBufferSize returned %u, expected > 0\n", size
);
1202 ID3DXBuffer_Release(buffer
);
1205 IDirect3DSurface9_Release(surface
);
1208 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9
*device
)
1211 IDirect3DSurface9
*surface
;
1213 D3DLOCKED_RECT lock_rect
;
1214 D3DXIMAGE_INFO image_info
;
1215 const BYTE pixels
[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
1216 0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
1217 DWORD pitch
= sizeof(pixels
) / 2;
1219 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_R8G8B8
, D3DPOOL_SCRATCH
, &surface
, NULL
);
1221 skip("Couldn't create surface\n");
1225 SetRect(&rect
, 0, 0, 2, 2);
1226 hr
= D3DXLoadSurfaceFromMemory(surface
, NULL
, NULL
, pixels
, D3DFMT_R8G8B8
, pitch
, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1227 if (SUCCEEDED(hr
)) {
1228 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, NULL
);
1229 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1231 hr
= D3DXLoadSurfaceFromFileA(surface
, NULL
, NULL
, "saved_surface.bmp", NULL
, D3DX_FILTER_NONE
, 0, &image_info
);
1232 ok(hr
== D3D_OK
, "Couldn't load saved surface %#x\n", hr
);
1233 if (FAILED(hr
)) goto next_tests
;
1235 ok(image_info
.Width
== 2, "Wrong width %u\n", image_info
.Width
);
1236 ok(image_info
.Height
== 2, "Wrong height %u\n", image_info
.Height
);
1237 ok(image_info
.Format
== D3DFMT_R8G8B8
, "Wrong format %#x\n", image_info
.Format
);
1238 ok(image_info
.ImageFileFormat
== D3DXIFF_BMP
, "Wrong file format %u\n", image_info
.ImageFileFormat
);
1240 hr
= IDirect3DSurface9_LockRect(surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1241 ok(hr
== D3D_OK
, "Couldn't lock surface %#x\n", hr
);
1242 if (FAILED(hr
)) goto next_tests
;
1244 ok(!memcmp(lock_rect
.pBits
, pixels
, pitch
), "Pixel data mismatch in first row\n");
1245 ok(!memcmp((BYTE
*)lock_rect
.pBits
+ lock_rect
.Pitch
, pixels
+ pitch
, pitch
), "Pixel data mismatch in second row\n");
1247 IDirect3DSurface9_UnlockRect(surface
);
1248 } else skip("Couldn't fill surface\n");
1251 hr
= D3DXSaveSurfaceToFileA(NULL
, D3DXIFF_BMP
, surface
, NULL
, NULL
);
1252 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1254 /* PPM and TGA are supported, even though MSDN claims they aren't */
1256 hr
= D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM
, surface
, NULL
, NULL
);
1257 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1258 hr
= D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA
, surface
, NULL
, NULL
);
1259 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1262 hr
= D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS
, surface
, NULL
, NULL
);
1263 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1264 if (SUCCEEDED(hr
)) {
1265 hr
= D3DXLoadSurfaceFromFileA(surface
, NULL
, NULL
, "saved_surface.dds", NULL
, D3DX_FILTER_NONE
, 0, &image_info
);
1266 ok(hr
== D3D_OK
, "Couldn't load saved surface %#x\n", hr
);
1268 if (SUCCEEDED(hr
)) {
1269 ok(image_info
.Width
== 2, "Wrong width %u\n", image_info
.Width
);
1270 ok(image_info
.Format
== D3DFMT_R8G8B8
, "Wrong format %#x\n", image_info
.Format
);
1271 ok(image_info
.ImageFileFormat
== D3DXIFF_DDS
, "Wrong file format %u\n", image_info
.ImageFileFormat
);
1273 hr
= IDirect3DSurface9_LockRect(surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1274 ok(hr
== D3D_OK
, "Couldn't lock surface %#x\n", hr
);
1275 if (SUCCEEDED(hr
)) {
1276 ok(!memcmp(lock_rect
.pBits
, pixels
, pitch
), "Pixel data mismatch in first row\n");
1277 ok(!memcmp((BYTE
*)lock_rect
.pBits
+ lock_rect
.Pitch
, pixels
+ pitch
, pitch
), "Pixel data mismatch in second row\n");
1278 IDirect3DSurface9_UnlockRect(surface
);
1281 } else skip("Couldn't save surface\n");
1283 hr
= D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM
+ 1, surface
, NULL
, NULL
);
1284 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1286 SetRect(&rect
, 0, 0, 4, 4);
1287 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1288 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1289 SetRect(&rect
, 2, 0, 1, 4);
1290 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1291 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1292 SetRect(&rect
, 0, 2, 4, 1);
1293 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1294 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1295 SetRect(&rect
, -1, -1, 2, 2);
1296 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1297 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1298 SetRect(&rect
, 0, 0, 0, 0);
1299 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1300 /* fails when debug version of d3d9 is used */
1301 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
), "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1303 DeleteFileA("saved_surface.bmp");
1304 DeleteFileA("saved_surface.ppm");
1305 DeleteFileA("saved_surface.tga");
1306 DeleteFileA("saved_surface.dds");
1308 IDirect3DSurface9_Release(surface
);
1315 IDirect3DDevice9
*device
;
1316 D3DPRESENT_PARAMETERS d3dpp
;
1319 if (!(wnd
= CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW
, 0, 0,
1320 640, 480, NULL
, NULL
, NULL
, NULL
)))
1322 skip("Couldn't create application window\n");
1325 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
1327 skip("Couldn't create IDirect3D9 object\n");
1332 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
1333 d3dpp
.Windowed
= TRUE
;
1334 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1335 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, wnd
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device
);
1337 skip("Failed to create IDirect3DDevice9 object %#x\n", hr
);
1338 IDirect3D9_Release(d3d
);
1343 test_D3DXGetImageInfo();
1344 test_D3DXLoadSurface(device
);
1345 test_D3DXSaveSurfaceToFileInMemory(device
);
1346 test_D3DXSaveSurfaceToFile(device
);
1348 check_release((IUnknown
*)device
, 0);
1349 check_release((IUnknown
*)d3d
, 0);