MCPcopy Create free account
hub / github.com/NetHack/NetHack / _nhapply_image_transparent

Function _nhapply_image_transparent

win/win32/NetHackW.c:357–437  ·  view source on GitHub ↗

apply bitmap pointed by sourceDc transparently over bitmap pointed by hDC */

Source from the content-addressed store, hash-verified

355/* apply bitmap pointed by sourceDc transparently over
356bitmap pointed by hDC */
357BOOL WINAPI
358_nhapply_image_transparent(HDC hDC, int x, int y, int width, int height,
359 HDC sourceDC, int s_x, int s_y, int s_width,
360 int s_height, UINT cTransparent)
361{
362 /* Don't use TransparentBlt; According to Microsoft, it contains a memory
363 * leak in Window 95/98. */
364 HDC hdcMem, hdcBack, hdcObject, hdcSave;
365 COLORREF cColor;
366 HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave;
367 HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
368
369 /* Create some DCs to hold temporary data. */
370 hdcBack = CreateCompatibleDC(hDC);
371 hdcObject = CreateCompatibleDC(hDC);
372 hdcMem = CreateCompatibleDC(hDC);
373 hdcSave = CreateCompatibleDC(hDC);
374
375 /* this is bitmap for our pet image */
376 bmSave = CreateCompatibleBitmap(hDC, width, height);
377
378 /* Monochrome DC */
379 bmAndBack = CreateBitmap(width, height, 1, 1, NULL);
380 bmAndObject = CreateBitmap(width, height, 1, 1, NULL);
381
382 /* resulting bitmap */
383 bmAndMem = CreateCompatibleBitmap(hDC, width, height);
384
385 /* Each DC must select a bitmap object to store pixel data. */
386 bmBackOld = SelectObject(hdcBack, bmAndBack);
387 bmObjectOld = SelectObject(hdcObject, bmAndObject);
388 bmMemOld = SelectObject(hdcMem, bmAndMem);
389 bmSaveOld = SelectObject(hdcSave, bmSave);
390
391 /* copy source image because it is going to be overwritten */
392 StretchBlt(hdcSave, 0, 0, width, height, sourceDC, s_x, s_y, s_width,
393 s_height, SRCCOPY);
394
395 /* Set the background color of the source DC to the color.
396 contained in the parts of the bitmap that should be transparent */
397 cColor = SetBkColor(hdcSave, cTransparent);
398
399 /* Create the object mask for the bitmap by performing a BitBlt
400 from the source bitmap to a monochrome bitmap. */
401 BitBlt(hdcObject, 0, 0, width, height, hdcSave, 0, 0, SRCCOPY);
402
403 /* Set the background color of the source DC back to the original
404 color. */
405 SetBkColor(hdcSave, cColor);
406
407 /* Create the inverse of the object mask. */
408 BitBlt(hdcBack, 0, 0, width, height, hdcObject, 0, 0, NOTSRCCOPY);
409
410 /* Copy background to the resulting image */
411 BitBlt(hdcMem, 0, 0, width, height, hDC, x, y, SRCCOPY);
412
413 /* Mask out the places where the source image will be placed. */
414 BitBlt(hdcMem, 0, 0, width, height, hdcObject, 0, 0, SRCAND);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected