From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/tests/texture.c | 15 ++++++--------- dlls/d3dx9_36/texture.c | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c index 9955d971cef..636dd3c7a08 100644 --- a/dlls/d3dx9_36/tests/texture.c +++ b/dlls/d3dx9_36/tests/texture.c @@ -2182,9 +2182,8 @@ static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9 *device) texture = NULL; hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_24bit, sizeof(dds_24bit), 32, 32, 6, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, test_filter_values[i].filter, 0, NULL, NULL, &texture); - todo_wine_if(FAILED(hr)) ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - if (texture) - IDirect3DTexture9_Release(texture); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + IDirect3DTexture9_Release(texture);
winetest_pop_context(); } @@ -2555,9 +2554,8 @@ static void test_D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *devic hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map, sizeof(dds_cube_map), D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, test_filter_values[i].filter, 0, NULL, NULL, &cube_texture); - todo_wine_if(FAILED(hr)) ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - if (cube_texture) - IDirect3DCubeTexture9_Release(cube_texture); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + IDirect3DCubeTexture9_Release(cube_texture);
winetest_pop_context(); } @@ -2851,9 +2849,8 @@ static void test_D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *dev hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, dds_24bit_8_8, sizeof(dds_24bit_8_8), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, test_filter_values[i].filter, 0, NULL, NULL, &texture); - todo_wine_if(FAILED(hr)) ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - if (texture) - IDirect3DVolumeTexture9_Release(texture); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + IDirect3DVolumeTexture9_Release(texture);
winetest_pop_context(); } diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 1487258d96a..9ed83c184ae 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -562,6 +562,17 @@ static D3DFORMAT get_alpha_replacement_format(D3DFORMAT format) return format; }
+static uint32_t d3dx9_get_mip_filter_value(uint32_t mip_filter, uint32_t *skip_levels) +{ + uint32_t filter = (mip_filter == D3DX_DEFAULT) ? D3DX_FILTER_BOX : mip_filter & ~D3DX9_FILTER_INVALID_BITS; + + *skip_levels = mip_filter != D3DX_DEFAULT ? mip_filter >> D3DX_SKIP_DDS_MIP_LEVELS_SHIFT : 0; + *skip_levels &= D3DX_SKIP_DDS_MIP_LEVELS_MASK; + if (!(filter & 0x7) || (filter & 0x7) > D3DX_FILTER_BOX) + filter = (filter & 0x007f0000) | D3DX_FILTER_BOX; + return filter; +} + HRESULT WINAPI D3DXCreateTextureFromFileInMemoryEx(struct IDirect3DDevice9 *device, const void *srcdata, UINT srcdatasize, UINT width, UINT height, UINT miplevels, DWORD usage, D3DFORMAT format, D3DPOOL pool, DWORD filter, DWORD mipfilter, D3DCOLOR colorkey, D3DXIMAGE_INFO *srcinfo, @@ -587,8 +598,7 @@ HRESULT WINAPI D3DXCreateTextureFromFileInMemoryEx(struct IDirect3DDevice9 *devi return D3DERR_INVALIDCALL;
staging_tex = tex = *texture = NULL; - skip_levels = mipfilter != D3DX_DEFAULT ? mipfilter >> D3DX_SKIP_DDS_MIP_LEVELS_SHIFT : 0; - skip_levels &= D3DX_SKIP_DDS_MIP_LEVELS_MASK; + mipfilter = d3dx9_get_mip_filter_value(mipfilter, &skip_levels); hr = d3dx_image_init(srcdata, srcdatasize, &image, skip_levels, 0); if (FAILED(hr)) { @@ -1120,8 +1130,7 @@ HRESULT WINAPI D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *devic return D3DERR_INVALIDCALL;
staging_tex = tex = *volume_texture = NULL; - skip_levels = mip_filter != D3DX_DEFAULT ? mip_filter >> D3DX_SKIP_DDS_MIP_LEVELS_SHIFT : 0; - skip_levels &= D3DX_SKIP_DDS_MIP_LEVELS_MASK; + mip_filter = d3dx9_get_mip_filter_value(mip_filter, &skip_levels); hr = d3dx_image_init(data, data_size, &image, skip_levels, 0); if (FAILED(hr)) { @@ -1407,8 +1416,7 @@ HRESULT WINAPI D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device, return D3DERR_INVALIDCALL;
staging_tex = tex = *cube_texture = NULL; - skip_levels = mip_filter != D3DX_DEFAULT ? mip_filter >> D3DX_SKIP_DDS_MIP_LEVELS_SHIFT : 0; - skip_levels &= D3DX_SKIP_DDS_MIP_LEVELS_MASK; + mip_filter = d3dx9_get_mip_filter_value(mip_filter, &skip_levels); hr = d3dx_image_init(src_data, src_data_size, &image, skip_levels, 0); if (FAILED(hr)) {