@@ -118,6 +118,9 @@ class XImage(Structure):
118118 ('blue_mask' , c_ulong )
119119 ]
120120
121+ def b (x ):
122+ return pack (b'<B' , x )
123+
121124elif system () == 'Windows' :
122125 from ctypes import (
123126 byref , memset , pointer , sizeof , windll ,
@@ -154,19 +157,19 @@ class BITMAPINFO(Structure):
154157 ('bmiColors' , DWORD * 3 )
155158 ]
156159
160+ if sys .version < '3' :
161+ def b (x ):
162+ return x
163+ else :
164+ def b (x ):
165+ return pack (b'<B' , x )
166+
157167
158168
159169# ----------------------------------------------------------------------
160170# --- [ C'est parti mon kiki ! ] ---------------------------------------
161171# ----------------------------------------------------------------------
162172
163- if sys .version < '3' :
164- def b (x ):
165- return x
166- else :
167- def b (x ):
168- return pack ('<B' , x )
169-
170173class MSS (object ):
171174 ''' This class will be overloaded by a system specific one.
172175 It checkes if there is a class available for the current system.
@@ -530,15 +533,15 @@ def get_pixels(self, monitor):
530533 if image is None :
531534 raise ValueError ('MSSLinux: XGetImage() failed.' )
532535
533- pixels = [None ] * (3 * width * height )
536+ pixels = [b'0' ] * (3 * width * height )
534537 for x in range (width ):
535538 for y in range (height ):
536539 pixel = self .XGetPixel (image , x , y )
537- b = pixel & 255
538- g = (pixel & 65280 ) >> 8
539- r = (pixel & 16711680 ) >> 16
540+ blue = pixel & 255
541+ green = (pixel & 65280 ) >> 8
542+ red = (pixel & 16711680 ) >> 16
540543 offset = (x + width * y ) * 3
541- pixels [offset :offset + 3 ] = pack ( b'3B' , r , g , b )
544+ pixels [offset :offset + 3 ] = b ( red ), b ( green ), b ( blue )
542545 self .XFree (image )
543546 return b'' .join (pixels )
544547
0 commit comments