Skip to content

Commit 4e97da1

Browse files
author
BoboTiG
committed
Code comments review
1 parent 0dfdbe6 commit 4e97da1

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

mss/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def enum_display_monitors(self, screen=0):
4343
'height': the height
4444
}
4545
'''
46+
4647
raise NotImplementedError('Subclasses need to implement this!')
4748

4849
def get_pixels(self, monitor):
@@ -56,6 +57,7 @@ def get_pixels(self, monitor):
5657
'heigth': the height
5758
}
5859
'''
60+
5961
raise NotImplementedError('Subclasses need to implement this!')
6062

6163
def save(self,

mss/darwin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
class MSS(MSSBase):
24-
''' Mutliple ScreenShots implementation for Mac OS X.
24+
''' Mutliple ScreenShots implementation for MacOS X.
2525
It uses intensively the Quartz.
2626
'''
2727

mss/linux.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _cleanup(self):
136136
def _set_argtypes(self):
137137
''' Functions arguments.
138138
139-
Curiously, if we set up self.xlib.XGetPixel.argtypes,
139+
Curiously, if we set up XGetPixel arguments type,
140140
the entire process takes twice more time.
141141
So, no need to waste this precious time :)
142142
Note: this issue does not occur when using libmss.
@@ -191,8 +191,6 @@ def validate(value):
191191
self.xlib.XDestroyImage.restype = c_void_p
192192
self.xlib.XCloseDisplay.restype = c_void_p
193193
self.xlib.XDefaultRootWindow.restype = POINTER(XWindowAttributes)
194-
# self.xrandr.XRRGetScreenResources.restype = \
195-
# POINTER(XRRScreenResources)
196194
self.xrandr.XRRGetScreenResources.restype = validate
197195
self.xrandr.XRRGetCrtcInfo.restype = POINTER(XRRCrtcInfo)
198196
self.xrandr.XRRFreeScreenResources.restype = c_void_p
@@ -202,7 +200,7 @@ def validate(value):
202200

203201
def enum_display_monitors(self, screen=0):
204202
''' Get positions of one or more monitors.
205-
Returns a dict with minimal requirements (see MSS class).
203+
Returns a dict with minimal requirements (see parent class).
206204
'''
207205

208206
if screen == -1:

mss/windows.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _set_restypes(self):
7474

7575
def enum_display_monitors(self, screen=-1):
7676
''' Get positions of one or more monitors.
77-
Returns a dict with minimal requirements (see MSS class).
77+
Returns a dict with minimal requirements (see parent class).
7878
'''
7979

8080
if screen == -1:
@@ -96,6 +96,7 @@ def _callback(monitor, data, rect, dc_):
9696
''' Callback for monitorenumproc() function, it will return
9797
a RECT with appropriate values.
9898
'''
99+
99100
del monitor
100101
del data
101102
del dc_
@@ -117,17 +118,30 @@ def _callback(monitor, data, rect, dc_):
117118
def get_pixels(self, monitor):
118119
''' Retrieve all pixels from a monitor. Pixels have to be RGB.
119120
120-
[1] A bottom-up DIB is specified by setting the height to a
121+
In the code, there are few interesting things:
122+
123+
[1] bmi.bmiHeader.biHeight = -height
124+
125+
A bottom-up DIB is specified by setting the height to a
121126
positive number, while a top-down DIB is specified by
122127
setting the height to a negative number.
123128
https://msdn.microsoft.com/en-us/library/ms787796.aspx
124129
https://msdn.microsoft.com/en-us/library/dd144879%28v=vs.85%29.aspx
125130
126-
[2] We grab the image in RGBX mode, so that each word is 32bit
131+
132+
[2] bmi.bmiHeader.biBitCount = 32
133+
image_data = create_string_buffer(height * width * 4)
134+
# and later, the BGRX to RGB conversion
135+
136+
We grab the image in RGBX mode, so that each word is 32bit
127137
and we have no striding, then we transform to RGB.
128138
Inspired by https://github.com/zoofIO/flexx
129139
130-
[3] When biClrUsed and biClrImportant are set to zero, there
140+
141+
[3] bmi.bmiHeader.biClrUsed = 0
142+
bmi.bmiHeader.biClrImportant = 0
143+
144+
When biClrUsed and biClrImportant are set to zero, there
131145
is "no" color table, so we can read the pixels of the bitmap
132146
retrieved by gdi32.GetDIBits() as a sequence of RGB values.
133147
Thanks to http://stackoverflow.com/a/3688682
@@ -148,7 +162,7 @@ def get_pixels(self, monitor):
148162
bmi = BITMAPINFO()
149163
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER)
150164
bmi.bmiHeader.biWidth = width
151-
bmi.bmiHeader.biHeight = -height # Why minus? See [1]
165+
bmi.bmiHeader.biHeight = -height # Why minux? See [1]
152166
bmi.bmiHeader.biPlanes = 1 # Always 1
153167
bmi.bmiHeader.biBitCount = 32 # See [2]
154168
bmi.bmiHeader.biCompression = bi_rgb

0 commit comments

Comments
 (0)