Skip to content

Commit

Permalink
getPixelColor bug fix.
Browse files Browse the repository at this point in the history
This should make this work.
  • Loading branch information
Deltatiger committed Jul 24, 2015
1 parent a511724 commit 20c9a19
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/screengrab.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect)

CGDirectDisplayID displayID = CGMainDisplayID();

//Replacement for CGDisplayBitsPerPixel.
//Replacement for CGDisplayBitsPerPixel.
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayID);
size_t depth = 0;

CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(mode);
if(CFStringCompare(pixEnc, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
depth = 32;
Expand All @@ -37,7 +37,7 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect)
else if(CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
depth = 8;

bitsPerPixel = (uint8_t) depth;
bitsPerPixel = (uint8_t) depth;
bytesPerPixel = bitsPerPixel / 8;
/* Align width to padding. */
//bytewidth = ADD_PADDING(rect.size.width * bytesPerPixel);
Expand All @@ -52,15 +52,15 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect)
CGDataProviderRef provider = CGImageGetDataProvider(image);
CFDataRef data = CGDataProviderCopyData(provider);

size_t width, height;
size_t width, height;
width = CGImageGetWidth(image);
height = CGImageGetHeight(image);
height = CGImageGetHeight(image);
size_t bpp = CGImageGetBitsPerPixel(image) / 8;

uint8 *pixels = malloc(width * height * bpp);
memcpy(pixels, CFDataGetBytePtr(data), width * height * bpp);
CFRelease(data);
CGImageRelease(image);
CFRelease(data);
CGImageRelease(image);

return createMMBitmap(pixels, rect.size.width, rect.size.height, bytewidth,
bitsPerPixel, bytesPerPixel);
Expand Down Expand Up @@ -118,11 +118,15 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect)
/* Copy the data into a bitmap struct. */
if ((screenMem = CreateCompatibleDC(screen)) == NULL ||
SelectObject(screenMem, dib) == NULL ||
!BitBlt(screenMem,
(int)rect.origin.x,
(int)rect.origin.y,
!BitBlt(screenMem,
(int)0,
(int)0,
(int)rect.size.width,
(int)rect.size.height, screen, 0, 0, SRCCOPY)) {
(int)rect.size.height,
screen,
rect.origin.x,
rect.origin.y,
SRCCOPY)) {
/* Error copying data. */
ReleaseDC(NULL, screen);
DeleteObject(dib);
Expand All @@ -135,7 +139,7 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect)
rect.size.width,
rect.size.height,
4 * rect.size.width,
(uint8_t)bi.bmiHeader.biBitCount,
(uint8_t)bi.bmiHeader.biBitCount,
4);

/* Copy the data to our pixel buffer. */
Expand Down

1 comment on commit 20c9a19

@octalmage
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's up?

Please sign in to comment.