Guest User

Untitled

a guest
Aug 8th, 2014
937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function EDIResize16 (clip input, int "target_width", int "target_height", float "src_left", float "src_top",
  2.          \            float "src_width", float "src_height",
  3.          \            string "edimode", string "kernel_d", string "kernel_u", float "f_d", float "f_u", int "taps",
  4.          \            float "a1", float "a2", float "a3", bool "invks_d", bool "invks_u", int "invkstaps", bool "noring",
  5.          \            float "alpha", float "beta", float "gamma", int "nrad", int "mdis",
  6.          \            bool "hp", bool "ucubic", bool "cost3", int "vcheck", float "vthresh0", float "vthresh1", float "vthresh2", clip "sclip", bool "mclip",
  7.          \            int "nsize", int "nns", int "qual", int "etype", int "pscrn", int "threads",
  8.          \            int "repmode", int "repmodeu", int "repmodev",
  9.          \            float "ratiothr", float "lthr", float "elast",
  10.          \            string "output", bool "tv_range", string "cplace", string "matrix", string "curve", float "gcor", bool "sigmoid", float "gthr", float "cont")
  11. {
  12.     sCSP   = input.EDIResize16_GetCSP ()
  13.     Assert (sCSP=="Y8" || sCSP=="YV12" || sCSP=="YV16" || sCSP=="YV24", "EDIResize16: Only Support Planar YUV Colorspaces (Y8, YV12, YV16, YV24)")
  14.     sw     = input.Width ()
  15.     sh     = input.Height ()/2
  16.     swc    = sCSP=="YV24" ? sw   : sw/2
  17.     shc    = sCSP=="YV12" ? sh/2 : sh
  18.     HD     = (sw > 1024 || sh > 576) ? True : False
  19.  
  20.     ow         = Default (target_width, sw)
  21.     oh         = Default (target_height, sh)
  22.     src_left   = Default (src_left, 0)
  23.     src_top    = Default (src_top, 0)
  24.     src_width  = Default (src_width, sw)
  25.     src_height = Default (src_height, sh)
  26.     ratiothr   = Default (ratiothr, 1.000)
  27.     lthr       = Default (lthr, 1.0)
  28.     elast      = Default (elast, 1.5)
  29.     alpha      = Default (alpha, 0.2)
  30.     beta       = Default (beta, 0.125)
  31.     gamma      = Default (gamma, 60.0)
  32.     nrad       = Default (nrad, 3)
  33.     mdis       = Default (mdis, 40)
  34.     hp         = Default (hp, False)
  35.     ucubic     = Default (ucubic, True)
  36.     cost3      = Default (cost3, True)
  37.     vcheck     = Default (vcheck, 2)
  38.     vthresh0   = Default (vthresh0, 32.0)
  39.     vthresh1   = Default (vthresh1, 64.0)
  40.     vthresh2   = Default (vthresh2, 4.0)
  41.     sclip      = Default (sclip, UnDefined())
  42.     mclip      = Default (mclip, False)
  43.     nsize      = Default (nsize, 2)
  44.     nns        = Default (nns, 4)
  45.     qual       = Default (qual, 2)
  46.     etype      = Default (etype, 1)
  47.     pscrn      = Default (pscrn, 1)
  48.     threads    = Default (threads, 0)
  49.     repmode    = Default (repmode, 13)
  50.     repmodeu   = Default (repmodeu, repmode)
  51.     repmodev   = Default (repmodev, repmode)
  52.     edimode    = Default (edimode, "eedi3")
  53.     kernel_d   = Default (kernel_d, "Spline")
  54.     kernel_u   = Default (kernel_u, "Spline")
  55.     f_d        = Default (f_d, 1.0)
  56.     f_u        = Default (f_u, 1.0)
  57.     taps       = Default (taps, 32)
  58.     a1         = Default (a1, UnDefined ())
  59.     a2         = Default (a2, UnDefined ())
  60.     a3         = Default (a3, UnDefined ())
  61.     invks_d    = Default (invks_d, False)
  62.     invks_u    = Default (invks_u, False)
  63.     invkstaps  = Default (invkstaps, 64)
  64.     noring     = Default (noring, False)
  65.     tv_range   = Default (tv_range, True)
  66.     output     = Default (output, sCSP)
  67.     cplace     = Default (cplace, "MPEG2")
  68.     matrix     = Default (matrix, HD ? "709" : "601")
  69.     curve      = Default (curve, "linear")
  70.     gcor       = Default (gcor, 1.0)
  71.     sigmoid    = Default (sigmoid, True)
  72.     gthr       = Default (gthr, UnDefined())
  73.     cont       = Default (cont, UnDefined())
  74.  
  75.     IsY8   = sCSP == "Y8" || output == "Y8"
  76.     sCSP   = IsY8 ? "YV24" : sCSP
  77.    
  78.     IsRGB  = LeftStr (output, 3) == "RGB"
  79.     oCSP   = IsRGB || IsY8 ? "YV24" : output
  80.  
  81.     Y      = 3
  82.     U      = IsY8 ? 1 : 3
  83.     V      = IsY8 ? 1 : 3
  84.     Yt     = Y == 3 || Y == 4
  85.     Ut     = U == 3 || U == 4
  86.     Vt     = V == 3 || V == 4
  87.     Y31    = Yt ? 3 : 1
  88.     U31    = Ut ? 3 : 1
  89.     V31    = Vt ? 3 : 1
  90.     Y32    = Yt ? 3 : Y
  91.     U32    = Ut ? 3 : U
  92.     V32    = Vt ? 3 : V
  93.     Y21    = Yt ? 2 : Y
  94.     U21    = Ut ? 2 : U
  95.     V21    = Vt ? 2 : V
  96.     Y321   = Y > 1 ? 3 : Y
  97.     U321   = U > 1 ? 3 : U
  98.     V321   = V > 1 ? 3 : V
  99.  
  100.     curve      = Yt ? curve : "linear"
  101.  
  102.     owc    = oCSP=="YV24" ? ow : ow/2
  103.     ohc    = oCSP=="YV12" ? oh/2 : oh
  104.     Assert (!(output=="YV16" && ow!=owc*2), "EDIResize16: Width of YV16 Output Clip Must Be MOD2!")
  105.     Assert (!(output=="YV12" && ow!=owc*2), "EDIResize16: Width of YV12 Output Clip Must Be MOD2!")
  106.     Assert (!(output=="YV12" && oh!=ohc*2), "EDIResize16: Height of YV12 Output Clip Must Be MOD2!")
  107.  
  108.     prel        = int(src_left/2) * 2
  109.     pret        = int(src_top /2) * 2
  110.     prer        = int((src_width > 0 ? -sw+src_left+src_width : src_width )/2) * 2
  111.     preb        = int((src_height> 0 ? -sh+src_top+src_height : src_height)/2) * 2
  112.     prew        = sw - prel + prer
  113.     preh        = sh - pret + preb
  114.    
  115.     sCSP=="YV24" ? \
  116.     Eval ("""
  117.        swmod2      = sw  /2*2 == sw
  118.        pwmod2      = prew/2*2 == prew
  119.        wpre        = prew < sw
  120.        prel        = wpre ?          prel            :          0
  121.        prer        = wpre ? pwmod2 ? prer : prer + 1 : swmod2 ? 0 : 1
  122.        prew        = sw - prel + prer
  123.        wpre        = prew < sw || !swmod2
  124.    """) : \
  125.     Eval ("""
  126.        swmod4      = sw  /4*4 == sw
  127.        pwmod4      = prew/4*4 == prew
  128.        wpre        = prew < sw
  129.        prel        = wpre ?          prel            :          0
  130.        prer        = wpre ? pwmod4 ? prer : prer + 2 : swmod4 ? 0 : 2
  131.        prew        = sw - prel + prer
  132.        wpre        = prew < sw || !swmod4
  133.    """)
  134.    
  135.     sCSP=="YV12" ? \
  136.     Eval ("""
  137.        shmod4      = sh  /4*4 == sh
  138.        phmod4      = preh/4*4 == preh
  139.        hpre        = preh < sh
  140.        pret        = hpre ?          pret            :          0
  141.        preb        = hpre ? phmod4 ? preb : preb + 2 : shmod4 ? 0 : 2
  142.        preh        = sh - pret + preb
  143.        hpre        = preh < sh || !shmod4
  144.    """) : \
  145.     Eval ("""
  146.        shmod2      = sh  /2*2 == sh
  147.        phmod2      = preh/2*2 == preh
  148.        hpre        = preh < sh
  149.        pret        = hpre ?          pret            :          0
  150.        preb        = hpre ? phmod2 ? preb : preb + 1 : shmod2 ? 0 : 1
  151.        preh        = sh - pret + preb
  152.        hpre        = preh < sh || !shmod2
  153.    """)
  154.    
  155.     src_width   = src_width <=0 ? +sw-src_left+src_width : src_width
  156.     src_height  = src_height<=0 ? +sh-src_top+src_height : src_height
  157.     src_left    = wpre ? src_left-prel : src_left
  158.     src_top     = hpre ? src_top -pret : src_top
  159.    
  160.     src_leftc   = sCSP=="YV24" ? src_left      : src_left  /2.
  161.     src_topc    = sCSP=="YV12" ? src_top   /2. : src_top
  162.     src_widthc  = sCSP=="YV24" ? src_width     : src_width /2.
  163.     src_heightc = sCSP=="YV12" ? src_height/2. : src_height
  164.  
  165.     yhratio  = float (ow) / float(src_width)
  166.     yvratio  = float (oh) / float(src_height)
  167.     chratio  = float (owc) / float(src_widthc)
  168.     cvratio  = float (ohc) / float(src_heightc)
  169.  
  170.     enable   = yhratio!=1 || yvratio!=1 || chratio!=1 || cvratio!=1 ||
  171.     \          src_width  !=int (src_width) || src_height !=int (src_height) || src_widthc !=int (src_widthc) || src_heightc!=int (src_heightc) ||
  172.     \          src_left   !=int (src_left) || src_top    !=int (src_top) || src_leftc  !=int (src_leftc) || src_topc   !=int (src_topc)
  173.  
  174.     yhct     = yhratio>ratiothr ? Ceil (log (yhratio/ratiothr) / log (2)) : 0
  175.     yhrf     = int (Pow (2, yhct))
  176.     yrhratio = yhratio/yhrf
  177.     yvct     = yvratio>ratiothr ? Ceil (log (yvratio/ratiothr) / log (2)) : 0
  178.     yvrf     = int (Pow (2, yvct))
  179.     yrvratio = yvratio/yvrf
  180.    
  181.     chct     = chratio>ratiothr ? Ceil (log (chratio/ratiothr) / log (2)) : 0
  182.     chrf     = int (Pow (2, chct))
  183.     crhratio = chratio/chrf
  184.     cvct     = cvratio>ratiothr ? Ceil (log (cvratio/ratiothr) / log (2)) : 0
  185.     cvrf     = int (Pow (2, cvct))
  186.     crvratio = cvratio/cvrf
  187.  
  188.     noneediy  = yhct<=0 && yvct<=0
  189.     noneedic  = chct<=0 && cvct<=0
  190.     noneedi   = noneediy || noneedic
  191.    
  192.     Yedit     = Yt&&!noneediy
  193.     Uedit     = Ut&&!noneedic
  194.     Vedit     = Vt&&!noneedic
  195.     Yedi31    = Yedit ? 3 : 1
  196.     Uedi31    = Uedit ? 3 : 1
  197.     Vedi31    = Vedit ? 3 : 1
  198.     Yedi      = Yt&&noneediy ? 2 : Y
  199.     Uedi      = Ut&&noneedic ? 2 : U
  200.     Vedi      = Vt&&noneedic ? 2 : V
  201.  
  202.     edit      = Yedit || Uedit || Vedit
  203.     mixed     = !edit || !enable ? False : True
  204.  
  205.     yhshift   = yhrf>=2 ? 0.5 : 0      
  206.     yvshift   = yvrf>=2 ? 0.5 : 0      
  207.     yhfix     = -yhshift              
  208.     yvfix     = -yvshift              
  209.    
  210.     chshift   = oCSP=="YV24" ? sCSP=="YV24" ?                  chrf>=2 ? 0.50         :  0
  211.     \                                      : cplace=="MPEG1" ? chrf>=2 ? 0.50         :  0
  212.     \                                                        : chrf>=2 ? 0.50-chrf/4. : -0.25
  213.     \                       : sCSP=="YV24" ? cplace=="MPEG1" ? chrf>=2 ? 0.50         :  0
  214.     \                                                        : chrf>=2 ? 0.75         :  0.25
  215.     \                                      : cplace=="MPEG1" ? chrf>=2 ? 0.50         :  0
  216.     \                                                        : chrf>=2 ? 0.75-chrf/4. :  0
  217.    
  218.     cvshift   = cvrf>=2 ? 0.5 : 0      
  219.     chfix     = -chshift                
  220.     cvfix     = -cvshift              
  221.    
  222.     cphfixe   = oCSP=="YV24" ?                  0
  223.     \                       : cplace=="MPEG1" ? 0
  224.     \                                         : 0.25-0.25/crhratio
  225.    
  226.     cphfix    = oCSP=="YV24" ? sCSP=="YV24" ?                  0
  227.     \                                      : cplace=="MPEG1" ? 0
  228.     \                                                        : 0.25
  229.     \                       : sCSP=="YV24" ? cplace=="MPEG1" ? 0
  230.     \                                                        : -0.5
  231.     \                                      : cplace=="MPEG1" ? 0
  232.     \                                                        : 0.25-0.25/chratio
  233.  
  234.     input  = wpre || hpre ? input.Dither_resize16 (wpre?prew:sw, hpre?preh:sh, wpre?prel:0, hpre?pret:0,
  235.                                   \                wpre?prew:sw, hpre?preh:sh, kernel="point")
  236.     \                     : input
  237.     input8 = input.Round8 (tv_range=tv_range)
  238.  
  239.     !(enable && edit) ? NOP() : \
  240.     yhct==chct && yvct==cvct && sCSP=="YV12" ? \
  241.     Eval ("""
  242.         edgeedi   = input8.EDICore (vct=yvct, hct=yhct, vfield=1, hfield=1, Y=Yt, U=Ut, V=Vt,
  243.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  244.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  245.             \      sclip=sclip, mclip=mclip,
  246.             \      nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads,
  247.             \      repmode=repmode, repmodeu=repmodeu, repmodev=repmodev, edimode=edimode)
  248.          edgeedi16 = edgeedi.Convert8To16 (tv_range=tv_range)
  249.          edgeediY  = edgeedi16.ConvertToY8 ()
  250.          edgeediU  = edgeedi16.UToY8 ()
  251.          edgeediV  = edgeedi16.VToY8 ()
  252.    """) : \
  253.     Eval ("""
  254.         edgeediY  = !Yedit ? NOP ()
  255.         \                          : input8.ConvertToYV12 ().EDICore (vct=yvct, hct=yhct, vfield=1, hfield=1, Y=Yt, U=False, V=False,
  256.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  257.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  258.             \      sclip=sclip, mclip=mclip,
  259.             \      nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads,
  260.             \      repmode=repmode, repmodeu=repmodeu, repmodev=repmodev, edimode=edimode)
  261.          \                                  .ConvertToY8 ().Convert8To16 (tv_range=tv_range)
  262.          edgeediU  = !Uedit ? NOP()
  263.          \                          : input8.UToY ().EDICore (vct=cvct, hct=chct, vfield=1, hfield=1, Y=Ut, U=False, V=False,
  264.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  265.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  266.             \      sclip=sclip, mclip=mclip,
  267.             \      nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads,
  268.             \      repmode=repmode, repmodeu=repmodeu, repmodev=repmodev, edimode=edimode)
  269.          \                                  .ConvertToY8 ().Convert8To16 (tv_range=tv_range)
  270.          edgeediV  = !Vedit ? NOP()
  271.          \                          : input8.VToY ().EDICore (vct=cvct, hct=chct, vfield=1, hfield=1, Y=Vt, U=False, V=False,
  272.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  273.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  274.             \      sclip=sclip, mclip=mclip,
  275.             \      nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads,
  276.             \      repmode=repmode, repmodeu=repmodeu, repmodev=repmodev, edimode=edimode)
  277.          \                                  .ConvertToY8 ().Convert8To16 (tv_range=tv_range)
  278.    """)
  279.  
  280.         resste   = "Dither_resize16"
  281.     yrh      = yrhratio>ratiothr
  282.     yrv      = yrvratio>ratiothr
  283.     crh      = crhratio>ratiothr
  284.     crv      = crvratio>ratiothr
  285.  
  286.     !(enable && edit) ? NOP() : \
  287.     Eval ("""
  288.         edgeediY = !Yedit ? NOP()
  289.         \                 : curve=="linear" ? edgeediY
  290.         \                                   : edgeediY.Dither_y_gamma_to_linear (tv_range_in=tv_range, tv_range_out=tv_range, curve=curve, u=1, v=1,
  291.                                                        \                         gcor=gcor, sigmoid=sigmoid, thr=gthr, cont=cont)
  292.         edgeY    = !Yedit ? input.BlankClip (width=ow, height=oh *2, pixel_type="Y8", color_yuv=$008080)
  293.          \                 : edgeediY.""" + resste + """ (ow, oh, src_left=src_left*yhrf+yhfix, src_top=src_top*yvrf+yvfix,
  294.         \                                                src_width=src_width*yhrf, src_height=src_height*yvrf,
  295.         \                                                kernelh=yrh ? kernel_u : kernel_d, kernelv=yrv? kernel_u : kernel_d,
  296.      \                                                fh=yrh ? f_u : f_d, fv=yrv ? f_u : f_d,
  297.      \                                                invksh=yrh ? invks_u : invks_d, invksv=yrv ? invks_u : invks_d,
  298.      \                                                taps=taps, a1=a1, a2=a2, a3=a3, invkstaps=invkstaps,
  299.      \                                                y=Y31, u=1, v=1)
  300.         edgeY   = !Yedit ? edgeY
  301.         \                : curve=="linear" ? edgeY
  302.         \                                  : edgeY.Dither_y_linear_to_gamma (tv_range_in=tv_range, tv_range_out=tv_range, curve=curve, u=1, v=1,
  303.                                                    \                         gcor=gcor, sigmoid=sigmoid, thr=gthr, cont=cont)
  304.          edgeU   = !Uedit ? input.BlankClip (width=owc, height=ohc*2, pixel_type="Y8", color_yuv=$008080)
  305.          \                : edgeediU.""" + resste + """ (owc, ohc, src_left=src_leftc*chrf+chfix+cphfixe, src_top=src_topc*cvrf+cvfix,
  306.         \                                               src_width=src_widthc*chrf, src_height=src_heightc*cvrf,
  307.         \                                               kernelh=crh ? kernel_u : kernel_d, kernelv=crv ? kernel_u : kernel_d,
  308.      \                                               fh=crh ? f_u : f_d, fv=crv ? f_u : f_d,
  309.      \                                               invksh=crh ? invks_u : invks_d, invksv=crv ? invks_u : invks_d,
  310.      \                                               taps=taps, a1=a1, a2=a2, a3=a3, invkstaps=invkstaps,
  311.      \                                               y=U31, u=1, v=1)
  312.          edgeV   = !Vedit ? input.BlankClip (width=owc, height=ohc*2, pixel_type="Y8", color_yuv=$008080)
  313.          \                : edgeediV.""" + resste + """ (owc, ohc, src_left=src_leftc*chrf+chfix+cphfixe, src_top=src_topc*cvrf+cvfix,
  314.         \                                               src_width=src_widthc*chrf, src_height=src_heightc*cvrf,
  315.         \                                               kernelh=crh ? kernel_u : kernel_d, kernelv=crv ? kernel_u : kernel_d,
  316.      \                                               fh=crh ? f_u : f_d, fv=crv ? f_u : f_d,
  317.      \                                               invksh=crh ? invks_u : invks_d, invksv=crv ? invks_u : invks_d,
  318.      \                                               taps=taps, a1=a1, a2=a2, a3=a3, invkstaps=invkstaps,
  319.      \                                               y=V31, u=1, v=1)
  320.          edge16  = IsY8 ? edgeY : YToUV (edgeU, edgeV, edgeY)
  321.    """)
  322.  
  323.         resstf   = noring ? "Dither_resize16nr" : "Dither_resize16"
  324.     yh       = yhratio>ratiothr
  325.     yv       = yvratio>ratiothr
  326.     ch       = chratio>ratiothr
  327.     cv       = cvratio>ratiothr
  328.  
  329.     !(enable && (mixed || !(Yedit && Uedit && Vedit))) ? NOP() : \
  330.     yhratio==chratio && yvratio==cvratio && (!mixed || (Yedit && Uedit && Vedit)) ? \
  331.     Eval("""
  332.         flat16  = curve=="linear" ? input
  333.         \                         : input.Dither_y_gamma_to_linear (tv_range_in=tv_range, tv_range_out=tv_range, curve=curve, u=1, v=1,
  334.                                             \                         gcor=gcor, sigmoid=sigmoid, thr=gthr, cont=cont)
  335.         flat16  =                   flat16.""" + resstf + """
  336.      \                                           (ow, oh, src_left=src_left, src_top=src_top,
  337.         \                                            src_width=src_width, src_height=src_height, cplace=cplace,
  338.         \                                            kernelh=yh ? kernel_u : kernel_d, kernelv=yv ? kernel_u : kernel_d,
  339.      \                                            fh=yh ? f_u : f_d, fv=yv ? f_u : f_d,
  340.      \                                            invksh=yh ? invks_u : invks_d, invksv=yv ? invks_u : invks_d,
  341.      \                                            taps=taps, a1=a1, a2=a2, a3=a3, invkstaps=invkstaps,
  342.      \                                            y=Y32, u=U32, v=V32)
  343.         flat16  = curve=="linear" ? flat16
  344.         \                         : flat16.Dither_y_linear_to_gamma (tv_range_in=tv_range, tv_range_out=tv_range, curve=curve, u=1, v=1,
  345.                                            \                         gcor=gcor, sigmoid=sigmoid, thr=gthr, cont=cont)
  346.    """) : \
  347.     Eval("""
  348.         flatY   = curve=="linear" ? input.ConvertToY8 () :
  349.      \         (mixed || !Yedit) && Yt ? input.ConvertToY8 ().Dither_y_gamma_to_linear (tv_range_in=tv_range, tv_range_out=tv_range, curve=curve, u=1, v=1,
  350.                                                                    \                         gcor=gcor, sigmoid=sigmoid, thr=gthr, cont=cont)
  351.         \                                 : input.ConvertToY8 ()
  352.         flatY   = (mixed || !Yedit) && Yt ? flatY.""" + resstf + """
  353.      \                                           (ow, oh, src_left=src_left, src_top=src_top,
  354.         \                                            src_width=src_width, src_height=src_height,
  355.         \                                            kernelh=yh ? kernel_u : kernel_d, kernelv=yv ? kernel_u : kernel_d,
  356.      \                                            fh=yh ? f_u : f_d, fv=yv ? f_u : f_d,
  357.      \                                            invksh=yh ? invks_u : invks_d, invksv=yv ? invks_u : invks_d,
  358.      \                                            taps=taps, a1=a1, a2=a2, a3=a3, invkstaps=invkstaps,
  359.      \                                            y=Y32, u=1, v=1)
  360.         \                                 : input.BlankClip (width=ow, height=oh *2, pixel_type="Y8", color_yuv=$008080)
  361.         flatY   = curve=="linear" ? flatY :
  362.         \         (mixed || !Yedit) && Yt ? flatY.Dither_y_linear_to_gamma (tv_range_in=tv_range, tv_range_out=tv_range, curve=curve, u=1, v=1,
  363.                                                   \                         gcor=gcor, sigmoid=sigmoid, thr=gthr, cont=cont)
  364.         \                                 : flatY
  365.         flatU   = (mixed || !Uedit) && Ut ? input.UToY8 ().""" + resstf + """
  366.      \                                           (owc, ohc, src_left=src_leftc+cphfix, src_top=src_topc,
  367.         \                                            src_width=src_widthc, src_height=src_heightc,
  368.         \                                            kernelh=ch ? kernel_u : kernel_d, kernelv=cv ? kernel_u : kernel_d,
  369.      \                                            fh=ch ? f_u : f_d, fv=cv ? f_u : f_d,
  370.      \                                            invksh=ch ? invks_u : invks_d, invksv=cv ? invks_u : invks_d,
  371.      \                                            taps=taps, a1=a1, a2=a2, a3=a3, invkstaps=invkstaps,
  372.      \                                            y=U32, u=1, v=1)
  373.         \                                 : input.BlankClip (width=owc, height=ohc*2, pixel_type="Y8", color_yuv=$008080)
  374.         flatV   = (mixed || !Vedit) && Vt ? input.VToY8 ().""" + resstf + """
  375.      \                                           (owc, ohc, src_left=src_leftc+cphfix, src_top=src_topc,
  376.         \                                            src_width=src_widthc, src_height=src_heightc,
  377.         \                                            kernelh=ch ? kernel_u : kernel_d, kernelv=cv ? kernel_u : kernel_d,
  378.      \                                            fh=ch ? f_u : f_d, fv=cv ? f_u : f_d,
  379.      \                                            invksh=ch ? invks_u : invks_d, invksv=cv ? invks_u : invks_d,
  380.      \                                            taps=taps, a1=a1, a2=a2, a3=a3, invkstaps=invkstaps,
  381.      \                                            y=V32, u=1, v=1)
  382.         \                                 : input.BlankClip (width=owc, height=ohc*2, pixel_type="Y8", color_yuv=$008080)
  383.          flat16  = IsY8 ? flatY : YToUV (flatU, flatV, flatY)
  384.    """)
  385.     enable ? \
  386.     Eval("""
  387.         merge16  = !edit ? flat16
  388.         \                : mixed ? Dither_limit_dif16 (flat16, edge16, thr=lthr, elast=elast, y=Yedi, u=Uedi, v=Vedi)
  389.         \                        : Yedit==Uedit && Uedit==Vedit || IsY8 ? edge16
  390.         \                                                               : mt_lutxy (edge16, flat16, Y=Yt ? Yedit ? 2 : 4 : 1, U=Ut ? Uedit ? 2 : 4 : 1, V=Vt ? Vedit ? 2 : 4 :1)
  391.         merge16  = IsY8 ? output=="Y8" ? merge16.ConvertToY8 () : Eval ("merge16.ConvertTo"+oCSP).Dither_lut16 (Y=2, U=-32768, V=-32768) : merge16
  392.         final    = IsRGB ? merge16.Dither_convert_yuv_to_rgb (matrix=matrix, tv_range=tv_range, lsb_in=True, mode=-1, output=output)
  393.         \                : merge16
  394.    """) : \
  395.     Eval("""
  396.         shift16  = input.Dither_resize16 (ow, oh, src_left, src_top, src_width, src_height, kernel="point", y=Y, u=U, v=V)
  397.         shift16  = IsY8 ? output=="Y8" ? merge16.ConvertToY8 () : Eval ("shift16.ConvertTo"+oCSP).Dither_lut16 (Y=2, U=-32768, V=-32768) : shift16
  398.         final    = IsRGB ? shift16.Dither_convert_yuv_to_rgb (matrix=matrix, tv_range=tv_range, lsb_in=True, mode=-1, output=output)
  399.         \                : shift16
  400.    """)
  401.  
  402.     return final
  403. }
  404.  
  405. Function EDICore (clip input, int "vct", int "hct", int "vfield", int "hfield", bool "Y", bool "U", bool "V",
  406.          \        float "alpha", float "beta", float "gamma", int "nrad", int "mdis",
  407.          \        bool "hp", bool "ucubic", bool "cost3", int "vcheck", float "vthresh0", float "vthresh1", float "vthresh2", clip "sclip", bool "mclip",
  408.          \        int "nsize", int "nns", int "qual", int "etype", int "pscrn", int "threads",
  409.          \        int "repmode", int "repmodeu", int "repmodev",
  410.          \        string "edimode", bool "honly")
  411. {
  412.     vct      = Default(vct,      1      )
  413.     hct      = Default(hct,      1      )
  414.     vfield   = Default(vfield,   1      )
  415.     hfield   = Default(hfield,   1      )
  416.     Y        = Default(Y,        True   )
  417.     U        = Default(U,        False  )
  418.     V        = Default(V,        False  )
  419.     honly    = Default(honly,    False  )
  420.  
  421.     alpha      = Default (alpha, 0.2)
  422.     beta       = Default (beta, 0.125)
  423.     gamma      = Default (gamma, 60.0)
  424.     nrad       = Default (nrad, 3)
  425.     mdis       = Default (mdis, 40)
  426.     hp         = Default (hp, False)
  427.     ucubic     = Default (ucubic, True)
  428.     cost3      = Default (cost3, True)
  429.     vcheck     = Default (vcheck, 2)
  430.     vthresh0   = Default (vthresh0, 32.0)
  431.     vthresh1   = Default (vthresh1, 64.0)
  432.     vthresh2   = Default (vthresh2, 4.0)
  433.     sclip      = Default (sclip, UnDefined())
  434.     mclip      = Default (mclip, False)
  435.     nsize      = Default (nsize, 2)
  436.     nns        = Default (nns, 4)
  437.     qual       = Default (qual, 2)
  438.     etype      = Default (etype, 1)
  439.     pscrn      = Default (pscrn, 1)
  440.     threads    = Default (threads, 0)
  441.     repmode    = Default (repmode, 13)
  442.     repmodeu   = Default (repmodeu, repmode)
  443.     repmodev   = Default (repmodev, repmode)
  444.     edimode    = Default (edimode, "eedi3")
  445.    
  446.    
  447.     input
  448.    
  449.     hct >= 1 ? \
  450.     Eval("""
  451.        (honly) ? last
  452.        \       : Eval(" try { fturnright(chroma=U||V, mt=threads!=1) } catch(error_msg) { TurnRight() } ")
  453.        eedim = mclip ? GenEMask () : UnDefined ()
  454.        (edimode=="eedi3") ? eedi3_dh (field=hfield, Y=Y, U=U, V=V, alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  455.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  456.             \      sclip=sclip, mclip=eedim, threads=threads)
  457.                         \ : (edimode=="nnedi3") ? nnedi3_dh (field=hfield, Y=Y, U=U, V=V, nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn,
  458.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  459.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  460.             \      sclip=sclip, mclip=eedim, threads=threads)
  461.                                               \ : (edimode=="eedi3+nnedi3") ? hedi_dh (field=hfield, Y=Y, U=U, V=V,
  462.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  463.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2, sclip=sclip, mclip=eedim,
  464.             \      nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads)
  465.                                                                           \ : (edimode=="eedi3_repaired") ? eedi3_dh_r (field=hfield, Y=Y, U=U, V=V,
  466.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  467.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2, sclip=sclip, mclip=eedim,
  468.             \      nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads,
  469.             \      repmode=repmode, repmodeu=repmodeu, repmodev=repmodev)
  470.                                                                                                         \ : (edimode=="nnedi3_repaired") ? nnedi3_dh_r (field=hfield, Y=Y, U=U, V=V,
  471.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  472.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2, sclip=sclip, mclip=eedim,
  473.             \      nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads,
  474.             \      repmode=repmode, repmodeu=repmodeu, repmodev=repmodev)
  475.                                                                                                                                        \ : (edimode=="eedi3+nnedi3_repaired") ? hedi_dh_r (field=hfield, Y=Y, U=U, V=V,
  476.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  477.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2, sclip=sclip, mclip=eedim,
  478.             \      nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads,
  479.             \      repmode=repmode, repmodeu=repmodeu, repmodev=repmodev)
  480.                                                                                                                                                                             \ : Assert (1>2,"EDIResize16: Invalid edimode !")
  481.        
  482.         hct    = hct - 1
  483.        honly  = hct >= 1
  484.        hfield = 0
  485.        
  486.         (honly) ? last
  487.        \       : Eval(" try { fturnleft (chroma=U||V, mt=threads!=1) } catch(error_msg) { TurnLeft () } ")
  488.    """) : NOP()
  489.    
  490.     vct >= 1 && !honly ? \
  491.     Eval("""
  492.        eedim = mclip ? GenEMask () : UnDefined ()
  493.        (edimode=="eedi3") ? eedi3_dh (field=vfield, Y=Y, U=U, V=V, alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  494.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  495.             \      sclip=sclip, mclip=eedim, threads=threads)
  496.                         \ : (edimode=="nnedi3") ? nnedi3_dh (field=vfield, Y=Y, U=U, V=V, nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn,
  497.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  498.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  499.             \      sclip=sclip, mclip=eedim, threads=threads)
  500.                                               \ : (edimode=="eedi3+nnedi3") ? hedi_dh (field=vfield, Y=Y, U=U, V=V,
  501.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  502.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2, sclip=sclip, mclip=eedim,
  503.             \      nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads)
  504.                                                                           \ : (edimode=="eedi3_repaired") ? eedi3_dh_r (field=vfield, Y=Y, U=U, V=V,
  505.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  506.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2, sclip=sclip, mclip=eedim,
  507.             \      nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads,
  508.             \      repmode=repmode, repmodeu=repmodeu, repmodev=repmodev)
  509.                                                                                                         \ : (edimode=="nnedi3_repaired") ? nnedi3_dh_r (field=vfield, Y=Y, U=U, V=V,
  510.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  511.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2, sclip=sclip, mclip=eedim,
  512.             \      nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads,
  513.             \      repmode=repmode, repmodeu=repmodeu, repmodev=repmodev)
  514.                                                                                                                                        \ : (edimode=="eedi3+nnedi3_repaired") ? hedi_dh_r (field=vfield, Y=Y, U=U, V=V,
  515.             \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  516.             \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2, sclip=sclip, mclip=eedim,
  517.             \      nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads,
  518.             \      repmode=repmode, repmodeu=repmodeu, repmodev=repmodev)
  519.                                                                                                                                                                             \ : Assert (1>2,"EDIResize16: Invalid edimode !")
  520.        
  521.         vct    = vct - 1
  522.        vfield = 0
  523.    """) : NOP()
  524.    
  525.    
  526.     return Y||U||V ? vct <= 0 && hct <= 0 ? last
  527.     \                                     : last.EDICore (vct=vct, hct=hct, vfield=vfield, hfield=hfield, Y=Y, U=U, V=V,
  528.              \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  529.              \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  530.              \      sclip=sclip, mclip=mclip,
  531.              \      nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads,
  532.              \      repmode=repmode, repmodeu=repmodeu, repmodev=repmodev, edimode=edimode, honly=honly)
  533.     \              : input
  534. }
  535.  
  536. Function hedi_dh_r (clip input, int "field", bool "Y", bool "U", bool "V",
  537.          \        float "alpha", float "beta", float "gamma", int "nrad", int "mdis",
  538.          \        bool "hp", bool "ucubic", bool "cost3", int "vcheck", float "vthresh0", float "vthresh1", float "vthresh2", clip "sclip", clip "mclip",
  539.          \        int "nsize", int "nns", int "qual", int "etype", int "pscrn", int "threads",
  540.          \        int "repmode", int "repmodeu", int "repmodev")
  541. {
  542.     nnedi3=input.nnedi3_dh (field=field, Y=Y, U=U, V=V, nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn,
  543.              \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  544.              \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  545.              \      sclip=sclip, mclip=mclip, threads=threads)
  546.     dh=input.eedi3_dh (field=field, Y=Y, U=U, V=V, alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  547.              \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  548.              \      sclip=nnedi3, mclip=mclip, threads=threads).repair (nnedi3, mode=repmode, modeu=repmodeu, modev=repmodev)
  549.     return dh
  550. }
  551.  
  552. Function nnedi3_dh_r (clip input, int "field", bool "Y", bool "U", bool "V",
  553.          \        float "alpha", float "beta", float "gamma", int "nrad", int "mdis",
  554.          \        bool "hp", bool "ucubic", bool "cost3", int "vcheck", float "vthresh0", float "vthresh1", float "vthresh2", clip "sclip", clip "mclip",
  555.          \        int "nsize", int "nns", int "qual", int "etype", int "pscrn", int "threads",
  556.          \        int "repmode", int "repmodeu", int "repmodev")
  557. {
  558.     eedi3=input.eedi3_dh (field=field, Y=Y, U=U, V=V, alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  559.              \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  560.              \      sclip=sclip, mclip=mclip, threads=threads)
  561.     dh=input.nnedi3_dh (field=field, Y=Y, U=U, V=V, nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn,
  562.              \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  563.              \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  564.              \      sclip=sclip, mclip=mclip, threads=threads).repair (eedi3, mode=repmode, modeu=repmodeu, modev=repmodev)
  565.     return dh
  566. }
  567.  
  568. Function eedi3_dh_r (clip input, int "field", bool "Y", bool "U", bool "V",
  569.          \        float "alpha", float "beta", float "gamma", int "nrad", int "mdis",
  570.          \        bool "hp", bool "ucubic", bool "cost3", int "vcheck", float "vthresh0", float "vthresh1", float "vthresh2", clip "sclip", clip "mclip",
  571.          \        int "nsize", int "nns", int "qual", int "etype", int "pscrn", int "threads",
  572.          \        int "repmode", int "repmodeu", int "repmodev")
  573. {
  574.     nnedi3=input.nnedi3_dh (field=field, Y=Y, U=U, V=V, nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn,
  575.              \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  576.              \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  577.              \      sclip=sclip, mclip=mclip, threads=threads)
  578.     dh=input.eedi3_dh (field=field, Y=Y, U=U, V=V, alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  579.              \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  580.              \      sclip=sclip, mclip=mclip, threads=threads).repair (nnedi3, mode=repmode, modeu=repmodeu, modev=repmodev)
  581.     return dh
  582. }
  583.  
  584. Function hedi_dh (clip input, int "field", bool "Y", bool "U", bool "V",
  585.          \        float "alpha", float "beta", float "gamma", int "nrad", int "mdis",
  586.          \        bool "hp", bool "ucubic", bool "cost3", int "vcheck", float "vthresh0", float "vthresh1", float "vthresh2", clip "sclip", clip "mclip",
  587.          \        int "nsize", int "nns", int "qual", int "etype", int "pscrn", int "threads")
  588. {
  589.     nnedi3=input.nnedi3_dh (field=field, Y=Y, U=U, V=V, nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn,
  590.              \      alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  591.              \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  592.              \      sclip=sclip, mclip=mclip, threads=threads)
  593.     dh=input.eedi3_dh (field=field, Y=Y, U=U, V=V, alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  594.              \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  595.              \      sclip=nnedi3, mclip=mclip, threads=threads)
  596.     return dh
  597. }
  598.  
  599. Function nnedi3_dh (clip input, int "field", bool "Y", bool "U", bool "V", int "nsize", int "nns", int "qual", int "etype", int "pscrn",
  600.          \        float "alpha", float "beta", float "gamma", int "nrad", int "mdis",
  601.          \        bool "hp", bool "ucubic", bool "cost3", int "vcheck", float "vthresh0", float "vthresh1", float "vthresh2", clip "sclip", clip "mclip", int "threads")
  602. {
  603.     nnedi3=input.nnedi3 (field=field, dh=true, Y=Y, U=U, V=V, nsize=nsize, nns=nns, qual=qual, etype=etype, pscrn=pscrn, threads=threads)
  604.     eedi3=input.eedi3_dh (field=field, Y=Y, U=U, V=V, alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  605.              \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  606.              \      sclip=sclip, mclip=mclip, threads=threads)
  607.     dh= (nsize==3 && nns==4 && qual==2) ? nnedi3.repair (eedi3, mode=16, modeu=16, modev=16)
  608.         \          : nnedi3
  609.     return dh
  610. }
  611.  
  612. Function eedi3_dh (clip input, int "field", bool "Y", bool "U", bool "V",
  613.          \        float "alpha", float "beta", float "gamma", int "nrad", int "mdis",
  614.          \        bool "hp", bool "ucubic", bool "cost3", int "vcheck", float "vthresh0", float "vthresh1", float "vthresh2", clip "sclip", clip "mclip", int "threads")
  615. {
  616.     dh=input.eedi3 (field=field, dh=true, Y=Y, U=U, V=V, alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis,
  617.              \      hp=hp, ucubic=ucubic, cost3=cost3, vcheck=vcheck, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2,
  618.              \      sclip=sclip, mclip=mclip, threads=threads)
  619.     return dh
  620. }
  621.  
  622. Function GenEMask (clip input)
  623. {
  624.     Mask = input.Grayscale ().mt_edge ("hprewitt", 0, 255).mt_lut ("x 5 195 / 255 * -").mt_lut ("x 5 195 / 255 * -").Grayscale ()
  625.  
  626.     return Mask
  627. }
  628.  
  629. Function EDIResize16_GetCSP (clip c)
  630. {
  631.     return c.IsPlanar ? c.IsYV12 ? "YV12" :
  632.     \                   c.IsYV16 ? "YV16" :
  633.     \                   c.IsYV24 ? "YV24" : c.GetCSP_Y8_YV411 () :
  634.     \      c.IsYUY2   ? "YUY2"   :
  635.     \      c.IsRGB32  ? "RGB32"  :
  636.     \      c.IsRGB24  ? "RGB24"  : "Unknown"
  637.    
  638.    
  639.     Function GetCSP_Y8_YV411 (clip c) {
  640.         try {
  641.             c.UtoY
  642.             csp = "YV411"
  643.         } catch ( error_msg ) {
  644.         csp = "Y8"
  645.         }
  646.         return csp
  647.     }
  648. }
  649.  
  650. Function Convert8To16 (clip input, bool "tv_range")
  651. {
  652.     tv_range  = Default (tv_range, True)
  653.  
  654.     iCceil    = (255-128) / (255.5-128) * (65535.5-32768) + 32768
  655.     Yexpr     = "0-0  ;                  255-65535             ;65535-65535          "
  656.     Cexpr     = "0-0.5;0.5-0.5;128-32768;255-"+String(iCceil)+";65535-"+String(iCceil)
  657.     fullrange = StackVertical (input.Dither_gen_null_lsb (), input).
  658.     \           SmoothCurve16 (Ycurve=Yexpr, Ucurve=Cexpr, Vcurve=Cexpr, mode=0, interp=0, HQ=True,
  659.     \                          dither=-1, limiter=False, TVrange=0)                          
  660.  
  661.     output    = tv_range ? input.Dither_convert_8_to_16 ()
  662.                 \        : fullrange
  663.  
  664.     return output
  665. }
  666.  
  667. Function Round8 (clip input, bool "tv_range")
  668. {
  669.     tv_range  = Default (tv_range, True)
  670.  
  671.     iCceil    = (255-128) / (255.5-128) * (65535.5-32768) + 32768
  672.     Yexpr     = "0-0;                                           65535-255"
  673.     Cexpr     = "0-0.5;0.5-0.5;32768-128;"+String(iCceil)+"-255;65535-255"
  674.     fullrange = input.SmoothCurve16 (Ycurve=Yexpr, Ucurve=Cexpr, Vcurve=Cexpr, mode=0, interp=0, HQ=True,
  675.     \                                dither=-1, limiter=False, TVrange=0)
  676.  
  677.     output    = tv_range ? input.ditherpost (mode=-1, y=3, u=3, v=3)
  678.                 \        : fullrange.Dither_get_lsb ()
  679.  
  680.     return output
  681. }
Advertisement
Add Comment
Please, Sign In to add comment