MCPcopy Create free account
hub / github.com/DiscordMessenger/dm / GetDataFromBitmap

Function GetDataFromBitmap

src/windows/WinUtils.cpp:1274–1322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1272}
1273
1274bool GetDataFromBitmap(HDC hdc, HBITMAP hbm, BYTE*& pBytes, int& width, int& height, int& bpp)
1275{
1276 // Man what the hell
1277 BITMAP bm;
1278 BITMAPINFO bmi;
1279
1280 ZeroMemory(&bm, sizeof bm);
1281 if (!GetObject(hbm, sizeof bm, &bm)) {
1282 DbgPrintW("Cannot obtain pointer to bitmap!");
1283 return false;
1284 }
1285
1286 width = bm.bmWidth;
1287 height = bm.bmHeight;
1288 bpp = bm.bmBitsPixel;
1289
1290 ZeroMemory(&bmi, sizeof bmi);
1291 bmi.bmiHeader.biSize = sizeof bmi.bmiHeader;
1292 bmi.bmiHeader.biWidth = bm.bmWidth;
1293 bmi.bmiHeader.biHeight = bm.bmHeight;
1294 bmi.bmiHeader.biPlanes = 1;
1295 bmi.bmiHeader.biBitCount = bm.bmBitsPixel;
1296 bmi.bmiHeader.biCompression = BI_RGB;
1297 bmi.bmiHeader.biSizeImage = 0;
1298
1299 int pitch = (((bm.bmWidth * bm.bmBitsPixel) + 31) & ~31) >> 3;
1300
1301 pBytes = new BYTE[pitch * bm.bmHeight];
1302
1303 if (!GetDIBits(hdc, hbm, 0, bm.bmHeight, pBytes, &bmi, DIB_RGB_COLORS))
1304 {
1305 DbgPrintW("Error, can't get DI bits for bitmap!");
1306 delete[] pBytes;
1307 return false;
1308 }
1309
1310 // swap in software, because in Windows NT 3.1, using negative height images is glitchy
1311 for (int y1 = 0, y2 = bm.bmHeight - 1; y1 < y2; y1++, y2--)
1312 {
1313 BYTE *scan1 = &pBytes[y1 * pitch], *scan2 = &pBytes[y2 * pitch];
1314 DWORD *scan1D = (DWORD*) scan1, *scan2D = (DWORD*) scan2;
1315
1316 for (int x = 0; x * 4 < pitch; x++) {
1317 std::swap(scan1D[x], scan2D[x]);
1318 }
1319 }
1320
1321 return true;
1322}
1323
1324std::string CutOutURLPath(const std::string& url)
1325{

Callers 1

HandleCommandFunction · 0.85

Calls 2

DbgPrintWFunction · 0.85
swapFunction · 0.50

Tested by

no test coverage detected