Advertisement
mawen1250

Contra-Sharpen mod 1.0

Jun 23rd, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function CSmod(clip filtered, clip original, string "blurF", float "strength", float "divisor", float "index",
  2. \ bool "chroma", bool "preblur", bool "preblurc", bool "secure", bool "limit", bool "limit2", bool "Slimit", bool "Tlimit",
  3. \ int "preR", int "Smethod", int "Smode", int "RGmode", int "RGmodeU", int "Repmode", int "RepmodeU",
  4. \ int "Sovershoot", int "Sundershoot", int "Tovershoot", int "Tundershoot", int "Soothe")
  5. {
  6.  
  7. chroma   = Default(chroma,  false  )
  8. preblur  = Default(preblur, true   )
  9. preblurc = Default(preblurc,preblur)
  10. preR     = Default(preR,    1      )
  11. limit    = Default(limit,   true   )
  12. limit2   = Default(limit2,  limit  )
  13. RGmode   = Default(RGmode,  11     )
  14. RGmodeU  = Default(RGmodeU, RGmode )
  15. Repmode  = Default(Repmode, 1      )
  16. RepmodeU = Default(RepmodeU,Repmode)
  17. limit    = Defined(original) ? limit    : false
  18. limit2   = Defined(original) ? limit2   : false
  19. original = Defined(original) ? original : filtered
  20.  
  21. Smethod  = Default(Smethod, 1      )
  22. secure   = Default(secure,  true   )
  23. Smode    = Default(Smode,   2      )
  24. divisor  = Default(divisor, 1.5    )
  25. index    = Default(index,   0.8    )
  26. strength = Default(strength,Smode==2 ? 3.0 : 1.8)
  27.  
  28. Slimit      = Default(Slimit,      !limit    )
  29. Sovershoot  = Default(Sovershoot,  5         )
  30. Sundershoot = Default(Sundershoot, Sovershoot)
  31. Tlimit      = Default(Tlimit,      false     )
  32. Tovershoot  = Default(Tovershoot,  3         )
  33. Tundershoot = Default(Tundershoot, Tovershoot)
  34. Soothe      = Default(Soothe,      24        )
  35.  
  36.  
  37. ch31     = chroma ? 3 : 1
  38. ch32     = chroma ? 3 : 2
  39. sw       = filtered.width()
  40. sh       = filtered.height()
  41. HD       = (sw > 1024 || sh > 576) ? true : false
  42.  
  43.  
  44. allD   = mt_makediff(original, filtered, U=ch31, V=ch31)
  45. pre    = preblur ? Defined(blurF) ? Eval("filtered."+blur)
  46. \                                 : filtered.minblur(preR, chroma ? (preblurc ? 3 : 2) : 1)
  47. \                : filtered
  48.  
  49.  
  50. dark_limit   = pre.mt_inpand(U=ch31, V=ch31)
  51. bright_limit = pre.mt_expand(U=ch31, V=ch31)
  52. minmaxavg    = Smethod==1 ? NOP() : mt_average(dark_limit, bright_limit, U=ch31, V=ch31)
  53.  
  54. method = Smethod==1  ? pre      .removegrain(RGmode, chroma ? RGmodeU : -1)
  55. \      : Smethod==2  ? minmaxavg
  56. \      :               minmaxavg.removegrain(RGmode, chroma ? RGmodeU : -1)
  57.  
  58. method = secure      ? method.mt_lutxy(pre,"x y < x 1 + x y > x 1 - x ? ?", U=ch31, V=ch31) : method
  59.  
  60.  
  61. sharpdiff = mt_makediff(pre, method, U=ch31,V=ch31)
  62.  
  63. sharpdiff = Smode==1 ? sharpdiff.mt_lut(expr="x 128 - "+string(strength)+" * 128 +", U=ch31, V=ch31)
  64. \         : Smode==2 ? sharpdiff.mt_lut("x 128 - "+String(divisor)+" / Abs "+String(index)+" ^ "+String(strength)+" * x 128 > 1 -1 ? * 128 +", U=ch31, V=ch31)
  65. \                    : sharpdiff
  66.  
  67. ssDD   = limit  ? sharpdiff.repair(allD, mode=Repmode, modeU=chroma ? RepmodeU : -1) : sharpdiff
  68. ssDD   = limit2 ? ssDD.mt_lutxy(sharpdiff, "x 128 - abs y 128 - abs < x y ?", U=ch31, V=ch31) : ssDD
  69.  
  70. sclp   = filtered.mt_adddiff(ssDD, U=ch32, V=ch32)
  71.  
  72. sclp   = Slimit ? sclp.mt_clamp(bright_limit, dark_limit, Sovershoot, Sundershoot, U=ch32, V=ch32) : sclp
  73.  
  74. srcMVS = Tlimit ? pre.MSuper(hpad=0,vpad=0,pel=2,sharp=2,chroma=false) : NOP()
  75. f1v    = Tlimit ? MAnalyse(srcMVS, isb=false, delta=1, truemotion=false, blksize=HD?16:8, overlap=HD?8:4, pelsearch=2, search=2, searchparam=2, DCT=0, global=true, chroma=false) : NOP()
  76. b1v    = Tlimit ? MAnalyse(srcMVS, isb=true,  delta=1, truemotion=false, blksize=HD?16:8, overlap=HD?8:4, pelsearch=2, search=2, searchparam=2, DCT=0, global=true, chroma=false) : NOP()
  77. f1c    = Tlimit ? MCompensate(original, srcMVS, f1v, thSAD=300, thSCD1=300, thSCD2=100) : NOP()
  78. b1c    = Tlimit ? MCompensate(original, srcMVS, b1v, thSAD=300, thSCD1=300, thSCD2=100) : NOP()
  79. Tmax   = Tlimit ? original.mt_logic(f1c, "max", U=1, V=1).mt_logic(b1c, "max", U=1, V=1) : NOP()
  80. Tmin   = Tlimit ? original.mt_logic(f1c, "min", U=1, V=1).mt_logic(b1c, "min", U=1, V=1) : NOP()
  81. sclp   = Tlimit ? sclp.mt_clamp(Tmax, Tmin, Tovershoot, Tundershoot, U=2, V=2) : sclp
  82.  
  83. (Soothe>=0 && Soothe<=100) ? Soothe(sclp, filtered, keep=Soothe) : sclp
  84.  
  85. return last
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement