Module: wine Branch: master Commit: 77d0bd8267d3b4c862bba5e6bcc287b844798945 URL: https://gitlab.winehq.org/wine/wine/-/commit/77d0bd8267d3b4c862bba5e6bcc287b...
Author: Piotr Caban piotr@codeweavers.com Date: Wed Jul 13 15:33:01 2022 +0200
d3dx10: Use WIC functions to obtain info about DDS image.
---
dlls/d3dx10_43/texture.c | 96 ++++++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 40 deletions(-)
diff --git a/dlls/d3dx10_43/texture.c b/dlls/d3dx10_43/texture.c index fa7918a0778..a530bd6b7f0 100644 --- a/dlls/d3dx10_43/texture.c +++ b/dlls/d3dx10_43/texture.c @@ -71,17 +71,6 @@ wic_pixel_formats[] = { &GUID_WICPixelFormat128bppRGBAFloat, DXGI_FORMAT_R32G32B32A32_FLOAT } };
-static const DXGI_FORMAT block_compressed_formats[] = -{ - DXGI_FORMAT_BC1_TYPELESS, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM_SRGB, - DXGI_FORMAT_BC2_TYPELESS, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC2_UNORM_SRGB, - DXGI_FORMAT_BC3_TYPELESS, DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC3_UNORM_SRGB, - DXGI_FORMAT_BC4_TYPELESS, DXGI_FORMAT_BC4_UNORM, DXGI_FORMAT_BC4_SNORM, - DXGI_FORMAT_BC5_TYPELESS, DXGI_FORMAT_BC5_UNORM, DXGI_FORMAT_BC5_SNORM, - DXGI_FORMAT_BC6H_TYPELESS, DXGI_FORMAT_BC6H_UF16, DXGI_FORMAT_BC6H_SF16, - DXGI_FORMAT_BC7_TYPELESS, DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_BC7_UNORM_SRGB -}; - static const DXGI_FORMAT to_be_converted_format[] = { DXGI_FORMAT_UNKNOWN, @@ -135,17 +124,6 @@ static D3D10_RESOURCE_DIMENSION wic_dimension_to_d3dx10_dimension(WICDdsDimensio } }
-static BOOL is_block_compressed(DXGI_FORMAT format) -{ - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(block_compressed_formats); ++i) - if (format == block_compressed_formats[i]) - return TRUE; - - return FALSE; -} - static unsigned int get_bpp_from_format(DXGI_FORMAT format) { switch (format) @@ -876,32 +854,70 @@ HRESULT load_texture_data(const void *data, SIZE_T size, D3DX10_IMAGE_LOAD_INFO if (FAILED(hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame))) goto end;
- width = img_info.Width; - height = img_info.Height; - if (is_block_compressed(img_info.Format)) + if (img_info.ImageFileFormat == D3DX10_IFF_DDS) { - width = (width + 3) & ~3; - height = (height + 3) & ~3; - } - stride = (width * get_bpp_from_format(img_info.Format) + 7) / 8; - frame_size = stride * height; + WICDdsFormatInfo format_info;
- if (!(res_data = malloc(sizeof(**resource_data) + frame_size))) - { - hr = E_FAIL; - goto end; - } - buffer = res_data + sizeof(**resource_data); - - if (is_block_compressed(img_info.Format)) - { if (FAILED(hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICDdsFrameDecode, (void **)&dds_frame))) goto end; - if (FAILED(hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, NULL, stride * 4, frame_size, buffer))) + if (FAILED(hr = IWICDdsFrameDecode_GetFormatInfo(dds_frame, &format_info))) + goto end; + if (FAILED(hr = IWICDdsFrameDecode_GetSizeInBlocks(dds_frame, &width, &height))) + goto end; + + if (img_info.Format == format_info.DxgiFormat) + { + stride = width * format_info.BytesPerBlock; + frame_size = stride * height; + width *= format_info.BlockWidth; + height *= format_info.BlockHeight; + } + else + { + width *= format_info.BlockWidth; + height *= format_info.BlockHeight; + stride = (width * get_bpp_from_format(img_info.Format) + 7) / 8; + frame_size = stride * height; + } + + if (!(res_data = malloc(sizeof(**resource_data) + frame_size))) + { + hr = E_FAIL; goto end; + } + buffer = res_data + sizeof(**resource_data); + + if (img_info.Format == format_info.DxgiFormat) + { + if (FAILED(hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, NULL, stride, frame_size, buffer))) + goto end; + } + else + { + if (!(dst_format = dxgi_format_to_wic_guid(img_info.Format))) + { + hr = E_FAIL; + FIXME("Unsupported DXGI format %#x.\n", img_info.Format); + goto end; + } + if (FAILED(hr = convert_image(factory, frame, dst_format, stride, frame_size, buffer))) + goto end; + } } else { + width = img_info.Width; + height = img_info.Height; + stride = (width * get_bpp_from_format(img_info.Format) + 7) / 8; + frame_size = stride * height; + + if (!(res_data = malloc(sizeof(**resource_data) + frame_size))) + { + hr = E_FAIL; + goto end; + } + buffer = res_data + sizeof(**resource_data); + if (!(dst_format = dxgi_format_to_wic_guid(img_info.Format))) { hr = E_FAIL;