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 static HRESULT
create_file(const char *filename
, const unsigned char *data
, const unsigned int size
)
68 hfile
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
69 if(hfile
== INVALID_HANDLE_VALUE
) return HRESULT_FROM_WIN32(GetLastError());
71 if(WriteFile(hfile
, data
, size
, &received
, NULL
))
78 return D3DERR_INVALIDCALL
;
81 static void test_D3DXGetImageInfo(void)
85 BOOL testdummy_ok
, testbitmap_ok
;
87 hr
= create_file("testdummy.bmp", noimage
, sizeof(noimage
)); /* invalid image */
88 testdummy_ok
= SUCCEEDED(hr
);
90 hr
= create_file("testbitmap.bmp", bmp01
, sizeof(bmp01
)); /* valid image */
91 testbitmap_ok
= SUCCEEDED(hr
);
93 /* D3DXGetImageInfoFromFile */
95 hr
= D3DXGetImageInfoFromFileA("testbitmap.bmp", &info
);
96 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
98 hr
= D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL
); /* valid image, second parameter is NULL */
99 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
100 } else skip("Couldn't create \"testbitmap.bmp\"\n");
103 hr
= D3DXGetImageInfoFromFileA("testdummy.bmp", NULL
); /* invalid image, second parameter is NULL */
104 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
106 hr
= D3DXGetImageInfoFromFileA("testdummy.bmp", &info
);
107 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
108 } else skip("Couldn't create \"testdummy.bmp\"\n");
110 hr
= D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info
);
111 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
113 hr
= D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL
);
114 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
116 hr
= D3DXGetImageInfoFromFileA("", &info
);
117 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
119 hr
= D3DXGetImageInfoFromFileA(NULL
, &info
);
120 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
122 hr
= D3DXGetImageInfoFromFileA(NULL
, NULL
);
123 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
126 /* D3DXGetImageInfoFromResource */
128 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDB_BITMAP_1x1
), &info
); /* RT_BITMAP */
129 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
131 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDB_BITMAP_1x1
), NULL
);
132 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
135 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), &info
); /* RT_RCDATA */
136 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
138 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDS_STRING
), &info
);
139 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
141 hr
= D3DXGetImageInfoFromResourceA(NULL
, MAKEINTRESOURCEA(IDS_STRING
), NULL
);
142 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
144 hr
= D3DXGetImageInfoFromResourceA(NULL
, "resourcedoesnotexist", &info
);
145 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
147 hr
= D3DXGetImageInfoFromResourceA(NULL
, "resourcedoesnotexist", NULL
);
148 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
150 hr
= D3DXGetImageInfoFromResourceA(NULL
, NULL
, NULL
);
151 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
154 /* D3DXGetImageInfoFromFileInMemory */
155 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
, sizeof(bmp01
), &info
);
156 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
158 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
, sizeof(bmp01
)+5, &info
); /* too large size */
159 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
161 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
, sizeof(bmp01
), NULL
);
162 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
164 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, sizeof(noimage
), NULL
);
165 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
167 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, sizeof(noimage
), &info
);
168 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
171 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
, sizeof(bmp01
)-1, &info
);
172 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
175 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
+1, sizeof(bmp01
)-1, &info
);
176 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
178 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
, 0, &info
);
179 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
181 hr
= D3DXGetImageInfoFromFileInMemory(bmp01
, 0, NULL
);
182 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
184 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, 0, &info
);
185 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
187 hr
= D3DXGetImageInfoFromFileInMemory(noimage
, 0, NULL
);
188 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
190 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 0, &info
);
191 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
193 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 4, NULL
);
194 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
196 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 4, &info
);
197 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
199 hr
= D3DXGetImageInfoFromFileInMemory(NULL
, 0, NULL
);
200 ok(hr
== D3DERR_INVALIDCALL
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
203 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
204 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
207 #define check_pixel_1bpp(lockrect, x, y, color) \
208 ok(((BYTE*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch] == color, "Got color %#x, expected %#x\n", ((BYTE*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch], color)
210 #define check_pixel_2bpp(lockrect, x, y, color) \
211 ok(((WORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 2] == color, "Got color %#x, expected %#x\n", ((WORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 2], color)
213 #define check_pixel_4bpp(lockrect, x, y, color) \
214 ok(((DWORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 4] == color, "Got color %#x, expected %#x\n", ((DWORD*)(lockrect).pBits)[(x) + (y) * (lockrect).Pitch / 4], color)
215 static void test_D3DXLoadSurface(IDirect3DDevice9
*device
)
218 BOOL testdummy_ok
, testbitmap_ok
;
219 IDirect3DSurface9
*surf
, *newsurf
;
221 D3DLOCKED_RECT lockrect
;
222 const WORD pixdata_a8r3g3b2
[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
223 const WORD pixdata_a1r5g5b5
[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
224 const WORD pixdata_r5g6b5
[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
225 const DWORD pixdata_g16r16
[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
226 const DWORD pixdata_a8b8g8r8
[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
227 const DWORD pixdata_a2r10g10b10
[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
229 hr
= create_file("testdummy.bmp", noimage
, sizeof(noimage
)); /* invalid image */
230 testdummy_ok
= SUCCEEDED(hr
);
232 hr
= create_file("testbitmap.bmp", bmp01
, sizeof(bmp01
)); /* valid image */
233 testbitmap_ok
= SUCCEEDED(hr
);
235 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf
, NULL
);
237 skip("Failed to create a surface (%#x)\n", hr
);
238 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
239 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
243 /* D3DXLoadSurfaceFromFile */
246 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "testbitmap.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
247 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3D_OK
);
250 hr
= D3DXLoadSurfaceFromFileA(NULL
, NULL
, NULL
, "testbitmap.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
251 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
252 } else skip("Couldn't create \"testbitmap.bmp\"\n");
256 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "testdummy.bmp", NULL
, D3DX_DEFAULT
, 0, NULL
);
257 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
259 } else skip("Couldn't create \"testdummy.bmp\"\n");
261 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0, NULL
);
262 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
264 hr
= D3DXLoadSurfaceFromFileA(surf
, NULL
, NULL
, "", NULL
, D3DX_DEFAULT
, 0, NULL
);
265 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
268 /* D3DXLoadSurfaceFromResource */
270 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, MAKEINTRESOURCE(IDB_BITMAP_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
271 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
273 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, MAKEINTRESOURCE(IDD_BITMAPDATA_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
274 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
277 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0, NULL
);
278 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
280 hr
= D3DXLoadSurfaceFromResourceA(NULL
, NULL
, NULL
, NULL
, MAKEINTRESOURCE(IDB_BITMAP_1x1
), NULL
, D3DX_DEFAULT
, 0, NULL
);
281 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
283 hr
= D3DXLoadSurfaceFromResourceA(surf
, NULL
, NULL
, NULL
, MAKEINTRESOURCE(IDS_STRING
), NULL
, D3DX_DEFAULT
, 0, NULL
);
284 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
287 /* D3DXLoadSurfaceFromFileInMemory */
289 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, bmp01
, sizeof(bmp01
), NULL
, D3DX_DEFAULT
, 0, NULL
);
290 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
292 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, noimage
, sizeof(noimage
), NULL
, D3DX_DEFAULT
, 0, NULL
);
293 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
296 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, bmp01
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
297 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
299 hr
= D3DXLoadSurfaceFromFileInMemory(NULL
, NULL
, NULL
, bmp01
, sizeof(bmp01
), NULL
, D3DX_DEFAULT
, 0, NULL
);
300 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
302 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, NULL
, 8, NULL
, D3DX_DEFAULT
, 0, NULL
);
303 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
305 hr
= D3DXLoadSurfaceFromFileInMemory(surf
, NULL
, NULL
, NULL
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
306 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
308 hr
= D3DXLoadSurfaceFromFileInMemory(NULL
, NULL
, NULL
, NULL
, 0, NULL
, D3DX_DEFAULT
, 0, NULL
);
309 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
312 /* D3DXLoadSurfaceFromMemory */
313 SetRect(&rect
, 0, 0, 2, 2);
315 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
316 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
318 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, 0, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
319 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
321 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, NULL
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
322 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
324 hr
= D3DXLoadSurfaceFromMemory(NULL
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
325 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
327 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, NULL
, D3DX_DEFAULT
, 0);
328 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
330 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata
, D3DFMT_UNKNOWN
, sizeof(pixdata
), NULL
, &rect
, D3DX_DEFAULT
, 0);
331 ok(hr
== E_FAIL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, E_FAIL
);
334 /* D3DXLoadSurfaceFromSurface */
335 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &newsurf
, NULL
);
338 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
339 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
342 hr
= D3DXLoadSurfaceFromSurface(NULL
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
343 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
345 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0);
346 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
348 check_release((IUnknown
*)newsurf
, 0);
349 } else skip("Failed to create a second surface\n");
351 check_release((IUnknown
*)surf
, 0);
354 /* test color conversion */
356 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf
, NULL
);
357 if(FAILED(hr
)) skip("Failed to create a surface (%#x)\n", hr
);
359 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
, D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
360 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
361 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
362 check_pixel_4bpp(lockrect
, 0, 0, 0x57dbffff);
363 check_pixel_4bpp(lockrect
, 1, 0, 0x98ffff00);
364 check_pixel_4bpp(lockrect
, 0, 1, 0xacdbff55);
365 check_pixel_4bpp(lockrect
, 1, 1, 0xc8929255);
366 IDirect3DSurface9_UnlockRect(surf
);
368 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
, D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
369 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
370 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
371 check_pixel_4bpp(lockrect
, 0, 0, 0x008cadad);
372 check_pixel_4bpp(lockrect
, 1, 0, 0xff317342);
373 check_pixel_4bpp(lockrect
, 0, 1, 0x0008ad10);
374 check_pixel_4bpp(lockrect
, 1, 1, 0xff29088c);
375 IDirect3DSurface9_UnlockRect(surf
);
377 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
, D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
378 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
379 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
380 check_pixel_4bpp(lockrect
, 0, 0, 0xff9cdfb5);
381 check_pixel_4bpp(lockrect
, 1, 0, 0xff63b26b);
382 check_pixel_4bpp(lockrect
, 0, 1, 0xff085d73);
383 check_pixel_4bpp(lockrect
, 1, 1, 0xff425d73);
384 IDirect3DSurface9_UnlockRect(surf
);
386 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
, D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
387 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
388 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
390 check_pixel_4bpp(lockrect
, 0, 0, 0xff3f08ff);
392 check_pixel_4bpp(lockrect
, 1, 0, 0xff44dcff);
393 check_pixel_4bpp(lockrect
, 0, 1, 0xff97e4ff);
394 check_pixel_4bpp(lockrect
, 1, 1, 0xfffe9aff);
395 IDirect3DSurface9_UnlockRect(surf
);
397 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
, D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
398 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
399 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
400 check_pixel_4bpp(lockrect
, 0, 0, 0xc3f04c39);
401 check_pixel_4bpp(lockrect
, 1, 0, 0x2392e85a);
402 check_pixel_4bpp(lockrect
, 0, 1, 0x09fd97b1);
403 check_pixel_4bpp(lockrect
, 1, 1, 0x8df62bc3);
404 IDirect3DSurface9_UnlockRect(surf
);
406 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
, D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
407 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
408 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
409 check_pixel_4bpp(lockrect
, 0, 0, 0x555c95bf);
410 check_pixel_4bpp(lockrect
, 1, 0, 0x556d663f);
411 check_pixel_4bpp(lockrect
, 0, 1, 0xaac385ad);
413 check_pixel_4bpp(lockrect
, 1, 1, 0xfffcc575);
415 IDirect3DSurface9_UnlockRect(surf
);
417 check_release((IUnknown
*)surf
, 0);
421 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A1R5G5B5
, D3DPOOL_DEFAULT
, &surf
, NULL
);
422 if(FAILED(hr
)) skip("Failed to create a surface (%#x)\n", hr
);
424 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
, D3DFMT_A8R3G3B2
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
425 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
426 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
427 check_pixel_2bpp(lockrect
, 0, 0, 0x6fff);
428 check_pixel_2bpp(lockrect
, 1, 0, 0xffe0);
429 check_pixel_2bpp(lockrect
, 0, 1, 0xefea);
430 check_pixel_2bpp(lockrect
, 1, 1, 0xca4a);
431 IDirect3DSurface9_UnlockRect(surf
);
433 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
, D3DFMT_A1R5G5B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
434 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
435 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
436 check_pixel_2bpp(lockrect
, 0, 0, 0x46b5);
437 check_pixel_2bpp(lockrect
, 1, 0, 0x99c8);
438 check_pixel_2bpp(lockrect
, 0, 1, 0x06a2);
439 check_pixel_2bpp(lockrect
, 1, 1, 0x9431);
440 IDirect3DSurface9_UnlockRect(surf
);
442 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
, D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
443 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
444 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
445 check_pixel_2bpp(lockrect
, 0, 0, 0xcf76);
446 check_pixel_2bpp(lockrect
, 1, 0, 0xb2cd);
447 check_pixel_2bpp(lockrect
, 0, 1, 0x856e);
448 check_pixel_2bpp(lockrect
, 1, 1, 0xa16e);
449 IDirect3DSurface9_UnlockRect(surf
);
451 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
, D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
452 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
453 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
455 check_pixel_2bpp(lockrect
, 0, 0, 0xa03f);
457 check_pixel_2bpp(lockrect
, 1, 0, 0xa37f);
458 check_pixel_2bpp(lockrect
, 0, 1, 0xcb9f);
459 check_pixel_2bpp(lockrect
, 1, 1, 0xfe7f);
460 IDirect3DSurface9_UnlockRect(surf
);
462 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
, D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
463 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
464 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
466 check_pixel_2bpp(lockrect
, 0, 0, 0xf527);
467 check_pixel_2bpp(lockrect
, 1, 0, 0x4b8b);
469 check_pixel_2bpp(lockrect
, 0, 1, 0x7e56);
470 check_pixel_2bpp(lockrect
, 1, 1, 0xf8b8);
471 IDirect3DSurface9_UnlockRect(surf
);
473 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
, D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
474 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
475 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
476 check_pixel_2bpp(lockrect
, 0, 0, 0x2e57);
478 check_pixel_2bpp(lockrect
, 1, 0, 0x3588);
480 check_pixel_2bpp(lockrect
, 0, 1, 0xe215);
481 check_pixel_2bpp(lockrect
, 1, 1, 0xff0e);
482 IDirect3DSurface9_UnlockRect(surf
);
484 check_release((IUnknown
*)surf
, 0);
488 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
489 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
496 IDirect3DDevice9
*device
;
497 D3DPRESENT_PARAMETERS d3dpp
;
500 wnd
= CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
502 skip("Couldn't create application window\n");
505 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
507 skip("Couldn't create IDirect3D9 object\n");
512 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
513 d3dpp
.Windowed
= TRUE
;
514 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
515 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, wnd
, D3DCREATE_MIXED_VERTEXPROCESSING
, &d3dpp
, &device
);
517 skip("Failed to create IDirect3DDevice9 object %#x\n", hr
);
518 IDirect3D9_Release(d3d
);
523 test_D3DXGetImageInfo();
524 test_D3DXLoadSurface(device
);
526 check_release((IUnknown
*)device
, 0);
527 check_release((IUnknown
*)d3d
, 0);