CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData, FX_BOOL bAlpha) { int width = pbmi->bmiHeader.biWidth; int height = pbmi->bmiHeader.biHeight; BOOL bBottomUp = TRUE; if (height < 0) { height = -height; bBottomUp = FALSE; } int pitch = (width * pbmi->bmiHeader.biBitCount + 31) / 32 * 4; CFX_DIBitmap* pBitmap = FX_NEW CFX_DIBitmap; if (!pBitmap) { return NULL; } FXDIB_Format format = bAlpha ? (FXDIB_Format)(pbmi->bmiHeader.biBitCount + 0x200) : (FXDIB_Format)pbmi->bmiHeader.biBitCount; FX_BOOL ret = pBitmap->Create(width, height, format); if (!ret) { delete pBitmap; return NULL; } FXSYS_memcpy32(pBitmap->GetBuffer(), pData, pitch * height); if (bBottomUp) { FX_LPBYTE temp_buf = FX_Alloc(FX_BYTE, pitch); if (!temp_buf) { if (pBitmap) { delete pBitmap; } return NULL; } int top = 0, bottom = height - 1; while (top < bottom) { FXSYS_memcpy32(temp_buf, pBitmap->GetBuffer() + top * pitch, pitch); FXSYS_memcpy32(pBitmap->GetBuffer() + top * pitch, pBitmap->GetBuffer() + bottom * pitch, pitch); FXSYS_memcpy32(pBitmap->GetBuffer() + bottom * pitch, temp_buf, pitch); top ++; bottom --; } FX_Free(temp_buf); temp_buf = NULL; } if (pbmi->bmiHeader.biBitCount == 1) { for (int i = 0; i < 2; i ++) { pBitmap->SetPaletteEntry(i, ((FX_DWORD*)pbmi->bmiColors)[i] | 0xff000000); } } else if (pbmi->bmiHeader.biBitCount == 8) { for (int i = 0; i < 256; i ++) { pBitmap->SetPaletteEntry(i, ((FX_DWORD*)pbmi->bmiColors)[i] | 0xff000000); } } return pBitmap; }