From 5572fc57ef6e60c69bc885f6fd2110c14a4f13cf Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 26 May 2010 15:39:17 +0200 Subject: [PATCH] comctl32/imagelist: Add support for 25% and 50% blending when using an alpha channel. --- dlls/comctl32/imagelist.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/dlls/comctl32/imagelist.c b/dlls/comctl32/imagelist.c index 11ff27fe8ff..7ca1fc96703 100644 --- a/dlls/comctl32/imagelist.c +++ b/dlls/comctl32/imagelist.c @@ -1157,7 +1157,8 @@ ImageList_DrawEx (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y, static BOOL alpha_blend_image( HIMAGELIST himl, HDC dest_dc, int dest_x, int dest_y, - int src_x, int src_y, int cx, int cy, BLENDFUNCTION func ) + int src_x, int src_y, int cx, int cy, BLENDFUNCTION func, + UINT style, COLORREF blend_col ) { BOOL ret = FALSE; HDC hdc; @@ -1184,6 +1185,30 @@ static BOOL alpha_blend_image( HIMAGELIST himl, HDC dest_dc, int dest_x, int des SelectObject( hdc, bmp ); BitBlt( hdc, 0, 0, cx, cy, himl->hdcImage, src_x, src_y, SRCCOPY ); + if (blend_col != CLR_NONE) + { + BYTE r = GetRValue( blend_col ); + BYTE g = GetGValue( blend_col ); + BYTE b = GetBValue( blend_col ); + + if (style & ILD_BLEND25) + { + for (i = 0, ptr = bits; i < cx * cy; i++, ptr++) + *ptr = ((*ptr & 0xff000000) | + ((((*ptr & 0x00ff0000) * 3 + (r << 16)) / 4) & 0x00ff0000) | + ((((*ptr & 0x0000ff00) * 3 + (g << 8)) / 4) & 0x0000ff00) | + ((((*ptr & 0x000000ff) * 3 + (b << 0)) / 4) & 0x000000ff)); + } + else if (style & ILD_BLEND50) + { + for (i = 0, ptr = bits; i < cx * cy; i++, ptr++) + *ptr = ((*ptr & 0xff000000) | + ((((*ptr & 0x00ff0000) + (r << 16)) / 2) & 0x00ff0000) | + ((((*ptr & 0x0000ff00) + (g << 8)) / 2) & 0x0000ff00) | + ((((*ptr & 0x000000ff) + (b << 0)) / 2) & 0x000000ff)); + } + } + if (himl->uBitsPixel == 32) /* we already have an alpha channel in this case */ { /* pre-multiply by the alpha channel */ @@ -1302,9 +1327,16 @@ ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp) has_alpha = (himl->has_alpha && himl->has_alpha[pimldp->i]); if (!bMask && (has_alpha || (fState & ILS_ALPHA))) { - COLORREF colour; + COLORREF colour, blend_col = CLR_NONE; BLENDFUNCTION func; + if (bBlend) + { + blend_col = pimldp->rgbFg; + if (blend_col == CLR_DEFAULT) blend_col = GetSysColor( COLOR_HIGHLIGHT ); + else if (blend_col == CLR_NONE) blend_col = GetTextColor( pimldp->hdcDst ); + } + func.BlendOp = AC_SRC_OVER; func.BlendFlags = 0; func.SourceConstantAlpha = (fState & ILS_ALPHA) ? pimldp->Frame : 255; @@ -1313,7 +1345,7 @@ ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp) if (bIsTransparent) { bResult = alpha_blend_image( himl, pimldp->hdcDst, pimldp->x, pimldp->y, - pt.x, pt.y, cx, cy, func ); + pt.x, pt.y, cx, cy, func, fStyle, blend_col ); goto end; } colour = pimldp->rgbBk; @@ -1322,7 +1354,7 @@ ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp) hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour)); PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY ); - alpha_blend_image( himl, hImageDC, 0, 0, pt.x, pt.y, cx, cy, func ); + alpha_blend_image( himl, hImageDC, 0, 0, pt.x, pt.y, cx, cy, func, fStyle, blend_col ); DeleteObject (SelectObject (hImageDC, hOldBrush)); bResult = BitBlt( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCCOPY ); goto end; -- 2.11.4.GIT