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");
255 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testdummy.bmp", NULL, D3DX_DEFAULT, 0, NULL);
256 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
257 } else skip("Couldn't create \"testdummy.bmp\"\n");
259 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
260 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
262 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "", NULL, D3DX_DEFAULT, 0, NULL);
263 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
266 /* D3DXLoadSurfaceFromResource */
268 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
269 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
272 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDD_BITMAPDATA_1x1), NULL, D3DX_DEFAULT, 0, NULL);
273 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
275 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL);
276 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
278 hr = D3DXLoadSurfaceFromResourceA(NULL, NULL, NULL, NULL, MAKEINTRESOURCE(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL);
279 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
281 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, MAKEINTRESOURCE(IDS_STRING), NULL, D3DX_DEFAULT, 0, NULL);
282 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
285 /* D3DXLoadSurfaceFromFileInMemory */
287 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
288 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
291 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, noimage, sizeof(noimage), NULL, D3DX_DEFAULT, 0, NULL);
292 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
294 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp01, 0, NULL, D3DX_DEFAULT, 0, NULL);
295 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
297 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, bmp01, sizeof(bmp01), NULL, D3DX_DEFAULT, 0, NULL);
298 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
300 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 8, NULL, D3DX_DEFAULT, 0, NULL);
301 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
303 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
304 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
306 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL);
307 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
310 /* D3DXLoadSurfaceFromMemory */
311 SetRect(&rect, 0, 0, 2, 2);
313 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
314 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
316 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, 0, NULL, &rect, D3DX_FILTER_NONE, 0);
317 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
319 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, NULL, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
320 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
322 hr = D3DXLoadSurfaceFromMemory(NULL, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
323 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
325 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, NULL, D3DX_DEFAULT, 0);
326 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
328 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_UNKNOWN, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0);
329 ok(hr == E_FAIL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, E_FAIL);
331 SetRect(&destrect, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
332 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
333 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
335 SetRect(&destrect, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
336 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
337 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
339 SetRect(&destrect, 1, 1, 0, 0); /* left > right, top > bottom */
340 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
341 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
343 SetRect(&destrect, 0, 0, 0, 0); /* left = right, top = bottom */
344 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
345 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
347 SetRect(&destrect, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
348 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0);
349 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
352 /* D3DXLoadSurfaceFromSurface */
353 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newsurf, NULL);
355 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
356 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
358 hr = D3DXLoadSurfaceFromSurface(NULL, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
359 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
361 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0);
362 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
364 check_release((IUnknown*)newsurf, 0);
365 } else skip("Failed to create a second surface\n");
367 check_release((IUnknown*)surf, 0);
370 /* test color conversion */
372 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL);
373 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
375 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
376 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
377 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
378 check_pixel_4bpp(lockrect, 0, 0, 0x57dbffff);
379 check_pixel_4bpp(lockrect, 1, 0, 0x98ffff00);
380 check_pixel_4bpp(lockrect, 0, 1, 0xacdbff55);
381 check_pixel_4bpp(lockrect, 1, 1, 0xc8929255);
382 IDirect3DSurface9_UnlockRect(surf);
384 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
385 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
386 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
387 check_pixel_4bpp(lockrect, 0, 0, 0x008cadad);
388 check_pixel_4bpp(lockrect, 1, 0, 0xff317342);
389 check_pixel_4bpp(lockrect, 0, 1, 0x0008ad10);
390 check_pixel_4bpp(lockrect, 1, 1, 0xff29088c);
391 IDirect3DSurface9_UnlockRect(surf);
393 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
394 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
395 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
396 check_pixel_4bpp(lockrect, 0, 0, 0xff9cdfb5);
397 check_pixel_4bpp(lockrect, 1, 0, 0xff63b26b);
398 check_pixel_4bpp(lockrect, 0, 1, 0xff085d73);
399 check_pixel_4bpp(lockrect, 1, 1, 0xff425d73);
400 IDirect3DSurface9_UnlockRect(surf);
402 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
403 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
404 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
406 check_pixel_4bpp(lockrect, 0, 0, 0xff3f08ff);
408 check_pixel_4bpp(lockrect, 1, 0, 0xff44dcff);
409 check_pixel_4bpp(lockrect, 0, 1, 0xff97e4ff);
410 check_pixel_4bpp(lockrect, 1, 1, 0xfffe9aff);
411 IDirect3DSurface9_UnlockRect(surf);
413 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
414 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
415 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
416 check_pixel_4bpp(lockrect, 0, 0, 0xc3f04c39);
417 check_pixel_4bpp(lockrect, 1, 0, 0x2392e85a);
418 check_pixel_4bpp(lockrect, 0, 1, 0x09fd97b1);
419 check_pixel_4bpp(lockrect, 1, 1, 0x8df62bc3);
420 IDirect3DSurface9_UnlockRect(surf);
422 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
423 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
424 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
425 check_pixel_4bpp(lockrect, 0, 0, 0x555c95bf);
426 check_pixel_4bpp(lockrect, 1, 0, 0x556d663f);
427 check_pixel_4bpp(lockrect, 0, 1, 0xaac385ad);
429 check_pixel_4bpp(lockrect, 1, 1, 0xfffcc575);
431 IDirect3DSurface9_UnlockRect(surf);
433 check_release((IUnknown*)surf, 0);
437 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A1R5G5B5, D3DPOOL_DEFAULT, &surf, NULL);
438 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
440 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
441 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
442 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
443 check_pixel_2bpp(lockrect, 0, 0, 0x6fff);
444 check_pixel_2bpp(lockrect, 1, 0, 0xffe0);
445 check_pixel_2bpp(lockrect, 0, 1, 0xefea);
446 check_pixel_2bpp(lockrect, 1, 1, 0xca4a);
447 IDirect3DSurface9_UnlockRect(surf);
449 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
450 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
451 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
452 check_pixel_2bpp(lockrect, 0, 0, 0x46b5);
453 check_pixel_2bpp(lockrect, 1, 0, 0x99c8);
454 check_pixel_2bpp(lockrect, 0, 1, 0x06a2);
455 check_pixel_2bpp(lockrect, 1, 1, 0x9431);
456 IDirect3DSurface9_UnlockRect(surf);
458 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
459 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
460 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
461 check_pixel_2bpp(lockrect, 0, 0, 0xcf76);
462 check_pixel_2bpp(lockrect, 1, 0, 0xb2cd);
463 check_pixel_2bpp(lockrect, 0, 1, 0x856e);
464 check_pixel_2bpp(lockrect, 1, 1, 0xa16e);
465 IDirect3DSurface9_UnlockRect(surf);
467 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
468 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
469 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
471 check_pixel_2bpp(lockrect, 0, 0, 0xa03f);
473 check_pixel_2bpp(lockrect, 1, 0, 0xa37f);
474 check_pixel_2bpp(lockrect, 0, 1, 0xcb9f);
475 check_pixel_2bpp(lockrect, 1, 1, 0xfe7f);
476 IDirect3DSurface9_UnlockRect(surf);
478 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
479 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
480 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
482 check_pixel_2bpp(lockrect, 0, 0, 0xf527);
483 check_pixel_2bpp(lockrect, 1, 0, 0x4b8b);
485 check_pixel_2bpp(lockrect, 0, 1, 0x7e56);
486 check_pixel_2bpp(lockrect, 1, 1, 0xf8b8);
487 IDirect3DSurface9_UnlockRect(surf);
489 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
490 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
491 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
492 check_pixel_2bpp(lockrect, 0, 0, 0x2e57);
494 check_pixel_2bpp(lockrect, 1, 0, 0x3588);
496 check_pixel_2bpp(lockrect, 0, 1, 0xe215);
497 check_pixel_2bpp(lockrect, 1, 1, 0xff0e);
498 IDirect3DSurface9_UnlockRect(surf);
500 check_release((IUnknown*)surf, 0);
504 if(testdummy_ok) DeleteFileA("testdummy.bmp");
505 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
512 IDirect3DDevice9 *device;
513 D3DPRESENT_PARAMETERS d3dpp;
516 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
518 skip("Couldn't create application window\n");
521 d3d = Direct3DCreate9(D3D_SDK_VERSION);
523 skip("Couldn't create IDirect3D9 object\n");
528 ZeroMemory(&d3dpp, sizeof(d3dpp));
529 d3dpp.Windowed = TRUE;
530 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
531 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
533 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
534 IDirect3D9_Release(d3d);
539 test_D3DXGetImageInfo();
540 test_D3DXLoadSurface(device);
542 check_release((IUnknown*)device, 0);
543 check_release((IUnknown*)d3d, 0);