RT2301: GetDIBits, not GetBitmapBits in rand_win
GetDIBits has been around since Windows2000 and BitBitmapBits is an old Win16 compatibility function that is much slower. Reviewed-by: Tim Hudson <tjh@openssl.org> (cherry picked from commit 99b00fd99330afb0be46265c3e28f25f938d3221)
This commit is contained in:
parent
478b3470ff
commit
5015a93ded
@ -739,9 +739,7 @@ static void readscreen(void)
|
|||||||
{
|
{
|
||||||
#if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN)
|
#if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN)
|
||||||
HDC hScrDC; /* screen DC */
|
HDC hScrDC; /* screen DC */
|
||||||
HDC hMemDC; /* memory DC */
|
|
||||||
HBITMAP hBitmap; /* handle for our bitmap */
|
HBITMAP hBitmap; /* handle for our bitmap */
|
||||||
HBITMAP hOldBitmap; /* handle for previous bitmap */
|
|
||||||
BITMAP bm; /* bitmap properties */
|
BITMAP bm; /* bitmap properties */
|
||||||
unsigned int size; /* size of bitmap */
|
unsigned int size; /* size of bitmap */
|
||||||
char *bmbits; /* contents of bitmap */
|
char *bmbits; /* contents of bitmap */
|
||||||
@ -749,13 +747,13 @@ static void readscreen(void)
|
|||||||
int h; /* screen height */
|
int h; /* screen height */
|
||||||
int y; /* y-coordinate of screen lines to grab */
|
int y; /* y-coordinate of screen lines to grab */
|
||||||
int n = 16; /* number of screen lines to grab at a time */
|
int n = 16; /* number of screen lines to grab at a time */
|
||||||
|
BITMAPINFOHEADER bi; /* info about the bitmap */
|
||||||
|
|
||||||
if (check_winnt() && OPENSSL_isservice()>0)
|
if (check_winnt() && OPENSSL_isservice()>0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Create a screen DC and a memory DC compatible to screen DC */
|
/* Get a reference to the screen DC */
|
||||||
hScrDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
|
hScrDC = GetDC(NULL);
|
||||||
hMemDC = CreateCompatibleDC(hScrDC);
|
|
||||||
|
|
||||||
/* Get screen resolution */
|
/* Get screen resolution */
|
||||||
w = GetDeviceCaps(hScrDC, HORZRES);
|
w = GetDeviceCaps(hScrDC, HORZRES);
|
||||||
@ -764,13 +762,22 @@ static void readscreen(void)
|
|||||||
/* Create a bitmap compatible with the screen DC */
|
/* Create a bitmap compatible with the screen DC */
|
||||||
hBitmap = CreateCompatibleBitmap(hScrDC, w, n);
|
hBitmap = CreateCompatibleBitmap(hScrDC, w, n);
|
||||||
|
|
||||||
/* Select new bitmap into memory DC */
|
|
||||||
hOldBitmap = SelectObject(hMemDC, hBitmap);
|
|
||||||
|
|
||||||
/* Get bitmap properties */
|
/* Get bitmap properties */
|
||||||
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
|
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
|
||||||
size = (unsigned int)bm.bmWidthBytes * bm.bmHeight * bm.bmPlanes;
|
size = (unsigned int)bm.bmWidthBytes * bm.bmHeight * bm.bmPlanes;
|
||||||
|
|
||||||
|
bi.biSize = sizeof(BITMAPINFOHEADER);
|
||||||
|
bi.biWidth = bm.bmWidth;
|
||||||
|
bi.biHeight = bm.bmHeight;
|
||||||
|
bi.biPlanes = bm.bmPlanes;
|
||||||
|
bi.biBitCount = bm.bmBitsPixel;
|
||||||
|
bi.biCompression = BI_RGB;
|
||||||
|
bi.biSizeImage = 0;
|
||||||
|
bi.biXPelsPerMeter = 0;
|
||||||
|
bi.biYPelsPerMeter = 0;
|
||||||
|
bi.biClrUsed = 0;
|
||||||
|
bi.biClrImportant = 0;
|
||||||
|
|
||||||
bmbits = OPENSSL_malloc(size);
|
bmbits = OPENSSL_malloc(size);
|
||||||
if (bmbits) {
|
if (bmbits) {
|
||||||
/* Now go through the whole screen, repeatedly grabbing n lines */
|
/* Now go through the whole screen, repeatedly grabbing n lines */
|
||||||
@ -778,11 +785,9 @@ static void readscreen(void)
|
|||||||
{
|
{
|
||||||
unsigned char md[MD_DIGEST_LENGTH];
|
unsigned char md[MD_DIGEST_LENGTH];
|
||||||
|
|
||||||
/* Bitblt screen DC to memory DC */
|
/* Copy the bits of the current line range into the buffer */
|
||||||
BitBlt(hMemDC, 0, 0, w, n, hScrDC, 0, y, SRCCOPY);
|
GetDIBits(hScrDC, hBitmap, y, n,
|
||||||
|
bmbits, (BITMAPINFO *)&bi, DIB_RGB_COLORS);
|
||||||
/* Copy bitmap bits from memory DC to bmbits */
|
|
||||||
GetBitmapBits(hBitmap, size, bmbits);
|
|
||||||
|
|
||||||
/* Get the hash of the bitmap */
|
/* Get the hash of the bitmap */
|
||||||
MD(bmbits,size,md);
|
MD(bmbits,size,md);
|
||||||
@ -794,13 +799,9 @@ static void readscreen(void)
|
|||||||
OPENSSL_free(bmbits);
|
OPENSSL_free(bmbits);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Select old bitmap back into memory DC */
|
|
||||||
hBitmap = SelectObject(hMemDC, hOldBitmap);
|
|
||||||
|
|
||||||
/* Clean up */
|
/* Clean up */
|
||||||
DeleteObject(hBitmap);
|
DeleteObject(hBitmap);
|
||||||
DeleteDC(hMemDC);
|
ReleaseDC(NULL, hScrDC);
|
||||||
DeleteDC(hScrDC);
|
|
||||||
#endif /* !OPENSSL_SYS_WINCE */
|
#endif /* !OPENSSL_SYS_WINCE */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user