# MaskTransition by stickboy
Import ("Function.ShowImage.avs")

function TransMask(clip c1, clip c2, string foto , int duration, int precision) 
{

    maska=ShowImage(foto,c1.Width(),c1.Height(),c1.Framerate(),duration,false,$000000,false,false)


    #transitionMask = Animate(maska, 0, duration, "Levels", 0,1, 20,0,235, 235, 1,  255, 0, 235)
    #transitionMask = Animate(maska, 0, duration, "Levels",  0,1, 0,0,255,         255, 1,  255, 0, 255)
    #transitionMask = Animate(maska, 0, duration, "Levels",  0,1, precision,0,255-precision,    255-precision,1,255,0,255-precision)
    transitionMask = Animate(maska, 0, duration, "Levels",  0,1, precision,0,255,    255-precision,1,255,0,255)

    overlap = transitionMask.FrameCount()
    
    Assert(overlap > 0, "JDL_MaskTransition: invalid overlap length: " + String(overlap))
    Assert(c1.FrameCount() >= overlap && c2.FrameCount() >= overlap,  "JDL_MaskTransition: clips must be longer than the transition")

    seg1 = c1.Trim(0, -(c1.FrameCount() - overlap))
    seg2 = c2.Trim(overlap, 0)

    trans1 = c1.Trim(c1.FrameCount() - overlap, 0)
    trans2 = c2.Trim(0, -overlap)
    #.Mask(transitionMask)
    #trans = Layer(trans2, trans1)
    trans = Overlay(trans2, trans1, mask=transitionMask)
    
    return seg1 + trans + seg2

    #return AudioDub(seg1 + trans + seg2, Dissolve(c1, c2, overlap))
}