def blend_color(a, b):
    """
    Blends two colors together by their alpha values.

    Args:
        a(tuple): the color to blend on top of b
        b(tuple): the color underneath a

    Return:
        The blended color.
    """
    if len(a) == 3:
        a = (*a, 255)

    if len(b) == 3:
        b = (*b, 255)

    barf = b[3] / 255
    brem = (255 - b[3]) / 255

    fred   = int(b[0] * barf + a[0] * brem)
    fgreen = int(b[1] * barf + a[1] * brem)
    fblue  = int(b[2] * barf + a[2] * brem)

    falpha = min(int(a[3]) + int(b[3]), 255)

    return (fred, fgreen, fblue, falpha)