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
22 #include "wine/test.h"
24 #include "resources.h"
26 static inline int get_ref(IUnknown
*obj
)
29 return IUnknown_Release(obj
);
32 static inline void check_ref(IUnknown
*obj
, int exp
)
34 int ref
= get_ref(obj
);
35 ok (exp
== ref
, "Invalid refcount. Expected %d, got %d\n", exp
, ref
);
38 static inline void check_release(IUnknown
*obj
, int exp
)
40 int ref
= IUnknown_Release(obj
);
41 ok (ref
== exp
, "Invalid refcount. Expected %d, got %d\n", exp
, ref
);
45 static const unsigned char bmp01
[66] = {
46 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
47 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
48 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
49 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
53 /* 2x2 A8R8G8B8 pixel data */
54 static const unsigned char pixdata
[] = {
55 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
58 /* invalid image file */
59 static const unsigned char noimage
[4] = {
63 /* 2x2 24-bit dds, 2 mipmaps */
64 static const unsigned char dds_24bit
[] = {
65 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00,
66 0x02,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
67 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
68 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
69 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
70 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
71 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
72 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
73 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
76 /* 2x2 16-bit dds, no mipmaps */
77 static const unsigned char dds_16bit
[] = {
78 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
79 0x02,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
80 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
81 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
82 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
83 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,
84 0xe0,0x03,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
85 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
86 0xff,0x7f,0xff,0x7f,0xff,0x7f,0xff,0x7f
89 /* 4x4 cube map dds */
90 static const unsigned char dds_cube_map
[] = {
91 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00,
92 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
93 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x20,0x00,0x00,0x00,
96 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
97 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
98 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
99 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
100 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
101 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
102 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
103 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
104 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50
107 /* 4x4x2 volume map dds, 2 mipmaps */
108 static const unsigned char dds_volume_map
[] = {
109 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
110 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
111 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
112 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
113 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
114 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
115 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
116 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
117 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
118 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
119 0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
120 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
123 static HRESULT
create_file(const char *filename
, const unsigned char *data
, const unsigned int size
)
128 hfile
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
129 if(hfile
== INVALID_HANDLE_VALUE
) return HRESULT_FROM_WIN32(GetLastError());
131 if(WriteFile(hfile
, data
, size
, &received
, NULL
))
138 return D3DERR_INVALIDCALL
;
141 #define DDS_CAPS 0x00000001
142 #define DDS_HEIGHT 0x00000002
143 #define DDS_WIDTH 0x00000004
144 #define DDS_PIXELFORMAT 0x00001000
146 #define DDS_CAPS_TEXTURE 0x00001000
148 #define DDS_PF_ALPHA 0x00000001
149 #define DDS_PF_ALPHA_ONLY 0x00000002
150 #define DDS_PF_FOURCC 0x00000004
151 #define DDS_PF_RGB 0x00000040
152 #define DDS_PF_LUMINANCE 0x00020000
153 #define DDS_PF_BUMPDUDV 0x00080000
155 static void check_dds_pixel_format(DWORD flags
, DWORD fourcc
, DWORD bpp
,
156 DWORD rmask
, DWORD gmask
, DWORD bmask
, DWORD amask
,
157 D3DFORMAT expected_format
)
185 memset(&dds
, 0, sizeof(dds
));
187 dds
.magic
= MAKEFOURCC('D','D','S',' ');
189 dds
.flags
= DDS_CAPS
| DDS_WIDTH
| DDS_HEIGHT
| DDS_PIXELFORMAT
;
192 dds
.pixel_format
.size
= sizeof(dds
.pixel_format
);
193 dds
.pixel_format
.flags
= flags
;
194 dds
.pixel_format
.fourcc
= fourcc
;
195 dds
.pixel_format
.bpp
= bpp
;
196 dds
.pixel_format
.rmask
= rmask
;
197 dds
.pixel_format
.gmask
= gmask
;
198 dds
.pixel_format
.bmask
= bmask
;
199 dds
.pixel_format
.amask
= amask
;
200 dds
.caps
= DDS_CAPS_TEXTURE
;
202 hr
= D3DXGetImageInfoFromFileInMemory(&dds
, sizeof(dds
), &info
);
203 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x for pixel format %#x, expected %#x\n", hr
, expected_format
, D3D_OK
);
205 ok(info
.Format
== expected_format
, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n", info
.Format
, expected_format
);
208 static void test_D3DXGetImageInfo(void)
212 BOOL testdummy_ok
, testbitmap_ok
;
214 hr
= create_file("testdummy.bmp", noimage
, sizeof(noimage
)); /* invalid image */
215 testdummy_ok
= SUCCEEDED(hr
);
217 hr
= create_file("testbitmap.bmp", bmp01
, sizeof(bmp01
)); /* valid image */
218 testbitmap_ok
= SUCCEEDED(hr
);
220 /* D3DXGetImageInfoFromFile */
222 hr
= D3DXGetImageInfoFromFileA("testbitmap.bmp", &info
);
223 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
225 hr
= D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL
); /* valid image, second parameter is NULL */
226 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
227 } else skip("Couldn't create \"testbitmap.bmp\"\n");
230 hr
= D3DXGetImageInfoFromFileA("testdummy.bmp", NULL
); /* invalid image, second parameter is NULL */
231 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
233 hr
= D3DXGetImageInfoFromFileA("testdummy.bmp", &info
);
234 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
235 } else skip("Couldn't create \"testdummy.bmp\"\n");
237 hr
= D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info
);
238 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
240 hr
= D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL
);
241 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
243 hr
= D3DXGetImageInfoFromFileA("", &info
);
244 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
246 hr
= D3DXGetImageInfoFromFileA(NULL
, &info
);
247 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
249 hr
= D3DXGetImageInfoFromFileA(NULL
, NULL
);
250 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
253 /* D3DXGetImageInfoFromResource */
255 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDB_BITMAP_1x1
), &info
); /* RT_BITMAP */
256 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
258 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDB_BITMAP_1x1
), NULL
);
259 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
262 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), &info
); /* RT_RCDATA */
263 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
265 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDS_STRING
), &info
);
266 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
268 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDS_STRING
), NULL
);
269 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
271 hr
= D3DXGetImageInfoFromResourceA(NULL
, "resourcedoesnotexist", &info
);
272 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
274 hr
= D3DXGetImageInfoFromResourceA(NULL
, "resourcedoesnotexist", NULL
);
275 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
277 hr
= D3DXGetImageInfoFromResourceA(NULL
, NULL
, NULL
);
278 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
281 /* D3DXGetImageInfoFromFileInMemory */
282 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
, sizeof(bmp01
), &info
);
283 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
285 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
, sizeof(bmp01
)+5, &info
); /* too large size */
286 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
288 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
, sizeof(bmp01
), NULL
);
289 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
291 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, sizeof(noimage
), NULL
);
292 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
294 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, sizeof(noimage
), &info
);
295 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
298 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
, sizeof(bmp01
)-1, &info
);
299 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
302 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
+1, sizeof(bmp01
)-1, &info
);
303 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
305 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
, 0, &info
);
306 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
308 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
, 0, NULL
);
309 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
311 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, 0, &info
);
312 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
314 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, 0, NULL
);
315 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
317 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 0, &info
);
318 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
320 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 4, NULL
);
321 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
323 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 4, &info
);
324 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
326 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 0, NULL
);
327 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
330 /* test DDS support */
331 hr
= D3DXGetImageInfoFromFileInMemory(dds_24bit
, sizeof(dds_24bit
), &info
);
332 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
334 ok(info
.Width
== 2, "Got width %u, expected 2\n", info
.Width
);
335 ok(info
.Height
== 2, "Got height %u, expected 2\n", info
.Height
);
336 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
337 ok(info
.MipLevels
== 2, "Got miplevels %u, expected 2\n", info
.MipLevels
);
338 ok(info
.Format
== D3DFMT_R8G8B8
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_R8G8B8
);
339 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
340 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
341 } else skip("Couldn't get image info from 24-bit DDS file in memory\n");
343 hr
= D3DXGetImageInfoFromFileInMemory(dds_16bit
, sizeof(dds_16bit
), &info
);
344 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
346 ok(info
.Width
== 2, "Got width %u, expected 2\n", info
.Width
);
347 ok(info
.Height
== 2, "Got height %u, expected 2\n", info
.Height
);
348 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
349 ok(info
.MipLevels
== 1, "Got miplevels %u, expected 1\n", info
.MipLevels
);
350 ok(info
.Format
== D3DFMT_X1R5G5B5
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_X1R5G5B5
);
351 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
352 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
353 } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
355 hr
= D3DXGetImageInfoFromFileInMemory(dds_cube_map
, sizeof(dds_cube_map
), &info
);
356 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
358 ok(info
.Width
== 4, "Got width %u, expected 4\n", info
.Width
);
359 ok(info
.Height
== 4, "Got height %u, expected 4\n", info
.Height
);
360 ok(info
.Depth
== 1, "Got depth %u, expected 1\n", info
.Depth
);
361 ok(info
.MipLevels
== 1, "Got miplevels %u, expected 1\n", info
.MipLevels
);
362 ok(info
.Format
== D3DFMT_DXT5
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_DXT5
);
363 ok(info
.ResourceType
== D3DRTYPE_CUBETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_CUBETEXTURE
);
364 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
365 } else skip("Couldn't get image info from cube map in memory\n");
367 hr
= D3DXGetImageInfoFromFileInMemory(dds_volume_map
, sizeof(dds_volume_map
), &info
);
368 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
370 ok(info
.Width
== 4, "Got width %u, expected 4\n", info
.Width
);
371 ok(info
.Height
== 4, "Got height %u, expected 4\n", info
.Height
);
372 ok(info
.Depth
== 2, "Got depth %u, expected 2\n", info
.Depth
);
373 ok(info
.MipLevels
== 3, "Got miplevels %u, expected 3\n", info
.MipLevels
);
374 ok(info
.Format
== D3DFMT_DXT3
, "Got format %#x, expected %#x\n", info
.Format
, D3DFMT_DXT3
);
375 ok(info
.ResourceType
== D3DRTYPE_VOLUMETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_VOLUMETEXTURE
);
376 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got image file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
377 } else skip("Couldn't get image info from volume map in memory\n");
379 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0, D3DFMT_DXT1
);
380 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0, D3DFMT_DXT2
);
381 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0, D3DFMT_DXT3
);
382 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0, D3DFMT_DXT4
);
383 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0, D3DFMT_DXT5
);
384 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8
);
385 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8
);
386 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0, D3DFMT_UYVY
);
387 check_dds_pixel_format(DDS_PF_FOURCC
, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0, D3DFMT_YUY2
);
388 check_dds_pixel_format(DDS_PF_RGB
, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5
);
389 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5
);
390 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4
);
391 check_dds_pixel_format(DDS_PF_RGB
, 0, 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2
);
392 check_dds_pixel_format(DDS_PF_ALPHA_ONLY
, 0, 8, 0, 0, 0, 0xff, D3DFMT_A8
);
393 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2
);
394 check_dds_pixel_format(DDS_PF_RGB
, 0, 16, 0xf00, 0x0f0, 0x00f, 0, D3DFMT_X4R4G4B4
);
395 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10
);
396 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10
);
397 check_dds_pixel_format(DDS_PF_RGB
| DDS_PF_ALPHA
, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8
);
398 check_dds_pixel_format(DDS_PF_RGB
, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_X8R8G8B8
);
399 check_dds_pixel_format(DDS_PF_RGB
, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_G16R16
);
400 check_dds_pixel_format(DDS_PF_LUMINANCE
, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8
);
401 check_dds_pixel_format(DDS_PF_LUMINANCE
, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16
);
402 check_dds_pixel_format(DDS_PF_LUMINANCE
| DDS_PF_ALPHA
, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8
);
403 check_dds_pixel_format(DDS_PF_LUMINANCE
| DDS_PF_ALPHA
, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4
);
404 check_dds_pixel_format(DDS_PF_BUMPDUDV
, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8
);
405 check_dds_pixel_format(DDS_PF_BUMPDUDV
, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16
);
407 hr
= D3DXGetImageInfoFromFileInMemory(dds_16bit
, sizeof(dds_16bit
) - 1, &info
);
408 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
410 hr
= D3DXGetImageInfoFromFileInMemory(dds_24bit
, sizeof(dds_24bit
) - 1, &info
);
411 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
413 hr
= D3DXGetImageInfoFromFileInMemory(dds_cube_map
, sizeof(dds_cube_map
) - 1, &info
);
414 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
416 hr
= D3DXGetImageInfoFromFileInMemory(dds_volume_map
, sizeof(dds_volume_map
) - 1, &info
);
417 todo_wine
ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
421 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
422 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
425 #define check_pixel_1bpp(lockrect, x, y, color) \
426 ok(((BYTE*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch] == color, "Got color 0x%02x, expected 0x%02x.\n", \
427 ((BYTE*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch], color)
429 #define check_pixel_2bpp(lockrect, x, y, color) \
430 ok(((WORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 2] == color, "Got color 0x%04x, expected 0x%04x.\n", \
431 ((WORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 2], color)
433 #define check_pixel_4bpp(lockrect, x, y, color) \
434 ok(((DWORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 4] == color, "Got color 0x%08x, expected 0x%08x.\n", \
435 ((DWORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 4], color)
436 static void test_D3DXLoadSurface(IDirect3DDevice9
*device
)
439 BOOL testdummy_ok
, testbitmap_ok
;
440 IDirect3DSurface9
*surf
, *newsurf
;
442 D3DLOCKED_RECT lockrect
;
443 const WORD pixdata_a8r3g3b2
[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
444 const WORD pixdata_a1r5g5b5
[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
445 const WORD pixdata_r5g6b5
[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
446 const WORD pixdata_a8l8
[] = { 0xff00, 0x00ff, 0xff30, 0x7f7f };
447 const DWORD pixdata_g16r16
[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
448 const DWORD pixdata_a8b8g8r8
[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
449 const DWORD pixdata_a2r10g10b10
[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
451 hr
= create_file("testdummy.bmp", noimage
, sizeof(noimage
)); /* invalid image */
452 testdummy_ok
= SUCCEEDED(hr
);
454 hr
= create_file("testbitmap.bmp", bmp01
, sizeof(bmp01
)); /* valid image */
455 testbitmap_ok
= SUCCEEDED(hr
);
457 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf
, NULL
);
459 skip("Failed to create a surface (%#x)\n", hr
);
460 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
461 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
465 /* D3DXLoadSurfaceFromFile */
468 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "testbitmap.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
469 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
472 hr
= D3DXLoadSurfaceFromFileA(NULL
, NULL
, NULL
, "testbitmap.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
473 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
474 } else skip("Couldn't create \"testbitmap.bmp\"\n");
477 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "testdummy.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
478 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
479 } else skip("Couldn't create \"testdummy.bmp\"\n");
481 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0, NULL
);
482 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
484 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "", NULL
, D3DX_DEFAULT
, 0, NULL
);
485 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
488 /* D3DXLoadSurfaceFromResource */
490 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, MAKEINTRESOURCE(IDB_BITMAP_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
491 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
494 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, MAKEINTRESOURCE(IDD_BITMAPDATA_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
495 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
497 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0, NULL
);
498 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
500 hr
= D3DXLoadSurfaceFromResourceA(NULL
, NULL
, NULL
, NULL
, MAKEINTRESOURCE(IDB_BITMAP_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
501 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
503 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, MAKEINTRESOURCE(IDS_STRING
), NULL
, D3DX_DEFAULT
, 0, NULL
);
504 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
507 /* D3DXLoadSurfaceFromFileInMemory */
509 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, bmp01
, sizeof(bmp01
), NULL
, D3DX_DEFAULT
, 0, NULL
);
510 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
513 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, noimage
, sizeof(noimage
), NULL
, D3DX_DEFAULT
, 0, NULL
);
514 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
516 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, bmp01
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
517 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
519 hr
= D3DXLoadSurfaceFromFileInMemory(NULL
, NULL
, NULL
, bmp01
, sizeof(bmp01
), NULL
, D3DX_DEFAULT
, 0, NULL
);
520 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
522 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, NULL
, 8, NULL
, D3DX_DEFAULT
, 0, NULL
);
523 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
525 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, NULL
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
526 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
528 hr
= D3DXLoadSurfaceFromFileInMemory(NULL
, NULL
, NULL
, NULL
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
529 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
532 /* D3DXLoadSurfaceFromMemory */
533 SetRect(&rect
, 0, 0, 2, 2);
535 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
536 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
538 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, 0, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
539 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
541 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, NULL
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
542 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
544 hr
= D3DXLoadSurfaceFromMemory(NULL
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
545 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
547 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, NULL
, D3DX_DEFAULT
, 0);
548 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
550 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_UNKNOWN
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
551 ok(hr
== E_FAIL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, E_FAIL
);
553 SetRect(&destrect
, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
554 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
555 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
557 SetRect(&destrect
, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
558 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
559 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
561 SetRect(&destrect
, 1, 1, 0, 0); /* left > right, top > bottom */
562 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
563 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
565 SetRect(&destrect
, 0, 0, 0, 0); /* left = right, top = bottom */
566 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
567 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
569 SetRect(&destrect
, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
570 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
571 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
574 /* D3DXLoadSurfaceFromSurface */
575 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &newsurf
, NULL
);
577 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
578 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
580 hr
= D3DXLoadSurfaceFromSurface(NULL
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
581 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
583 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0);
584 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
586 check_release((IUnknown
*)newsurf
, 0);
587 } else skip("Failed to create a second surface\n");
589 check_release((IUnknown
*)surf
, 0);
592 /* test color conversion */
594 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf
, NULL
);
595 if(FAILED(hr
)) skip("Failed to create a surface (%#x)\n", hr
);
597 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
, D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
598 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
599 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
600 check_pixel_4bpp(lockrect
, 0, 0, 0x57dbffff);
601 check_pixel_4bpp(lockrect
, 1, 0, 0x98ffff00);
602 check_pixel_4bpp(lockrect
, 0, 1, 0xacdbff55);
603 check_pixel_4bpp(lockrect
, 1, 1, 0xc8929255);
604 IDirect3DSurface9_UnlockRect(surf
);
606 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
, D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
607 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
608 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
609 check_pixel_4bpp(lockrect
, 0, 0, 0x008cadad);
610 check_pixel_4bpp(lockrect
, 1, 0, 0xff317342);
611 check_pixel_4bpp(lockrect
, 0, 1, 0x0008ad10);
612 check_pixel_4bpp(lockrect
, 1, 1, 0xff29088c);
613 IDirect3DSurface9_UnlockRect(surf
);
615 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
, D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
616 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
617 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
618 check_pixel_4bpp(lockrect
, 0, 0, 0xff9cdfb5);
619 check_pixel_4bpp(lockrect
, 1, 0, 0xff63b26b);
620 check_pixel_4bpp(lockrect
, 0, 1, 0xff085d73);
621 check_pixel_4bpp(lockrect
, 1, 1, 0xff425d73);
622 IDirect3DSurface9_UnlockRect(surf
);
624 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
, D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
625 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
626 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
628 check_pixel_4bpp(lockrect
, 0, 0, 0xff3f08ff);
630 check_pixel_4bpp(lockrect
, 1, 0, 0xff44dcff);
631 check_pixel_4bpp(lockrect
, 0, 1, 0xff97e4ff);
632 check_pixel_4bpp(lockrect
, 1, 1, 0xfffe9aff);
633 IDirect3DSurface9_UnlockRect(surf
);
635 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
, D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
636 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
637 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
638 check_pixel_4bpp(lockrect
, 0, 0, 0xc3f04c39);
639 check_pixel_4bpp(lockrect
, 1, 0, 0x2392e85a);
640 check_pixel_4bpp(lockrect
, 0, 1, 0x09fd97b1);
641 check_pixel_4bpp(lockrect
, 1, 1, 0x8df62bc3);
642 IDirect3DSurface9_UnlockRect(surf
);
644 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
, D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
645 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
646 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
647 check_pixel_4bpp(lockrect
, 0, 0, 0x555c95bf);
648 check_pixel_4bpp(lockrect
, 1, 0, 0x556d663f);
649 check_pixel_4bpp(lockrect
, 0, 1, 0xaac385ad);
651 check_pixel_4bpp(lockrect
, 1, 1, 0xfffcc575);
653 IDirect3DSurface9_UnlockRect(surf
);
655 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8l8
,
656 D3DFMT_A8L8
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
657 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
658 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
659 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
660 check_pixel_4bpp(lockrect
, 0, 0, 0xff000000);
661 check_pixel_4bpp(lockrect
, 1, 0, 0x00ffffff);
662 check_pixel_4bpp(lockrect
, 0, 1, 0xff303030);
663 check_pixel_4bpp(lockrect
, 1, 1, 0x7f7f7f7f);
664 hr
= IDirect3DSurface9_UnlockRect(surf
);
665 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
667 check_release((IUnknown
*)surf
, 0);
671 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A1R5G5B5
, D3DPOOL_DEFAULT
, &surf
, NULL
);
672 if(FAILED(hr
)) skip("Failed to create a surface (%#x)\n", hr
);
674 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
, D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
675 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
676 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
677 check_pixel_2bpp(lockrect
, 0, 0, 0x6fff);
678 check_pixel_2bpp(lockrect
, 1, 0, 0xffe0);
679 check_pixel_2bpp(lockrect
, 0, 1, 0xefea);
680 check_pixel_2bpp(lockrect
, 1, 1, 0xca4a);
681 IDirect3DSurface9_UnlockRect(surf
);
683 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
, D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
684 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
685 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
686 check_pixel_2bpp(lockrect
, 0, 0, 0x46b5);
687 check_pixel_2bpp(lockrect
, 1, 0, 0x99c8);
688 check_pixel_2bpp(lockrect
, 0, 1, 0x06a2);
689 check_pixel_2bpp(lockrect
, 1, 1, 0x9431);
690 IDirect3DSurface9_UnlockRect(surf
);
692 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
, D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
693 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
694 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
695 check_pixel_2bpp(lockrect
, 0, 0, 0xcf76);
696 check_pixel_2bpp(lockrect
, 1, 0, 0xb2cd);
697 check_pixel_2bpp(lockrect
, 0, 1, 0x856e);
698 check_pixel_2bpp(lockrect
, 1, 1, 0xa16e);
699 IDirect3DSurface9_UnlockRect(surf
);
701 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
, D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
702 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
703 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
705 check_pixel_2bpp(lockrect
, 0, 0, 0xa03f);
707 check_pixel_2bpp(lockrect
, 1, 0, 0xa37f);
708 check_pixel_2bpp(lockrect
, 0, 1, 0xcb9f);
709 check_pixel_2bpp(lockrect
, 1, 1, 0xfe7f);
710 IDirect3DSurface9_UnlockRect(surf
);
712 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
, D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
713 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
714 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
716 check_pixel_2bpp(lockrect
, 0, 0, 0xf527);
717 check_pixel_2bpp(lockrect
, 1, 0, 0x4b8b);
719 check_pixel_2bpp(lockrect
, 0, 1, 0x7e56);
720 check_pixel_2bpp(lockrect
, 1, 1, 0xf8b8);
721 IDirect3DSurface9_UnlockRect(surf
);
723 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
, D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
724 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
725 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
726 check_pixel_2bpp(lockrect
, 0, 0, 0x2e57);
728 check_pixel_2bpp(lockrect
, 1, 0, 0x3588);
730 check_pixel_2bpp(lockrect
, 0, 1, 0xe215);
731 check_pixel_2bpp(lockrect
, 1, 1, 0xff0e);
732 IDirect3DSurface9_UnlockRect(surf
);
734 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8l8
,
735 D3DFMT_A8L8
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
736 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
737 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
738 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
739 check_pixel_2bpp(lockrect
, 0, 0, 0x8000);
740 check_pixel_2bpp(lockrect
, 1, 0, 0x7fff);
741 check_pixel_2bpp(lockrect
, 0, 1, 0x98c6);
742 check_pixel_2bpp(lockrect
, 1, 1, 0x3def);
743 hr
= IDirect3DSurface9_UnlockRect(surf
);
744 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
746 check_release((IUnknown
*)surf
, 0);
750 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A8L8
, D3DPOOL_DEFAULT
, &surf
, NULL
);
752 skip("Failed to create A8L8 surface, hr %#x.\n", hr
);
755 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
,
756 D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
757 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
758 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
759 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
760 check_pixel_2bpp(lockrect
, 0, 0, 0x57f7);
761 check_pixel_2bpp(lockrect
, 1, 0, 0x98ed);
762 check_pixel_2bpp(lockrect
, 0, 1, 0xaceb);
763 check_pixel_2bpp(lockrect
, 1, 1, 0xc88d);
764 hr
= IDirect3DSurface9_UnlockRect(surf
);
765 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
767 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
,
768 D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
769 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
770 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
771 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
772 check_pixel_2bpp(lockrect
, 0, 0, 0x00a6);
773 check_pixel_2bpp(lockrect
, 1, 0, 0xff62);
774 check_pixel_2bpp(lockrect
, 0, 1, 0x007f);
775 check_pixel_2bpp(lockrect
, 1, 1, 0xff19);
776 hr
= IDirect3DSurface9_UnlockRect(surf
);
777 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
779 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
,
780 D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
781 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
782 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
783 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
784 check_pixel_2bpp(lockrect
, 0, 0, 0xffce);
785 check_pixel_2bpp(lockrect
, 1, 0, 0xff9c);
786 check_pixel_2bpp(lockrect
, 0, 1, 0xff4d);
787 check_pixel_2bpp(lockrect
, 1, 1, 0xff59);
788 hr
= IDirect3DSurface9_UnlockRect(surf
);
789 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
791 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
,
792 D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
793 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
794 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
795 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
796 check_pixel_2bpp(lockrect
, 0, 0, 0xff25);
797 check_pixel_2bpp(lockrect
, 1, 0, 0xffbe);
798 check_pixel_2bpp(lockrect
, 0, 1, 0xffd6);
799 check_pixel_2bpp(lockrect
, 1, 1, 0xffb6);
800 hr
= IDirect3DSurface9_UnlockRect(surf
);
801 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
803 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
,
804 D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
805 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
806 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
807 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
808 check_pixel_2bpp(lockrect
, 0, 0, 0xc36d);
809 check_pixel_2bpp(lockrect
, 1, 0, 0x23cb);
810 check_pixel_2bpp(lockrect
, 0, 1, 0x09af);
811 check_pixel_2bpp(lockrect
, 1, 1, 0x8d61);
812 hr
= IDirect3DSurface9_UnlockRect(surf
);
813 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
815 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
,
816 D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
817 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
818 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
819 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
820 check_pixel_2bpp(lockrect
, 0, 0, 0x558c);
821 check_pixel_2bpp(lockrect
, 1, 0, 0x5565);
822 check_pixel_2bpp(lockrect
, 0, 1, 0xaa95);
823 check_pixel_2bpp(lockrect
, 1, 1, 0xffcb);
824 hr
= IDirect3DSurface9_UnlockRect(surf
);
825 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
827 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8l8
,
828 D3DFMT_A8L8
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
829 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
830 hr
= IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
831 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
832 check_pixel_2bpp(lockrect
, 0, 0, 0xff00);
833 check_pixel_2bpp(lockrect
, 1, 0, 0x00ff);
834 check_pixel_2bpp(lockrect
, 0, 1, 0xff30);
835 check_pixel_2bpp(lockrect
, 1, 1, 0x7f7f);
836 hr
= IDirect3DSurface9_UnlockRect(surf
);
837 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
839 check_release((IUnknown
*)surf
, 0);
842 /* DXT1, DXT2, DXT3, DXT4, DXT5 */
843 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_R8G8B8
, D3DPOOL_SYSTEMMEM
, &surf
, NULL
);
845 skip("Failed to create R8G8B8 surface, hr %#x.\n", hr
);
848 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, dds_24bit
, sizeof(dds_24bit
), NULL
, D3DX_FILTER_NONE
, 0, NULL
);
849 ok(SUCCEEDED(hr
), "Failed to load surface, hr %#x.\n", hr
);
851 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_DXT2
, D3DPOOL_SYSTEMMEM
, &newsurf
, NULL
);
853 skip("Failed to create DXT2 surface, hr %#x.\n", hr
);
856 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
857 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT2 format.\n");
858 check_release((IUnknown
*)newsurf
, 0);
861 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_DXT3
, D3DPOOL_SYSTEMMEM
, &newsurf
, NULL
);
863 skip("Failed to create DXT3 surface, hr %#x.\n", hr
);
866 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
867 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT3 format.\n");
868 check_release((IUnknown
*)newsurf
, 0);
871 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_DXT4
, D3DPOOL_SYSTEMMEM
, &newsurf
, NULL
);
873 skip("Failed to create DXT4 surface, hr %#x.\n", hr
);
876 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
877 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT4 format.\n");
878 check_release((IUnknown
*)newsurf
, 0);
881 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_DXT5
, D3DPOOL_SYSTEMMEM
, &newsurf
, NULL
);
883 skip("Failed to create DXT5 surface, hr %#x.\n", hr
);
886 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
887 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT5 format.\n");
888 check_release((IUnknown
*)newsurf
, 0);
891 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_DXT1
, D3DPOOL_SYSTEMMEM
, &newsurf
, NULL
);
893 skip("Failed to create DXT1 surface, hr %#x.\n", hr
);
896 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
897 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels to DXT1 format.\n");
899 hr
= D3DXLoadSurfaceFromSurface(surf
, NULL
, NULL
, newsurf
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
900 todo_wine
ok(SUCCEEDED(hr
), "Failed to convert pixels from DXT1 format.\n");
902 check_release((IUnknown
*)newsurf
, 0);
905 check_release((IUnknown
*)surf
, 0);
909 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
910 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
913 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9
*device
)
916 IDirect3DSurface9
*surface
;
918 D3DLOCKED_RECT lock_rect
;
919 D3DXIMAGE_INFO image_info
;
920 const BYTE pixels
[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
921 0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
922 DWORD pitch
= sizeof(pixels
) / 2;
924 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_R8G8B8
, D3DPOOL_SCRATCH
, &surface
, NULL
);
926 skip("Couldn't create surface\n");
930 SetRect(&rect
, 0, 0, 2, 2);
931 hr
= D3DXLoadSurfaceFromMemory(surface
, NULL
, NULL
, pixels
, D3DFMT_R8G8B8
, pitch
, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
933 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, NULL
);
934 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
936 hr
= D3DXLoadSurfaceFromFileA(surface
, NULL
, NULL
, "saved_surface.bmp", NULL
, D3DX_FILTER_NONE
, 0, &image_info
);
937 ok(hr
== D3D_OK
, "Couldn't load saved surface %#x\n", hr
);
938 if (FAILED(hr
)) goto next_tests
;
940 ok(image_info
.Width
== 2, "Wrong width %u\n", image_info
.Width
);
941 ok(image_info
.Height
== 2, "Wrong height %u\n", image_info
.Height
);
942 ok(image_info
.Format
== D3DFMT_R8G8B8
, "Wrong format %#x\n", image_info
.Format
);
943 ok(image_info
.ImageFileFormat
== D3DXIFF_BMP
, "Wrong file format %u\n", image_info
.ImageFileFormat
);
945 hr
= IDirect3DSurface9_LockRect(surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
946 ok(hr
== D3D_OK
, "Couldn't lock surface %#x\n", hr
);
947 if (FAILED(hr
)) goto next_tests
;
949 ok(!memcmp(lock_rect
.pBits
, pixels
, pitch
), "Pixel data mismatch in first row\n");
950 ok(!memcmp((BYTE
*)lock_rect
.pBits
+ lock_rect
.Pitch
, pixels
+ pitch
, pitch
), "Pixel data mismatch in second row\n");
952 IDirect3DSurface9_UnlockRect(surface
);
953 } else skip("Couldn't fill surface\n");
956 hr
= D3DXSaveSurfaceToFileA(NULL
, D3DXIFF_BMP
, surface
, NULL
, NULL
);
957 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
959 /* PPM and TGA are supported, even though MSDN claims they aren't */
961 hr
= D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM
, surface
, NULL
, NULL
);
962 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
963 hr
= D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA
, surface
, NULL
, NULL
);
964 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
965 hr
= D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS
, surface
, NULL
, NULL
);
966 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
969 hr
= D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM
+ 1, surface
, NULL
, NULL
);
970 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
972 SetRect(&rect
, 0, 0, 4, 4);
973 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
974 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
975 SetRect(&rect
, 2, 0, 1, 4);
976 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
977 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
978 SetRect(&rect
, 0, 2, 4, 1);
979 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
980 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
981 SetRect(&rect
, -1, -1, 2, 2);
982 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
983 ok(hr
== D3DERR_INVALIDCALL
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
984 SetRect(&rect
, 0, 0, 0, 0);
985 hr
= D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP
, surface
, NULL
, &rect
);
986 ok(hr
== D3D_OK
, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr
, D3D_OK
);
988 DeleteFileA("saved_surface.bmp");
989 DeleteFileA("saved_surface.ppm");
990 DeleteFileA("saved_surface.tga");
991 DeleteFileA("saved_surface.dds");
993 IDirect3DSurface9_Release(surface
);
1000 IDirect3DDevice9
*device
;
1001 D3DPRESENT_PARAMETERS d3dpp
;
1004 wnd
= CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
1006 skip("Couldn't create application window\n");
1009 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
1011 skip("Couldn't create IDirect3D9 object\n");
1016 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
1017 d3dpp
.Windowed
= TRUE
;
1018 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1019 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, wnd
, D3DCREATE_MIXED_VERTEXPROCESSING
, &d3dpp
, &device
);
1021 skip("Failed to create IDirect3DDevice9 object %#x\n", hr
);
1022 IDirect3D9_Release(d3d
);
1027 test_D3DXGetImageInfo();
1028 test_D3DXLoadSurface(device
);
1029 test_D3DXSaveSurfaceToFile(device
);
1031 check_release((IUnknown
*)device
, 0);
1032 check_release((IUnknown
*)d3d
, 0);