changeset 960:841b66d2d1b9

Added initial support for transparent pixmap/bitmaps on Windows... without using dw_pixmap_set_transparent_color() using AlphaBlend().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 02 May 2011 14:18:47 +0000
parents 37f2938ecd72
children 25b24bb098fd
files dw.h image/test.bmp makefile.vc win/dw.c
diffstat 4 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Mon May 02 05:39:37 2011 +0000
+++ b/dw.h	Mon May 02 14:18:47 2011 +0000
@@ -636,6 +636,7 @@
    unsigned long transcolor;
    HWND handle;
    void *bits;
+   unsigned long depth;
 } *HPIXMAP;
 
 typedef HWND HMENUI;
Binary file image/test.bmp has changed
--- a/makefile.vc	Mon May 02 05:39:37 2011 +0000
+++ b/makefile.vc	Mon May 02 14:18:47 2011 +0000
@@ -48,7 +48,7 @@
 
 CC = cl
 CFLAGS = -c $(PLATFORM_DEF) -D__WIN32__ -DMSVC -DBUILD_DLL -I$(SRCDIR)\platform -I$(SRCDIR)
-LIBS = wsock32.lib kernel32.lib user32.lib comctl32.lib gdi32.lib advapi32.lib shell32.lib comdlg32.lib ole32.lib oleaut32.lib userenv.lib
+LIBS = wsock32.lib kernel32.lib user32.lib comctl32.lib gdi32.lib advapi32.lib shell32.lib comdlg32.lib ole32.lib oleaut32.lib userenv.lib msimg32.lib
 RES =
 LINKFLAGS = -machine:$(TARGET_CPU) -manifest $(LINK_DEBUG)
 DLLLINKFLAGS = -dll
--- a/win/dw.c	Mon May 02 05:39:37 2011 +0000
+++ b/win/dw.c	Mon May 02 14:18:47 2011 +0000
@@ -8871,6 +8871,7 @@
    pixmap->hdc = CreateCompatibleDC( hdc );
    GetObject( pixmap->hbm, sizeof(bm), &bm );
    pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight;
+   pixmap->depth = bm.bmBitsPixel;
    SelectObject( pixmap->hdc, pixmap->hbm );
    ReleaseDC( handle, hdc );
    free( file );
@@ -8943,6 +8944,7 @@
    GetObject( pixmap->hbm, sizeof(bm), &bm );
 
    pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight;
+   pixmap->depth = bm.bmBitsPixel;
 
    SelectObject( pixmap->hdc, pixmap->hbm );
 
@@ -8988,17 +8990,18 @@
 
    hdc = GetDC(handle);
 
-
    pixmap->hbm = LoadBitmap(DWInstance, MAKEINTRESOURCE(id));
    pixmap->hdc = CreateCompatibleDC(hdc);
 
    GetObject(pixmap->hbm, sizeof(BITMAP), (void *)&bm);
 
    pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight;
+   pixmap->depth = bm.bmBitsPixel;
 
    SelectObject(pixmap->hdc, pixmap->hbm);
 
    ReleaseDC(handle, hdc);
+   pixmap->transcolor = DW_RGB_TRANSPARENT;
 
    return pixmap;
 }
@@ -9038,6 +9041,7 @@
    HDC hdcdest;
    HDC hdcsrc;
    HDC hdcMem;
+   static BLENDFUNCTION bf = { AC_SRC_OVER, 0, 0xFF, AC_SRC_ALPHA };
 
    if ( dest )
       hdcdest = GetDC( dest );
@@ -9052,12 +9056,20 @@
       hdcsrc = srcp->hdc;
    else
       return;
-   if ( srcp && srcp->transcolor != DW_RGB_TRANSPARENT )
+
+   /* If it is a 32bpp bitmap (with alpha) use AlphaBlend unless it fails */
+   if ( srcp && srcp->depth == 32 && AlphaBlend( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, width, height, bf ) )
+   {
+        /* Don't do anything */
+   }
+   /* Otherwise perform special bitblt with manual transparency */
+   else if ( srcp && srcp->transcolor != DW_RGB_TRANSPARENT )
    {
       DrawTransparentBitmap( hdcdest, srcp->hdc, srcp->hbm, xdest, ydest, RGB( DW_RED_VALUE(srcp->transcolor), DW_GREEN_VALUE(srcp->transcolor), DW_BLUE_VALUE(srcp->transcolor)) );
    }
    else
    {
+      /* Finally fall back to the classic BitBlt */
       BitBlt( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, SRCCOPY );
    }
    if ( !destp )