comparison win/dw.c @ 1006:3e1c70896c13

Switched to using TransparentBlt() on Windows, and allow transparent bitblt for any depths below 32bpp. Also upped the Dynamic Windows version to 2.0.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 11 May 2011 05:12:34 +0000
parents 1b40686277df
children 3573878d1239
comparison
equal deleted inserted replaced
1005:751522e9f3ac 1006:3e1c70896c13
243 argv = _convertargs(&argc, lpCmdLine); 243 argv = _convertargs(&argc, lpCmdLine);
244 244
245 return main(argc, argv); 245 return main(argc, argv);
246 } 246 }
247 #endif 247 #endif
248
249 void DrawTransparentBitmap(HDC hdc, HDC hdcSrc, HBITMAP hBitmap, int xStart, int yStart, COLORREF cTransparentColor)
250 {
251 BITMAP bm;
252 COLORREF cColor;
253 HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave;
254 HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
255 HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
256 POINT ptSize;
257
258 #if 0
259 hdcTemp = CreateCompatibleDC(hdc);
260 SelectObject(hdcTemp, hBitmap); // Select the bitmap
261 #else
262 hdcTemp = hdcSrc;
263 #endif
264
265 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
266 ptSize.x = bm.bmWidth; // Get width of bitmap
267 ptSize.y = bm.bmHeight; // Get height of bitmap
268 DPtoLP(hdcTemp, &ptSize, 1); // Convert from device
269
270 // to logical points
271
272 // Create some DCs to hold temporary data.
273 hdcBack = CreateCompatibleDC(hdc);
274 hdcObject = CreateCompatibleDC(hdc);
275 hdcMem = CreateCompatibleDC(hdc);
276 hdcSave = CreateCompatibleDC(hdc);
277
278 // Create a bitmap for each DC. DCs are required for a number of
279 // GDI functions.
280
281 // Monochrome DC
282 bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
283
284 // Monochrome DC
285 bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
286
287 bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
288 bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
289
290 // Each DC must select a bitmap object to store pixel data.
291 bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack);
292 bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject);
293 bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem);
294 bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave);
295
296 // Set proper mapping mode.
297 SetMapMode(hdcTemp, GetMapMode(hdc));
298
299 // Save the bitmap sent here, because it will be overwritten.
300 BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);
301
302 // Set the background color of the source DC to the color.
303 // contained in the parts of the bitmap that should be transparent
304 cColor = SetBkColor(hdcTemp, cTransparentColor);
305
306 // Create the object mask for the bitmap by performing a BitBlt
307 // from the source bitmap to a monochrome bitmap.
308 BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);
309
310 // Set the background color of the source DC back to the original
311 // color.
312 SetBkColor(hdcTemp, cColor);
313
314 // Create the inverse of the object mask.
315 BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY);
316
317 // Copy the background of the main DC to the destination.
318 BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart, SRCCOPY);
319
320 // Mask out the places where the bitmap will be placed.
321 BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);
322
323 // Mask out the transparent colored pixels on the bitmap.
324 BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);
325
326 // XOR the bitmap with the background on the destination DC.
327 BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);
328
329 // Copy the destination to the screen.
330 BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0,
331 SRCCOPY);
332
333 // Place the original bitmap back into the bitmap sent here.
334 BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);
335
336 // Delete the memory bitmaps.
337 DeleteObject(SelectObject(hdcBack, bmBackOld));
338 DeleteObject(SelectObject(hdcObject, bmObjectOld));
339 DeleteObject(SelectObject(hdcMem, bmMemOld));
340 DeleteObject(SelectObject(hdcSave, bmSaveOld));
341
342 // Delete the memory DCs.
343 DeleteDC(hdcMem);
344 DeleteDC(hdcBack);
345 DeleteDC(hdcObject);
346 DeleteDC(hdcSave);
347 DeleteDC(hdcTemp);
348 }
349 248
350 DWORD GetDllVersion(LPCTSTR lpszDllName) 249 DWORD GetDllVersion(LPCTSTR lpszDllName)
351 { 250 {
352 251
353 HINSTANCE hinstDll; 252 HINSTANCE hinstDll;
8919 /* 8818 /*
8920 * Creates a bitmap mask for rendering bitmaps with transparent backgrounds 8819 * Creates a bitmap mask for rendering bitmaps with transparent backgrounds
8921 */ 8820 */
8922 void API dw_pixmap_set_transparent_color( HPIXMAP pixmap, ULONG color ) 8821 void API dw_pixmap_set_transparent_color( HPIXMAP pixmap, ULONG color )
8923 { 8822 {
8924 if ( pixmap && pixmap->depth == 8) 8823 if ( pixmap && pixmap->depth < 32)
8925 { 8824 {
8926 pixmap->transcolor = _internal_color(color); 8825 pixmap->transcolor = _internal_color(color);
8927 } 8826 }
8928 } 8827 }
8929 8828
8994 */ 8893 */
8995 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) 8894 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)
8996 { 8895 {
8997 HDC hdcdest; 8896 HDC hdcdest;
8998 HDC hdcsrc; 8897 HDC hdcsrc;
8999 HDC hdcMem;
9000 static BLENDFUNCTION bf = { AC_SRC_OVER, 0, 0xFF, AC_SRC_ALPHA }; 8898 static BLENDFUNCTION bf = { AC_SRC_OVER, 0, 0xFF, AC_SRC_ALPHA };
9001 8899
9002 if ( dest ) 8900 if ( dest )
9003 hdcdest = GetDC( dest ); 8901 hdcdest = GetDC( dest );
9004 else if ( destp ) 8902 else if ( destp )
9019 /* Don't do anything */ 8917 /* Don't do anything */
9020 } 8918 }
9021 /* Otherwise perform special bitblt with manual transparency */ 8919 /* Otherwise perform special bitblt with manual transparency */
9022 else if ( srcp && srcp->transcolor != DW_RGB_TRANSPARENT ) 8920 else if ( srcp && srcp->transcolor != DW_RGB_TRANSPARENT )
9023 { 8921 {
9024 DrawTransparentBitmap( hdcdest, srcp->hdc, srcp->hbm, xdest, ydest, RGB( DW_RED_VALUE(srcp->transcolor), DW_GREEN_VALUE(srcp->transcolor), DW_BLUE_VALUE(srcp->transcolor)) ); 8922 TransparentBlt( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, width, height, RGB( DW_RED_VALUE(srcp->transcolor), DW_GREEN_VALUE(srcp->transcolor), DW_BLUE_VALUE(srcp->transcolor)) );
9025 } 8923 }
9026 else 8924 else
9027 { 8925 {
9028 /* Finally fall back to the classic BitBlt */ 8926 /* Finally fall back to the classic BitBlt */
9029 BitBlt( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, SRCCOPY ); 8927 BitBlt( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, SRCCOPY );