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