comparison win/dw.c @ 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 4519a1d2525e
children 25b24bb098fd
comparison
equal deleted inserted replaced
959:37f2938ecd72 960:841b66d2d1b9
8869 } 8869 }
8870 8870
8871 pixmap->hdc = CreateCompatibleDC( hdc ); 8871 pixmap->hdc = CreateCompatibleDC( hdc );
8872 GetObject( pixmap->hbm, sizeof(bm), &bm ); 8872 GetObject( pixmap->hbm, sizeof(bm), &bm );
8873 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; 8873 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight;
8874 pixmap->depth = bm.bmBitsPixel;
8874 SelectObject( pixmap->hdc, pixmap->hbm ); 8875 SelectObject( pixmap->hdc, pixmap->hbm );
8875 ReleaseDC( handle, hdc ); 8876 ReleaseDC( handle, hdc );
8876 free( file ); 8877 free( file );
8877 pixmap->transcolor = DW_RGB_TRANSPARENT; 8878 pixmap->transcolor = DW_RGB_TRANSPARENT;
8878 8879
8941 pixmap->hdc = CreateCompatibleDC( hdc ); 8942 pixmap->hdc = CreateCompatibleDC( hdc );
8942 8943
8943 GetObject( pixmap->hbm, sizeof(bm), &bm ); 8944 GetObject( pixmap->hbm, sizeof(bm), &bm );
8944 8945
8945 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; 8946 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight;
8947 pixmap->depth = bm.bmBitsPixel;
8946 8948
8947 SelectObject( pixmap->hdc, pixmap->hbm ); 8949 SelectObject( pixmap->hdc, pixmap->hbm );
8948 8950
8949 ReleaseDC( handle, hdc ); 8951 ReleaseDC( handle, hdc );
8950 pixmap->transcolor = DW_RGB_TRANSPARENT; 8952 pixmap->transcolor = DW_RGB_TRANSPARENT;
8986 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) 8988 if (!(pixmap = calloc(1,sizeof(struct _hpixmap))))
8987 return NULL; 8989 return NULL;
8988 8990
8989 hdc = GetDC(handle); 8991 hdc = GetDC(handle);
8990 8992
8991
8992 pixmap->hbm = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); 8993 pixmap->hbm = LoadBitmap(DWInstance, MAKEINTRESOURCE(id));
8993 pixmap->hdc = CreateCompatibleDC(hdc); 8994 pixmap->hdc = CreateCompatibleDC(hdc);
8994 8995
8995 GetObject(pixmap->hbm, sizeof(BITMAP), (void *)&bm); 8996 GetObject(pixmap->hbm, sizeof(BITMAP), (void *)&bm);
8996 8997
8997 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; 8998 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight;
8999 pixmap->depth = bm.bmBitsPixel;
8998 9000
8999 SelectObject(pixmap->hdc, pixmap->hbm); 9001 SelectObject(pixmap->hdc, pixmap->hbm);
9000 9002
9001 ReleaseDC(handle, hdc); 9003 ReleaseDC(handle, hdc);
9004 pixmap->transcolor = DW_RGB_TRANSPARENT;
9002 9005
9003 return pixmap; 9006 return pixmap;
9004 } 9007 }
9005 9008
9006 /* 9009 /*
9036 void API dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc) 9039 void API dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc)
9037 { 9040 {
9038 HDC hdcdest; 9041 HDC hdcdest;
9039 HDC hdcsrc; 9042 HDC hdcsrc;
9040 HDC hdcMem; 9043 HDC hdcMem;
9044 static BLENDFUNCTION bf = { AC_SRC_OVER, 0, 0xFF, AC_SRC_ALPHA };
9041 9045
9042 if ( dest ) 9046 if ( dest )
9043 hdcdest = GetDC( dest ); 9047 hdcdest = GetDC( dest );
9044 else if ( destp ) 9048 else if ( destp )
9045 hdcdest = destp->hdc; 9049 hdcdest = destp->hdc;
9050 hdcsrc = GetDC( src ); 9054 hdcsrc = GetDC( src );
9051 else if ( srcp ) 9055 else if ( srcp )
9052 hdcsrc = srcp->hdc; 9056 hdcsrc = srcp->hdc;
9053 else 9057 else
9054 return; 9058 return;
9055 if ( srcp && srcp->transcolor != DW_RGB_TRANSPARENT ) 9059
9060 /* If it is a 32bpp bitmap (with alpha) use AlphaBlend unless it fails */
9061 if ( srcp && srcp->depth == 32 && AlphaBlend( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, width, height, bf ) )
9062 {
9063 /* Don't do anything */
9064 }
9065 /* Otherwise perform special bitblt with manual transparency */
9066 else if ( srcp && srcp->transcolor != DW_RGB_TRANSPARENT )
9056 { 9067 {
9057 DrawTransparentBitmap( hdcdest, srcp->hdc, srcp->hbm, xdest, ydest, RGB( DW_RED_VALUE(srcp->transcolor), DW_GREEN_VALUE(srcp->transcolor), DW_BLUE_VALUE(srcp->transcolor)) ); 9068 DrawTransparentBitmap( hdcdest, srcp->hdc, srcp->hbm, xdest, ydest, RGB( DW_RED_VALUE(srcp->transcolor), DW_GREEN_VALUE(srcp->transcolor), DW_BLUE_VALUE(srcp->transcolor)) );
9058 } 9069 }
9059 else 9070 else
9060 { 9071 {
9072 /* Finally fall back to the classic BitBlt */
9061 BitBlt( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, SRCCOPY ); 9073 BitBlt( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, SRCCOPY );
9062 } 9074 }
9063 if ( !destp ) 9075 if ( !destp )
9064 ReleaseDC( dest, hdcdest ); 9076 ReleaseDC( dest, hdcdest );
9065 if ( !srcp ) 9077 if ( !srcp )