def getcolor(color, 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)
 elif (mode[(-1)] == 'A'):
  return (color + (alpha,))
 return color

def getcolor ( color , 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 ) elif ( mode [ ( - 1 ) ] == 'A' ) : return ( color + ( alpha , ) ) return color
same as :py:func:~pil .