Advertisement
mirkosp

Untitled

Apr 15th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #quadratura v1.0 by mirkosp
  2. #Substitutes the outer clip's selected area with the same area in the inner clip.
  3. #Make sure outer and inner clips are of the same resolution and colourspace.
  4. #If sources are, for example, both YUV, but with different subsampling, the filter
  5. #will still work with the avisynth's default behaviour to determine which subsampling will be used.
  6. #x, y, w, and h work as with avisynth's crop to determine the area.
  7. #In order to allow odd values to be used with YUV sources, I am using Overlay.
  8. #However, since overlay would internally convert RGB sources to YUV,
  9. #I am using it only if the sources are YUV to avoid colourspace conversions,
  10. #which means that the opacity parameter is ignored with RGB sources.
  11. #If you want to overlay them so badly, convert to YUV yourself before using this script.
  12. #I don't want to be responsible for incorrect RGB->YUV conversions,
  13. #even more so because they're lossy and should be avoided if not necessary.
  14. #For fine tuning of the area, turn on show.
  15.  
  16. function quadratura (clip outer, clip inner, int "x", int "y", int "w", int "h", float "opacity", bool "show") {
  17. x = default(x,0)
  18. y = default(y,0)
  19. w = default(w,outer.width)
  20. h = default(h,outer.height)
  21. opacity = default(opacity,1.0)
  22. show = default(show,false)
  23.  
  24. #brainfarts check
  25. x = (x < 0) ? 0 : x
  26. x = (x > outer.width) ? outer.width : x
  27. y = (y < 0) ? 0 : y
  28. y = (y > outer.height) ? 0 : y
  29. w = (w < -(outer.width)) ? (outer.width-x) : w
  30. w = (w > (outer.width-x)) ? (outer.width-x) : w
  31. h = (h < -(outer.height)) ? (outer.height-y) : h
  32. h = (h > (outer.height-y)) ? (outer.height-y) : h
  33. opacity = (opacity < 0) ? 0 : (opacity > 1) ? 1 : opacity
  34. assert(outer.width == inner.width, "Outer and inner clips must have the same width.")
  35. assert(outer.height == inner.height, "Outer and inner clips must have the same height.")
  36. assert(outer.isrgb == inner.isrgb, "Outer and inner clips must have the same colourspace.")
  37. assert((x > (w+outer.width)) ? (w <=0) : (x < (w + outer.width)), "Dude... wait, what? Check x and w.")
  38. assert((y > (h+outer.height)) ? (h <=0) : (y < (h + outer.height)), "Dude... wait, what? Check y and h.")
  39. assert((x <> 0) || (y <> 0) || (( w <> inner.width) && (w <> 0)) || ((h <> inner.height) && (h <> 0)), "Just keep inner, bro.")
  40.  
  41. #I don't want to handle all of the special cases, so I'll be doing this instead
  42. co = outer.isrgb ? outer : blankclip(outer,outer.framecount,color=$000000,pixel_type="RGB32")
  43. ci = inner.isrgb ? (show ? outer.invert() : inner) : blankclip(inner,inner.framecount,color=$FFFFFF,pixel_type="RGB32")
  44. co = co.addborders(2,2,2,2)
  45. ci = ci.addborders(2,2,2,2)
  46. x = x+2
  47. y = y+2
  48. w = (w > 0) ? w : w-2
  49. h = (h > 0) ? h : h-2
  50. #now stuff happens, though maybe it could happen faster
  51. cs = stackvertical(co.crop(0,0,0,y),stackhorizontal(co.crop(0,y,x,h),ci.crop(x,y,w,h),co.crop(((w > 0) ? x+w : (co.width)+w),y,0,h)),co.crop(0,((h > 0) ? y+h : (co.height)+h),0,0))
  52. cs = cs.crop(2,2,-2,-2)
  53. return outer.isrgb ? cs : overlay(outer,(show ? outer.invert : inner),opacity=(show ? 1.0 : opacity),mask=cs)
  54. }
  55.  
  56. #this mod doesn't use overlay, so it doesn't incur in the overlay bug of overlay() and mt_merge()
  57. function quadraturamod (clip outer, clip inner, int "x", int "y", int "w", int "h", float "opacity", bool "show") {
  58. x = default(x,0)
  59. y = default(y,0)
  60. w = default(w,outer.width)
  61. h = default(h,outer.height)
  62. opacity = default(opacity,1.0)
  63. show = default(show,false)
  64.  
  65. #brainfarts check
  66. x = (x < 0) ? 0 : x
  67. x = (x > outer.width) ? outer.width : x
  68. y = (y < 0) ? 0 : y
  69. y = (y > outer.height) ? 0 : y
  70. w = (w < -(outer.width)) ? (outer.width-x) : w
  71. w = (w > (outer.width-x)) ? (outer.width-x) : w
  72. h = (h < -(outer.height)) ? (outer.height-y) : h
  73. h = (h > (outer.height-y)) ? (outer.height-y) : h
  74. opacity = (opacity < 0) ? 0 : (opacity > 1) ? 1 : opacity
  75. assert(outer.width == inner.width, "Outer and inner clips must have the same width.")
  76. assert(outer.height == inner.height, "Outer and inner clips must have the same height.")
  77. assert(outer.isrgb == inner.isrgb, "Outer and inner clips must have the same colourspace.")
  78. assert((x > (w+outer.width)) ? (w <=0) : (x < (w + outer.width)), "Dude... wait, what? Check x and w.")
  79. assert((y > (h+outer.height)) ? (h <=0) : (y < (h + outer.height)), "Dude... wait, what? Check y and h.")
  80. assert((x <> 0) || (y <> 0) || (( w <> inner.width) && (w <> 0)) || ((h <> inner.height) && (h <> 0)), "Just keep inner, bro.")
  81.  
  82. #I don't want to handle all of the special cases, so I'll be doing this instead
  83. co = outer
  84. ci = show ? outer.invert() : inner
  85. co = co.addborders(2,2,2,2)
  86. ci = ci.addborders(2,2,2,2)
  87. x = x+2
  88. y = y+2
  89. w = (w > 0) ? w : w-2
  90. h = (h > 0) ? h : h-2
  91. #now stuff happens, though maybe it could happen faster
  92. cs = stackvertical(co.crop(0,0,0,y),stackhorizontal(co.crop(0,y,x,h),ci.crop(x,y,w,h),co.crop(((w > 0) ? x+w : (co.width)+w),y,0,h)),co.crop(0,((h > 0) ? y+h : (co.height)+h),0,0))
  93. cs = cs.crop(2,2,-2,-2)
  94. return cs
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement