https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7a64c4dcc939403cce50fc31d475619a724d3609

commit 7a64c4dcc939403cce50fc31d475619a724d3609
Author:     winesync <[email protected]>
AuthorDate: Tue Jan 5 13:16:40 2021 +0100
Commit:     Jérôme Gardou <[email protected]>
CommitDate: Thu Feb 4 16:37:07 2021 +0100

    [WINESYNC] d3dx9: Return D3DFMT_A8R8G8B8 in 
D3DXGetImageInfoFromFileInMemory for 32 bpp BMP with alpha.
    
    wine-staging patch by Christian Costa <[email protected]>
---
 dll/directx/wine/d3dx9_36/surface.c                | 18 ++++++++++
 modules/rostests/winetests/d3dx9_36/surface.c      |  2 +-
 ...FromFileInMemory_for_32_bpp_BMP_with_alpha.diff | 42 ++++++++++++++++++++++
 3 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/dll/directx/wine/d3dx9_36/surface.c 
b/dll/directx/wine/d3dx9_36/surface.c
index 0deca8c01a0..30d04684044 100644
--- a/dll/directx/wine/d3dx9_36/surface.c
+++ b/dll/directx/wine/d3dx9_36/surface.c
@@ -1010,6 +1010,24 @@ HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const 
void *data, UINT datasize,
                 }
             }
 
+            /* For 32 bpp BMP, windowscodecs.dll never returns a format with 
alpha while
+             * d3dx9_xx.dll returns one if at least 1 pixel has a non zero 
alpha component */
+            if (SUCCEEDED(hr) && (info->Format == D3DFMT_X8R8G8B8) && 
(info->ImageFileFormat == D3DXIFF_BMP)) {
+                DWORD size = sizeof(DWORD) * info->Width * info->Height;
+                BYTE *buffer = HeapAlloc(GetProcessHeap(), 0, size);
+                hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, 
sizeof(DWORD) * info->Width, size, buffer);
+                if (SUCCEEDED(hr)) {
+                    DWORD i;
+                    for (i = 0; i < info->Width * info->Height; i++) {
+                        if (buffer[i*4+3]) {
+                            info->Format = D3DFMT_A8R8G8B8;
+                            break;
+                        }
+                    }
+                }
+                HeapFree(GetProcessHeap(), 0, buffer);
+            }
+
             if (frame)
                  IWICBitmapFrameDecode_Release(frame);
 
diff --git a/modules/rostests/winetests/d3dx9_36/surface.c 
b/modules/rostests/winetests/d3dx9_36/surface.c
index 4590a758d78..1d32b68c3a6 100644
--- a/modules/rostests/winetests/d3dx9_36/surface.c
+++ b/modules/rostests/winetests/d3dx9_36/surface.c
@@ -698,7 +698,7 @@ static void test_D3DXGetImageInfo(void)
     ok(info.Format == D3DFMT_X8R8G8B8, "Got unexpected format %u.\n", 
info.Format);
     hr = D3DXGetImageInfoFromFileInMemory(bmp_32bpp_argb, 
sizeof(bmp_32bpp_argb), &info);
     ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
-    todo_wine ok(info.Format == D3DFMT_A8R8G8B8, "Got unexpected format 
%u.\n", info.Format);
+    ok(info.Format == D3DFMT_A8R8G8B8, "Got unexpected format %u.\n", 
info.Format);
 
     /* Grayscale PNG */
     hr = D3DXGetImageInfoFromFileInMemory(png_grayscale, 
sizeof(png_grayscale), &info);
diff --git 
a/sdk/tools/winesync/d3dx9_staging/0001-d3dx9__Return_D3DFMT_A8R8G8B8_in_D3DXGetImageInfoFromFileInMemory_for_32_bpp_BMP_with_alpha.diff
 
b/sdk/tools/winesync/d3dx9_staging/0001-d3dx9__Return_D3DFMT_A8R8G8B8_in_D3DXGetImageInfoFromFileInMemory_for_32_bpp_BMP_with_alpha.diff
new file mode 100644
index 00000000000..0370cad886e
--- /dev/null
+++ 
b/sdk/tools/winesync/d3dx9_staging/0001-d3dx9__Return_D3DFMT_A8R8G8B8_in_D3DXGetImageInfoFromFileInMemory_for_32_bpp_BMP_with_alpha.diff
@@ -0,0 +1,42 @@
+diff --git a/dll/directx/wine/d3dx9_36/surface.c 
b/dll/directx/wine/d3dx9_36/surface.c
+index 045d726..ebec81f 100644
+--- a/dll/directx/wine/d3dx9_36/surface.c
++++ b/dll/directx/wine/d3dx9_36/surface.c
+@@ -1006,6 +1006,24 @@ HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const 
void *data, UINT datasize,
+                 }
+             }
+ 
++            /* For 32 bpp BMP, windowscodecs.dll never returns a format with 
alpha while
++             * d3dx9_xx.dll returns one if at least 1 pixel has a non zero 
alpha component */
++            if (SUCCEEDED(hr) && (info->Format == D3DFMT_X8R8G8B8) && 
(info->ImageFileFormat == D3DXIFF_BMP)) {
++                DWORD size = sizeof(DWORD) * info->Width * info->Height;
++                BYTE *buffer = HeapAlloc(GetProcessHeap(), 0, size);
++                hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, 
sizeof(DWORD) * info->Width, size, buffer);
++                if (SUCCEEDED(hr)) {
++                    DWORD i;
++                    for (i = 0; i < info->Width * info->Height; i++) {
++                        if (buffer[i*4+3]) {
++                            info->Format = D3DFMT_A8R8G8B8;
++                            break;
++                        }
++                    }
++                }
++                HeapFree(GetProcessHeap(), 0, buffer);
++            }
++
+             if (frame)
+                  IWICBitmapFrameDecode_Release(frame);
+ 
+diff --git a/modules/rostests/winetests/d3dx9_36/surface.c 
b/modules/rostests/winetests/d3dx9_36/surface.c
+index 4590a75..1d32b68 100644
+--- a/modules/rostests/winetests/d3dx9_36/surface.c
++++ b/modules/rostests/winetests/d3dx9_36/surface.c
+@@ -698,7 +698,7 @@ static void test_D3DXGetImageInfo(void)
+     ok(info.Format == D3DFMT_X8R8G8B8, "Got unexpected format %u.\n", 
info.Format);
+     hr = D3DXGetImageInfoFromFileInMemory(bmp_32bpp_argb, 
sizeof(bmp_32bpp_argb), &info);
+     ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+-    todo_wine ok(info.Format == D3DFMT_A8R8G8B8, "Got unexpected format 
%u.\n", info.Format);
++    ok(info.Format == D3DFMT_A8R8G8B8, "Got unexpected format %u.\n", 
info.Format);
+ 
+     /* Grayscale PNG */
+     hr = D3DXGetImageInfoFromFileInMemory(png_grayscale, 
sizeof(png_grayscale), &info);

Reply via email to