def divide_quad(quad):
    """
    divide_quad in up to four sub quads. Only divide horizontal if quad is twice as wide then high,
    and vertical vice versa.
    PIL.Image.transform expects that the lower-right corner
    of a quad overlaps by one pixel.

    >>> divide_quad((0, 0, 500, 500))
    [(0, 0, 250, 250), (250, 0, 500, 250), (0, 250, 250, 500), (250, 250, 500, 500)]
    >>> divide_quad((0, 0, 2000, 500))
    [(0, 0, 1000, 500), (1000, 0, 2000, 500)]
    >>> divide_quad((100, 200, 200, 500))
    [(100, 200, 200, 350), (100, 350, 200, 500)]

    """
    w = quad[2] - quad[0]
    h = quad[3] - quad[1]
    xc = int(quad[0] + w / 2)
    yc = int(quad[1] + h / 2)
    if w > 2 * h:
        return [(quad[0], quad[1], xc, quad[3]), (xc, quad[1], quad[2],
            quad[3])]
    if h > 2 * w:
        return [(quad[0], quad[1], quad[2], yc), (quad[0], yc, quad[2],
            quad[3])]
    return [(quad[0], quad[1], xc, yc), (xc, quad[1], quad[2], yc), (quad[0
        ], yc, xc, quad[3]), (xc, yc, quad[2], quad[3])]
