code: def getcolor(color, mode):
      """
      Same as :py:func:`~PIL.ImageColor.getrgb`, but converts the RGB value to a
      greyscale value if the mode is not color or a palette image. If the string
      cannot be parsed, this function raises a :py:exc:`ValueError` exception.
  
      .. versionadded:: 1.1.4
  
      :param color: A color string
      :return: ``(graylevel [, alpha]) or (red, green, blue[, alpha])``
      """
      # same as getrgb, but converts the result to the given mode
      color, alpha = getrgb(color), 255
      if len(color) == 4:
          color, alpha = color[0:3], color[3]
  
      if Image.getmodebase(mode) == "L":
          r, g, b = color
          color = (r * 299 + g * 587 + b * 114) // 1000
          if mode[-1] == "A":
              return (color, alpha)
      else:
          if mode[-1] == "A":
              return color + (alpha,)
      return color
  
imports: import re
  from .None import Image
label_desc: Use image node_id 2 for calling a global function with example usage: getcolor(color, mode) and returns: color, color,  alpha, unknown