Advertisement
Guest User

nnchromaupsubsampling

a guest
Apr 17th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # NNEDI chroma upsubsampling v0.6 by A.SONY
  2. FUNCTION nnchromaupsubsampling(clip srco, bool "interlaced", bool "inv420") {
  3.  
  4. interlaced    = default(interlaced, false)
  5. inv420        = default(inv420    , false)
  6. ssispmt       = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
  7. sislumaonly   = ssispmt ? srco.isy() : srco.isy8()
  8. sis420        = ssispmt ? srco.is420() : srco.isyv12()
  9. sisfullchroma = ssispmt ? srco.is444() : srco.isyv24()
  10.  
  11. Assert(IsPlanar(srco) && isyuv(srco), "nnchromaupsubsampling: input clip must be planar YUV")
  12. Assert(!(Isyv12(srco) && !interlaced), "nnchromaupsubsampling: YV12/420 must be interlaced PAL DV")
  13. Assert(!(sisfullchroma || sislumaonly), "nnchromaupsubsampling: this function for subsampling sources")
  14.  
  15. src = interlaced ? srco.SeparateFields().AssumeFrameBased() : srco
  16.  
  17. chromay8     = ssispmt ? Interleave(src.ExtractU(),src.ExtractV()) : Interleave(src.UToY8(),src.VToY8())
  18. chromaturn   = !sis420 ? Eval("try { fTurnLeft(ssispmt ? nop() : chromay8) } catch(error_msg) { TurnLeft(chromay8) }").Padding(2,2,2,2).nnedi3(field=0,dh=true).crop(2,4,-2,-4,true) : nop()
  19. chromaupturn = !sis420 ? Eval("try { fTurnRight(ssispmt ? nop() : chromaturn) } catch(error_msg) { TurnRight(chromaturn) }") : nop()
  20.  
  21. chromaup = sis420 ? ssispmt ? YToUV(chromaupturn.SelectEven().Padding(2,2,2,2).nnedi3(field=inv420 ? 1 : 0,dh=true).crop(2,4,-2,-4,true),chromaupturn.SelectOdd().Padding(2,2,2,2).nnedi3(field=inv420 ? 0 : 1,dh=true).crop(2,4,-2,-4,true),src.ConvertToY()) : \
  22.                               YToUV(chromay8.SelectEven().Padding(2,2,2,2).nnedi3(field=inv420 ? 1 : 0,dh=true).crop(2,4,-2,-4,true),chromay8.SelectOdd().Padding(2,2,2,2).nnedi3(field=inv420 ? 0 : 1,dh=true).crop(2,4,-2,-4,true),src.ConvertToY8()) : \
  23.                     ssispmt ? YToUV(chromaupturn.SelectEven(),chromaupturn.SelectOdd(),src.ConvertToY()) : \
  24.                               YToUV(chromaupturn.SelectEven(),chromaupturn.SelectOdd(),src.ConvertToY8())
  25.  
  26. return interlaced ? GetParity(srco) ? chromaup.AssumeFieldBased().AssumeTFF().Weave() : chromaup.AssumeFieldBased().AssumeBFF().Weave() : chromaup
  27. }
  28.  
  29. # NNEDI chroma upsubsampling v0.4 by A.SONY (Inverse for testing purposes)
  30. FUNCTION Innchromaupsubsampling(clip srco, bool "interlaced") {
  31. srco
  32. nnchromaupsubsampling(interlaced,true)
  33. }
  34.  
  35. # NNEDI yv12 point subsampling fix v0.5 by A.SONY
  36. # the output will be yv12 in mode 2 and yv16 in mode 1 and yv24 in mode 3, convert it back to yv12 by the method you like, the default setting work with Konjiki no Gash Bell!! S1 R2J DVD
  37. FUNCTION yv12pointsamplingnnfix(clip srco, bool "interlaced", bool "top", bool "left", int "mode", bool "leftshift", int "qual", int  "nns", int "nsize", int "etype", int "pscrn", bool "eed", int "vcheck", float "vthresh0", float "vthresh1", float "vthresh2", int "nrad", int "mdis", float "alpha", float "beta", float "gamma", bool "nnrep" ) {
  38. interlaced    = default(interlaced, false)
  39. eed           = default(eed,      false)
  40. top           = default(top,       true)
  41. left          = default(left,      true)
  42. mode          = default(mode,         1)
  43. leftshift     = default(leftshift, left)
  44. nnrep         = Default(nnrep, false)
  45.  
  46. Assert(Isyv12(srco), "yv12pointsamplingnnfix: input must be YV12")
  47.  
  48. src = interlaced ? srco.SeparateFields().AssumeFrameBased() : srco
  49.  
  50. chromay8 = mode==3 || mode==1 ? Interleave(src.UToY8(),src.VToY8()) : nop()
  51.  
  52. chromay8n = mode==3 || mode==1 ? chromay8.Padding(2,2,2,2) : chromay8
  53. chromay8n = mode==3 || mode==1 ? chromay8n.nnedi3(field=top ? 1 : 0,dh=true, qual=qual, nns=nns, nsize=nsize, etype=etype, pscrn=pscrn ).crop(2,4,-2,-4,true) : chromay8n
  54. chromay8e = (mode==3 || mode==1) && eed ? chromay8.EEdi3(field=top ? 1 : 0,dh=true,sclip=chromay8n,u=false,v=false,vcheck=vcheck, nrad=nrad, mdis=mdis, alpha=alpha, beta=beta, gamma=gamma, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2) : chromay8n
  55. chromay8 = (mode==3 || mode==1) && eed && nnrep ? chromay8e.Repair(chromay8n,9) : chromay8e
  56.  
  57. chromay8 = mode==2 || mode==3 ? Eval("try { fTurnRight(mode==3 ? chromay8 : Interleave(src.UToY8(),src.VToY8())) } catch(error_msg) { TurnRight(mode==3 ? chromay8 : Interleave(src.UToY8(),src.VToY8())) }") : chromay8
  58.  
  59. chromay8n = mode==2 || mode==3 ? chromay8.Padding(2,2,2,2) : chromay8
  60. chromay8n = mode==2 || mode==3 ? chromay8n.nnedi3(field=left ? 1 : 0,dh=true, qual=qual, nns=nns, nsize=nsize, etype=etype, pscrn=pscrn ).crop(2,4,-2,-4,true) : chromay8n
  61. chromay8e = (mode==2 || mode==3) && eed ? chromay8.EEdi3(field=left ? 1 : 0,dh=true,sclip=chromay8n,u=false,v=false,vcheck=vcheck, nrad=nrad, mdis=mdis, alpha=alpha, beta=beta, gamma=gamma, vthresh0=vthresh0, vthresh1=vthresh1, vthresh2=vthresh2) : chromay8n
  62. chromay8 = (mode==2 || mode==3) && eed && nnrep ? chromay8e.Repair(chromay8n,9) : chromay8e
  63.  
  64. chromay8 = mode==2 || mode==3 ? Eval("try { fTurnLeft(chromay8) } catch(error_msg) { TurnLeft(chromay8) }") : chromay8
  65.  
  66. chromay8 = mode==2 ? chromay8.BilinearResize(width(chromay8)/2,height(chromay8),src_left=leftshift ? -0.5 : 0.5) : chromay8
  67. chromaup = YToUV(chromay8.SelectEven(),chromay8.SelectOdd(),src.ConvertToY8())
  68. return interlaced ? GetParity(srco) ? chromaup.AssumeFieldBased().AssumeTFF().Weave() :  chromaup.AssumeFieldBased().AssumeBFF().Weave() : chromaup
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement