6#define MAX_ALPHABUF 1<<16
8BYTE CGdiAlpha::s_byAlphaBack[MAX_ALPHABUF];
10LPBYTE CGdiAlpha::ALPHABACKUP(BITMAP *pBitmap,
int x,
int y,
int cx,
int cy)
12 LPBYTE lpAlpha=s_byAlphaBack;
13 if(x+cx>=pBitmap->bmWidth) cx=pBitmap->bmWidth-x;
14 if(y+cy>=pBitmap->bmHeight) cy=pBitmap->bmHeight-y;
15 if(cx<0 || cy<0 ||pBitmap->bmBits==NULL)
return NULL;
17 if(cx*cy>MAX_ALPHABUF) lpAlpha=(LPBYTE)malloc(cx*cy);
19 for(
int iRow=0; iRow<cy; iRow++)
21 lpBits=(LPBYTE)pBitmap->bmBits+(y+iRow)*pBitmap->bmWidth*4+x*4;
23 for(
int iCol=0; iCol<cx; iCol++)
25 lpAlpha[iRow*cx+iCol]=*lpBits;
33void CGdiAlpha::ALPHARESTORE(BITMAP *pBitmap,
int x,
int y,
int cx,
int cy,LPBYTE lpAlpha)
35 if(x+cx>=pBitmap->bmWidth) cx=pBitmap->bmWidth-x;
36 if(y+cy>=pBitmap->bmHeight) cy=pBitmap->bmHeight-y;
37 if(cx<0 || cy<0)
return;
39 for(
int iRow=0; iRow<cy; iRow++)
41 lpBits=(LPBYTE)pBitmap->bmBits+(y+iRow)*pBitmap->bmWidth*4+x*4;
43 for(
int iCol=0; iCol<cx; iCol++)
45 *lpBits=lpAlpha[iRow*cx+iCol];
49 if(lpAlpha!=s_byAlphaBack) free(lpAlpha);
52BOOL CGdiAlpha::AlphaBackup(HDC hdc,LPCRECT pRect,ALPHAINFO &alphaInfo)
55 HBITMAP hBmp=(HBITMAP)GetCurrentObject(hdc,OBJ_BITMAP);
57 GetObject(hBmp,
sizeof(BITMAP),&alphaInfo.bm);
59 if(alphaInfo.bm.bmBitsPixel!=32)
return FALSE;
62 alphaInfo.rc.right ++;
63 alphaInfo.rc.bottom ++;
65 GetViewportOrgEx(hdc,&pt);
66 RECT rcImg= {0,0,alphaInfo.bm.bmWidth,alphaInfo.bm.bmHeight};
67 OffsetRect(&alphaInfo.rc,pt.x,pt.y);
68 IntersectRect(&alphaInfo.rc,&alphaInfo.rc,&rcImg);
69 alphaInfo.lpBuf=ALPHABACKUP(&alphaInfo.bm,alphaInfo.rc.left,alphaInfo.rc.top,alphaInfo.rc.right - alphaInfo.rc.left, alphaInfo.rc.bottom - alphaInfo.rc.top);
73void CGdiAlpha::AlphaRestore(ALPHAINFO &alphaInfo)
75 if(!alphaInfo.lpBuf)
return;
76 ALPHARESTORE(&alphaInfo.bm,alphaInfo.rc.left,alphaInfo.rc.top,alphaInfo.rc.right - alphaInfo.rc.left, alphaInfo.rc.bottom - alphaInfo.rc.top,alphaInfo.lpBuf);