original_docstring:  Retrieve all pixels from a monitor. Pixels have to be RGB.
  
              In the code, there are few interesting things:
  
              [1] bmi.bmiHeader.biHeight = -height
  
              A bottom-up DIB is specified by setting the height to a
              positive number, while a top-down DIB is specified by
              setting the height to a negative number.
              https://msdn.microsoft.com/en-us/library/ms787796.aspx
              https://msdn.microsoft.com/en-us/library/dd144879%28v=vs.85%29.aspx
  
  
              [2] bmi.bmiHeader.biBitCount = 32
                  image_data = create_string_buffer(height * width * 4)
  
              We grab the image in RGBX mode, so that each word is 32bit
              and we have no striding, then we transform to RGB.
              Inspired by https://github.com/zoofIO/flexx
  
  
              [3] bmi.bmiHeader.biClrUsed = 0
                  bmi.bmiHeader.biClrImportant = 0
  
              When biClrUsed and biClrImportant are set to zero, there
              is "no" color table, so we can read the pixels of the bitmap
              retrieved by gdi32.GetDIBits() as a sequence of RGB values.
              Thanks to http://stackoverflow.com/a/3688682
          
docstring: Retrieve all pixels from a monitor. Pixels have to be RGB.
  In the code, there are few interesting things.
  
  
  
  A bottom-up DIB is specified by setting the height to a
  positive number, while a top-down DIB is specified by
  setting the height to a negative number.
  
  [2] bmi.bmiHeader.biBitCount = 32
  image_data = create_string_buffer(height * width * 4)
  
  We grab the image in RGBX mode, so that each word is 32bit
  and we have no striding, then we transform to RGB.
  
  
  
  When biClrUsed and biClrImportant are set to zero, there
  is "no" color table, so we can read the pixels of the bitmap
  retrieved by gdi32.GetDIBits() as a sequence of RGB values.
docstring_tokens: Retrieve all pixels from a monitor . Pixels have to be RGB . In the code there are few interesting things . A bottom - up DIB is specified by setting the height to a positive number while a top - down DIB is specified by setting the height to a negative number . [ 2 ] bmi . bmiHeader . biBitCount = 32 image_data = create_string_buffer ( height * width * 4 ) We grab the image in RGBX mode so that each word is 32bit and we have no striding then we transform to RGB . When biClrUsed and biClrImportant are set to zero there is " no " color table so we can read the pixels of the bitmap retrieved by gdi32 . GetDIBits () as a sequence of RGB values .
code: def grab(self, monitor):
          # type: (Monitor) -> ScreenShot
          """ Retrieve all pixels from a monitor. Pixels have to be RGB.
  
              In the code, there are few interesting things:
  
              [1] bmi.bmiHeader.biHeight = -height
  
              A bottom-up DIB is specified by setting the height to a
              positive number, while a top-down DIB is specified by
              setting the height to a negative number.
              https://msdn.microsoft.com/en-us/library/ms787796.aspx
              https://msdn.microsoft.com/en-us/library/dd144879%28v=vs.85%29.aspx
  
  
              [2] bmi.bmiHeader.biBitCount = 32
                  image_data = create_string_buffer(height * width * 4)
  
              We grab the image in RGBX mode, so that each word is 32bit
              and we have no striding, then we transform to RGB.
              Inspired by https://github.com/zoofIO/flexx
  
  
              [3] bmi.bmiHeader.biClrUsed = 0
                  bmi.bmiHeader.biClrImportant = 0
  
              When biClrUsed and biClrImportant are set to zero, there
              is "no" color table, so we can read the pixels of the bitmap
              retrieved by gdi32.GetDIBits() as a sequence of RGB values.
              Thanks to http://stackoverflow.com/a/3688682
          """
  
          # Convert PIL bbox style
          if isinstance(monitor, tuple):
              monitor = {
                  "left": monitor[0],
                  "top": monitor[1],
                  "width": monitor[2] - monitor[0],
                  "height": monitor[3] - monitor[1],
              }
  
          srcdc, memdc = MSS.srcdc, MSS.memdc
          width, height = monitor["width"], monitor["height"]
  
          if (self._bbox["height"], self._bbox["width"]) != (height, width):
              self._bbox = monitor
              self._bmi.bmiHeader.biWidth = width
              self._bmi.bmiHeader.biHeight = -height  # Why minus? [1]
              self._data = ctypes.create_string_buffer(width * height * 4)  # [2]
              if MSS.bmp:
                  self.gdi32.DeleteObject(MSS.bmp)
              MSS.bmp = self.gdi32.CreateCompatibleBitmap(srcdc, width, height)
              self.gdi32.SelectObject(memdc, MSS.bmp)
  
          self.gdi32.BitBlt(
              memdc,
              0,
              0,
              width,
              height,
              srcdc,
              monitor["left"],
              monitor["top"],
              SRCCOPY | CAPTUREBLT,
          )
          bits = self.gdi32.GetDIBits(
              memdc, MSS.bmp, 0, height, self._data, self._bmi, DIB_RGB_COLORS
          )
          if bits != height:
              raise ScreenShotError("gdi32.GetDIBits() failed.")
  
          return self.cls_image(bytearray(self._data), monitor)
code_tokens: def grab ( self , monitor ) : if isinstance ( monitor , tuple ) : monitor = { "left" : monitor [ 0 ] , "top" : monitor [ 1 ] , "width" : monitor [ 2 ] - monitor [ 0 ] , "height" : monitor [ 3 ] - monitor [ 1 ] , } srcdc , memdc = MSS . srcdc , MSS . memdc width , height = monitor [ "width" ] , monitor [ "height" ] if ( self . _bbox [ "height" ] , self . _bbox [ "width" ] ) != ( height , width ) : self . _bbox = monitor self . _bmi . bmiHeader . biWidth = width self . _bmi . bmiHeader . biHeight = - height self . _data = ctypes . create_string_buffer ( width * height * 4 ) if MSS . bmp : self . gdi32 . DeleteObject ( MSS . bmp ) MSS . bmp = self . gdi32 . CreateCompatibleBitmap ( srcdc , width , height ) self . gdi32 . SelectObject ( memdc , MSS . bmp ) self . gdi32 . BitBlt ( memdc , 0 , 0 , width , height , srcdc , monitor [ "left" ] , monitor [ "top" ] , SRCCOPY | CAPTUREBLT , ) bits = self . gdi32 . GetDIBits ( memdc , MSS . bmp , 0 , height , self . _data , self . _bmi , DIB_RGB_COLORS ) if bits != height : raise ScreenShotError ( "gdi32.GetDIBits() failed." ) return self . cls_image ( bytearray ( self . _data ) , monitor )
short_docstring: Retrieve all pixels from a monitor.
short_docstring_tokens: Retrieve all pixels from a monitor .
comment: # type: (Monitor) -> ScreenShot$SEP$""" Retrieve all pixels from a monitor. Pixels have to be RGB.
  
              In the code, there are few interesting things:
  
              [1] bmi.bmiHeader.biHeight = -height
  
              A bottom-up DIB is specified by setting the height to a
              positive number, while a top-down DIB is specified by
              setting the height to a negative number.
              https://msdn.microsoft.com/en-us/library/ms787796.aspx
              https://msdn.microsoft.com/en-us/library/dd144879%28v=vs.85%29.aspx
  
  
              [2] bmi.bmiHeader.biBitCount = 32
                  image_data = create_string_buffer(height * width * 4)
  
              We grab the image in RGBX mode, so that each word is 32bit
              and we have no striding, then we transform to RGB.
              Inspired by https://github.com/zoofIO/flexx
  
  
              [3] bmi.bmiHeader.biClrUsed = 0
                  bmi.bmiHeader.biClrImportant = 0
  
              When biClrUsed and biClrImportant are set to zero, there
              is "no" color table, so we can read the pixels of the bitmap
              retrieved by gdi32.GetDIBits() as a sequence of RGB values.
              Thanks to http://stackoverflow.com/a/3688682
          """$SEP$# Convert PIL bbox style$SEP$# Why minus? [1]$SEP$# [2]