Jaded-Encoding-Thaumaturgy / vs-scale

VapourSynth (de)scaling functions
MIT License
10 stars 4 forks source link

use fmtc/zimg for ssim #82

Closed NSQY closed 1 year ago

NSQY commented 1 year ago

gamma2linear/linear2gamma evil

fmtc fast

yap yap

fastest avs function

Function SSIM_downsample(clip c, int target_width, int target_height, val "smooth", string "kernel", float "epsilon", string "resample_args", string "dither")
{
    smooth = Default(smooth, 1.5)
    kernel = Default(kernel, "z_BicubicResize")
    epsilon = Default(epsilon, 0.000001)
    dither = Default(dither, "none")

    c
    _32bits = (BitsPerComponent() == 32)

    if (!_32bits)
    {
        ConvertBits(32, fulld=true)
    }   

    resample_args = (Defined(resample_args)) ? ", " + resample_args : ""

    l = Eval(kernel + "(" + String(target_width) + "," +  String(target_height) + resample_args + ")")

    if (IsFloat(smooth))
    {
        m = vsTCanny(l, sigmaY=smooth, sigma_vY=smooth, mode=-1)
        r = Expr(vsTCanny(Expr(l, "x dup *"), sigmaY=smooth, sigma_vY=smooth, mode=-1), vsTCanny(Eval(kernel + """(Expr("x x *"),""" + String(target_width) + "," +  String(target_height) + resample_args + ")"), sigmaY=smooth, sigma_vY=smooth, mode=-1), Expr(m, "x dup *"), "x z - "+ String(epsilon) +" < 0 y z - x z - / 0.5 pow ?")
        Expr(vsTCanny(m, sigmaY=smooth, sigma_vY=smooth, mode=-1), vsTCanny(r, sigmaY=smooth, sigma_vY=smooth, mode=-1), l, vsTCanny(Expr(r, m, "x y *"), sigmaY=smooth, sigma_vY=smooth, mode=-1), "x y z * + a -")
    }
    else
    {      
        m = l.Eval(smooth)
        r = Expr(Expr(l, "x dup *").Eval(smooth), Eval(kernel + """(Expr("x x *"),""" + String(target_width) + "," +  String(target_height) + resample_args + ")").Eval(smooth),  Expr(m, "x dup *"), "x z - "+ String(epsilon) +" < 0 y z - x z - / 0.5 pow ?")
        Expr(m.Eval(smooth), r.Eval(smooth), l, Expr(r, m, "x y *").Eval(smooth), "x y z * + a -")        
    }

    if (!_32bits)
    {
        z_ConvertFormat(pixel_type=PixelType(c), dither_type=dither)
    }
}
Setsugennoao commented 1 year ago

Didn't read but i saw fmtc, avs and yap