Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # LimitedSharpen()   ( a modded version, 29 Oct 2005 )
  2. #
  3. # A multi-purpose sharpener by Didée
  4. #
  5. #
  6. # Changes in this mod:
  7. #
  8. # - RemoveGrain >= v0.9  IS REQUIRED!!
  9. #   ==================================
  10. #
  11. # - Smode=4   / sometimes does the magic ;-)
  12. # - a separate "undershoot" parameter, to allow for some line darkening in comic or Anime
  13. # - Lmode=3   / on edges, limited sharpening with zero OS & US. On not-edges, limited sharpening with specified OS + LS
  14. # - "soft" acts different now: no more boolean true/false, but instead integer 0 - 100  (or -1 -> automatic)
  15. #    instead of blurring before finding minima/maxima, it now softens the "effect-of-sharpening"
  16. # - edgemode=-1 now shows the edgemask. (scaling still not implemented :p )
  17. #
  18. ## - MODIFIED version using MaskTools 2.0
  19.  
  20. function LimitedSharpenFaster( clip clp,
  21.  \                       float "ss_x",   float "ss_y",
  22.  \                       int   "dest_x", int   "dest_y",
  23.  \                       int   "Smode" , int   "strength", int  "radius",
  24.  \                       int   "Lmode",  bool  "wide",     int  "overshoot", int "undershoot",
  25.  \                       int   "soft",   int   "edgemode", bool "special",
  26.  \                       int   "exborder" )
  27. {
  28. ox = clp.width
  29. oy = clp.height
  30.  
  31. Smode     = default( Smode,       3 )
  32. ss_x      = (Smode==4)
  33.  \        ? default( ss_x,      1.25)
  34.  \        : default( ss_x,      1.5 )
  35. ss_y      = (Smode==4)
  36.  \        ? default( ss_y,      1.25)
  37.  \        : default( ss_y,      1.5 )
  38. dest_x    = default( dest_x,     ox )
  39. dest_y    = default( dest_y,     oy )
  40. strength  = (Smode==1)
  41.  \        ? default( strength,  160 )
  42.  \        : default( strength,  100 )
  43. strength  = (Smode==2&&strength>100) ? 100 : strength
  44. radius    = default( radius,      2 )
  45. Lmode     = default( Lmode,       1 )
  46. wide      = default( wide,    false )
  47. overshoot = default( overshoot, 1)
  48. undershoot= default( undershoot, overshoot)
  49. softdec   = default( soft,        0 )
  50. soft    =  softdec!=-1 ? softdec : sqrt( (((ss_x+ss_y)/2.0-1.0)*100.0) ) * 10
  51. soft    = soft>100 ? 100 : soft
  52. edgemode  = default( edgemode,    0 )
  53. special   = default( special, false )
  54. exborder  = default( exborder, 0)
  55. #radius =   round( radius*(ss_x+ss_y)/2)  #  If it's you, Mug Funky - feel free to activate it again  
  56. xxs=round(ox*ss_x/8)*8
  57. yys=round(oy*ss_y/8)*8
  58. smx=exborder==0?dest_x:round(dest_x/Exborder/4)*4
  59. smy=exborder==0?dest_y:round(dest_y/Exborder/4)*4
  60.  
  61. clp.isYV12() ? clp : clp.converttoyv12()
  62.  
  63. ss_x != 1.0 || ss_y != 1.0 ? last.lanczosresize(xxs,yys) : last
  64. tmp = last
  65.  
  66. edge = mt_logic( tmp.mt_edge(thY1=0,thY2=255,"8 16 8 0 0 0 -8 -16 -8 4")
  67.  \              ,tmp.mt_edge(thY1=0,thY2=255,"8 0 -8 16 0 -16 8 0 -8 4")
  68.  \              ,"max") .mt_lut("x 128 / 0.86 ^ 255 *") #.levels(0,0.86,128,0,255,false)
  69.  
  70. tmpsoft       = tmp.removegrain(11,-1)
  71. dark_limit1   = tmp.mt_inpand()
  72. bright_limit1 = tmp.mt_expand()
  73. dark_limit    = (wide==false) ? dark_limit1   : dark_limit1  .removegrain(20,-1).mt_inpand()
  74. bright_limit  = (wide==false) ? bright_limit1 : bright_limit1.removegrain(20,-1).mt_expand()
  75. minmaxavg     = special==false
  76.  \            ? mt_average(dark_limit1, bright_limit1)
  77.  \            : mt_merge(dark_limit,bright_limit,tmp.removegrain(11,-1),Y=3,U=-128,V=-128)
  78.  
  79. Str=string(float(strength)/100.0)
  80. normsharp = Smode==1 ? unsharpmask(strength,radius,0)
  81.  \        : Smode==2 ? sharpen(float(strength)/100.0)
  82.  \        : Smode==3 ? mt_lutxy(tmp,minmaxavg,yexpr="x x y - "+Str+" * +")
  83.  \        :            mt_lutxy(tmp,tmpsoft,"x y == x x x y - abs 16 / 1 2 / ^ 16 * "+Str+
  84.  \                       " * x y - 2 ^ x y - 2 ^ "+Str+" 100 * 25 / + / * x y - x y - abs / * + ?")
  85.  
  86. OS = string(overshoot)
  87. US = string(undershoot)
  88. mt_lutxy( bright_limit, normsharp, yexpr="y x "+OS+" + < y x y x - "+OS+" - 1 2 / ^ + "+OS+" + ?")
  89. mt_lutxy( dark_limit, last, yexpr="y x "+US+" - > y x x y - "+US+" - 1 2 / ^ - "+US+" - ?")
  90.  
  91. Lmode==1 ? mt_clamp(normsharp, bright_limit, dark_limit, overshoot, undershoot) : last
  92.  
  93. normal = last
  94. zero   = mt_clamp(normsharp, bright_limit, dark_limit, 0,0)
  95.  
  96. Lmode==3 ? mt_merge(normal,zero,edge.mt_inflate()) : normal
  97.  
  98.       edgemode==0  ?  last
  99.  \  : edgemode==1  ?  mt_merge(tmp,last,edge.mt_inflate().mt_inflate().removegrain(11,-1),Y=3,U=1,V=1)
  100.  \  :                 mt_merge(last,tmp,edge.mt_inflate().mt_inflate().removegrain(11,-1),Y=3,U=1,V=1)
  101.  
  102. AMNT  = string(soft)
  103. AMNT2 = string(100-soft)
  104. sharpdiff=mt_makediff(tmp,last)
  105. sharpdiff2=mt_lutxy(sharpdiff,sharpdiff.removegrain(19,-1),
  106.  \           "x 128 - abs y 128 - abs > y "+AMNT+" * x "+AMNT2+" * + 100 / x ?")
  107.  
  108. soft==0 ? last : mt_makediff(tmp,sharpdiff2)
  109.  
  110.      (ss_x != 1.0 || ss_y != 1.0)
  111. \ || (dest_x != ox || dest_y != oy) ? lanczosresize(dest_x,dest_y) : last
  112.  
  113. ex=blankclip(last,width=smx,height=smy,color=$FFFFFF).addborders(2,2,2,2).coloryuv(levels="TV->PC")
  114.  \.blur(1.3).mt_inpand().blur(1.3).bicubicresize(dest_x,dest_y,1.0,.0)
  115. tmp =  clp.lanczosresize(dest_x,dest_y)
  116.  
  117. clp.isYV12() ? ( exborder==0 ? tmp.mergeluma(last)
  118.  \                           : mt_merge(tmp,last,ex,Y=3,U=1,V=1) )
  119.  \           : ( exborder==0 ? tmp.mergeluma(last.converttoyuy2())
  120.  \                           : tmp.mergeluma( mt_merge(tmp.converttoyv12(),last,ex,Y=3,U=1,V=1)
  121.  \                                           .converttoyuy2()) )
  122.  
  123. (edgemode!= -1) ? last : edge.lanczosresize(dest_x,dest_y).greyscale
  124.  
  125. return last
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement