Bitmap.c: Avoid calling GetProcessHeap so much

Not really a major functionality/performance change, it just makes me feel better.

git-svn-id: svn://vcs.sdm.2ki.xyz/Grabby/trunk@13 27729192-006e-004d-b9b5-06fbd0ef7001
This commit is contained in:
snow flurry 2024-02-15 05:55:27 +00:00
parent 7d1c91401f
commit dc07b5e612

View file

@ -63,7 +63,8 @@ GenerateBitmapInfo(Screen *scrn,
// GDI seems to modify the DWORD after the info header, even if we
// don't need a palette (>8 bit BMPs). Thus, an extra RGBQUAD just
// to be safe.
PFULLBMPHDR pBmpHdr = HeapAlloc(GetProcessHeap(),
HANDLE hHeap = GetProcessHeap();
PFULLBMPHDR pBmpHdr = HeapAlloc(hHeap,
HEAP_ZERO_MEMORY,
sizeof(struct _FULLBMPHDR) + sizeof(RGBQUAD));
RECT rcScrn = {0};
@ -73,6 +74,7 @@ GenerateBitmapInfo(Screen *scrn,
if (!pBmpHdr) return NULL;
if (!GetRgnBox(scrn->hScreenRgn, &rcScrn)) {
HeapFree(hHeap, 0, pBmpHdr);
return NULL;
}
@ -162,7 +164,8 @@ WriteRegionToFile(Screen *scrn,
LPTSTR fname)
{
BITMAP bmp = {0}; // hBitmap's metadata
HANDLE hOutFile = NULL; // Output .bmp
HANDLE hOutFile = NULL, // Output .bmp
hHeap = GetProcessHeap();
LPBYTE lpBits = NULL; // Actual bitmap bits
HDC hdcRgn = NULL; // HDC for defined region
@ -242,7 +245,7 @@ WriteRegionToFile(Screen *scrn,
goto cleanup;
}
lpBits = HeapAlloc(GetProcessHeap(),
lpBits = HeapAlloc(hHeap,
0,
pHdr->info.biSizeImage);
if (!lpBits) {
@ -251,7 +254,7 @@ WriteRegionToFile(Screen *scrn,
}
if (pHdr->info.biBitCount <= 8) {
pbmi = HeapAlloc(GetProcessHeap(),
pbmi = HeapAlloc(hHeap,
HEAP_ZERO_MEMORY,
sizeof(BITMAPINFOHEADER) +
(pHdr->info.biClrUsed * sizeof(RGBQUAD)));
@ -335,13 +338,13 @@ cleanup:
}
}
if (lpBits) HeapFree(GetProcessHeap(), 0, lpBits);
if (lpBits) HeapFree(hHeap, 0, lpBits);
// In case our bits are <= 8, pbmi will be an actual heap-alloc'd
// pointer. Let's make sure to handle that.
if (pbmi && pbmi != (PBITMAPINFO) &pHdr->info) HeapFree(GetProcessHeap(), 0, pbmi);
if (pbmi && pbmi != (PBITMAPINFO) &pHdr->info) HeapFree(hHeap, 0, pbmi);
if (pHdr) HeapFree(GetProcessHeap(), 0, pHdr);
if (pHdr) HeapFree(hHeap, 0, pHdr);
if (hOldObj) SelectObject(hdcRgn, hOldObj);
if (hRgnBitmap) DeleteObject(hRgnBitmap);