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
);
333 SetRect(&destrect
, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
334 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
335 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
337 SetRect(&destrect
, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
338 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
339 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
341 SetRect(&destrect
, 1, 1, 0, 0); /* left > right, top > bottom */
342 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
343 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
345 SetRect(&destrect
, 0, 0, 0, 0); /* left = right, top = bottom */
346 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
347 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
349 SetRect(&destrect
, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
350 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, &destrect
, pixdata
, D3DFMT_A8R8G8B8
, sizeof(pixdata
), NULL
, &rect
, D3DX_FILTER_NONE
, 0);
351 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
354 /* D3DXLoadSurfaceFromSurface */
355 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &newsurf
, NULL
);
357 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
358 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3D_OK
);
360 hr
= D3DXLoadSurfaceFromSurface(NULL
, NULL
, NULL
, surf
, NULL
, NULL
, D3DX_DEFAULT
, 0);
361 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
363 hr
= D3DXLoadSurfaceFromSurface(newsurf
, NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, 0);
364 ok(hr
== D3DERR_INVALIDCALL
, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
366 check_release((IUnknown
*)newsurf
, 0);
367 } else skip("Failed to create a second surface\n");
369 check_release((IUnknown
*)surf
, 0);
372 /* test color conversion */
374 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf
, NULL
);
375 if(FAILED(hr
)) skip("Failed to create a surface (%#x)\n", hr
);
377 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
, D3DFMT_A8R3G3B2
, 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, 0x57dbffff);
381 check_pixel_4bpp(lockrect
, 1, 0, 0x98ffff00);
382 check_pixel_4bpp(lockrect
, 0, 1, 0xacdbff55);
383 check_pixel_4bpp(lockrect
, 1, 1, 0xc8929255);
384 IDirect3DSurface9_UnlockRect(surf
);
386 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
, D3DFMT_A1R5G5B5
, 4, 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
);
389 check_pixel_4bpp(lockrect
, 0, 0, 0x008cadad);
390 check_pixel_4bpp(lockrect
, 1, 0, 0xff317342);
391 check_pixel_4bpp(lockrect
, 0, 1, 0x0008ad10);
392 check_pixel_4bpp(lockrect
, 1, 1, 0xff29088c);
393 IDirect3DSurface9_UnlockRect(surf
);
395 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
, D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
396 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
397 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
398 check_pixel_4bpp(lockrect
, 0, 0, 0xff9cdfb5);
399 check_pixel_4bpp(lockrect
, 1, 0, 0xff63b26b);
400 check_pixel_4bpp(lockrect
, 0, 1, 0xff085d73);
401 check_pixel_4bpp(lockrect
, 1, 1, 0xff425d73);
402 IDirect3DSurface9_UnlockRect(surf
);
404 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
, D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
405 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
406 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
408 check_pixel_4bpp(lockrect
, 0, 0, 0xff3f08ff);
410 check_pixel_4bpp(lockrect
, 1, 0, 0xff44dcff);
411 check_pixel_4bpp(lockrect
, 0, 1, 0xff97e4ff);
412 check_pixel_4bpp(lockrect
, 1, 1, 0xfffe9aff);
413 IDirect3DSurface9_UnlockRect(surf
);
415 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
, D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
416 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
417 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
418 check_pixel_4bpp(lockrect
, 0, 0, 0xc3f04c39);
419 check_pixel_4bpp(lockrect
, 1, 0, 0x2392e85a);
420 check_pixel_4bpp(lockrect
, 0, 1, 0x09fd97b1);
421 check_pixel_4bpp(lockrect
, 1, 1, 0x8df62bc3);
422 IDirect3DSurface9_UnlockRect(surf
);
424 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
, D3DFMT_A2R10G10B10
, 8, 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_4bpp(lockrect
, 0, 0, 0x555c95bf);
428 check_pixel_4bpp(lockrect
, 1, 0, 0x556d663f);
429 check_pixel_4bpp(lockrect
, 0, 1, 0xaac385ad);
431 check_pixel_4bpp(lockrect
, 1, 1, 0xfffcc575);
433 IDirect3DSurface9_UnlockRect(surf
);
435 check_release((IUnknown
*)surf
, 0);
439 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 2, 2, D3DFMT_A1R5G5B5
, D3DPOOL_DEFAULT
, &surf
, NULL
);
440 if(FAILED(hr
)) skip("Failed to create a surface (%#x)\n", hr
);
442 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8r3g3b2
, D3DFMT_A8R3G3B2
, 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, 0x6fff);
446 check_pixel_2bpp(lockrect
, 1, 0, 0xffe0);
447 check_pixel_2bpp(lockrect
, 0, 1, 0xefea);
448 check_pixel_2bpp(lockrect
, 1, 1, 0xca4a);
449 IDirect3DSurface9_UnlockRect(surf
);
451 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a1r5g5b5
, D3DFMT_A1R5G5B5
, 4, 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
);
454 check_pixel_2bpp(lockrect
, 0, 0, 0x46b5);
455 check_pixel_2bpp(lockrect
, 1, 0, 0x99c8);
456 check_pixel_2bpp(lockrect
, 0, 1, 0x06a2);
457 check_pixel_2bpp(lockrect
, 1, 1, 0x9431);
458 IDirect3DSurface9_UnlockRect(surf
);
460 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_r5g6b5
, D3DFMT_R5G6B5
, 4, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
461 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
462 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
463 check_pixel_2bpp(lockrect
, 0, 0, 0xcf76);
464 check_pixel_2bpp(lockrect
, 1, 0, 0xb2cd);
465 check_pixel_2bpp(lockrect
, 0, 1, 0x856e);
466 check_pixel_2bpp(lockrect
, 1, 1, 0xa16e);
467 IDirect3DSurface9_UnlockRect(surf
);
469 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_g16r16
, D3DFMT_G16R16
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
470 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
471 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
473 check_pixel_2bpp(lockrect
, 0, 0, 0xa03f);
475 check_pixel_2bpp(lockrect
, 1, 0, 0xa37f);
476 check_pixel_2bpp(lockrect
, 0, 1, 0xcb9f);
477 check_pixel_2bpp(lockrect
, 1, 1, 0xfe7f);
478 IDirect3DSurface9_UnlockRect(surf
);
480 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a8b8g8r8
, D3DFMT_A8B8G8R8
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
481 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
482 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
484 check_pixel_2bpp(lockrect
, 0, 0, 0xf527);
485 check_pixel_2bpp(lockrect
, 1, 0, 0x4b8b);
487 check_pixel_2bpp(lockrect
, 0, 1, 0x7e56);
488 check_pixel_2bpp(lockrect
, 1, 1, 0xf8b8);
489 IDirect3DSurface9_UnlockRect(surf
);
491 hr
= D3DXLoadSurfaceFromMemory(surf
, NULL
, NULL
, pixdata_a2r10g10b10
, D3DFMT_A2R10G10B10
, 8, NULL
, &rect
, D3DX_FILTER_NONE
, 0);
492 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
493 IDirect3DSurface9_LockRect(surf
, &lockrect
, NULL
, D3DLOCK_READONLY
);
494 check_pixel_2bpp(lockrect
, 0, 0, 0x2e57);
496 check_pixel_2bpp(lockrect
, 1, 0, 0x3588);
498 check_pixel_2bpp(lockrect
, 0, 1, 0xe215);
499 check_pixel_2bpp(lockrect
, 1, 1, 0xff0e);
500 IDirect3DSurface9_UnlockRect(surf
);
502 check_release((IUnknown
*)surf
, 0);
506 if(testdummy_ok
) DeleteFileA("testdummy.bmp");
507 if(testbitmap_ok
) DeleteFileA("testbitmap.bmp");
514 IDirect3DDevice9
*device
;
515 D3DPRESENT_PARAMETERS d3dpp
;
518 wnd
= CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
520 skip("Couldn't create application window\n");
523 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
525 skip("Couldn't create IDirect3D9 object\n");
530 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
531 d3dpp
.Windowed
= TRUE
;
532 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
533 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, wnd
, D3DCREATE_MIXED_VERTEXPROCESSING
, &d3dpp
, &device
);
535 skip("Failed to create IDirect3DDevice9 object %#x\n", hr
);
536 IDirect3D9_Release(d3d
);
541 test_D3DXGetImageInfo();
542 test_D3DXLoadSurface(device
);
544 check_release((IUnknown
*)device
, 0);
545 check_release((IUnknown
*)d3d
, 0);