def BlendColour(fg, bg, alpha):
    """
    Blends the two colour component `fg` and `bg` into one colour component, adding
    an optional alpha channel.

    :param wx.Colour `fg`: the first colour component;
    :param wx.Colour `bg`: the second colour component;
    :param integer `alpha`: an optional transparency value.
    """
    result = bg + alpha * (fg - bg)
    if result < 0.0:
        result = 0.0
    if result > 255:
        result = 255
    return result
