From 1934220f501a03b984e238ffa1f7f06a289695fc Mon Sep 17 00:00:00 2001 From: vcaesar Date: Thu, 23 Jun 2022 21:11:41 -0700 Subject: [PATCH] Fixed Windows bitmap copy #501 --- base/MMBitmap.h | 1 + screen/screengrab_c.h | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/base/MMBitmap.h b/base/MMBitmap.h index b652a2d..85b4a2e 100644 --- a/base/MMBitmap.h +++ b/base/MMBitmap.h @@ -11,6 +11,7 @@ struct _MMBitmap { uint8_t *imageBuffer; /* Pixels stored in Quad I format; */ int32_t width; /* Never 0, unless image is NULL. */ int32_t height; /* Never 0, unless image is NULL. */ + int32_t bytewidth; /* The aligned width (width + padding). */ uint8_t bitsPerPixel; /* Should be either 24 or 32. */ uint8_t bytesPerPixel; /* For convenience; should be bitsPerPixel / 8. */ diff --git a/screen/screengrab_c.h b/screen/screengrab_c.h index 470d386..1118391 100644 --- a/screen/screengrab_c.h +++ b/screen/screengrab_c.h @@ -98,10 +98,11 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect, int32_t display_id) dib = CreateDIBSection(screen, &bi, DIB_RGB_COLORS, &data, NULL, 0); /* Copy the data into a bitmap struct. */ - BOOL smem = (screenMem = CreateCompatibleDC(screen)) == NULL; - BOOL bitb = BitBlt(screenMem, (int)0, (int)0, (int)rect.size.w, (int)rect.size.h, + BOOL b = (screenMem = CreateCompatibleDC(screen)) == NULL || + SelectObject(screenMem, dib) == NULL || + !BitBlt(screenMem, (int)0, (int)0, (int)rect.size.w, (int)rect.size.h, screen, rect.origin.x, rect.origin.y, SRCCOPY); - if (smem || SelectObject(screenMem, dib) == NULL || !bitb) { + if (b) { /* Error copying data. */ ReleaseDC(hwnd, screen); DeleteObject(dib);