code: def read_pixels(
      viewport=None, alpha=True, mode="color", out_type="unsigned_byte"
  ):
      """Read pixels from the currently selected buffer.
  
      Under most circumstances, this function reads from the front buffer.
      Unlike all other functions in vispy.gloo, this function directly executes
      an OpenGL command.
  
      Parameters
      ----------
      viewport : array-like | None
          4-element list of x, y, w, h parameters. If None (default),
          the current GL viewport will be queried and used.
      alpha : bool
          If True (default), the returned array has 4 elements (RGBA).
          If False, it has 3 (RGB). This only effects the color mode.
      mode : str
          Type of buffer data to read. Can be one of 'colors', 'depth',
          or 'stencil'. See returns for more information.
      out_type : str | dtype
          Can be 'unsigned_byte' or 'float'. Note that this does not
          use casting, but instead determines how values are read from
          the current buffer. Can also be numpy dtypes ``np.uint8``,
          ``np.ubyte``, or ``np.float32``.
  
      Returns
      -------
      pixels : array
          3D array of pixels in np.uint8 or np.float32 format.
          The array shape is (h, w, 3) or (h, w, 4) for colors mode,
          with the top-left corner of the framebuffer at index [0, 0] in the
          returned array. If 'mode' is depth or stencil then the last dimension
          is 1.
      """
      _check_valid("mode", mode, ["color", "depth", "stencil"])
  
      # Check whether the GL context is direct or remote
      context = get_current_canvas().context
      if context.shared.parser.is_remote():
          raise RuntimeError(
              "Cannot use read_pixels() with remote GLIR parser"
          )
  
      finish()  # noqa - finish first, also flushes GLIR commands
      type_dict = {
          "unsigned_byte": gl.GL_UNSIGNED_BYTE,
          np.uint8: gl.GL_UNSIGNED_BYTE,
          "float": gl.GL_FLOAT,
          np.float32: gl.GL_FLOAT,
      }
      type_ = _check_conversion(out_type, type_dict)
      if viewport is None:
          viewport = gl.glGetParameter(gl.GL_VIEWPORT)
      viewport = np.array(viewport, int)
      if viewport.ndim != 1 or viewport.size != 4:
          raise ValueError(
              "viewport should be 1D 4-element array-like, not %s"
              % (viewport,)
          )
      x, y, w, h = viewport
      gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 1)  # PACK, not UNPACK
      if mode == "depth":
          fmt = gl.GL_DEPTH_COMPONENT
          shape = (h, w, 1)
      elif mode == "stencil":
          fmt = gl.GL_STENCIL_INDEX8
          shape = (h, w, 1)
      elif alpha:
          fmt = gl.GL_RGBA
          shape = (h, w, 4)
      else:
          fmt = gl.GL_RGB
          shape = (h, w, 3)
      im = gl.glReadPixels(x, y, w, h, fmt, type_)
      gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 4)
      # reshape, flip, and return
      if not isinstance(im, np.ndarray):
          np_dtype = (
              np.uint8 if type_ == gl.GL_UNSIGNED_BYTE else np.float32
          )
          im = np.frombuffer(im, np_dtype)
  
      im.shape = shape
      im = im[::-1, ...]  # flip the image
      return im
  
imports: import numpy
  from copy import deepcopy
  from .None import gl
  from ..color import Color
  from ..util import logger
label_desc: Use image node_id 5 for calling a global function with example usage: read_pixels(viewport, alpha, mode, out_type) and returns: im