@@ -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