//! creates a surface from the file Image* ImageLoaderX::LoadImageFromFile(FileReader* file) { IDirect3DSurface9* pSurf = NULL; D3DXIMAGE_INFO info; D3DXGetImageInfoFromFileA(file->GetFileName(), &info); m_pID3DDevice->CreateOffscreenPlainSurface(info.Width, info.Height, info.Format, D3DPOOL_SCRATCH, &pSurf, NULL); D3DXLoadSurfaceFromFileA(pSurf, NULL, NULL, file->GetFileName(), NULL, D3DX_FILTER_NONE, 0, &info); Image* image = 0; if (pSurf) { // create surface D3DLOCKED_RECT lockRect; D3DSURFACE_DESC desc; switch (info.Format) { case D3DFMT_A8R8G8B8: case D3DFMT_X8R8G8B8: pSurf->LockRect(&lockRect, NULL, D3DLOCK_READONLY); image = new Image(ECF_A8R8G8B8, dimension2d<s32>(info.Width, info.Height), lockRect.pBits, FALSE); break; case D3DFMT_R8G8B8: pSurf->LockRect(&lockRect, NULL, D3DLOCK_READONLY); pSurf->GetDesc(&desc); image = new Image(ECF_R8G8B8, dimension2d<s32>(info.Width, info.Height), lockRect.pBits, FALSE); break; case D3DFMT_A1R5G5B5: case D3DFMT_X1R5G5B5: pSurf->LockRect(&lockRect, NULL, D3DLOCK_READONLY); image = new Image(ECF_A1R5G5B5, dimension2d<s32>(info.Width, info.Height), lockRect.pBits, FALSE); break; case D3DFMT_R5G6B5: pSurf->LockRect(&lockRect, NULL, D3DLOCK_READONLY); image = new Image(ECF_R5G6B5, dimension2d<s32>(info.Width, info.Height), lockRect.pBits, FALSE); break; default: Printer::Log("No matched image format", ELL_ERROR); break; } } else { Printer::Log("D3DXLoadSuface failed", ELL_ERROR); return NULL; } pSurf->Release(); return image; }
static void test_D3DXLoadSurface(IDirect3DDevice9 *device) { HRESULT hr; BOOL testdummy_ok, testbitmap_ok; IDirect3DSurface9 *surf, *newsurf; RECT rect, destrect; D3DLOCKED_RECT lockrect; const WORD pixdata_a8r3g3b2[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 }; const WORD pixdata_a1r5g5b5[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 }; const WORD pixdata_r5g6b5[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee }; const DWORD pixdata_g16r16[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 }; const DWORD pixdata_a8b8g8r8[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 }; const DWORD pixdata_a2r10g10b10[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 }; hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */ testdummy_ok = SUCCEEDED(hr); hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01)); /* valid image */ testbitmap_ok = SUCCEEDED(hr); hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL); if(FAILED(hr)) { skip("Failed to create a surface (%#x)\n", hr); if(testdummy_ok) DeleteFileA("testdummy.bmp"); if(testbitmap_ok) DeleteFileA("testbitmap.bmp"); return; } /* D3DXLoadSurfaceFromFile */ if(testbitmap_ok) { todo_wine { hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL); ok(hr == D3D_OK, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3D_OK); } hr = D3DXLoadSurfaceFromFileA(NULL, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL); ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); } else skip("Couldn't create \"testbitmap.bmp\"\n");