@@ -25,10 +25,10 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect)
25
25
26
26
CGDirectDisplayID displayID = CGMainDisplayID ();
27
27
28
- //Replacement for CGDisplayBitsPerPixel.
28
+ //Replacement for CGDisplayBitsPerPixel.
29
29
CGDisplayModeRef mode = CGDisplayCopyDisplayMode (displayID );
30
30
size_t depth = 0 ;
31
-
31
+
32
32
CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding (mode );
33
33
if (CFStringCompare (pixEnc , CFSTR (IO32BitDirectPixels ), kCFCompareCaseInsensitive ) == kCFCompareEqualTo )
34
34
depth = 32 ;
@@ -37,7 +37,7 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect)
37
37
else if (CFStringCompare (pixEnc , CFSTR (IO8BitIndexedPixels ), kCFCompareCaseInsensitive ) == kCFCompareEqualTo )
38
38
depth = 8 ;
39
39
40
- bitsPerPixel = (uint8_t ) depth ;
40
+ bitsPerPixel = (uint8_t ) depth ;
41
41
bytesPerPixel = bitsPerPixel / 8 ;
42
42
/* Align width to padding. */
43
43
//bytewidth = ADD_PADDING(rect.size.width * bytesPerPixel);
@@ -52,15 +52,15 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect)
52
52
CGDataProviderRef provider = CGImageGetDataProvider (image );
53
53
CFDataRef data = CGDataProviderCopyData (provider );
54
54
55
- size_t width , height ;
55
+ size_t width , height ;
56
56
width = CGImageGetWidth (image );
57
- height = CGImageGetHeight (image );
57
+ height = CGImageGetHeight (image );
58
58
size_t bpp = CGImageGetBitsPerPixel (image ) / 8 ;
59
59
60
60
uint8 * pixels = malloc (width * height * bpp );
61
61
memcpy (pixels , CFDataGetBytePtr (data ), width * height * bpp );
62
- CFRelease (data );
63
- CGImageRelease (image );
62
+ CFRelease (data );
63
+ CGImageRelease (image );
64
64
65
65
return createMMBitmap (pixels , rect .size .width , rect .size .height , bytewidth ,
66
66
bitsPerPixel , bytesPerPixel );
@@ -118,11 +118,15 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect)
118
118
/* Copy the data into a bitmap struct. */
119
119
if ((screenMem = CreateCompatibleDC (screen )) == NULL ||
120
120
SelectObject (screenMem , dib ) == NULL ||
121
- !BitBlt (screenMem ,
122
- (int )rect . origin . x ,
123
- (int )rect . origin . y ,
121
+ !BitBlt (screenMem ,
122
+ (int )0 ,
123
+ (int )0 ,
124
124
(int )rect .size .width ,
125
- (int )rect .size .height , screen , 0 , 0 , SRCCOPY )) {
125
+ (int )rect .size .height ,
126
+ screen ,
127
+ rect .origin .x ,
128
+ rect .origin .y ,
129
+ SRCCOPY )) {
126
130
/* Error copying data. */
127
131
ReleaseDC (NULL , screen );
128
132
DeleteObject (dib );
@@ -135,7 +139,7 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect)
135
139
rect .size .width ,
136
140
rect .size .height ,
137
141
4 * rect .size .width ,
138
- (uint8_t )bi .bmiHeader .biBitCount ,
142
+ (uint8_t )bi .bmiHeader .biBitCount ,
139
143
4 );
140
144
141
145
/* Copy the data to our pixel buffer. */
0 commit comments