VB Code:
Public Function Morph2D(X As Long, Y As Long, NumRow As Long) As Long
Morph2D = (Y - 1) * NumRow + X
End Function
Public Function Mask(Color As Long) As Boolean
Dim Co As mLong
Dim sBitmap As Long
Dim sBMP As BITMAP
Dim sPic() As mRGB
Dim sMem As BITMAPINFO
Dim mBitmap As Long
Dim mBMP As BITMAP
Dim mPic() As mRGB
Dim mMem As BITMAPINFO
Dim i As Long
Dim j As Long
sBitmap = GetCurrentObject(DCSprite, OBJ_BITMAP)
GetObjectAPI sBitmap, Len(sBMP), sBMP
With sMem.bmiHeader
.biBitCount = 32
.biCompression = BI_RGB
.biPlanes = 1
.biSize = Len(sMem.bmiHeader)
.biWidth = sBMP.bmWidth
.biHeight = sBMP.bmHeight
ReDim Preserve sPic(0 To (.biWidth * .biHeight) - 1) As mRGB
End With
GetDIBits DCSprite, sBitmap, 0, sBMP.bmHeight, sPic(0), sMem, DIB_RGB_COLORS
mBitmap = GetCurrentObject(DCMask, OBJ_BITMAP)
GetObjectAPI mBitmap, Len(mBMP), mBMP
With mMem.bmiHeader
.biBitCount = 32
.biCompression = BI_RGB
.biPlanes = 1
.biSize = Len(mMem.bmiHeader)
.biWidth = mBMP.bmWidth
.biHeight = mBMP.bmHeight
ReDim Preserve mPic(0 To (.biWidth * .biHeight) - 1) As mRGB
End With
GetDIBits DCMask, mBitmap, 0, mBMP.bmHeight, mPic(0), mMem, DIB_RGB_COLORS
Mask=false
If bValidSprite Then
For j = 0 To lSpriteHeight - 1
For i = 0 To lSpriteWidth - 1
LSet Co = sPic(Morph2D(i, lSpriteHeight - j, lSpriteWidth))
If Co.L = Color Then
Co.L = 0
Else
Co.L = RGB(255, 255, 255)
End If
LSet mPic(Morph2D(i, lSpriteHeight - j, lSpriteWidth)) = Co
Next i
Next j
bValidMask = True
Mask=true
SetDIBits DCMask, mBitmap, 0, mBMP.bmHeight, mPic(0), mMem, DIB_RGB_COLORS
End If
End Function
I'm still not sure how to do the cleanup in this code, but I'm sure it would be deleting the bitmaps and BMPs, etc. Here are the declarations:
VB Code:
Public Const BI_RGB = 0&
Public Const DIB_RGB_COLORS = 0
Public Type mLong
L As Long
End Type
Public Type mRGB
R As Byte
G As Byte
B As Byte
A As Byte
End Type
Public Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Public Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As mRGB
End Type
Public Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Public Declare Function SetDIBits Lib "gdi32" (ByVal hdc As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Public Declare Function GetCurrentObject Lib "gdi32" (ByVal hdc As Long, ByVal uObjectType As Long) As Long
Public Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long