diff --git a/dlls/d3dx9_36/Makefile.in b/dlls/d3dx9_36/Makefile.in index 2ed85ea..59fe39f 100644 --- a/dlls/d3dx9_36/Makefile.in +++ b/dlls/d3dx9_36/Makefile.in @@ -4,12 +4,13 @@ SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = d3dx9_36.dll IMPORTLIB = d3dx9 -IMPORTS = d3d9 d3dx8 kernel32 +IMPORTS = d3d9 d3dx8 kernel32 ntdll C_SRCS = \ d3dx9_36_main.c \ font.c \ - math.c + math.c \ + texture.c @MAKE_DLL_RULES@ diff --git a/dlls/d3dx9_36/d3dx9_36.spec b/dlls/d3dx9_36/d3dx9_36.spec index e616d23..5096394 100644 --- a/dlls/d3dx9_36/d3dx9_36.spec +++ b/dlls/d3dx9_36/d3dx9_36.spec @@ -93,12 +93,12 @@ @ stub D3DXCreateTextA @ stub D3DXCreateTextW @ stub D3DXCreateTexture -@ stub D3DXCreateTextureFromFileA +@ stdcall D3DXCreateTextureFromFileA(ptr str ptr) @ stub D3DXCreateTextureFromFileExA @ stub D3DXCreateTextureFromFileExW @ stub D3DXCreateTextureFromFileInMemory @ stub D3DXCreateTextureFromFileInMemoryEx -@ stub D3DXCreateTextureFromFileW +@ stdcall D3DXCreateTextureFromFileW(ptr wstr ptr) @ stub D3DXCreateTextureFromResourceA @ stub D3DXCreateTextureFromResourceExA @ stub D3DXCreateTextureFromResourceExW diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c new file mode 100644 index 0000000..6420c38 --- /dev/null +++ b/dlls/d3dx9_36/texture.c @@ -0,0 +1,137 @@ +/* + * Texture functions. + * + * Copyright (C) 2008 Louis Lenders + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ +#include "windef.h" +#include "wingdi.h" +#include "wine/debug.h" +#include "winternl.h" +#include "d3d9.h" + +WINE_DEFAULT_DEBUG_CHANNEL(d3dx); + +/************************************************************************* + * D3DXCreateTextureFromFileW + * + * Create a texture from a file. + */ +HRESULT WINAPI D3DXCreateTextureFromFileW(LPDIRECT3DDEVICE9 pDevice, LPWSTR filename, LPDIRECT3DTEXTURE9 * ppTexture) +{ + HANDLE hFile,hFileMapping; + int i,j,k=0; + int bpp; + LPBYTE view=0; + DWORD size, offset; + DWORD width,height; + WORD fileType; + WORD bmBitsPixel; + BYTE *Buffer=0; + DWORD* pData; + LPDIRECT3DSURFACE9 pSurface = NULL; + D3DLOCKED_RECT LockedRect; + + /* Load file into memory */ + hFile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL, NULL); + if(hFile == INVALID_HANDLE_VALUE) goto cleanup; + + hFileMapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL); + if(!hFileMapping) goto cleanup; + + size=GetFileSize(hFile, NULL); + if(size == INVALID_FILE_SIZE) goto cleanup; + + view=(LPBYTE)MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0); + if(!view) goto cleanup; + + memcpy(&fileType,view,sizeof(WORD)); + + switch(fileType) + { + case(0x4d42): /* Bitmapi = "BM" */ + + memcpy(&offset, view+10, sizeof(DWORD)); /* Start of the rgb data */ + memcpy(&width, view+18, sizeof(DWORD)); + memcpy(&height, view+22, sizeof(DWORD)); + memcpy(&bmBitsPixel,view+28, sizeof(WORD)); + + Buffer=(BYTE*) HeapAlloc(GetProcessHeap(),0,size-offset); + memcpy(Buffer,view+offset ,size-offset); + + switch(bmBitsPixel) + { + case 32: + case 24: + { + bpp=bmBitsPixel/8; + + IDirect3DDevice9_CreateTexture(pDevice, width, height, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, ppTexture,0); + IDirect3DTexture9_GetSurfaceLevel(*ppTexture,0, &pSurface); + IDirect3DTexture9_LockRect( *ppTexture, 0, &LockedRect, NULL, D3DLOCK_DISCARD); + pData=(LockedRect.pBits); + /* fill the locked surface with the pixel data */ + for(j=height-1;j>=0;--j) + { + for(i=0;i