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

commit ad319ef944e38829efcdca3d6a8d778fffbe61e4
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Mon Dec 23 19:43:20 2019 +0900
Commit:     GitHub <[email protected]>
CommitDate: Mon Dec 23 19:43:20 2019 +0900

    [SHIMGVW] Image Viewer transparent image fix (#2165)
    
    If the pixel is transparent or translucent, fill the background with a 
checkered pattern. CORE-15287
---
 dll/win32/shimgvw/shimgvw.c | 42 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/dll/win32/shimgvw/shimgvw.c b/dll/win32/shimgvw/shimgvw.c
index 46553b3e23f..7f2d0393a71 100644
--- a/dll/win32/shimgvw/shimgvw.c
+++ b/dll/win32/shimgvw/shimgvw.c
@@ -580,6 +580,26 @@ ImageView_UpdateWindow(HWND hwnd)
     UpdateWindow(hwnd);
 }
 
+static HBRUSH CreateCheckerBoardBrush(HDC hdc)
+{
+    static const CHAR pattern[] =
+        
"\x28\x00\x00\x00\x10\x00\x00\x00\x10\x00\x00\x00\x01\x00\x04\x00\x00\x00"
+        
"\x00\x00\x80\x00\x00\x00\x23\x2E\x00\x00\x23\x2E\x00\x00\x10\x00\x00\x00"
+        
"\x00\x00\x00\x00\x99\x99\x99\x00\xCC\xCC\xCC\x00\x00\x00\x00\x00\x00\x00"
+        
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+        
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+        
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x11\x11\x11"
+        
"\x00\x00\x00\x00\x11\x11\x11\x11\x00\x00\x00\x00\x11\x11\x11\x11\x00\x00"
+        
"\x00\x00\x11\x11\x11\x11\x00\x00\x00\x00\x11\x11\x11\x11\x00\x00\x00\x00"
+        
"\x11\x11\x11\x11\x00\x00\x00\x00\x11\x11\x11\x11\x00\x00\x00\x00\x11\x11"
+        
"\x11\x11\x00\x00\x00\x00\x00\x00\x00\x00\x11\x11\x11\x11\x00\x00\x00\x00"
+        
"\x11\x11\x11\x11\x00\x00\x00\x00\x11\x11\x11\x11\x00\x00\x00\x00\x11\x11"
+        
"\x11\x11\x00\x00\x00\x00\x11\x11\x11\x11\x00\x00\x00\x00\x11\x11\x11\x11"
+        "\x00\x00\x00\x00\x11\x11\x11\x11\x00\x00\x00\x00\x11\x11\x11\x11";
+
+    return CreateDIBPatternBrushPt(pattern, DIB_RGB_COLORS);
+}
+
 static VOID
 ImageView_DrawImage(HWND hwnd)
 {
@@ -591,6 +611,7 @@ ImageView_DrawImage(HWND hwnd)
     HDC hdc;
     HBRUSH white;
     HGDIOBJ hbrOld;
+    UINT uFlags;
 
     hdc = BeginPaint(hwnd, &ps);
     if (!hdc)
@@ -652,9 +673,24 @@ ImageView_DrawImage(HWND hwnd)
             GdipSetSmoothingMode(graphics, SmoothingModeHighQuality);
         }
 
-        hbrOld = SelectObject(hdc, GetStockObject(NULL_BRUSH));
-        Rectangle(hdc, x - 1, y - 1, x + ZoomedWidth + 1, y + ZoomedHeight + 
1);
-        SelectObject(hdc, hbrOld);
+        uFlags = 0;
+        GdipGetImageFlags(image, &uFlags);
+
+        if (uFlags & (ImageFlagsHasAlpha | ImageFlagsHasTranslucent))
+        {
+            HBRUSH hbr = CreateCheckerBoardBrush(hdc);
+            hbrOld = SelectObject(hdc, hbr);
+            Rectangle(hdc, x - 1, y - 1, x + ZoomedWidth + 1, y + ZoomedHeight 
+ 1);
+            SelectObject(hdc, hbrOld);
+            DeleteObject(hbr);
+        }
+        else
+        {
+            hbrOld = SelectObject(hdc, GetStockObject(NULL_BRUSH));
+            Rectangle(hdc, x - 1, y - 1, x + ZoomedWidth + 1, y + ZoomedHeight 
+ 1);
+            SelectObject(hdc, hbrOld);
+        }
+
         GdipDrawImageRectI(graphics, image, x, y, ZoomedWidth, ZoomedHeight);
     }
     GdipDeleteGraphics(graphics);

Reply via email to