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_MIPMAPCOUNT 0x00020000
175 #define DDS_LINEARSIZE 0x00080000
177 /* dds_header.caps */
178 #define DDSCAPS_ALPHA 0x00000002
179 #define DDS_CAPS_TEXTURE 0x00001000
181 /* dds_pixel_format.flags */
182 #define DDS_PF_ALPHA 0x00000001
183 #define DDS_PF_ALPHA_ONLY 0x00000002
184 #define DDS_PF_FOURCC 0x00000004
185 #define DDS_PF_RGB 0x00000040
186 #define DDS_PF_LUMINANCE 0x00020000
187 #define DDS_PF_BUMPDUDV 0x00080000
189 struct dds_pixel_format
207 DWORD pitch_or_linear_size
;
211 struct dds_pixel_format pixel_format
;
219 /* fills dds_header with reasonable default values */
220 static void fill_dds_header(struct dds_header
*header
)
222 memset(header
, 0, sizeof(*header
));
224 header
->size
= sizeof(*header
);
225 header
->flags
= DDS_CAPS
| DDS_WIDTH
| DDS_HEIGHT
| DDS_PIXELFORMAT
;
228 header
->pixel_format
.size
= sizeof(header
->pixel_format
);
230 header
->pixel_format
.flags
= DDS_PF_RGB
;
231 header
->pixel_format
.fourcc
= 0;
232 header
->pixel_format
.bpp
= 32;
233 header
->pixel_format
.rmask
= 0xff0000;
234 header
->pixel_format
.gmask
= 0x00ff00;
235 header
->pixel_format
.bmask
= 0x0000ff;
236 header
->pixel_format
.amask
= 0;
237 header
->caps
= DDS_CAPS_TEXTURE
;
240 #define check_dds_pixel_format(flags, fourcc, bpp, rmask, gmask, bmask, amask, format) \
241 check_dds_pixel_format_(__LINE__, flags, fourcc, bpp, rmask, gmask, bmask, amask, format)
242 static void check_dds_pixel_format_(unsigned int line
,
243 DWORD flags
, DWORD fourcc
, DWORD bpp
,
244 DWORD rmask
, DWORD gmask
, DWORD bmask
, DWORD amask
,
245 D3DFORMAT expected_format
)
252 struct dds_header header
;
256 dds
.magic
= MAKEFOURCC('D','D','S',' ');
257 fill_dds_header(&dds
.header
);
258 dds
.header
.pixel_format
.flags
= flags
;
259 dds
.header
.pixel_format
.fourcc
= fourcc
;
260 dds
.header
.pixel_format
.bpp
= bpp
;
261 dds
.header
.pixel_format
.rmask
= rmask
;
262 dds
.header
.pixel_format
.gmask
= gmask
;
263 dds
.header
.pixel_format
.bmask
= bmask
;
264 dds
.header
.pixel_format
.amask
= amask
;
265 memset(dds
.data
, 0, sizeof(dds
.data
));
267 hr
= D3DXGetImageInfoFromFileInMemory(&dds
, sizeof(dds
), &info
);
268 ok_(__FILE__
, line
)(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x for pixel format %#x, expected %#x\n",
269 hr
, expected_format
, D3D_OK
);
272 ok_(__FILE__
, line
)(info
.Format
== expected_format
, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n",
273 info
.Format
, expected_format
);
277 static void test_dds_header_handling(void)
285 struct dds_header header
;
286 BYTE data
[4096 * 1024];
291 struct dds_pixel_format pixel_format
;
297 DWORD pixel_data_size
;
305 /* pitch is ignored */
306 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, 0, 4, 4, 0, 0,
307 63 /* pixel data size */, { D3DXERR_INVALIDDATA
, 0 } },
308 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 0 /* pitch */, 0,
310 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 1 /* pitch */, 0,
312 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 2 /* pitch */, 0,
314 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 3 /* pitch */, 0,
316 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 4 /* pitch */, 0,
318 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 16 /* pitch */, 0,
320 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, 1024 /* pitch */, 0,
322 { { 32, DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH
, 4, 4, -1 /* pitch */, 0,
324 /* linear size is ignored */
325 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, 0, 4, 4, 0, 0,
326 7 /* pixel data size */, { D3DXERR_INVALIDDATA
, 1 } },
327 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 0 /* linear size */, 0,
329 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 1 /* linear size */, 0,
331 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 2 /* linear size */, 0,
333 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 9 /* linear size */, 0,
335 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, 16 /* linear size */, 0,
337 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE
, 4, 4, -1 /* linear size */, 0,
339 /* integer overflows */
340 { { 32, DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000000, 0x80000000 /* 0x80000000 * 0x80000000 * 4 = 0 */, 0, 0,
342 { { 32, DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x8000100, 0x800100 /* 0x8000100 * 0x800100 * 4 = 262144 */, 0, 0,
343 64, { D3DXERR_INVALIDDATA
, 0 } },
344 { { 32, DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0, 0,
346 { { 32, DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0, 0,
347 3 /* pixel data size */, { D3DXERR_INVALIDDATA
, 0 } },
348 /* file size is validated */
349 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 64, 0, 0, 49151, { D3DXERR_INVALIDDATA
, 0 } },
350 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 64, 0, 0, 49152, { D3D_OK
, 1 } },
351 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 64, 0, 4, 65279, { D3DXERR_INVALIDDATA
, 0 } },
352 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 64, 0, 4, 65280, { D3D_OK
, 4 } },
353 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 64, 0, 9, 65540, { D3DXERR_INVALIDDATA
, 0 } },
354 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 64, 0, 9, 65541, { D3D_OK
, 9 } },
355 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196607, { D3DXERR_INVALIDDATA
, 0 } },
356 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196608, { D3D_OK
, 1 } },
357 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196609, { D3D_OK
, 1 } },
358 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 1, 196607, { D3DXERR_INVALIDDATA
, 0 } },
359 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 1, 196608, { D3D_OK
, 1 } },
360 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 0, 196607, { D3DXERR_INVALIDDATA
, 0 } },
361 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 0, 196608, { D3D_OK
, 1 } },
362 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 0, 400000, { D3D_OK
, 1 } },
363 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 9, 262142, { D3DXERR_INVALIDDATA
, 0 } },
364 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 9, 262143, { D3D_OK
, 9 } },
365 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 10, 262145, { D3DXERR_INVALIDDATA
, 0 } },
366 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 10, 262146, { D3D_OK
, 10 } },
367 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 20, 262175, { D3DXERR_INVALIDDATA
, 0 } },
368 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 20, 262176, { D3D_OK
, 20 } },
369 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 32767, { D3DXERR_INVALIDDATA
, 0 } },
370 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 32768, { D3D_OK
, 1 } },
371 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 0, 32767, { D3DXERR_INVALIDDATA
, 0 } },
372 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 0, 32768, { D3D_OK
, 1 } },
373 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 9, 43703, { D3DXERR_INVALIDDATA
, 0 } },
374 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 9, 43704, { D3D_OK
, 9 } },
375 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 20, 43791, { D3DXERR_INVALIDDATA
, 0 } },
376 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 20, 43792, { D3D_OK
, 20 } },
377 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT4
, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 65535, { D3DXERR_INVALIDDATA
, 0 } },
378 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT4
, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 65536, { D3D_OK
, 1 } },
379 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT4
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 0, 65535, { D3DXERR_INVALIDDATA
, 0 } },
380 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT4
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 0, 65536, { D3D_OK
, 1 } },
381 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT4
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 9, 87407, { D3DXERR_INVALIDDATA
, 0 } },
382 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT4
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 9, 87408, { D3D_OK
, 9 } },
383 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT4
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 20, 87583, { D3DXERR_INVALIDDATA
, 0 } },
384 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT4
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 256, 0, 20, 87584, { D3D_OK
, 20 } },
385 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT4
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 64, 0, 4, 21759, { D3DXERR_INVALIDDATA
, 0 } },
386 { { 32, DDS_PF_FOURCC
, D3DFMT_DXT4
, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT
, 256, 64, 0, 4, 21760, { D3D_OK
, 4 } },
387 /* DDS_MIPMAPCOUNT is ignored */
388 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 262146, { D3D_OK
, 1 } },
389 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 2, 262146, { D3D_OK
, 2 } },
390 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 9, 262146, { D3D_OK
, 9 } },
391 { { 32, DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 10, 262146, { D3D_OK
, 10 } },
394 dds
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*dds
));
397 skip("Failed to allocate memory.\n");
401 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
403 DWORD file_size
= sizeof(dds
->magic
) + sizeof(dds
->header
) + tests
[i
].pixel_data_size
;
404 assert(file_size
<= sizeof(*dds
));
406 dds
->magic
= MAKEFOURCC('D','D','S',' ');
407 fill_dds_header(&dds
->header
);
408 dds
->header
.flags
|= tests
[i
].flags
;
409 dds
->header
.width
= tests
[i
].width
;
410 dds
->header
.height
= tests
[i
].height
;
411 dds
->header
.pitch_or_linear_size
= tests
[i
].pitch
;
412 dds
->header
.miplevels
= tests
[i
].miplevels
;
413 dds
->header
.pixel_format
= tests
[i
].pixel_format
;
415 hr
= D3DXGetImageInfoFromFileInMemory(dds
, file_size
, &info
);
416 ok(hr
== tests
[i
].expected
.hr
, "%d: D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n",
417 i
, hr
, tests
[i
].expected
.hr
);
420 ok(info
.MipLevels
== tests
[i
].expected
.miplevels
, "%d: Got MipLevels %u, expected %u\n",
421 i
, info
.MipLevels
, tests
[i
].expected
.miplevels
);
425 HeapFree(GetProcessHeap(), 0, dds
);
428 static void test_D3DXGetImageInfo(void)
432 BOOL testdummy_ok
, testbitmap_ok
;
434 hr
= create_file("testdummy.bmp", noimage
, sizeof(noimage
)); /* invalid image */
435 testdummy_ok
= SUCCEEDED(hr
);
437 hr
= create_file("testbitmap.bmp", bmp_1bpp
, sizeof(bmp_1bpp
)); /* valid image */
438 testbitmap_ok
= SUCCEEDED(hr
);
440 /* D3DXGetImageInfoFromFile */
442 hr
= D3DXGetImageInfoFromFileA("testbitmap.bmp", &info
);
443 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
445 hr
= D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL
); /* valid image, second parameter is NULL */
446 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
447 } else skip("Couldn't create \"testbitmap.bmp\"\n");
450 hr
= D3DXGetImageInfoFromFileA("testdummy.bmp", NULL
); /* invalid image, second parameter is NULL */
451 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
453 hr
= D3DXGetImageInfoFromFileA("testdummy.bmp", &info
);
454 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
455 } else skip("Couldn't create \"testdummy.bmp\"\n");
457 hr
= D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info
);
458 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
460 hr
= D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL
);
461 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
463 hr
= D3DXGetImageInfoFromFileA("", &info
);
464 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
466 hr
= D3DXGetImageInfoFromFileA(NULL
, &info
);
467 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
469 hr
= D3DXGetImageInfoFromFileA(NULL
, NULL
);
470 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
473 /* D3DXGetImageInfoFromResource */
474 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDB_BITMAP_1x1
), &info
); /* RT_BITMAP */
475 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
477 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDB_BITMAP_1x1
), NULL
);
478 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
480 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), &info
); /* RT_RCDATA */
481 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
483 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDS_STRING
), &info
);
484 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
486 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDS_STRING
), NULL
);
487 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
489 hr
= D3DXGetImageInfoFromResourceA(NULL
, "resourcedoesnotexist", &info
);
490 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
492 hr
= D3DXGetImageInfoFromResourceA(NULL
, "resourcedoesnotexist", NULL
);
493 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
495 hr
= D3DXGetImageInfoFromResourceA(NULL
, NULL
, NULL
);
496 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
499 /* D3DXGetImageInfoFromFileInMemory */
500 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
), &info
);
501 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
503 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
)+5, &info
); /* too large size */
504 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
506 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
), NULL
);
507 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
509 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, sizeof(noimage
), NULL
);
510 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
512 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, sizeof(noimage
), &info
);
513 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
516 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
)-1, &info
);
517 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
520 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
+1, sizeof(bmp_1bpp
)-1, &info
);
521 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
523 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, 0, &info
);
524 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
526 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, 0, NULL
);
527 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
529 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, 0, &info
);
530 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
532 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, 0, NULL
);
533 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
535 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 0, &info
);
536 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
538 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 4, NULL
);
539 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
541 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 4, &info
);
542 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
544 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 0, NULL
);
545 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
547 /* test BMP support */
548 hr
= D3DXGetImageInfoFromFileInMemory(bmp_1bpp
, sizeof(bmp_1bpp
), &info
);
549 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
550 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
551 ok(info
.Format
== D3DFMT_P8
, "Got format %u, expected %u\n", info
.Format
, D3DFMT_P8
);
552 hr
= D3DXGetImageInfoFromFileInMemory(bmp_2bpp
, sizeof(bmp_2bpp
), &info
);
553 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
554 hr
= D3DXGetImageInfoFromFileInMemory(bmp_4bpp
, sizeof(bmp_4bpp
), &info
);
555 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
556 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
557 ok(info
.Format
== D3DFMT_P8
, "Got format %u, expected %u\n", info
.Format
, D3DFMT_P8
);
558 hr
= D3DXGetImageInfoFromFileInMemory(bmp_8bpp
, sizeof(bmp_8bpp
), &info
);
559 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
560 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
561 ok(info
.Format
== D3DFMT_P8
, "Got format %u, expected %u\n", info
.Format
, D3DFMT_P8
);
564 hr
= D3DXGetImageInfoFromFileInMemory(png_grayscale
, sizeof(png_grayscale
), &info
);
565 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
566 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
567 ok(info
.Format
== D3DFMT_L8
, "Got format %u, expected %u\n", info
.Format
, D3DFMT_L8
);
569 /* test DDS support */
570 hr
= D3DXGetImageInfoFromFileInMemory(dds_24bit
, sizeof(dds_24bit
), &info
);
571 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
573 ok(info
.Width
== 2, "Got width %u, expected 2\n", info
.Width
);
574 ok(info
.Height
== 2, "Got height %u, expected 2\n", info
.Height
);
575 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
576 ok(info
.MipLevels
== 2, "Got miplevels %u, expected 2\n", info
.MipLevels
);
577 ok(info
.Format
== D3DFMT_R8G8B8
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_R8G8B8
);
578 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
579 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
580 } else skip("Couldn't get image info from 24-bit DDS file in memory\n");
582 hr
= D3DXGetImageInfoFromFileInMemory(dds_16bit
, sizeof(dds_16bit
), &info
);
583 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
585 ok(info
.Width
== 2, "Got width %u, expected 2\n", info
.Width
);
586 ok(info
.Height
== 2, "Got height %u, expected 2\n", info
.Height
);
587 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
588 ok(info
.MipLevels
== 1, "Got miplevels %u, expected 1\n", info
.MipLevels
);
589 ok(info
.Format
== D3DFMT_X1R5G5B5
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_X1R5G5B5
);
590 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
591 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
592 } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
594 hr
= D3DXGetImageInfoFromFileInMemory(dds_cube_map
, sizeof(dds_cube_map
), &info
);
595 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
597 ok(info
.Width
== 4, "Got width %u, expected 4\n", info
.Width
);
598 ok(info
.Height
== 4, "Got height %u, expected 4\n", info
.Height
);
599 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
600 ok(info
.MipLevels
== 1, "Got miplevels %u, expected 1\n", info
.MipLevels
);
601 ok(info
.Format
== D3DFMT_DXT5
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_DXT5
);
602 ok(info
.ResourceType
== D3DRTYPE_CUBETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_CUBETEXTURE
);
603 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
604 } else skip("Couldn't get image info from cube map in memory\n");
606 hr
= D3DXGetImageInfoFromFileInMemory(dds_volume_map
, sizeof(dds_volume_map
), &info
);
607 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
609 ok(info
.Width
== 4, "Got width %u, expected 4\n", info
.Width
);
610 ok(info
.Height
== 4, "Got height %u, expected 4\n", info
.Height
);
611 ok(info
.Depth
== 2, "Got depth %u, expected 2\n", info
.Depth
);
612 ok(info
.MipLevels
== 3, "Got miplevels %u, expected 3\n", info
.MipLevels
);
613 ok(info
.Format
== D3DFMT_DXT3
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_DXT3
);
614 ok(info
.ResourceType
== D3DRTYPE_VOLUMETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_VOLUMETEXTURE
);
615 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
616 } else skip("Couldn't get image info from volume map in memory\n");
618 check_dds_pixel_format(DDS_PF_FOURCC
, D3DFMT_DXT1
, 0, 0, 0, 0, 0, D3DFMT_DXT1
);
619 check_dds_pixel_format(DDS_PF_FOURCC
, D3DFMT_DXT2
, 0, 0, 0, 0, 0, D3DFMT_DXT2
);
620 check_dds_pixel_format(DDS_PF_FOURCC
, D3DFMT_DXT3
, 0, 0, 0, 0, 0, D3DFMT_DXT3
);
621 check_dds_pixel_format(DDS_PF_FOURCC
, D3DFMT_DXT4
, 0, 0, 0, 0, 0, D3DFMT_DXT4
);
622 check_dds_pixel_format(DDS_PF_FOURCC
, D3DFMT_DXT5
, 0, 0, 0, 0, 0, D3DFMT_DXT5
);
623 check_dds_pixel_format(DDS_PF_FOURCC
, D3DFMT_R8G8_B8G8
, 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8
);
624 check_dds_pixel_format(DDS_PF_FOURCC
, D3DFMT_G8R8_G8B8
, 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8
);
625 check_dds_pixel_format(DDS_PF_FOURCC
, D3DFMT_UYVY
, 0, 0, 0, 0, 0, D3DFMT_UYVY
);
626 check_dds_pixel_format(DDS_PF_FOURCC
, D3DFMT_YUY2
, 0, 0, 0, 0, 0, D3DFMT_YUY2
);
627 check_dds_pixel_format(DDS_PF_RGB
, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5
);
628 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5
);
629 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4
);
630 check_dds_pixel_format(DDS_PF_RGB
, 0, 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2
);
631 check_dds_pixel_format(DDS_PF_ALPHA_ONLY
, 0, 8, 0, 0, 0, 0xff, D3DFMT_A8
);
632 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2
);
633 check_dds_pixel_format(DDS_PF_RGB
, 0, 16, 0xf00, 0x0f0, 0x00f, 0, D3DFMT_X4R4G4B4
);
634 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10
);
635 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10
);
636 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8
);
637 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, D3DFMT_A8B8G8R8
);
638 check_dds_pixel_format(DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_X8R8G8B8
);
639 check_dds_pixel_format(DDS_PF_RGB
, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8B8G8R8
);
640 check_dds_pixel_format(DDS_PF_RGB
, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_R8G8B8
);
641 check_dds_pixel_format(DDS_PF_RGB
, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_G16R16
);
642 check_dds_pixel_format(DDS_PF_LUMINANCE
, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8
);
643 check_dds_pixel_format(DDS_PF_LUMINANCE
, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16
);
644 check_dds_pixel_format(DDS_PF_LUMINANCE
| DDS_PF_ALPHA
, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8
);
645 check_dds_pixel_format(DDS_PF_LUMINANCE
| DDS_PF_ALPHA
, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4
);
646 check_dds_pixel_format(DDS_PF_BUMPDUDV
, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8
);
647 check_dds_pixel_format(DDS_PF_BUMPDUDV
, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16
);
649 test_dds_header_handling();
651 hr
= D3DXGetImageInfoFromFileInMemory(dds_16bit
, sizeof(dds_16bit
) - 1, &info
);
652 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
654 hr
= D3DXGetImageInfoFromFileInMemory(dds_24bit
, sizeof(dds_24bit
) - 1, &info
);
655 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
657 hr
= D3DXGetImageInfoFromFileInMemory(dds_cube_map
, sizeof(dds_cube_map
) - 1, &info
);
658 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
660 hr
= D3DXGetImageInfoFromFileInMemory(dds_volume_map
, sizeof(dds_volume_map
) - 1, &info
);
661 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
665 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
666 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
669 #define check_pixel_2bpp(lockrect, x, y, color) _check_pixel_2bpp(__LINE__, lockrect, x, y, color)
670 static inline void _check_pixel_2bpp(unsigned int line
, const D3DLOCKED_RECT
*lockrect
, int x
, int y
, WORD expected_color
)
672 WORD color
= ((WORD
*)lockrect
->pBits
)[x
+ y
* lockrect
->Pitch
/ 2];
673 ok_(__FILE__
, line
)(color
== expected_color
, "Got color 0x%04x, expected 0x%04x\n", color
, expected_color
);
676 #define check_pixel_4bpp(lockrect, x, y, color) _check_pixel_4bpp(__LINE__, lockrect, x, y, color)
677 static inline void _check_pixel_4bpp(unsigned int line
, const D3DLOCKED_RECT
*lockrect
, int x
, int y
, DWORD expected_color
)
679 DWORD color
= ((DWORD
*)lockrect
->pBits
)[x
+ y
* lockrect
->Pitch
/ 4];
680 ok_(__FILE__
, line
)(color
== expected_color
, "Got color 0x%08x, expected 0x%08x\n", color
, expected_color
);
683 static void test_D3DXLoadSurface(IDirect3DDevice9
*device
)
686 BOOL testdummy_ok
, testbitmap_ok
;
687 IDirect3DTexture9
*tex
;
688 IDirect3DSurface9
*surf
, *newsurf
;
690 D3DLOCKED_RECT lockrect
;
691 const WORD pixdata_a8r3g3b2
[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
692 const WORD pixdata_a1r5g5b5
[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
693 const WORD pixdata_r5g6b5
[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
694 const WORD pixdata_a8l8
[] = { 0xff00, 0x00ff, 0xff30, 0x7f7f };
695 const DWORD pixdata_g16r16
[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
696 const DWORD pixdata_a8b8g8r8
[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
697 const DWORD pixdata_a2r10g10b10
[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
699 hr
= create_file("testdummy.bmp", noimage
, sizeof(noimage
)); /* invalid image */
700 testdummy_ok
= SUCCEEDED(hr
);
702 hr
= create_file("testbitmap.bmp", bmp_1bpp
, sizeof(bmp_1bpp
)); /* valid image */
703 testbitmap_ok
= SUCCEEDED(hr
);
705 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf
, NULL
);
707 skip("Failed to create a surface (%#x)\n", hr
);
708 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
709 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
713 /* D3DXLoadSurfaceFromFile */
715 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "testbitmap.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
716 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
718 hr
= D3DXLoadSurfaceFromFileA(NULL
, NULL
, NULL
, "testbitmap.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
719 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
720 } else skip("Couldn't create \"testbitmap.bmp\"\n");
723 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "testdummy.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
724 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
725 } else skip("Couldn't create \"testdummy.bmp\"\n");
727 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0, NULL
);
728 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
730 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "", NULL
, D3DX_DEFAULT
, 0, NULL
);
731 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
734 /* D3DXLoadSurfaceFromResource */
735 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
,
736 MAKEINTRESOURCEA(IDB_BITMAP_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
737 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
739 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
,
740 MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
741 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
743 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0, NULL
);
744 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
746 hr
= D3DXLoadSurfaceFromResourceA(NULL
, NULL
, NULL
, NULL
,
747 MAKEINTRESOURCEA(IDB_BITMAP_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
748 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
750 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
,
751 MAKEINTRESOURCEA(IDS_STRING
), NULL
, D3DX_DEFAULT
, 0, NULL
);
752 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
755 /* D3DXLoadSurfaceFromFileInMemory */
756 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, bmp_1bpp
, sizeof(bmp_1bpp
), NULL
, D3DX_DEFAULT
, 0, NULL
);
757 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
759 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, noimage
, sizeof(noimage
), NULL
, D3DX_DEFAULT
, 0, NULL
);
760 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
762 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, bmp_1bpp
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
763 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
765 hr
= D3DXLoadSurfaceFromFileInMemory(NULL
, NULL
, NULL
, bmp_1bpp
, sizeof(bmp_1bpp
), NULL
, D3DX_DEFAULT
, 0, NULL
);
766 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
768 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, NULL
, 8, NULL
, D3DX_DEFAULT
, 0, NULL
);
769 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
771 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, NULL
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
772 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
774 hr
= D3DXLoadSurfaceFromFileInMemory(NULL
, NULL
, NULL
, NULL
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
775 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
778 /* D3DXLoadSurfaceFromMemory */
779 SetRect(&rect
, 0, 0, 2, 2);
781 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
782 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
784 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, 0, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
785 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
787 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, NULL
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
788 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
790 hr
= D3DXLoadSurfaceFromMemory(NULL
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
791 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
793 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, NULL
, D3DX_DEFAULT
, 0);
794 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
796 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_UNKNOWN
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
797 ok(hr
== E_FAIL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, E_FAIL
);
799 SetRect(&destrect
, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
800 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
801 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
803 SetRect(&destrect
, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
804 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
805 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
807 SetRect(&destrect
, 1, 1, 0, 0); /* left > right, top > bottom */
808 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
809 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
811 SetRect(&destrect
, 1, 2, 1, 2); /* left = right, top = bottom */
812 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
813 /* fails when debug version of d3d9 is used */
814 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
), "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
816 SetRect(&destrect
, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
817 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
818 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
821 /* D3DXLoadSurfaceFromSurface */
822 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &newsurf
, NULL
);
824 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
825 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
827 hr
= D3DXLoadSurfaceFromSurface(NULL
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
828 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
830 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0);
831 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
833 check_release((IUnknown
*)newsurf
, 0);
834 } else skip("Failed to create a second surface\n");
836 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
839 IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
841 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
842 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
844 IDirect3DSurface9_Release(newsurf
);
845 IDirect3DTexture9_Release(tex
);
846 } else skip("Failed to create texture\n");
848 /* non-lockable render target */
849 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &newsurf
, NULL
);
851 hr
= D3DXLoadSurfaceFromSurface(surf
, NULL
, NULL
, newsurf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
852 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
854 IDirect3DSurface9_Release(newsurf
);
855 } else skip("Failed to create render target surface\n");
857 /* non-lockable multisampled render target */
858 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_2_SAMPLES
, 0, FALSE
, &newsurf
, NULL
);
860 hr
= D3DXLoadSurfaceFromSurface(surf
, NULL
, NULL
, newsurf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
861 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
863 IDirect3DSurface9_Release(newsurf
);
864 } else skip("Failed to create multisampled render target\n");
866 check_release((IUnknown
*)surf
, 0);
869 /* test color conversion */
871 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf
, NULL
);
872 if(FAILED(hr
)) skip("Failed to create a surface (%#x)\n", hr
);
874 PALETTEENTRY palette
;
876 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
, D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
877 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
878 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
879 check_pixel_4bpp(&lockrect
, 0, 0, 0x57dbffff);
880 check_pixel_4bpp(&lockrect
, 1, 0, 0x98ffff00);
881 check_pixel_4bpp(&lockrect
, 0, 1, 0xacdbff55);
882 check_pixel_4bpp(&lockrect
, 1, 1, 0xc8929255);
883 IDirect3DSurface9_UnlockRect(surf
);
885 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
, D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
886 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
887 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
888 check_pixel_4bpp(&lockrect
, 0, 0, 0x008cadad);
889 check_pixel_4bpp(&lockrect
, 1, 0, 0xff317342);
890 check_pixel_4bpp(&lockrect
, 0, 1, 0x0008ad10);
891 check_pixel_4bpp(&lockrect
, 1, 1, 0xff29088c);
892 IDirect3DSurface9_UnlockRect(surf
);
894 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
, D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
895 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
896 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
897 check_pixel_4bpp(&lockrect
, 0, 0, 0xff9cdfb5);
898 check_pixel_4bpp(&lockrect
, 1, 0, 0xff63b26b);
899 check_pixel_4bpp(&lockrect
, 0, 1, 0xff085d73);
900 check_pixel_4bpp(&lockrect
, 1, 1, 0xff425d73);
901 IDirect3DSurface9_UnlockRect(surf
);
903 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
, D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
904 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
905 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
907 check_pixel_4bpp(&lockrect
, 0, 0, 0xff3f08ff);
909 check_pixel_4bpp(&lockrect
, 1, 0, 0xff44dcff);
910 check_pixel_4bpp(&lockrect
, 0, 1, 0xff97e4ff);
911 check_pixel_4bpp(&lockrect
, 1, 1, 0xfffe9aff);
912 IDirect3DSurface9_UnlockRect(surf
);
914 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
, D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
915 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
916 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
917 check_pixel_4bpp(&lockrect
, 0, 0, 0xc3f04c39);
918 check_pixel_4bpp(&lockrect
, 1, 0, 0x2392e85a);
919 check_pixel_4bpp(&lockrect
, 0, 1, 0x09fd97b1);
920 check_pixel_4bpp(&lockrect
, 1, 1, 0x8df62bc3);
921 IDirect3DSurface9_UnlockRect(surf
);
923 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
, D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
924 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
925 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
926 check_pixel_4bpp(&lockrect
, 0, 0, 0x555c95bf);
927 check_pixel_4bpp(&lockrect
, 1, 0, 0x556d663f);
928 check_pixel_4bpp(&lockrect
, 0, 1, 0xaac385ad);
930 check_pixel_4bpp(&lockrect
, 1, 1, 0xfffcc575);
932 IDirect3DSurface9_UnlockRect(surf
);
934 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8l8
,
935 D3DFMT_A8L8
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
936 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
937 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
938 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
939 check_pixel_4bpp(&lockrect
, 0, 0, 0xff000000);
940 check_pixel_4bpp(&lockrect
, 1, 0, 0x00ffffff);
941 check_pixel_4bpp(&lockrect
, 0, 1, 0xff303030);
942 check_pixel_4bpp(&lockrect
, 1, 1, 0x7f7f7f7f);
943 hr
= IDirect3DSurface9_UnlockRect(surf
);
944 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
946 /* Test D3DXLoadSurfaceFromMemory with indexed color image */
947 palette
.peRed
= bmp_1bpp
[56];
948 palette
.peGreen
= bmp_1bpp
[55];
949 palette
.peBlue
= bmp_1bpp
[54];
950 palette
.peFlags
= bmp_1bpp
[57]; /* peFlags is the alpha component in DX8 and higher */
951 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, &bmp_1bpp
[62], D3DFMT_P8
, 4, (const PALETTEENTRY
*)&palette
, &rect
, D3DX_FILTER_NONE
, 0);
952 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
953 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
954 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x\n", hr
);
955 ok(*(DWORD
*)lockrect
.pBits
== 0x80f3f2f1, "Pixel color mismatch: got %#x, expected 0x80f3f2f1\n", *(DWORD
*)lockrect
.pBits
);
956 hr
= IDirect3DSurface9_UnlockRect(surf
);
957 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x\n", hr
);
959 /* Test D3DXLoadSurfaceFromFileInMemory with indexed color image (alpha is not taken into account for bmp file) */
960 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, bmp_1bpp
, sizeof(bmp_1bpp
), NULL
, D3DX_FILTER_NONE
, 0, NULL
);
961 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
962 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
963 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x\n", hr
);
964 ok(*(DWORD
*)lockrect
.pBits
== 0xfff3f2f1, "Pixel color mismatch: got %#x, expected 0xfff3f2f1\n", *(DWORD
*)lockrect
.pBits
);
965 hr
= IDirect3DSurface9_UnlockRect(surf
);
966 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x\n", hr
);
968 check_release((IUnknown
*)surf
, 0);
972 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A1R5G5B5
, D3DPOOL_DEFAULT
, &surf
, NULL
);
973 if(FAILED(hr
)) skip("Failed to create a surface (%#x)\n", hr
);
975 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
, D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
976 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
977 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
978 check_pixel_2bpp(&lockrect
, 0, 0, 0x6fff);
979 check_pixel_2bpp(&lockrect
, 1, 0, 0xffe0);
980 check_pixel_2bpp(&lockrect
, 0, 1, 0xefea);
981 check_pixel_2bpp(&lockrect
, 1, 1, 0xca4a);
982 IDirect3DSurface9_UnlockRect(surf
);
984 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
, D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
985 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
986 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
987 check_pixel_2bpp(&lockrect
, 0, 0, 0x46b5);
988 check_pixel_2bpp(&lockrect
, 1, 0, 0x99c8);
989 check_pixel_2bpp(&lockrect
, 0, 1, 0x06a2);
990 check_pixel_2bpp(&lockrect
, 1, 1, 0x9431);
991 IDirect3DSurface9_UnlockRect(surf
);
993 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
, D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
994 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
995 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
996 check_pixel_2bpp(&lockrect
, 0, 0, 0xcf76);
997 check_pixel_2bpp(&lockrect
, 1, 0, 0xb2cd);
998 check_pixel_2bpp(&lockrect
, 0, 1, 0x856e);
999 check_pixel_2bpp(&lockrect
, 1, 1, 0xa16e);
1000 IDirect3DSurface9_UnlockRect(surf
);
1002 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
, D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1003 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1004 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1006 check_pixel_2bpp(&lockrect
, 0, 0, 0xa03f);
1008 check_pixel_2bpp(&lockrect
, 1, 0, 0xa37f);
1009 check_pixel_2bpp(&lockrect
, 0, 1, 0xcb9f);
1010 check_pixel_2bpp(&lockrect
, 1, 1, 0xfe7f);
1011 IDirect3DSurface9_UnlockRect(surf
);
1013 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
, D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1014 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1015 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1017 check_pixel_2bpp(&lockrect
, 0, 0, 0xf527);
1018 check_pixel_2bpp(&lockrect
, 1, 0, 0x4b8b);
1020 check_pixel_2bpp(&lockrect
, 0, 1, 0x7e56);
1021 check_pixel_2bpp(&lockrect
, 1, 1, 0xf8b8);
1022 IDirect3DSurface9_UnlockRect(surf
);
1024 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
, D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1025 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1026 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1027 check_pixel_2bpp(&lockrect
, 0, 0, 0x2e57);
1029 check_pixel_2bpp(&lockrect
, 1, 0, 0x3588);
1031 check_pixel_2bpp(&lockrect
, 0, 1, 0xe215);
1032 check_pixel_2bpp(&lockrect
, 1, 1, 0xff0e);
1033 IDirect3DSurface9_UnlockRect(surf
);
1035 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8l8
,
1036 D3DFMT_A8L8
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1037 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1038 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1039 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1040 check_pixel_2bpp(&lockrect
, 0, 0, 0x8000);
1041 check_pixel_2bpp(&lockrect
, 1, 0, 0x7fff);
1042 check_pixel_2bpp(&lockrect
, 0, 1, 0x98c6);
1043 check_pixel_2bpp(&lockrect
, 1, 1, 0x3def);
1044 hr
= IDirect3DSurface9_UnlockRect(surf
);
1045 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1047 check_release((IUnknown
*)surf
, 0);
1051 hr
= IDirect3DDevice9_CreateTexture(device
, 2, 2, 1, 0, D3DFMT_A8L8
, D3DPOOL_MANAGED
, &tex
, NULL
);
1053 skip("Failed to create A8L8 texture, hr %#x.\n", hr
);
1056 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &surf
);
1057 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1059 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
,
1060 D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1061 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1062 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1063 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1064 check_pixel_2bpp(&lockrect
, 0, 0, 0x57f7);
1065 check_pixel_2bpp(&lockrect
, 1, 0, 0x98ed);
1066 check_pixel_2bpp(&lockrect
, 0, 1, 0xaceb);
1067 check_pixel_2bpp(&lockrect
, 1, 1, 0xc88d);
1068 hr
= IDirect3DSurface9_UnlockRect(surf
);
1069 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1071 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
,
1072 D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1073 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1074 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1075 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1076 check_pixel_2bpp(&lockrect
, 0, 0, 0x00a6);
1077 check_pixel_2bpp(&lockrect
, 1, 0, 0xff62);
1078 check_pixel_2bpp(&lockrect
, 0, 1, 0x007f);
1079 check_pixel_2bpp(&lockrect
, 1, 1, 0xff19);
1080 hr
= IDirect3DSurface9_UnlockRect(surf
);
1081 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1083 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
,
1084 D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1085 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1086 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1087 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1088 check_pixel_2bpp(&lockrect
, 0, 0, 0xffce);
1089 check_pixel_2bpp(&lockrect
, 1, 0, 0xff9c);
1090 check_pixel_2bpp(&lockrect
, 0, 1, 0xff4d);
1091 check_pixel_2bpp(&lockrect
, 1, 1, 0xff59);
1092 hr
= IDirect3DSurface9_UnlockRect(surf
);
1093 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1095 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
,
1096 D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1097 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1098 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1099 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1100 check_pixel_2bpp(&lockrect
, 0, 0, 0xff25);
1101 check_pixel_2bpp(&lockrect
, 1, 0, 0xffbe);
1102 check_pixel_2bpp(&lockrect
, 0, 1, 0xffd6);
1103 check_pixel_2bpp(&lockrect
, 1, 1, 0xffb6);
1104 hr
= IDirect3DSurface9_UnlockRect(surf
);
1105 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1107 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
,
1108 D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1109 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1110 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1111 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1112 check_pixel_2bpp(&lockrect
, 0, 0, 0xc36d);
1113 check_pixel_2bpp(&lockrect
, 1, 0, 0x23cb);
1114 check_pixel_2bpp(&lockrect
, 0, 1, 0x09af);
1115 check_pixel_2bpp(&lockrect
, 1, 1, 0x8d61);
1116 hr
= IDirect3DSurface9_UnlockRect(surf
);
1117 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1119 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
,
1120 D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1121 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1122 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1123 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1124 check_pixel_2bpp(&lockrect
, 0, 0, 0x558c);
1125 check_pixel_2bpp(&lockrect
, 1, 0, 0x5565);
1126 check_pixel_2bpp(&lockrect
, 0, 1, 0xaa95);
1127 check_pixel_2bpp(&lockrect
, 1, 1, 0xffcb);
1128 hr
= IDirect3DSurface9_UnlockRect(surf
);
1129 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1131 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8l8
,
1132 D3DFMT_A8L8
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1133 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1134 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
1135 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
1136 check_pixel_2bpp(&lockrect
, 0, 0, 0xff00);
1137 check_pixel_2bpp(&lockrect
, 1, 0, 0x00ff);
1138 check_pixel_2bpp(&lockrect
, 0, 1, 0xff30);
1139 check_pixel_2bpp(&lockrect
, 1, 1, 0x7f7f);
1140 hr
= IDirect3DSurface9_UnlockRect(surf
);
1141 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
1143 check_release((IUnknown
*)surf
, 1);
1144 check_release((IUnknown
*)tex
, 0);
1147 /* DXT1, DXT2, DXT3, DXT4, DXT5 */
1148 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surf
, NULL
);
1150 skip("Failed to create R8G8B8 surface, hr %#x.\n", hr
);
1153 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, dds_24bit
, sizeof(dds_24bit
), NULL
, D3DX_FILTER_NONE
, 0, NULL
);
1154 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
1156 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT2
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1158 skip("Failed to create DXT2 texture, hr %#x.\n", hr
);
1161 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1162 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1163 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1164 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT2 format.\n");
1165 check_release((IUnknown
*)newsurf
, 1);
1166 check_release((IUnknown
*)tex
, 0);
1169 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT3
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1171 skip("Failed to create DXT3 texture, hr %#x.\n", hr
);
1174 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1175 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1176 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1177 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT3 format.\n");
1178 check_release((IUnknown
*)newsurf
, 1);
1179 check_release((IUnknown
*)tex
, 0);
1182 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT4
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1184 skip("Failed to create DXT4 texture, hr %#x.\n", hr
);
1187 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1188 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1189 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1190 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT4 format.\n");
1191 check_release((IUnknown
*)newsurf
, 1);
1192 check_release((IUnknown
*)tex
, 0);
1195 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT5
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1197 skip("Failed to create DXT5 texture, hr %#x.\n", hr
);
1200 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1201 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1202 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1203 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT5 format.\n");
1204 check_release((IUnknown
*)newsurf
, 1);
1205 check_release((IUnknown
*)tex
, 0);
1208 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT1
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
1210 skip("Failed to create DXT1 texture, hr %#x.\n", hr
);
1213 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, 0, &newsurf
);
1214 ok(SUCCEEDED(hr
), "Failed to get the surface, hr %#x.\n", hr
);
1215 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1216 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT1 format.\n");
1218 hr
= D3DXLoadSurfaceFromSurface(surf
, NULL
, NULL
, newsurf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1219 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels from DXT1 format.\n");
1221 check_release((IUnknown
*)newsurf
, 1);
1222 check_release((IUnknown
*)tex
, 0);
1225 check_release((IUnknown
*)surf
, 0);
1229 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
1230 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
1233 static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9
*device
)
1237 ID3DXBuffer
*buffer
;
1238 IDirect3DSurface9
*surface
;
1242 struct dds_header header
;
1246 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &surface
, NULL
);
1248 skip("Couldn't create surface\n");
1252 SetRectEmpty(&rect
);
1253 hr
= D3DXSaveSurfaceToFileInMemory(&buffer
, D3DXIFF_BMP
, surface
, NULL
, &rect
);
1254 /* fails with the debug version of d3d9 */
1255 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
), "D3DXSaveSurfaceToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1256 if (SUCCEEDED(hr
)) {
1257 DWORD size
= ID3DXBuffer_GetBufferSize(buffer
);
1258 ok(size
> 0, "ID3DXBuffer_GetBufferSize returned %u, expected > 0\n", size
);
1259 ID3DXBuffer_Release(buffer
);
1262 SetRectEmpty(&rect
);
1263 hr
= D3DXSaveSurfaceToFileInMemory(&buffer
, D3DXIFF_DDS
, surface
, NULL
, &rect
);
1264 todo_wine
ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1267 dds
= ID3DXBuffer_GetBufferPointer(buffer
);
1269 ok(dds
->magic
== MAKEFOURCC('D','D','S',' '), "Got unexpected DDS signature %#x.\n", dds
->magic
);
1270 ok(dds
->header
.size
== sizeof(dds
->header
), "Got unexpected DDS size %u.\n", dds
->header
.size
);
1271 ok(!dds
->header
.height
, "Got unexpected height %u.\n", dds
->header
.height
);
1272 ok(!dds
->header
.width
, "Got unexpected width %u.\n", dds
->header
.width
);
1273 ok(!dds
->header
.depth
, "Got unexpected depth %u.\n", dds
->header
.depth
);
1274 ok(!dds
->header
.miplevels
, "Got unexpected miplevels %u.\n", dds
->header
.miplevels
);
1275 ok(!dds
->header
.pitch_or_linear_size
, "Got unexpected pitch_or_linear_size %u.\n", dds
->header
.pitch_or_linear_size
);
1276 ok(dds
->header
.caps
== (DDS_CAPS_TEXTURE
| DDSCAPS_ALPHA
), "Got unexpected caps %#x.\n", dds
->header
.caps
);
1277 ok(dds
->header
.flags
== (DDS_CAPS
| DDS_HEIGHT
| DDS_WIDTH
| DDS_PIXELFORMAT
),
1278 "Got unexpected flags %#x.\n", dds
->header
.flags
);
1279 ID3DXBuffer_Release(buffer
);
1282 hr
= D3DXSaveSurfaceToFileInMemory(&buffer
, D3DXIFF_DDS
, surface
, NULL
, NULL
);
1283 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1285 dds
= ID3DXBuffer_GetBufferPointer(buffer
);
1286 ok(dds
->magic
== MAKEFOURCC('D','D','S',' '), "Got unexpected DDS signature %#x.\n", dds
->magic
);
1287 ok(dds
->header
.size
== sizeof(dds
->header
), "Got unexpected DDS size %u.\n", dds
->header
.size
);
1288 ok(dds
->header
.height
== 4, "Got unexpected height %u.\n", dds
->header
.height
);
1289 ok(dds
->header
.width
== 4, "Got unexpected width %u.\n", dds
->header
.width
);
1290 ok(!dds
->header
.depth
, "Got unexpected depth %u.\n", dds
->header
.depth
);
1291 ok(!dds
->header
.miplevels
, "Got unexpected miplevels %u.\n", dds
->header
.miplevels
);
1292 ok(!dds
->header
.pitch_or_linear_size
, "Got unexpected pitch_or_linear_size %u.\n", dds
->header
.pitch_or_linear_size
);
1293 todo_wine
ok(dds
->header
.caps
== (DDS_CAPS_TEXTURE
| DDSCAPS_ALPHA
), "Got unexpected caps %#x.\n", dds
->header
.caps
);
1294 ok(dds
->header
.flags
== (DDS_CAPS
| DDS_HEIGHT
| DDS_WIDTH
| DDS_PIXELFORMAT
),
1295 "Got unexpected flags %#x.\n", dds
->header
.flags
);
1296 ID3DXBuffer_Release(buffer
);
1298 IDirect3DSurface9_Release(surface
);
1301 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9
*device
)
1304 IDirect3DSurface9
*surface
;
1306 D3DLOCKED_RECT lock_rect
;
1307 D3DXIMAGE_INFO image_info
;
1308 const BYTE pixels
[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
1309 0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
1310 DWORD pitch
= sizeof(pixels
) / 2;
1312 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_R8G8B8
, D3DPOOL_SCRATCH
, &surface
, NULL
);
1314 skip("Couldn't create surface\n");
1318 SetRect(&rect
, 0, 0, 2, 2);
1319 hr
= D3DXLoadSurfaceFromMemory(surface
, NULL
, NULL
, pixels
, D3DFMT_R8G8B8
, pitch
, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
1320 if (SUCCEEDED(hr
)) {
1321 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, NULL
);
1322 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1324 hr
= D3DXLoadSurfaceFromFileA(surface
, NULL
, NULL
, "saved_surface.bmp", NULL
, D3DX_FILTER_NONE
, 0, &image_info
);
1325 ok(hr
== D3D_OK
, "Couldn't load saved surface %#x\n", hr
);
1326 if (FAILED(hr
)) goto next_tests
;
1328 ok(image_info
.Width
== 2, "Wrong width %u\n", image_info
.Width
);
1329 ok(image_info
.Height
== 2, "Wrong height %u\n", image_info
.Height
);
1330 ok(image_info
.Format
== D3DFMT_R8G8B8
, "Wrong format %#x\n", image_info
.Format
);
1331 ok(image_info
.ImageFileFormat
== D3DXIFF_BMP
, "Wrong file format %u\n", image_info
.ImageFileFormat
);
1333 hr
= IDirect3DSurface9_LockRect(surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1334 ok(hr
== D3D_OK
, "Couldn't lock surface %#x\n", hr
);
1335 if (FAILED(hr
)) goto next_tests
;
1337 ok(!memcmp(lock_rect
.pBits
, pixels
, pitch
), "Pixel data mismatch in first row\n");
1338 ok(!memcmp((BYTE
*)lock_rect
.pBits
+ lock_rect
.Pitch
, pixels
+ pitch
, pitch
), "Pixel data mismatch in second row\n");
1340 IDirect3DSurface9_UnlockRect(surface
);
1341 } else skip("Couldn't fill surface\n");
1344 hr
= D3DXSaveSurfaceToFileA(NULL
, D3DXIFF_BMP
, surface
, NULL
, NULL
);
1345 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1347 /* PPM and TGA are supported, even though MSDN claims they aren't */
1349 hr
= D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM
, surface
, NULL
, NULL
);
1350 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1351 hr
= D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA
, surface
, NULL
, NULL
);
1352 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1355 hr
= D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS
, surface
, NULL
, NULL
);
1356 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1357 if (SUCCEEDED(hr
)) {
1358 hr
= D3DXLoadSurfaceFromFileA(surface
, NULL
, NULL
, "saved_surface.dds", NULL
, D3DX_FILTER_NONE
, 0, &image_info
);
1359 ok(hr
== D3D_OK
, "Couldn't load saved surface %#x\n", hr
);
1361 if (SUCCEEDED(hr
)) {
1362 ok(image_info
.Width
== 2, "Wrong width %u\n", image_info
.Width
);
1363 ok(image_info
.Format
== D3DFMT_R8G8B8
, "Wrong format %#x\n", image_info
.Format
);
1364 ok(image_info
.ImageFileFormat
== D3DXIFF_DDS
, "Wrong file format %u\n", image_info
.ImageFileFormat
);
1366 hr
= IDirect3DSurface9_LockRect(surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1367 ok(hr
== D3D_OK
, "Couldn't lock surface %#x\n", hr
);
1368 if (SUCCEEDED(hr
)) {
1369 ok(!memcmp(lock_rect
.pBits
, pixels
, pitch
), "Pixel data mismatch in first row\n");
1370 ok(!memcmp((BYTE
*)lock_rect
.pBits
+ lock_rect
.Pitch
, pixels
+ pitch
, pitch
), "Pixel data mismatch in second row\n");
1371 IDirect3DSurface9_UnlockRect(surface
);
1374 } else skip("Couldn't save surface\n");
1376 hr
= D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM
+ 1, surface
, NULL
, NULL
);
1377 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1379 SetRect(&rect
, 0, 0, 4, 4);
1380 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1381 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1382 SetRect(&rect
, 2, 0, 1, 4);
1383 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1384 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1385 SetRect(&rect
, 0, 2, 4, 1);
1386 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1387 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1388 SetRect(&rect
, -1, -1, 2, 2);
1389 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1390 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1391 SetRectEmpty(&rect
);
1392 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
1393 /* fails when debug version of d3d9 is used */
1394 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
), "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
1396 DeleteFileA("saved_surface.bmp");
1397 DeleteFileA("saved_surface.ppm");
1398 DeleteFileA("saved_surface.tga");
1399 DeleteFileA("saved_surface.dds");
1401 IDirect3DSurface9_Release(surface
);
1408 IDirect3DDevice9
*device
;
1409 D3DPRESENT_PARAMETERS d3dpp
;
1412 if (!(wnd
= CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW
, 0, 0,
1413 640, 480, NULL
, NULL
, NULL
, NULL
)))
1415 skip("Couldn't create application window\n");
1418 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
1420 skip("Couldn't create IDirect3D9 object\n");
1425 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
1426 d3dpp
.Windowed
= TRUE
;
1427 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1428 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, wnd
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device
);
1430 skip("Failed to create IDirect3DDevice9 object %#x\n", hr
);
1431 IDirect3D9_Release(d3d
);
1436 test_D3DXGetImageInfo();
1437 test_D3DXLoadSurface(device
);
1438 test_D3DXSaveSurfaceToFileInMemory(device
);
1439 test_D3DXSaveSurfaceToFile(device
);
1441 check_release((IUnknown
*)device
, 0);
1442 check_release((IUnknown
*)d3d
, 0);