#!/usr/bin/python

#
# Can read either:
# "#FF0000", "red" or (1,0,0)
# Returns in (1,0,0) convention all the time,
# raise an error is something goes wrong
#
def color_normalize(args):
    # input notation type:
    # 0 = rgb ((1,0,0))
    # 1 = html (#FF0000)
    # 2 = color name (red)
    notation_type = 0

    red = ""
    green = ""
    blue = ""

    # This is fine, just return
    if type(args) == tuple:
        return args

    if type(args) == str:
        if args[0] == '#':
            if len(args) > 7:
                raise "Invalid html color code"

            red = "0x" + args[1] + args[2]
            redint = int(str(red), 16)
            green = "0x" + args[3] + args[4]
            greenint = int(str(green), 16)
            blue = "0x" + args[5] + args[6]
            blueint = int(str(blue), 16)

            redf = redint / 255.
            greenf = greenint / 255.
            bluef = blueint / 255.

            return (redf,greenf,bluef)
        else:
            colors = {
                "black": "(0,0,0)",
                "blue": "(0,0,1)",
                "green": "(0,1,0)",
                "red": "(1,0,0)",
		"orange": "(1,0.5,0)",
		"sienna": "(0.051 0.718 0.627)",
                "turquoise": "(0.482,0.714,0.878)",
                "white": "(1,1,1)",
            }

            args = args.lower()
            
            if args in colors.keys():
                return colors[args]
            else:
                raise "Cannot find corresponding color"
            
        return

    raise "Unsupported input"


#ac = color_normalize("turquoise")
#
#print str(ac)
