def getIIsum(data, X):
    """
    Compute summed area as:
       A=U          Bi=U[0],B[1]
        +----------+
        |          |
        |          |
        +----------+
       C=B[0],U[1]  D=B

    \sum = I(D) - I(A) + I(Bi) + I(C)
    """
    r0, c0, r1, c1 = X
    S = 0
    S += data[r1, c1]
    if (r0 - 1 >= 0) and (c0 - 1 >= 0):
        S += data[r0 - 1, c0 - 1]
    if (r0 - 1 >= 0):
        S -= data[r0 - 1, c1]
    if (c0 - 1 >= 0):               
        S -= data[r1, c0 - 1]
    return S