Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6768994

Browse files
committed
Prefer use of monitor's vars
1 parent 268a563 commit 6768994

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

mss/darwin.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ def enum_display_monitors(self, force=False):
141141
def get_pixels(self, monitor):
142142
''' Retrieve all pixels from a monitor. Pixels have to be RGB. '''
143143

144-
width, height = monitor['width'], monitor['height']
145-
left, top = monitor['left'], monitor['top']
146-
rect = CGRect((left, top), (width, height))
144+
rect = CGRect((monitor['left'], monitor['top']),
145+
(monitor['width'], monitor['height']))
147146

148147
image_ref = self.core.CGWindowListCreateImage(rect, 1, 0, 0)
149148
if not image_ref:
@@ -155,7 +154,7 @@ def get_pixels(self, monitor):
155154
prov = self.core.CGImageGetDataProvider(image_ref)
156155
data = self.core.CGDataProviderCopyData(prov)
157156
data_ref = self.core.CFDataGetBytePtr(data)
158-
buf_len = self.height * self.width * 4 # or CFDataGetLength()
157+
buf_len = self.width * self.height * 4
159158
data = cast(data_ref, POINTER(c_ubyte * buf_len))
160159
self.core.CGDataProviderRelease(prov)
161160
self.image = self.bgra_to_rgb(bytearray(data.contents))

mss/linux.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,8 @@ def get_pixels(self, monitor):
227227

228228
ximage = self.xlib.XGetImage(self.display, root,
229229
monitor['left'], monitor['top'],
230-
self.width, self.height,
231-
0x00ffffff,
232-
2) # ZPIXMAP
230+
monitor['width'], monitor['height'],
231+
0x00ffffff, 2) # ZPIXMAP
233232
if not ximage:
234233
err = 'xlib.XGetImage() failed. Monitor informations: '
235234
for key, val in sorted(monitor.items()):

mss/windows.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,28 +128,30 @@ def get_pixels(self, monitor):
128128
try:
129129
bmi = BITMAPINFO()
130130
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER)
131-
bmi.bmiHeader.biWidth = self.width
132-
bmi.bmiHeader.biHeight = -self.height # Why minux? See [1]
131+
bmi.bmiHeader.biWidth = monitor['width']
132+
bmi.bmiHeader.biHeight = -monitor['height'] # Why minus? See [1]
133133
bmi.bmiHeader.biPlanes = 1 # Always 1
134134
bmi.bmiHeader.biBitCount = 32 # See [2]
135135
bmi.bmiHeader.biCompression = 0 # 0 = BI_RGB (no compression)
136136
bmi.bmiHeader.biClrUsed = 0 # See [3]
137137
bmi.bmiHeader.biClrImportant = 0 # See [3]
138138

139-
buf_len = self.height * self.width * 4 # See [2]
139+
buf_len = monitor['width'] * monitor['height'] * 4 # See [2]
140140
image_data = create_string_buffer(buf_len)
141141
srcdc = windll.user32.GetWindowDC(0)
142142
memdc = windll.gdi32.CreateCompatibleDC(srcdc)
143-
bmp = windll.gdi32.CreateCompatibleBitmap(srcdc, self.width,
144-
self.height)
143+
bmp = windll.gdi32.CreateCompatibleBitmap(
144+
srcdc, monitor['width'], monitor['height'])
145+
145146
windll.gdi32.SelectObject(memdc, bmp)
146147
windll.gdi32.BitBlt(memdc, 0, 0,
147-
self.width, self.height,
148+
monitor['width'], monitor['height'],
148149
srcdc,
149150
monitor['left'], monitor['top'],
150151
0xcc0020) # SRCCOPY
151-
bits = windll.gdi32.GetDIBits(memdc, bmp, 0, self.height,
152-
image_data, bmi, 0)
152+
153+
bits = windll.gdi32.GetDIBits(
154+
memdc, bmp, 0, monitor['height'], image_data, bmi, 0)
153155
if bits != self.height:
154156
raise ScreenshotError('gdi32.GetDIBits() failed.')
155157
finally:

0 commit comments

Comments
 (0)