# logoAdd for JX fan-sub
# Author: QiuSJ
# 
# logo:            a logo's file name
# start:           the frame logo appeared
# end:             the frame logo disappeared
# x, y:            possition
# fadein, fadeout: fade frames
# 
# version 1.0




function logoAdd(clip "src", string "logo", int "start", int "end", int "x", int "y", int "fadein", int "fadeout", float "zoom")
{
    start   = Default(start,               0)
    end     = Default(end, FrameCount(src)-1)
    x       = Default(x,                   0)
    y       = Default(y,                   0)
    fadein  = Default(fadein,              0)
    fadeout = Default(fadeout,             0)
    zoom    = Default(zoom,                1)
    
    Assert(end     >= 0,  "end below 0")
    Assert(fadein  >= 0,  "fadein below 0")
    Assert(fadeout >= 0,  "fadeout below 0")
    Assert(zoom    >0,    "zoom must greater than zero")
    Assert(Defined(logo), "a png file is required")
    
    logo = ImageSource(logo, end=end-start+1, pixel_type="RGB32")
    
    pre  = src.Trim(0, start-1)
    proc = src.Trim(start, end)    
    post = src.Trim(end+1,   0)

    logo = logo.Spline64Resize(int(logo.width*zoom), int(logo.height*zoom)).FadeIn0(fadein).FadeOut0(fadeout)
    return Eval(
\       (start == 0 ? "" : "pre +")
\+      "proc.Overlay(logo, mask=logo.ShowAlpha(), x=" + string(x) + ", y=" + string(y) + ")"
\+      (end   == FrameCount(src)-1 ? "" : "+post") 
\   )
}

# Example:
# Import("JXlogoAdd.avsi")
# LwLibavVideoSource("F:\Work\‡εΟΔ\fx_test\00009.m2ts")
# logoAdd("F:\Work\‡εΟΔ\logo\logo Έ±±Ύ 1920_1080.png", x=100, y=-200, start=100, end=2205, fadein=24, fadeout=24, zoom=1)


