Code: Select all
Procedure CountColorsUsed(pBitmap)
GetObject_(pBitmap, SizeOf(BITMAP), @bmp.BITMAP)
*bmi.BITMAPINFO = AllocateMemory(SizeOf(BITMAPINFO)+SizeOf(RGBQUAD)*255)
With *bmi\bmiHeader
\biSize = SizeOf(BITMAPINFOHEADER)
\biWidth = bmp\bmWidth
\biHeight = bmp\bmHeight
\biPlanes = 1
\biBitCount = 32
EndWith
hDC = GetWindowDC_(#Null)
GetDIBits_(hDC, pBitmap, 0, bmp\bmHeight, #Null, *bmi, #DIB_RGB_COLORS)
Global *pPixels = AllocateMemory(*bmi\bmiHeader\biSizeImage)
iRes = GetDIBits_(hDC, pBitmap, 0, bmp\bmHeight, *pPixels, *bmi, #DIB_RGB_COLORS)
ReleaseDC_(#Null, hDC)
Global NewMap Colors(MemorySize(*pPixels)/2)
*p.long = *pPixels
For i=1 To MemorySize(*pPixels)/SizeOf(RGBQUAD)
Colors(Hex(*p\l)) = *p\l
*p+SizeOf(RGBQUAD)
Next
result = MapSize(colors())
ClearMap(colors())
FreeMemory(*pPixels)
FreeMemory(*bmi)
ProcedureReturn result
EndProcedure