def transformblit(src_tri, dst_tri, src_img, dst_img, alpha=255):
    ((x11,x12), (x21,x22), (x31,x32)) = src_tri
    ((y11,y12), (y21,y22), (y31,y32)) = dst_tri

    minx = int(math.floor(min(y11, y21, y31)))
    miny = int(math.floor(min(y12, y22, y32)))
    y11 -= minx
    y21 -= minx
    y31 -= minx
    y12 -= miny
    y22 -= miny
    y32 -= miny
    sizex = int(math.ceil(max(y11, y21, y31)))
    sizey = int(math.ceil(max(y12, y22, y32)))
    
    M = numpy.array([
                     [y11, y12, 1, 0, 0, 0],
                     [y21, y22, 1, 0, 0, 0],
                     [y31, y32, 1, 0, 0, 0],
                     [0, 0, 0, y11, y12, 1],
                     [0, 0, 0, y21, y22, 1],
                     [0, 0, 0, y31, y32, 1]
                ])
    
    y = numpy.array([x11, x21, x31, x12, x22, x32])

    try:
        A = numpy.linalg.solve(M, y)
    except numpy.linalg.LinAlgError:
        #can happen if the new triangle is a single point, so no need to paint it
        return

    transformed = src_img.transform((sizex, sizey), Image.AFFINE, A, Image.BICUBIC)
    
    mask = Image.new('1' if alpha == 255 else 'L', (sizex, sizey))
    maskdraw = ImageDraw.Draw(mask)
    maskdraw.polygon(((y11,y12), (y21,y22), (y31,y32)), outline=alpha, fill=alpha)

    dst_img.paste(transformed, (minx, miny), mask=mask)
Pastes a triangular region from one image
dataset/ETHPy150Open pycollada/meshtool/meshtool/filters/simplify_filters/sander_simplify.py/transformblit