[SHIMGVW] Image Viewer transparent image fix (#2165)

If the pixel is transparent or translucent, fill the background with a checkered pattern. CORE-15287
This commit is contained in:
Katayama Hirofumi MZ 2019-12-23 19:43:20 +09:00 committed by GitHub
parent 12c683a846
commit ad319ef944
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);