Zastin

Desample.avsi

Nov 9th, 2017
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Avisynth 22.56 KB | None | 0 0
  1. /*Desample.avsi - v1.3
  2.  
  3. ---Included script functions---
  4. DesampleX: Wrapper for doing various things involving DesampleMT, deinterlacers, resizers, and masks
  5.            Default behavior identical to DebilinearM, can also function as lineart_rpow2
  6. DeCrossConversionMT: Replacement for ccc, ccc_720
  7.  
  8. ---Requirements---
  9. Avisynth+ r2455-MT or newer
  10.  
  11. Formats: YUV, Y
  12. Plugins: masktools2-pfmod, ResampleMT
  13. Plugins (DesampleX): RgTools-pfmod, Dither, nnedi3, nnedi3ocl, eedi2, eedi3
  14. Scripts (DesampleX): edi_rpow2, ResizeX
  15.  
  16. ---Parameters---
  17. dw, dh                            | "Native" width & height
  18. kernel                            | Desampling kernel. Takes string or integer. Mostly corresponds to the kernel strings for Dither Tools, plus "ccc" for cross-conversions
  19. b, c, p, taps, cc                 | Parameters for Debicubic (b, c), Degauss (p), Delanczos/blackman/sinc (taps), and DeCrossConversion (cc)
  20.                                   | Note that "c" will be calculated automatically based on "b" according to b+2c=1, if not supplied (i.e. 0/0.5, 0.2/0.4, 0.333/0.333)
  21.  
  22. ow, oh                            | Output width & height. Default is same as dw, dh
  23. kerneld                           | Post-Desample/edi kernel. Mostly like Dither
  24. a1d, a2d, tapsd                   | Parameters to go with kerneld
  25. edi                               | Set deinterlacer for height doubling
  26. ratiothr                          | If scaling factor >= ratiothr, use edi_rpow2 to upscale, otherwise scale normally. This was copied from nnedi3_resize16 so assume this works the same
  27.  
  28. ^ these parameters can be abused to do antialiasing while still downscaling.
  29. ratiothr=0.5 will usually work right, don't set it to 0.000001 or it'll try to double the height a million or so times
  30.  
  31. kernely, kernelc                  | When output is resized, this controls the resizer(s) for the base clip
  32. a1y, a2y, tapsy, a1c, a2c, tapsc  | Parameters for kernely/kernelc
  33. yuv444                            | Scale chroma to 4:4:4 - this does nothing when output and input resolutions are the same. Use a boolean or set to "nnedi3" to upscale chroma with nnedi3_rpow2 (don't use nnedi3 if your input is float!)
  34.  
  35. edgemask                          | Enable or disable edge masking. Default: enabled only when edi_rpow2 is used
  36. thr                               | Cutoff for the absolute error of descaling -> rescaling for a pixel to be considered distorted and included in protection mask. Set to 0 to disable
  37. expand, inflate                   | Iterations of mt_expand/inflate. mt_expand uses the pattern both/both/square for "mode"
  38. paramscale                        | masktools2 parameter, applies to "thr". Basically, mt_binarize defaults to an 8 bit scale, regardless of input depth, unless you change this
  39. rgmode                            | Which removegrain mode to use to soften the line mask
  40. blur_first                        | Whether to use removegrain on the line mask before or after subtracting the error mask
  41. exmask                            | External edgemask string/clip. Renders rgmode and blur_first moot. Error mask is still subtracted from this clip
  42.                                   | i.e. a clip: exmask=last.mt_edge("hprewitt") or a string: exmask="""des.mt_edge("hprewitt")""" - desampled clip is "des", or normal clip is "src" (needs ExtractY)
  43. show                              | Display mask (0 = normal output, 1 = credits mask, 2 = full mask) Mask is overlayed 50% onto the output clip: set negative values for the raw mask clip
  44.  
  45. (DesampleMask)
  46. ow, oh                            | Mask "output" width & height, for masking at a different resolution
  47. dw, dh                            | Descaled clip width & height. You don't usually need to set this
  48.  
  49. ---Notes---
  50. Desample can have a sharpening effect on low detail areas; grain added after upscaling, blocking, noise, etc. It may be a good idea to enable the edgemask even when not using edi_rpow2
  51.  
  52. Due to its very destructive nature, using an error mask with ccc can give a very high error, causing false positives which will be much more noticeable than usual. To deal with this, I would recommend scene-
  53. filtering things like text overlays manually to only mask those scenes, and if possible limiting the mask to those black and white areas only, using the input clip's luma, DesampleMask with thr=0, and mt_lutxy
  54.  
  55. ---Changelog---
  56. v1.3.0 - DeCrossConversionMT actually works now
  57. v1.2.2 - Set DeCrossConversionMT "order" default to 1 (vertical first)
  58. v1.2.1 - Fix YV12 chroma center shift
  59. v1.2.0 - Add nnedi3 YV12 -> YV24
  60. v1.1.0 - Fixes and "exmask" enhancement
  61. v1.0.0 - Initial release
  62.  
  63. */
  64.  
  65. # TODO: saner controls over antialiasing features. maybe rfactor override
  66. #       allow setting a second, lower thr value to smooth 0 - 255 from thr1 -> thr2
  67. Function DesampleX(clip src, int "dw", int "dh", val "kernel", float "b", float "c", float "p", int "taps", float "cc", \
  68.                    int "ow", int "oh", string "kerneld", float "a1d", float "a2d", int "tapsd", string "edi", float "ratiothr", \
  69.                    string "kernely", float "a1y", float "a2y", int "tapsy", string "kernelc", float "a1c", float "a2c", int "tapsc", val "yuv444", \
  70.                    bool "edgemask", float "thr", int "expand", int "inflate", string "paramscale", int "rgmode", bool "blur_first", val "exmask", int "show", \
  71.                    int "nsize", int "nns", int "qual", int "etype", int "pscrn", int "edi_threads", int "opt", int "fapprox", \
  72.                    float "alpha", float "beta", float "gamma", int "nrad", int "mdis", bool "hp", bool "ucubic", bool "cost3", \
  73.                    int "vcheck", float "vthresh0", float "vthresh1", float "vthresh2", string "sclip", string "sclip_params", clip "mclip", \
  74.                    int "mthresh", int "lthresh", int "vthresh", int "estr", int "dstr", int "maxd", int "map", int "nt", int "pp", bool "mt", string "mt_params", \
  75.                    int "threads", bool "logicalCores", bool "MaxPhysCore", bool "SetAffinity", bool "sleep", int "prefetch", int "range", int "accuracy", int "order"){
  76.                    # Row 1: Desample parameters
  77.                    # Row 2: Post-Desample/edi resizing parameters
  78.                    # Row 3: Base clip resizing parameters
  79.                    # Row 4: masking parameters
  80.                    # Rows 5-8: edi parameters
  81.                    # Row 9: More Desample parameters
  82.    
  83.     assert(!src.IsRGB, "DesampleX: YUV and Y format only")
  84.    
  85.     bits = src.BitsPerComponent
  86.     none = Undefined()
  87.    
  88.     ratiothr = Default(ratiothr, 1.125)
  89.    
  90.     iw = src.Width
  91.     w = default(dw,1280)
  92.     ow = default(ow, w)
  93.     wratio = (float(ow) / float(w))/ratiothr
  94.     rfactorX = wratio > 1 ? Round(Pow(2, Ceil( log(wratio) / log(2) ))) : 1
  95.    
  96.     ih = src.Height
  97.     h = default(dh,720)
  98.     oh = default(oh, h)
  99.     hratio = (float(oh) / float(h))/ratiothr
  100.     rfactorY = hratio > 1 ? Round(Pow(2, Ceil( log(hratio) / log(2) ))) : 1
  101.    
  102.     kernel = default(kernel, "bilinear")
  103.     kernel = isint(kernel) ? select(kernel, "ccc", "bilinear", "bicubic", "lanczos", "spline16", "spline36", "spline64", "blackman", "gauss", "sinc") : kernel
  104.     kerneld = default(kerneld, "spline36")
  105.     kernely = default(kernely, "spline36")
  106.     kernelc = default(kernelc, kernely)
  107.     b = default(b, 1.0/3.0)
  108.     c = default(c, (1.0-b)/2.0)
  109.     p = default(p, 30.0)
  110.     yuv444 = default(yuv444, ow%2==1 || oh%2==1)
  111.    
  112.     edi = default(edi, "nnedi3")
  113.    
  114.     edgemask = default(edgemask, edi!="" && (rfactorX>1 || rfactorY>1))
  115.     thr = default(thr, 10)
  116.     expand = default(expand, min(max((iw - 960)/320, (ih - 540)/180), 6))
  117.     inflate = default(inflate, max(expand, 2))
  118.     rgmode = default(rgmode, iw < 960 || ih < 720 ? 11 : 20)
  119.     blur_first = default(blur_first, true)
  120.     show = default(show,0)
  121.    
  122.     usemask = Defined(exmask) || edgemask || thr>0
  123.    
  124.     show!=0 ? assert(usemask, "DesampleX: Mask cannot be previewed while disabled") : NOP()
  125.    
  126.     srcy = src.ExtractY()
  127.    
  128.     src = iw==ow && ih==oh ? src : src.Resize(ow, oh, kernely, a1y, a2y, tapsy, kernelc, a1c, a2c, tapsc, yuv444, !usemask)
  129.    
  130.     down = srcy.Desample_internal(w, h, none, none, none, none, kernel, b, c, p, taps, cc, threads, logicalCores, MaxPhysCore, SetAffinity, sleep, prefetch, range, accuracy, order)
  131.     errmask = thr>0 ? down.DesampleMask(srcy, ow, oh, w, h, thr, expand, inflate, kernel, b, c, p, taps, cc, paramscale) : NOP()
  132.    
  133.     (rfactorX<2 && rfactorY<2) || edi=="" ? Eval("""
  134.        des = ow==w && oh==h ? down : down.Resize(ow, oh, kerneld, a1d, a2d, tapsd)
  135.    """) : Eval("""
  136.        des = bits>8 ? down.ConvertBits(8, dither=1) : down
  137.        des = des.edi_rpow2(rfactorX, rfactorY, edi, kerneld+"resize", ow, oh, tapsd, a1d, a2d, none, true, false, false, bits>8, true, none,
  138.                           \nsize, nns, qual, etype, pscrn, edi_threads, opt, fapprox, alpha, beta, gamma, nrad, mdis, hp, ucubic, cost3,
  139.                           \vcheck, vthresh0, vthresh1, vthresh2, sclip, sclip_params, mclip, mthresh, lthresh, vthresh, estr, dstr, maxd,
  140.                           \map, nt, pp, mt, mt_params)
  141.        des = bits>8 ? des.ConvertFromStacked(16) : des
  142.        des = bits==8 || bits==16 ? des : des.ConvertBits(bits)
  143.    """)
  144.    
  145.     Defined(exmask) ? Eval("""
  146.        exmask = IsString(exmask) ? Eval(exmask) : exmask
  147.        mask = thr>0 ? exmask.mt_lutxy(errmask, "x y -") : exmask
  148.    """) : edgemask ? Eval("""
  149.        lines = des.mt_edge("prewitt", 4, 24)
  150.        
  151.        lines = (kernel=="bicubic" && c > 0.5) || kernel=="lanczos" ? lines.mt_expand() : lines
  152.        lines = kernel=="blackman" || kernel=="spline16" || kernel=="spline36" || kernel=="spline64" ? lines.mt_inflate() : lines
  153.        lines = kernel=="sinc" ? lines.mt_expand().mt_expand().mt_inflate().mt_inflate() : lines
  154.        
  155.        lines = blur_first ? lines.removegrain(rgmode) : lines
  156.        
  157.        mask = thr>0 ? blur_first || inflate>0 ? lines.mt_lutxy(errmask, "x y -") : errmask.mt_logic(lines, "andn") : lines
  158.        mask = blur_first ? mask : mask.removegrain(rgmode)
  159.    """) : thr > 0 ? Eval("""
  160.        mask = errmask
  161.    """) : NOP()
  162.    
  163.     return usemask ? show>0 ? mt_merge(src, src.BlankClip(color=$35FF11), show==1?errmask.clamp():mask.clamp(), luma=true)
  164.     \                       : show<0 ? show==-1 ? errmask : mask
  165.     \                                : edgemask || Defined(exmask) ? mt_merge(src, des, mask)
  166.     \                                                              : mt_merge(des.csp(src), src, mask, u=4, v=4)
  167.     \              : src.IsYUV ? CombinePlanes(des, src, planes="YUV", source_planes="YUV", sample_clip=src) : des
  168.    
  169.     Function clamp(clip clip){clip.mt_clamp(clip.BlankClip(color=$808080), clip.BlankClip(), overshoot=0, undershoot=0)}
  170.     Function csp(clip clip, clip ref){return ref.IsY ? clip : ref.Is420 ? clip.converttoyuv420() : ref.Is422 ? clip.converttoyuv422() : ref.Is444 ? clip.converttoyuv444() : clip.converttoyv411()}
  171.     Function Desample_internal(clip src, int w, int h, float "src_left", float "src_top", float "src_width", float "src_height", string "kernel", float "b", float "c", float "p", int "taps", float "cc", \
  172.                       int "threads", bool "logicalCores", bool "MaxPhysCore", bool "SetAffinity", bool "sleep", int "prefetch", int "range", int "accuracy", int "order"){
  173.         src
  174.         return kernel=="point"                     ? pointresize(w, h, src_left, src_top, src_width, src_height)
  175.         \ : kernel=="bilinear" || kernel=="linear" ? DeBilinearResizeMT(w, h, src_left, src_top, src_width, src_height, threads, logicalCores, MaxPhysCore, SetAffinity, sleep, prefetch, range, accuracy, order)
  176.         \ : kernel=="bicubic" || kernel=="cubic"   ? DeBicubicResizeMT(w, h, b, c, src_left, src_top, src_width, src_height, threads, logicalCores, MaxPhysCore, SetAffinity, sleep, prefetch, range, accuracy, order)
  177.         \ : kernel=="lanczos"                      ? DeLanczosResizeMT(w, h, src_left, src_top, src_width, src_height, taps, threads, logicalCores, MaxPhysCore, SetAffinity, sleep, prefetch, range, accuracy, order)
  178.         \ : kernel=="lanczos4"                     ? DeLanczos4ResizeMT(w, h, src_left, src_top, src_width, src_height, threads, logicalCores, MaxPhysCore, SetAffinity, sleep, prefetch, range, accuracy, order)
  179.         \ : kernel=="spline16"                     ? DeSpline16ResizeMT(w, h, src_left, src_top, src_width, src_height, threads, logicalCores, MaxPhysCore, SetAffinity, sleep, prefetch, range, accuracy, order)
  180.         \ : kernel=="spline36"                     ? DeSpline36ResizeMT(w, h, src_left, src_top, src_width, src_height, threads, logicalCores, MaxPhysCore, SetAffinity, sleep, prefetch, range, accuracy, order)
  181.         \ : kernel=="spline64"                     ? DeSpline64ResizeMT(w, h, src_left, src_top, src_width, src_height, threads, logicalCores, MaxPhysCore, SetAffinity, sleep, prefetch, range, accuracy, order)
  182.         \ : kernel=="blackman"                     ? DeBlackmanResizeMT(w, h, src_left, src_top, src_width, src_height, taps, threads, logicalCores, MaxPhysCore, SetAffinity, sleep, prefetch, range, accuracy, order)
  183.         \ : kernel=="gauss" || kernel=="gaussian"  ? DeGaussResizeMT(w, h, src_left, src_top, src_width, src_height, p, threads, logicalCores, MaxPhysCore, SetAffinity, sleep, prefetch, range, accuracy, order)
  184.         \ : kernel=="sinc"                         ? DeSincResizeMT(w, h, src_left, src_top, src_width, src_height, taps, threads, logicalCores, MaxPhysCore, SetAffinity, sleep, prefetch, range, accuracy, order)
  185.         \ : kernel=="ccc"                          ? DeCrossConversionMT(w, h, cc, taps, threads, logicalCores, MaxPhysCore, SetAffinity, sleep, prefetch, range, accuracy, order)
  186.         \                                          : assert(false, "DesampleX: Invalid kernel setting")
  187.         }
  188.     }
  189.  
  190. # TODO: Implement option for luma-matching to catch only black/white credits
  191. #       see if abusing floats when binarizing and downscaling the mask works in Avisynth
  192. #       Add src_left/top
  193. Function DesampleMask(clip descaled, clip input, int "ow", int "oh", float "dw", float "dh", float "thr", int "expand", int "inflate", val "kernel", float "b", float "c", float "p", int "taps", float "cc", string "paramscale"){
  194.     iw = input.Width
  195.     ih = input.Height
  196.     dw = default(dw, descaled.Width)
  197.     dh = default(dh, descaled.Height)
  198.     ow = default(ow, round(dw))
  199.     oh = default(oh, round(dh))
  200.     thr = default(thr, 10)
  201.     expand = default(expand, min(max((iw - 960)/320, (ih - 540)/180), 6))
  202.     inflate = default(inflate, max(expand, 2))
  203.     kernel = default(kernel, "bilinear")
  204.     b = default(b, 1.0/3.0)
  205.     c = default(c, (1.0-b)/2.0)
  206.     paramscale = default(paramscale, "i8")
  207.    
  208.     kernel = isint(kernel) ? select(kernel, "ccc", "bilinear", "bicubic", "lanczos", "spline16", "spline36", "spline64", "blackman", "gauss", "sinc") : kernel
  209.    
  210.     resc = descaled.DeDesample(iw, ih, dw, dh, kernel, b, c, p, taps, cc)
  211.    
  212.     error = mt_lutxy(input, resc, "x y - abs", chroma="process")
  213.    
  214.     mask = thr>0 ? error.mt_binarize(thr, chroma="process", paramscale=paramscale) : error
  215.     mask = ow==iw && oh==ih ? mask : mask.bilinearresize(ow, oh).mt_binarize(3, chroma="process")
  216.     mask = expand>0 ? mask.expand_rec(expand) : mask
  217.     mask = inflate>0 ? mask.inflate_rec(inflate) : mask
  218.    
  219.     return mask
  220.    
  221.     Function expand_rec(clip clp, int iter){return iter==0 ? clp : clp.mt_expand(chroma="process", mode=iter%3==0?"square":"both").expand_rec(iter-1)}
  222.     Function inflate_rec(clip clp, int iter){return iter==0 ? clp : clp.mt_inflate(chroma="process").inflate_rec(iter-1)}
  223.     Function DeDesample(clip src, int iw, int ih, float dw, float dh, string "kernel", float "b", float "c", float "p", int "taps", float "cc"){
  224.         src
  225.         return kernel=="point"                        ? pointresize(iw, ih, 0, 0, dw, dh)
  226.         \    : kernel=="bilinear" || kernel=="linear" ? bilinearresize(iw, ih, 0, 0, dw, dh)
  227.         \    : kernel=="bicubic" || kernel=="cubic"   ? bicubicresize(iw, ih, b, c, 0, 0, dw, dh)
  228.         \    : kernel=="lanczos"                      ? lanczosresize(iw, ih, 0, 0, dw, dh, taps)
  229.         \    : kernel=="lanczos4"                     ? lanczos4resize(iw, ih, 0, 0, dw, dh)
  230.         \    : kernel=="spline16"                     ? spline16resize(iw, ih, 0, 0, dw, dh)
  231.         \    : kernel=="spline36"                     ? spline36resize(iw, ih, 0, 0, dw, dh)
  232.         \    : kernel=="spline64"                     ? spline64resize(iw, ih, 0, 0, dw, dh)
  233.         \    : kernel=="blackman"                     ? blackmanresize(iw, ih, 0, 0, dw, dh, taps)
  234.         \    : kernel=="gauss" || kernel=="gaussian"  ? gaussresize(iw, ih, 0, 0, dw, dh, p)
  235.         \    : kernel=="sinc"                         ? sincresize(iw, ih, 0, 0, dw, dh, taps)
  236.         \    : kernel=="ccc"                          ? crossconversion(iw, ih, cc)
  237.         \                                             : assert(false, "DesampleMask: invalid kernel")
  238.         }
  239.     }
  240.  
  241.  
  242. # Unlike CCC, this doesn't scale chroma normally, so you'll have to do that yourself
  243. Function DeCrossConversionMT(clip src, int "target_width", int "target_height", float "cc", \
  244.                     int "threads", bool "logicalCores", bool "MaxPhysCore", bool "SetAffinity", \
  245.                     bool "sleep", int "prefetch", int "range", int "accuracy", int "order"){
  246.    
  247.     target_width = default(target_width, 1280)
  248.     target_height = default(target_height, 720)
  249.     order = default(order, 1)
  250.     cc = default(cc, 0.0)
  251.    
  252.     assert(target_height % 2 == 0, "DeCrossConversionMT: Height must be even")
  253.    
  254.     fh = float(target_height/2)
  255.     sfac = float(target_height) / float(src.Height)
  256.     cc = -cc * sfac
  257.    
  258.     sf = src.separatefields()
  259.    
  260.     e = sf.selecteven().DeBilinearResizeMT(target_width, target_height/2, src_top=-cc, src_height=fh-cc, \
  261.                                           threads=threads, logicalCores=logicalCores, MaxPhysCore=MaxPhysCore, SetAffinity=SetAffinity, \
  262.                                           sleep=sleep, prefetch=prefetch, range=range, accuracy=accuracy, order=order)
  263.     o = sf.selectodd().DeBilinearResizeMT(target_width, target_height/2, src_top=cc, src_height=fh+cc, \
  264.                                           threads=threads, logicalCores=logicalCores, MaxPhysCore=MaxPhysCore, SetAffinity=SetAffinity, \
  265.                                           sleep=sleep, prefetch=prefetch, range=range, accuracy=accuracy, order=order)
  266.     return interleave(e,o).weave()
  267.     }
  268.  
  269. Function crossconversion(clip src, int w, int h, float cc){
  270.     src.separatefields()
  271.     fh = float(last.Height)
  272.     sfac = (fh * 2.) / float(h)
  273.     cc = -cc * sfac
  274.     e = selecteven().bilinearresize(w, h/2, src_top=-cc, src_height=fh-cc)
  275.     o = selectodd().bilinearresize(w, h/2, src_top=cc, src_height=fh+cc)
  276.     return interleave(e, o).weave()
  277.     }
  278.    
  279. Function Resize(clip src, int "w", int "h", string "kernely", float "a1y", float "a2y", int "tapsy", string "kernelc", float "a1c", float "a2c", int "tapsc", val "yuv444", bool "trashluma"){
  280.     bits = src.BitsPerComponent
  281.    
  282.     yuv444 = Default(yuv444, false)
  283.     trashluma = Default(trashluma, false)
  284.    
  285.     nnedi3_uv = IsString(yuv444)
  286.     yuv444 = nnedi3_uv ? true : yuv444
  287.    
  288.     # love that trend of never adding plane parameters to core filters
  289.     src8   = nnedi3_uv && bits>8 ? bits==16 ? src.ConvertToStacked().DitherPost(mode=6, y=1)  
  290.     \                                       : src.ConvertBits(8, dither=1)
  291.     \                            : Undefined()
  292.     u_clip = nnedi3_uv && bits>8 ? src8.ExtractU() : src.ExtractU()
  293.     v_clip = nnedi3_uv && bits>8 ? src8.ExtractV() : src.ExtractV()
  294.    
  295.     yuv = src.IsYUV
  296.     hss = src.IsYV411 ? 4 : src.Is420 || src.Is422 ? 2 : 1
  297.     vss = src.Is420 ? 2 : 1
  298.    
  299.     cw = yuv444 ? w : w/hss
  300.     ch = yuv444 ? h : h/vss
  301.     sx = hss>1 ? yuv444 ? 0.25 : calign(src.Width, w, hss) : 0
  302.    
  303.     return trashluma ? yuv ? CombinePlanes(u_clip.Resize_internal_uv(cw, ch, sx, kernelc, a1c, a2c, tapsc, nnedi3_uv, bits),
  304.                                           \v_clip.Resize_internal_uv(cw, ch, sx, kernelc, a1c, a2c, tapsc, nnedi3_uv, bits),
  305.                                           \planes="UV", source_planes="YY", sample_clip=src)
  306.     \                      : Undefined()
  307.     \      : !yuv || hss==1 ? src.Resize_internal(w, h, 0,  0, kernely, a1y, a2y, tapsy)
  308.     \                       : CombinePlanes(src.ExtractY().Resize_internal(w, h,  0,  0, kernely, a1y, a2y, tapsy),
  309.                                            \u_clip.Resize_internal_uv(cw, ch, sx, kernelc, a1c, a2c, tapsc, nnedi3_uv, bits),
  310.                                            \v_clip.Resize_internal_uv(cw, ch, sx, kernelc, a1c, a2c, tapsc, nnedi3_uv, bits),
  311.                                            \planes="YUV", source_planes="YYY", sample_clip=src)
  312.    
  313.     Function calign(float in, float out, int hss){return hss==2 ? 0.25*(1.0-in/out) : 0.375*(1.0-in/out)}
  314.    
  315.     Function Resize_internal_uv(clip src, int w, int h, float sx, string "kernel", float "a1", float "a2", int "taps", bool "usennedi3", int "bits"){
  316.         src
  317.         usennedi3           ? nnedi3_rpow2(2)   : last
  318.         usennedi3 && bits>8 ? ConvertBits(bits) : last
  319.         Resize_internal(w, h, usennedi3 ? 0 : sx, usennedi3 ? -0.5 : 0, kernel, a1, a2, taps)
  320.         }
  321.    
  322.     Function Resize_internal(clip src, int w, int h, float sx, float sy, string "kernel", float "a1", float "a2", int "taps"){
  323.         src
  324.         return kernel=="point"                        ? pointresize(w, h, sx, sy)
  325.         \    : kernel=="bilinear" || kernel=="linear" ? bilinearresize(w, h, sx, sy)
  326.         \    : kernel=="bicubic" || kernel=="cubic"   ? bicubicresize(w, h, a1, a2, sx, sy)
  327.         \    : kernel=="lanczos"                      ? lanczosresize(w, h, sx, sy, taps=taps)
  328.         \    : kernel=="lanczos4"                     ? lanczos4resize(w, h, sx, sy)
  329.         \    : kernel=="spline16"                     ? spline16resize(w, h, sx, sy)
  330.         \    : kernel=="spline36"                     ? spline36resize(w, h, sx, sy)
  331.         \    : kernel=="spline64"                     ? spline64resize(w, h, sx, sy)
  332.         \    : kernel=="blackman"                     ? blackmanresize(w, h, sx, sy, taps=taps)
  333.         \    : kernel=="gauss" || kernel=="gaussian"  ? gaussresize(w, h, sx, sy, p=a1)
  334.         \    : kernel=="sinc"                         ? sincresize(w, h, sx, sy, taps=taps)
  335.         \                                             : assert(false, "DesampleX: invalid kernely or kernelc")
  336.         }
  337.     }
Advertisement
Add Comment
Please, Sign In to add comment